akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
int main(void){
    int x,y;
    while(1){
    scanf("%d %d",&x,&y);
    if(x==0&&y==0)break;
    if(x>=y){
        printf("%d %d\n",y,x);
    }
    else{
        printf("%d %d\n",x,y);
    } 
    }
    
    return 0;
}



Measured memory_bytes: 2032
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    cin>>s;
    int l=s.size();
    int i,c=0,mv=0;
    for(i=0;i<l;i++){
        if(s[i]=='R')
            c++;
        else
            c--;
        if(c==4){
            mv++;
            c=0;
        }
        if(c==-4)
            c=0;
    }
    cout<<mv<<endl;
    return 0;
}



Measured memory_bytes: 3224
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
const int inf = 1e9 + 7;
const ll INF = 1e18;
#define abs(x) (x >= 0 ? x : -(x))
#define lb(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define ub(v, x) (int)(upper_bound(all(v), x) - v.begin())
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
template<typename T> T pow(T a, int b) { return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
const int mod = 1000000007;
ll modpow(ll a, int b, int _mod) { return b ? modpow(a * a % _mod, b / 2, _mod) * (b % 2 ? a : 1) % _mod : 1; }
template<class T> ostream& operator<<(ostream& os, const vector<T>& vec) { for (auto &vi: vec) os << vi << " "; return os; }
template<class T, class U> ostream& operator<<(ostream& os, const pair<T, U>& p) { os << p.F << " " << p.S; return os; }
template<class T> inline void add(T &a, int b) { a += b; if (a >= mod) a -= mod; }



void solve();

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

    int T;
    // cin >> T;
    T = 1;

    while (T--) {
        solve();
    }
}


struct edge { int to, cost; };

const int maxn = 200005;
vector<edge> G[maxn];
ll dp[maxn];
int n, m;

void dfs(int v, int p) {
  ll ret = 1;
  for (edge& e : G[v]) {
    if (e.to == p) continue;
    dfs(e.to, v);

    (ret *= dp[e.to] + 1) %= m;
  }
  dp[v] = ret;
}

vector<ll> ans(maxn);

void dfs2(int v, int Dpar, int p) {
  int n2 = sz(G[v]);
  vector<ll> mul(n2 + 1, 1), mul2(n2 + 1, 1);
  ll ret = 1;

  rep(i, n2) {
    edge e = G[v][i];
    if (e.to == p) {
      (ret *= Dpar + 1) %= m;
      if (i) (mul[i - 1] *= Dpar + 1) %= m;
      (mul2[i + 1] *= Dpar + 1) %= m;
    } else {
      (ret *= dp[e.to] + 1) %= m;
      if (i) (mul[i - 1] *= dp[e.to] + 1) %= m;
      (mul2[i + 1] *= dp[e.to] + 1) %= m;
    }
  }
  for (int i = n2 - 2; i >= 0; --i) (mul[i] *= mul[i + 1]) %= m;
  rep3(i, 1, n2) (mul2[i] *= mul2[i - 1]) %= m;
  rep(i, n2) (mul[i] *= mul2[i]) %= m;
  // cout << endl << v << endl << mul << endl;

  ans[v] = ret;
  rep(i, n2) {
    edge e = G[v][i];
    if (e.to == p) continue;
    dfs2(e.to, mul[i], v);
  }
}

void solve() {
  cin >> n >> m;
  rep(i, n - 1) {
    int a, b;
    cin >> a >> b;
    // a = i + 1; b = i + 2;
    a--; b--; // debuged
    G[a].eb(edge{b, 1});
    G[b].eb(edge{a, 1});
  }
  dfs(0, -1);
  // rep(i, n) cout << dp[i] << " "; cout << endl;
  dfs2(0, 0, -1);
  rep(i, n) cout << ans[i] << endl;
}


Measured memory_bytes: 23040
#include <stdio.h>

int main(void){
	int x1,y1,x2,y2,x3,y3,x4,y4;
	
	scanf("%d %d %d %d",&x1,&y1,&x2,&y2);
	x3 = x2 - (y2 - y1);
	y3 = y2 + (x2 - x1);
	x4 = x1 - (y2 - y1);
	y4 = y1 + (x2 - x1);
	printf("%d %d %d %d",x3,y3,x4,y4);
	return 0;
}

Measured memory_bytes: 128
h,w,d = map(int,input().split())
dic = {}

for y in range(h):
    line = list(map(int,input().split()))
    for x in range(w):
        num = line[x]
        dic[num] = (x,y)

com_sum = [0]*(h*w + 1)

for n in range(1,d+1):
    com_sum[n] = 0
    while n+d <= h*w:
        nx,ny = dic[n+d]
        x,y = dic[n]
        com_sum[n+d] = com_sum[n] + abs(nx-x) + abs(ny-y)
        n += d
    
Q = int(input())
for q in range(Q):
    l,r = map(int,input().split())
    print(com_sum[r] - com_sum[l])

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

#include <bits/stdc++.h>
#define DEBUG true
#ifdef ONLINE_JUDGE
#undef DEBUG
#define DEBUG false
#endif 

using namespace std;

#define TRACE(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); cerr << endl;}

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << "[" << *it << " = " << a << "]";
	err(++it, args...);
}

#define MAXN ((int)2e5+5)
#define MOD ((int)1e9 + 7)
#define INF ((int)1e9 + 9)
#define ll long long
#define _ << " " <<
#define CLEAR(a, b) memset(a, b, sizeof(a))
#define LOG(x) if(DEBUG) cerr << x << endl;
#define pb push_back
#define all(x) x.begin(), x.end()
#define endl "\n"
#define pii pair<int,int>
#define mid ((l+r)/2)

ll sum;
map <ll, ll> mp;

void solve()
{
	ll b,c;
	cin >> b >> c;

	sum += mp[b] * (c-b);
	mp[c] += mp[b];
	mp[b] = 0;

	cout << sum << endl;
}

int main()
{
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	ll n;
	cin >> n;
	for (int i = 0; i < n; ++i)
	{
		ll a;
		cin >> a;
		mp[a]++;
	}

	for(auto x : mp)
		sum += x.first * x.second;

	ll q;
	cin >> q;
	while(q--)
		solve();
}

/* stuff you should look for
	* int overflow, array bounds
	* special cases (n=1?)
	* do smth instead of nothing and stay organized
	* WRITE STUFF DOWN
*/

Measured memory_bytes: 9452
//abc163D
int main(void) {
  long long n, k, i, mod=1000000007,sum=0;
  scanf(" %lld %lld", &n,&k);
  for(i=k; i <=n+1; i++) sum=(sum+(n+1-i)*i+1)%mod;
  printf("%lld",sum);
  return 0;
}

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

#define SZ 105
int a[SZ];

int main(){

    int N, K, dis;
    int val;

    dis = 0;
    scanf("%d%d", &N, &K);
    for(int i = 0; i < N; i++){
        scanf("%d", &val);

        int A = abs(val - 0);
        int B = abs(K - val);

        dis += min(A, B);
    }

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

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	int t=1;
	while(t--){
		int n;
		cin>>n;
		int a[n];
		int dp[n];
		for(int i=0;i<n;i++){
			cin>>a[i];
		}
		dp[0]=0;
		if(n>1)
			dp[1]=abs(a[0]-a[1]);
		for(int i=2;i<n;i++){
			dp[i]=min(dp[i-1]+abs(a[i]-a[i-1]),dp[i-2]+abs(a[i]-a[i-2]));
		}
		cout<< dp[n-1]<<endl;
		

	}
	return 0;
}

Measured memory_bytes: 1024
// Author : harry
// Language : C++ 
// Time : 2018.9.23
// Problem : A - Maximize the Formula
// Tell Myself : Think Twice Code Once
// All rights reserved by harry

#include <map>
#include <set>
#include <cmath>
#include <ctime>
#include <queue>
#include <stack>
#include <vector>
#include <bitset>
#include <cstdio>
#include <cctype>
#include <string>
#include <cstring>
#include <cassert>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std ;

#define rep(i, a, b) for (int (i)=(a);(i)<=(b);(i)++)
#define Rep(i, a, b) for (int (i)=(a)-1;(i)<(b);(i)++)
#define REP(i, a, b) for (int (i)=(a);(i)>=(b);(i)--)
#define reg(i, x) for (int (i)=head[x];(i);i=e[i].next)
#define clear(a) memset(a,0,sizeof(a))

#define ull unsigned long long
#define ll long long
#define ls ((rt) << 1)
#define rs ((rt) << 1 | 1)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define endl '\n'
#define Pii pair<int, int>

const int N = 100010 ;
const int iinf = INT_MAX/2 ;
const ll linf = LONG_MAX/2 ;
const int MOD = 1e9+7 ;

inline int read(){
    int X = 0,w = 0 ;
	char ch = 0;
    while(!isdigit(ch)) {w |= ch == '-';ch = getchar();}
    while(isdigit(ch)) X = (X<<3) + (X<<1) + (ch ^ 48),ch = getchar();
    return w ? -X : X;
}

void write(int x){
     if(x < 0) putchar('-'),x = -x;
     if(x > 9) write(x / 10);
     putchar(x%10 + '0');
}

int a,b,c,x ;

int main(){
	scanf("%d%d%d",&a,&b,&c) ;
	x=max(a,max(b,c)) ;
	cout<<x*10+(a+b+c-x)<<endl ;
}


Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static System.Math;

public static class P
{
    public static void Main()
    {
        var lrd = Console.ReadLine().Split().Select(int.Parse).ToArray();
        var l = lrd[0];
        var r = lrd[1];
        var d = lrd[2];
        int res = 0;
        for (int i = l; i <= r; i++)
            if (i % d == 0) res++;
        Console.WriteLine(res);
    }
}


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

int main() 
{
    int n;
    string s;
    cin >> n >> s;

    int C[26*3];
    rep(i,26) {
        C[i] = i;
        C[i + 26] = i;
        C[i + 26*2] = i;
    }

    vector<char> CH;
    for (char ch : s) {
        int idx = ch - 'A';
        idx = C[idx+n];
        CH.push_back((char)(idx + 'A'));
    }

    rep(i,CH.size()) cout << CH[i];
    cout << endl;

    return 0;
}


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

int main(){
  int x;
  cin>>x;
  if(x>=400&&x<=599){
    cout<<8<<endl;
  }
  else if(x>=600&&x<=799){
    cout<<7<<endl;
  }
  else if(x>=800&&x<=999){
    cout<<6<<endl;
  }
  else if(x>=1000&&x<=1199){
    cout<<5<<endl;
  }
  else if(x>=1200&&x<=1399){
    cout<<4<<endl;
  }
  else if(x>=1400&&x<=1599){
    cout<<3<<endl;
  }
  else if(x>=1600&&x<=1799){
    cout<<2<<endl;
  }
  else if(x>=1800&&x<=1999){
    cout<<1<<endl;
  }
}
  
  
  
  

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

#define mp make_pair
#define fi first
#define se second
#define pb push_back

typedef long long ll;
typedef pair<int,int> ii;
typedef pair<ii,int> iii;
typedef pair<ll,ll> pll;

int ar[5];

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    for (int i = 0; i < 5; i++)
    {
        cin >> ar[i];
    }
    for (int i = 0; i < 5; i++)
    {
        if (ar[i] == 0)
        {
            cout << i+1 << '\n';
            return 0;
        }
    }
    return 0;
}

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

using namespace std;

#define X first
#define Y second
#define eps  1e-5
#define gcd __gcd
#define pb push_back
#define PI acos(-1.0)
#define lowbit(x) (x)&(-x)
#define bug printf("!!!!!\n");
#define mem(x,y) memset(x,y,sizeof(x))

typedef long long LL;
typedef long double LD;
typedef pair<int,int> pii;
typedef unsigned long long uLL;

const int maxn = 1e5+7;
const int INF  = 1<<30;
const int mod  = 1e9+7;

int v[maxn];
priority_queue<double>Q;
void solve(){
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)cin>>v[i],Q.push(-v[i]);
    double res = 0;
	while(Q.size()>1){
		double x = -Q.top();Q.pop();
		double y = -Q.top();Q.pop();
		Q.push(-(x+y)/2.0);
	}
	printf("%.10f\n",-Q.top());
    return;
}

int main()
{
#ifndef ONLINE_JUDGE
    //freopen("in.txt","r",stdin);
#endif
//    freopen("out.txt","w",stdout);
//    ios::sync_with_stdio(false);
    int t = 1;
    //scanf("%d",&t);
    while(t--){
    //    printf("Case %d: ",cas++);
        solve();
    }
#ifndef ONLINE_JUDGE
    //printf("%.10f\n",1.0*clock()/CLOCKS_PER_SEC);
#endif
    return 0;
}

Measured memory_bytes: 256
import javax.management.Query;
import javax.print.attribute.SupportedValuesAttribute;
import java.io.*;
import java.lang.reflect.Array;
import java.security.interfaces.DSAKeyPairGenerator;
import java.util.*;
import java.util.function.Predicate;


public class Main {

    static class TaskB {

        public void solve(InputReader in, PrintWriter out) {
            String s= in.next();
            int cnt = 0;
            int ans = 0;
            for(int i = 0; i < 3; i++)
            {
                if(s.charAt(i)=='R')cnt++;
                else cnt = 0;
                ans  = Math.max(ans, cnt);
            }
            out.print(ans);
        }
    }


    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(in, out);
        out.close();
    }



    static void sort(int[] a)
    {
        ArrayList<Integer> list = new ArrayList<>();
        for(int i: a)list.add(i);
        Collections.sort(list);
        for(int i = 0; i < a.length; i++)a[i]=list.get(i);
    }


    static class InputReader {
        private BufferedReader reader;
        private StringTokenizer tokenizer = new StringTokenizer("");

        public InputReader(InputStream inputStream) {
            this.reader = new BufferedReader(
                    new InputStreamReader(inputStream));
        }

        public String next() {
            while (!tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return tokenizer.nextToken();
        }

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

        public long nextLong() {
            return Long.parseLong(next());
        }

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

Measured memory_bytes: 32928
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i < (n); i++)
#define all(v) (v).begin(), (v).end()
using namespace std;
typedef long long LL;
const LL INF = 999999999999;


int main(){
    string buff;
    int n, k;
    cin >> n >> k;
    vector<vector<int>> G(n+1);
    vector<pair<int, int>> E;
    for(int i=1; i<=n; i<<=1){
        rep1(j, n+1){
            if(i != j && i&j){
                E.emplace_back(i, j);
                G[i].push_back(j);
                G[j].push_back(i);
            }
        }
    }
    cout << E.size() << endl;
    rep(i, E.size()){
        cout << E[i].first << " " << E[i].second << endl;
    }
    rep(q, k){
        int ans = 0;
        bool f = 0;
        for(int i=1; i<=n; i<<=1){
            cout << i << endl;
            cin >> buff;
            if(buff != "No") ans += i;
            if(buff == "Yes"){
                f = 1;
                break;
            }
        }
        if(!f){
            cout << ans << endl;
            cin >> buff;
            assert(buff == "Yes");
        }
    }
}



Measured memory_bytes: 3308
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <climits>
#include <cmath>
#include <map>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++ )
#define repf(i,m,n) for(int (i)=m;(i)<n;(i)++)
#define all(v) (v).begin(), (v).end()
#define ll long long
#define vec(name,num) vector<ll> name((num),0);
#define op(i) cout<<(i)<<endl;
#define ip(i) cin>>(i);
#define opN cout<<"No"<<endl;
#define opY cout<<"Yes"<<endl;
#define opP cout<<"Possible"<<endl;
#define opI cout<<"Impossible"<<endl;
#define mat(name,fnum,snum); vector<vector<ll>> name((fnum),vector<ll>((snum),0));
#define debugP int debug_point; cin>>debug_point;
const ll MOD= 1e9 + 7;
template <typename T>
void putv(vector<T>& V){
	// cout << "The elements in the vector are: " << endl;
	for(auto x: V)
		cout << x << " ";
	cout << endl;
}


template <class T>
vector<T> getv(ll n){
	vector<T> Vector_temp;
	rep(i,n){
		T input;
		cin >> input;
		Vector_temp.emplace_back(input);
	}
	return Vector_temp;
}
ll gcd(ll c,ll b){
    while(1){
        if(c%b!=0){
        ll tmp=b;
        b=c%b;
        c=tmp;
        }else{
            return b;
        }
    }
}
/* <3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3*/

int main(){
    vec(a,3);
    a=getv<ll>(3);
    sort(all(a));
    if(a[2]==a[1]&&a[1]==a[0]){
        op("Yes");
    }else op("No");
    return 0;
}

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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template < typename T >
void vprint(T &v){
	REP(i, v.size()){
		cout << v[i] << " ";
	}
	cout << endl;
}

int main(){
	ll N, K;
	cin >> N >> K;
	vector<ll> x(N);
	REP(i, N) cin >> x[i];

	ll res = 0;
	REP(i, N){
		res += 2*min(K-x[i], x[i]);
	}
	cout << res << endl;
    return 0;
}

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

// 素因数分解
map<int, ll> prime_factor(int n) {
    map<int, ll> res;
    for (int i=2;i*i<=n;++i) {
        while (n%i == 0) {
            ++res[i];
            n /= i;
        }
    }
    if (n != 1) res[n] = 1;
    return res;
}

int main() {
    ll N;
    cin >> N;
    map<int, ll> mp;
    for (int i=1; i<=N; ++i) {
        map<int, ll> tmp = prime_factor(i);
        for (auto& t : tmp) mp[t.first] += t.second;
    }

    ll ans = 0;
    for (auto& t1 : mp) {
        // 1つの数字だけで作れるか
        if (t1.second >= 74) {
            ans++;
        }
        for (auto& t2 : mp) {
            if (t2.first >= t1.first) continue;

            // 2つの数字
            // 3 * 25 or 15 * 5
            if (t1.second >= 2 and t2.second >= 2) {
                if (t1.second >= 24) ans++;
                if (t2.second >= 24) ans++;
            }
            if (t1.second >= 4 and t2.second >= 4) {
                if (t1.second >= 14) ans++;
                if (t2.second >= 14) ans++;
            }

            for (auto& t3 : mp) {
                if (t3.first >= t2.first) continue;
                // 3つの数字だけで作れるか
                int abc[3];
                abc[0] = t1.second;
                abc[1] = t2.second;
                abc[2] = t3.second;
                sort(abc, abc+3);
                reverse(abc, abc+3);
                if (abc[2] >= 2) {
                    if (abc[2] >= 4) ans += 3;
                    else if (abc[1] >= 4) ans += 1;
                }
            }
        }
    }

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


Measured memory_bytes: 256
import java.io.*;
import java.math.BigInteger;
import java.util.*;

/**
 * @author yoshikyoto
 */
class Main{
	static final boolean DEBUG = false;
	static Scanner sc = new Scanner(new InputStreamReader(System.in));
	static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	
	public static void main(String args[]) throws Exception{
		p(readLine().toUpperCase());
	}
		

	public static int[] readIntMap() throws IOException{return parseInt(readLine().split(" "));}
	public static String readLine() throws IOException{return br.readLine();}
	public static int readInt() throws IOException{return Integer.parseInt(br.readLine());}
	public static void pa(Object[] arr){System.out.println(Arrays.toString(arr));}
	public static void pa(int[] arr){System.out.println(Arrays.toString(arr));}
	public static void pa(double[] arr){System.out.println(Arrays.toString(arr));}
	public static void pa(boolean[] arr){System.out.println(Arrays.toString(arr));}
	public static void p(Object o){System.out.println(o.toString());}
	public static void pr(Object o){System.out.print(o.toString());}
	public static void e(Object o){System.err.println(o.toString());}
	public static void d(Object o){if(DEBUG)System.out.println(o.toString());}
	public static void da(int[] arr){if(DEBUG)System.out.println(Arrays.toString(arr));}
	public static void sort(int[] a){Arrays.sort(a);}
	public static int[] parseInt(String[] arr){
		int[] res = new int[arr.length];
		for(int i = 0; i < arr.length; i++)res[i] = Integer.parseInt(arr[i]);
		return res;
	}
	public static boolean[] parseBool(String[] arr){
		int[] t = parseInt(arr);
		boolean[] res = new boolean[t.length];
		for(int i = 0; i < t.length; i++){
			if(t[i] == 1){res[i] = true;
			}else{res[i] = false;}
		}
		return res;
	}
	public static int parseInt(Object o){return Integer.parseInt(o.toString());}
	public static int digit(int n){return String.valueOf(n).length();}
	public static String reverse(String s){
		StringBuffer sb = new StringBuffer(s);
		return sb.reverse().toString();
	}
	public static double sin(int r){return Math.sin(Math.toRadians(r));}
	public static double cos(int r){return Math.cos(Math.toRadians(r));}
}

/**
 * 整数を数え上げたりするクラス
 * Prime.calc(int n) でnまでエラトステネスの篩を実行。
 * @author yoshikyoto
 * @param a[i] iが素数の時true
 * @param count[i] i以下の素数の数
 */
class Prime{
	static boolean[] a;
	static int[] count;
	public static void calc(int n){
		a = new boolean[n+1];
		a[0] = false; a[1] = false;
		for(int i = 2; i <= n; i++) a[i] = true;
		// ふるい
		for(int i = 2; i < (n - 3) / 2; i++)
			if(a[i]) for(int j = 2; j * i <= n; j++)
					a[j * i] = false;
		
		// 数え上げ
		count = new int[n+1];
		count[0] = 0;
		for(int i = 1; i <= n; i++){
			int gain = 0;
			if(a[i]) gain = 1;
			count[i] = count[i-1] + gain;
		}
	}
}

class AI extends ArrayList<Integer>{}
class SI extends Stack<Integer>{}

class HI<E> extends HashMap<E, Integer>{
	ArrayList<E> keyArray = new ArrayList<E>();
	public void add(E key){add(key, 1);}
	public void add(E key, Integer value){
		if(containsKey(key)){value += get(key);
		}else{keyArray.add(key);}
		put(key, value);
	}
}

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

int main() {
    cin.tie(nullptr); ios::sync_with_stdio(false);
    int h1, m1, h2, m2, k; cin >> h1 >> m1 >> h2 >> m2 >> k;
    m1 += h1 * 60; m2 += h2 * 60;
    m2 -= m1 + k;
    cout << m2 << endl;
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
int n,m;
string dp[100010];

const long long INF = 1LL << 62;

int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}

bool sub(string a, string b){
	int ret=2;
	int i=0;
	if(a==b){
		ret=0;
	}
	while(ret==2){
		if(ctoi(a[i])>ctoi(b[i])){
			ret=0;
		}else if(ctoi(a[i])<ctoi(b[i])){
			ret=1;
		}else{
			i++;
		}
	}
	if(ret==0){
		return false;
	}else{
		return true;
	}
}
 
int main(){
	cin >> n >> m;
	int a[m];
	for(int i = 0; i < m; ++i){
		cin >> a[i];
	}
	int b[10]={0, 2, 5, 5, 4, 5, 6, 3, 7, 6};

	for(int i = 0; i <= n; ++i){
		dp[i]="";
	}
	
	for(int i = 1; i <= n; ++i){
		for(int j = 0; j < m; ++j){
			if(i-b[a[j]]>=0 && dp[i-b[a[j]]]!="-"){
				if(dp[i].size() < dp[i-b[a[j]]].size() + 1){

					dp[i]=dp[i-b[a[j]]]+to_string(a[j]);

				}else if(dp[i].size() == dp[i-b[a[j]]].size() + 1 && sub(dp[i], dp[i-b[a[j]]]+to_string(a[j]))){
					
					dp[i]=dp[i-b[a[j]]]+to_string(a[j]);

				}
			}
		}

		if(dp[i]==""){

			dp[i]="-";

		}
	}
 
	cout << dp[n];
	return 0;
}

Measured memory_bytes: 32640
#include<bits/stdc++.h>
using namespace std;
int n;
int l[400]; 
int main(){
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	cin>>n;
	for(int i=1;i<=n*2;i++)
		cin>>l[i];
	sort(l+1,l+2*n+1);
	int res=0;
	for(int i=1;i<=n*2;i+=2){
		res+=l[i];
	}
	cout<<res<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <fstream>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <stack>
#include <vector>
#include <set>
#include <tuple>
#include <utility>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
const int INF = 1000000000;
const int MOD = 1000000007;

int main(){
	int n,m;
	cin >> n >> m;
	//接続する2頂点の辺をみて,その辺の長さよりそれらの最短経路が真に小さいならそれは使わない.
	int d[100][100];
	for(int i = 0;i < 100;i++){
		for(int j = 0;j < 100;j++){
			d[i][j] = INF;
		}
	}
	vector<T> edges;
	for(int i = 0;i < m;i++){
		int a,b,c;
		cin >> a >> b >> c;
		a--,b--;
		d[a][b] = c;
		d[b][a] = c;
		edges.push_back(T(a,b,c));
	}

	for(int k = 0;k < n;k++){
		for(int i = 0;i < n;i++){
			for(int j = 0;j < n;j++)d[i][j] = min(d[i][j],d[i][k] + d[k][j]);
		}
	}

	int ans = 0;
	for(int i = 0;i < m;i++){
		int a,b,c;
		tie(a,b,c) = edges[i];
		if(d[a][b] != c)ans++;
	}

	cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#ifdef ENABLE_DEBUG
#define dump(a) cerr<<#a<<"="<<a<<endl
#define dumparr(a,n) cerr<<#a<<"["<<n<<"]="<<a[n]<<endl
#else
#define dump(a) 
#define dumparr(a,n) 
#endif
#define FOR(i, a, b) for(ll i = a;i < b;i++)
#define For(i, a) FOR(i, 0, a)
#define REV(i, a, b) for(ll i = b-1;i >= a;i--)
#define Rev(i, a) REV(i, 0, a)
#define REP(a) For(i, a)
#define SIGN(a) (a==0?0:(a>0?1:-1))

typedef long long int ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef pair<ll, ll> pll;
typedef pair<ll,pll> ppll;
typedef vector<ll> vll;
typedef long double ld;
typedef pair<ld,ld> pdd;

const ll INF=(1LL<<50);
#if __cplusplus<201700L
ll gcd(ll a, ll b) {
  if(a < b) return gcd(b, a);
  ll r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}
#endif
template<class T>
bool chmax(T& a,const T& b){
  if(a<b){
    a=b;
    return true;
  }
  return false;
}
template<class T>
bool chmin(T& a,const T& b){
  if(a>b){
    a=b;
    return true;
  }
  return false;
}
template<class S,class T>
std::ostream& operator<<(std::ostream& os,pair<S,T> a){
  os << "(" << a.first << "," << a.second << ")";
  return os;
}
template<class T>
std::ostream& operator<<(std::ostream& os,vector<T> a){
  os << "[ ";
  REP(a.size()){
    os<< a[i] << " ";
  }
  os<< " ]";
  return os;
}


void solve(long long N, long long K){
  ll cnt=0;
  while(N>0){
    ++cnt;
    N/=K;
  }
  cout<<cnt<<endl;
}

int main(){
  cout<<setprecision(1000);
  cin.tie(0);
  ios::sync_with_stdio(false);
    long long N;
    scanf("%lld",&N);
    long long K;
    scanf("%lld",&K);
    solve(N, K);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include<algorithm>
using namespace std;
vector<pair<int, int>> g;
int main() {
  long long a,v,b,w,t;
  cin >>a >>v>>b>>w>>t;
  
  if((v*t-w*t)- abs(a-b)>= 0){
    cout << "YES";
  }else{
   cout << "NO";
  }
  
  
}


Measured memory_bytes: 3596
#include<stdio.h>
int main(void)
{
     int h,m,s,S;
     scanf("%d",&S);
     
     h=S/3600;
     m=S%3600/60;
     s=S%3600%60;
     
     printf("%d:%d:%d\n",h,m,s);
     
     return 0;
}


Measured memory_bytes: 2124
#include "bits/stdc++.h"

using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
	REP(i, v.size()) { if (i)os << " "; os << v[i]; }return os;
}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
	REP(i, v.size()) { if (i)os << endl; os << v[i]; }return os;
}

const ll INF = 1LL << 60;

int main() {
	ll n, k;
	vector<ll> v;
	ll ans = 0;

	cin >> n >> k;

	REP(i, n) {
		ll x;
		cin >> x;
		v.push_back(x);
	}

	REP(i, n) {
		ans += min(abs(0 - v[i]) * 2, abs(k - v[i]) * 2);
	}

	cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define int long long
#define ld long double
#define fi first
#define se second
#define all(uiet) uiet.begin(),uiet.end()
#define read(UIET) for(int i = 0; i < n; ++i) cin >> UIET[i]
#define out(UIET) for(int i = 0; i < n; ++i) cout << UIET[i]
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define vpp vector<pair< int, int > >
#define pll pair<int , int >
#define ppll pair < pll , pll >
#define debug(n1) cout << n1 << endl
#define len(a) ((int) (a).size())
#define endl "\n"
#define mod 1000000007
const int INF=(1LL<<60)-1;
const int maxN = 87;
int32_t main(){
    SPEED;
    string a, b;
    cin >> a >> b;
    if(len(a) > len(b)) cout << "GREATER";
    else if(len(a) < len(b)) cout << "LESS";
    else{
        if(a == b){
            cout << "EQUAL";
            return 0;
        }
        for(int i = 0; i < len(a); ++i){
            if(a[i] - '0' > b[i] - '0'){
                cout << "GREATER";
                return 0;
            }
            else{
                cout << "LESS";
                return 0;
            }
        }
    }
}

Measured memory_bytes: 3648
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <map>
#define rep(i, n) for(int i=0;i<(int)(n);i++)
#define pb(a) push_back(a)
#define MAX(a, b) ((a < b)?b:a)
#define MIN(a, b) ((a > b)?b:a)
typedef long long int ll;
typedef unsigned long long int ull;
using namespace std;

template<typename T> void cinpb(vector<T>& x) { T n; cin >> n; x.push_back(n); }
ull gcd(ull a, ull b) { return b ? gcd(b, a%b) : a; }
ull lcm(ull m, ull n) {	return ((0 == m) || (0 == n)) ? 0 : ((m / gcd(m, n)) * n); }
int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,1,0,-1 };


//
int n, m, x, y;
vector<int> xn;
vector<int> ym;

int main()
{
	cin >> n >> m >> x >> y;

	rep(i, n)
	{
		cinpb(xn);
	}
	rep(i, m)
	{
		cinpb(ym);
	}

	int ymin = *min_element(ym.begin(), ym.end());
	int xmax = *max_element(xn.begin(), xn.end());

	bool f = false;

	for (int z = x + 1; z <= y; z++)
	{
		if ( xmax < z && ymin >= z )
		{
			f = true;
			break;
		}
	}

	cout << (f ? "No War" : "War") << endl;

	return 0;
}


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

int main()
{
	double A,B,H,M;
	cin >> A >> B >> H >> M;

	double tanshin = 0.0;
	double choushin = 0.0;
	double kakudo = 0.0;
	double ans = 0.0;

	tanshin = H * 30.0 + M * 0.5;
	choushin = M * 6.0;

	if (tanshin > choushin) {
		kakudo = tanshin - choushin;
	}
	else {
		kakudo = choushin - tanshin;
	}
	/*

	if (kakudo > 180) {
		kakudo = kakudo - 180;

	}

	if (kakudo == 0) {
		cout << 1 << endl;

	}else if (kakudo == 180) {
		cout << A + B << endl;
	}else{
	*/
		double pi = 3.14159265358979323846264338327950;
		
		ans =  A * A + B * B - 2 * A * B * cos(kakudo*(pi/180));
		ans = sqrt(ans);
		cout << fixed << setprecision(20);
		cout << ans << endl;
	//}
}

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

#define mp make_pair
#define pb push_back

typedef pair<int, int> pii;
typedef unsigned long long ull;
typedef long long ll;
typedef double db;

const int N = 2e5 + 10;

int n, a[N], b[N], tag;

int main() {
	scanf("%d", &n);
	for(int i = 1; i <= n; i ++) {
		scanf("%d", a + i);
	}
	for(int i = n; i >= 1; i --) {
		if(i == n) b[i] = a[i];
		else {
			int cnt = 0;
			for(int j = i + i; j <= n; j += i) {
				cnt += b[j];
			}
			cnt &= 1;
			if(cnt == a[i]) b[i] = 0;
			else b[i] = 1;
		}
	}
	for(int i = 1; i <= n; i ++) tag += b[i];
	printf("%d\n", tag);
	for(int i = 1; i <= n; i ++) if(b[i]) printf("%d ", i);
	return 0;
}


Measured memory_bytes: 2432
#include <stdio.h>
#define N 100000

int main(){
  int n;
  scanf("%d\n",&n);
  //
  if(n==2){
    n = 0;
    printf("%d",n);
    return 0;
  }
  //
  int a1[N];
  int a2[N];
  for(int i=0;i<N;i++){
    a1[i] = 0;
    a2[i] = 0;
  }
  int m1 = 1;
  int n1 = 1;
  int m2 = 0;
  int n2 = 0;
  int num11 = 0;
  int num12 = 0;
  int num21 = 0;
  int num22 = 0;
  int y,z;
  for(int i=0;i<n;i++){
    y = i%2;
    scanf("%d%*c",&z);
    if(y==0){
      a1[z]++;
    }else{
      a2[z]++;
    }
  }
  //
  for(int i=0;i<N;i++){
    if(a1[i] > m1){
      m2 = m1;
      num12 = num11;
      m1 = a1[i];
      num11 = i;
    }else if(a1[i] > m2){
      m2 = a1[i];
      num12 = i;
    }
    if(a2[i] > n1){
      n2 = n1;
      num22 = num21;
      n1 = a2[i];
      num21 = i;
    }else if(a2[i] > n2){
      n2 = a2[i];
      num22 = i;
    }
  }
  int answer;
  if(num11 == num21){
    if(m1+n2 < m2+n1){
      answer = n - m2 - n1;
    }else if(m1==n/2 && n1==n/2){
      answer = n/2;
    }else{
      answer = n - m1 - n2;
    }
  }else{
    answer = n - m1 - n1;
  }
  printf("%d",answer);
}


Measured memory_bytes: 896
#include<bits/stdc++.h>
using namespace std;
typedef vector<int> vi;

class UF{
  vi p,r;

public:
  UF(int n):p(n,-1),r(n,0){ }

  int find(int x){ return (p[x]<0)?x:(p[x] = find(p[x])); }

  void unite(int x,int y){
    x = find(x); y = find(y);
    if(x==y)return;

    if(r[x] < r[y])p[x] = y;
    else p[y] = x;
    if(r[x] == r[y])r[x]++;
  }

  bool same(int x,int y){return find(x)==find(y);}
};

const int INF= 1e9;

struct edge{
  int from, to, cost;
  edge(int x,int y, int z):from(x),to(y),cost(z){}
  bool operator<(const edge &x)const{ return cost<x.cost; }
};

class Kruskal{
  int n;
  vector< vector<edge> > g;
public:
  Kruskal(int a=0):n(a){ g.resize(n); }

  void AddEdge(int a, int b, int cost){
    g[a].push_back(edge(a,b,cost));
    g[b].push_back(edge(b,a,cost));
  }

  int MinSpanningTree(){
    UF connect(n);
    vector<edge> edges;
    for(int v=0;v<n;v++){
      for(edge e : g[v])edges.push_back(e);
    }
    sort(edges.begin(), edges.end());
    
    int res = 0;
    for(edge e : edges){
      if(!connect.same(e.from,e.to)){
	res += e.cost;
	connect.unite(e.from,e.to);
      }
    }
    return res;
  }
};

int main(){
  int n,m;
  while(scanf("%d",&n),n){
    Kruskal p(n);
    cin >> m;
    for(int i=0;i<m;i++){
      int a,b,c;
      scanf("%d,%d,%d",&a,&b,&c);
      p.AddEdge(a,b,c/100-1);
    }
    cout << p.MinSpanningTree() << endl;
  }
}

Measured memory_bytes: 1632
#include<math.h>
#include<limits.h>
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<sstream>
#include<list>
#include<queue>
#include <algorithm>
#include<initializer_list>
using namespace std;
#define ul unsigned long long

#define rup(i, a, b) for(int (i) = (a); (i) < (b); (i)++)
#define rdn(i, a, b) for(int (i) = (a); (i) > (b); (i)--)B

int main() {
	long long x, t;
	cin >> x>> t;
	long long r = x - t;
	cout << ((r > 0) ? x - t : 0) << endl;



	return 0;
}





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

int main() {
	int n;
	cin>>n;
	int R[n];
	for(int i=0;i<n;i++){
		cin>>R[i];
	}
	
	int maxv;
	int minv=R[0];
	for(int j=1;j<n;j++){
		if(j==1) maxv=R[j]-minv;
		maxv=(max(maxv,R[j]-minv));
		minv=(min(minv,R[j]));
	}
	cout<<maxv<<endl;
	return 0;
}

Measured memory_bytes: 3876
using System;
class _0049
{
    public static void Main()
    {
        string str;
        int a, b, o, ab;
        a = b = o = ab = 0;
        while ((str = Console.ReadLine()) != null)
        {
            switch (str.Split(',')[1])
            {
                case "A": a++; break;
                case "B": b++; break;
                case "O": o++; break;
                case "AB": ab++; break;
            }
        }
        Console.WriteLine("{0}\n{1}\n{2}\n{3}", a, b, ab, o);
    }
}

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

// definition {{{ 1

// scaning {{{ 2
#define Scd(x) scanf("%d", &x)
#define Scd2(x,y) scanf("%d%d", &x, &y)
#define Scd3(x,y,z) scanf("%d%d%d", &x, &y, &z)

#define Scll(x) scanf("%llu", &x)
#define Scll2(x,y) scanf("%llu%llu", &x, &y)
#define Scll3(x,y,z) scanf("%llu%llu%llu", &x, &y, &z)

#define Scc(c) scanf("%c", &c);
#define Scs(s) scanf("%s", s);
#define Scstr(s) scanf("%s", &s);
// }}} 2

// constants {{{ 2
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
// }}} 2

// systems {{{ 2
#define Rep(x,y) for(int x = 0; x < y; x++)
#define Repe(x,y,z) for(int x = z; x < y; x++)
// }}} 2

// output {{{ 2
#define YesNo(a) (a)?printf("Yes\n"):printf("No\n");
// }}} 2

// }}} 1

int main() {

    ll h,w,n;
    Scll3(h,w,n);
    ll ans[10] = {};
    ans[0] = (h-2)*(w-2);
    int a,b;
    multiset< pair<int,int> > s;
    set< pair<int,int> > r;
    Rep(i,n){
        Scd2(a,b);
        s.insert(make_pair(a,b));
        a++;
        s.insert(make_pair(a,b));
        b++;
        s.insert(make_pair(a,b));
        a--;
        s.insert(make_pair(a,b));
        a--;
        s.insert(make_pair(a,b));
        b--;
        s.insert(make_pair(a,b));
        b--;
        s.insert(make_pair(a,b));
        a++;
        s.insert(make_pair(a,b));
        a++;
        s.insert(make_pair(a,b));
    }

    int x,y;
    while(!s.empty()){
        y = (*s.begin()).first;
        x = (*s.begin()).second;
        int num = s.count(make_pair(y,x));
        if( !(x < 2 || y < 2 || x > w-1 || y > h-1) )
        ans[num]++;
        s.erase(make_pair(y,x));
    }

    Repe(i,10,1){
        ans[0] -= ans[i];
    }

    Rep(i,10){
        printf ("%llu\n", ans[i]);
    }


    return 0;
}



Measured memory_bytes: 42496
#include <bits/stdc++.h>
using namespace std;
int main() {
  int a;
  int b = 0;
  cin >> a;
  vector<int> vec(a);
  for (int i = 0; i < a; i++) {
    cin >> vec.at(i);
    if (vec.at(i) % 2 == 0) {
      if (vec.at(i) % 3 == 0 || vec.at(i) % 5 == 0) {
        continue;
      } else {
        b++;
      }
    }
  }
  if (b == 0) {
    cout << "APPROVED";
  } else {
  cout << "DENIED";
 }
}

Measured memory_bytes: 256
from itertools import accumulate
N = int(input())
s = input()
w = list(map(lambda x: 1 if x == 'W' else 0, s))
e = list(map(lambda x: 1 if x == 'E' else 0, s))
e.reverse()
w = list(accumulate(w))
e = list(accumulate(e))
e.reverse()
# print(w)
# print(e)
ans = []
for i in range(N):
    num = 0
    if 0 < i: num += w[i - 1]
    if i < N - 1: num += e[i + 1]
    ans.append(num)
# print(ans)
print(min(ans))

Measured memory_bytes: 95912
N, X = map(int, input().split())
x = list(map(int, input().split()))
y = [i-X if i-X >= 0 else X-i for i in x]
#print(y)

def gcp(a,b):
    if b == 0:
        return a
    else:
        return gcp(b, a%b)
koyaku = y[0]
for i in range(1, N):
    koyaku = gcp(koyaku,y[i])
print(koyaku)

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

using namespace std;

int main() {

    int n;
    cin >> n;
    
    int max = 0, cnt = 0;
    for(int i = 0; i < n; i++) {
        int height;
        cin >> height;
        
        if(height >= max) {
            max = height;
            cnt++;
        }
    }
    
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<set>
#include<unordered_set>
#include<vector>
#include<array>
#include<string>
#include<stack>
#include<queue>
#include<algorithm>
#include<cassert>
#include<functional>
#include<random>
#include<complex>
#include<bitset>
#include<chrono>
//#include<boost/multiprecision/cpp_int.hpp>
#define int int64_t
#define uint uint64_t
#define REP(i, a, b) for (int64_t i = (int64_t)(a); i < (int64_t)(b); i++)
#define rep(i, a) REP(i, 0, a)
#define EACH(i, a) for (auto i: a)
#define ITR(x, a) for (auto x = a.begin(); x != a.end(); x++)
#define ALL(a) (a.begin()), (a.end())
#define HAS(a, x) (a.find(x) != a.end())
#define Min(x) *min_element(ALL(x))
#define Max(x) *max_element(ALL(x))
#define Unique(L) (L.erase(unique(ALL(L)), L.end()))
#define veccat(v1, v2) std::copy((v2).begin(),(v2).end(),std::back_inserter(v1)/*v1の後ろにv2を入れる*/)
#define intmax (std::numeric_limits<int64_t>::max() / 4)
using namespace std;
//typedef boost::multiprecision::cpp_int bigint;
const double EPS = 1e-9;
const double PI = acos(-1.0);

int exist[50][50];

void mycout(int a, int b, int c, int d) {
	cout << "? " << a << " " << b << " " << c << " " << d << endl;
}

void solve(int y, int lb, int ub, int N) {
	//y行目の[lb,ub)にN個の爆弾があるとして、解く

	if (N == 0)return;

	if (ub - lb == N) {
		REP(x, lb, ub)exist[y][x] = 1;
		return;
	}

	int med = (lb + ub - 1) / 2;
	mycout(y, lb, y, med);
	int hN;
	cin >> hN;
	solve(y, lb, med + 1, hN);
	solve(y, med + 1, ub, N - hN);
}

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

	int H, W, N, K;
	cin >> H >> W >> N >> K;

	int table[50][50];
	int zzz = 1;
	rep(i, H)rep(j, W) {
		table[i][j] = zzz;
		zzz *= 2;
		zzz %= K;
	}

	rep(i, 50)rep(j, 50)exist[i][j] = 0;
	int unknown = N;

	rep(y, 50) {
		//y行目の爆弾の総数を聞く
		int ybomb;
		if (y == 49)ybomb = unknown;
		else {
			mycout(y, 0, y, W - 1);
			cin >> ybomb;
		}
		solve(y, 0, W, ybomb);
		unknown -= ybomb;
		if (unknown == 0)break;
	}

	int ans = 0;
	rep(i, 50)rep(j, 50)if (exist[i][j]) {
		ans += table[i][j];
		ans %= K;
	}
	cout << "! " << ans << endl;

	return 0;
}

Measured memory_bytes: 720
#![allow(non_snake_case)]

use std::io::{stdin, Read};
use std::str::FromStr;
fn read_option<T: FromStr>() -> Option<T> {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok()
}
fn read<T: FromStr>() -> T {
    let opt = read_option();
    opt.expect("failed to parse token")
}

fn main() {
    let N: usize = read();
    use std::collections::HashMap;
    let mut map: HashMap<usize, usize> = HashMap::new();
    for _ in 0..N {
        let entry = map.entry(read()).or_insert(0);
        *entry += 1;
    }
    let mut ans = 0;
    let mut minus = 0;
    for (_, v) in map {
        let v = if v % 2 == 0 { 2 } else { 1 };
        match v {
            1 => ans += 1,
            2 => {
                if minus != 0 {
                    minus = 0;
                } else {
                    minus += 1
                }
                ans += 1;
            }
            _ => unimplemented!(),
        }
    }
    if minus != 0 {
        ans -= 1;
    }
    println!("{}", ans);
}


Measured memory_bytes: 5420
typedef long long ll;

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

#include <cstdio>
inline int getInt(){ int s; scanf("%d", &s); return s; }

#include <queue>
#include <set>

using namespace std;

template<typename Data, typename Func>
class SegmentTree{
  int n;
  std::vector<Data> data;
  Func f;
  Data d;

  Data query(int a, int b, int k, int l, int r) const{
    if(r <= a || b <= l) return d;
    if(a <= l && r <= b) return data[k];
    else{
      const Data v1 = query(a, b, k * 2 + 1, l, (l + r) / 2);
      const Data v2 = query(a, b, k * 2 + 2, (l + r) / 2, r);
      return f(v1, v2);
    }
  }

public:
  SegmentTree(int nn, Func f, Data d) : f(f), d(d){
    n = 1;
    while(n < nn) n *= 2;
    data = std::vector<Data>(2 * n, d);
  }

  void update(int k, const Data &a){
    k += n - 1;
    data[k] = a;
    while(k > 0){
      k = (k - 1) / 2;
      data[k] = f(data[k * 2 + 1], data[k * 2 + 2]);
    }
  }

  // [a, b)
  Data query(int a, int b) const{
    return query(a, b, 0, 0, n);
  }
};

template<typename Data, typename Func> SegmentTree<Data, Func>
segtree(int numberOfElements, Data defaultValue, Func mergeFunc){
  return SegmentTree<Data, Func>(numberOfElements, mergeFunc, defaultValue);
}


int main(){
  const int n = getInt();
  vector<int> h(n);
  vector<int> a(n);
  REP(i,n) h[i] = getInt() - 1;
  REP(i,n) a[i] = getInt();

  auto seg = segtree(n, 0ll, [](ll a, ll b){ return max(a, b); });

  REP(i,n){
    const ll mx = seg.query(0, h[i]);
    seg.update(h[i], mx + a[i]);
  }

  printf("%lld\n", seg.query(0, n));

  return 0;
}

Measured memory_bytes: 5888
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <list>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_set>
#include <unordered_map>
#include <array>
#include <cassert>
#include <bitset>
using namespace std;
using LL = long long;

string S;

int main(void)
{
	cin >> S;
	int N = S.size();
	for (int i = N / 2; i < N; ++i) {
		if (i == N / 2 && N % 2 == 1)continue;
		if (S[i] == S[N - 1 - i] && S[i] == S[i - 1]) {}
		else {
			cout << i;
			return 0;
		}
	}
	cout << N << endl;
	return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
int n;

struct Edge{
    int to,id; //枝のid
};

//木の問題は大体深さ優先探索
vector<vector<Edge>> g;
vector<int> ans;
//隣り合ってる頂点を列挙したリスト　a[i]={i,j,k,l...}

void dfs(int v,int c=-1,int p=-1){
    int k=1;
    rep(i,g[v].size()){
        int u = g[v][i].to,ei=g[v][i].id;
        if(u==p) continue; //親から来た場合は無視
        if(k==c) k++; //親辺と一致しそうならとばす
        ans[ei]=k;
        k++;
        dfs(u,ans[ei],v);
    }
}

int main(){
    cin>>n;
    g.resize(n);
    ans.resize(n);
    rep(i,n-1){
        int a,b;
        cin>>a>>b;
        a--;b--;
        g[a].push_back((Edge){b,i});//向かう点とid追加
        g[b].push_back((Edge){a,i}); //双方向に
    }
    dfs(0);
    //cout<<"eskape"<<endl;
    int mx=0;
    rep(i,n) mx= max(mx,int(g[i].size()));
    cout<<mx<<endl;
    rep(i,n-1){
        cout<<ans[i]<<endl;
    }
    return 0;
}

Measured memory_bytes: 8320
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const ll mod = 1000000007;
const ll INF = 9223372036854775807;
#define Sort(a) sort(a.begin(), a.end())
#define Bsort(a) sort(a.begin(), a.end(), greater<ll>())
#define Pi acos(-1)

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  int k, s;
  cin >> k >> s;
  ll count = 0;
  for (int i = 0; i <= k; i++) {
    for (int j = 0; j <= k; j++) {
      if (s-i-j <= k && s-i-j >= 0) {
        count++;
      }
    }
  }
  cout << count << '\n';
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
    int x,y;
    while(1){
        scanf("%d%d",&x,&y);
        if(x==0&&y==0){
            break;
        }
        for(int i=0;i<x;i++){
            for(int j=0;j<y;j++){
                printf("#");
            }
            printf("\n");
        }
        printf("\n");
    }
    return 0;
}


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

int main(){
	int n;
	cin >> n;
	string str;
	cin >> str;
	int ans = 0;
	for (int i=0; i+2<n; i++){
		if(str.substr(i, 3) == "ABC") ans++;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <cassert>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>

#ifdef _DEBUG
#define DMP(x) cerr << #x << ": " << x << "\n"
#else
#define DMP(x) ((void)0)
#endif

const int MOD = 1000000007, INF = 1111111111; 
using namespace std;
using lint = long long;

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	int N, Y;
	cin >> N >> Y;

	bool flag = false;
	for (int i = 0; i <= 2000; i++) {
		for (int j = 0; j <= 2000; j++) {

			if ((Y - 10000 * i - 5000 * j) / 1000 == N - i - j && N - i - j >= 0) {
				cout << i << " " << j << " " << N - i - j << "\n";
				return 0;
			}

		}
	}

	cout << "-1 -1 -1 " << "\n";

	return 0;
}

Measured memory_bytes: 256
#include <iostream>

int d[51];
int main(void) {
	int N;
	std::cin >> N;
	for (int i = 1; i <= N; i++) {
		std::cin >> d[i];
	}
	long sum = 0;
	for (int i = 1; i <= N-1; i++) {
		for (int j = i+1; j <= N; j++) {
			sum += d[i]*d[j];
		}
	}
	std::cout << sum << std::endl;
	return 0;
}


Measured memory_bytes: 256