akhauriyash/Code-Regression huggingface dataset:
//#include "debug.h"
#include <string.h>
#include <limits.h>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
using namespace std;

//#include "math/modulo.h"

template<class T, T M>
struct modulo {
	T n;
	modulo(T n): n(n<0? n%M+M: n%M)   { }
	operator T() const                { return n;             }
	modulo operator-()                { return modulo(-n);    }
	modulo operator+(const modulo &o) { return modulo(n+o.n); }
	modulo operator-(const modulo &o) { return modulo(n-o.n); }
	modulo operator*(const modulo &o) { return modulo(n*o.n); }
	bool operator< (const modulo &o) const { return n< o.n; }
	bool operator<=(const modulo &o) const { return n<=o.n; }
	bool operator> (const modulo &o) const { return n> o.n; }
	bool operator>=(const modulo &o) const { return n>=o.n; }
	bool operator==(const modulo &o) const { return n==o.n; }
	bool operator!=(const modulo &o) const { return n!=o.n; }

	friend modulo pow(const modulo &x, T n) {
		if (n==0) return 1;
		modulo y = pow(x, n/2);
		y = y*y;
		if (n%2) y = y*x;
		return y;
	}

	modulo inv() {
		return pow(this, M-2);
	}

	T gcd_ext(T a, T b, T *x, T *y) {
		if (a == 0) {
			*x = 0;
			*y = 1;
			return b;
		}
		T x1, y1;
		T gcd = gcd_ext(b%a, a, &x1, &y1);
		*x = y1 - (b/a) * x1;
		*y = x1;
		return gcd;
	}
	modulo operator/(const modulo &o) {
		T x, y;
		T g = gcd_ext(o.n, M, &x, &y);
		if (g != 1) return 0;
		else return modulo(n * (x % M));
	}
	friend ostream &operator<<(ostream &os, const modulo &x) {
		return os << x.n;
	}
};

typedef modulo<long,998244353> T;
//#include "math/comb.h"

void comb_inc_k(T &r, int n, int &k) {
        //C(n,k+1) = C(n,k) * (n-k) / (k+1)
	r = r * T(n-k) / T(k+1);
	k++;
}

void comb_dec_k(T &r, int n, int &k) {
        //C(n,k-1) = C(n,k) * k / (n-k+1)
	r = r * T(k) / T(n-k+1);
	k--;
}

void comb_inc_n(T &r, int &n, int k) {
        //C(n+1,k) = C(n,k) * (n+1) / (n+1-k)
	r = r * T(n+1) / T(n+1-k);
	n++;
}

void comb_dec_n(T &r, int &n, int k) {
        //C(n-1,k) = C(n,k) * (n-k) / n
	r = r * T(n-k) / T(n);
	n--;
}

T comb(int n, int k) {
    if (k*2 > n) k = n-k;
    if (n==0) return 0;
    T r = 1; //C(n,0)
    int i = 0;
    while (i<k) comb_inc_k(r, n, i);
    return r;
}


#define MAXN 100000

int n;


int input() {
	if (scanf("%d", &n) < 0) return 0;
	return 1;
}

void init() {
}

int solve() {
	T r = pow(T(3), n);
	int k = n/2;
	T e = comb(n, k);
	while (k+1<=n) {
		comb_inc_k(e, n, k);
		r = r - e*pow(T(2), n-k)*T(2);
	}
	return r;
}

void output(int ans) {
	printf("%d\n", ans);
}

void cleanup() {
}

int main() {
	//int ca; scanf("%d", &ca);
	while (input()) {
		init();
		output(solve());
		cleanup();
		//break;
	}
}





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



int main() {

    long long N;
    //bool sosu[10000000]{ false };
    //vector<long long> NG;

    cin >> N;

    long long ans = 0;
    //cout << sosu[0] << " " << sosu[1] << " " << sosu[2] << " " << endl;;
    long long ma = sqrt(N) + 1;
    long long hoge = 0;
    for (long long i = 2; i < ma; i++)
    {
        if (N >= i)
        {
            hoge = 1;
            long long hogege;
            while (true)
            {
                hogege = pow(i, hoge);
                if (N % hogege == 0)
                {
                    N = N / hogege;
                    // cout << N << " ";
                    hoge++;
                    ans++;
                }
                else break;
            }
            while (N % i == 0)
            {
                N = N / i;
            }
        }
        else break;
    }
    //素数が残っていたら
    if (N != 1) ans++;
    

    cout << ans << endl;
    return 0;
    
}

Measured memory_bytes: 4088
import bisect,collections,copy,heapq,itertools,math,string
import sys
def I():
    #1 line 1 int
     return int(sys.stdin.readline().rstrip())
def LI():
    #1 line n int
     return list(map(int,sys.stdin.readline().rstrip().split()))
def S():
    #1 line 1 string
     return sys.stdin.readline().rstrip()
def LS():
    #1 line n strings
     return list(sys.stdin.readline().rstrip().split())

A,B,C,D,=LI()

if A + B > C + D:
    print("Left")
elif A + B == C + D:
    print("Balanced")
else:
    print("Right")

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

int main(){
  int H, W;
  cin >> H >> W;
  int count = 0;
  bool judge = 0;
  rep(i, H){
    rep(j, W){
      char a;
      cin >> a;
      if (a == '#') count++;
    }
  }
  
  if (count == H + W - 1) judge = 1;
  if (judge) cout << "Possible" << endl;
  else cout << "Impossible" << endl;
  
  
    
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

	static Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		while(sc.hasNextInt()) {
			int[] a = new int[4], b = new int[4];
			for(int i = 0; i < 4; i++) a[i] = sc.nextInt();
			for(int i = 0; i < 4; i++) b[i] = sc.nextInt();
			int hit = 0, blow = 0;
			for(int i = 0; i < 4; i++) {
				for(int j = 0; j < 4; j++) {
					if(a[i] == b[j]) {
						if(i == j) {
							hit++;
						} else {
							blow++;
						}
					}
				}
			}
			System.out.println("" + hit + " " + blow);
		}
	}

}

Measured memory_bytes: 11000
#!/usr/bin/node
(function(){
  var T=[];
  var stdin = process.openStdin();
  stdin.setEncoding('utf8');
  var a=[1,1,2];
  for(var i=3;i<31;i++)a.push(a[i-1]+a[i-2]+a[i-3]);

  stdin.on('data', function(input) {
    var i=0,len,ref,x=[];
    ref=input.split("\n");
    for(len=ref.length;i<len;i++){
    	if(ref[i]=='')continue;
    	x.push(ref[i]^0);
    }
    //リダイレクトしてもttyから読み込んでも実行できる特殊処理
    if(x.length>2||!isNaN(x[1]))T=x;
    else T.push(x[0]);
  });

  stdin.on('end', function(z) {
    for(var i=0;T[i];i++){
      console.log((a[T[i]]+3649)/3650^0);
	}
  });
})();

Measured memory_bytes: 7640
#include"bits/stdc++.h"
using namespace std;
int main(){
	string s;
	cin>>s;
	int n;
	cin>>n;
	string ans;
	for(int i=0;i!=s.size();++i){
		if(!(i%n))
			ans+=s[i];
	}
	cout<<ans;
}


Measured memory_bytes: 256
using namespace std;
#include<iostream>
#include<bits/stdc++.h>
#include<algorithm>
#define w(x) int x;cin>>x;while(x--)

#define FIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)

#define ll long long

void abc()
{
	FIO;
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}

int mod = 1000000007;
vector<vector<int>> mat;
vector<vector<int>> dp;
int n, m;





int go(int i, int  j) {
	if (i<0 or i >= n or j<0 or j >= m or mat[i][j] == 1) return 0;
	if (i == n - 1 and j == m - 1) return 1;
	if (dp[i][j] != -1) return dp[i][j];
	int x = (go(i + 1, j) + go(i, j + 1))%mod;
	return dp[i][j] = x;
}


int main()
{
	abc();

	cin >> n >> m;
	mat.resize(n, vector<int>(m, 0));
	dp.resize(n, vector<int>(m, -1));
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			char c;
			cin >> c;
			if (c == '#') mat[i][j] = 1;
		}
	}



	cout << go(0, 0);

}

Measured memory_bytes: 11132
#include<iostream>
using namespace std;
#define L long long int
int main(){
int n,ans;
while(cin>>n){
ans=0;
int a,b,c,d;
for(a=9;a>=0;a--)for(b=9;b>=0;b--)for(c=9;c>=0;c--)for(d=9;d>=0;d--){
	if(a+b+c+d==n){ans++;
	}else if(a+b+c+d<n){break;
	}
}
cout<<ans<<endl;
}
return 0;
}

Measured memory_bytes: 1160
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <iomanip>
#include <cassert>

using namespace std;
typedef long long ll;

int main(){
   int K;
   cin >> K;
   int cur = 7%K;
   int ans =1;
   for(int i = 0; i<=K; i++){
      if(cur==0){
         cout << ans << endl;
         return 0;
      }
      cur*=10;
      cur+=7;
      cur%=K;
      ans++;
   }
   cout << -1<< endl;
   return 0;
}


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

#define REP(i, x) REPI(i, 0, x)
#define REPI(i, a, b) for (int i = int(a); i < int(b); ++i)
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
using namespace std;

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

  int N, K;
  cin >> N >> K;
  string S;
  cin >> S;
  S.at(K - 1) = char(S.at(K - 1) + 32);
  cout << S << endl;

  return 0;
}


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

using namespace std;

using ll = long long;

#define FOR(i,n,m) for(ll i=(n);i<(m);++i)
#define REP(i,n) FOR(i,0,n)

using Field=vector<vector<string>>;


pair<Field,int> move(const Field b,int dh,int dw){
  Field res(2,vector<string>(2,".."));
  for(int i=0;i<2;i++){
    for(int j=0;j<2;j++){
      for(int k=0;k<2;k++){
	if(0<=j+dh && j+dh<2 && 0<=k+dw && k+dw<2){
	  res[i][j+dh][k+dw]=b[i][j][k];
	}
	else{
	  if(b[i][j][k]=='#'){
	    return make_pair(res,-1);
	  }
	}
      }
    }
  }
  return {res,0};
}

Field drop(Field f,Field nb){
  int soko=-1;

  for(int x=18;x>=-1;x--){
    if(x==-1){
      soko=0;
      break;
    }
    for(int i=0;i<2;i++){
      for(int j=0;j<2;j++){
	for(int k=0;k<2;k++){
	  if(f[i+x][j][k]=='#' && nb[i][j][k]=='#'){
	    soko=x+1;
	  }
	}
      }
    }
    if(soko!=-1){
      break;
    }
  }

  Field res=f;
  for(int i=0;i<2;i++){
    for(int j=0;j<2;j++){
      for(int k=0;k<2;k++){
	if(nb[i][j][k]=='#'){
	  res[i+soko][j][k]='#';
	}
      }
    }
  }
  return res; 
}

int fresh(Field &nf){
  int res=0;
  for(int i=0;i<20;i++){
    bool isFresh=true;
    for(int j=0;j<2;j++){
      for(int k=0;k<2;k++){
	isFresh&=(nf[i][j][k]=='#');
      }
    }
    if(isFresh){
      res++;
      for(int j=0;j<2;j++){
	for(int k=0;k<2;k++){
	  nf[i][j][k]='.';
	}
      }
      for(int ii=i+1;ii<20;ii++){
	for(int j=0;j<2;j++){
	  for(int k=0;k<2;k++){
	    nf[ii-1][j][k]=nf[ii][j][k];
	  }
	}
      }
      i--;
    }
  }
  return res;
}

int dfs(int index,Field &f,const vector<Field> &blocks,const int n){
  if(index==n) return 0;
  int res=0;
  for(int dh=-1;dh<=1;dh++){
    for(int dw=-1;dw<=1;dw++){
	auto nbp=move(blocks[index],dh,dw);
	if(nbp.second==-1){
	  continue;
	}
	Field nb=nbp.first;
	Field nf=drop(f,nb);
	int sc=fresh(nf);
	res=max(sc+dfs(index+1,nf,blocks,n),res);	
    }
  }
  return res;
}
int solve(int h,int n){
  Field f(20,vector<string>(2,".."));
  for(int i=0;i<h;i++){
    cin>>f[i][0];
    cin>>f[i][1];
  }

  vector<Field> b(n,Field(2,vector<string>(2,"..")));
  for(int i=0;i<n;i++){
    cin>>b[i][0][0];
    cin>>b[i][0][1];
    cin>>b[i][1][0];
    cin>>b[i][1][1];
    if(b[i][0][0][0]=='.' && b[i][0][0][1]=='.' && b[i][0][1][0]=='.' && b[i][0][1][1]=='.'){
      b[i][0][0][0]=b[i][1][0][0];
      b[i][0][0][1]=b[i][1][0][1];
      b[i][0][1][0]=b[i][1][1][0];
      b[i][0][1][1]=b[i][1][1][1];
      b[i][1][0][0]='.';
      b[i][1][0][1]='.';
      b[i][1][1][0]='.';
      b[i][1][1][1]='.';
    }
  }

    return dfs(0,f,b,n);
}
int main() {

  while(true){
    int h,n;
    cin>>h>>n;
    if(h==0) break;
    // cout<<h<<" "<<n<<endl;
    cout<<solve(h,n)<<endl;
  }
  return 0;
}


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007

int main() {
  
  int H,W,K;
  cin >> H >> W >> K;

  int black = 0;
  vector<string> S(H);
  for(int i = 0;i < H;i++) {
    cin >> S[i];
    for(int j = 0;j < W;j++) {
      if(S[i][j] == '#') black++;
    }
  }

  int ans = 0;
  for(int t = 0;t < 1<<H;t++) {
    for(int y = 0;y < 1<<W;y++) {
      int num = 0;
      for(int i = 0;i < H;i++) {
        if(t>>i&1) {
          for(int j = 0;j < W;j++) {
            if(S[i][j] == '#') num++;
          }
        }
      }

      for(int i = 0;i < W;i++) {
        if(y>>i&1) {
          for(int j = 0;j < H;j++) {
            if(S[j][i] == '#') num++;
          }
        }
      }

      for(int i = 0;i < H;i++) {
        if(t>>i&1) {
          for(int j = 0;j < W;j++) {
            if(y>>j&1 && S[i][j] == '#') num--;
          }
        }
      }

      if(black - num == K) ans++;
    }
  }

  cout << ans << endl;
  
}


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

using namespace std;
 
#define MD 1000000007
typedef long long int ll;

template <typename T> std::string tostr(const T& t)
{
    std::ostringstream os; os<<t; return os.str();
}

int main(){
    int a,b;
    cin>>a>>b;
    int ans=0;
    for(int i=a;i<=b;i++){
        string s1=tostr(i),s2=tostr(i);
        reverse(s2.begin(),s2.end());
        if(s1==s2){
            ans++;
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#import pysnooper
#import os,re,sys,operator,math,heapq,string
#from collections import Counter,deque
#from operator import itemgetter
#from itertools import accumulate,combinations,groupby,combinations_with_replacement,permutations
from sys import stdin,setrecursionlimit
#from copy import deepcopy

setrecursionlimit(10**6)
input=stdin.readline

h,w=map(int,input().split())
s=[list(input().rstrip()) for _ in range(h)]
mas=[["."]*w for _ in range(h)]
for i in range(h):
    for j in range(w):
        if j+1<w and (s[i][j],s[i][j+1])==("#","#"):
            mas[i][j],mas[i][j+1]="#","#"
        if j-1>=0 and (s[i][j],s[i][j-1])==("#","#"):
            mas[i][j],mas[i][j-1]="#","#"
        if i+1<h and (s[i][j],s[i+1][j])==("#","#"):
            mas[i][j],mas[i+1][j]="#","#"
        if i-1>=0 and (s[i][j],s[i-1][j])==("#","#"):
            mas[i-1][j],mas[i][j]="#","#"
print("Yes" if mas==s else "No")

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define dump(...)
#endif
#define endl "\n"
#define ll long long
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, x) for (int i = 0; i < (int)(x); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define RREP(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (int i = ((int)(x)); i > 0; i--)
#define INF (1 << 30 - 1)
#define LLINF (1LL << 60)
#define vi vector<int>
#define vvi vector<vector<int>>
#define pi pair<int, int>
#define ALL(a) (a).begin(), (a).end()
#define BIT(n) (1LL << (n))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()) //sortしてからつかうこと
constexpr ll MOD = 1e9 + 7;
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};
ll A, B, C, D, E, F, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S, T;
ll ans = 0;

template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
    for (T &x : vec)
        is >> x;
    return is;
}

signed main() {
    cin >> X >> N;
    vi p(N);
    cin >> p;
    vi a(101);
    REP(i, N) {
        a[p[i]] = 1;
    }
    ans = INF;
    int res = 0;
    for (int i = -100; i <= 200; i++) {
        if (a[i] == 0) {
            if (ans > abs(X - i)) {
                ans = abs(X - i);
                res = i;
            }
        }
    }
    cout << res << endl;
}

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

#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = (n)-1; i >= 0; i--)
using namespace std;
typedef long long ll;

const int INF = 1e9;
int a,b;

int main() {
  cin >> a >> b;
  int ans = 0;
  ans = max(a + b, max(a - b, a * b));
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
typedef vector<int> vi;
typedef pair<int, int> pi;
#define SQ(a) (a) * (a)
#define deb(x) cout << #x << " = " << x << '\n'
#define deb2(x, y) cout << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")\n"
 
 
int main(int argc, char const *argv[])
{
 
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
 
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll int n,d;
    cin>>n>>d;
    d = SQ(d);
    vector<pair<ll int,ll int>> v(n);
    for(int i=0;i<n;i++){
        cin>>v[i].first>>v[i].second;
    }
    int count=0;
    for(int i=0;i<n;i++){
        ll int dist = SQ(v[i].first) + SQ(v[i].second);
        // deb(dist);
        if(dist<=d ){
            count++;
        }
    }
    cout<<count;
    return 0;
}

Measured memory_bytes: 6356
#include <iostream>
#include <map>
#include <cstdio>
#include <cstring>
#include <cmath>

using namespace std;

typedef unsigned long long ull;

int main()
{
    int x;
    
    cin >> x;
    
    printf("%s\n", (x < 1200) ? "ABC" : "ARC" );
    
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <cmath>

using namespace std;

#define REP(i,n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef pair<int, int> pint;

bool solve(string S, const string T) {
  int len = S.length();
  REP(i,len) {
    //    cout << S << endl;                                                                             
    if(S==T) return true;
    S = S.substr(1) + S.substr(0,1);
  }
  return false;
}

int main() {
  string S, T; cin>>S>>T;
  bool ans = solve(S, T);
  cout << ( ans ? "Yes" : "No") << endl;
  return 0;
}


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

using namespace std;

int main()
{
    int n; cin >> n;
    vector<int> as(n);
    for (auto& a: as) cin >> a;
    vector<int> bs(n);
    for (auto& b: bs) cin >> b;

    int64_t limit = 0;
    int64_t val = 0;
    for (int i = 0; i < n; i++) {
        int a = as[i];
        int b = bs[i];
        if (b > a) limit += (b - a) / 2;
        else       val   += a - b;
    }

    if (val <= limit) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

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

typedef long long ll;
#define PI 3.1415926535897932384626433
#define mod 1000000007

int gcd(int a, int b) { return b ? gcd(b, a%b) : a; }

int lcm(int a, int b) { return a * b / gcd(a, b); }

int main(){
    int n[4];
    for (int i = 0; i < 4; i++){
        cin >> n[i];
    }
    sort(n, n + 4);
    if(n[0] == 1 && n[1] == 4 && n[2] == 7 && n[3] == 9){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
    return 0;
}

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

int main(){

  string S;
  cin >> S;
  
  if ( S.at(0) == S.at(1) && S.at(2) == S.at(3) && S.at(0) != S.at(2) ){
    cout << "Yes" << endl;
  }else if ( S.at(0) == S.at(2) && S.at(1) == S.at(3) && S.at(0) != S.at(1) ){
    cout << "Yes" << endl;    
  }else if ( S.at(0) == S.at(3) && S.at(1) == S.at(2) && S.at(0) != S.at(1) ){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define rep(...) overload_rep(__VA_ARGS__, rep_1, rep_0) (__VA_ARGS__)
#define rep_0(i, end) for (int i = 0; i < (end); ++i)
#define rep_1(i, fr, ba) for (int i = (fr); i <= (ba); ++i)
#define overload_rep(arg_0, arg_1, arg_2, name, ...) name
#define all(box) box.begin(), box.end()
 
template <class T, class U> inline bool chmax(T& lhs, const U& rhs) { if (lhs < rhs) { lhs = rhs; return 1; } return 0; }
template <class T, class U> inline bool chmin(T& lhs, const U& rhs) { if (lhs > rhs) { lhs = rhs; return 1; } return 0; }

constexpr int dx[] = { 1, 0, -1, 0 };
constexpr int dy[] = { 0, 1, 0, -1 };

int H, W;
int dist[20][20];
char grid[20][20];

bool inside(int x, int y) {
  return 0 <= x && x < H && 0 <= y && y < W;
}

int bfs(int x, int y) {
  rep (i, H) rep (j, W) dist[i][j] = 100000;
  dist[x][y] = 0;
  std::queue<std::pair<int, int>> que;
  que.push(std::make_pair(x, y));
  while (!que.empty()) {
    int s, t;
    std::tie(s, t) = que.front();
    que.pop();
    rep (k, 4) {
      int ns = s + dx[k], nt = t + dy[k];
      if (!inside(ns, nt) || grid[ns][nt] == '#') {
        continue;
      }
      if (chmin(dist[ns][nt], dist[s][t] + 1)) {
        que.push(std::make_pair(ns, nt));
      }
    }
  }
  int res = 0;
  rep (i, H) rep (j, W) {
    if (grid[i][j] == '#') continue;
    chmax(res, dist[i][j]);
  }
  return res;
}

int main() {

  std::cin >> H >> W;
  rep (i, H) rep (j, W) std::cin >> grid[i][j];

  int ans = 0;
  rep (i, H) rep (j, W) {
    if (grid[i][j] == '#') continue;
    chmax(ans, bfs(i, j));
  }
  std::cout << ans << '\n';
  return 0;

}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstdio>
using namespace std;
 
int main() {
 
  while(1) {
     
    string str;
     
    cin >> str;
 
 
    if(str[0] == '0' ) break;
 
    int a,b;
    a = b = 0;
 
    for(int i=1;i<str.size();i++) {
      if(str[i] == 'A') a++;
      else if(str[i] == 'B') b++;
    }
 
     
    if(a > b) a++;
    else b++;
 
    cout << a <<" "<< b << endl;
 
  }
 
  return 0;
 
}

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

int main() {
  string s;
  cin >> s;
  if(s.at(2)==s.at(3)&&s.at(4)==s.at(5)) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cmath>
#include <numeric>
#include <iomanip>
#include <string.h>
#include <cstdarg>

using namespace std;

typedef long long ll;

#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define REP3(i,st,en) for(ll (i)=(st);(i)<(en);(i)++)

using P = pair<ll, ll>;
const int MOD = 1e9+7;
const ll INF = 1e+14;
const double PI = 3.14159265349;


// Extended Print Func
template<class T> std::ostream& operator<<(std::ostream& os, const std::vector<T>& input){
    os << "[ ";
    REP(i, input.size()){
        os << input[i];
        if (i < input.size()-1) { os << " "; }
    }
    os << " ]";
    return os;
}
void print() { std::cout << "\n"; }
template<class T, class... A> void print(const T& first, const A&... rest) { std::cout << first << " "; print(rest...); }
template<class... A> void print(const A&... rest) { print(rest...); }



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

  ll ans = (N-1) * N / 2;
  std::cout << ans << "\n";  
  return 0;
}

Measured memory_bytes: 256
let content = '';
process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', buf => {
  content += buf;
});
process.stdin.on('end', () => {
  const rects = content
    .trim()
    .split('\n')
    .map(line => line.split(' ').map(n => parseInt(n, 10)));

  for (const rect of rects) {
    if (rect[0] !== 0 || rect[1] !== 0) {
      console.log(drawReact(rect));
    }
  }
});

const drawReact = ([h, w]) => {
  let result = '';
  for (let i = 0; i < h; i++) {
    result += drawLine(w, i) + '\n';
  }

  return result;
};

const drawLine = (w, y) => {
  let result = '';
  for (let i = 0; i < w; i++) {
    result += getCharOn(i, y);
  }

  return result;
};

const getCharOn = (x, y) => {
  const chars = ['.', '#'];
  if (y % 2 === 0) {
    chars.reverse();
  }

  return chars[x % 2];
};


Measured memory_bytes: 19496
#include <iostream>
#include <algorithm>
using namespace std;

int tr[300];
int sq[300];
int dp1[1000000];
int dp2[1000000];

int main() {

  for(int i=1; i < 300; i++) {
    tr[i] = tr[i-1] + i;
    sq[i] = sq[i-1] + tr[i];
  }
  for(int i=1; i < 1000000; i++) {
      dp1[i] = 1000111000;
      dp2[i] = 1000111000;
  }

  for(int i=0; i<1000000; i++) {
    for(int j=1; j < 300; j++) {
      if(i+sq[j] < 1000000) {
        dp1[i+sq[j]] = min(dp1[i] + 1, dp1[i+sq[j]]);
        if(sq[j]%2 == 1) {
          dp2[i+sq[j]] = min(dp2[i] + 1, dp2[i+sq[j]]);
        }
      }
    }
  }

  int n;
  while(cin >> n, n) {
    cout << dp1[n] << " " << dp2[n] << endl;
  }

  return 0;
}

Measured memory_bytes: 10892
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <queue>
#include <set>
#include <string>
#include <map>

using namespace std;

typedef long long ll;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)

int main() {
    int a,b,q; cin >> a >> b >> q;
    vector<ll> s(a);
    vector<ll> t(b);
    vector<ll> x(q);
    rep(i, a) cin >> s[i];
    rep(i, b) cin >> t[i];
    rep(i, q) cin >> x[i];
    for(int i = 0; i < q; i++) {
        auto its = upper_bound(s.begin(), s.end(), x[i]);
        ll leftsdiff = 0;
        ll rightsdiff = 0;
        if(its == s.end()) {
            leftsdiff = abs(s[a-1]-x[i]);
            rightsdiff = 1ull << 40;
        } else if (its == s.begin()){
            leftsdiff = 1ull << 40;
            rightsdiff = abs(*its - x[i]);
        } else {
            rightsdiff = abs(*its - x[i]);
            its--;
            leftsdiff = abs(*its - x[i]);
        }

        auto itt = upper_bound(t.begin(), t.end(), x[i]);
        ll lefttdiff = 0;
        ll righttdiff = 0;
        if(itt == t.end()) {
            lefttdiff = abs(t[b-1]-x[i]);
            righttdiff = 1ull << 40;
        } else if (itt == t.begin()){
            lefttdiff = 1ull << 40;
            righttdiff = abs(*itt - x[i]);
        } else {
            righttdiff = abs(*itt - x[i]);
            itt--;
            lefttdiff = abs(*itt - x[i]);
        }
        // cout << leftsdiff << " " << rightsdiff << " " << lefttdiff << " " << righttdiff << endl;

        // lefts leftt
        ll res = max(leftsdiff,lefttdiff);
        // cout << "pattern1: " << res << endl;
        // lefts rightt
        ll tmp = min(leftsdiff,righttdiff)*2 + max(leftsdiff,righttdiff);
        // cout << "pattern2: " << tmp << endl;

        if(res > tmp)
            res = tmp;
        // rights leftt
        tmp = min(rightsdiff,lefttdiff)*2 + max(rightsdiff,lefttdiff);
        // cout << "pattern3: " << tmp << endl;
        if(res > tmp)
            res = tmp;
        // rights rightt
        tmp = max(rightsdiff,righttdiff);
        // cout << "pattern4: " << tmp << endl;
        if(res > tmp)
            res = tmp;
        cout << res << endl;
    }
}


Measured memory_bytes: 3712
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = (ll)1e5;  
using  p = pair<int,int>;
int gcd(int a,int b){
	return b==0 ? a : gcd(b,a%b);
}

int main(){
   int n;
   cin >>n;
   ll ans = 0;
   for (int i = 1; i < n; i++)
   {  
      ans += i;
   }

   cout << ans;

}
  
  

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1e9;
const int MOD = 1000000007;
const double PI = acos(-1);
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};

void solve() {
	int n;
	cin >> n;
	string s;
	cin >> s;
	int l = 0;
	int r = n - 1;
	int ans = 0;
	for (;;) {
		while (l < n - 1 && s[l] != 'W') l++;
		if (l >= r) break;
		while (r > 0 && s[r] != 'R') r--;
		if (l >= r) break;
		ans++;
		swap(s[l], s[r]);
	}
	cout << ans << endl;
}

int main() {
	solve();
	return 0;
}

Measured memory_bytes: 3752
"""

Xorを0にする

(A1-X)^(A2+X) ^ C == 0
となる最小のX

合計が決まっている
C側からありえそうなものだけ出す？
1なら 10 , 01
0なら 00 , 11
大きい方から決めていく
0の桁が両0 or 1は確定する
1は好きな方に割り振っていい
A1以下最大になるように寄せればおｋ

"""
import sys
N = int(input())
A = list(map(int,input().split()))

c = 0
for i in range(2,N):
    c ^= A[i]

a = A[0]
b = A[1]

remc = a+b
ori = 0

#print (remc)
lis = [None] * 60
for i in range(59,-1,-1):

    np = 2**i

    if np & c > 0:
        lis[i] = -1 #自由
        remc -= np
    else:
        if remc >= np*2:
            remc -= np * 2
            lis[i] = 1
            ori |= np
        else:
            lis[i] = 0
#print (remc,lis)
if remc != 0 or ori > a:
    print (-1)
    sys.exit()

ao = ori
#print (lis)
for i in range(59,-1,-1):

    np = 2**i
    if lis[i] == -1 and ao|np <= a:
        ao |= np

if ao > 0:
    print (a-ao)
else:
    print (-1)


Measured memory_bytes: 62064
#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define MAXN 200005
#define eps 1e-10
//#define ivorysi
using namespace std;
typedef long long int64;
typedef double db;
template<class T>
void read(T &res) {
	res = 0;T f = 1;char c = getchar();
	while(c < '0' || c > '9') {
		if(c == '-') f = -1;
		c = getchar();
	}
	while(c >= '0' && c <= '9') {
		res = res * 10 + c - '0';
		c = getchar();
	}
	res *= f;
}
template<class T>
void out(T x) {
	if(x < 0) {x = -x;putchar('-');}
	if(x >= 10) {
		out(x / 10);
	}
	putchar('0' + x % 10);
}
int N;int64 D;
int64 A[MAXN];
struct seg_tr {
	struct node {
		int L,R;
		int64 cov;
		pair<int64,int> val[2];
	}tr[MAXN * 4];
	void update(int u) {
		tr[u].val[1] = mp(1e16,0);
		if(tr[u].L != tr[u].R) {
			tr[u].val[0] = min(tr[u << 1].val[0],tr[u << 1 | 1].val[0]);
			tr[u].val[1] = min(tr[u << 1].val[1],tr[u << 1 | 1].val[1]);
		}
		tr[u].val[1] = min(tr[u].val[1],mp(tr[u].cov + tr[u].val[0].fi,tr[u].val[0].se));
	}
	void build(int u,int l,int r,int on) {
		tr[u].L = l;tr[u].R = r;tr[u].cov = 1e16;
		if(l == r) {
			tr[u].val[0] = mp(A[l] + on * l * D,l);
			update(u);
			return;
		}
		int mid = (l + r) >> 1;
		build(u << 1,l,mid,on);build(u << 1 | 1,mid + 1,r,on);
		update(u);
	}
	void Change(int u,int l,int r,int64 v) {
		if(l > r) return;
		if(tr[u].L == l && tr[u].R == r) {
			tr[u].cov = min(tr[u].cov,v);
			update(u);
			return;
		}
		int mid = (tr[u].L + tr[u].R) >> 1;
		if(r <= mid) Change(u << 1,l,r,v);
		else if(l > mid) Change(u << 1 | 1,l,r,v);
		else {Change(u << 1,l,mid,v);Change(u << 1 | 1,mid + 1,r,v);}
		update(u);
	}
	void Change_pos(int u,int p) {
		if(tr[u].L == tr[u].R) {
			tr[u].val[0] = mp(1e16,tr[u].L);
			update(u);return;
		}
		int mid = (tr[u].L + tr[u].R) >> 1;
		if(p <= mid) Change_pos(u << 1,p);
		else Change_pos(u << 1 | 1,p);
		update(u);
	}
}s[2];


void Solve() {
	read(N);read(D);
	for(int i = 1 ; i <= N ; ++i) read(A[i]);
	s[0].build(1,1,N,1);
	s[1].build(1,1,N,-1);
	s[0].Change_pos(1,1);s[1].Change_pos(1,1);
	s[0].Change(1,2,N,A[1] - D);
	int cnt = N - 1;
	int64 ans = 0;
	while(cnt--) {
		pair<int64,int> t[2];
		t[0] = s[0].tr[1].val[1],t[1] = s[1].tr[1].val[1];
		if(t[0] > t[1]) swap(t[0],t[1]);
		ans += t[0].fi;
		int u = t[0].se;
		s[0].Change_pos(1,u);s[1].Change_pos(1,u);
		s[1].Change(1,1,u - 1,1LL * u * D + A[u]);
		s[0].Change(1,u + 1,N,-1LL * u * D + A[u]);
	}
	out(ans);enter;
}
int main() {
#ifdef ivorysi
	freopen("f1.in","r",stdin);
#endif
	Solve();
}


Measured memory_bytes: 76800
#include <stdio.h>
#include <string.h>

int main(){
  char w[110] = {};
  char count[30] = {};

  scanf("%s", w);

  for(int i = 0; i < strlen(w); i++){
    count[w[i] - 'a']++;
  }

  for(int i = 0; i < 26; i++){
    if(count[i]%2 != 0){
      printf("No\n");
      return 0;
    }
  }

  printf("Yes\n");

  return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;

int main() {
    char s[11];
    cin >> s;

    cout << (memcmp(s, "YAKI", 4) == 0 ? "Yes" : "No") << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
using PL = pair<ll, ll>;
// Welcome to my source code!

bool f(int x) {
    for (int i = 2; i * i <= x; i++) {
        if (x % i == 0) return false;
    }
    return true;
}

int main() {
    int n;
    cin >> n;
    int ans = 0;
    for (int i = 0, a; i < n; i++) {
        cin >> a;
        if (f(a)) ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3100
#include <iostream>
#include <iomanip>
#include <cmath>
#include <string>
#include <vector>
#include <cstdlib>
#include <map>
#include <queue>
#include <deque>
#include <algorithm>
#include <stack>
#include <functional>
#include <sstream>
#define rep(i,j,n) for(i=j;i<(n);i++)
#define rrep(i,j,n) for(i=j;i>(n);i--)
typedef long long int lli;
#define N 1000000007
#define M 998244353

using namespace std;

int main(){
    lli x,y=100;
    lli i,j;
    cin>>x;
    rep(i,0,10000){
        y*=1.01;
        if(y>=x){
            cout<<i+1<<endl;
            break;
        }
    }
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define int long long
#define gcd            __gcd
#define setbits(x)     __builtin_popcountll(x)
#define zrobits(x)     __builtin_ctzll(x)
#define mod            1000000007
#define mod2           998244353
#define maxe           *max_element
#define mine           *min_element
#define inf            1e18
#define deci(x,y)      fixed<<setprecision(y)<<x
#define w(t)           int t; cin>>t; while(t--)
#define nitin          ios_base::sync_with_stdio(false); cin.tie(NULL)
#define PI             3.141592653589793238
using namespace std;

int power(int x, int y, int p)
{
    int res = 1;
    x = x % p;
    while (y > 0)
    {
        if (y & 1)
            res = (res * x) % p;
        y = y >> 1;
        x = (x * x) % p;
    }
    return res;
}
int modi(int a, int m)
{
    return power(a, m - 2, m);
}
int32_t main()
{
    nitin;
    int n;
    cin>>n;
    if(n%2==0)
        cout<<n<<endl;
    else
        cout<<2*n<<endl;
    return 0;
}

Measured memory_bytes: 3612
#include <iostream>
#include <cmath>
#include <stdint.h>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
using namespace std;
 
#define int long long
#define INF (1e18)+1
 
int nChoosek( int n, int k )
{
    if (k > n) return 0;
    if (k * 2 > n) k = n-k;
    if (k == 0) return 1;

    int result = n;
    for( int i = 2; i <= k; ++i ) {
        result *= (n-i+1);
        result /= i; 
    }
    return result;
}

int choose2(int n){
	
	return n*(n-1)/2;
}

int arr[200001];

int32_t main() {
 
  	int N,K;
  	
  	cin >> N >> K;
  	
  	for(int i=0; i<N; i++){
  	 
  		cin >> arr[i];  	
  		
	}
	
	sort(arr,arr+N);
	
	int l = -INF , r = INF;
	
	while(l+1 < r){
		
		int x = (l+r)/2;
		int cnt = 0;
		for(int i=0; i<N; i++){
			
			if(arr[i] < 0){
				
				int left = -1;
				int right =  N;
				
				while(left+1 < right){
					
					int m = (left+right)/2;
					
					if(arr[m] * arr[i]  < x ){
						right = m;
					}
					else{
						left = m;
					}
				}
				cnt += N - right;
			}
			else{
				
				int left = -1;
				int right = N;
				
				while(left+1 < right){
					
					int m = (left+right)/2;
					
					if(arr[m] * arr[i] < x)
						left = m;
					else
						right =m;
					
				}
				
				cnt+= right;
				
				
			}
			
			if(arr[i] * arr[i] < x){
				cnt--;
			}
			
			
		}
		
		cnt /= 2;
		
		if(cnt < K){
			l = x;
		}
		else{
			r = x;
		}
		
	}
	
	
	cout << l << endl;
	
	
 
}

Measured memory_bytes: 4668
// problem: "https://atcoder.jp/contests/abc128/tasks/abc128_b"

#include<bits/stdc++.h>

using namespace std;

struct Node
{
    string s;
    int i,p;

    Node (string s,int i,int p) : s(s),i(i),p(p) {}
};

bool func (Node n1,Node n2)
{
    if(n1.s == n2.s)
        return n1.p>n2.p;

    return n1.s < n2.s;
}

int main()
{
    int n;
    cin>>n;
    int i;
    vector<Node>V;

    for(i=0;i!=n;i++)
    {
        string s;
        int p;

        cin>>s>>p;

        V.push_back(Node(s,i+1,p));
    }

    sort(V.begin(),V.end(),func);

    for(i=0;i!=n;i++)
        cout<<V[i].i<<'\n';

    return 0;
}


Measured memory_bytes: 256
N,T = map(int,input().split())
c = []
t = []
for i in range(N):
    c1,t1 = [int(i) for i in input().split()]
    c.append(c1)
    t.append(t1)
ans = 10000
for i in range(N):
  if t[i] <= T:
    ans = min(ans,c[i])
if ans == 10000:
  print('TLE')
else:
  print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
//using namespace __gnu_pbds;

#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define lb lower_bound
#define ub upper_bound

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
//template<class T> using oset=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
const ll mod=1000000007;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}

//head
int main()
{
	ios::sync_with_stdio(false);
  	cin.tie(0);
  	ll x;
  	cin >> x;
  	if(x < 7) cout << 1 << endl;
  	else{
  		int add = 0;
  		if(x % 11 > 6) add+=2;
  		else if(x % 11 > 0) add++;
  		cout << (ll)((x/11)*2) + add << endl;
  	}
	return 0;
}


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

int main() {
  int N;
  cin>>N;
  set<int> S;
  for(int i=0;i<N;i++){
    int A;
    cin>>A;
    if(S.count(A))
      S.erase(A);
    else
      S.insert(A);
  }
  cout<<S.size()<<endl;
}


Measured memory_bytes: 8184
#include <iostream>
using namespace std;
int gcd (int a, int b) {
    if (a < b) {
        int tmp = a;
        a = b;
        b = tmp;
    }
    if (a % b == 0) {
        return b;
    } else {
        return gcd(b, a % b);
    }
}
int main (void) {
    int N;
    int K;

    cin >> N >> K;
    int G;
    int M = 0;
    for (int i = 0; i < N; i++) {
        int A;
        cin >> A;
        if (i == 0) {
            G = A;
        } else {
            G = gcd(G, A);
        }
        M = max(M, A);
    }

    if (K % G == 0 && K <= M) {
        cout << "POSSIBLE" << endl;
    } else {
        cout << "IMPOSSIBLE" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define pii pair<int,int>
const long long MOD=1000000007;

int main(){
    int a,b;
    cin>>a>>b;
    map<int,int> strength;
    rep(i,13) strength[i+1]=i;
    strength[1]=13;
    if(strength[a]>strength[b]) cout<<"Alice"<<endl;
    else if(strength[a]<strength[b]) cout<<"Bob"<<endl;
    else cout<<"Draw"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);i++)
int dy[] = {1, 0, 0, -1};
int dx[] = {0, 1, -1, 0};
int b[110][110];
int w, h;
int xs, ys, xg, yg;
int color;
bool flag = false;
bool used[110][110];

void dfs(int y, int x){
	rep(i, 4){
		int ny = y + dy[i], nx = x + dx[i];
		if(used[ny][nx]) continue;//???????????¨???????????????????????????
		if(!(0 <= ny && ny < h && 0 <= nx && nx < w)) continue;
		if(b[ny][nx] != color) continue;
		if(ny == yg && nx == xg){
			used[ny][nx] = true;
			flag = true; return;//????????????
		}
		used[ny][nx] = true;
		dfs(ny, nx);
	}
	return;//????????¢?????¨???????????????
}

int main(void){
	while(1){
		rep(i, 110)rep(j, 110){
			b[i][j] = -1; used[i][j] = false;
		}
		cin >> w >> h;
		if(w == 0 && h == 0) return 0;
		cin >> xs >> ys >> xg >> yg;
		xs--; ys--; xg--; yg--;
		int n; cin >> n;
		rep(i, n){
			int c, d, x, y;
			cin >> c >> d >> x >> y;
			x--; y--;
			if(d == 0){//?¨?
				b[y][x] = b[y][x + 1] = b[y][x + 2] = b[y][x + 3] = c;
				b[y + 1][x] = b[y + 1][x + 1] = b[y + 1][x + 2] = b[y + 1][x + 3] = c;
			}else{//???
				b[y][x] = b[y][x + 1] = c;
				b[y + 1][x] = b[y + 1][x + 1] = c;
				b[y + 2][x] = b[y + 2][x + 1] = c;
				b[y + 3][x] = b[y + 3][x + 1] = c;
			}
		}
		color = b[ys][xs];
		if(color == -1) {//?????????????????????????????????
			printf("NG\n"); continue;
		}
		used[ys][xs] = true; flag = false;
		dfs(ys, xs);
		if(flag) printf("OK\n");
		else printf("NG\n");
	}
}

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

int n;
double d0, d;

int main() {
	double ans = 0.0;
	cin >> n >> d0 >> d;
	n = n << 1;
	d0 -= d;
	for( ; n >= 2; n -= 2 ) {
		ans += d0 + d * (n + 1) / 2.0;
		double nd0 = d0 + (2 * d0 + 3 * d) / n;
		double nd = d + (4 * d) / n;
		d0 = nd0, d = nd;
	}
	cout << setprecision(20) << fixed << ans << endl;
}




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

using namespace std;

typedef long long ll;
typedef vector<ll> vl;
typedef long double ld;
typedef vector<ld> vd;
typedef bool bl;
typedef vector<bl> vb;
typedef unordered_map<ll,unordered_map<ll,ll>> graph;

const ll e5 = 1 << 21;
const ll mod = 1000000007;
const ll e3 = 1 << 13;
const ll INF = 1ll << 62;

ll n;
ll b[e3];
vl ans;

void error(){
  cout << -1 << endl;
  exit(0);
}

int main(){
  cin >> n;
  for(ll i = 1;i <= n;i++) cin >> b[i];
  for(ll i = n;i >= 1;i--){
    ll k = 1;
    ll max_arg = 0;
    for(ll j = 1;j <= n;j++){
      if(b[j] == k){
        max_arg = j;
      }
      if(b[j])k++;
    }
    // cerr << max_arg << endl;
    if(max_arg == 0 || b[max_arg] > i) error();
    ans.push_back(b[max_arg]);
    b[max_arg] = 0;
  }
  for(ll i = ans.size()-1;i >= 0;i--){
    cout << ans[i] << endl;
  }
}


Measured memory_bytes: 768
#include <iostream>
#include <cstdio>
#include <string>
#include <string.h>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cassert>
#include <bitset>
#include <fstream>
#include <stack>
#include <cstdlib>
#include <unordered_set>
#include <unordered_map>

using namespace std;

#define fst first
#define snd second
#define pb push_back
#define mp make_pair
#define ll long long
#define ull unsigned long long
#define ld long double

template < typename T>
T sqr(T x) {
	return x * x;
}

template < typename T>
T abs(T x) {
	return x > 0 ? x : -x;
}

//////////////////////////////////////////////////



int main() {
	//srand(time(NULL));
	#ifdef LOCAL	
		//gen();
		freopen("a.in", "r", stdin);
		//freopen("a.out", "w", stdout);
		cout << endl << endl;
	#else
		//freopen("whats.in", "r", stdin);
		//freopen("whats.out", "w", stdout);
	#endif
	//check();
	
	ios_base::sync_with_stdio(false);
	
	int n;
	cin >> n;
	vector < ll > a(n), b(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i] >> b[i];
	}
	ll all = 0;
	for (int i = n - 1; i >= 0; i--) {
		int x = (a[i] + all) % b[i];
		all += (b[i] - x) % b[i];
	}
	
	cout << all << "\n";
	
	return 0;
}


Measured memory_bytes: 1792
from collections import deque
H, W = map(int, input().split())
ch, cw = map(int, input().split())
dh, dw = map(int, input().split())
ch, cw, dh, dw = ch-1, cw-1, dh-1, dw-1
s = [input() for _ in range(H)]

d = [[-1]*W for _ in range(H)]

que = deque([[cw, ch, 0]])
while que:
    x, y, cost = que.popleft()
    if d[y][x]==-1 or d[y][x]>cost:
        d[y][x] = cost
        for dx in range(-2, 3):
            for dy in range(-2, 3):
                nx, ny = x+dx, y+dy
                if 0<=nx<W and 0<=ny<H and s[ny][nx]!='#':
                    if abs(dx)+abs(dy) == 1:
                        que.appendleft([nx, ny, cost])
                    else:
                        que.append([nx, ny, cost+1])  
print(d[dh][dw])

Measured memory_bytes: 238344
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  string S;
  cin >> S;
  vector<int> X(N+1);
  int x = 0;
  for(int i = 1;i<=N;i++){
    if(S[i-1] == 'I'){
      x++;
      X[i] =x;
    }
    else if(S[i-1] == 'D'){
      x--;
      X[i] = x;
    }
  }
  sort(X.begin(),X.end());
  cout << X[N] << endl;
}

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

int main() {
    ll N, count = 0, sub = 0;
    cin >> N;
    vector<string> S(N);
    REP(i, N) cin >> S[i];

    sort(S.begin(), S.end());

    S.erase(unique(S.begin(), S.end()), S.end());
    cout << S.size() << endl;
}

Measured memory_bytes: 9584
import java.util.Scanner;

public class Main {

	static int[][] list = {
		{0,0,0},
		{0,0,255},
		{0,255,0},
		{0,255,255},
		{255,0,0},
		{255,0,255},
		{255,255,0},
		{255,255,255},
	};
	
	static String[] name = {"black","blue","lime","aqua","red","fuchsia","yellow","white"};
	
	static int trans(char jyu, char ichi){
		int sum = 0;
		if('a'<=jyu&&jyu<='f'){
			sum += jyu-'a'+10;
		}
		else{
			sum += jyu-'0';
		}
		sum*=16;
		if('a'<=ichi&&ichi<='f'){
			sum += ichi-'a'+10;
		}
		else{
			sum += ichi-'0';
		}
		return sum;
	}
	
	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		
		while(true){
			char[] in = stdIn.next().toCharArray();
			if(in[0]=='0'){
				return;
			}
			int r = trans(in[1],in[2]);
			int g = trans(in[3],in[4]);
			int b = trans(in[5],in[6]);
//			System.out.println(r+" "+g+" "+b);
//			System.out.println("------------------");
			
			double min = Double.MAX_VALUE;
			int min_idx = -1;
			for(int k=0;k<8;k++){
				double tmp = Math.abs(Math.sqrt(Math.pow(r-list[k][0], 2)+Math.pow(g-list[k][1], 2)+Math.pow(b-list[k][2], 2)));
//				System.out.println(tmp);
				if(tmp<min){
					min = tmp;
					min_idx = k;
				}
			}
			System.out.println(name[min_idx]);
//			System.out.println("------------------");
		}
	}
}

Measured memory_bytes: 12000
import java.util.Comparator;
import java.util.List;
import java.util.Scanner;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

public class Main {
    public static void main(final String[] args) {
        final Scanner scanner = new Scanner(System.in);
        final int n = scanner.nextInt();
        final int m = scanner.nextInt();

        final List<Integer> list = IntStream.range(0, n)
                .mapToObj(i -> scanner.nextInt())
                .collect(Collectors.toList());

        final int sum = list.stream()
                .mapToInt(Integer::intValue)
                .sum();

        final long count = list.stream()
                .filter(i -> i * 4 * m >= sum)
                .count();

        System.out.println(count >= m ? "Yes" : "No");
    }
}


Measured memory_bytes: 28496
#include<stdio.h>

int main(void){
	int x, y, tmp;
	while(1){
		scanf("%d %d", &x, &y);
		if(x == 0 && y == 0){
			break;	
		}
		if(x > y){
			tmp = y;
			y = x;
			x = tmp;
		}
		printf("%d %d\n", x, y);
	}
	return 0;
}

Measured memory_bytes: 2668
#include <iostream>
#include <stdio.h>

using namespace std;

int left(int i){
    return 2*i;
}

int right(int i){
    return 2*i +1;
    
}

int maxHeapify(int A[], int i, int H){
    /*
    for(int i = 1; i <= H; ++i){
        printf(" %d", A[i]);
    }
    cout << endl;
    */
    int l, r, largest;
    l = left(i);
    r = right(i);
    
    if(l <= H and A[l] > A[i]){
        largest = l;
    } else {
        largest = i;
    }
    if(r <= H and A[r] > A[largest]){
        largest = r;
    }
    
    if(largest != i){
        int kari;
        kari = A[i];
        A[i] =  A[largest];
        A[largest] = kari;
        maxHeapify(A,largest, H);
    }
    
    return 0;
}
int buildMaxHeap(int A[], int H){
    for(int i = H/2; i>=1; --i){
        //cout << i << endl;
        maxHeapify(A, i, H);
    }
    return 0;
}

int main(){
    int H;
    int n,tmp;
    cin >> n;
    H = n;
    int *l;
    H = n;
    l = new int[n+1];
    for(int i = 1; i <=n; ++i){
        cin >> tmp;
        l[i] = tmp;
    }
    buildMaxHeap(l, H);
    for(int i = 1; i <= n; ++i){
        printf(" %d", l[i]);
    }
    cout << endl;
    return 0;
}




Measured memory_bytes: 5100