akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	vector<ll> c(n-1), s(n-1), f(n-1);
	rep(i,n-1) cin >> c[i] >> s[i] >> f[i];
	rep(i,n-1){
		ll time = 0;
		for(int j = i; j < n-1; ++j){
			chmax(time, s[j]);
			if(time%f[j] != 0) time = ((time + f[j] - 1) / f[j]) * f[j];
			time += c[j];
		}
		cout << time << endl;
	}
	cout << 0 << endl;
	return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
int main(){
  ll n;
  cin>> n;
  vll a(n);
  ll sum=0,count=0,min=1000000000;
  for (ll i=0;i<n;i++) {
    cin >> a[i];
    sum+=abs(a[i]);
    if (a[i]<0) {
      count++;
    }
    if (min>abs(a[i])) {
      min=abs(a[i]);
    }
  }
  
  ll ans;
  if (count%2==0) {
    ans=sum;
  }
  else {
    ans=sum-2*min;
  }
  
  cout << ans;
}

Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;

const int INF = 100000;

const int MAX_V = 15;
int d[MAX_V][MAX_V];
int V;

int dp[1 << MAX_V][MAX_V];

int solve(int S, int v)
{
  if(dp[S][v] >= 0) return dp[S][v];

  if(S == (1 << V) - 1 && v == 0) return dp[S][v] = 0;

  int ans = INF;
  for(int u = 0; u < V; u++)
    if(!(S >> u & 1))
      ans = min(ans, solve(S | 1 << u, u) + d[v][u]);

  return dp[S][v] = ans;
}

int main()
{
  int E;
  scanf("%d %d", &V, &E);

  fill(&d[0][0], &d[MAX_V][0], INF);
  for(int i = 0; i < E; i++){
    int s, t, c;
    scanf("%d %d %d", &s, &t, &c);
    d[s][t] = c;
  }

  fill(&dp[0][0], &dp[1 << MAX_V][0], -1);
  int ans = solve(0, 0);
  if(ans != INF)
    printf("%d\n", ans);
  else
    printf("-1\n");
}

Measured memory_bytes: 3112
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <memory.h>
#include <cassert>

using namespace std;


#define all(c) ((c).begin()), ((c).end())
#define debug(c) cerr << "> " << #c << " = " << (c) << endl;
#define iter(c) __typeof((c).begin())
#define present(c, e) ((c).find((e)) != (c).end())
#define cpresent(c, e) (find(all(c), (e)) != (c).end())
#define tr(i, c) for (iter(c) i = (c).begin(); i != (c).end(); i++)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, a, b) for (int i = (int)(a); i <= (int)(b); i++)

#define mp make_pair
#define fst first
#define snd second
#define pb push_back


const double EPS = 1e-10;


typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef complex<double> P;


bool check(vi a) {
	int n = a.size();
	rep (i, n) rep (j, n) if (i < j) if (a[i] == a[j]) {
		vi h(11, 0);
		rep (k, n) {
			h[a[k]]++;
			if (h[a[k]] == 5) return false;
		}
		h[a[i]] -= 2;
		rep (k, 9) {
			if (h[k + 1] >= 3) h[k + 1] -= 3;
			if (h[k + 1] <= 2) {
				if (k >= 8) continue;
				if (h[k + 1] >= 1 && h[k + 2] >= 1 && h[k + 3] >= 1) {
					h[k + 1]--;
					h[k + 2]--;
					h[k + 3]--;
				}
			}
			if (h[k + 1] <= 1) {
				if (k >= 8) continue;
				if (h[k + 1] >= 1 && h[k + 2] >= 1 && h[k + 3] >= 1) {
					h[k + 1]--;
					h[k + 2]--;
					h[k + 3]--;
				}
			}
		}
		bool ok = true;
		rep(i, 9) ok &= (h[i + 1] == 0);
		if (ok) return true;
	}
	return false;
}

int main() {
	for (string s; cin >> s; ) {
		vi a;
		rep(i, 13) a.pb(s[i] - '0');
		vi ans;
		rep (i, 9) {
			vi b = a;
			b.pb(i + 1);
			sort(all(b));
			if (check(b)) ans.pb(i + 1);
		}
		if (ans.size() == 0) cout << 0 << endl;
		else {
			rep (i, ans.size()) {
				if (i == ans.size() - 1) cout << ans[i] << endl;
				else cout << ans[i] << ' ';
			}
		}
	}
	
	return 0;
}

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

const int N = 100050;

int main() {
  int n, a, ans = 0, num = 0;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a);
    if ( i == a ) num++;
    else {
      ans += ( num + 1 ) / 2;
      num = 0;
    }
  }
  printf("%d\n", ans + ( num + 1 ) / 2 );
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(){
	int S,h,m,s;
	scanf("%d",&S);

	h = S / 3600;
	m = (S - h * 3600) / 60;
	s = S % 60;
	printf("%d:%d:%d\n",h,m,s);

	return 0;
}


Measured memory_bytes: 2120
from collections import Counter
def min_distance(i,j):
    return min(abs(i-j),abs(x-i)+1+abs(y-j),abs(y-i)+1+abs(x-j))
               
n,x,y=list(map(int,input().split()))
x=x-1
y=y-1
dp=[]
for i in range(n-1):
    for j in range(i+1,n):
        dp.append(min_distance(i,j))
dic=Counter(dp)
for i in range(1,n):
    print(int(dic[i]))
    
        
     
    
    

Measured memory_bytes: 67824
// B.

#include <iostream>

using namespace std;

int main(int argc, char *argv[]) {
	int n, m, k, r;
	cin >> n >> m >> k;
	bool ans = false;
	for (int i = 0; i <= n; ++i) {
		r = i * m;
		if (r == k) {
			ans = true;
		}
		for (int j = 0; j < m; ++j) {
			r += (-i + (n - i));
			if (r == k) {
				ans = true;
			}
		}
	}
	cout << (ans ? "Yes" : "No") << endl;
	return 0;
}


Measured memory_bytes: 256
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
        }

        public void Solve(ConsoleInput cin)
        {
            long N = cin.ReadLong;
            var v = cin.ReadDoubleArray(N);
            Array.Sort(v);
            double ans = (v[0]+v[1])/2;
            for(int i = 2; i < N; i++)
            {
                ans = (ans + v[i]) / 2;
            }
            Console.WriteLine(ans);
        }
            

                
    }  
            


    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); } }
        public int ReadInt { get { return int.Parse(Read); } }
        public long ReadLong { get { return long.Parse(Read); } }
        public double ReadDouble { get { return double.Parse(Read); } }
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
        public double[] ReadDoubleArray(long N) { var ret = new double[N]; for (long i = 0; i < N; ++i) ret[i] = ReadDouble; return ret; }
    }
}


Measured memory_bytes: 13524
#include<iostream>
#include<math.h>
using namespace std;

int main() {
  int N,L,taste,apple,pie;
  pie = 0;
  cin >> N >> L;
  taste = L + 1 -1;
  apple = 1;

  for(int i = 2;i <= N;++i){
    if(abs(taste) > abs(L + i - 1)){
      apple = i;
      taste = L + i - 1;
    }
  }
  for(int i = 1;i <= N;i++){
    if(apple != i){

      pie = pie + L + i - 1;
    }
  }
  cout << pie << endl;
  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
#define rep(i,n) for (int i=0; i<n;++i)
using namespace std;

map<pair<int, int>, int> ansMap;
int N, K, L;
int a_par[200003]; //親
int b_par[200003]; //木の深さ

// n要素で初期化
void init(int n){
  rep(i, n){
    a_par[i] = i;
    b_par[i] = i;
  }
}

// 木の根を求める
int find(int* c, int x){ 
  if (c[x] == x) return x;
  else return c[x] = find(c, c[x]);
}

// xとyの属する集合を併合
void unite(int* c, int x, int y){
  int root_x = find(c, x);
  int root_y = find(c, y);
  if (root_x == root_y) return;
  c[root_x] = root_y;
}

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

  cin >> N >> K >> L;
  int p,q,r,s;
  init(N);
  rep(i, K){
    cin >> p >> q;
    unite(a_par, p-1, q-1);
  }

  rep(i, L){
    cin >> r >> s;
    unite(b_par, r-1, s-1);
  }

  pair<int, int> P[N];
  rep(i, N){
    pair<int, int> p(find(a_par, i), find(b_par, i));
    P[i] = p;
    ansMap[p]++;
  }

  rep(i, N){
    if (i==N-1){
      cout << ansMap[P[i]] << endl;
      break;  
    }
    cout << ansMap[P[i]] << ' ';
  } 
  
  return 0;
}

Measured memory_bytes: 15104
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<set>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0; i<n; ++i)

int main()
{
	int k; cin >> k;
	int m = 0, ans = 0;
	set<int> s;
	while (1) {
		++ans;
		m = m * 10 + 7;
		m = m % k;
		if (!m) break;
		auto p = s.insert(m);
		if (!p.second) {
			cout << -1 << endl;
			return 0;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 49980
import sys
import heapq
from operator import itemgetter
 
MAX_INT = int(10e15)
MIN_INT = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

N,K = IL()
p = N - N//K*K

print(min(p, abs(K-p)))

Measured memory_bytes: 38256
#include <iostream>
#include <string>
using namespace std;

int main(void){
    string s;
    cin >> s;
    int count = 0;
    int check = 0;
    while(s.length() > 0){
        s.pop_back();
        // cout << 's' << endl;
        if(s.length() % 2 == 0){
            count = 0;
        for(int j = 0; j < s.length()/2; j++){
            if(s[j] == s[s.length()/2 + j])
                count++;
        }
        }
        if(count*2 == s.length()){
            cout << count*2 << endl;
            break;
        }

        if(s.length() == 0)
            cout << '0' << endl;
    }
    

    return 0;
}

Measured memory_bytes: 256
from collections import defaultdict as dd
from collections import deque
import bisect
import heapq

def ri():
    return int(input())

def rl():
    return list(map(int, input().split()))

def T(i):
    return i * (i + 1) // 2


def solve():
    # n log n : sieving
    # n = ri()
    # sieve = [1] * (n + 1)
    # ans = 1
    # for p in range(2, n + 1):
        # for q in range(p, n + 1, p):
            # sieve[q] += 1
        # ans += p * sieve[p]
    # print (ans)

    # summing with floor n / i technique
    # O(sqrt n)
    n = ri()
    if n in [1,2,3]:
        print ({1:1, 2:5, 3:11}[n])
        return

    sq = int(n**0.5)
    ans = 0
    for i in range(1, sq + 1):
        # print (i, i * T(n // i), T(i) * (T(n // i) - T(n // (i + 1))))
        ans += i * T(n // i)
        ans += T(i) * (T(n // i) - T(n // (i + 1)))

    if sq * (sq + 1) > n:
        ans -= sq * T(n // sq)
    print (ans)





mode = 's'

if mode == 'T':
    t = ri()
    for i in range(t):
        solve()
else:
    solve()


Measured memory_bytes: 69756
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cassert>
#include <cstdint>
#include <iostream>
#include <iomanip>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <bitset>

using namespace std;

using ll =  long long;
using Pll = pair<ll, ll>;
using Pii = pair<int, int>;

constexpr ll MOD = 1000000007;
constexpr long double EPS = 1e-10;
constexpr int dyx[4][2] = {
    { 0, 1}, {-1, 0}, {0,-1}, {1, 0}
};

int main() {
    std::ios::sync_with_stdio(0); cin.tie(0);
    int n;
    cin >> n;
    vector<int> a(n);
    set<int> st;
    map<int, int> mp;
    for(int i=0;i<n;++i){
        cin >> a[i];
        ++mp[a[i]];
        st.insert(a[i]);
    }

    if(n % 3 == 0) {
        auto itr = st.begin();
        if(st.size() == 1) {    
            ll x = *itr;
            if(x == 0) {
                cout << "Yes" << endl;
                return 0;
            }
        } else if(st.size() == 2) {
            ll x = *itr; ++itr;
            ll y = *itr;
            if(x > y) swap(x, y);
            if(x == 0 && mp[x]*2 == mp[y]) {
                cout << "Yes" << endl;
                return 0;
            }
        } else if(st.size() == 3) {
            ll x = *itr; ++itr;
            ll y = *itr; ++itr;
            ll z = *itr;
            if((x^y) == z && mp[x] == mp[y] && mp[y] == mp[z]) {
                cout << "Yes" << endl;
                return 0;
            }
        }
    } else {
        if(mp[0] == n) {
            cout << "Yes" << endl;
            return 0;
        }
    }

    cout << "No" << endl;
        
    return 0;
}


Measured memory_bytes: 7808
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
sa=sum(a)
sb=sum(b)
if sb<sa:
  print("No")
  exit(0)
husoku_a=0
husoku_b=0
for aa,bb in zip(a,b):
  if bb<aa:
    husoku_a+=aa-bb
  elif bb>aa:
    husoku_b+=(bb-aa)//2

if husoku_a<=husoku_b:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 68588
import java.util.Scanner;

public class Main {
    public static Scanner sc;
    public static void main(String[] args) throws Exception {
        sc = new Scanner(System.in);
        String t = sc.next();
        String p = sc.next();
        StringBuilder sb;
        
        for (int i = 0; i <= t.length() - p.length(); i++) {
            boolean b = true;
            for (int j = 0; j < p.length(); j++) {
                if (t.charAt(i+j)!=p.charAt(j)) {
                    b = false;
                    break;
                }
            }
            if (b) {
                System.out.println(i);
            }
        }
    }
}

Measured memory_bytes: 26364
#include <algorithm>
#include <cassert>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <vector>
#include <list>
#include <queue>

using std::list;
using std::max;
using std::min;
using std::vector;

static const long long kInitialMoney = 100000ll * 100000ll * 100000ll;

class Edge {
  public:
    long long snuke;
    long long yen;
    int to;
};

class Node {
  public:
    size_t id;
    long long snuke;
    long long yen;
    long long total;
    list<Edge> edge;
    bool operator>(const Node& node) const;
    bool operator<(const Node& node) const;
    void compute_total();
};

bool Node::operator>(const Node& node) const
{
  return this->snuke > node.snuke;
}

bool Node::operator<(const Node& node) const
{
  return this->yen > node.yen;
}

void Node::compute_total()
{
  total = snuke + yen;
}

vector<Node> node;

bool largest_fisrt(const Node& a, const Node& b)
{
  return a.total > b.total;
}

bool smallest_first(const Node& a, const Node& b)
{
  return a.total < b.total;
}

void solve(int start, int goal)
{
  std::priority_queue<Node, vector<Node>, std::less<Node>> normal;
  std::priority_queue<Node, vector<Node>, std::greater<Node>> rev;
  node[start].yen = 0;
  normal.push(node[start]);
  while(!normal.empty()) {
    Node n = normal.top();
    normal.pop();
    for(const auto& e : n.edge) {
      if(n.yen + e.yen < node[e.to].yen) {
        node[e.to].yen = n.yen + e.yen;
        normal.push(node[e.to]);
      }
    }
  }

  node[goal].snuke = 0;
  rev.push(node[goal]);
  while(!rev.empty()) {
    Node n = rev.top();
    rev.pop();
    for(const auto& e : n.edge) {
      if(n.snuke + e.snuke < node[e.to].snuke) {
        node[e.to].snuke = n.snuke + e.snuke;
        rev.push(node[e.to]);
      }
    }
  }

  for(auto& x : node) {
    x.compute_total();
  }
  std::sort(node.begin()+1, node.end(), smallest_first);
}

void print_result()
{
  size_t index = 1;
  for(size_t i = 1; i < node.size(); i++) {
    while(node.at(index).id < i) {
      index++;
    }
    printf("%lld\n", kInitialMoney - node.at(index).total);
  }
}

int main()
{
  int ncity, nedge, start, goal;
  scanf("%d%d%d%d", &ncity, &nedge, &start, &goal);
  node.resize(ncity+1);
  for(int i = 1; i <= ncity; i++) {
    node.at(i).id = i;
    node.at(i).snuke = kInitialMoney + 1;
    node.at(i).yen   = kInitialMoney + 1;
    node.at(i).total = kInitialMoney + 1;
  }
  for(int i = 0; i < nedge; i++) {
    int u, v, a, b;
    Edge edge;
    scanf("%d%d%d%d", &u, &v, &a, &b);
    edge.yen = a;
    edge.snuke = b;
    edge.to = v;
    node[u].edge.push_back(edge);
    edge.to = u;
    node[v].edge.push_back(edge);
  }
  solve(start, goal);
  print_result();
  return 0;
}


Measured memory_bytes: 50724
h,n = map(int,input().split())
dp = [0]+[1000000000 for _ in range(h)]
for i in range(n):
    ai,bi = map(int,input().split())
    for j in range(h):
        dp[min(j+ai,h)] = min(dp[min(j+ai,h)],dp[j]+bi)
print(dp[h])

Measured memory_bytes: 44508
#include<bits/stdc++.h>
using namespace std;
#define lli long long int
#define rep(i,n) for(lli i=0;i<n;i++)
#define repb(i,n) for(lli i=n-1;i>=0;i--)
#define pb push_back
#define mp make_pair
#define bg() begin()
#define en() end()
#define ft first
#define sc second
#define vect_lli_it vector<lli>::iterator
#define set_lli_it set<lli>::iterator
#define inf 1e18
#define all(X) X.begin(),X.end()
#define iterate(X) for(it=X.begin();it!=X.end();it++)
#define pii pair<lli,lli>
#define vi vector <lli>
lli combi(lli n,lli k)
{
    lli ans=1;
    k=k>n-k?n-k:k;
    lli j=1;
    for(;j<=k;j++,n--)
    {
        if(n%j==0)
        {
            ans*=n/j;
        }else
        if(ans%j==0)
        {
            ans=ans/j*n;
        }else
        {
            ans=(ans*n)/j;
        }
    }
    return ans;
}
lli gcd(lli a, lli b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}
lli findlcm(vector <lli> arr, lli n)
{
    lli ans = arr[0];
    for (lli i = 1; i < n; i++)
        ans = (((arr[i] * ans)) /
                (gcd(arr[i], ans)));

    return ans;
}
lli power(lli x, lli y, lli p)
{
    lli res = 1;
    x = x % p;
    if (x == 0) return 0;
    while (y > 0)
    {
        if (y & 1)
            res = (res*x) % p;
        y = y>>1;
        x = (x*x) % p;
    }
    return res;
}
lli gcdExtended(lli a, lli b, lli *x, lli *y);
lli modInverse(lli b, lli m)
{
    lli x, y;
    lli g = gcdExtended(b, m, &x, &y);
    if (g != 1)
        return -1;
    return (x%m + m) % m;
}
lli modDivide(lli a, lli b, lli m)
{
    a = a % m;
    lli inv = modInverse(b, m);
    return (inv * a) % m;
}
lli gcdExtended(lli a, lli b, lli *x, lli *y)
{
    if (a == 0)
    {
        *x = 0, *y = 1;
        return b;
    }
    lli x1, y1;
    lli gcd = gcdExtended(b%a, a, &x1, &y1);
    *x = y1 - (b/a) * x1;
    *y = x1;
    return gcd;
}
int main(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    lli n;
    cin>>n;
    vector <lli> arr;
    lli x;
    rep(i,n){
    	cin>>x;
    	arr.pb(x);
	}
	sort(all(arr),greater<lli>());
	priority_queue <lli> pq;
	lli ans=0;
	rep(i,n){
		if(pq.size()>0){
			ans=ans+(pq.top());
			pq.pop();
			pq.push(arr[i]);
			pq.push(arr[i]);
		}
		else{
			pq.push(arr[i]);
		}
	}
	cout<<ans;
    return 0;
}


Measured memory_bytes: 7904
A,B = map(int, input().split())
ans=-1
for i in range(1250):
    if ans>0:
        break
    x=i*0.08
    x=int(x)
    if x==A:
        y=i*0.1
        y=int(y)
        if y==B:
            ans=i


if ans<0:
    print("-1")
else:
    print(ans)


Measured memory_bytes: 2940
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <numeric>
#include <regex>
using namespace std;

typedef long long ll;
#define modulo 1000000007 // 10^9 + 7
#define MAX 1000000000 // 10^9


int main() {
	string S;
	cin >> S;
	int l = S.size();
	string key("keyence");

	for (int i = 0; i < 7; i++) {
		string tmp;
		for (int j = 0; j < i; j++) tmp.push_back(S[j]);
		for (int j = l - 7 + i; j < l; j++) tmp.push_back(S[j]);
		if (tmp == key) {
			cout << "YES" << endl;
			return 0;
		}
	}

	cout << "NO" << endl;

	return 0;
}

Measured memory_bytes: 256
for e in iter(input,'0 0'):
 r,_=map(int,e.split())
 d=[int(''.join(x),2)for x in zip(*[input().split()for _ in[0]*r])]
 a=0
 for i in range(1<<r):
  b=0
  for j in d:
   c=bin(i^j).count('1')
   b+=c if c>r//2 else r-c
  a=max(a,b)
 print(a)


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

#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;

int main() {
    int n;
    cin >> n;
    vi a(n);
    rep(i,n) cin >> a[i];

    bool flag = true;

    rep(i,n){
        if(a[i]%2 == 1) continue;
        if(a[i]%3 != 0 && a[i]%5 != 0) flag = false;
    }

    cout << (flag == true ? "APPROVED" : "DENIED") << endl;
    return 0;
}

Measured memory_bytes: 256
using System;
class Program
 {
   static void Main(string[] args)
   {
     int n;
     n = int.Parse(Console.ReadLine());

     if(n<1200)
     {
       Console.WriteLine("ABC");
     }else if(n>=1200&&n<2800)
     {
       Console.WriteLine("ARC");
     }else
     {
       Console.WriteLine("AGC");
     }
   }
 }

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

int main() {

    string S;
    cin >> S;
    rep(i, S.size()) cout << "x";
    cout << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define endl "\n"
#define ll long long int
#define mod 1000000007

using namespace std;
int solve(){
	int a,b,c,k;
	cin>>a>>b>>c>>k;
	if(k<=(a)){
		return k;
	}
	if(k<=(a+b)){
		return a;
	}
	if(k<=(a+b+c)){
		k = k-a-b;
		return a-k;
	}
}
int main()
{
	// #ifndef ONLINE_JUDGE
	// freopen("input.txt","r",stdin);
	// freopen("output.txt","w",stdout);
	// #endif
	std::ios::sync_with_stdio(false);
	cout<<solve();
	return 0;
}

Measured memory_bytes: 3656
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <sstream>
#include <string>
#define _repargs(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _repargs(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define inf 2000000007
#define mp make_pair
#define pb push_back
typedef long long ll;
using namespace std;
template <typename T>
inline void output(T a, int p = 0) {
    if(p) cout << fixed << setprecision(p)  << a << "\n";
    else cout << a << "\n";
}
// end of template

string alp = "abcdefghijklmnopqrstu";

//void dfs(string s, int c, int d) {
//    if(d == 0) output(s);
//    else {
//        int i = 0;
//        while(c + 1 >= i) {
//            if(c + 1 == i) dfs(s + alp[i], c + 1, d - 1);
//            else dfs(s + alp[i], c, d - 1);
//        }
//    }
//}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    // source code
    
    int N;
    cin >> N;
    vector<pair<string, int>> A = {mp("", -1)};
    rep(i, N) {
        vector<pair<string, int>> B;
        rep(j, A.size()) {
            rep(k, A[j].second + 1) {
                B.pb(mp(A[j].first + alp[k], A[j].second));
            }
            B.pb(mp(A[j].first + alp[A[j].second + 1], A[j].second + 1));
        }
        A = B;
    }
    rep(i, A.size()) {
        output(A[i].first);
    }
    
    return 0;
}


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

long long n;
string s;

int main() {
  cin >> s >> n;
  for(int i = 0; i < n; ++i) {
    string t;
    int a, b;
    cin >> t >> a >> b;
    if(t == "print")
      cout << s.substr(a, b - a + 1) << endl;
    else if(t == "reverse")
      reverse(s.begin() + a, s.begin() + b + 1);
    else {
      string p;
      cin >> p;
      for(int i = 0; i < b - a + 1; ++i) s[a + i] = p[i];
    }
  }
  return 0;
}


Measured memory_bytes: 3208
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
#include<assert.h>
#include<bitset>
#include<stack>
#include<memory>
using namespace std;
typedef long long int llint;
typedef long double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
/*
cout<<setprecision(20);
cin.tie(0);
ios::sync_with_stdio(false);
*/
const llint mod=924844033;
const llint big=2.19e15+1;
const long double pai=3.141592653589793238462643383279502884197;
const long double eps=1e-15;
template <class T,class U>bool mineq(T& a,U b){if(a>b){a=b;return true;}return false;}
template <class T,class U>bool maxeq(T& a,U b){if(a<b){a=b;return true;}return false;}
llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);}
llint lcm(llint a,llint b){if(a==0){return b;}return a/gcd(a,b)*b;}
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());}
template<class T>llint LBI(vector<T>&ar,T in){return lower_bound(ar.begin(),ar.end(),in)-ar.begin();}
template<class T>llint UBI(vector<T>&ar,T in){return upper_bound(ar.begin(),ar.end(),in)-ar.begin();}
int main(void){
	cout<<setprecision(20);
	cin.tie(0);
	ios::sync_with_stdio(false);
	llint n,x,i,ans=0;cin>>n>>x;
	vector<llint>a(n);
	for(i=0;i<n;i++){cin>>a[i];}
	SO(a);
	for(i=0;i<n;i++){
		if(x>=a[i]){ans++;x-=a[i];}
	}
	if(ans==n&&x>0){ans--;}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 888
#include<bits/stdc++.h>
using namespace std;
int main(){
	int len;
	string s;
	cin>>s;
	len=s.length();
	int color=1;
	int ans=0,finalans=0;
	for(int i=0;i<len;i++)
	{
		if(s[i]-'0'!=color) finalans++;
		color^=1;
	}
	color=0;
	for(int i=0;i<len;i++)
	{
		if(s[i]-'0'!=color) ans++;
		color^=1;
	}
	printf("%d\n",min(ans,finalans));
	return 0;
}

Measured memory_bytes: 512
#include<map>
#include<iostream>
#include<deque>
#include<algorithm>
#include<string>
#include<cctype>
#include<iomanip>
#include<vector>
#include<queue>
#include<math.h>
#include<bitset>
#include<random>
#include<set>
using namespace std;
using ll = __int64_t;
using lll = __int128_t;
typedef pair<ll,ll> P;
#define REP(i,b,e) for(ll i=(ll)b;i<(ll)e;i++)
#define rep0(i,n) REP(i,0ll,n)
#define rep1(i,n) REP(i,1ll,n+1)
const ll longinf=1ll<<60;
const int inf=(1<<30)-1;
const ll mod=1e9+7;



int main(void){
      int n,k;
      cin>>n>>k;
      int p[n+1];
      rep0(i,n){
            cin>>p[i];
      }
      p[n]=-inf;
      int l=0;
      int r=0;
      int pos=0;
      int ans=1;
      rep0(i,n){
            if(p[i+1]>p[i]){
                  r++;
            }
            else{
                  if(r-l-k+2>0) pos++;
                  l=i+1;
                  r=i+1;
            }
      }
      if(pos>0) --pos;
      multiset<int> st;
      rep0(i,k) st.insert(p[i]);
      for(int i=k;i<n;i++){
            auto dd=*st.begin();
            bool ok=true;
            if(dd!=p[i-k]) ok=false;
            st.erase(p[i-k]);
            st.insert(p[i]);
            dd=*(--st.end());
            if(dd!=p[i]) ok=false;
            //cout<<ok<<endl;
            if(!ok) ans++;
      }
      cout<<ans-pos<<endl;
      return 0;
}

Measured memory_bytes: 10496
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin, log, log10, gcd
from itertools import permutations, combinations, product, accumulate, combinations_with_replacement
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
#from fractions import gcd
def debug(*args):
    if debugmode:
        print(*args)
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def FLOAT(): return float(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7
dx = [0, 1, 0, -1, 1, -1, -1, 1]
dy = [1, 0, -1, 0, 1, -1, 1, -1]
debugmode = True

n, k = MAP()
a = LIST()
arr = set([])
loop = []
i = 0
idx = 0
cnt = -1
flag = True
flag2 = True
strt = -1
while i < k:
    idx = a[idx] - 1
    i += 1
    l = len(arr)
    arr.add(idx)
    if l == len(arr) and flag:
        flag = False
        cnt = 1
        strt = idx
        loop.append(idx)
    elif not flag and idx == strt:
        flag2 = False
        break
    elif not flag:
        cnt += 1
        loop.append(idx)
    #debug(idx, loop)
#debug(arr, loop, cnt, flag, flag2)
if flag2:
    print(idx + 1)
else:
    print(loop[(k - i) % cnt] + 1)

Measured memory_bytes: 112320
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;


int main()
{
    int h, n;
    cin >> h >> n;
    vector<int> vec(n);
    REP(i, n) cin >> vec[i];
    cout << (accumulate(ALL(vec), 0) >= h ? "Yes" : "No") << endl;
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define forloop(n) for(int i = 0; i < n; i++)
int main(){
	int b; string a; cin>>b>>a;
	for(int i = 0; i < a.size(); i++){
		a[i] = 'A' + (a[i]-'A'+b)%('Z' - 'A'+1);
	}
	cout<<a;
	return 0;
}

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


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

    string S;
    cin >> S;

    int N=S.size();
    int ans=0;
    for(int i=1;i<N;i++){
        if(S.at(i)==S.at(i-1)){
            ans++;
            if(S.at(i)=='0') S.at(i)='1';
            else S.at(i)='0';
        }
    }
    cout << ans << endl;

}


Measured memory_bytes: 512
a=input().split()
N,A,B=int(a[0]),int(a[1]),int(a[2])
b=int(N/(A+B))
ans=int(A*b)
if(N-b*(A+B)<=A):
    ans=ans+N-b*(A+B)
else:
    ans+=A
print(int(ans))


Measured memory_bytes: 3060
import sys
import numpy as np

input = sys.stdin.readline
k, a, b = map(int, input().split())
ans = 0
if b - a > 2:
    if k >= a+1:
        ans += b
        k -= a+1
        ans += int(k/2) * (b - a) + int(k%2)
    else:
        ans += k+1
else:
    ans += k+1
        
print(ans)


Measured memory_bytes: 12500
#include<bits/stdc++.h>
#define sz 200002
#define pb push_back
#define ff first
#define ln '\n'
#define ss second
#define ll long long
#define VEC vector<ll int>v
#define TEST() int test;cin>>test; while(test--)
#define FAST() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
using namespace std;

//ll int LCM(ll int a,ll int b) { ll int gcd=__gcd(a,b);ll int lcm=a*b/gcd;return lcm;}
//ll int bigmod(ll int b, ll int p, ll int m){if(p==0)return 1;if(p%2!=0) return b%m*fun(b,p-1,m)%m;if(p%2==0){ ll int res=fun(b,p/2,m);return (res%m*res%m)%m;}}
//void seive() { prime[np++]=2;for(i=3; i<=sz; i+=2){if(mark[i]==0){ prime[np++]=i;for(j=i*i; j<=sz; j+=i) mark[j]=1; } }}
//string add(string s1,string s2) {string s;int j=s1.size()-1,c=0,m; for(int i=s2.size()-1; i>=0; i--) {if(j>=0)m=s2[i]-'0'+s1[j]-'0'+c;else m=s2[i]-'0'+c; if(m>9) { s+=m%10+'0';c=m/10; } else {  c=0;s+=m+'0'; }j--; } if(c!=0) {s+=c+'0'; }reverse(s.begin(),s.end());return s;}
//int pos;string mul(int n) {string s;for(int i=0; i<pos; i++) { s+="0"; }pos++;int c=0,m; for(int i=s1.size()-1; i>=0; i--) { m=(s1[i]-'0')*n+c;if(m>9) { s+=m%10+'0';c=m/10;} else { c=0; s+=m+'0';} }while(c!=0) { s+=c%10+'0';c=c/10;}    reverse(s.begin(),s.end());return s;}



int main()
{

string s1,s2,s3;
int n,m;
cin>>s1>>s2;
cin>>n>>m>>s3;
if(s1==s3)n--;
else m--;
cout<<n<<" "<<m<<endl;

    return 0;
}




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

#define REP(i, a, b) for(int i = a; i <= b; ++i)
#define DEC(i, a, b) for(int i = a; i >= b; --i)
#define getmid(l,r) ((l) + ((r) - (l)) / 2)
#define MEM(a,b) memset(a,b,sizeof(a))
#define FI first
#define SE second
#define SZ(x) ((int)(x).size())
#define MP make_pair
#define PB push_back
 
typedef long long ll;
typedef pair<int,int> pii;
const int mod = 1000000007;

int n;
string a, b;

int main(){
    ios_base::sync_with_stdio(false);
	cin >> n >> a >> b;
    REP(i, 0, n - 1){
        cout << a[i] << b[i];
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 256
# coding: utf-8
# Your code here!
import sys
input=sys.stdin.readline

N,K=map(int,input().split())
l=list(map(int,input().split()))

dp=[float('inf')]*(N)

dp[0]=0
for i in range(1,N):
    
    for j in range(1,min(i,K)+1):

        dp[i]=min(dp[i],dp[i-j]+abs(l[i]-l[i-j]))

print(dp[N-1])
    


Measured memory_bytes: 55004
#include<bits/stdc++.h>                   // below comment for pbds
#include<ext/pb_ds/assoc_container.hpp>   // to use it make ordered_set
#include<ext/pb_ds/tree_policy.hpp>       // all set fnct + = 1. order_of_key(x); // number of 
#define ll long long                      //element strictly smaller than it;
#define ld long double                    // 2. find_by_order(x),pointer el at x pos after sort  use as s.f();
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
using namespace std;                     
using namespace __gnu_pbds;
// assert(a[i]<n ) // if we want to check for special cond , used for debug
// make less_equal in order to make a multiset pbds
const ll Mod = (int)1e9;
ll CaseN=1;
ll fast_power(ll a,ll b,ll mod){
	ll ans=1;
	while(b>0){
	if(b&1){
	ans=(a*ans)%mod;
	}
	b=b>>1;
	a=(a*a)%mod;
	}
	return ans;
	}


ll nCr(ll n ,ll r)
{
ll p= n;
r = min(r,n-r);
ll a =1;
ll b=1;	
while(r)
{
	a = a*p;
	b = b*r;
	
	ll g = __gcd(a,b);
	
	a = a/g;
	b = b/g;
	
	p--;
	r--;	
}	
return a;
	
}

//ll gcd(ll a,ll b)
//{
	//if(b==0)
	//{
	//return a;	
	//}
//return gcd(b,a%b);	
//}

ll lcm(ll a,ll b)
{
return (a*b)/(__gcd(a,b)) ;	
}


void solve()
{
	ll n;
	cin>>n;
	ll a[n+4];
	vector<ll> c(100002,0);
	ll sum=0;
	for(ll i=1;i<=n;i++)
	{
	cin>>a[i];
	sum+=a[i];
	c[a[i]]++;	
	}
	
//	cout<<sum<<"==="<<endl;
	ll q;
	cin>>q;
	while(q--)
	{
		ll x,y;
		// x to y;
		cin>>x>>y;
		sum = sum -(c[x]*x)+(c[x]*y) ;
		c[y]+=c[x];
		c[x]=0;
		
		
		cout<<sum<<endl;
	}
	
	
   //cout<<"Case #"<<CaseN<<": ";
   CaseN++;
	// print your ans below;

  return ;
}


signed main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int t=1;
	//cin>>t;
	while(t--)
	{
		
	solve();	
	}
}

/*
 if(ans)
  {
  cout<<"YES"<<endl; 
  }
  else
   {
  cout<<"NO"<<endl;
  }
 
 
*/


Measured memory_bytes: 4712
import sys
import math
import bisect
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop
from operator import mul
from functools import reduce


def LI(): return [int(x) for x in sys.stdin.readline().split()]


def I(): return int(sys.stdin.readline())


def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res


# A
def A():
    r = I()
    print(r * r)
    return


# B
def B():
    N = I()
    s = S()
    if N % 2 != 0:
        print("No")
    elif ''.join(s[:N // 2]) == ''.join(s[N // 2:]):
        print("Yes")
    else:
        print("No")
    return


# C
def C():
    n = I()
    a = [LI() for i in range(n)]
    ans = 0
    for i in range(n):
        for j in range(i + 1, n):
            ans += pow(pow(a[i][0] - a[j][0], 2) + pow(a[i][1] - a[j][1], 2), 0.5)
    avg = ans / (n * (n - 1) / 2)
    print(avg * (n - 1))
    return


# D
def D():
    X, Y = LI()

    def cmb(n, r, mod):
        if (r < 0 or r > n):
            return 0
        r = min(r, n - r)
        return g1[n] * g2[r] * g2[n - r] % mod

    mod = 10 ** 9 + 7  # 出力の制限
    N = X + Y
    g1 = [1, 1]  # 元テーブル
    g2 = [1, 1]  # 逆元テーブル
    inverse = [0, 1]  # 逆元テーブル計算用テーブル

    for i in range(2, N + 1):
        g1.append((g1[-1] * i) % mod)
        inverse.append((-inverse[mod % i] * (mod // i)) % mod)
        g2.append((g2[-1] * inverse[-1]) % mod)

    if (X + Y) % 3 != 0:
        print(0)
    elif X < ((X + Y) // 3) or Y < ((X + Y) // 3):
        print(0)
    else:
        print(cmb((X + Y) // 3, min(X, Y) - ((X + Y) // 3), mod))

    return


# E
def E():
    return


# F
def F():
    return


# Unittest
def resolve():
    D()
    return


# Solve
if __name__ == "__main__":
    D()


Measured memory_bytes: 132908
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;


public class Main {
    private static int MOD = 1000000007;


    public static void main(String[] args) throws IOException {
        InputStreamReader isr = new InputStreamReader(System.in);
        BufferedReader br = new BufferedReader(isr);
        Integer k = Integer.parseInt(br.readLine());
        String str = br.readLine();
        String[] s = str.split(" ");
        int a = Integer.parseInt(s[0]);
        int b = Integer.parseInt(s[1]);

        for (int i = a; i <= b; i++) {
            if(i % k == 0 ){
                System.out.println("OK");
                return;
            }
        }
        System.out.println("NG");
    }


}


Measured memory_bytes: 25380
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>

#define MAX_N 100005

int N;
std::vector<int> G[MAX_N];

int father[MAX_N], siz[MAX_N], dis[MAX_N];

void dfs(int u, int p) {
	dis[u] = dis[p] + 1;
	father[u] = p;
	siz[u]++;
	for (auto v : G[u]) 
		if (v != p) { 
			dfs(v, u);
			siz[u] += siz[v];
		}
}

int main() {
	scanf("%d", &N);
	for (int i = 1; i < N; i++) {
		int a, b;
		scanf("%d%d", &a, &b);
		G[a].push_back(b);
		G[b].push_back(a);
	}
	dfs(1, 0);

	int d = (dis[N] - 2) / 2;

	int u = N;

	for (int i = 1; i <= d; i++)
		u = father[u];

	if (N - siz[u] > siz[u]) printf("Fennec\n");
	else printf("Snuke\n");
	return 0;
}

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

using namespace std;

int main()
{
	cin.tie(0),ios::sync_with_stdio(0);
	int n,m;
	cin>>n>>m;
	string str;
	cin>>str;
	vector<int> arr(n,0);
	for(int i=1;i<n;i++)
	{
		if(str[i-1]=='A'&&str[i]=='C')
			arr[i]++;
	}
	for(int i=1;i<n;i++)
		arr[i]+=arr[i-1];
	while(m--)
	{
		int l,r;
		cin>>l>>r;
		cout<<arr[r-1]-arr[l-1]<<'\n';
	}
	return 0;
}

Measured memory_bytes: 1488
#include<stdio.h>
int main(){
	int n,m,dist[15][15],sum=0,i,j,k,a;
	scanf("%d%d",&n,&m);
	for(i=0;i<10;i++){
		for(j=0;j<10;j++){
			scanf("%d",&dist[i][j]);
		}
	}
	for(k=0;k<10;k++){
		for(i=0;i<10;i++){
			for(j=0;j<10;j++){
				if(dist[i][k]+dist[k][j]<dist[i][j])
				dist[i][j]=dist[i][k]+dist[k][j];
			}
		}
	}
	for(i=0;i<n;i++){
		for(j=0;j<m;j++){
			scanf("%d",&a);
			if(a!=-1){
				sum+=dist[a][1];
			}
		}
	}
	printf("%d\n",sum);
	return 0;
}

Measured memory_bytes: 128
#include <cstdio>
#include <map>

using namespace std;
typedef pair<int, int> pii;
typedef pair<int, pii> pipii;

int main(){
	while(true){
		int n, m, a;
		scanf("%d%d%d", &n, &m, &a);
		if(n == 0 || m == 0 || a == 0){ break; }
		multimap<int, pii, greater<int> > field;
		for(int i = 0; i < m; i++){
			int h, p, q;
			scanf("%d%d%d", &h, &p, &q);
			field.insert(pipii(h, pii(p, q)));
		}
		for(
			multimap<int, pii, greater<int> >::iterator it = field.begin();
			it != field.end(); it++
		){
			pii item = (*it).second;
			if(a == item.first){
				a = item.second;
			}else if(a == item.second){
				a = item.first;
			}
		}
		printf("%d\n", a);
	}
	return 0;
}

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

#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define ALL(c) (c).begin(), (c).end()

int main() {
    int64_t a, b, c, d; cin >> a >> b >> c >> d;
    int64_t m = max({
        a * c,
        a * d,
        b * c,
        b * d,
    });
    cout << m << endl;
}


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


int main() {
  vector<int> S = {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};
  
  int K;
  cin >> K;
  
  cout << S.at(K-1) << endl;
  
  
  
  return 0;
}



Measured memory_bytes: 3636
# ABC129D - Lamp
def main():
    H, W, *S = open(0).read().split()
    H, W = int(H), int(W)
    L, R = [[0] * W for _ in range(H)], [[0] * W for _ in range(H)]
    U, D = [[0] * W for _ in range(H)], [[0] * W for _ in range(H)]
    for x1 in range(H):
        for y1 in range(W):
            if S[x1][y1] == ".":  # left and upper sides of S[i][j]
                U[x1][y1] = U[x1 - 1][y1] + 1
                L[x1][y1] = L[x1][y1 - 1] + 1
            x2, y2 = -x1 - 1, -y1 - 1
            if S[x2][y2] == ".":  # right and under sides
                D[x2][y2] = D[x2 + 1][y2] + 1
                R[x2][y2] = R[x2][y2 + 1] + 1
    ans = -1
    for i in range(H):
        for j in range(W):
            ans = max(ans, L[i][j] + R[i][j] + U[i][j] + D[i][j] - 3)
    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 176728
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    ll a = 100, i;
    ll k; cin >> k;
    for (i = 0; a < k; i++) {
        a += a/100;
    }
    cout << i;
}

Measured memory_bytes: 3656
#include<iostream>
#include<cmath>
#include<map>
#include<deque>
#include<string>
#include<algorithm>

#define all(x) (x).begin(),(x).end()
#define puts(x) cout<< x << endl;
#define rep(i,m,n) for(int i=m;i<n;i++)
#define fore(i,a) for(auto i:a)
#define ll long long
using namespace std;
int h,w;
int ma[50][50];//[縦][横]
int s[50][50];//[縦][横]
void clean(int h,int w){
    rep(i,0,h)rep(j,0,w)s[i][j]=500;
}
void dfs(int i,int j,int h,int w,int c){
    if(i<0||i>=h||j<0||j>=w||ma[i][j]==1){
        return;
    }
    if(c<s[i][j]){
        s[i][j]=c;
        int x[]={-1,1,0,0};
        int y[]={0,0,-1,1};
        rep(k,0,4){
            dfs(i+y[k],j+x[k],h,w,c+1);
        }
    }
    return;
}
int p_max(int h,int w){
    int m=0;
    rep(i,0,h){//y
        rep(j,0,w){//x スタート地点を決める
            if(ma[i][j]==0&&s[i][j]!=500){
                m=max(m,s[i][j]);
            }
        }
    }
    return m;
}
int main(){
    cin>>h;
    cin>>w;
    rep(i,0,h){
        string x;
        cin>>x;
        rep(j,0,w){
            if(x[j]=='#')ma[i][j]=1;
        }
    }

    int maxi=0;
    rep(i,0,h){//y
        rep(j,0,w){//x スタート地点を決める
            clean(h,w);
            dfs(i,j,h,w,0);
            maxi=max(p_max(h,w),maxi);
        }
    }
    puts(maxi);
}

Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>

using namespace std;

int main()
{
	int n,u,k,v;
	cin>>n;
	int G[110][110];
	memset(G,0,sizeof(G));
	for(int i=0;i<n;++i){
		cin>>u>>k;
		u--;//转化成0起点
		for(int j=0;j<k;++j){
			cin>>v;
			v--;
			G[u][v]=1;//u和v之间画一条边 
		} 
	} 
	for(int i=0;i<n;++i){
		for(int j=0;j<n;j++){
			if(j>0)cout<<' ';
			cout<<G[i][j]; 
		}
		cout<<endl;
	}
	//cout<<endl;
	return 0;
}


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

int main()
{
  int N,M;scanf("%d %d",&N,&M);
  vector<int> foods(M+1,0);
  for(int K,i=0;i<N;i++)
  {
    cin>>K;vector<int> A(K);vector<bool> check(M+1,false);
    for(int i=0;i<K;i++)
    {
      cin>>A[i];check[A[i]]=true;
    }
    for(int i=0;i<M+1;i++)if(check[i])foods[i]++;
  }
  int ans=0;
  for(int i=0;i<M+1;i++)if(foods[i]==N)ans++;
  printf("%d\n",ans);
}

Measured memory_bytes: 3764
#include<stdio.h>

int main(){

int a,b,c,count=0,i,t;

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

for(i=a;i<(b+1);i++){
 t = c%i;
 if(t==0)
 count++;
}

printf("%d\n",count);

return 0;

}

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

using namespace std;
typedef long long ll;
typedef pair<ll, ll> p_ll;

template<class T>
void debug(T itr1, T itr2) { auto now = itr1; while(now<itr2) { cout << *now << " "; now++; } cout << endl; }
#define repr(i,from,to) for (int i=(int)from; i<(int)to; i++)
#define all(vec) vec.begin(), vec.end()
#define rep(i,N) repr(i,0,N)
#define per(i,N) for (int i=(int)N-1; i>=0; i--)

const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,30)-1;

vector<ll> fac;
void c_fac(int x=pow(10,6)+10) { fac.resize(x,true); rep(i,x) fac[i] = i ? (fac[i-1]*i)%MOD : 1; }
ll inv(ll a, ll m=MOD) { ll b = m, x = 1, y = 0; while (b!=0) { int d = a/b; a -= b*d; swap(a,b); x -= y*d; swap(x,y); } return (x+m)%m; }
ll nck(ll n, ll k) { return fac[n]*inv(fac[k]*fac[n-k]%MOD)%MOD; }
ll gcd(ll a, ll b) { if (a<b) swap(a,b); return b==0 ? a : gcd(b, a%b); }
ll lcm(ll a, ll b) { return a/gcd(a,b)*b; }


int main() {
  ll A, B, C, K; cin >> A >> B >> C >> K;
  ll result = 0;
  if (K<=A) result = K;
  else if (K<=A+B) result = A;
  else result = A - (K-(A+B));
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 3640
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

typedef long long LL;

#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))
#define ALL(a)  (a).begin(),(a).end()
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

#define dump(x)  cerr << #x << " = " << (x) << endl;

int main() {
  int N;
  cin >> N;
  vector<int> T(N), A(N);
  REP(i, N) {
    cin >> T[i] >> A[i];
  }

  LL t = T[0], a = A[0];
  FOR(i, 1, N) {
    LL times;
    times = (t + T[i] - 1) / T[i];
    times = max((LL)((a + A[i] - 1) / A[i]), times);
    t = T[i]*times;
    a = A[i]*times;
  }

  cout << t + a << endl;

  return 0;
}

Measured memory_bytes: 888
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define Sort(Array) sort(Array.begin(), Array.end())
#define Reverse(a) reverse(a.begin(), a.end())
#define out(ans) cout << ans << endl;
const int MOD = 1000000007;
const int INF = 2147483647;
const ld PI = 3.14159265358979323846;

//------------↓------------- M -------------- E ---------------- M --------------- O ---------------↓--------------//
// コンパイル 
// g++ -std=c++1z
//
// -------型変換--------
// int を string に変換
// string s = to_string(n);
// string を int に変換
// int n = stoi(s);
//
// -------二分探索---------
// k以上の値が最初に現れる時のイテレータ
// lower_bound(data.begin(), data.end(), k)
// kより大きい値が最初の現れる時のイテレータ O(logN)
// upper_bound(data.begin(), data.end(), k)
// kがdataに存在するかをtrue or falseで返す O(logN)
// binary_search(data.begin(), data.end(), k)
// 
//
//
//
//
//
// 
//------------↑------------- M -------------- E ---------------- M --------------- O ---------------↑--------------//



int main(void) {

    ll X; cin >> X;
    bool flag = false;
    for (ll a = -1000; a <= 1000; ++a) {
        for (ll b = -1000; b <= 1000; ++b) {
            if (pow(a,5) - pow(b, 5) == X){
                cout << a << " " << b << endl;
                flag = true;
                break;
            }
        }
        if (flag) break;
    }


    
    
    return 0;
}











Measured memory_bytes: 4096
#!/usr/bin/env python3

#import
#import math
#import numpy as np
N = int(input())
AB = [list(map(int, input().split())) for _ in range(N)]

ans = 0

AB.reverse()

for a, b in AB:
    if (a + ans) % b != 0:
        ans += b - (a + ans) % b

print(ans)

Measured memory_bytes: 27052