akhauriyash/Code-Regression huggingface dataset:
import java.util.HashMap;
import java.util.Map;
import java.util.TreeSet;

public class Main {

  private static void solve() {
    int n = ni();
    Map<String, Integer> map = new HashMap<>();
    for (int i = 0; i < n; i++) {
      String s = next();
      map.putIfAbsent(s, 0);
      map.put(s, map.get(s) + 1);
    }

    int max = 0;
    TreeSet<String> ret = new TreeSet<>();
    for (Map.Entry<String, Integer> entry : map.entrySet()) {
      int v = entry.getValue();
      String s = entry.getKey();
      if (v > max) {
        max = v;
        ret.clear();
      }

      if (v == max) {
        ret.add(s);
      }
    }

    for (String s : ret) {
      System.out.println(s);
    }
  }

  public static void main(String[] args) {
    new Thread(null, new Runnable() {
      @Override
      public void run() {
        long start = System.currentTimeMillis();
        String debug = args.length > 0 ? args[0] : null;
        if (debug != null) {
          try {
            is = java.nio.file.Files.newInputStream(java.nio.file.Paths.get(debug));
          } catch (Exception e) {
            throw new RuntimeException(e);
          }
        }
        reader = new java.io.BufferedReader(new java.io.InputStreamReader(is), 32768);
        solve();
        out.flush();
        tr((System.currentTimeMillis() - start) + "ms");
      }
    }, "", 64000000).start();
  }

  private static java.io.InputStream is = System.in;
  private static java.io.PrintWriter out = new java.io.PrintWriter(System.out);
  private static java.util.StringTokenizer tokenizer = null;
  private static java.io.BufferedReader reader;

  public static String next() {
    while (tokenizer == null || !tokenizer.hasMoreTokens()) {
      try {
        tokenizer = new java.util.StringTokenizer(reader.readLine());
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
    return tokenizer.nextToken();
  }

  private static double nd() {
    return Double.parseDouble(next());
  }

  private static long nl() {
    return Long.parseLong(next());
  }

  private static int[] na(int n) {
    int[] a = new int[n];
    for (int i = 0; i < n; i++)
      a[i] = ni();
    return a;
  }

  private static char[] ns() {
    return next().toCharArray();
  }

  private static long[] nal(int n) {
    long[] a = new long[n];
    for (int i = 0; i < n; i++)
      a[i] = nl();
    return a;
  }

  private static int[][] ntable(int n, int m) {
    int[][] table = new int[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[i][j] = ni();
      }
    }
    return table;
  }

  private static int[][] nlist(int n, int m) {
    int[][] table = new int[m][n];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[j][i] = ni();
      }
    }
    return table;
  }

  private static int ni() {
    return Integer.parseInt(next());
  }

  private static void tr(Object... o) {
    if (is != System.in)
      System.out.println(java.util.Arrays.deepToString(o));
  }
}



Measured memory_bytes: 76676
// In His Name
     
#include <bits/stdc++.h>
     
#define pb push_back
#define F first
#define S second
#define gcd __gcd
#define int long long
#define ull unsigned long long
     
using namespace std;
     
typedef pair<int, int> pii;
     
const int N = 1e5 + 1e2, INF = 1e15;
int n, W, mx, w[N], v[N], dp[110][N], ps[N];
         
main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin >> n >> W;
	for (int i = 1 ; i <= n ; i++)
		cin >> w[i] >> v[i];
	for (int i = 1 ; i <= n ; i++)
		ps[i] = ps[i - 1] + v[i];
	for (int i = 0 ; i <= n ; i++){
		for (int j = 0 ; j <= 1e5 ; j++){
			dp[i][j] = INF;
		}
	}
	for (int i = 1 ; i <= v[0] ; i++){
		dp[0][i] = w[0];
	}
	for (int i = 1 ; i <= n ; i++){
		for (int j = 1 ; j <= ps[i] ; j++){
			if (v[i] > j){
				dp[i][j] = dp[i - 1][j];
			}
			dp[i][j] = min (dp[i - 1][j] , dp[i - 1][j - v[i]] + w[i]);
		}
	}
	for (int i = 0 ; i <= n ; i++){
		for (int j = 0 ; j <= 1e5 ; j++){
			if (dp[i][j] <= W){
				mx = max (mx , j);
			}
		}
	}
	cout << mx + 1;
}

Measured memory_bytes: 81408
#include <cstdio>
#include <algorithm>
#include <vector>

using namespace std;

vector <int> v[512];
int in[512], out[512], trec[512];

#define v (v + 230)
#define trec (trec + 230)
#define in (in + 230)
#define out (out + 230)

bool OK;

void dfs (int nod)
{
    trec[nod] = 1;
    if (in[nod] != out[nod]) OK = true;

    for (auto &it : v[nod])
        if (!trec[it]) dfs (it);
}

int main ()
{
   // freopen ("file.in", "r", stdin);

    int n, h;
    scanf ("%d %d", &n, &h);

    for (int i = 1; i <= n; ++i)
    {
        int a, b, c, d, l, r;
        scanf ("%d %d %d %d", &a, &b, &c, &d);

        if (!c) l = a;
        else l = -c;

        if (!d) r = -b;
        else r = d;

        v[l].push_back (r);
        v[r].push_back (l);

        ++out[l];
        ++in[r];
    }

    for (int i = -h; i <= h; ++i)
    {
        if (i < 0)
        {
            if (in[i] < out[i])
            {
                printf ("NO\n");
                return 0;
            }
        }

        if (i > 0)
        {
            if (in[i] > out[i])
            {
                printf ("NO\n");
                return 0;
            }
        }
    }

    trec[0] = 1;

    for (int i = -h; i <= h; ++i)
        if (!trec[i] && (in[i] || out[i]))
        {
            OK = false;
            dfs (i);

            if (!OK)
            {
                printf ("NO\n");
                return 0;
            }
        }

    printf ("YES\n");

    return 0;
}


Measured memory_bytes: 1664
n=int(input())
a,b,c,d=0,0,0,0
for i in range(n):
  A=input()
  if A=='AC':
    a+=1
  elif A=='WA':
    b+=1
  elif A=='TLE':
    c+=1
  elif A=='RE':
    d+=1
print('AC x',a)
print('WA x',b)
print('TLE x',c)
print('RE x',d)

Measured memory_bytes: 9148
#include <iostream>
#include <algorithm>
#include <utility>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <math.h>
#include <string.h>
#include <iomanip>
#include <numeric>
#include <cstdlib>
#include <cstdint>
#include <cmath>
#include <functional>
#include <limits>
#include <cassert>

using namespace std;

/* template */

using ll = long long;

void debug_out() { std::cout << std::endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cout << H << " ";
  debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cout << "debug: "; debug_out(__VA_ARGS__)
#else
#define debug(...) 
#endif

#define rep(i, a, n) for (int i = (int)(a); i < (int)(n); i++)
#define rrep(i, a, n) for (int i = ((int)(n-1)); i >= (int)(a); i--)
#define Rep(i, a, n) for (long long i = (long long)(a); i< (long long)(n); i++)
#define RRep(i, a, n) for (long long i = ((long long)(n-1ll)); i>=(long long)(a); i--)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()

template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
  for (std::size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  return os;
}

struct Edge{
    int to;
    int weight;
    Edge(int t, int w) : to(t), weight(w){ }
};

struct edge{
    int from;
    int to;
    int weight;
    edge(int f,int t,int w) : from(f), to(t), weight(w){ }
};


using Graph = vector<vector<Edge>>;
using graph = vector<vector<int>>;
using edges = vector<edge>;

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;
}

template <class T>
T lcm(T a, T b){
    return (a*b)/gcd(a,b);
}

bool isPalindrome(string s){
    string t = s;
    reverse(all(t));
    return s==t;
}

constexpr ll LNF = 1e18+7;

constexpr int INF = 1e9+7;

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

/* template */

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n,m; cin >> n >> m;
    vector<pair<ll,ll>> a(n),c(m);
    rep(i,0,n) cin >> a[i].first >> a[i].second;
    rep(i,0,m) cin >> c[i].first >> c[i].second;
    rep(i,0,n){
        ll ans = LNF;
        int flag = 0;
        rep(j,0,m){
            ll x = abs(a[i].first-c[j].first)+abs(a[i].second-c[j].second);
            if(chmin(ans,x)){
                flag = j+1;
                debug(ans,x);
            }
        }
        cout << flag << endl;
    }
}

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

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, k;
	cin >> n >> k;
	vector<pair<int, int>> in(n);
	for (int i = 0; i < n; i++) {
		cin >> in[i].first >> in[i].second;
		in[i].first--;
	}
	sort(in.begin(), in.end());
	reverse(in.begin(), in.end());
	vector<int> kind(n), to_max(n);
	for (int i = 0; i < n; i++) {
		int x = in[i].first;
		if (kind[x] == 0) {
			kind[x]++;
			to_max[i]++;
		}
	}
	vector<int> mx, els;
	for (int i = 0; i < n; i++) {
		if (to_max[i]) mx.push_back(in[i].second);
		else els.push_back(in[i].second);
	}
	sort(mx.rbegin(), mx.rend());
	sort(els.rbegin(), els.rend());
	vector<long long> a((int) mx.size() + 1), b((int) els.size() + 1);
	for (int i = 0; i < (int) mx.size(); i++) {
		a[i + 1] = a[i] + mx[i];
	}
	for (int i = 0; i < (int) els.size(); i++) {
		b[i + 1] = b[i] + els[i];
	}
	long long ans = 0;
	int sa = (int) a.size() - 1;
	for (int i = 1; i <= sa; i++) {
		long long tmp = 1LL * i * i;
		if(i > k) break;
		tmp += a[i] + b[min((int) b.size()  - 1, k - i)];
		ans = max(ans, tmp);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3196
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
//        String[] str = br.readLine().split(" ");

        int n = Integer.parseInt(br.readLine());
        String[] str = br.readLine().split(" ");
        int[] nl = new int[n];
        for(int i=0; i<n; i++) nl[i] = Integer.parseInt(str[i]);
        Arrays.sort(nl);

        int m = Integer.parseInt(br.readLine());
        int[] ml = new int[m];
        str = br.readLine().split(" ");
        for(int i=0; i<m; i++) ml[i] = Integer.parseInt(str[i]);
        Arrays.sort(ml);

        int ni = 0;
        for(int i=0; i<m; i++){
            while(nl[ni] != ml[i]){
                ni++;
                if(ni >= n){
                    System.out.println("NO");
                    return;
                }
            }
            ni++;
        }

        System.out.println("YES");
    }
}


Measured memory_bytes: 94668
#include <stdio.h>
int n;
int i;
int a;
long b;
long max = -1000000;
long min = 1000000;
long sum = 0;

main(){
 scanf("%d",&n);
 for(i=1; i<=n; i++){
 	scanf(" %d",&a);
 	if(a > max){
 		max=a;
 	}if(a < min){
 		min =a;
 	}
 	sum += a;
 	}
 printf("%ld %ld %ld\n",min,max,sum);
 return 0;
}

Measured memory_bytes: 600
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.stream.IntStream;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.io.IOException;
import java.util.InputMismatchException;
import java.util.BitSet;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author amotoma3
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskC solver = new TaskC();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskC {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int[] a = in.nextIntArray(n);

            int sum = Arrays.stream(a).sum();

            BitSet bitSet = new BitSet();
            bitSet.set(sum);
            for (int i = 0; i < n; i++) {
                bitSet.or(bitSet.get(a[i], sum + 1));
            }

            out.println(bitSet.nextSetBit((sum + 1) / 2));
        }

    }

    static class InputReader {
        BufferedReader in;
        StringTokenizer tok;

        public String nextString() {
            while (!tok.hasMoreTokens()) {
                try {
                    tok = new StringTokenizer(in.readLine(), " ");
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
            }
            return tok.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(nextString());
        }

        public int[] nextIntArray(int n) {
            int[] res = new int[n];
            for (int i = 0; i < n; i++) {
                res[i] = nextInt();
            }
            return res;
        }

        public InputReader(InputStream inputStream) {
            in = new BufferedReader(new InputStreamReader(inputStream));
            tok = new StringTokenizer("");
        }

    }
}



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

using namespace std;

int main() {
    int n,k;

    cin >> n >> k;

    unsigned long int h[n];

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

    sort(h,h+n,greater<int>());

    unsigned long int count=0;
    for(int i = k; i < n; i++) {
        count += h[i];
    }

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

Measured memory_bytes: 1920
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
int main(){
  ll n;
  cin>>n;
  ll ans=0;
  for(int i=1;i<=n;i+=2){
    ll cnt=0;
    for(int j=1;j<=i;j++)if(i%j==0)cnt++;
    if(cnt==8)ans++;
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 256
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
#include <cstdlib>
using namespace std;
#define Ma_PI 3.141592653589793
#define eps 0.00000000000000000000000001
#define LONG_INF 10000000000000000
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define REP(i,n) for(long long i = 0;i < n;++i)
int main() {
	int a, b;
	cin >> a >> b;
	cout << a / b + a%b << endl;
	return 0;
}


Measured memory_bytes: 3120
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <queue>
#include <cmath>
#include <map>
#include <set>
#include <deque>
using namespace std;

int main() {
  int N; cin >> N;
  map<string, int> mp;
  set<string> st;
  for(int i = 0; i < N; i++) {
    string s; cin >> s;
    mp[s]++;
    st.insert(s);
  }

  int max_cnt = 0;
  for(string s: st) {
    max_cnt = max(max_cnt, mp[s]);
  }
  vector<string> ans;
  for(string s: st) {
    if(mp[s] == max_cnt) ans.push_back(s);
  }
  sort(ans.begin(), ans.end());
  for(int i = 0; i < ans.size(); i++) {
    cout << ans[i] << endl;
  }

  return 0;
}


Measured memory_bytes: 36212
#!/usr/bin/env python3
import sys


def solve(N: int, K: int, X: int, Y: int):
    print(X * min(N, K) + Y * max(0, N - K))


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    X = int(next(tokens))  # type: int
    Y = int(next(tokens))  # type: int
    solve(N, K, X, Y)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include<stdio.h>
int main()
{
	int a[8]={0},i;
	double l,r;
	while(scanf("%lf%lf",&l,&r)>0)
	{
		if(l>=1.1)a[0]++;
		else if(l>=0.6)a[2]++;
		else if(l>=0.2)a[4]++;
		else a[6]++;
		if(r>=1.1)a[1]++;
		else if(r>=0.6)a[3]++;
		else if(r>=0.2)a[5]++;
		else a[7]++;
	}
	for(i=0;i<8;i+=2)
		printf("%d %d\n",a[i],a[i+1]);
	return 0;
}

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

const ll MAXN = 200000;
const ll INF = 1001001001;
const ll MOD = 1000000007;

ll N, K, ans=0, tmp=0;
vector<ll> A, B;

void rekkyo(){
    for(int i=1;i*i<=tmp;i++) {
        if(tmp%i==0) {
            if(i*i==tmp) {
                B.push_back(i);
            }
            else {
                B.push_back(i);
                B.push_back(tmp/i);
            }
        }
    }
    sort(B.begin(),B.end());
}

signed main(){
    cin >> N >> K;
    for(int i=0;i<N;i++) {
        ll a;
        cin >> a;
        tmp += a;
        A.push_back(a);
    }
    rekkyo();
    for(int i=0;i<B.size();i++) {
        vector<ll> C;
        tmp=0;
        for(int j=0;j<A.size();j++) {
            tmp += A[j]%B[i];
            C.push_back(A[j]%B[i]);
        }
        sort(C.begin(),C.end());
        tmp = tmp/B[i];
        ll tmpsum=0;
        for(int j=C.size()-tmp;j<C.size();j++) {
            tmpsum += B[i]-C[j];
        }
        if(tmpsum<=K) ans = B[i];
        //cout << B[i] << " " << tmpsum << endl;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3648
#include <iostream>

using namespace std;

    char C[1 << 8];
    char RC[1 << 8];

int main() {
    string S, T;
    cin >> S >> T;

    bool ans = true;
    for (int i = 0; i < S.size(); ++i) {
        if (C[S[i]]) {
            if (C[S[i]] != T[i]) {
                ans = false;
                break;
            }
        }
        else if (RC[T[i]]) {
            if (RC[T[i]] != S[i]) {
                ans = false;
                break;
            }
        }
        else {
            C[S[i]] = T[i];
            RC[T[i]] = S[i];
        }
    }

    cout << (ans ? "Yes" : "No") << endl;
}

Measured memory_bytes: 776
//#include <iostream>
//#include <algorithm>
//#include <functional>
//#include <vector>
//#include <string>
//#include <map>
//#include <sstream>
//#include <cmath>
//#include <cstdio>
//#include <iomanip>
//#include <stdexcept>
//#include <utility>

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define rep(i,h) for(int i = 0; i < h; ++i)
#define rep1(i,h) for(int i = 0; i <= h; ++i)
#define rep2(i,n,h) for(int i = n; i < h; ++i)
#define rep3(l,n,h) for(int l = n; l <= h; ++l)
typedef pair<int,int> int_pair;


int main() {
    int a,b,k;
    cin >> a >> b >>k;
    int j = 0;
    rep3(i,a,b) {
        if (j < k) {
            cout << i << endl;
        } else if(b - k < i) {
            cout << i << endl;
        }
    j++;
    }
     return 0;
    }


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

#define MAX_N (100000)

int main(int argc, char *argv[]) {
  // read inputs
  int N, as[MAX_N];
  scanf("%d", &N);
  for (int i = 0; i < N; i++) {
    scanf("%d", &as[i]);
  }

  // solve
  int us[MAX_N] = {}, ans = 0;
  // all as are smaller than 2^30
  // and thus use only the first 30 bits
  for (int k = 29; k >= 0; k--) {
    const int mask1 = 1 << k;     // 0..010..0
    const int mask2 = mask1 - 1;  // 0..001..1
    // calculate XOR
    int cur_xor = 0;
    for (int i = 0; i < N; i++) {
      cur_xor ^= as[i];
    }
    // printf("k = %d, cur_xor = %#08x\n", k, cur_xor);

    // check if kth LSB is 1
    if (cur_xor & mask1) {
      // printf("k( = %d)th bit is set. attempt removal.\n", k);
      // we need to remove this 1 from the xor result
      // look for an unused a that can be used
      // the a we're looking for has the form,
      //     31   k    0
      //     *...*10...0
      int i0 = -1;
      for (int i = 0; i < N; i++) {
        const int a = as[i];
        if (!us[i] && (a & mask1) != 0 && (a & mask2) == 0) {
          i0 = i;
          break;
        }
      }

      if (i0 >= 0) {  // found
        // printf("i = %d, as[i] = %#08x\n", i0, as[i0]);
        // if found subtract 1 from it and mark as used
        as[i0]--;
        us[i0] = 1;
        ans++;
      } else {  // not found
        // printf("could not remove the k( = %d)th bit. impossible.\n", k);
        // not possible
        ans = -1;
        break;
      }
    }
  }
  printf("%d\n", ans);

  return 0;
}


Measured memory_bytes: 896
#include<cstdio>
#include<algorithm>
#define rep(i,l,r) for (int i=(l); i<=(r); i++)
using namespace std;

int n;

int main(){
	scanf("%d",&n);
	if (n==3){ puts("2\n1 3\n2 3"); return 0; }
	if (n==4){ puts("4\n1 2\n3 4\n1 3\n2 4"); return 0; }
	if (n&1){
		int t=n/2; printf("%d\n",t*4);
		rep(i,1,t-1) printf("%d %d\n%d %d\n%d %d\n%d %d\n",i,n-i-1,i+1,n-i,i,i+1,n-i-1,n-i);
		printf("%d %d\n%d %d\n%d %d\n%d %d\n",n,1,n,n-1,n,t,n,n-t);
	}else{
		int t=n/2; printf("%d\n",t*4);
		rep(i,1,t-1) printf("%d %d\n%d %d\n%d %d\n%d %d\n",i,n-i,i+1,n-i+1,i,i+1,n-i,n-i+1);
		printf("%d %d\n%d %d\n%d %d\n%d %d\n",t,n,n-t+1,1,t,1,n-t+1,n);
	}
	return 0;
}

Measured memory_bytes: 128
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.numeric, std.math, std.random;
import core.bitop;

string FMT_F = "%.10f";

static string[] s_rd;
T RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
string RDR()() { return readln.chomp; }
T[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }
size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
long lcm(long x, long y) { return x * y / gcd(x, y); }

long mod = 10^^9 + 7;
//long mod = 998244353;
//long mod = 1_000_003;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }

void main()
{
	auto c1 = RD!(char[]);
	auto c2 = RD!(char[]);
	c2.reverse();
	bool ans = true;
	foreach (i; 0..c1.length)
	{
		if (c1[i] != c2[i])
			ans = false;
	}

	writeln(ans ? "YES" : "NO");
	stdout.flush();
	debug readln();
}

Measured memory_bytes: 256
while n = gets
  n = n.to_i
 
  break if n == 0
  
  a_score = 0
  b_score = 0
  
  n.times do
  	
  	a, b = gets.split.map(&:to_i)
  	
  	if a == b 
  	  a_score += a
  	  b_score += b
  	elsif a > b
  	  a_score += a + b
    else
      b_score += a + b
    end
  end
  
  puts "#{a_score} #{b_score}"
  
end

Measured memory_bytes: 6108
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e5+7;
int main(){
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    int n,h,w;
    cin>>n>>h>>w;
    int ans = (n-h+1)*(n-w+1);
    cout<<(ans>=0?ans:0)<<endl;
    return 0;
}


Measured memory_bytes: 256
n=int(input())
p,q=1,1

for _ in range(n):
    t,a=map(int,input().split())
    #n=1
    #hile p>n*t or q>n*a:
    #    n+=1
    n=max((p+t-1)//t,(q+a-1)//a)
    p,q=n*t,n*a
    #print(n,p,q)

print(p+q)

Measured memory_bytes: 9020
#include <bits/stdc++.h>
using namespace std;
#include <string.h>
#include <map>
#define MEM(var, val) memset(var, (val), sizeof(var))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define nitro                         \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> pll;
typedef vector<ll> vll;
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define mod 1000000007
//*max_element(a.begin(), a.end())


int main()
{
    
    ll n,k;
    cin>>n>>k;
    vll a(n);
    for(int i=0;i<n;i++)
    cin>>a[i];
    vector<bool>dp(k+1);
    for(int i=0;i<=k;i++)
    dp[i]=false;
    for(ll stones=0;stones<=k;stones++)
    {
        for(int x:a)
        {
            if(stones-x>=0&&!dp[stones-x])
            dp[stones]=true;
        }
    }

    if(dp[k])
    cout<<"First";
    else cout<<"Second";
}

Measured memory_bytes: 3648
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
using namespace std;

int main()
{
    int m, n;
    cin >> m >> n;

    vector<int> p(m);
    for(int i=0; i<m; ++i)
        cin >> p[i];
    sort(p.rbegin(), p.rend());

    vector<int> dp(m+1, INT_MAX / 2);
    dp[0] = 0;
    for(int i=0; i<n; ++i){
        int c, e;
        cin >> c >> e;
        for(int j=m; j>=0; --j){
            int k = min(m, j + c);
            dp[k] = min(dp[k], dp[j] + e);
        }
    }
    for(int i=m-1; i>=0; --i)
        dp[i] = min(dp[i], dp[i+1]);

    int ret = 0;
    int sum = 0;
    for(int i=0; i<m; ++i){
        sum += p[i];
        ret = max(ret, sum - dp[i+1]);
    }
    cout << ret << endl;

    return 0;
}

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

int main() {
    vector<vector<int>> bingo(3, vector<int>(3));
    for (int i = 0; i < 3; i++) {
        for (int j = 0; j < 3; j++) {
            cin >> bingo[i][j];
        }
    }
    int N;
    cin >> N;
    for (int i = 0; i < N; i++) {
        int b;
        cin >> b;
        for (int i = 0; i < 3; i++) {
            replace(bingo.at(i).begin(), bingo.at(i).end(), b, -1);
        }
    }
    bool isb = false;
    if (bingo[0][0] == -1) {
        if ((bingo[0][1] == -1 && bingo[0][2] == -1) ||
            (bingo[1][0] == -1 && bingo[2][0] == -1) ||
            (bingo[1][1] == -1 && bingo[2][2] == -1)) {
                isb = true;
            }
    } else if (  
        (bingo[0][1] == -1 && bingo[1][1] == -1 && bingo[2][1] == -1) ||
        (bingo[0][2] == -1 && bingo[1][2] == -1 && bingo[2][2] == -1) ||
        (bingo[1][0] == -1 && bingo[1][1] == -1 && bingo[1][2] == -1) ||
        (bingo[2][0] == -1 && bingo[2][1] == -1 && bingo[2][2] == -1) ||
        (bingo[0][2] == -1 && bingo[1][1] == -1 && bingo[2][0] == -1)) {
            isb = true;
    }
    cout << (isb ? "Yes" : "No") << endl;
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
#define fi first
#define se second
using namespace std;

const int mod = 1000000007;

map <int, vector <int> > mp;
int sum[500010];

long long power(long long a, long long b){
	if (!b) return 1;
	long long t = power(a, b >> 1);
	return b & 1 ? t * t % mod * a % mod : t * t % mod;
}

int main(){
	int n; scanf("%d", &n);
	for (int i = 1; i <= n; i++){
		int x; scanf("%d", &x);
		sum[i] = sum[i - 1] ^ x;
		mp[sum[i]].push_back(i);
	}
	if (sum[n] != 0){
		vector <int> a = mp[0], b = mp[sum[n]];
		int m = b.size() * 2;
		b.push_back(0x3f3f3f3f);
		vector <long long> sum1(m + 1, 0), sum2(m + 1, 0), dp(m + 1, 0);
		dp[0] = 1, sum2[0] = 1;
		long long res = 0;
		for (int i = 1; i <= m - 1; i++){
			int cnt;
			if (i & 1) cnt = 1;
			else {
				vector <int> :: iterator pos1 = lower_bound(a.begin(), a.end(), b[i + 1 >> 1]);
				cnt = pos1 - lower_bound(a.begin(), a.end(), b[i - 1 >> 1]);
			}
			if (i & 1){
				dp[i] = sum2[i - 1] * cnt % mod;
				sum2[i] = sum2[i - 1];
				sum1[i] = (sum1[i - 1] + dp[i]) % mod;
			} else {
				dp[i] = sum1[i - 1] * cnt % mod;
				sum1[i] = sum1[i - 1];
				sum2[i] = (sum2[i - 1] + dp[i]) % mod;
			}
			if (i == m - 1) res = sum2[i - 1];
		}
		printf("%lld\n", res);
		return 0;
	}
	long long ans = 0;
	vector <int> a = mp[0];
	for (map <int, vector <int> > :: iterator it = mp.begin(); it != mp.end(); it++){
		if (it->fi == 0){
			ans = (ans + power(2, it->se.size() - 1)) % mod;
			continue;
		}
		vector <int> b = it->se;
		int m = b.size() * 2;
		b.push_back(0x3f3f3f3f);
		vector <long long> sum1(m + 1, 0), sum2(m + 1, 0), dp(m + 1, 0);
		dp[0] = 1, sum2[0] = 1;
		long long res = 0;
		for (int i = 1; i <= m; i++){
			int cnt;
			if (i & 1) cnt = 1;
			else {
				vector <int> :: iterator pos1 = lower_bound(a.begin(), a.end(), b[i + 1 >> 1]);
				cnt = pos1 - lower_bound(a.begin(), a.end(), b[i - 1 >> 1]);
			}
			if (i & 1){
				dp[i] = sum2[i - 1] * cnt % mod;
				sum2[i] = sum2[i - 1];
				sum1[i] = (sum1[i - 1] + dp[i]) % mod;
			} else {
				dp[i] = sum1[i - 1] * cnt % mod;
				sum1[i] = sum1[i - 1];
				sum2[i] = (sum2[i - 1] + dp[i]) % mod;
			}
			if (i == m) res = sum1[i - 1];
		}
		ans = (ans + res) % mod;
	}
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 34932
#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define pdi pair<db,int>
#define mp make_pair
#define pb push_back
#define enter putchar('\n')
#define space putchar(' ')
#define eps 1e-8
#define mo 974711
#define MAXN 200005
//#define ivorysi
using namespace std;
typedef long long int64;
typedef double db;
template<class T>
void read(T &res) {
    res = 0;char c = getchar();T f = 1;
    while(c < '0' || c > '9') {
    if(c == '-') f = -1;
    c = getchar();
    }
    while(c >= '0' && c <= '9') {
    res = res * 10 + c - '0';
    c = getchar();
    }
    res *= f;
}
template<class T>
void out(T x) {
    if(x < 0) {x = -x;putchar('-');}
    if(x >= 10) {
    out(x / 10);
    }
    putchar('0' + x % 10);
}
int H,W,N;
vector<int> v[MAXN];
bool pass[MAXN];
void Solve() {
    read(H);read(W);read(N);
    int x,y;
    for(int i = 1 ; i <= N ; ++i) {
	read(x);read(y);
	v[y].pb(x);
    }
    for(int i = 1 ; i <= W ; ++i) v[i].pb(H + 1);
    sort(v[1].begin(),v[1].end());
    int ans = v[1][0] - 1;
    int t = 0;
    for(int i = 2 ; i <= W ; ++i) {
	sort(v[i].begin(),v[i].end());
	int s = v[i].size();
	int m = 0;
	for(int k = 0 ; k < s ; ++k) {
	    if(v[i][k] <= i + t) {pass[v[i][k]] = 1;m = max(v[i][k],m);}
	    else if(pass[v[i][k] - 1]) {pass[v[i][k]] = 1;m = max(v[i][k],m);}
	    else {
		ans = min(ans,v[i][k] - 1);
		break;
	    }
	}
	t = max(t,m - i + 1);
    }
    out(ans);enter;
}
int main() {
#ifdef ivorysi
    freopen("f1.in","r",stdin);
#endif
    Solve();
}


Measured memory_bytes: 11520
#include<stdio.h>
#include<string.h>
int main()
{

    while(1)
    {
        int i,n=0;
    char x[1000];
        scanf("%s",&x);
        if(x[0]=='0')
            break;
        else
        {
            for(i=0;i<strlen(x);i++)
            {
                n+=x[i]-'0';
            }
            printf("%d\n",n);
        }
    }
    return 0;
}




Measured memory_bytes: 2100
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define INF 1<<30
#define LINF 1LL<<60

int main(void) {
    cin.tie(0); ios::sync_with_stdio(false);
    int L; cin >> L;
    string s,t;cin >> s >> t;
    if(t + s < s + t) swap(s,t);
    string ans;
    for(int i = L; i >= 0; i--){
        ll len = s.length() * i;
        if(L - len >= 0 && (L - len)%t.length() == 0){
            for(int j = 0; j < i;j++){
                ans += s;
            }
            for(int j = 0; j < (L-len)/t.length();j++){
                ans += t;
            }
            break;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1684
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
using namespace std;
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int,int>;
const ll inf = 1e18;

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

int main() {
    int K;
    cin >> K;
    ll sum = 0;
    REP(i,K+1)REP(j,K+1)REP(k,K+1) {
        sum += gcd(gcd(i,j),k);
    }
    cout << sum << endl;
}

Measured memory_bytes: 3636
(require '[clojure.string :as str])

(defn getCharIdx [s c sidx]
  (if (nil? sidx) nil
      (str/index-of s c sidx)))

(defn inc2 [a]
  (if (nil? a) nil
      (inc a)))

(defn luckyPin2 [n s]
  (->>
   (for [i (range 1000)
         :let [a (format "%03d" i)
               a0 (get a 0)
               a1 (get a 1)
               a2 (get a 2)]
          :when (some? 
                 (getCharIdx s a2
                              (inc2 (getCharIdx s a1
                                              (inc2 (getCharIdx s a0 0))))))
         ]
     a)
   (count)
   ))

(println (luckyPin2 (read-line) (read-line)))


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

using ll = long long;
using db = double;
using pii = pair < int, int >;
using pll = pair < ll, ll >;
const int N = 2e5 + 10;
const ll inf = 1e15 + 42;
#define endl "\n"

void testCase() {
    int n;
    cin >> n;
    ll arr[n+1];
    for (int i=0; i<n; i++)
        cin >> arr[i];
    ll dp[n+3];
    for (int i=0; i<=n; i++)
        dp[i] = inf;
    dp[n-1] = 0;
    for (int i=n-1; i>0; i--) {
        if (i-1 >= 0)
            dp[i-1] = min (dp[i-1], dp[i]+abs(arr[i]-arr[i-1]));
        if (i-2 >= 0)
            dp[i-2] = min (dp[i-2], dp[i]+abs(arr[i]-arr[i-2]));
    }
    cout << dp[0] << endl;
}

int main() {
    ios_base :: sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    testCase();
    return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <cmath>
#include <vector>
#include <queue>
#include <iomanip>
using namespace std;
using ll = long long;

const long double PI = acos(-1.0);
const int MOD = 1e9 + 7;
const int INF = 1001001001;

vector<vector<int>> list;

int main() {
    int n, x, y;
    cin >> n >> x >> y;
    x--;  y--;

    list.resize(n);
    for(int i = 0; i < n - 1; i++) {
        list[i].push_back(i + 1);
        list[i + 1].push_back(i);
    }
    list[x].push_back(y);
    list[y].push_back(x);

    int ans[n] = {};

    for(int sv = 0; sv < n; sv++) {
        vector<int> dist(n, INF);
        queue<int> q;
        q.push(sv);
        dist[sv] = 0;
        while(!q.empty()) {
            int v = q.front();
            q.pop();
            for(int u : list[v]) {
                if(dist[u] != INF) continue;
                dist[u] = dist[v] + 1;
                q.push(u);
            }
        }
        for(int i = 0; i < n; i++) ans[dist[i]]++;
    }

    for(int i = 1; i < n; i++) {
        ans[i] /= 2;
        cout << ans[i] << endl;
    }

    return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
#include <list>
#include <stack>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#define mkp(a, b) make_pair(a, b)
#define pb(t) push_back(t)
#define ft first
#define sc second
#define pt(num) cout << num << "\n"
#define moC(a, s, b) (a)=((a)s(b)+MOD)%MOD
#define max(a, b) ((a)>(b) ? (a):(b))
#define min(a, b) ((a)<(b) ? (a):(b))
#define chmax(a, b) (a<b ? a=b : 0)
#define chmin(a, b) (a>b ? a=b : 0)
#define INF 1000000000000000000
#define MOD 1000000007LL
#define MAX 101010
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef map<ll, ll> Map;

string s, t;
ll dp[3333][3333];

void printLCS(ll i, ll j) {
    if(i==0 || j==0) return;
    
    if(s[i-1]==t[j-1]) {
        printLCS(i-1, j-1);
        cout << s[i-1];
    }else if(dp[i-1][j]>=dp[i][j-1])
        printLCS(i-1, j);
    else
        printLCS(i, j-1);
}

int main(void) {
    cin >> s >> t;
    ll N=s.size();
    ll M=t.size();
    ll i, j;
    
    for(i=1; i<=N; i++) {
        for(j=1; j<=M; j++) {
            if(s[i-1]==t[j-1])
                dp[i][j]=dp[i-1][j-1]+1;
            else
                dp[i][j]=max(dp[i][j-1], dp[i-1][j]);
        }
    }
    printLCS(N, M);
}





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

long long n;
long long x[112];


int main(){
    ios_base::sync_with_stdio(0);
    //freopen("input.txt","r",stdin);

    cin>>n;

    for(int i=0;i<n;i++)cin>>x[i];
    long long res = 1e18;
    for(int p=1;p<=100;p++){
        long long sum = 0;
        for(int i=0;i<n;i++){
            sum += (x[i] - p)*(x[i] - p);
        }
        res = min(res, sum);
    }
    cout << res;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }
#define printpair(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<"{"<<_.first<<","<<_.second<<"}"<<", "; cerr<<"]"<<endl; }
#define bit(k) (1LL<<(k))
typedef long long ll;

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

const int INF = 1e9;
const ll INFLL = 1e18;
const ll MOD = 1e9+7;
const double PI = acos(-1.0);

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

/*------------------------------------/
for library*/

/*------------------------------------*/

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    int N;
    ll D,A;
    cin>>N>>D>>A;
    vector<pair<ll,ll>> XH;
    rep(i,N){
        int x,h;
        cin>>x>>h;
        XH.push_back({x,h});
    }
    sort(all(XH));
    vector<ll> X(N),H(N);
    rep(i,N){
        X[i] = XH[i].first;
        H[i] = XH[i].second;
    }
    //今までの爆発でいくら減っているかを持つためのimos配列
    vector<ll> Attack(N+1, 0);

    ll ans = 0;
    rep(i,N){
        //残りの体力
        int rem = H[i] - Attack[i];
        if(rem > 0){
            int need_cnt = (rem + A - 1)/A;
            int right_x = X[i] + 2 * D;
            int right_id = upper_bound(all(X), right_x) - X.begin();
            //[X[i], X[right_id])の区間爆発が起こるので、
            //imosの配列であるAttack[i]に+
            //Attack[right_id]に-
            Attack[i] += need_cnt * A;
            Attack[right_id] -= need_cnt * A;
            ans += need_cnt;
        }
        Attack[i+1] += Attack[i];
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 8940
#include <iostream>
#include <string>

using namespace std;

int main() {
  for ( ; ; ) {
    string s;
    cin >> s;
    if (0 == s.compare("-")) break;
    int m;
    cin >> m;
    size_t h = 0;
    size_t tmp;
    for (int i = 0; i < m; ++i) {
      cin >> tmp;
      h += tmp;
    }
    h %= s.length();
    string result(s.substr(h) + s.substr(0, h));
    cout << result << endl;
  }
  return 0;
}



Measured memory_bytes: 3216
#!usr/bin/env python3
from collections import defaultdict
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
mod = 1000000007

#A
"""
a,b,c = LI()
print(min(b//a,c))
"""

#B
"""
a,b,k = LI()
i = 1
ans = [1]
while i <= min(a,b):
    i += 1
    if a%i == 0 and b%i == 0:
        ans.append(i)
print(ans[-k])
"""

#C
s = list(map(int,S()))
print(2*min(sum(s),len(s)-sum(s)))

#D
"""
def root(x):
    if par[x] == x:
        return x
    par[x] = root(par[x])
    return par[x]
def unite(x,y):
    x = root(x)
    y = root(y)
    if x == y:
        ans.append(ans[-1])
        return
    sx = s[x]
    sy = s[y]
    if rank[x] < rank[y]:
        par[x] = y
        s[y] += sx
    else:
        par[y] = x
        if rank[x] == rank[y]:
            rank[x] += 1
        s[x] += sy
    ans.append(ans[-1]+sx*sy)
n,m  = LI()
v = LIR(m)
v = v[::-1]
par = [i for i in range(n)]
rank = [0 for i in range(n)]
s = [1 for i in range(n)]
ans = [0]
k = n*(n-1)//2
v.pop(-1)
for a,b in v:
    if ans[0] == k:
        ans.append(k)
        continue
    a -= 1
    b -= 1
    unite(a,b)
for i in ans[::-1]:
    print(k-i)
"""
#E
"""
n,a,b = LI()
s = input()
ans = 0
i = 0
while i < n:
    j = i+1
    if s[i:j] in s[:i]:
        while s[i:j] in s[:i]:
            j += 1
            if j >= n-1:break
        ans += min(b,a*(j-i))
    else:
        ans += a*(j-i)
    i = j
print(ans)
"""
#F

#G

#H

#I

#J

#K

#L

#M

#N

#O

#P

#Q

#R

#S

#T


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

const int sq = 30000;
int ans, n;

int sg(int x, int k) {
	if (x % k == 0)return x / k;
	if (x / k > sq)return sg(x - x / k - 1, k);
	else {
		int m1 = x % k;
		return sg(x - max(x / k + 1, m1 - m1 % (x / k + 1)), k);
	}
}

int main() {
	cin >> n;
	for (int i = 1; i <= n; i++) {
		int x, k;
		scanf("%d%d", &x, &k);
		ans ^= sg(x, k);
	}
	cout << (ans ? "Takahashi" : "Aoki") << endl;

	return 0;
}

Measured memory_bytes: 256
n, k = map(int, input().split())
lr = [list(map(int, input().split())) for _i in range(k)]
mod = 998244353

dp = [0]*(n+1)
dp[1] = 1

for p in range(2, n+1):
    for i, j in lr:
        dp[p] += dp[max(p-i, 0)] - dp[max(p-j-1, 0)]
        dp[p] %= mod
    dp[p] += dp[p-1]

print((dp[n]-dp[n-1])%mod)

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

int n;
vector<int> A(50);

bool calc(int i, int m){
  if(m == 0) return true;
  if(i > n) return false;

  int ans = calc(i+1, m) || calc(i+1, m - A[i]);
  return ans;

}

int main()
{
  cin >> n;

  for(int i = 0; i < n; i++) cin >> A[i];

  int q;
  cin >> q;
  for(int i = 0; i < q; i++){
    int x;
    cin >> x;

    if(calc(0, x)) cout << "yes" << endl;
    else cout << "no" << endl;

  }

  return 0;

}




Measured memory_bytes: 3092
#include <stdio.h>
#include <stdlib.h>

int partition(int *);

int n;

int main(){
  int i,x;
  int *A;

  scanf("%d",&n);

  A = (int *)malloc(sizeof(int)*n);

  for(i = 0; i < n; i++)
    scanf("%d",&A[i]);

  x =  partition(A);

  for(i = 0; i < n; i++){
    if(i == n-1) printf("%d",A[i]);
    else{
    if(i == x) printf("[%d] ",A[i]);
    else printf("%d ",A[i]);
    }
  }
  printf("\n");

  return 0;
}

int partition(int *A)
{
  int x,i,j,k=0,num;

  x = A[n-1];
  i = -1;
  j = 0;

  while(k != n){
    if(A[j] > x) j++;
    else if(A[j] <= x){
      i++;
      num = A[i];
      A[i] = A[j];
      A[j] = num;
      j++;
    }
    k++;
  }
  return i;
}


	

Measured memory_bytes: 3044
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi vector<vector<int> >
#define vvl vector<vector<ll> >
#define vll vector<ll>
typedef long long int ll;
typedef long double ld;
using namespace std;

int main(int argc, char const *argv[]) {
  ll n;std::cin >> n;
  set<ll> num;
  for(int i=4;i<=1000000;i*=2) num.insert(i);
  bool flag = true;
  if(n==1||n==2) flag = false;
  if((n%2==0&&(num.upper_bound(n)!=num.upper_bound(n-2)))) flag = false;
  if(!flag){
    std::cout << "No" << '\n';
    return 0;
  }
  std::cout << "Yes" << '\n';
  std::cout << "1 2" << '\n';
  std::cout << "2 3" << '\n';
  std::cout << "3 " << 1+n << '\n';
  std::cout << 1+n << " " << 2+n << '\n';
  std::cout << 2+n << " " << 3+n << '\n';
  if(n==6){
    std::cout << 5 << " " << 6 << '\n';
    std::cout << 6 << " " << 3 << '\n';
    std::cout << 3 << " " << 11 << '\n';
    std::cout << 11 << " " << 12 << '\n';
    std::cout << 4 << " " << 11 << '\n';
    std::cout << 2 << " " << 10 << '\n';
    return 0;
  }
  if(n%2==1){
    for(int i=4;i<=n;i+=2){
      std::cout << i << " " << i+1  << '\n';
      std::cout << i+1 << " " << 2 << '\n';
      std::cout << 3 << " " << i+n << '\n';
      std::cout << i+n << " " << i+n+1 << '\n';
    }
  }else{
    for(int i=4;i<=n-5;i+=2){
      std::cout << i << " " << i+1  << '\n';
      std::cout << i+1 << " " << 2 << '\n';
      std::cout << 3 << " " << i+n << '\n';
      std::cout << i+n << " " << i+n+1 << '\n';
    }
    std::cout << n-1 << " " << n << '\n';
    std::cout << n << " " << (n^(n-1)) << '\n';
    std::cout << (n^(n-1)) << " " << 2*n-1 << '\n';
    std::cout << 2*n-1 << " " << 2*n << '\n';
    std::cout << n-4 << " " << n-3  << '\n';
    std::cout << n-3 << " " << n-2  << '\n';
    std::cout << n-2 << " " << n-1  << '\n';
    std::cout << n-1 << " " << 2*n-4  << '\n';
    std::cout << 2*n-4 << " " << 2*n-3  << '\n';
    std::cout << 2*n-3 << " " << 2*n-2  << '\n';
  }
  return 0;
}


Measured memory_bytes: 2304
#include<iostream>
#include<queue>
#include<vector>
using namespace std;

int main(){
    int n, l, a;
    cin >> n >> l;
    
    priority_queue<pair<int,int>> pq;
    vector<int> ans;
    for(int i = 0; i < n; i++){
        cin >> a;
        pq.push({-a, i});
        if(i >= l-1){
            while(pq.top().second < i-(l-1))    pq.pop();
            ans.push_back(-pq.top().first);
        }
    }

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


Measured memory_bytes: 18528
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_map>
#include<climits>
#include<cstdlib>
#include<cmath>
#include<string>
#include<iomanip>

using namespace std;

#define INF 1 << 29
#define LL long long int

LL const MOD = 1000000007;

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

    LL n,m,x,y;

    cin >> n >> m >> x >> y;

    for(int i = 0; i < n; i++){
        LL a;
        cin >> a;
        x = max(x,a);
    }

    for(int i = 0; i < m; i++){
        LL a;
        cin >> a;
        y = min(y,a);
    }

    if(x < y){
        cout << "No War" << endl;
    }else{
        cout << "War" << endl; 
    }
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include<string>
using namespace std;
char element[] = "abcdefghijklmnopqrstuvwxyz";
int main() {
    char cha;
    cin >> cha;
    char* p = nullptr;
    p = &element[0];
    while(1){
        if (p[0] == cha) {
            cout << ++p[0];
            break;
        }
      p++;
    }
}

Measured memory_bytes: 256
#include <atcoder/math>
#include <bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()
#ifdef _DEBUG_
  #define debug(...) printf(__VA_ARGS__)
#else
  #define debug(...) (void)0
#endif
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;

constexpr ll INF = 1e18;

vector<ll> fac;
ll solve(int n, ll x, ll y) {
  if (n == SZ(fac)) {
    if (x == 1)
      return INF;
    auto r = atcoder::crt({1ll, 0ll}, {x, y});
    debug("%lld %lld -- %lld, %lld\n", x, y, r.F, r.S);
    if (r.F <= 1)
      return INF;
    return r.F - 1;
  }
  return min(solve(n + 1, x * fac[n], y), solve(n + 1, x, y * fac[n]));
}

int main() {
  ll N;
  cin >> N;
  if (N == 1) {
    cout << 1 << endl;
    return 0;
  }
  N *= 2;
  for (ll i = 2; i * i <= N; i++) {
    ll val = 1;
    while (N % i == 0) {
      val *= i;
      N /= i;
    }
    if (val > 1)
      fac.PB(val);
  }
  if (N > 1)
    fac.PB(N);
  ll ans = solve(0, 1, 1);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3628