akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;
int main()
{
    int a, b, c, d, l, r;
    cin >> a >> b >> c >> d;
    l = a + b; r = c + d;
    if(l > r) cout << "Left" << endl;
    else if(l < r) cout << "Right" << endl;
    else cout << "Balanced" << endl;
    return 0;
}

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

int main() {
  int a, b;
  cin >> a >> b;
  int c;
  if (b < 10) c = a*10 + b;
  else if (b < 100) c = a * 100 + b;
  else if (b < 1000) c = a*1000 + b;
//  cout << c << endl;
  bool ans = false;
  for (int i = 0; i < 1000; i++) {
    if (i * i == c) ans = true;
  }
  if (ans)  cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int maxN = 5000;
vector<ll> dp1(maxN + 10);
vector<ll> dp2(maxN*maxN + 10);
int main() {
	ll N;
	cin >> N;
	vector<ll> A(3), B(3);
	for (int i = 0; i < 3; ++i)
    {
      cin >> A[i];
    }
  
	for (int i = 0; i < 3; ++i) 
    { 
      cin >> B[i];
    }
	dp1[0] = N;
	for (int i = 1; i <= N; ++i) {
		dp1[i] = dp1[i - 1];
		for (int j = 0; j < 3; ++j) {
			if (i - A[j] >= 0) {
				dp1[i] = max(dp1[i], dp1[i - A[j]] - A[j] + B[j]);
			}
		}
	}

	int n = *max_element(dp1.begin(), dp1.end());
	dp2[0] = n;
	for (int i = 1; i <= n; ++i) {
		dp2[i] = dp2[i - 1];
		for (int j = 0; j < 3; ++j) {
			if (i - B[j] >= 0) {
				dp2[i] = max(dp2[i], dp2[i - B[j]] - B[j] + A[j]);
			}
		}
	}

	cout << dp2[n] << endl;

	return 0;
}


Measured memory_bytes: 195584
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = (int)(a); i <= (int)(n); ++i)
#define rrep(i, a, n) for (int i = (int)(a); i >= (int)(n); --i)
#define debug(x) cerr << #x << " = " << x << "\n"
#define debugv(x) \
  rep(f, 0, (x.size() - 1)) cerr << x[f] << (f == (x.size() - 1) ? "\n" : " ")
#define all(x) x.begin(), x.end()
#define int long long
using namespace std;
typedef pair<int, int> pii;
typedef vector<int> vi;
const int MX = 1e5 + 5, INF = 5 << 28, MOD = 1e9 + 7;

string A, B;
void input() { cin >> A >> B; }
void solve() {
  ;
  if (A.size() > B.size()) {
    cout << "GREATER" << endl;
  } else if (A.size() < B.size()) {
    cout << "LESS" << endl;
  } else {
    cout << (A < B ? "LESS" : (A == B ? "EQUAL" : "GREATER")) << endl;
  };
}
signed main() {
  input();
  solve();
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int a,s;
  cin>>a>>s;
  if(a%3==0)cout<<"Possible"<<endl;
  else if(s%3==0)cout<<"Possible"<<endl;
  else if((a+s)%3==0)cout<<"Possible"<<endl;
  else cout<<"Impossible"<<endl;

}


Measured memory_bytes: 256
#include <stdio.h>

 int main(void){
 int a, b, c;

 scanf("%d%d%d", &a, &b, &c);

 int ispoor = 0;
 if (a == b && b != c) ispoor = 1;
if (b == c && c != a) ispoor = 1;
 if (c == a && a != b) ispoor = 1;

 if (ispoor) {
 puts("Yes");
 } else {
 puts("No");
 }

 return 0;
 }

Measured memory_bytes: 128
#include <iostream>
#include <queue>
using namespace std;
static const int N = 100;
static const int INFTY = (1 << 21);

int n, M[N][N];
int d[N];

void bfs(int s)
{
    queue<int> q;
    q.push(s);
    for (int i = 0; i < n; i++) {
        d[i] = INFTY;
    }
    d[s] = 0;
    int u;
    while (!q.empty()) {
        u = q.front();
        q.pop();
        for (int v = 0; v < n; v++) {
            if (M[u][v] == 0) continue;
            if (d[v] != INFTY) continue;
            d[v] = d[u] + 1;
            q.push(v);
        }
    }

    for (int i = 0; i < n; i++) {
        cout << i + 1 << " " << ((d[i] == INFTY) ? (-1) : d[i]) << endl;
    }
}

int main(int argc, char const *argv[])
{
    int u, k, v;

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

    for (int i = 0; i < n; i++) {
        cin >> u >> k;
        u--;
        for (int j = 0; j < k; j++) {
            cin >> v;
            v--;
            M[u][v] = 1;
        }
    }

    bfs(0);

    return 0;
}




Measured memory_bytes: 3100
/*
 * c.cc: 
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>

using namespace std;

/* constant */

const int MAX_N = 1000;

/* typedef */

/* global variables */

int dp[MAX_N + 1][MAX_N + 1];

/* subroutines */

/* main */

int main() {
  int qn;
  cin >> qn;

  while (qn--) {
    string x, y;
    cin >> x >> y;

    int xn = x.size(), yn = y.size();

    memset(dp, 0, sizeof(dp));

    for (int i = 0; i <= xn; i++)
      for (int j = 0; j <= yn; j++) {
	if (i < xn && j < yn && x[i] == y[j] &&
	    dp[i + 1][j + 1] < dp[i][j] + 1)
	  dp[i + 1][j + 1] = dp[i][j] + 1;

	if (i < xn && dp[i + 1][j] < dp[i][j])
	  dp[i + 1][j] = dp[i][j];

	if (j < yn && dp[i][j + 1] < dp[i][j])
	  dp[i][j + 1] = dp[i][j];
      }

    printf("%d\n", dp[xn][yn]);
  }

  return 0;
}

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

int main(){

    int N, M, X;
    cin >> N >> M >> X;
    vector<int> A(M);
    for(int i = 0; i < M; i++) cin >> A[i];

    int left = 0, right = 0;
    for(int i = 0; i < M; i++){
        if(A[i] < X) left++;
        else right++;
    }

    cout << min(left, right) << endl;

    return 0;
}

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

// 頂点数、変数
int v, e;
const int MAX_N = 100100;
// 隣接リスト
vector<int> to[MAX_N];
vector<int> from[MAX_N];
bool used[MAX_N];
// トポロジカルソートされた数列
vector<int> tps;

void dfs(int u) {
  if(used[u]) return;
  used[u] = true;
  for(int i: to[u]) dfs(i);
  // 帰りがけ順で追加
  tps.push_back(u);
}

void tsort() {
  for(int i=0; i<v; ++i) dfs(i);
  reverse(tps.begin(), tps.end());
}

int main(void){
  int n,m;
  cin >> n >> m;
  v = n;
  e = n+m-1;
  for(int i=0; i<e; ++i) {
    int s, t;
    cin >> s >> t;
    s--;t--;
    to[s].push_back(t);
    from[t].push_back(s);
  }

  tsort();
  int rvs[v];
  //rep(i,n)cout << tps[i] << endl;
  rep(i,v){
    int t = tps[i];
    rvs[t] = i;
  }
  //rep(i,n)cout << rvs[i] << endl;
  int ans[v];
  rep(i,v){
    if(i==tps[0]){
      cout << 0 << endl;
      continue;
    }
    int mx = 0;
    for(int j:from[i]){
      mx = max(rvs[j],mx);
      // cout << rvs[j] << endl;
    }
    cout << tps[mx]+1 << endl;
  }
  return 0;
}


Measured memory_bytes: 15612
MOD = 1000000007
def repeatSquares(x, n):  # x^n
  res = 1
  while n != 0:
    if n % 2 == 1:
      res *= x
      res %= MOD  # MOD演算ないなら消していい
    x *= x
    n //= 2
    x %= MOD      # MOD演算ないなら消していい
  return res

n = int(input())
A = list(map(int, input().split()))

dp = [0]*(n+1)
flag1 = True
for e in A:
  dp[e] += 1
if n % 2 == 0:
  for i in range(1, n):
    if i % 2 == 1:
      if dp[i] != 2:
        flag1 = False

  if flag1:
    ans = repeatSquares(2, n//2)
    print(ans)
  else:
    print(0)
else:
  for i in range(2, n):
    if i % 2 == 0:
      if dp[i] != 2:
        flag1 = False

  if flag1:
    ans = repeatSquares(2, n//2)
    print(ans)
  else:
    print(0)


Measured memory_bytes: 53480
#include <iostream>
using namespace std;
int main() {
    string s, t, result;
    cin >> s;
    cin >> t;
    if (s.length() + 1 == t.length()) {
        if (t.find(s) == 0) {
            result = "Yes";
        } else {
            result = "No";
        }
    } else {
        result = "No";
    }
    cout << result << endl;
    return 0;
}

Measured memory_bytes: 3576
import java.util.Arrays;
import java.util.Scanner;
import java.util.Vector;
public class Main {

	public static void main(String[] args) {
		Scanner ob=new Scanner(System.in);
		int n=ob.nextInt();
		int a[]=new int[n];
		int b[]=new int[n];
		for(int i=0;i<n;i++)
		{
		int x=ob.nextInt();
		int y=ob.nextInt();
		a[i]=x;b[i]=y;
		}
		for(int i=0;i<=a.length-3;i++)
		{
		if(a[i]==b[i]&&a[i+1]==b[i+1]&&a[i+2]==b[i+2]){
			System.out.println("Yes");
			System.exit(0);
		}
		}
		System.out.println("No");
	}
}

Measured memory_bytes: 27312
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr ll MOD=1000000007;
#define REP(i,n) for(ll i=0; i<(n); i++)
#define REP2(i,x,n) for(ll i=x; i<(n); i++)
const long long INF = numeric_limits<long long>::max();
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;
}
int main()
{
    ll N,D;
    cin >> N >> D;
    D *= D;
    ll count = 0;
    for ( ll i = 0; i < N; ++ i ){
        ll x, y;
        cin >> x >> y;
        ll value = x*x + y*y;
        if ( value <= D ){
            count++;
        }

    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
#define For(i,n,k) for(int i=(n);i<(k);i++)
#define ALL(a)  (a).begin(),(a).end()
int ans=0;
void Main(){
    int n;cin>>n;
    vector<vector<int>> graph(n);
    For(i,0,n-1){
        int a,b;cin>>a>>b;a--;b--;
        graph[a].push_back(b);
        graph[b].push_back(a);
    }
    vector<int> dist(n,-1),parity(2,0);
    queue<int> que;
    que.push(0);
    dist[0]=0;
    while(!que.empty()){
      int i=que.front();
      que.pop();
      for(auto j:graph[i]){
        if(dist[j]==-1){
          dist[j]=dist[i]+1;
          que.push(j);
        }
      }
    }
    For(i,0,n){
      parity[dist[i]%2]++;
    }
    int one=(n+2)/3,two=(n+1)/3,three=n/3;
    vector<int> p(n);
    if(parity[0]<=n/3){
      For(i,0,n){
        if(dist[i]%2==0){
          p[i]=3;
          three--;
        }
        else{
          if(one>0){
            p[i]=1;
            one--;
          }
          else if(two>0){
            p[i]=2;
            two--;
          }
          else{
            p[i]=3;
            three--;
          }
        }
      }
    }
    else if(parity[1]<=n/3){
      For(i,0,n){
        if(dist[i]%2==1){
          p[i]=3;
          three--;
        }
        else{
          if(one>0){
            p[i]=1;
            one--;
          }
          else if(two>0){
            p[i]=2;
            two--;
          }
          else{
            p[i]=3;
            three--;
          }
        }
      }
    }
    else{
      For(i,0,n){
        if(dist[i]%2==0){
          if(two>0){
            p[i]=2;
            two--;
          }
          else{
            p[i]=3;
            three--;
          }
        }
        else{
          if(one>0){
            p[i]=1;
            one--;
          }
          else{
            p[i]=3;
            three--;
          }
        }        
      }
    }
    vector<int> cnt(4,-1);
    For(i,0,n){
      cnt[p[i]]++;
      p[i]+=(cnt[p[i]]*3);
      cout<<p[i]<<" ";
    }
    cout<<endl;
}
int main(){
    Main();
    return 0;
}

Measured memory_bytes: 15220
import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		final int n = sc.nextInt();

		List<Integer> mochiList = new ArrayList<Integer>();

		for (int i = 0; i < n; i++) {
			mochiList.add(sc.nextInt());
		}

		Collections.sort(mochiList);
		List<Integer> mochiList2 = new ArrayList<Integer>(new LinkedHashSet<>(mochiList));

		System.out.print(mochiList2.size());

	}

}


Measured memory_bytes: 22736
#include <iostream>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <tuple>
#include <queue>
#include <set>
#include <cstdio>
#include <climits>
#include <cmath>
#include <array>
#include <functional>
#include <list>
#include <iomanip>
#include <set>
const int MOD=1000000007;
const int INF=1000000000;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
const double eps=1e-9;
const int inf=1e9;
typedef pair<ll,ll> P;

int mx[10005];
int mn[10005];
int main(int argc,char const* argv[])
{
  int n,m;
  while(cin >> n >> m && n)
    {
      memset(mx,0,sizeof(mx));
      memset(mn,0,sizeof(mn));
      for(int i=0;i<m;i++)
	{
	  int s,k;
	  cin >> s >> k;
	  for(int j=0;j<k;j++)
	    {
	      int c;
	      cin >>c;
	      c--;
	      if(k==1) mn[c]+=s;
	      mx[c]+=s;
	    }
	}
      int ans=0;
      for(int i=0;i<n;i++)
	{
	  for(int j=0;j<n;j++)
	    {
	      if(i==j) continue;
	      ans=max(ans,mx[i]-mn[j]);
	    }
	}
      cout << ans+1 << endl;
    }
  
  return 0;
}



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

int main(){
  int N; cin >> N;
  vector<tuple<int, int, int>> p(N);
  for(int i=0;i<N;i++){
    cin >> get<1>(p[i]) >> get<2>(p[i]) >> get<0>(p[i]);
  }
  sort(p.rbegin(),p.rend());
  int Cx=0;
  int Cy=0;
  int H=0;
  int count=0;
  for(int i=0;i<=100;i++){
    for(int j=0;j<=100;j++){
      count=0;
      Cx=i;
      Cy=j;
      H=get<0>(p[0])+abs(i-get<1>(p[0]))+abs(j-get<2>(p[0]));
      for(int l=0;l<N;l++){
        if(max(H-abs(i-get<1>(p[l]))-abs(j-get<2>(p[l])),0)!=get<0>(p[l])){
          break;
        }
        else count++;
        if(count==N){
          cout << i << " " << j << " " << H << endl;
          return 0;
        }
      }
    }
  }
}
      
    
    
  

Measured memory_bytes: 256
k, a, b = map(int, input().split())
if a+2 >= b:
    ans = k+1
else:
    if k <= a:
        ans = k+1
    else:
        n = k-(a-1)
        if n%2 == 0:
            ans = b + (b-a)*((n-2)//2)
        else:
            ans = b + (b-a)*((n-2)//2)+1
print(ans)


Measured memory_bytes: 2940
import numpy as np

def check_num_of_remaining_teleport(num_of_teleport, i):
    if num_of_teleport == 0:
        print(i)
        exit()

num_of_town, num_of_teleport = map(int, input().split())
town = np.array(list(map(int, input().split())))

# 香り高い町の探索
i = 1
# テレポートの移動ルールに合わせて1始まりにする
fragranttown_index = 1
fragrants = [0] * num_of_town
fragrants[0] = 1
for _ in range(num_of_town):
    i = town[i - 1]
    num_of_teleport = num_of_teleport - 1

    # 移動回数が終了した場合
    check_num_of_remaining_teleport(num_of_teleport, i)

    # すでに通った町か
    if fragrants[i - 1] != 1:
        fragrants[i - 1] = 1
    else:
        fragranttown_index = i
        break

# 香り高い町への再訪までの回数探索
# 再訪までの回数
revisit = 0
j = fragranttown_index
for _ in range(num_of_town):
    j = town[j - 1]
    revisit = revisit + 1
    num_of_teleport = num_of_teleport - 1

    # 移動回数が終了した場合
    check_num_of_remaining_teleport(num_of_teleport, j)

    # テレポート先が香り高い町なら
    if fragranttown_index == j:
        break

# 香り高い町からの最終移動
num_of_last_teleport = num_of_teleport % revisit
k = fragranttown_index
# rangeの中は一時変数にした方が高速
for _ in range(num_of_last_teleport):
    k = town[k - 1]
    
print(k)


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

using ll = long long;

const int INF = 1001001001;
const ll INF_LL = 1001001001001001001LL;

int main(void){
  int n; cin >> n;
  vector<int> a(n+1),b(n+1),c(n-1+1);
  for(int i = 1;i<=n;i++) cin >> a[i];
  for(int i = 1;i<=n;i++) cin >> b[i];
  for(int i = 1;i<=n-1;i++) cin >> c[i];

  int ans = 0;
  for(int i = 1;i<=n;i++){
    if(i>1 && a[i]-a[i-1]==1) ans += b[a[i]]+c[a[i]-1];
    else ans += b[a[i]];
  }

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


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

using namespace std;

using ll = long long;

const int MAX_V = 10000;
const ll INF = 100000000000000LL;

struct Edge {
    int to;
    ll cap;
    int rev;  //行き先、容量、逆辺
    Edge(int to, ll cap, int rev) : to(to), cap(cap), rev(rev) {}
};

vector<Edge> G[MAX_V];
int level[MAX_V];
int iter[MAX_V];

void add_edge(int from, int to, ll cap) {
    G[from].push_back(Edge(to, cap, G[to].size()));
    G[to].push_back(Edge(from, 0, G[from].size() - 1));
}

void bfs(int s) {
    memset(level, -1, sizeof(level));
    queue<int> que;
    level[s] = 0;
    que.push(s);
    while (!que.empty()) {
        int v = que.front();
        que.pop();
        for (int i = 0; i < G[v].size(); i++) {
            Edge& e = G[v][i];
            if (e.cap > 0 && level[e.to] < 0) {
                level[e.to] = level[v] + 1;
                que.push(e.to);
            }
        }
    }
}

ll dfs(int v, int t, ll f) {
    if (v == t) return f;
    for (int& i = iter[v]; i < G[v].size(); i++) {
        Edge& e = G[v][i];
        if (e.cap > 0 && level[v] < level[e.to]) {
            int d = dfs(e.to, t, min(f, e.cap));
            if (d > 0) {
                e.cap -= d;
                G[e.to][e.rev].cap += d;
                return d;
            }
        }
    }
    return 0;
}

ll max_flow(int s, int t) {
    ll flow = 0;
    while (true) {
        bfs(s);
        if (level[t] < 0) return flow;
        memset(iter, 0, sizeof(iter));
        ll f;
        while ((f = dfs(s, t, INF)) > 0) {
            flow += f;
        }
    }
}

ll a[105];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++) cin >> a[i];
    ll ans = 0;
    for (int i = 1; i <= n; i++) {
        if (a[i] >= 0) {
            ans += a[i];
            add_edge(i, n + 1, a[i]);
        } else {
            add_edge(0, i, -a[i]);
        }
        for (int j = i * 2; j <= n; j += i) {
            add_edge(i, j, INF);
        }
    }
    ans -= max_flow(0, n + 1);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 640
import sys
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()
from math import factorial
from collections import Counter

def main():
    N, X = LI()
    S = LI()
    S.sort(reverse=True)
    dp = Counter()
    dp[X] = factorial(N)
    for i, s in enumerate(S):
        pre = dp
        dp = Counter()
        for n, cnt in pre.items():
            if s <= n:
                dp[n] += cnt * (N - 1 - i) // (N - i)
                dp[n % s] += cnt // (N - i)
            else:
                dp[n] += cnt
    ans = 0
    for n, cnt in dp.items():
        ans = (ans + (n * cnt) % MOD) % MOD

    return ans

print(main())

Measured memory_bytes: 9076
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <iomanip>
#include <map>
using namespace std;

void solve(){
  int a[5]; for(int i = 0; i < 5; i++) cin >> a[i];
  int k; cin >> k;
  int ans = 0;
  for(int i = 0; i < 4; i++){
    for(int j = i + 1; j < 5; j++){
      if(a[j] - a[i] > k) ans++;
    }
  }
  if(ans > 0) cout << ":(" << endl;
  else cout << "Yay!" << endl;
  return;
}

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


Measured memory_bytes: 256
#include <stdio.h>
#define N 10000
#define M 500
int linearSearch(int,int[],int);
int main(){
  int a[N],b[M];
  int x,y,i,j,s=0;
  scanf("%d",&x);
  for(i=0;i<x;i++){
    scanf("%d",&a[i]);
  }
  scanf("%d",&y);
  for(i=0;i<y;i++){
    scanf("%d",&b[i]);
  }
  for(i=0;i<y;i++){
    if(linearSearch(b[i],a,x)==1){
      s++;
    }
  }
  printf("%d\n",s);
  return 0;
}

int linearSearch(int d,int a[],int x){
  int i=0;
  while(d!=a[i]||i==x){
    i++;
    if(i==x){
      return 0;
    }
  }
  return 1;
}


Measured memory_bytes: 2108
#include<algorithm>
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
using namespace std;
int main(){
  long long a,b,x;
  cin>>a>>b>>x;
  long long ans=0;
  if(a%x==0){
    cout<<b/x-a/x+1<<endl;
  }else{
    ans=b/x-a/x;
    cout<<ans<<endl;
  }


  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <stdbool.h>

int N;
int M = 10;
int **inData;
int *lTube;
int *rTube;

bool dfs(int n, int i, int l, int r)
{
	if (i==M)
		return true;

	//left tube
	if (l==-1 || inData[n][i]>lTube[l]) {
		lTube[l+1] = inData[n][i];
		if (dfs(n, i+1, l+1, r)) return true;
	}

	//right tube
	if (r==-1 || inData[n][i]>rTube[r]) {
		rTube[r+1] = inData[n][i];
		if (dfs(n, i+1, l, r+1)) return true;
	}

	//failed
	return false;
}

int main()
{
	int n, i, j;

	while (1) {

		//input & allocate memory
		if (scanf("%d ", &N) == EOF) break;

		inData = (int **)calloc(N, sizeof(int *));
		for (i=0; i<N; i++) {
			inData[i] = (int *)calloc(M, sizeof(int));
			
			for (j=0; j<M; j++)
				scanf("%d ", &(inData[i][j]));
		}

		lTube = (int *)calloc(M, sizeof(int));
		rTube = (int *)calloc(M, sizeof(int));

		for (n=0; n<N; n++) {
			for (i=0; i<M; i++)
				lTube[i] = rTube[i] = 0;

			//dfs & output
			if (dfs(n, 0, -1, -1))
				printf("YES\n");
			else
				printf("NO\n");
/*			
			printf("Left:\n");
			for (i=0; i<M; i++)
				printf("%d ", lTube[i]);
			puts("");
			printf("Right:\n");
			for (i=0; i<M; i++)
				printf("%d ", rTube[i]);
			puts("");
			printf("------------------\n");
*/
		}
/*
		for (i=0; i<N; i++) {
			for (j=0; j<M; j++)
				printf("%d ", inData[i][j]);
			puts("");
		}
*/
		//free memory
		for (i=0; i<N; i++)
			free(inData[i]);
		free(inData);
		free(lTube);
		free(rTube);
	}

	return 0;
}

Measured memory_bytes: 1024
//Volume0-0044
import java.util.*;

public class Main {

	//declare
	private static int   MAX = 50022;
	private static boolean[] prm = new boolean[MAX];
	
	public static void main(String[] args) {

		int n,
	    small = MAX,
	    large = 0;
		
		//initialize
		init();

		//input
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()){
			n = sc.nextInt();
			
			//calculate
			for(int i=n-1;i>0;i--){
				if(prm[i]){small = i; break;}
			}
			for(int i=n+1;i<MAX;i++){
				if(prm[i]){large = i; break;}
			}
			
			//output
			System.out.println(small + " " + large);
		}
	}

	//Creation of a prime number table.
	private static void init(){
		for(int i=0;i<MAX;i++){prm[i] = true;}
		prm[0] = false;
		prm[1] = false;
		for(int i=4;i<MAX;i+=2){prm[i] = false;}
		for(int i=3;i<MAX;i+=2){
			if(!prm[i]){continue;}
			for(int k=i*2;k<MAX;k+=i){
				prm[k] = false;
			}
		}
	}
}

Measured memory_bytes: 20052
object Main extends App {
  import scala.io.StdIn._
  implicit val timeOrdering = TimeOrdering
  val firstLine = readLine.trim.split(' ').map(_.toInt)
  val secondLine = readLine.trim.split(' ').map(_.toInt)
  val times = (0 until firstLine.head).map(i ⇒ Time(firstLine(i * 2 + 1), firstLine(i * 2 + 2))) ++ (0 until secondLine.head).map(i ⇒ Time(secondLine(i * 2 + 1), secondLine(i * 2 + 2)))
  println(times.distinct.sorted.mkString(" "))

  object TimeOrdering extends Ordering[Time] {
    override def compare(x: Time, y: Time): Int = if (x.hour == y.hour) x.minute.compare(y.minute) else x.hour.compare(y.hour)
  }
}
case class Time(hour: Int, minute: Int) {
  override def toString: String = f"$hour:$minute%02d"
}


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

string s;

void input() {
    cin >> s;
//    cout << s;
}

void solve() {
    int n = s.size();
    vector<int> v(n), result(n);
    int count = 1;
    for(int i = 0; i < n-1; i++ ){
        if(s.at(i) == 'R') {
            if(s.at(i+1) == 'R') {
                count++;
            } else {
                v.at(i) = count;
                count = 1;
            }
        }
    }
    count = 1;
    for(int i = n-1; i > 0; i-- ){
        if(s.at(i) == 'L') {
            if(s.at(i-1) == 'L') {
                count++;
            } else {
                v.at(i) = count;
                count = 1;
            }
        }
    }

    for(int i = 0; i < n; i++) {
        if (v.at(i) != 0 && s.at(i) == 'R') {
            if(v.at(i) % 2 == 0) {
                result.at(i) += v.at(i) / 2;
                result.at(i+1) += v.at(i) / 2;
            } else {
                result.at(i) += v.at(i) /2 + 1;
                result.at(i+1) += v.at(i) / 2;
            }
        }
    }
    for(int i = n-1; i > 0; i--) {
        if (v.at(i) != 0 && s.at(i) == 'L') {
            if(v.at(i) % 2 == 0) {
                result.at(i) += v.at(i) / 2;
                result.at(i-1) += v.at(i) / 2;
            } else {
                result.at(i) += v.at(i) /2 + 1;
                result.at(i-1) += v.at(i) / 2;
            }
        }
    }

    for(int e: result) {
        cout << e << endl;
    }

}



int main() {
    input();
    solve();

}


Measured memory_bytes: 1408
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
inf = float('inf')
ninf = -float('inf')
 
#整数input
def ii(): return int(sys.stdin.readline().rstrip()) #int(input())
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) #list(map(int,input().split()))
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]
#文字列input
def ss(): return sys.stdin.readline().rstrip() #input()
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) #list(input().split())
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]

#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？


n=list(ss())

if int(n[-1]) in [2,4,5,7,9]:
    print("hon")
elif int(n[-1]) in [0,1,6,8]:
    print("pon")
else:
    print("bon")



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

int main() {
	vector<int> ABCDE(5);
	for (int& i : ABCDE) cin >> i;
	sort(ABCDE.begin(), ABCDE.end(), [](int& a, int& b)->bool { return a % 10 && a % 10 < b % 10 && b % 10; });
	int ans = ABCDE[0];
	for (int i = 1; i < 5; ++i) {
		if (ABCDE[i] % 10) ans += ABCDE[i] + 10 - ABCDE[i] % 10;
		else ans += ABCDE[i];
	}
	cout << ans;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    string s,t;
    cin>>s>>t;
    int a=s.size(),ans=0;
    for(int i=0;a>i;++i){
        if(s.at(i)==t.at(i))
        ++ans;
    }
    if(ans==a)
    cout<<"Yes"<<endl;
    else
    {
        cout<<"No"<<endl;
    }
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0; i<n; i++)
typedef long long ll;
typedef long long unsigned int llu;
ll mod = 1000000007;
ll INF = 1000000009;

void solve(){
    string s;
    cin >> s;
    reverse(s.begin(),s.end());
    string ans="YES";
    while(s.size()!=0){
        if(s.substr(0,5)=="maerd") s = s.substr(5);
        else if(s.substr(0,7)=="remaerd") s = s.substr(7);
        else if(s.substr(0,5)=="esare") s = s.substr(5);
        else if(s.substr(0,6)=="resare") s = s.substr(6);
        else {
            ans = "NO";
            break;
        }
    }
    cout << ans << endl;
}

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


Measured memory_bytes: 512
x = int(input())
if x % 11 == 0:
    print((x // 11) * 2)
elif 6 < x and x < 11:
    print(2)
elif x <= 6:
    print(1)
else:
    if x % 11 > 6:
        print((x // 11) * 2 + 2)
    else:
        print((x // 11) * 2 + 1)

Measured memory_bytes: 3060
#include<cstdio>
#include<cmath>
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
    int N,K;
    cin>>N>>K;
    long long int lis[11][2003],lissize[11]={0};
    for(int i=0;i<11;i++){
        for(int j=1;j<2003;j++)lis[i][j]=-2000000000;
    }
    for(int i=0;i<N;i++){
        int a,b;
        cin>>a>>b;
        lis[b][lissize[b]+1]=a;
        lissize[b]++;
    }
    for(int i=0;i<11;i++){
        sort(lis[i]+1,lis[i]+2003);
        reverse(lis[i]+1,lis[i]+2003);
    }
    for(int i=0;i<11;i++){
        for(int j=1;j<2003;j++)lis[i][j]+=lis[i][j-1]+(j-1)*2;
    }
    /*
    for(int i=0;i<10;i++){
        for(int j=0;j<10;j++){
            if(0<=lis[i][j])printf("[%lld]",lis[i][j]);
        }
        puts("");
    }
    */
    long long int fie[13][4003]={0};
    for(int i=0;i<10;i++){
        for(int j=0;j<2001;j++){
            for(int k=0;k<2001;k++){
                if(j+k<=2000)fie[i+1][j+k]=max(fie[i+1][j+k],fie[i][j]+lis[i+1][k]);
            }
        }
    }
    cout<<fie[10][K]<<endl;
    return 0;
}

Measured memory_bytes: 1744
#include <iostream>
#include <map>
#include <set>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <fstream>
#include <bitset>
#include <queue>
#include <stack>
#include <deque>
#include <complex>
#include <iomanip>
#include <stdio.h>
#include <string.h>
#include <random>
#include <functional>

using namespace std;

#define F(i, n) for (int (i) = 0; (i) != (n); (i)++)
#define fi first
#define se second
#define re return
#define all(x) (x).begin(), (x).end()
#define NAME ""
#define int long long

const long long MOD = 1e9 + 7;
long long inq(long long a, long long b)
{
    if (b == 0) return 1;
    long long l = inq(a, b / 2);
    if (b % 2) return l * l % MOD * a % MOD;
    return l * l % MOD;
}

long long n;
string s[500000];
int x[500000];
string a;

signed main()
{
    cin >> n;
    for (int i = 0; i < n; i++)
        cin >> s[i] >> x[i];
    cin >> a;
    int ans = 0;
    for (int i = n - 1; i >= 0; i--)
    {
        if (s[i] == a) break;
        ans += x[i];
    }
    cout << ans;
}


Measured memory_bytes: 6144
N,M,K = map(int,input().split())
MOD = 998244353

MAXN = N+5
fac = [1,1] + [0]*MAXN
finv = [1,1] + [0]*MAXN
inv = [0,1] + [0]*MAXN
for i in range(2,MAXN+2):
    fac[i] = fac[i-1] * i % MOD
    inv[i] = -inv[MOD%i] * (MOD // i) % MOD
    finv[i] = finv[i-1] * inv[i] % MOD

def comb(n,r):
    if n < r: return 0
    if n < 0 or r < 0: return 0
    return fac[n] * (finv[r] * finv[n-r] % MOD) % MOD

ans = 0
for i in range(K+1):
    if i==N: break
    n = N-i
    ans += M * pow(M-1,n-1,MOD) * comb(N-1,i)
    ans %= MOD
print(ans)

Measured memory_bytes: 34104
import bisect
A, B, Q = map(int, input().split())
INF = 10 ** 18
s = [-INF] + [int(input()) for i in range(A)] + [INF]
t = [-INF] + [int(input()) for i in range(B)] + [INF]
for q in range(Q):
    x = int(input())
    b, d = bisect.bisect_right(s, x), bisect.bisect_right(t, x)
    res = INF
    for S in [s[b - 1], s[b]]:
        for T in [t[d - 1], t[d]]:
            d1, d2 = abs(S - x) + abs(T - S), abs(T - x) + abs(S - T)
            res = min(res, d1, d2)
    print(res)

Measured memory_bytes: 12812
#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() {
  int k;
  cin >> k;
  vector<int> vec;
  vec = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  cout << vec.at(k-1) << endl;
  return 0;
}

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

int N, X[1 << 18], Y[1 << 18];
char D[1 << 18];

void Rotate(){
    for(int i = 1; i <= N; i++){
        int cx = Y[i], cy = 200000 - X[i], cz;
        if(D[i] == 'U') cz = 'R';
        if(D[i] == 'R') cz = 'D';
        if(D[i] == 'D') cz = 'L';
        if(D[i] == 'L') cz = 'U';
        X[i] = cx;
        Y[i] = cy;
        D[i] = cz;
    }
}

vector<pair<int, char>> V1[1 << 19];
vector<pair<int, char>> V2[1 << 19];

int solve_01() {
	int Answer = (1 << 24);
	for (int i = 0; i <= 500000; i++) V1[i].clear();
	for (int i = 1; i <= N; i++) {
		if (!(D[i] == 'R' || D[i] == 'U')) continue;
		V1[X[i] + Y[i]].push_back(make_pair(X[i], D[i]));
	}
	for (int i = 0; i <= 500000; i++) {
		sort(V1[i].begin(), V1[i].end());
		for (int j = 0; j < (int)V1[i].size() - 1; j++) {
			if (!(V1[i][j].second == 'R' && V1[i][j + 1].second == 'U')) continue;
			Answer = min(Answer, V1[i][j + 1].first - V1[i][j].first);
		}
	}
	return Answer * 10;
}
 
int solve_02() {
	int Answer = (1 << 24);
	for (int i = 0; i <= 500000; i++) V2[i].clear();
	for (int i = 1; i <= N; i++) {
		if (!(D[i] == 'L' || D[i] == 'R')) continue;
		V2[Y[i]].push_back(make_pair(X[i], D[i]));
	}
	for (int i = 0; i <= 500000; i++) {
		sort(V2[i].begin(), V2[i].end());
		for (int j = 0; j < (int)V2[i].size() - 1; j++) {
			if (!(V2[i][j].second == 'R' && V2[i][j + 1].second == 'L')) continue;
			Answer = min(Answer, V2[i][j + 1].first - V2[i][j].first);
		}
	}
	return Answer * 5;
}

int main(){
    cin >> N;
	for (int i = 1; i <= N; i++) cin >> X[i] >> Y[i] >> D[i];
 
	int FinalAns = (1 << 24);
	for (int t = 1; t <= 4; t++) {
		int val1 = solve_01(); FinalAns = min(FinalAns, val1);
		int val2 = solve_02(); FinalAns = min(FinalAns, val2);
		Rotate();
	}
	if (FinalAns == (1 << 24)) cout << "SAFE" << endl;
	else cout << FinalAns << endl;
    return 0;
}

Measured memory_bytes: 42648
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main(){
    int n,k; cin>>n>>k;
    int A[n];
    for(int i=0;i<n;i++) cin>>A[i];
    int dp[n]={0};
    dp[1]=abs(A[1]-A[0]);
    for(int i=2;i<n;i++){
        dp[i]=INT_MAX;
        int ans=INT_MAX;
        for(int j=1;j<=k && i-j>=0;j++){
            ans=min(ans,dp[i-j]+abs(A[i]-A[i-j]));
        }
        dp[i]=min(dp[i],ans);
    }
    cout<<dp[n-1];
}

Measured memory_bytes: 4372
n,m=map(int,input().split())
l=[list(map(int,input().split())) for i in range(m)]
nums=[x+1 for x in range(n)]
ans=0
r=[0,100000]
for i in l:
  r[0]=max(r[0],i[0])
  r[1]=min(r[1],i[1])
for i in nums:
  if(r[0]<=i<=r[1]):
    ans+=1
print(ans)

Measured memory_bytes: 31460
#include <bits/stdc++.h>
using namespace std;
using ll = long long; // ll は long long　と同じとする。
int main() {
    int N;
    cin >> N;
    vector <int> H(N);
    int sum = 0;
    int num = 0;
    for(int i = 0; i < N; i++){
        cin >> H.at(i);
        sum += abs(num - H.at(i));
        num = H.at(i);
    }
    sum += num;
    cout << sum / 2 << endl;

}


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

int main() {
  int n;
  
  cin >> n;
  if(n/1000 == (n%1000)/100) {
    if(n/1000 == (n%100)/10) {
      cout << "Yes" << endl;
    }else {
      cout << "No" << endl;
    }
  }else{
    if((n%1000)/100 == (n%100)/10) {
      if((n%100)/10 == n%10) {
        cout << "Yes" << endl;
      }else {
        cout << "No" << endl;
      }
    }else {
      cout << "No" << endl;
    }
  }
}

Measured memory_bytes: 256
open System 
open System.Text

type Explicit =          
    static member inline ($) (_:int32, _:Explicit) = int
    static member inline ($) (_:int64, _:Explicit) = int64

let inline convert (value:'a): 'b = 
    (Unchecked.defaultof<'b> $ Unchecked.defaultof<Explicit>) value

let inline fromInt (x: int): 'a = convert x

module NumericLiteralG =
    let inline FromZero(): 'a = LanguagePrimitives.GenericZero
    let inline FromOne(): 'a = LanguagePrimitives.GenericOne
    let inline FromInt32 (n: int): 'a = fromInt n

let R() = Console.ReadLine()



let f (x: int): int =
    let g n = let t = string n in t.[0], t.[t.Length - 1]
    let g' n = let t = string n in t.[t.Length - 1], t.[0]
    let m = 
        [ for i in 1 .. x do g i ]
        |> List.groupBy id 
        |> List.map (fun (k, v) -> k, List.length v)
        |> Map.ofList
    [ for i in 1 .. x do g' i ]
    |> List.sumBy(fun t -> 
        match Map.tryFind t m with 
        | Some v -> v 
        | _ -> 0)

let N = int <| R()

f N 
|> printfn "%i"

Measured memory_bytes: 74328
#bit全探索
#解説AC

H, W, K = map(int, input().split())
C = [list(map(str, input())) for _ in range(H)]

ans = 0
#1<<n : 2^n
for i in range(1<<H):
    for j in range(1<<W):
      cnt = 0
      for h in range(H):
        for w in range(W):
          #1>>n : 下からn桁目(0 index)
          if (i>>h & 1): continue
          if (j>>w & 1): continue
          cnt += C[h][w] == '#'

      if cnt == K: ans += 1
print(ans)

Measured memory_bytes: 9188
#pragma GCC optimize("O3")

#define _GLIBCXX_DEBUG
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <cassert>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
using namespace std;

/*----------macros----------*/

//output================
#define endl '\n'
#define fcout cout << fixed << setprecision(15)

//typedef===============
typedef long long       ll;
typedef long double     ld;
typedef pair<int, int>  Pii;
typedef pair<ll, ll>    Pll;

//const number==========
constexpr ll INF9   = (ll)1e9 + 1;
constexpr ll INF18  = (ll)1e18 + 1;
constexpr ll MOD    = 1000000007;
constexpr ld PI     = 3.141592653589793L;

//member================
#define pb push_back
#define eb emplace_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second

//others================
#define all(x)          (x).begin(), (x).end()
#define rall(x)         (x).rbegin(), (x).rend()
#define rep(i, n)       for(int i = 0; (i) < (n); ++(i))
#define reps(i, n)       for(int i = 1; (i) <= (n); ++(i))
#define rrep(i, n)      for(int i = n - 1; (i) >= 0 ; --(i))
#define CtoI(c)         int((c)) - int('0')
#define ItoC(c)         char((c) + '0')

//functions=============
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }

template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

//vector<int> dx = {1, 0, -1, 0}, dy = {0, 1, 0, -1};
//vector<int> dx2 = { 1,1,0,-1,-1,-1,0,1 }, dy2 = { 0,1,1,1,0,-1,-1,-1 };

/*--------additional--------*/

enum{
    SUN = 7,
    MON = 6,
    TUE = 5,
    WED = 4,
    THU = 3,
    FRI = 2,
    SAT = 1
};

/*----------main------------*/

int main() {
/*----------fastio----------*/
    std::cin.tie(nullptr);
    std::cout.tie(nullptr);
    std::ios::sync_with_stdio(false);
/*----------solve-----------*/

    string s; cin >> s;
    if(s == "SUN"){
        cout << SUN << endl;
        return 0;
    }
    if(s == "MON"){
        cout << MON << endl;
        return 0;
    }
    if(s == "TUE"){
        cout << TUE << endl;
        return 0;
    }
    if(s == "WED"){
        cout << WED << endl;
        return 0;
    }
    if(s == "THU"){
        cout << THU << endl;
        return 0;
    }
    if(s == "FRI"){
        cout << FRI << endl;
        return 0;
    }
    if(s == "SAT"){
        cout << SAT << endl;
        return 0;
    }

return 0;
}

Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
int two,one;
int dp[100005];
int fun(int a[],int i,int n)
{if(i==n-1)return 0;
 if(i>=n)return INT_MAX;
 if(dp[i]!=-1)return dp[i];
 one=abs(a[i]-a[i+1])+fun(a,i+1,n);
 two=INT_MAX;
 if(i+2<n)
    two=abs(a[i]-a[i+2])+fun(a,i+2,n);
 return dp[i]=min(one,two);
}
int main()
{
int n;cin>>n;
  int a[n];
  memset(dp,-1,sizeof dp);
  for(int i=0;i<n;i++)cin>>a[i];
  cout<<fun(a,0,n);
  return 0;
}


Measured memory_bytes: 8832
def nasu(N):
  ans = 0
  i = 0
  while i < len(N):
    t = N[i]
    if t < 5 or (t == 5 and i == len(N) - 1) or (t == 5 and N[i + 1] <= 4):
      ans += t
      i += 1
    else:
      ans += 1
      ans += 9 - t
      i += 1
      while i < len(N):
        t = N[i]
        if t < 4 or (t == 4 and i == len(N) - 1) or (t == 4 and N[i + 1] <= 4):
          ans += 1
          break
        else:
          ans += 9 - t
          i += 1
      else:
        ans += 1

  return ans


N = list(map(int, list(input())))

print(nasu(N))

exit()
for i in range(500, 600):
  N = list(map(int, list(str(i))))
  print(i, nasu(N))

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

const int N = 100005;

int n;
int a[N];

int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    scanf("%d", a + i);
  }
  
  if (n % 3 > 0) {
    for (int i = 0; i < n; ++i) if (a[i] != 0) return 0 * printf("No\n");
    return 0 * printf("Yes\n");
  }
  
  sort(a, a + n);
  
  for (int i = n/3 * 0 + 1; i < n/3 * 1; ++i) if (a[i] != a[i-1]) return 0 * printf("No\n");
  for (int i = n/3 * 1 + 1; i < n/3 * 2; ++i) if (a[i] != a[i-1]) return 0 * printf("No\n");
  for (int i = n/3 * 2 + 1; i < n/3 * 3; ++i) if (a[i] != a[i-1]) return 0 * printf("No\n");
  
  if ((a[0] ^ a[n/3]) == a[n/3 * 2] || (a[0] ^ a[n/3 * 2]) == a[n/3] || (a[n/3] ^ a[n/3 * 2]) == a[0]) {
    printf("Yes\n");
  } else printf("No\n");
  
  return 0;
}


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

int sum_digit(int n)
{
  int sum_n = 0;

  while (n != 0)
  {
    sum_n += n % 10;
    n /= 10;
  }
  return (sum_n);
}

int main()
{
  int N, temp;
  int ans = 100000;

  cin >> N;
  for (int i = 1; i < N; i++)
  {
    temp = sum_digit(i);
    temp += sum_digit(N - i);
    ans = min(temp, ans);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main{
  public static void main(String[] args){
    
    Scanner sn = new Scanner(System.in);
    
    String a = sn.next();
    String b = sn.next();
    String c = sn.next();
    
    String ans = a.substring(0,1) + b.substring(0,1) + c.substring(0,1);
    
    System.out.println(ans);
    
  }
}

Measured memory_bytes: 21716
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main(void){
  string s, t;
  int ans, k;
  while(cin >> s >> t){
    ans = 0;
    for(int i = 0;i < s.size(); i++){
      for(int j = 0;j < t.size(); j++){
	if((i != 0 && j != 0 && s[i - 1] != t[j - 1] && s[i] == t[j]) || i == 0 || j == 0){
	  for(k = 0;i + k < s.size() && j + k < t.size() && s[i + k] == t[j + k]; k++) ;
	  ans = max(ans, k);
	}
      }
    }
    cout << ans << endl;
  }
}


Measured memory_bytes: 1208
#include<iostream>
#include<string>
#include <vector>
#include<stack>
#include<queue>
#include<map>
#include<algorithm>
#include<iomanip>
#include<cmath>
#include<bitset>
using namespace std;
using vi = vector<int>;
using vii = vector<vi>;
using vs = vector<string>;
using pii = pair<int, int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep2(i,m,n) for(int i=m;i<n;i++)
#define vsort(v) sort(v.begin(), v.end())
#define rv(v) reverse(v.begin(), v.end())
#define ll long long
#define PI 3.141592653589793
using vll = vector<ll>;
using Graph = vii;
const ll MOD = 1e9 + 7;

int main() {
	int n;
	string s;
	cin >> n;
	cin >> s;
	int cnt = 0;
	rep(i, n - 2) {
		if (s[i] == 'A' && s[i + 1] == 'B' && s[i + 2] == 'C') cnt++;
	}
	cout << cnt << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int main() {
    int n;
    int a, b;
    cin >> n;
    cin >> a >> b;
    // cout << abs(a-b) + 1;
    // if((abs(a-b) + 1 )/ n >=1) {
    //     cout << "OK";
    // } else 
    // {
    //     cout << "NG";
    // }
    for(int i = a; i<=b; i++) {
        if(i%n == 0){
            cout << "OK";
            exit(0);
        }
    }
    cout << "NG";
}

Measured memory_bytes: 3640
#include <iostream>
#include <algorithm>
#include <cstring>
#include <stack>
#include <utility>

using namespace std;

typedef long long ll;
typedef pair <int, int> pii;

int uf[100000];
ll mx;

int root(int i) { return (uf[i] < 0 ? i : uf[i] = root(uf[i])); }
void merge(int i, int j) {
    if((i = root(i)) == (j = root(j))) return ;
    if(uf[i] < uf[j]) swap(i, j);
    mx -= (ll) uf[i] * uf[j];
    uf[j] += uf[i];
    uf[i] = j;
    return ;
}

int main() {
    int n, k; cin >> n >> k;
    for(int i = 0; i < n; ++i)
        uf[i] = -1;
    mx = (ll) n * (n - 1) >> 1;
    stack <pii> box;
    stack <ll> res;

    int u, v;
    while(k--) {
        cin >> u >> v;
        box.emplace(u - 1, v - 1);
    }

    while(!box.empty()) {
        res.push(mx);
        merge(box.top().first, box.top().second);
        box.pop();
    }

    while(!res.empty()) {
        cout << res.top() << '\n';
        res.pop();
    }
    
    return 0;
}


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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void Main() {
    ll H, W, h, w; cin >> H >> W >> h >> w;
    cout << (H - h) * (W - w) << endl;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 3616
#include <iostream>
#include <string>
#include <queue>
#include <cmath>
using namespace std;
 
#define MAX 20
bool is_wall[MAX][MAX];
int is_dirty[MAX][MAX];

#define BIT_MAX (1 << 10)
#define INF 1e8
int smallest_time[MAX][MAX][BIT_MAX];

#define DIRS 4
int dx[DIRS] = {-1, 0, 0, 1};
int dy[DIRS] = { 0,-1, 1, 0};

bool is_ok(int x, int y, int w, int h){
  return 0 <= x && x < w && 0 <= y && y < h;
}

int main() {
  
  int w, h;
  
  while(cin >> w >> h, w || h ) {
    int start_x = -1, start_y = -1;
    int dirtys = 0;
    
    for(int i = 0; i < h; i++){
      string line;
      cin >> line;
      
      for(int j = 0; j < w; j++){
	is_wall[i][j] = false;
	is_dirty[i][j] = -1;
	for(int k = 0; k < BIT_MAX; k++){
	  smallest_time[i][j][k] = INF;
	}
	
	if(line[j] == 'x'){
	  is_wall[i][j] = true;
	}else if(line[j] == '*'){
	  is_dirty[i][j] = dirtys++;
	}else if(line[j] == 'o'){
	  start_x = j;
	  start_y = i;
	}
      }
    }
    
    queue<int> xq, yq, bq;
    xq.push(start_x);
    yq.push(start_y);
    bq.push(0);
    smallest_time[start_y][start_x][0] = 0;
    
    bool answered = false;
    while(!bq.empty()){
      const int x    = xq.front(); xq.pop();
      const int y    = yq.front(); yq.pop();
      const int bit  = bq.front(); bq.pop();
      const int time = smallest_time[y][x][bit];
      
      if(bit == (1 << dirtys) - 1){
	answered = true;
	cout << time << endl;
	break;
      }
      
      for(int dir = 0; dir < DIRS; dir++){
	const int nx = x + dx[dir];
	const int ny = y + dy[dir];
	const int n_time = time + 1;
	
	if(!is_ok(nx, ny, w, h)){
	  continue;
	}else if(is_wall[ny][nx]){
	  continue;
	}
	
	const int n_bit = bit | (is_dirty[ny][nx] < 0 ? 0 : (1 << is_dirty[ny][nx]));
	
	if(n_time >= smallest_time[ny][nx][n_bit]){
	  continue;
	}
	
	smallest_time[ny][nx][n_bit] = n_time;
	xq.push(nx);
	yq.push(ny);
	bq.push(n_bit);
      }
    }
    
    if(!answered){
      cout << -1 << endl;
    }
  }
  
  return 0;  
}

Measured memory_bytes: 2924
#include <bits/stdc++.h>
using namespace std;
int main(){
	int sum=0,m,n,a[10001],i;
	cin>>n>>m;
	for(i=0;i<m;i++){
		cin>>a[i];
		sum+=a[i];
	}
	if(sum<=n)cout<<n-sum;
	else cout<<"-1";
    return 0;
}


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

int e[110000][2];
int f[110000];
int q[110000], q1, q2;
int root[110000];
int fc[110000];

int main()
{
  int n, m;
  scanf("%d%d", &n, &m);
  memset(f, 0, sizeof(f));
  memset(fc, 0, sizeof(f));
  for (int i = 1; i <= n + m - 1; ++i)
  {
    int a, b;
    scanf("%d%d", &a, &b);
    e[i][0] = b;
    e[i][1] = f[a];
    f[a] = i;
    ++fc[b];
  }
  int r;
  for (int i = 1; i <= n; ++i)
  {
    if (fc[i] == 0)
    {
      r = i;
      break;
    }
  }
  memset(root, 0, sizeof(root));
  q[0] = r;
  q1 = 0;
  q2 = 1;
  while (q1 < q2)
  {
    int x = q[q1++];
    for (int i = f[x]; i != 0; i = e[i][1])
    {
      if (--fc[e[i][0]] == 0)
      {
        root[e[i][0]] = x;
        q[q2++] = e[i][0];
      }
    }
  }
  for (int i = 1; i <= n; ++i)
  {
    printf("%d\n", root[i]);
  }
  return 0;
}

Measured memory_bytes: 3200