akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <map>
#include <string>
#include <cstdio>
using namespace std;

int main() {
	map<char,string> table1;
	map<string,char> table2;
	table1[' ']="101";
	table1['\'']="000000";
	table1[',']="000011";
	table1['-']="10010001";
	table1['.']="010001";
	table1['?']="000001";
	table1['A']="100101";
	table1['B']="10011010";
	table1['C']="0101";
	table1['D']="0001";
	table1['E']="110";
	table1['F']="01001";
	table1['G']="10011011";
	table1['H']="010000";
	table1['I']="0111";
	table1['J']="10011000";
	table1['K']="0110";
	table1['L']="00100";
	table1['M']="10011001";
	table1['N']="10011110";
	table1['O']="00101";
	table1['P']="111";
	table1['Q']="10011111";
	table1['R']="1000";
	table1['S']="00110";
	table1['T']="00111";
	table1['U']="10011100";
	table1['V']="10011101";
	table1['W']="000010";
	table1['X']="10010010";
	table1['Y']="10010011";
	table1['Z']="10010000";
	
	table2["00000"]='A';
	table2["00001"]='B';
	table2["00010"]='C';
	table2["00011"]='D';
	table2["00100"]='E';
	table2["00101"]='F';
	table2["00110"]='G';
	table2["00111"]='H';
	table2["01000"]='I';
	table2["01001"]='J';
	table2["01010"]='K';
	table2["01011"]='L';
	table2["01100"]='M';
	table2["01101"]='N';
	table2["01110"]='O';
	table2["01111"]='P';
	table2["10000"]='Q';
	table2["10001"]='R';
	table2["10010"]='S';
	table2["10011"]='T';
	table2["10100"]='U';
	table2["10101"]='V';
	table2["10110"]='W';
	table2["10111"]='X';
	table2["11000"]='Y';
	table2["11001"]='Z';
	table2["11010"]=' ';
	table2["11011"]='.';
	table2["11100"]=',';
	table2["11101"]='-';
	table2["11110"]='\'';
	table2["11111"]='?';
	
	string strIn;
	string strOut;
	string code;
	int codelen;
	
	while(getline(cin,strIn)){
		code = "";
		strOut = "";
		for(int i=0,l=strIn.length();i<l;++i){
			code += table1[strIn[i]];
		}
		
		if(codelen=code.length()%5){
			for(int i=0;i<5-codelen;++i)code += "0";
		}
		
		for(int i=0,len=code.length()/5;i<len;++i){
			 cout << table2[code.substr(i*5,5)];
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 1200
match = {1: 2, 2: 5, 3: 5, 4: 4, 5: 5, 6: 6, 7: 3, 8: 7, 9: 6}

N, M = map(int, input().split())
A = sorted(list(map(int, input().split())), reverse=True)

dp = [-1 for i in range(N + 1)]
dp[0] = 0
for i in range(N + 1):
    for a in A:
        if dp[i] >= 0 and i + match[a] <= N:
            dp[i + match[a]] = max(dp[i] + 1, dp[i + match[a]])

ans = ""
while N > 0:
    for a in A:
        if N - match[a] >= 0 and dp[N - match[a]] == dp[N] - 1:
            ans += str(a)
            N -= match[a]
            break

print(ans)

Measured memory_bytes: 3416
//diverta 2019 Programming Contest
#include <bits/stdc++.h>
using namespace std;
int main()
{

    int n, k;
    int num = 0;
    cin >> n >> k;
    if (k == 1)
    {
        cout << 0 << endl;
    }
    else
    {
        cout << n - k << endl;
    }
}


Measured memory_bytes: 256
fiveh = int(input())
oneh = int(input())
fifty = int(input())
n = int(input())

cnt = 0
for i in range(fiveh+1):
  for s in range(oneh+1):
    for l in range(fifty+1):
      if (i*500)+(s*100)+(l*50) == n:
        cnt+=1

print(cnt)
        
          


Measured memory_bytes: 39536
if __FILE__ == $0

	class UnionFindTree
		attr_reader :n, :parent , :rank

		def initialize(n)
			@n =n
			@parent = Array.new(n){ |idx| idx }
			@rank = Array.new(n,0)
		end

		def root(x)
			return parent[x]==x ? x : parent[x]=root(parent[x])
		end
		
		def is_same(x,y)
			return root(x)==root(y)
		end

		def unite(x,y)
			x=root(x)
			y=root(y)

			return false if x==y

			if rank[x]<rank[y]
				parent[x]=y
			else
				parent[y]=x
				rank[y]+=1 if rank[x]==rank[y]
			end
			
			return true
		end
		
	end

	class Edge

		attr_reader :from,:to,:cost
		include Comparable

		def initialize(from,to,cost)
			@from =from
			@to = to
			@cost = cost
		end

		def <=>(other)
			return @cost - other.cost
		end

	end

	n,m = gets.split.map(&:to_i)
	uft = UnionFindTree.new(n)
	
	edges = []
	m.times do
		s,t,w = gets.split.map(&:to_i)
		edges << Edge.new(s,t,w)
	end
	
	edges.sort!

	
	res=0
	edges.each do |e|
		if !uft.is_same(e.from,e.to)
			uft.unite(e.from,e.to)
			res+=e.cost
		end
	end

	puts res


end

Measured memory_bytes: 16712
import sys, math
def input(): return sys.stdin.readline().strip()

def main():
    N, M = map(int, input().split())
    A = list(map(int, input().split()))

    free = N - sum(A)
    if free < 0:
        print(-1)
    else:
        print(N - sum(A))


if __name__ == "__main__":
    main()


Measured memory_bytes: 68260
#include<bits/stdc++.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#define REP(i,a) for (int i = 0;i < (a);++i)
#define FOR(i,a,b) for (int i = (a);i < (b); ++i)
#define FORR(i,a,b) for (int i = (a);i >= (b); --i)
#define ALL(obj) (obj).begin,(obj).end()
#define SORT(list) sort(ALL((list)));
using namespace std;
using ll = long long;
int main(){
    int n,d;
    cin >> n >> d;
    if(n%(2*d+1) != 0 ){
        cout << (n/(2*d+1)) +1 << endl;
    }
    else{
        cout << (n/(2*d+1)) << endl;
    }
    return 0;
}

Measured memory_bytes: 256
/*
author: Apoorv Singh
*/

#include <bits/stdc++.h>
using namespace std;

typedef vector <long long> vi;
typedef pair <long long, long long> pii;
#define pb push_back   
#define all(c) c.begin(), c.end()
#define FOR(i, a, b) for (long long i = a; i < b; ++i)
#define FORR(i, a, b) for (long long i = a; i > b; --i)
#define um unordered_map
#define F first
#define S second
#define int long long
#define inf LLONG_MAX
#define endl "\n"
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define _CRT_SECURE_NO_WARNINGS

#define TRACE
#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

template <class X>
void printarr(X arr[], int n)
{
    for (int i = 0; i < n; ++i)
        cout << arr[i] << " ";
    cout << endl;
}
template <typename X> ostream& operator << (ostream& x,const vector<X>& v){ for (X a : v) x << a << ' '; return x;} 
template <typename X, typename Y> ostream& operator << (ostream& x, const vector< pair<X, Y> >& v) {for (pair <X, Y> it : v) x << it.first << ' ' << it.second << endl; return x;} 
template <typename T, typename S> ostream& operator << (ostream& os, const map<T, S>& v) { for (pair <T, S> it : v) os << it.first << " => " << it.second << endl; return os; }

double pi = 3.14159265358979323846264338327950288419716939937510582097494459230;
int modulo = 1e9 + 7;

int fpow(int a, int n)
{
    int ans = 1;
    while (n)
    {
        if (n&1)
            ans = (ans * a)%modulo;
        a = (a*a)%modulo;
        n = n >> 1;
    }
    return ans;
}

/*
const int M = 1e6 + 10;
int composite[M] = {0};

void sieve()
{
    FOR(i,2,M)
    {
        if (!composite[i])
        {
            for (int j = 2*i; j < M; j += i)
                composite[j] = max(composite[j], i);
        }
    }
}
*/

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n; cin >> n;
    pii arr[n];
    FOR(i,0,n) cin >> arr[i].S >> arr[i].F;
    sort(arr, arr+n);
    int curr = 0;
    FOR(i,0,n)
    {
        if (curr + arr[i].S > arr[i].F)
        {
            cout << "No";
            return 0;
        }
        curr += arr[i].S;
    }
    cout << "Yes";
    return 0;
}

Measured memory_bytes: 3328
#include<iostream>
#include<cstring>
#include<cstdio>
#define inf 0X3f3f3f3f
#define N 100010
#define ll long long
using namespace std;
int num[N];
ll lf[N],rf[N];
int main()
{
	int n,m;
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++) scanf("%d",&num[i]);
	for(int i=1;i<n;i++)
	{
		int x=num[i],y=num[i+1];
		if(x<y)
		{
			lf[1]+=(y-x);
			lf[x+1]+=(y+1)-(y-x);
			rf[x+1]--;
			lf[y+1]+=(y-x)-(y+1);
			rf[y+1]++;
		}
		else if(x>y)
		{
			lf[1]+=y+1;
			rf[1]--;
			lf[y+1]+=m-x+y-(y+1);
			rf[y+1]++;
			lf[x+1]+=y+1+m-(m-x+y);
			rf[x+1]--;
		}
	}
	lf[0]=rf[0]=0;
	for(int i=1;i<=m;i++) lf[i]+=lf[i-1];
	for(int i=1;i<=m;i++) rf[i]+=rf[i-1];
	ll ans=100000000000ll;
	for(int i=1;i<=m;i++) ans=min(ans,lf[i]+i*rf[i]);
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 2176
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (n); i++)

int main() {
    stack<int> st;
    string s[200];
    int cnt = 0;
    while(1) {
        if(cin.eof()) break;
        cin >> s[cnt];
        cnt++;
    }

    rep(i, cnt) {
        if(s[i]!="+" && s[i]!="-" && s[i]!="*" && s[i]!=" " && s[i]!="\0") {
            st.push(atoi(s[i].c_str()));
            //cout << "in" << endl;
        }
        else if(s[i]=="+") {
            int tmp1 = st.top();
            st.pop();
            int tmp2 = st.top();
            st.pop();
            st.push(tmp1+tmp2);
            //cout << tmp1 << "+" << tmp2 << endl;
        }
        else if(s[i]=="-") {
            int tmp1 = st.top();
            st.pop();
            int tmp2 = st.top();
            st.pop();
            st.push(tmp2-tmp1);
            //cout << tmp1 << "-" << tmp2 << endl;
        }
        else if(s[i]=="*") {
            int tmp1 = st.top();
            st.pop();
            int tmp2 = st.top();
            st.pop();
            st.push(tmp1*tmp2);
            //cout << tmp1 << "*" << tmp2 << endl;
        }
    }
	
  	int ansint = st.top();
  
  	string ans = to_string(ansint);  
  
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3272
H, W = map(int, input().split())
lst = [input() for _ in range(H)]
res = [[0 for i in range(W)] for j in range(H)]
x = [-1, -1, -1, 0, 0, 1, 1, 1]
y = [-1, 0, 1, -1, 1, -1, 0, 1]

for i in range(H):
    for j in range(W):
        if lst[i][j] == '#':
            res[i][j] = '#'
            for k in range(8):
                xk = i + x[k]
                yk = j + y[k]
                if 0<= xk < H and 0 <= yk < W:
                    if res[xk][yk] != '#':
                        res[xk][yk] += 1
for row in res:
    for i in row:
        print(i, end='')
    print('')


Measured memory_bytes: 3444
#n, m, q = map(int, input().split())
#List = list(map(int, input().split()))
#req = [list(map(int, input().split())) for _ in range(q)]
#t = t[:-1]
#print(ans[j], end = "") 改行無しで出力
#[0]*n
import math
x, n = map(int, input().split())
p = list(map(int, input().split()))

if n == 0:
    print(x)

else:
    max = -1
    i = -1
    while(max == -1):
        i = i + 1
        if p.count(x+i) == 0:
            max = x+i

    min = -1
    j = -1
    while(min == -1):
        j = j + 1
        if p.count(x-j) == 0:
            min = x-j

    if (abs(x-max) < abs(x-min)):
        print(max)
    else:
        print(min)


Measured memory_bytes: 9208
#include <iostream>
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cstring>
#include <deque>
#include <functional>
#include <initializer_list>
#include <math.h>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <queue>
#include <vector>

#define FOR(i, a, b) for(int (i) = (a); (i) < (b); ++(i))
#define rFOR(i, a, b) for(int (i) = (b); (i) >= (a); --(i))
#define REP(i, n) FOR(i, 0, n)
#define rREP(i, n) rFOR(i, 0, (n-1))
#define SORT(A) std::sort((A).begin(), (A).end())
#define ALL(A) (A).begin(), (A).end()
// 座標圧縮 (for vector) : ソートしてから使うのが一般的 ; SORT(A) => COORDINATE_COMPRESSION(A)
#define COORDINATE_COMPRESSION(A) (A).erase(unique((A).begin(),(A).end()),(A).end())

using lli = long long int;
using pii = std::pair<int, int>;

void VintOut(std::vector<int>& A){
    const int n = A.size();
    if(n == 0){putchar('\n'); return;}
    printf("%d", A[0]);
    for(int i = 1; i < n; ++i) printf(" %d", A[i]);
    putchar('\n');
}
void VintOut(std::vector<long long int>& A){
    const int n = A.size();
    if(n == 0){ putchar('\n'); return;}
    printf("%lld", A[0]);
    for(int i = 1; i < n; ++i) printf(" %lld", A[i]);
    putchar('\n');
}

template <typename T>
inline bool chmin(T& a, T b){
    if(b < a){ a = b; return true;}
    return false;
}

template <typename T>
inline bool chmax(T& a, T b){
    if(a < b){ a = b; return true;}
    return false;
}

inline bool bitUP(int state, int k){ return (state >> k) & 1; }
inline bool bitUP(long long int state, int k){ return (state >> k) & 1;}


// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


//-100 -200 10

constexpr int inf = 1e9 + 334;
std::vector<int> A;

int main(void){
    int n; scanf("%d", &n);
    A.resize(n); REP(i, n) scanf("%d", &A[i]);

    int Mx = -inf, argMx;
    int mn = inf, argMn;
    REP(i, n){
        if(A[i] < mn) mn = A[i], argMn = i;
        if(A[i] > Mx) Mx = A[i], argMx = i;
    }
    argMx++; argMn++;

    printf("%d\n", 2 * n - 1);

    if(Mx + mn >= 0){
        for(int i = 1; i <= n; ++i) printf("%d %d\n", argMx, i);
        for(int i = 1; i + 1 <= n; ++i) printf("%d %d\n", i, i + 1);
    }
    else{
        for(int i = 1; i <= n; ++i) printf("%d %d\n", argMn, i);
        for(int i = n; i - 1 >= 1; --i) printf("%d %d\n", i, i - 1);
    }



    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>

using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define MIN(a, b) ((a) > (b) ? (b) : (a))
#define MAX(a, b) ((a) < (b) ? (b) : (a))

const long long INF = 1LL << 60;
typedef unsigned long long ll;
const long long MOD = 1000000000 + 7;

int main()
{
    int a, b;
    cin >> a >> b;
    if (a % 3 == 0 || b % 3 == 0 || (a + b) % 3 == 0)
    {
        cout << "Possible" << endl;
    }
    else
    {
        cout << "Impossible" << endl;
    }
    return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n,s) for(int i=(s);i<(n);i++)
#define rrep(i,n) for(int i=(n-1);i>=0;i--)
#define rreps(i,n,s) for(int i=s;i>=n;i--)
#define MOD 1000000007
using ll = long long;
using namespace std;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

int main(){
cin.tie(0);
ios::sync_with_stdio(false);
int x1,y1,x2,y2;
cin>>x1>>y1>>x2>>y2;
int dx=x2-x1,dy=y2-y1;
cout<<x2-dy<<" "<<y2+dx<<" "<<x1-dy<<" "<<y1+dx<<endl;
//system("pause");
return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
  int m,f,r;
  while (1) {
    cin >> m >> f >> r;
    if (m+f+r==-3) break;
    if (m==-1 || f==-1) {
      cout << "F" << endl;
      continue;
    }
    if (m+f>=80) {
      cout << "A" << endl;
      continue;
    }
    if (m+f>=65) {
      cout << "B" << endl;
      continue;
    }
    if (m+f>=50 || (m+f>=30 && r >=50)) {
      cout << "C" << endl;
      continue;
    }
    if (m+f>=30) {
      cout << "D" << endl;
      continue;
    }
    cout << "F" << endl;
  }

  return 0;
}



Measured memory_bytes: 3072
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main(){

	int r, d, x;
	cin >> r >> d >> x;

	int ans = x;
	for(int i=0; i<10; i++){
		ans = r * ans - d;
		cout << ans << endl;
	}

	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  int N;
  while (cin >> N, N) {
    int k[10010];
    int cnt = 0;
    for (int i = 0; i < N; i++) {
      cin >> k[i];
      if (k[i]) cnt++;
    }
    if (*max_element(k, k + N) <= 1) {
      cout << "NA" << endl;
      continue;
    }
    cout << cnt + 1 << endl;
  }

  return 0;
}


Measured memory_bytes: 3180
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define REP(i,n) for(ll i=0;i<(n);++i)
#define itn int
#define ocut cout
#define ouct cout
int main(){
    string s,t,u;
    cin >> s >> t;
    int a,b;
    cin >> a >> b;
    cin >> u;
    if(s==u){
        cout << a-1 << " " << b;
    }
    else{
        cout << a << " " << b-1;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define repr(i,from,to) for(int (i)=(from);(i)<(to);(i)++)
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
// const bool debug=true;
const bool debug=false;
#define DEBUG if(debug==true)
#define vprint(x) for(auto a:(x)) cout << x << endl;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll MOD = 1000000007;

int main(void) {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;cin>>n;
    cout << n*n*n << endl;
    return 0;
}


Measured memory_bytes: 256
n=int(input())
l=list(map(int,input().split()))
d=[l[0]]
for i in l[1:]:
    d.append(d[-1]+i)
s=d[-1]
ans=100000000000000000000000000000000000000000000000000000
for i in d:
    ans=min(ans,abs(s-2*i))
print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n,d; cin >> n >> d; vector<vector<int> > A(n,vector<int> (d,0));
    for (int i=0;i<n;i++)
    {
        for (int j=0;j<d;j++)
        {
            cin >>A[i][j];
        }
    }
    long long rep=0;
    for (int i=0;i<n;i++)
    {
        for (int j=i+1;j<n;j++)
        {
            long double ans=0;
            for (int k=0;k<d;k++)
            {
                ans+=(A[i][k]-A[j][k])*(A[i][k]-A[j][k]);
            }
            ans=sqrt(ans);
            if (ans==(long long)ans)
                rep++;
        }
    }
    cout << rep;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair <ll, ll> pll;

#define pb push_back
#define mp make_pair
#define all(_c) _c.begin(), _c.end()

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    int n, k;
    cin >> n >> k;

    int a[n];
    for (int i = 0; i < n; i++)
        cin >> a[i];
    
    vector <bool> dp(k + 1, 0);
    for (int i = 1; i <= k; i++) {
        bool f = 1;
        for (int j = 0; j < n; j++)
            if (a[j] <= i)
                f = f and dp[i - a[j]];
        if (!f)
            dp[i] = 1;
    }

    cout << (dp.back() ? "First" : "Second") << '\n';
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	
	void main() {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long sum = 0;
		int max = -1000000;
		int min = 1000000;
		for(int i=0;i<n;i++) {
			int a = sc.nextInt();
			sum += a;
			if(a<min) {
				min = a;
			}
			if(a>max) {
				max = a;
			}
		}
		
		System.out.println(min +" "+ max +" "+ sum);
				
	}
	public static void main(String[] args) {
		new Main().main();
	}

}



Measured memory_bytes: 42136
from collections import deque
s = input()
q = int(input())
s = deque(s)
ans = []
ans_s = ''
one_count = 0
key = 0
for i in range(q):
    ans.append(list(input().split()))
for i in ans:
    if int(i[0])==1:
        one_count += 1
    else:
        if one_count%2==0:
            if int(i[1]) == 1:
                s.appendleft(i[2])
            else:
                s.append(i[2])
        else:
            if int(i[1]) == 1:
                s.append(i[2])
            else:
                s.appendleft(i[2])

if one_count%2==0:
    print(''.join(s))
else:
    print(''.join(s)[::-1])


Measured memory_bytes: 118468
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int , int> i_i;
typedef vector<ll> vel;
typedef vector<int> vei;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> ve_vel;
typedef vector<vector<int>> ve_vei;
typedef vector<vector<char>> ve_vec;
typedef vector<vector<bool>> ve_veb;
typedef vector<vector<string>> ve_ves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define fs first
#define sc second
#define pub push_back
#define pob pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
typedef long long int64;
//const int64 INF = 1LL << 58;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);

    int W, H, x, y, r; cin >> W >> H >> x >> y >> r;
    int dis = INF;
    int temp = min(y, H - y);
    chmin(dis, temp);
    temp = min(x, W - x);
    chmin(dis, temp);
    if(dis >= r) cout << "Yes" << endl;
    else cout << "No" << endl;

    
}


Measured memory_bytes: 3168
#include <bits/stdc++.h>

using namespace std;

const long long mod = 1e9 + 7;

int main () {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  int N, M;
  cin >> N >> M;
  char grid[N][M];
  for (int i = 0; i < N; ++i)
    cin >> grid[i];
  long long dp[N][M];
  for (int i = 0; i < N; ++i)
    for (int j = 0; j < M; ++j)
      dp[i][j] = 0;
  for (int j = 0; j < M; ++j)
    if (grid[0][j] == '.')
      dp[0][j] = 1;
    else
      if (grid[0][j] == '#')
        break;
  for (int i = 0; i < N; ++i)
    if (grid[i][0] == '.')
      dp[i][0] = 1;
    else
      if (grid[i][0] == '#')
        break;
  for (int i = 1; i < N; ++i)
    for (int j = 1; j < M; ++j)
      if (grid[i][j] == '.') {
        if (grid[i - 1][j] == '.')
          dp[i][j] = (dp[i][j] + dp[i - 1][j]) % mod;
        if (grid[i][j - 1] == '.')
          dp[i][j] = (dp[i][j] + dp[i][j - 1]) % mod;
      }
  cout << dp[N - 1][M - 1];
}


Measured memory_bytes: 12404
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define ld long double
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define x first
#define y second

signed main(){
	ios::sync_with_stdio(false);
   	cin.tie(0);

	int x[10];
	for (int i=0; i<5; i++)
		cin>>x[i];
	for (int i=0; i<5; i++){
		if (x[i]==0){
			cout<<i+1<<endl;
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 3540
N, M, S = map(int, input().split())
G = [[] for i in range(N)]
for i in range(M):
    s, t, d = map(int, input().split())
    G[s].append([t, d])


def dijkstra(graph, start, inf=float('inf')):
    import heapq
    n = len(graph)
    distances = [inf] * n
    distances[start] = 0
    visited = [False] * n

    # 距離・頂点
    hq = [(0, start)]
    while hq:
        dist, fr = heapq.heappop(hq)
        visited[fr] = True

        for to, cost in graph[fr]:
            new_dist = distances[fr] + cost
            if (visited[to]) or (distances[to] <= new_dist):
                continue

            distances[to] = new_dist
            heapq.heappush(hq, (new_dist, to))

    return distances


ans = dijkstra(G, S)
for a in ans:
    print(a if a != float('inf') else 'INF')



Measured memory_bytes: 97732
program test
implicit none
integer::c=0
character*10::S
read*,S
if(trim(S)=='hi')then
	print*,'Yes'
else if(trim(S)=='hihi')then
	print*,'Yes'
else if(trim(S)=='hihihi')then
	print*,'Yes'
else if(trim(S)=='hihihihi')then
	print*,'Yes'
else if(trim(S)=='hihihihihi')then
	print*,'Yes'
else
	print*,'No'
end if
end program test

Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main() {
	string S, T;
	cin >> S >> T;
	int index = -1;
	//using size_t = unsigned long long;
	//using std::string::size_type = size_t;
	//std::string::size_typeが符号なし整数型として定義されている為、
	// S.size() - T.size() < 0の場合でout_of_range例外が発生していた
	for (int i = 0; i <= (int)S.size() - (int)T.size(); i++) {
		string s = S.substr(i, T.size());
		bool match = true;
		for (int i = 0; i < T.size(); i++) {
			if (s[i] != '?' && s[i] != T[i]) match = false;
		}
		if (match) index = i;
	}
	if (index == -1) cout << "UNRESTORABLE" << endl;
	else {
		S.replace(index, T.size(), T);
		for (char c : S) cout << (c == '?' ? 'a' : c);
		cout << endl;
	}
}


Measured memory_bytes: 256
a, b, m = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
xyc = []
for i in range(m):
    xyc.append(list(map(int, input().split())))

x = 0
y = 1
c = 2

price = []

for i in range(m):
    price.append(a[xyc[i][x]-1] + b[xyc[i][y]-1] - xyc[i][c])

print(min(min(price), min(a) + min(b)))

Measured memory_bytes: 86204
#include <bits/stdc++.h>
 
using namespace std;
 
#define repr(i,a,b) for (int i=a; i<b; i++)
#define rep(i,n) for (int i=0; i<  n; i++)
 
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
 
const long long INF = 1LL << 60;
#define PI 3.14159265359 
long long MOD = 1000000007;


template<typename T>
void remove(std::vector<T>& vector, unsigned int index)
{
    vector.erase(vector.begin() + index);
}
 
int gcd(int a, int b){
    if(b == 0) return a;
    else return gcd(b, a%b);
}
 
long long lcm (int a, int b){
    return  (long long) a*b /gcd(a,b);
}

long long GCD(long long a, long long b) { return b ? GCD(b, a%b) : a; }


int main(){
    int a, b, k;
    cin >> a >> b >> k;

    vector<int>K;
    repr(i,1,101){
        if(a%i ==0 && b%i == 0){
            K.push_back(i);
        }
    }
    cout << K[(K.size()-k)] << endl;

}



Measured memory_bytes: 3624
#include <iostream>
#include <vector>
#include <set>

using namespace std;

const int M = 1000005;

int main(void) {
	int N;
	cin >> N;
	vector<int> a(N);

	for (int i = 0; i < N; i++) {
		cin >> a[i];
	}
	//ふるい
	vector<int> cnt(M);
	for (int x : a) {
		if(cnt[x] != 0) {
			cnt[x] = 2;
			continue;
		}
		for (int i = x; i < M; i += x) {
			cnt[i]++;
		}
	}
	int ans = 0;
	for (int x : a) {
		if (cnt[x] == 1) ans++;
	}
	
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 7520
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define pp pair<pair<ll, ll>,pair<ll, ll>>
#define pll pair<ll,ll>
#define pdd pair<double,double>
#define vii vector<int>
#define vll vector<ll>
#define mat vector<vector<ll>>
#define lb lower_bound
#define pb push_back
#define mp make_pair
#define fi first
#define sc second
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define LB(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define UB(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
#define ERASE(v) sort(v.begin(),v.end());v.erase(unique(v.begin(),v.end()),v.end())
// #define int ll
using namespace std;
const ll INF = (1 << 30 ) - 1;
const ll LLINF = (1LL << 60LL);
const ll MOD = 1000000007;
const ll mod = 998244353;
const ll MAX = 1100000;
const double pi = acos(-1);
const double eps = 1e-10;
ll dx[4] ={1,0,-1,0} , dy[4] ={0,1,0,-1};


signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    string s;
    cin>>s;
    ll n=s.size();
    ll ans=0;
    rep(i,n/2){
        if(s[i]!=s[n-1-i]) ans++;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
A,B = list(map(int,input().split()))

i_num=100

def get_one(N,i_num=i_num):
    n_list=[0]*i_num

    for i in range(i_num):
        N_ = N
        if 2**i > N_:
            break
        if (N_//2**i) % 2 == 0:
            N_ = (2**i)*(N//2**i)-1

        n_list[i] = (((N_//(2**i))-1)//2)*2**i + N_%(2**i)+1
    return(n_list)

B_=get_one(B)
A_=get_one(A-1)

ans_ = [0]*i_num
for i in range(i_num):
    if (B_[i] - A_[i]) % 2 != 0:
        ans_[i] = 1
        
ans_.reverse()
ans=''.join(map(str,ans_))

print(int(ans,2))

Measured memory_bytes: 9236
#include<bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
#define pb push_back
int dy[]={0, 0, 1, -1, 1, 1, -1, -1};
int dx[]={1, -1, 0, 0, 1, -1, -1, 1};

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define mp make_pair
#define fi first
#define sc second
ll n,m;

ll p[300000];
ll r[300000];

void init(ll n) {
	REP(i,n) {
		p[i] = i;
		r[i] = 0;
	}
}

ll find(ll i) {
	if(p[i] == i) {
		return i;
	}
	return p[i] = find(p[i]);
}

bool same(ll i,ll j) {
	return find(i) == find(j);
}

void unit(ll i,ll j) {
	i = find(i);
	j = find(j);
	if(i == j)
		return;

	if(r[i] < r[j]) {
		p[i] = j;
	}else {
		p[j] = i;
		if(r[i] == r[j]) {
			r[i]++;
		}
	}
}

int main(){
	cin >> n >> m;
	init(n + m);

	REP(i,n) {
		ll k;
		cin >> k;
		REP(j,k) {
			ll l;
			cin >> l;
			l += n - 1;
			unit(i,l);
		}
	}

	REP(i,n - 1) {
		if(!same(i,i+1)) {
			cout << "NO" << endl;
			return 0;
		}
	}
	cout << "YES" << endl;
	return 0;
}



Measured memory_bytes: 3840
#include <iostream>
#include <set>
#include <queue>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstring>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
#include <numeric>

using namespace std;

/*-----------------------------------------------------------------------------
　定義
 -------------------------------------------------------------------------------*/
typedef long long				ll;
#define ALL(x)					(x).begin(),(x).end()
#define REP(i, n)				for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n)			for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define INF						2e9
#define MOD						(1000 * 1000 * 1000 + 7)
#define Ceil(x, n)				(((((x))+((n)-1))/n))		/* Nの倍数に切り上げ割り算 */
#define CeilN(x, n)				(((((x))+((n)-1))/n)*n)		/* Nの倍数に切り上げ */
#define FloorN(x, n)			((x)-(x)%(n))				/* Nの倍数に切り下げ */
#define IsOdd(x)				(((x)&0x01UL) == 0x01UL)			
#define IsEven(x)				(!IsOdd((x)))						
#define M_PI					3.14159265358979323846
typedef pair<ll, ll>			P;

/*-----------------------------------------------------------------------------
　処理
 -----------------------------------------------------------------------------*/
int main()
{
	int H, N;
	cin >> H >> N;
	vector<int> A(N), B(N);
	REP(i, N) cin >> A[i] >> B[i];

	vector<int> dp(H + 1, INF);
	dp[0] = 0;
	REP(i, H) {
		if (INF != dp[i]) {
			REP(j, N) {
				int idx = min(A[j] + i, H);
				int exp = dp[i] + B[j];
				if (exp < dp[idx]) {
					dp[idx] = exp;
				}
			}
		}
	}

	cout << dp[H] << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define repr(i,n) for(int i=(int)(n-1);i>=0;i--)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout << #x" = " << x << endl
#define print(x) cout << x << endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt(x) bitset<32>(x).count()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;
typedef pair<int, P> PIP;
typedef pair<ll, ll> PL;
typedef pair<P, ll> PPL;
typedef set<int> S;

#define INF INT_MAX/3
#define MAX_N 1000000001


int main(){
    cin.sync_with_stdio(false);
    int d, e;
    while(cin >> d >> e, d | e) {
        double mini = INF;
        rep(i, d / 2 + 1) {
            minch(mini, abs(sqrt(i * i + (d - i) * (d - i)) - e));
        }
        cout << mini << endl;
    }

    return 0;
}

Measured memory_bytes: 3152
import fractions
A,B,C,D = map(int,input().split())
C_wareru = B//C-(A-1)//C
D_wareru = B//D-(A-1)//D
def lcm(a,b):
    return ((a*b) // fractions.gcd(a,b))
CD = lcm(C,D)
CD_wareru = B//CD-(A-1)//CD
print(B-A+1-(C_wareru+D_wareru-CD_wareru))

Measured memory_bytes: 5344
#include<bits/stdc++.h>
#define f(i,a,b) for(register int i=a;i<=b;++i)
#define ff(i,a,b) for(register int i=a;i>=b;--i)
#define debug(x) cerr << #x << " : " << x << " " << endl
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<string, string> pss;
const ll mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
const double tiaohe = 0.57721566490153286060651209;
ll oula(ll x) { ll res = x;f(i, 2, x / i) { if (x % i == 0) { res = res / i * (i - 1);while (x % i == 0) x /= i; } }if (x > 1) res = res / x * (x - 1);return res; }
ll quickmod(ll a, ll n, ll m) { ll s = 1;while (n) { if (n & 1) { s = s * a % m; }a = (a*a) % m;n = n / 2; }return s; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
void ex_gcd(ll a, ll b, ll &x, ll &y, ll &d) { if (!b) { d = a, x = 1, y = 0; } else { ex_gcd(b, a % b, y, x, d);y -= x * (a / b); } }
ll inv(ll t, ll p) { ll d, x, y;ex_gcd(t, p, x, y, d);return d == 1 ? (x % p + p) % p : -1; }
bool isPrime(ll x) { if (x == 2)return true;if (x % 2 == 0)return false;for (ll i = 2;i*i <= x;i++) if (x % i == 0)return false; return true; }
inline int in() { char ch = getchar();int x = 0, f = 1;while (ch<'0' || ch>'9') { if (ch == '-')f = -1;ch = getchar(); }while (ch >= '0'&&ch <= '9') { x = x * 10 + ch - '0';ch = getchar(); }return x * f; }
//double a = log(n) +tiaohe + 1.0 / (2 * n);
double eqa = (1 + sqrt(5.0)) / 2.0;
const int N = 6e5 + 4;
int a[N];
int main()
{
	//freopen("in.txt", "r", stdin);
	int n;n = in();
	f(i, 1, n)a[i] = in();
	ll ans = 0;
	ll sub = 0;
	ff(i, n , 1)
	{
		ans = (ans+sub*a[i] % mod) % mod;
		sub = (sub + a[i]) % mod;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 4372
#include<bits/stdc++.h>
  using namespace std;
  #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  #define endl "\n"
  #define int long long
  #define all(v) v.begin(),v.end()
  #define f first
  #define s second
  #define PB push_back
  #define MP make_pair
  #define double long double
  #define trace1(x)                cerr<<#x<<": "<<x<<endl
  #define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
  #define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
  #define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
  #define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
  #define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
  #define cases int testcases;cin>>testcases; while(testcases--)
  #define MOD 998244353
  #define N 200005
  #define INF 1000000000000
  #define eps 1e-6

vector<int> adj[N];
int ans[N];
bool vis[N];

void dfs(int s)
{
  if(vis[s])return;
  vis[s] = 1;

  for(auto i :adj[s])
  {
    if(!vis[i])
    {
      ans[i] += ans[s];
      dfs(i);
    }
  }
}
int32_t main()
{

    IOS

  
  int n,q;
  cin >> n >> q;


  for(int i = 1; i <= n - 1; i++)
  {
    int x, y;
    cin >> x >> y;
    adj[x].PB(y);
    adj[y].PB(x);
  }




  for(int i = 1; i <= q; i++)
  {
    int x,y;
    cin >> x >> y;
    ans[x] += y;
  }

  for(int i = 1; i <= n; i++)
  {
    if(!vis[i])dfs(i);
  }

  for(int i = 1; i <= n; i++)
  {
    cout << ans[i] << " ";
  }
	return 0;
}

Measured memory_bytes: 21376
#include <bits/stdc++.h>
using namespace std;

int main() {
  string s;
  cin >> s;
  int ans = 0;
  string a,b;
  if(s.size() % 2 == 0){
    int n = s.size()/2;
    for(int i = 0; i < n; i++){
      a += s[i];
      b += s[i+n];
    }
  }else{
    int n = (s.size()+1)/2;
    if(s.size() == 1){
      cout << ans << endl;
      return 0;
    }
    for(int i = 0; i < n-1; i++){
      a += s[i];
      b += s[i+n];
    }
  }
  reverse(b.begin(), b.end());
  while(a != b){
    for(int i = 0; i < a.size(); i++){
      if(a[i] != b[i]){
        a[i] = b[i];
        ans++;
        break;
      }
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    int c[3][3];

    for(int i=0; i<3; i++){
        for(int j=0; j<3; j++){
            cin >> c[i][j];
        }
    }

    for(int i=0; i<=100; i++){
        for(int j=0; j<=100; j++){
            for(int k=0; k<=100; k++){
                int b1 = c[0][0] -i;
                int b2 = c[0][1] -i;
                int b3 = c[0][2] -i;

                if(j+b1 == c[1][0] && k+b1 == c[2][0] &&
                   j+b2 == c[1][1] && k+b2 == c[2][1] &&
                   j+b3 == c[1][2] && k+b3 == c[2][2]){
                       
                       cout << "Yes" << endl;
                       return 0;
                   }
            }
        }
    }
    cout << "No" << endl;
}

Measured memory_bytes: 3640
#include <iostream> // C++の入出力
#include <stdio.h> // C の入出力
#include <algorithm> // sort などのアルゴリズム
#include <string.h> // C の文字列用
#include <ctype.h> // C の文字種用
#include <string> // C++の文字列
using namespace std;
int main(void){
    int n;
    string target;
    cin >> target;
    cin >> n;
    int len = target.length();
    int cnt=0;
    for(int i=0;i<n;i++){
        string in;
        cin >> in;
        string work = in.substr(0,len);
        in+=work;
        for(int t=0;t<10;t++){
            if(target==in.substr(t,len)){
                cnt++;
                break;
            }
        }
    }
    cout << cnt <<"\n";
    return 0;
}

Measured memory_bytes: 1216
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.Deque;
import java.util.Queue;
import java.util.StringTokenizer;

public class Main {
	
	static int di[] = {0, 0, 1, -1};
	static int dj[] = {1, -1, 0, 0};
	
	public static void main(String[] args) throws IOException {
		MyScanner sc = new MyScanner();
		PrintWriter out = new PrintWriter(System.out);
		int H = sc.nextInt();
		int W = sc.nextInt();
		int K = sc.nextInt();
		char[][] grid = new char[H][];
		int iFrom = sc.nextInt() - 1;
		int jFrom = sc.nextInt() - 1;
		int iTo = sc.nextInt() - 1;
		int jTo = sc.nextInt() - 1;
		for (int i = 0; i < H; i++) {
			grid[i] = sc.next().toCharArray();
		}
		int[][] dist = new int[H][W];
		for (int i = 0; i < H; i++) {
			Arrays.fill(dist[i], Integer.MAX_VALUE);
		}
		int[][] forb = new int[H][W];
		Deque<Integer> cola = new ArrayDeque<>();
		dist[iFrom][jFrom] = 0;
		cola.addLast(iFrom * W + jFrom);
		while (!cola.isEmpty()) {
			int val = cola.pollFirst();
			int ii = val / W;
			int jj = val % W;
			int nextDist = dist[ii][jj] + 1;
			for (int k = 0; k < 4; k++) if ((forb[ii][jj] & (1<<k)) == 0) {
				for (int steps = 1; steps <= K; steps++) {
					int ni = ii + di[k]*steps;
					int nj = jj + dj[k]*steps;
					if (0 <= ni && ni < H && 0 <= nj && nj < W && grid[ni][nj] == '.') {
						if (dist[ni][nj] > nextDist) {
							if (steps < K) {
								forb[ni][nj] |= 1 << k;
							}
							dist[ni][nj] = nextDist;
							cola.addLast(ni * W + nj);
						} else if (dist[ni][nj] < nextDist) break;
					} else break;
				}
			}
		}
		out.println(dist[iTo][jTo] == Integer.MAX_VALUE ? -1 : dist[iTo][jTo]);
		
		out.flush();
	}
	
	static class MyScanner {
		private BufferedReader br;
		private StringTokenizer tokenizer;
		
		public MyScanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}
		
		public String next() {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return tokenizer.nextToken();
		}
		
		public int nextInt() {
			return Integer.parseInt(next());
		}
		
		public long nextLong() {
			return Long.parseLong(next());
		}
	}
}


Measured memory_bytes: 63436
import java.util.*;
import java.text.*;

public class Main {

    Scanner sc = new Scanner(System.in);

    int n = sc.nextInt();
    int m = sc.nextInt();

    List<Integer>[] lists = new ArrayList[n+1];

    //        2 ... n
    int[] res = new int[n+1];


    public static void main(String[] args) {
        new Main().run();
    }

    void run() {

        for (int i=0; i<n+1; i++) lists[i] = new ArrayList<>();

        for (int i=0; i<m; i++) {
            int s = sc.nextInt();
            int t = sc.nextInt();
            lists[s].add(t);
            lists[t].add(s);
        }

//        System.out.println(lists[1]);

        bfs(1);

        int cnt = 0;

        for (int i=2; i<=n; i++) {
            if (res[i] != 0) cnt++;
        }

        if (cnt != n-1) {
            System.out.println("No");
        } else {
            System.out.println("Yes");
            StringBuilder sb = new StringBuilder();
            for (int i=2; i<=n; i++) {
                sb.append(res[i] + "\n");
            }
            System.out.println(sb.toString());
        }



    }

    void bfs(int s) {
        Queue<Integer> queue = new ArrayDeque<>();
        queue.add(s);
        while (!queue.isEmpty()) {
            int t = queue.peek();
            for (int u: lists[t]) {
                if (res[u] == 0) {
                    res[u] = t;
                    queue.add(u);
                }
            }
            queue.poll();
        }
    }
}



Measured memory_bytes: 76156
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main() {
    string S, T;
    cin >> S >> T;
    bool flag = false;
    if (S.size()+1 == T.size()) {
        flag = true;
        for (int i = 0; i < S.size(); i++) {
            if (S[i] != T[i]) {
                flag = false;
                break;
            }
        }
    }
    if (flag)
        cout << "Yes";
    else
        cout << "No";
}

Measured memory_bytes: 3616
#include<iostream>
#include<vector>
#include<queue>

using namespace std;

int main(){
	while(1){
		int h, w; cin >> h >> w;
		if (h + w == 0) break;
		int taikaku = h * h + w * w;
		int larger_min = 10000000;
		int ansh = h,answ = w;
		int f = 0;
		for (int i = 1; i <= 150; i++){	
			for (int j = i + 1; j <= 150; j++){
				int T = i * i + j * j;
				if (T > taikaku){
					if (larger_min > T){
						larger_min = T;
						ansh = i;
						answ = j;
					}
				}else if (T == taikaku and h < i and f == 0){
						larger_min = T;
						ansh = i;
						answ = j;
						f = 1;
				}
			}	
		}
		cout << ansh << " " << answ << endl; 
	}
return 0;
}

Measured memory_bytes: 3088
#include<bits/stdc++.h>
using namespace std;

int main()
{
  int H, W;
  cin >> H >> W;;
  
  vector<char> a(H * W);
  for(int i = 0; i < (H * W); i++)
  {
    cin >> a.at(i);
  }
  
  for(int i = 0; i < (H + 2); i++)
  {
    for(int j = 0; j < (W + 2); j++)
    {
      if((i == 0) || (i == H + 1) || (j == 0) || (j == W + 1))
        cout << '#';
      else
      {
        cout << a.at(((i - 1) * W) + j - 1);
      }
    }
    cout << endl;
  }
}

Measured memory_bytes: 256
B = input()
ACGT = ["A","C","G","T"]
temp = 0
ans = 0
for b,i in zip(B,range(len(B))):
    
    if ACGT.__contains__(b):
        temp += 1
    else:
        temp = 0
    if temp > ans:
        ans = temp
print(ans)
    

Measured memory_bytes: 2940
N,x=input().split()
X=int(x)
n=int(N)
y=0
A = [int(i) for i in input().split()]
A.sort()
for z in range(n):
  y+=A[z]
  if y>=X:
    if y==X:
      print(z+1)
    else:
      print(z)
    break
else:
  print(n-1)

Measured memory_bytes: 9056
#include <bits/stdc++.h>
#define INF (1ll<<60)
#define MOD 1000000007
#define l_ength size
using ll = long long;
using namespace std;

int main(){
	int n;
	cin >> n;
	vector<ll> a(n);
	for( auto &i : a ){
		cin >> i;
	}
	ll sum = accumulate( a.begin(), a.end(), 0ll );
	ll ans = INF;
	ll snuke = 0;
	for( int i = 0; i < n-1; ++i ){
		snuke += a.at(i);
		ans = min( ans, abs(snuke-(sum-snuke)) );
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
struct Fast {Fast(){std::cin.tie(0);ios::sync_with_stdio(false);}} fast;

/* define */
#define FOR(I,X,Y) for(long long (I)=(X);(I)<(Y);(I)++)
#define REP(I,X,Y) for(long long (I)=(Y)-1;(I)>=(X);(I)--)
#define ALL(X) (X).begin(),(X).end()
#define pb push_back
#define COUNT(V,X) upper_bound((V).begin(),(V).end(),X)-lower_bound((V).begin(),(V).end(),X)
#define debug(x) cerr<<#x<<':'<<x<<endl;
#define DEBUG(v) cerr<<#v<<':';for(auto xXx:v)cerr<<xXx<<' ';cerr<<endl;
#define Yes(X) if(X){cout<<"Yes"<<endl;}else{cout<<"No"<<endl;}
#define YES(X) if(X){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define ctoi(C) (C-'0')

/* alias */
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vii = vector<vector<int>>;
using vl = vector<long long>;
using vll = vector<vector<long long>>;
using pi = pair<int,int>;
using pl = pair<long long,long long>;
template<typename T> using PQ = priority_queue<T>;
template<typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

/* const */
const long long dx[] = {1,0,-1,0};
const long long dy[] = {0,1,0,-1};
const long long dx8[] = {1,1,0,-1,-1,-1,0,1};
const long long dy8[] = {0,1,1,1,0,-1,-1,-1};
const long long dx9[] = {1,1,0,-1,-1,-1,0,1,0};
const int INF = 1000000007;
const long long LINF = 1000000000000000007;

/* func */
template <typename T> inline bool chmin(T& a, const T& b) {if (a > b) a = b; return a > b;}
template <typename T> inline bool chmax(T& a, const T& b) {if (a < b) a = b; return a < b;}

/* main */

signed main(){
    string S;
    cin >> S;
    if(S.substr(0,7) == "keyence" || S.substr(S.size()-7,7) == "keyence"){
        YES(1);
        return 0;
    }
    FOR(i,0,7){
        string pre = S.substr(0,i);
        string back = S.substr(S.size()-7+i);
        debug(pre)
        debug(back)
        if(pre + back == "keyence"){
            YES(1);
            return 0;
        }
    }
    YES(0);
}


Measured memory_bytes: 256
def main():
    n = int(input())
    
    c = list(input())

    wcusum = [0]
    for c_i in c:
        wcusum.append(wcusum[-1]+(1 if c_i == 'W' else 0))

    rinv = [0]
    for c_i in c[::-1]:
        rinv.append(rinv[-1]+(1 if c_i == 'R' else 0))
    rinv = rinv[::-1]

    answers = []

    for i in range(n):
        answers.append(max(wcusum[i],rinv[i+1]))
    print(min(answers))



if __name__ == "__main__":
    main()

Measured memory_bytes: 27856
#include<bits/stdc++.h>
using namespace std;
using p=pair<int,int>;
#define int long long
#define rep(i,N) for(int i=0;i<N;i++)

signed main(){
  int A,B,C,D;
  cin>>A>>B>>C>>D;
  int ans=0;
  if(D==1){
    if(B==30||B==31||B==28)ans=1;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int main(void){
while(1){
	int a[9]={0};
	int flg=0;
	int m=0;
	int ed=0;
	for(int i=0;i<5;i++){
        int s;
        cin>>s;
        a[i]+=s;
        cin>>s;
        a[i]+=s;
        if(a[i]==0){
            ed=1;
            break;
        }
        if(a[i]>m)m=a[i],flg=i;

	}
	if(ed==1)break;
	switch(flg){
	case 0:cout<<"A ";break;
	case 1:cout<<"B ";break;
	case 2:cout<<"C ";break;
	case 3:cout<<"D ";break;
	case 4:cout<<"E ";break;

	};
	cout<<m<<endl;


}
	return 0;
}

Measured memory_bytes: 1160
N = int(input())

num_list = [int(input()) for i in range(N)]

sort_num_list = sorted(num_list)
max_n = sort_num_list[-1]
smax_n = sort_num_list[-2]

for i in num_list:
  if i==max_n:
    print(smax_n)
  else:
    print(max_n)


Measured memory_bytes: 14112
#include <bits/stdc++.h>
  using namespace std;

int main(){
  int n;
  cin>>n;
  int count=0;
  vector<int> p(n);
  for(int i=0;i<n;i++){
    cin>>p.at(i);
  }
  
  for(int i=0;i<n;i++){
   if( p.at(i)!=i+1){
   count++;
   }
  }
  if((count==2)||(count==0)){
   cout<<"YES"<<endl; 
  }else{
    cout<<"NO"<<endl; 
  }
}

Measured memory_bytes: 256