akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define fastIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define fi first
#define se second
#define pub push_back
#define pi pair<int,int>
#define all(v) (v).begin(), (v).end()
#define rep(i, l, r) for(int i=(int)(l);i<(int)(r);i++)
#define repd(i, l, r) for (int i=(int)(l);i>=(int)(r);i--)
#define clrg(i, l, r) for(int i=(int)(l);i<(int)(r);i++)vis[i]=0,v[i].clear();
int power(int x, unsigned int y){int res = 1;while (y > 0){ if (y & 1){res = res*x;} y = y>>1;x = x*x;}return res;}
int powermod(int x, unsigned int y, int p){int res = 1;x = x % p;while (y > 0){if (y & 1){res = (res*x) % p;}y = y>>1; x = (x*x) % p;}return res;}
#define print2d(mat,n,m){for(int i=0;i<(int)(n);i++){for(int j=0;j<(m);j++){cout<<mat[i][j]<<" ";}cout<< endl;}}
#define clr(a,x) memset(a,x,sizeof(a))
#define rr(v) for(auto &val:v)
#define print(v) for (const auto itr : v){cout<<itr<<' ';}cout<<"\n";
#define ln length()
#define sz size()
#define mod 1000000007
#define elif else if
#define ld long double
ld dp[3001][3001][2];
ld ar[3001][2];
int n;
ld solve(int i,int c,int h){
  if(i==n){
    //cout<<c<<" "<<h<<"\n";
    return (ld)(c<=n/2?1:0);
  }
  if(dp[i][c][h]>=0)return dp[i][c][h];
  ld ans=0.0000;
  ans+=ar[i][h]*solve(i+1,c+(h==1),0);
  //cout<<i<<" "<<ans<<" 1 \n";
  if(i<n-1)ans+=ar[i][h]*solve(i+1,c+(h==1),1);
  //cout<<i<<" "<<ans2<<" 2 \n";
  dp[i][c][h]=ans;
  //cout<<ans<<"\n";
  return ans;
}
int32_t main(){
   cin>>n;
  rep(i,0,n){
    cin>>ar[i][0];
    ar[i][1]=1-ar[i][0];
    //cout<<ar[i][0]<<" "<<ar[i][1]<<"\n";
  }
  rep(i,0,n+1)rep(j,0,n+1)dp[i][j][0]=-1,dp[i][j][1]=-1;
  ld ans=solve(0,0,0)+solve(0,0,1);
  cout<<fixed<<setprecision(11)<<ans<<"\n";
   return 0;
}
/*
Edge cases? n=1? a[i]<=0?
long vs int? 1LL? 64bits?
Re-read problem. Is it as easy as it seems?
KEEP CORRECTING AND SUBMITTING!
*/


Measured memory_bytes: 285516
#include <cstdio>           // printf(), getc(), scanf()
#include <cctype>           // isdigit()
#include <vector>
#include <queue>            // priority_queue
#include <algorithm>        // fill()
#include <utility>          // pair

using namespace std;

static const int MAX_V = 10000;
static const int INF = 100000000;

typedef pair<int, int> P;
struct edge
{
	int to;
	int cost;
};

vector<edge> G[MAX_V];
int V;

void
dijkstra()
{
	priority_queue<P, vector<P>, greater<P> > que;
	int d[MAX_V];
	int u;
	unsigned int v; 

	fill(d, d + V, INF);
	d[0] = 0;
	que.push(P(0, 0));

	while (!que.empty())
	{
		P p = que.top(); que.pop();
		int u = p.second;
		if (d[u] < p.first)
			continue;

		for (v = 0; v < G[u].size(); ++v)
		{
			edge e = G[u][v];
			if (d[u] + e.cost < d[e.to])
			{
				d[e.to] = d[u] + e.cost;
				que.push(P(d[e.to], e.to));
			}
		}
	}

	for (u = 0; u < V; ++u)
		printf("%d %d\n", u, d[u]);
}

int
main(int argc, char** argv)
{
	edge e;
	int u, v;
	int i, j, k;
	int n;
	int c;

	c = getc(stdin);
	while (c == ' ')
		c = getc(stdin);
	
	n = 0;
	while (isdigit(c))
	{
		n = n * 10 + c - '0';
		c = getc(stdin);
	}

	V = n;
	for (i = 0; i < V; ++i)
	{
		while (c == ' ' || c == '\n')
			c = getc(stdin);

		n = 0;
		while (isdigit(c))
		{
			n = n * 10 + c - '0';
			c = getc(stdin);
		}

		u = n;
		while (c == ' ')
			c = getc(stdin);

		n = 0;
		while (isdigit(c))
		{
			n = n * 10 + c - '0';
			c = getc(stdin);
		}

		k = n;
		for (j = 0; j < k; ++j)
		{
			while (c == ' ')
				c = getc(stdin);

			n = 0;
			while (isdigit(c))
			{
				n = n * 10 + c - '0';
				c = getc(stdin);
			}

			v = n;
			while (c == ' ')
				c = getc(stdin);

			n = 0;
			while (isdigit(c))
			{
				n = n * 10 + c - '0';
				c = getc(stdin);
			}

			e.to = v;
			e.cost = n;
			G[u].push_back(e);
		}
	}

	dijkstra();
	return 0;
}

Measured memory_bytes: 6096
import sys
import numpy as np
from numba import njit
 
readline = sys.stdin.readline
 
@njit('i8,i8,i8[::1]',cache=True)
def loop(n,k,a):
    for j in range(k):
        b = np.zeros(n+1, dtype=np.int64)
        for i in range(n):
            b[max(i-a[i], 0)] += 1
            b[min(i+a[i]+1, n)] -= 1
        a = np.cumsum(b)[:-1]
        if np.all(a==n):
            return(a)
            break
    else:
        return(a)
 
 
n, k = map(int, readline().split())
a = np.array(readline().split(), dtype=np.int64)
 
ans = loop(n,k,a)
print(*ans)

Measured memory_bytes: 129300
import java.io.*;
import java.util.*;


class Main {
    public static void main(String[] args) {
        MyScanner sc = new MyScanner();
        out = new PrintWriter(new BufferedOutputStream(System.out));
        int n=sc.nextInt();
        int max=0;
        int ans=0;
        for(int i=0;i<n;++i){
            int a=sc.nextInt();
            int b=sc.nextInt();
            if(max<a){
                max=a;
                ans=a+b;
            }
        }
        out.println(ans);
        out.close();
    }
    // http://codeforces.com/blog/entry/7018
    //-----------PrintWriter for faster output---------------------------------
    public static PrintWriter out;
    //-----------MyScanner class for faster input----------
    public static class MyScanner {
        BufferedReader br;
        StringTokenizer st;
        public MyScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }
        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }
        int nextInt() {
            return Integer.parseInt(next());
        }
        long nextLong() {
            return Long.parseLong(next());
        }
        double nextDouble() {
            return Double.parseDouble(next());
        }
        String nextLine(){
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
}


Measured memory_bytes: 41192
#include<iostream>
using namespace std;
int main(){
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  if(abs(c-a)<=d || (abs(b-a)<=d && abs(c-b)<=d)){
    cout << "Yes" << endl;
    return 0;
  }
  cout << "No" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
bool debug;
#define all(x) (x).begin(), (x).end()
#define ll long long

#define db(x) if(debug)cout << " " << (x) <<" "
#define dbn(x) if(debug)cout << "\n" << (#x) << " is " << (x) << endl
#define endl "\n"
#define pb push_back
#define fi first
#define se second
#define rep(i,n) for(ll i=0;i<n;i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define rep1(i,n) for(ll i=1;i<=n;i++)
#define per1(i,n) for(ll i=n;i>=1;i--)
// fill(all(vec), 1);
//vec.resize(unique(all(vec))-vec.begin())
const int N = 3e6;
void solve()
{
    ll h, w;
    cin >> h >> w;
    if(h == 1 || w == 1)
    {
        cout << 1;
        return;
    }
    ll ans = h * w / 2 + h * w % 2;
    cout << ans;

}



int main()
{
    debug = 0;


    if(debug)
    {
#ifndef ONLINE_JUDGE
        // for getting input from input.txt
        freopen("input.txt", "r", stdin);
        // for writing output to output.txt
        freopen("output.txt", "w", stdout);
#endif
    }

    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t = 1;
    // cin >> t;


    while(t--)
    {
        solve();
        // cout << endl;
    }


}

Measured memory_bytes: 256
n = int(input())
t,a = map(int,input().split())
nowt = t
nowa = a
for i in range(n-1):
    t , a = map(int,input().split())
    kou = max(nowt//t,nowa//a)
    while True:
        if t*kou >= nowt and a*kou >= nowa:
            break
        else:
            kou += 1
    nowt = t*kou
    nowa = a*kou
print(nowt+nowa)

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

int main(){
  ll a,b,v,w,t;
  cin >>a >>v >>b >>w >>t;
  ll d = abs(a-b);
  ll d2 = (v-w)*t;
  if(d<=d2) cout << "YES" << endl;
  else cout << "NO" << endl;
  return 0;
}

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

int main(){
    int  n,m;
    cin >> n >> m;
    int s,c;
    bool flag = true;
    int list[3]={10,10,10};
    for(int i=0;i<m;i++){
        cin >> s >> c;
        if(s==1&&c==0&&n!=1) flag = false;
        else{
            if(c==list[s-1]||list[s-1]==10) list[s-1] = c;
            else flag = false;
        }
    }

    if(!flag) cout << -1 << endl;
    else if(n==1&&list[0]==10) cout << 0 << endl;
    else{
        for(int i=0;i<n;i++){
            if(list[i]==10&&i==0) cout << 1;
            else if(list[i]==10) cout << 0;
            else cout << list[i];
        }
        cout << endl;
    }
}


Measured memory_bytes: 256
import sys
from itertools import permutations
input = sys.stdin.readline

def main():
    N, M = map(int, input().split())
    link = [[False] * N for i in range(N)]

    for i in range(M):
        a, b = map(int, input().split())
        link[a-1][b-1] = True
        link[b-1][a-1] = True
    
    ans = 0
    path = [i for i in range(1, N)]
    for p in permutations(path):
        if link[0][p[0]]:
            ok = True
            for i in range(N-2):
                if not link[p[i]][p[i+1]]:
                    ok = False
                    break
            if ok:
                ans += 1
    print(ans)

if __name__ == "__main__":
    main()

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

const int INF = 1000000007;
const int MOD = 1000000007;

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

int main(){
    int N;
    scanf("%d", &N);
    printf("%d\n", (int)ceil(log(N) / log(3)));
    return 0;
}

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

const int MAX_N = 2e5 + 10;
int n, q, ans;
int Arr[MAX_N];
int cnt[MAX_N];
int val[MAX_N];

int main() {
	ios::sync_with_stdio(false), cin.tie(0);
	cin >> n >> q;
	for (int i = 0; i < n; i++) {
		cin >> Arr[i];
		cnt[Arr[i]]++;
	}

	for (int i = 1; i <= n; i++)
		for (int j = max(0, i - cnt[i]); j < i; j++)
			val[j]++;

	for (int i = 0; i < n; i++)
		ans += !val[i];

	while (q--) {
		int x, y;
		cin >> x >> y;
		x--;

		if (0 <= Arr[x] - cnt[Arr[x]]) {
			if (val[Arr[x] - cnt[Arr[x]]] == 1)
				ans++;

			val[Arr[x] - cnt[Arr[x]]]--;
		}

		cnt[Arr[x]]--;

		Arr[x] = y;
		cnt[Arr[x]]++;
		if (0 <= Arr[x] - cnt[Arr[x]]) {
			if (val[Arr[x] - cnt[Arr[x]]] == 0)
				ans--;
			
			val[Arr[x] - cnt[Arr[x]]]++;
		}

		cout << ans << "\n";
	}
	return 0;
}

Measured memory_bytes: 3840
#include <iostream>
#include <fstream>
#include <iomanip>

#include <vector>
#include <set>
#include <bitset>
#include <map>
#include <deque>
#include <string>

#include <algorithm>
#include <numeric>
#include <random>

#include <cstdio>
#include <cassert>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>

using namespace std;

#define forn(i, n) for (ll i = 0; i < (ll) (n); ++i)
#define sz(a) static_cast<int>((a).size())
#define endl '\n'

using ll = long long;

const ll INF = static_cast<ll>(1e9) + 7;
const int MAXN = static_cast<int>(3e5) + 17;

int n;
ll a, b, k, MOD = 998244353;
ll F[MAXN];

bool read() {
    if (!(cin >> n >> a >> b >> k))
        return false;

    return true;
}

ll binpow(ll a, ll b, ll MOD) {
    ll res = 1;

    for (; b > 0; b /= 2, a = a * a % MOD)
        if (b & 1)
            res = res * a % MOD;

    return res;
}

ll rev(ll x) { return binpow(x, MOD - 2, MOD); }

ll binomial(int n, int k) { return F[n] * (rev(F[k]) * rev(F[n - k]) % MOD) % MOD; }

void solve() {
    F[0] = 1ll;

    forn (i, MAXN - 1)
        F[i + 1] = (i + 1) * F[i] % MOD;

    ll ans = 0;

    for (int cnta = 0; cnta <= n; ++cnta)
        if (a * cnta <= k && (k - a * cnta) % b == 0) {
            auto cntb = (k - a * cnta) / b;

            if (cntb <= n)
                ans = (ans + binomial(n, cnta) * binomial(n, cntb) % MOD) % MOD;
        }

    cout << ans << endl;
}

int main() {
    cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::mt19937 rand('S' + 'E' + 'R' + 'E' + 'Z' + 'H' + 'K' + 'A');

#ifdef SEREZHKA
    freopen("file.in", "r", stdin);
#endif

    while (read())
        solve();

    return 0;
}



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


int main() {
  ll n;
  cin >> n;
  vector<long long> h(n);
  rep(i,n){
    cin >> h[i];
  }
  ll ans = 0;
  if(n == 1){
    cout << 0;
  }
  else{
    rep(i,n-1){
      if(h[i] > h[i+1]){
        ans = ans + h[i] - h[i+1];
        h[i+1] = h[i];
      }
    }
    cout << ans;
  }
  
  
  return 0;
}






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

int main() {
  int n , p, a=0, b=0; cin >> n >> p;
  int arr[n];
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
    if (arr[i]%2==0)
      a++;
    else
      b++;
  }
  long long x = pow(2, a+b-1);
  if (p%2==0 && b==0)
    cout << x*2 << endl;
  else if (p%2!=0 && b==0)
    cout << 0 << endl;
  else
    cout << x << endl;
  return 0;
}
  

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

using namespace std;

int nums[100000 + 5];
int LNDSL(int sequence[], int n){
    if (n == 0)
        return 0;
    vector<int> tails;
    tails.push_back(sequence[0]);
    for (size_t i = 1; i < n; i++){
        if (sequence[i] <= tails.back())
            tails.push_back(sequence[i]);
        else {
            *upper_bound(tails.begin(), tails.end(), sequence[i], greater<int>()) = sequence[i];
        }
    }
    return tails.size();
}

int main() {
    int n;
    scanf("%d", &n);
    for (int i = 0; i < n; i++){
        scanf("%d", &nums[i]);
    }
    printf("%d", LNDSL(nums, n));
}

Measured memory_bytes: 1276
// Aizu 2823: JAG Practice Contest
// 2017.9.23 bal4u@uu

#include <stdio.h>
#include <string.h>

int dmax[101];		// ?????£????????????????????????????????§??¨??????

int main()
{
	int n, m, i, d, v, ans;

	while (scanf("%d%d", &n, &m) && n > 0) {
		memset(dmax, 0, sizeof(int)*(m+1));
		while (n-- > 0) {
			scanf("%d%d", &d, &v);
			if (dmax[d] == 0 || v > dmax[d]) dmax[d] = v;
		}
		for (ans = 0, i = 1; i <= m; i++) ans += dmax[i];
		printf("%d\n", ans);
	}
	return 0;
}

Measured memory_bytes: 1760
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<55;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

int h,w,n;
vs a;
vvi b;

int main(){
	cin>>h>>w>>n;
	a=vs(h);
	b=vvi(h,vi(w));
	int I=-1;
	for(int i=0;i<h;i++){
		cin>>a[i];
		if(I==-1&&a[i]!=string(w,'.')) I=i;
	}
	vi c;
	for(int i=0;i<w;i++) if(a[I][i]=='#') c.push_back(i);
	for(int i=0;i<=I;i++){
		for(int j=0;j<w;j++) b[i][j]=upper_bound(c.begin(),c.end(),max(c[0],j))-c.begin();
	}
	int N=0;
	for(int i=I+1;i<h;i++){
		if(a[i]!=string(w,'.')){
			N+=c.size();
			c.clear();
			for(int j=0;j<w;j++) if(a[i][j]=='#') c.push_back(j);
		}
		for(int j=0;j<w;j++) b[i][j]=(upper_bound(c.begin(),c.end(),max(c[0],j))-c.begin())+N;
	}
	for(int i=0;i<h;i++) for(int j=0;j<w;j++) cout<<b[i][j]<<" \n"[j==w-1];
}

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

int main() {
    int A[3];
    cin >> A[0] >> A[1] >> A[2];

    int num=0;
    while (A[0] != A[1] || A[1] != A[2]) {
        sort(A, A+3);
 
         // 最小値の＋2
        // 同じ値が2つできれば値の組に＋1
        if (A[0] == A[1]) {
            A[0]++;
            A[1]++;
        } else {
            A[0] += 2;
        }
        num++;
    }
    cout << num << endl;
}

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

namespace At
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = ReadInt();
            var tn = ReadInts();
            var h = ReadInts();
            var ans = 0;
            var tmp = double.MaxValue;
            for (int i = 0; i < n; i++)
            {
                if (Math.Abs(tn[0] - h[i] * 0.006 - tn[1]) <= tmp)
                {
                    tmp = Math.Abs(tn[0] - h[i] * 0.006 - tn[1]);
                    ans = i + 1;
                }
            }
            WriteLine(ans);
        }
       

        private static string Read() { return ReadLine(); }
        private static string[] Reads() { return (Read().Split()); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }

        //最大公約数
        public static int Gcd(int a, int b)
        {
            if (a < b)
            {
                return Gcd(b, a);
            }
            while (b != 0)
            {
                var reminder = a % b;
                a = b;
                b = reminder;
            }
            return a;
        }

        //最小公倍数
        public static int Lcm(int a, int b)
        {
            return a * b / Gcd(a, b);
        }

    }
}


Measured memory_bytes: 13204
function main(_stdin){
    const stdin = _stdin.split('\n');
    const length = parseInt(stdin.shift(), 10);
    const series = stdin.shift().split(' ').map(e => parseInt(e, 10));

    console.log(series.join(' '));
    for (let i = 1, l = length; i < l; i++) {
        const t = series[i];
        let j = i - 1;

        while(j >= 0 && series[j] > t){
            series[j+1] = series[j];
            j--;
        }
        series[j+1] = t;
        console.log(series.join(' '));
    }
}
// main(require("fs").readFileSync("./ALDS1_1_A", "utf8"));
main(require("fs").readFileSync("/dev/stdin", "utf8"));




Measured memory_bytes: 16552
s = input()
a = []


for i in range(0,len(s)):
  if(s[i]=="0"):
    a.append(0)
  elif(s[i]=="1"):
    a.append(1)
  elif(s[i]=="B" and len(a)==0):
    continue
  elif(s[i]=="B"):
    del a[-1]

L=[str(a) for a in a]
L="".join(L)
print(L)

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

#define ll long long
#define F first
#define S second
#define ii pair < int , int >
#define ever (;;)

const int N = 200100;

bool vis[N];
int n,m,cnt,ans;
vector <int> adj[N];

void dfs(int u)
{
    cnt++;
    vis[u] = 1;

    for(auto &x:adj[u])
        if( !vis[x] )
            dfs(x);
}

int main()
{
    scanf("%d%d",&n,&m);
    for(int i=1;i<=m;i++)
    {
        int a,b;
        scanf("%d%d",&a,&b);
        adj[a].push_back(b);
        adj[b].push_back(a);
    }

    for(int i=1;i<=n;i++)
        if( !vis[i] )
        {
            cnt = 0;
            dfs(i);
            ans = max( ans , cnt );
        }

    printf("%d\n",ans);
}


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

int main() {
  string s;
  cin >> s;
  
  bool ans = true;
  for(int i=0;i<s.size();i++){
    if(i % 2 == 0 && s.at(i) == 'L') ans = false;
    if(i % 2 == 1 && s.at(i) == 'R') ans = false;
  }
  
  if(ans) cout << "Yes" << endl;
  else cout << "No" << endl;
}


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

signed main() {
  cin.tie(0); ios::sync_with_stdio(false);
  int n; cin >> n;
  cout << 0 << endl;
  string sa; cin >> sa;
  if (sa == "Vacant") return 0;
  cout << n - 1 << endl;
  string sb; cin >> sb;
  if (sb == "Vacant") return 0;
  int a = 0, b = n - 1;
  while (true) {
    int m = (a + b) / 2;
    cout << m << endl;
    string sm; cin >> sm;
    if (sm == "Vacant") return 0;
    if (sa == sm and (m - a) % 2 == 1 or sa != sm and (m - a) % 2 == 0) {
      b = m;
      sb = sm;
    } else {
      a = m;
      sa = sm;
    }
  }
  return 0;
}

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

#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define FOR(e, c) for (auto &e : c)
#define SORT(v, n) sort(v, v + n);
#define vsort(v) sort(v.begin(), v.end());
#define rvisort(v) sort(v.begin(), v.end(), greater<int>());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
// #define int long long
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) int(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using ul = unsigned long;

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

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e15;

ll GCD(ll a, ll b) { return b ? GCD(b, a%b) : a; }
ll LCM(ll a, ll b) { return a * b / GCD(a, b); }

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

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

ll dp[105][100005]; // dp[i][j]:=i人目まででj個を分け合う通り数

int main(){
  int n,k; cin>>n>>k;
  vi a(n);
  rep(i,n) cin>>a[i];
  
  dp[0][0]=1;
  
  rep(i,n){
    vector<ll> psum(k+2,0); // dp[i][0~j]の累積和
    for(int j=0; j<=k; j++) psum[j+1]=(psum[j]+dp[i][j])%MOD;
    for(int j=0; j<=k; j++){
      dp[i+1][j]=psum[j+1]-psum[max(0, j-a[i])]; // dp[i+1][j]=dp[i][0]+dp[i][1]+ ... dp[i][j] を高速化
      dp[i+1][j]=(dp[i+1][j]+MOD)%MOD;
    }
  }
  cout<<dp[n][k]<<endl;
}

Measured memory_bytes: 80124
fun main() {
    val s = readString()
    val t = readString()
    var count = 0
    for(i in 0..s.length-1) {
        if(s[i] != t[i]) {
            count += 1
        }
    }
    println(count)
}

fun readString() = readLine()!!
fun readInt() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readIntList() = readLine()!!.split(" ").map(String::toInt)
fun readLongList() = readLine()!!.split(" ").map(String::toLong)

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

const vector<int> DX = {-1, 0, 1, 0};
const vector<int> DY = {0, -1, 0, 1};

const vector<int> DX2 = {-2, -2, -2, -2, -2, -1, -1, -1, -1, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 2};
const vector<int> DY2 = {-2, -1, 0, 1, 2, -2, -1, 1, 2, -2, 2, -2, -1, 1, 2, -2, -1, 0, 1, 2};

int main()
{
    int H, W;
    cin >> H >> W;
    int Ch, Cw;
    cin >> Ch >> Cw;
    Ch--;
    Cw--;
    int Dh, Dw;
    cin >> Dh >> Dw;
    Dh--;
    Dw--;
    vector<string> S(H);
    for (int r = 0; r < H; r++)
    {
        cin >> S.at(r);
    }

    int res = 0;

    queue<pair<int, int>> q, q2;
    vector<vector<bool>> visited(H, vector<bool>(W));
    vector<vector<bool>> can_jump(H, vector<bool>(W));
    q.push(make_pair(Ch, Cw));
    visited.at(Ch).at(Cw) = true;

    while (true)
    {
        while (!q.empty())
        {
            int x = q.front().first, y = q.front().second;
            q.pop();
            for (int i = 0; i < 4; i++)
            {
                int nx = x + DX.at(i), ny = y + DY.at(i);
                if (nx < 0 || H <= nx || ny < 0 || W <= ny)
                    continue;
                if (S.at(nx).at(ny) == '#')
                    continue;
                if (visited.at(nx).at(ny))
                    continue;
                visited.at(nx).at(ny) = true;
                q.push(make_pair(nx, ny));
            }
            for (int i = 0; i < 20; i++)
            {
                int nx = x + DX2.at(i), ny = y + DY2.at(i);
                if (nx < 0 || H <= nx || ny < 0 || W <= ny)
                    continue;
                if (S.at(nx).at(ny) == '#')
                    continue;
                if (visited.at(nx).at(ny) || can_jump.at(nx).at(ny))
                    continue;
                can_jump.at(nx).at(ny) = true;
                q2.push(make_pair(nx, ny));
            }
        }

        if (visited.at(Dh).at(Dw))
            break;

        res++;

        while (!q2.empty())
        {
            int x = q2.front().first, y = q2.front().second;
            q2.pop();
            if (visited.at(x).at(y))
                continue;
            visited.at(x).at(y) = true;
            q.push(make_pair(x, y));
        }

        if (q.empty())
        {
            res = -1;
            break;
        }
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 5888
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
int N , M ,C,ans = 0;

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

	cin >> N >> M >> C;

	vector<int> B(M);
	for(auto &x:B){
		cin >> x;
	}

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

	REP(i,N){
		int tmp = 0;
		REP(j,M){
			tmp += A[i][j] * B[j];
		}
		if(tmp + C > 0) ans++;
	}

	cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
int main()
{
	int n;
	vector<int> a;
	scanf("%i",&n);
	a.resize(n);
	for(int i=0;i<n;i++) scanf("%i",&a[i]);
	sort(a.begin(),a.end());
	vector<int> v,sz;
	int cnt=0;
    for(int i=0;i<n;i++)
	{
		if(i==0 || a[i]!=a[i-1]) cnt=1;
		else cnt++;
		if(i==n-1 || a[i]!=a[i+1]) v.pb(a[i]),sz.pb(cnt);
	}
	if(sz.size()>3) return 0*printf("No\n");
	if(sz.size()==3)
	{
		int x=v[0],y=v[1],z=v[2];
		if((x^y)==z && sz[0]==sz[1] && sz[1]==sz[2]) printf("Yes\n");
		else printf("No\n");
	}
	if(sz.size()==2)
	{
		if(v[0]==0 && sz[0]*2==sz[1]) printf("Yes\n");
		else printf("No\n");
	}
	if(sz.size()==1)
	{
		if(v[0]==0) printf("Yes\n");
		else printf("No\n");
	}
	return 0;
}

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

string N;

int dp[20][2];

int dfs(int idx = 0, bool tight = true) {
  if (idx == N.size()) {
    return 0;
  }
  int &res = dp[idx][tight];
  if (~res) return res;
  res = 0;
  int x = N[idx] - '0';
  int r = (tight ? x : 9);
  for (int i = 0; i <= r; ++i) {
    res = max(res, dfs(idx + 1, tight && i == r) + i);
  }

  return res;
}

int main() {
  memset(dp, -1, sizeof(dp));
  cin >> N;

  cout << dfs() << endl;
}


Measured memory_bytes: 256
N = input()
n = len(N)
a = int(N[0])
b = 11-int(N[0])
for i in range(n-1):
    a1 = min(a+int(N[i+1]), b+int(N[i+1]))
    b1 = min(a+11-int(N[i+1]), b+9-int(N[i+1]))
    a = a1
    b = b1
print(min(a,b))

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

using namespace std;

using ll = long long;

int main() {

	string S, T;
	cin>>S>>T;
	int A, B;
	cin>>A>>B;
	string U;
	cin>>U;
	if (S == U) {
		cout<<A-1<<" "<<B<<endl;
	}	
	else {
		cout<<A<<" "<<B-1<<endl;
	}

	return 0;
}


Measured memory_bytes: 256
# coding: utf-8

n = int(input())
w = list(map(int, input().split()))
s = sum(w)
s1 = 0
s2 = 0
mind = s
_t = -1
i = 0
while i < n - 1:
    t = w[i]
    s1 = s1 + t
    s2 = s - s1
    d = abs(s2 - s1)
    if d < mind:
        mind = d
    i += 1
print(mind)


Measured memory_bytes: 3064
#include <stdio.h>

#define N	70
#define M	70
#define MD	1000000007

int min(int a, int b) { return a < b ? a : b; }

int ch[N + 1][N + 1], cnt[N + 1][N + 1];

void init() {
	int n, b, k, l;

	ch[0][0] = 1;
	for (n = 1; n <= N; n++) {
		ch[n][0] = 1;
		for (k = 1; k <= n; k++)
			ch[n][k] = (ch[n - 1][k] + ch[n - 1][k - 1]) % MD;
	}
	for (n = 1; n <= N; n++) {
		cnt[n][0] = 1;
		for (b = 1; b <= (n + 1) / 2; b++)
			for (l = b; l <= n; l++)
				cnt[n][b] = (cnt[n][b] + (long long) ch[l - 1][b - 1] * ch[n - l + 1][b]) % MD;
	}
}

int main() {
	static char cc[M + 1];
	static int iir[M + 1], iib[M + 1], dp[N + 1][M + 1][M + 1], pp[M];
	int n, m, mr, mb, c, h, i, j, k, i_, j_, k_, b, l, ans;

	init();
	scanf("%d%d%s", &n, &m, cc);
	mr = mb = 0, k = 0;
	for (i = 0; i < m; i++)
		if (cc[i] == 'r')
			iir[mr++] = i, k++;
		else if (k > 0)
			iib[mb++] = i, k--;
	ans = 1;
	for (c = 1; c <= (n + 1) / 2 && c <= mr; c++) {
		for (i = 0; i < m; i++)
			pp[i] = 1;
		for (h = 0; h < c; h++)
			pp[iir[h]] = 0;
		for (i = m - 2; i >= 0; i--)
			pp[i] += pp[i + 1];
		for (i = 0; i <= n - c + 1; i++)
			for (j = 0; j <= c && j <= i; j++)
				for (k = 0; k <= m && k <= i / 2 + j; k++)
					dp[i][j][k] = 0;
		dp[0][0][0] = 1;
		for (b = 0; b <= m; b++)
			for (l = b == 0 ? 1 : b * 2 - 1; l <= n - c + 1; l++) {
				int y = cnt[l][b];

				for (i = n - c + 1 - l; i >= 0; i--)
					for (j = min(c - 1, i); j >= 0; j--)
						for (k = min(m - b, i / 2 + j); k >= 0; k--) {
							int x = dp[i][j][k], p;

							if (x == 0)
								continue;
							p = 1;
							for (h = 1; (i_ = i + h * l) <= n - c + 1 && (j_ = j + h) <= c && (k_ = k + h * b) <= m; h++) {
								if (b > 0 && (c - j_ >= mb || pp[iib[c - j_]] < k_))
									break;
								p = (long long) p * y % MD;
								dp[i_][j_][k_] = (dp[i_][j_][k_] + (long long) x * p % MD * ch[j_][h]) % MD;
							}
						}
			}
		j = c;
		for (i = 0; i <= n - c + 1; i++)
			for (k = 0; k <= m && k <= i / 2 + j; k++)
				ans = (ans + (long long) dp[i][j][k] * ch[n - i + 1][j]) % MD;
	}
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 2336
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <numeric>
#include <array>
#include <cmath>
#include <memory>
using namespace std;
#define DEB(variable) cout << #variable << '=' << variable << endl

#define FOR(LoopVariable,numberOFbegin,numberOFend) for (long long int LoopVariable = (numberOFbegin); (LoopVariable) < (numberOFend); (LoopVariable)++)
#define DEFOR(LoopVariable,numberOFbegin,numberOFend) for (long long int LoopVariable = (numberOFbegin)-1; (LoopVariable) >= (numberOFend); (LoopVariable)--)
#define REP(LoopVariable,numberOFend) for(long long int LoopVariable = 0;(LoopVariable)<(numberOFend);LoopVariable++)

using llint = long long int;

constexpr long long int linf = numeric_limits<long long int>::max()-5;
constexpr long long int inf= numeric_limits<int>::max()-5;
constexpr long long int mod = 1000000007;

int main(){

    llint n,m;
    cin>>n>>m;
    vector<llint> v(n);
    llint sum = 0;
    REP(i,n){
        cin>>v[i];
        sum += v[i];
    }
    sort(v.begin(), v.end(), greater<llint>());

    REP(i,m){
        if((double)v[i]<(double)sum/(4.*m)){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;

    return 0;
}


Measured memory_bytes: 256
def bubblesort(array):
    flag = True
    res = 0
    while flag:
        flag = False
        for i in range(len(array)-1, 0, -1):
            if array[i] < array[i-1]:
                array[i], array[i-1] = array[i-1], array[i]
                res += 1
                flag = True
    return (array, res)
      
int(input())
arr, c = bubblesort([int(i) for i in input().split()])
print(*arr,sep=' ')
print(c)


Measured memory_bytes: 5608
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cmath>
#include <set>
#include <queue>
#include <deque>
#include <vector>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;

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

	vector<bool> exist(30);
	for (auto i = 0; i < (int)s.length(); ++i)
	{
		exist[s[i] - 'a'] = true;
	}

	auto num = 0;
	for (auto i = 0; i < (int)exist.size(); ++i)
	{
		if (exist[i])
		{
			++num;
		}
	}

	auto first = true;
	if (num <= 2)
	{
		first = false;
	}
	else if (s[0] == s[(int)s.length() - 1])
	{
		if (s.length() % 2 == 1)
		{
			first = false;
		}
	}
	else
	{
		if (s.length() % 2 == 0)
		{
			first = false;
		}
	}

	if (first)
	{
		cout << "First" << endl;
	}
	else
	{
		cout << "Second" << endl;
	}

	return 0;
}

Measured memory_bytes: 512
#include <stdio.h>
#include <algorithm>

using namespace std;

int main(){
	int n,max_num = -1000001,min_num = 1000001,tmp;
	long long int sum = 0;
	scanf("%d",&n);
	for(int i = 0; i < n; i++){
		scanf("%d",&tmp);
		sum += tmp;
		max_num = max(max_num,tmp);
		min_num = min(min_num,tmp);
	}
	printf("%d %d %lld\n",min_num,max_num,sum);
}



Measured memory_bytes: 2748
mod = 10 ** 9 + 7

h, w = map(int, input().split())
a = tuple(input() for _ in range(h))

dp = [[0] * w for _ in range(h)]
dp[0][0] = 1

# 配る
for r in range(h):
    for c in range(w):
        if a[r][c] == '#':
            continue
        if r + 1 < h and a[r + 1][c] == '.':
            dp[r + 1][c] = (dp[r + 1][c] + dp[r][c]) % mod
        if c + 1 < w and a[r][c + 1] == '.':
            dp[r][c + 1] = (dp[r][c + 1] + dp[r][c]) % mod
print(dp[h - 1][w - 1])


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

const int MAX_N  = 12;
const int MAX_M  = 12;

const int MAX_C = 99999999;

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    // Failed to predict input format
    int n, m, x;
    cin >> n >> m >> x;

    vector<int> c(n+10);
    // vector<vector<int> > a(n+1, vector<int>(m+1));
    int a[MAX_N][MAX_M];
    // int a[MAX_N][MAX_M];

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


    // 全探索
    int min_C = MAX_C;
    for(int i = 0; i < (1 << n); i++) {
        int total_C = 0;
        vector<int> total_a(m);
        fill(total_a.begin(), total_a.end(), 0);
        bitset<MAX_N> comb(i);
        string comb_s = comb.to_string();

        for(int k = MAX_N - n; k < comb_s.size(); k++) {
            if(comb_s[k] == '1') {
                for(int j = 0; j < m; j++) total_a[j] += a[k-(MAX_N -n)][j];
                total_C += c[k-(MAX_N -n)];
            }
        }

        bool flag = true;
        for(int k = 0; k < m; k++) {
            if(x > total_a[k]) {
                flag = false;
                break;
            }
        }

        if(flag && (min_C > total_C)) {
            min_C = total_C;
        }
    }

    if(min_C == MAX_C) cout << -1 << endl;
    else cout << min_C << endl;

    return 0;
}


Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, a, b) for(int i = a; i < b; i++)
#define rrep(i, n) for(int i = n-1; i >= 0; i--)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
using P = pair<int,int>;
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; }

int main(){
    int n;
    string s;
    cin >> n >> s;
    vector<vector<int>> dp(n+1, vector<int>(n+1));
    rrep(i,n ){
        rrep(j,n){
            if (s[i] == s[j]) dp[i][j] = dp[i+1][j+1] + 1;
            else dp[i][j] = 0;
        }
    }

    int ans = 0;
    rep(i,n){
        rep(j,n){
            if (i >= j) continue;
            int now = min(dp[i][j], j-i);
            ans = max(ans, now);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 101164
#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <string>
#include <functional>
#include <queue>
#include <map>
#define REP(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;

int main(){
    int n, l;
    cin >> n >> l;
    int sum = n*n/2 - n/2 + n*l;
    if(n+l-1 > 0){
        if(l > 0){
            cout << sum-l << endl;
        }else{
            cout << sum << endl;
        }
    }else{
        if(n+l-1 == 0){
            cout << sum << endl;
        }else{
            cout << sum-n-l+1 << endl;
        }
    }
}

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

int main() {
  int a, b, c, d, e, k;
  cin >> a >> b >> c >> d >> e >> k;
  
  if ( e - a > k ) {
    cout << ":(" << endl;
  }
  else {
    cout << "Yay!" << endl;
  }
 
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{

    int n,b=0;
    cin>>n;
    int a[2*n];
    for(int i=0; i<n*2; i++)
        cin>>a[i];

    for(int i=0; i<n*2; i+=2)
        b+=(a[i+1]-a[i])+1;

    cout<<b;

    return 0;
}


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

#define INF (1<<28)

struct UnionFind {
    vector<int> parent; 
    UnionFind(int size) : parent(size, -1) {}
    int root(int x) {
        if (parent[x] < 0) return x;
        return parent[x] = root(parent[x]); 
    }
    void unite(int x, int y) {
        x = root(x);
        y = root(y);
        if (x == y) return;
        parent[x] = y;
    }
    bool same(int x, int y) {
        return root(x) == root(y);
    }
    bool all_same() {
        for (int i = 1; i < parent.size(); i++) 
            if (!same(0, i)) return false;
        return true;
    }
};

struct Edge {
    int from, to;
    int cost;
    Edge(int from, int to, int cost) : from(from), to(to), cost(cost) {}
    bool operator<(const Edge &o) const {
        return (cost < o.cost);
    }
    bool operator>(const Edge &o) const {
        return (cost > o.cost);
    }
};

typedef vector<Edge> Vertex;

struct Graph {
    vector<Vertex> g;
    Graph(int vertex_count=0) : g(vertex_count) {}

    inline Vertex& operator[](int index) {
        return g[index];
    }

    inline void add_edge(int from, int to, int cost) {
        g[from].push_back(Edge(from, to, cost));
    }

    int kruskal() { 
        vector<Edge> edges;
        for (int i = 0; i < g.size(); i++) 
            for (int j = 0; j < g[i].size(); j++) 
                edges.push_back(g[i][j]);
        sort(edges.begin(), edges.end(), greater<Edge>());

        int ret = -1;
        for (int k = 0; k < edges.size(); k++) {
            UnionFind uf(g.size());
            int lb = INF, ub = 0;
            for (int i = k; i < edges.size(); i++) {
                Edge e = edges[i];
                if (!uf.same(e.from, e.to)) {
                    uf.unite(e.from, e.to);
                    lb = min(lb, e.cost);
                    ub = max(ub, e.cost);
                }
            }
            if (uf.all_same()) {
                if (ret == -1) ret = ub-lb;
                else ret = min(ret, (ub-lb));
            }
        }
        return ret;
    }
};

int main() {
    int n, m;
    while (cin >> n >> m, n || m) {
        Graph g(n);
        for (int i = 0; i < m; i++) {
            int a, b, w;
            scanf("%d %d %d", &a, &b, &w);
            a--, b--;
            g.add_edge(a, b, w);
        }
        printf("%d\n", g.kruskal());
    }
    return 0;
}

Measured memory_bytes: 1448
#include<iostream>
#include<map>
#include<queue>
using namespace std;

string s;
char c[] = {'r','b','g'};

char rem(char a,char b){
  for(int i=0;i<3;i++){
    if(c[i] != a && c[i] != b)return c[i];
  }
  return 'x';
}

int main(){
  while(cin >> s,s!="0"){
    map<string,int> m;
    m[s] = 0;
    queue<string> q;
    q.push(s);
    
    int res = -1;
    while(q.size()){
      s = q.front(); q.pop();
      bool f = true;
      for(int i=0;i<s.size()-1;i++){
	if(s[i]!=s[i+1]){
	  f = false;
	  string tmp = s;
	  tmp[i] = tmp[i+1] = rem(s[i],s[i+1]);
	  if(m.find(tmp)==m.end()){
	    m[tmp] = m[s] + 1;
	    q.push(tmp);
	  }
	}
      }
      if(f){
	res = m[s];
	break;
      }
    }
    if(res<0)cout << "NA\n";
    else cout << res << endl;
  }
}	

Measured memory_bytes: 2880
#include<iostream>
using namespace std;
int fa[200001];
int t[200001];
int getf(int k)
{
	return fa[k]==k?k:fa[k]=getf(fa[k]);
}
int main()
{
	int n,m;cin>>n>>m;
	for(int i=1;i<=n;i++)fa[i]=i;
	for(int i=1;i<=m;i++)
	{
		int u,v;cin>>u>>v;
		fa[getf(u)]=getf(v);
	}
	for(int i=1;i<=n;i++)
		t[getf(i)]++;
	int ans=0;
	for(int i=1;i<=n;i++)
		ans=max(ans,t[i]);
	cout<<ans;
	return 0;
}

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

int main() {
  string s1;
  cin >> s1;
  if (s1 == "Sunny") {
    cout << "Cloudy" << endl;
  }
  else if (s1 == "Cloudy") {
    cout << "Rainy" << endl;
  }
  else {
    cout << "Sunny" << endl;
  }
}

Measured memory_bytes: 256
#include<string>
#include<iostream>
#include<unordered_map>

using namespace std;

int main(void) {
  
  string s;
  cin >> s;
  
  unordered_map<char, char> map;
  map['A'] = 'T';
  map['T'] = 'A';
  map['C'] = 'G';
  map['G'] = 'C';
  
  for(int i = 0; i < s.size(); ++i) {
    s[i] = map[s[i]];
  }
  
  cout << s << endl;
  
  return 0;
  
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
    int A, B, C;
    cin >> A >> B >> C;
    while(C != 0) {
        if(B >= A * C) {
            cout << C << endl;
            return 0;
        }
        C--;
    }
    cout << C << endl;
    return 0;
}

Measured memory_bytes: 256
//do not think about past and stay in this moment
//organize and work - Abhinav IIITA
#include <bits/stdc++.h>
#include <ctime>
using namespace std;
#define int long long
#define ld long double
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(),(v).end() 
const ld pi = acos(-1.0);
const int day[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());


// -----------------------------------------------------------------------




// -----------------------------------------------------------------------

int arr[3000000];
void input(int n){
	for(int i=0;i<n;++i)
	cin>>arr[i];
}

// -----------------------------------------------------------------------



void solve(){
	int n;
  cin>>n;
  map<int,int>mp;
  while(n--)
  {
    int tp;
    cin>>tp;
    mp[tp]++;
  }
  cout<<mp.size();
  
	
	
		
}


// -----------------------------------------------------------------------


int32_t main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); 	
	int t=1;
	//cin>>t;
	while(t--)
	solve();
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
static const int MAX = 200000;

int main()
{
    int R[MAX], n;

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

    int maxv = -2000000000;
    int minv = R[0];

    for (int i = 1; i < n; i++)
    {
        maxv = max(maxv, R[i] - minv);
        minv = min(minv, R[i]);
    }

    cout << maxv << endl;

    return 0;
}       


Measured memory_bytes: 3876
x = int(input())

c5 = []
iter5 = []
for i in range(-1000, 1000, 1): # 100
    c5.append(i**5)
    iter5.append(i)

a, b = 0, 0
for i in range(len(c5)):
    for j in range(len(c5)):
        if (c5[i] - c5[j]) == x:
            a, b = iter5[i], iter5[j]
            break

print(a,b)

Measured memory_bytes: 9328
n = int(input())
al = list(map(int, input().split()))


def is_diff_sign(s, t):
    return (s > 0 > t) or (s < 0 < t)


def count(_list, first):
    cnt = abs(first - _list[0])
    prev_sum = first
    prev_positive = first > 0
    for a in _list[1:]:
        _sum = prev_sum + a
        if is_diff_sign(prev_sum, _sum):
            prev_sum = _sum
            prev_positive = prev_sum > 0
            continue
        if prev_positive:
            prev_sum = -1
        else:
            prev_sum = 1
        prev_positive = not prev_positive
        cnt += abs(_sum) + 1
    return cnt


ans = 0
if al[0] == 0:
    ans = min(count(al, 1), count(al, -1))
else:
    ans = min(count(al, al[0]), count(al, -al[0] // abs(al[0])))
print(ans)


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

set<int>prime;
int main(){
	prime.insert(2);
	for(int i=3;i<500000;i++){
		for(int j=2;j*j<=i;j++){
			if(i%j==0)goto fail;
		}
		prime.insert(i);
		fail:;
	}
	
	int n;
	while(cin>>n && n){
		int ans=0;
		for(set<int>::iterator itr=prime.upper_bound(n);*itr<=n*2;itr++)ans++;
		cout<<ans<<endl;
	}
	
}

Measured memory_bytes: 3136
using System;
using System.Collections.Generic;
using System.Linq;

class Program
{

    static void Main(string[] args)
    {

        int n = int.Parse(Console.ReadLine());
        var list = new List<hoge>();
        for (var i = 1; i <= n; i++)
        {
            var s = Console.ReadLine().Split(' ');
            list.Add(new hoge(i, s[0], s[1]));
        }

        foreach (var v in list.OrderByDescending(x => x.score).OrderBy(x => x.name))
        {
            Console.WriteLine(v.seq.ToString());
        }
    }
    public class hoge
    {
        public int seq { get; set; }
        public string name { get; set; }
        public int score { get; set; }

        public hoge(int seq, string name, string score)
        {
            this.seq = seq;
            this.name = name;
            this.score = int.Parse(score);
        }
    }
}


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

#define rep(i, s, n) for(int i = s; i < n; ++i)
#define rrep(i, n) for(int i = n - 1; i > -1; --i)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
using namespace std;
const long long INF = 1000000000;
const int MOD = 1000000007;
typedef long long ll;
typedef pair<int, int> P;

int main() {
    int n, m;
    cin >> n >> m;
    priority_queue<int> que;
    int tmp;
    rep(i, 0, n){
        cin >> tmp;
        que.push(tmp);
    }
    rep(i, 0, m){
        tmp = que.top();
        que.pop();
        que.push(tmp / 2);
    }
    ll ans = 0;
    rep(i, 0, n){
        ans += que.top();
        que.pop();
    }
    cout << ans << endl;

}


Measured memory_bytes: 892
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <cstring>
#include <iomanip>

using namespace std;
// ascending order
#define vsort(v) sort(v.begin(), v.end())
// descending order
#define vsort_r(v) sort(v.begin(), v.end(), greater<int>())
#define vunique(v) unique(v.begin(), v.end())
#define mp make_pair
#define ts(x) to_string(x)
#define rep(i, a, b) for(int i = (int)a; i < (int)b; i++)
#define repm(i, a, b) for(int i = (int)a; i > (int)b; i--)
#define bit(a) bitset<8>(a)
#define des_priority_queue priority_queue<int, vector<int>, greater<int> >
#define all(v) (v).begin(), (v).end()
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1ll << 60;

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

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

    int a[5], k;
    rep(i, 0, 5) cin >> a[i];
    cin >> k;
    sort(a, a + 5);
    if(a[4] - a[0] <= k) cout << "Yay!" << endl;
    else cout << ":(" << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long i,j,k,a,b,n,m;
	cin>>n>>a>>b;

	if(n==1)
	{
		if(a==b)
			cout<<"1";
		else
			cout<<"0";
	}
	else
	{
		if(a>b)
			cout<<"0";
		else
			cout<< ((n-1)*b+a) - ((n-1)*a+b) + 1 ;
	}
	return 0;
}
/*有4根竹竿，最短的有4节，最长的6节。
这时将竹竿可能组合出如下5种不同节数：
18=4+4+4+6, 19=4+4+5+6, 20=4+5+5+6, 21=4+5+6+6
 22=4+6+6+6，所以应当输出5    。其中，4+4+6+6也是20*/
//

Measured memory_bytes: 256