akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashSet;
import java.util.Set;
import java.util.StringTokenizer;

public class Main {
    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            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;
        }
    }
    public static void main(String[] args) {
        FastReader fr = new FastReader();
        int x = fr.nextInt();
        int n = fr.nextInt();
        if(n==0){
            System.out.println(x);
        }
        else{
            Set<Integer> set = new HashSet<>();
            for (int i = 0; i < n; i++) {
                set.add(fr.nextInt());
            }
            if(!set.contains(x)){
                System.out.println(x);
            }
            else{
                int forward = x+1;
                while(set.contains(forward)){
                    forward++;
                }
                int backward = x-1;
                while(set.contains(backward)){
                    backward--;
                }
                int val1 = forward-x;
                int val2 = 0;
                if(backward<0){
                    val2+=(x);
                    val2+=(Math.abs(backward));
                }
                else{
                    val2=(x-backward);
                }
                if(val1<val2){
                    System.out.println(x+val1);
                }
                else{
                    System.out.println(x-val2);
                }
            }
        }
    }
}

Measured memory_bytes: 32636
#include<iostream>
#include<queue>
#include<set>
#include<iomanip>

#define N 5
using namespace std;

#define NORTH 0
#define EAST 1
#define SOUTH 2
#define WEST 3

const int di[] = {-1,0,1,0};
const int dj[] = {0,1,0,-1};

struct Dice{
  int D[6];
  Dice(){for(int i = 0; i < 6; ++i)D[i]=-1;}
  void roll(int dir){
    int t;
    switch(dir){
    case NORTH:t=D[4];D[4]=D[5];D[5]=D[1];D[1]=D[0];D[0]=t;break;
    case EAST: t=D[3];D[3]=D[5];D[5]=D[2];D[2]=D[0];D[0]=t;break;
    case SOUTH:t=D[1];D[1]=D[5];D[5]=D[4];D[4]=D[0];D[0]=t;break;
    case WEST: t=D[2];D[2]=D[5];D[5]=D[3];D[3]=D[0];D[0]=t;break;
    }
  }
  bool isDice(){
    for(int i = 0; i < 3;++i){
      if(D[i]+D[5-i]!=7)return false;
    }
    return true;
  }
};

struct state{
  int i,j,pre;
  state(int i, int j, int p):i(i),j(j),pre(p){}
};

bool isinside(int i, int j){
  return 0<=i&&i<N&&0<=j&&j<N;
}

bool solve(int M[][N], int sti, int stj, int L){
  queue<state> Q;
  set<pair<int,int> > vS;
  state st(sti,stj,1);
  Dice d;
  d.D[0]=M[sti][stj];
  Q.push(st);
  int stop=0;
  while(!Q.empty()){
    ++stop;
    if(stop>625)break;
    state now = Q.front();Q.pop();
    vS.insert(make_pair(now.i,now.j));
    for(int k = (now.pre-1+4)%4, nk=0; nk < 4; ++nk){
      state next(now.i+di[k],now.j+dj[k],k);
      Dice td=d;
      if(isinside(next.i,next.j)&&M[next.i][next.j]>0){
	td.roll(k);
	if(td.D[0]==-1||td.D[0]==M[next.i][next.j]){
	  td.D[0]=M[next.i][next.j];
	  Q.push(next);
	  d=td;
	  break;
	}else return false;
      }
      ++k;
      k%=4;
    }
  }
  set<int> S;
  for(int i = 0; i < 6; ++i){
    if(d.D[i]>0&&d.D[i]<7)S.insert(d.D[i]);
  }
  return (S.size()==6)&&vS.size()==6&&d.isDice()&&L==6;
}

int main(){
  int T;
  
  cin >> T;
  for(int tc=1;tc<=T;++tc){

    int M[N][N];
    int sti,stj,l=0;
    
    for(int i = 0; i < N; ++i){
      for(int j = 0; j < N; ++j){
	cin >> M[i][j];
	if(M[i][j]>0){
	  sti=i;
	  stj=j;
	  ++l;
	}
      }
    }
    cout << (solve(M,sti,stj,l)?"true":"false") << endl;
  }
  return 0;
}

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

void solve(int MAP[12][12],int i,int j);

int main()
{
    int MAP[12][12];
    string str;

    while(true)
    {
        int cnt = 0;

        for(int i=0; i<12; i++){
            cin >> str;
            if(cin.eof())break;
            for(int j=0; j<12; j++){
                MAP[i][j] = str[j]-'0';
            }
        }
        if(cin.eof())return 0;

        for(int i=0; i<12; i++){
            for(int j=0; j<12; j++){
                if(MAP[i][j] == 1){
                    solve(MAP,i,j);
                    cnt++;
                }
            }
        }

        cout << cnt << endl;
    }

    return 0;
}

void solve(int MAP[12][12],int i,int j)
{
    MAP[i][j] = 2;

    if(i-1 >= 0){
        if(MAP[i-1][j] == 1){
            solve(MAP,i-1,j);
        }
    }
    if(i+1 <= 11){
        if(MAP[i+1][j] == 1){
            solve(MAP,i+1,j);
        }
    }
    if(j-1 >= 0){
        if(MAP[i][j-1] == 1){
            solve(MAP,i,j-1);
        }
    }
    if(j+1 <= 11){
        if(MAP[i][j+1] == 1){
            solve(MAP,i,j+1);
        }
    }

}

Measured memory_bytes: 1188
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
using System.Threading;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            int A = int.Parse(input[0]);
            int B = int.Parse(input[1]);

            Console.WriteLine(A * B);
        }
    }
}


Measured memory_bytes: 27532
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a) for(int i = 0; i < (a); i++)
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const int MOD = 1e9 + 7;

int main(){
	int a,b,c,x;
	cin >> a;
	cin >> b;
	cin >> c;
	cin >> x;
	int cnt = 0;
	for(int i = 0; i <= a; i++){
		for(int j = 0; j <= b; j++){
			for(int k = 0; k <= c; k++){
				if(500 * i + 100 * j + 50 * k == x) cnt++;
			}
		}
	}
	cout << cnt << endl;
}

Measured memory_bytes: 256
S = input()

mae = int(S[:2])
ato = int(S[2:])

if 1 <= mae <= 12 and 1 <= ato <= 12:
  print("AMBIGUOUS")
elif 1 <= ato <= 12:
  print("YYMM")
elif 1 <= mae <= 12:
  print("MMYY")
else:
  print("NA")

Measured memory_bytes: 3060
#include<iostream>
#include<map>
#include<numeric>
#include<set>
#include<vector>
#include<algorithm>
#include<cstdlib>
template<typename T>
void fin(T const& t){ std::cout << t << std::endl; exit(0); }

struct union_find {
  std::vector<int> par, rank;
  
  explicit union_find(int n): par(n), rank(n,0) {
    std::iota(par.begin(), par.end(), 0);
  }
  
  int find(int x) {
    if(par[x] == x) return x;
    return par[x] = find(par[x]);
  }
  
  void unite(int x, int y) {
    x = find(x); y = find(y);
    if(x == y) return;
    if(rank[x] < rank[y]) par[x] = y;
    else {
      par[y] = x;
      if(rank[x] == rank[y]) ++rank[x];
    }
  }
};

int main() {
  int N; std::cin >> N;
  union_find uf(2e5);
  for(int i = 0; i < N; ++i) {
    int x, y; std::cin >> x >> y; --x; --y; y += 1e5;
    uf.unite(x, y);
  }
  
  std::map<int,int> cmpx, cmpy;
  for(int i = 0; i < 1e5; ++i) ++cmpx[uf.find(i)];
  for(int i = 1e5; i < 2e5; ++i) ++cmpy[uf.find(i)];
  int64_t ans = -N;
  for(auto const& p: cmpx) ans += (int64_t)p.second * cmpy[p.first];
  fin(ans);
  return 0;
}


Measured memory_bytes: 15872
def f(n,k):
  total = 0
  
  for u in range(1, n + 1):
    prob = 1.0/n 
    start = u
    p = 0
    while(start < k):
      start *= 2
      p+=1
    prob *= (0.5) ** p
    total += prob
  return total

n,k = map(int ,raw_input().split(' '))
print f(n,k)

Measured memory_bytes: 30060
n, m = map(int, input().split())

ab = []
for i in range(n):
  a, b = map(int, input().split())
  ab.append([a,b])

cd = []
for i in range(m):
  c, d = map(int, input().split())
  cd.append([c,d])



for i in range(len(ab)):
  x = [10000000000000000, 1000]
  for j in range(len(cd)):
    if x[0] > abs(ab[i][0] - cd[j][0]) + abs(ab[i][1] - cd[j][1]):
      x[0] = abs(ab[i][0] - cd[j][0]) + abs(ab[i][1] - cd[j][1])
      x[1] = j

  print(x[1] + 1)

Measured memory_bytes: 3064
//#include<bits/stdc++.h>
#include<iostream>
#include<cmath>
#include<cstdio>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<utility>
#include<algorithm>
#include<cstring>
#include<sstream>
#include <iomanip>

using namespace std;

typedef long long ll ;
typedef double db;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector< pair<int,int> > vii;
const double pi = 2*acos(0) ;

#define pf		  	printf
#define sf			  scanf
#define pb(a)         push_back(a)
#define mp			make_pair
#define fi			 first
#define se			 second
#define for0(i,n)        for(ll i=0;i<n;i++)
#define for1(i,n)        for(int i=1;i<=n;i++)
#define forab(i,a,b)       for(int i=a;i<=b;i++)
#define lcm(a, b)     ((a)*((b)/gcd(a,b)))
#define sq(a)		   (a)*(a)
#define nw				"\n"
#define abs(x)		fabs(x)
#define pcase(z,x)    cout<<"Case "<<z<<": "<<x<<"\n"
int main()
{
	ll n,m,x,s=0;
	cin>>n>>m;
	pair<ll,ll>p[n];
	for0(i,n){
		cin>>p[i].fi;
		cin>>p[i].se;
		}
	sort(p,p+n);
	for0(i,n){
		x = min(m,p[i].se);
		s += x*p[i].fi;
		m -= x;
		if(m==0) break;
		}
	cout<<s<<nw;
	return 0;
}

Measured memory_bytes: 1792
#include <iostream>

using namespace std;

int t[8]={0, 1, 2, 3, 5, 7, 8, 9};

void solve(int);

int main() {

	int n;

	while(cin >> n) {
		if(!n) {
			break;
		}
		solve(n);
		cout << endl;
	}

	return 0;

}

void solve(int n) {

	if(n>=8) {
		solve(n/8);
	}

	cout << t[n%8];
	
}

Measured memory_bytes: 868
lis = [int(input()) for _ in range(5)]
lis1 = [lis[i]%10 for i in range(5)]
lis10 = [lis[i]//10 for i in range(5)]
ans = 0
for i in range(5):
    if lis1[i]:
        ans += 10
    if not lis1[i]:
        lis1[i] = 10
minlis1 = min(lis1)
ans += sum(lis10)*10
ans += minlis1-10

print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <string.h>
#include <math.h>
#include <stdlib.h>
using namespace std;

int main(void) {
	// your code goes here
	char s[101],t[101];
	cin >> s >> t;
	int l=strlen(s);
	for(int i=0;i<l;i++){
		int flag=0;
		for(int j=0;j<l;j++){
			if(s[j]!=t[(i+j)%l]) flag=1;
		}
		if(flag==0) {
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" <<endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<set>
#include<map>
#include<cmath>
#include<string>
#include<cstring>
using namespace std;
int main()
{
	string str;
	cin >> str;
	bool wa = false;
	int n = str.length();
	int l = 0, r = n - 1;
	while (l <= r)
	{
		if (str[l] != str[r])
		{
			wa = true;
			break;
		}
		l++, r--;
	}
	l = 0, r = (n - 1) / 2 - 1;
	while (l <= r)
	{
		if (str[l] != str[r])
		{
			wa = true;
			break;
		}
		l++, r--;
	}
	l = (n + 3) / 2 - 1, r = n - 1;
	while (l <= r)
	{
		if (str[l] != str[r])
		{
			wa = true;
			break;
		}
		l++, r--;
	}
	if (!wa)cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

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

const int V_MAX=100000;
const int E_MAX=100000;

vector<int> G[V_MAX];
int used[V_MAX]={};
bool flag=false;

void dfs(int s){
	if(used[s]==1){return;}
	used[s]=2;
	for (int i=0;i<G[s].size();i++){
		if(used[G[s][i]]==2){
			flag=true;
		}
		if(used[G[s][i]]==0)
		dfs(G[s][i]);
	}
	used[s]=1;
}

int main(){
	int V,E,s,t;
	cin>> V >> E;
	for (int i=0;i<E;i++){
		cin >> s >> t;
		G[s].push_back(t);
	}
	
	for(int i=0;i<V;i++){
		dfs(i);
	}
	
	flag ? cout << 1 << endl : cout << 0 <<endl;
	
	return 0;
}

Measured memory_bytes: 5488
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.io.IOException;
import java.io.InputStream;

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

    static class DTriangles {
        PrintWriter out;
        InputReader in;

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            this.out = out;
            this.in = in;
            int n = ni();
            int[] arr = new int[n];
            int i = 0, j = 0;
            for (i = 0; i < n; i++)
                arr[i] = ni();
            Arrays.sort(arr);
            long ans = 0;
            for (i = 0; i < n; i++) {
                for (j = i + 1; j < n; j++) {
                    int sum = arr[i] + arr[j];
                    int lo = j + 1, hi = n - 1;
                    while (lo <= hi) {
                        int mid = (lo + hi) >> 1;
                        if (arr[mid] < sum)
                            lo = mid + 1;
                        else
                            hi = mid - 1;
                    }
                    ans += lo - j - 1;
                }
            }
            pn(ans);
        }

        int ni() {
            return in.nextInt();
        }

        void pn(long zx) {
            out.println(zx);
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1) {
                throw new UnknownError();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new UnknownError();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

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

        public String next() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            StringBuffer res = new StringBuffer();
            do {
                res.appendCodePoint(c);
                c = read();
            } while (!isSpaceChar(c));

            return res.toString();
        }

        private boolean isSpaceChar(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

    }
}



Measured memory_bytes: 24276
#include<bits/stdc++.h>
using namespace std;
const int maxn=3e5+10;
int n,m;
priority_queue<int> q;
pair<int,int> p[maxn];

int main(){
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++){
        scanf("%d%d",&p[i].first,&p[i].second);
        p[i].first=m-p[i].first+1;
    }
    sort(p+1,p+1+n);

    reverse(p+1,p+1+n);
   /* for(int i=1;i<=n;i++){
        cerr<<p[i].first<<' '<<p[i].second<<'\n';
    }*/
    int pt=1;
    while(pt<=n&&p[pt].first>m)++pt;
    long long ans=0;
    for(int i=m;i>=1;i--){
        while(p[pt].first>=i&&pt<=n){
            q.push(p[pt].second);
            ++pt;
        }
        if(!q.empty()){
         ///   cerr<<i<<' '<<q.top()<<'\n';
            ans+=q.top();
            q.pop();
        }
    }
    printf("%lld\n",ans);
}


Measured memory_bytes: 1660
#include<bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
typedef long long ll;
#define pb push_back

// 累積積でa^nを計算
ll pow(ll a, ll n){
    ll res = 1;
    while(n>0){
        if(n&1) res = res*a; 
        a = a*a;
        n >>= 1; 
    }
    return res;
}
void solve(){
    ll n, m; cin >> n >> m;
    priority_queue<ll> a;
    REP(i, n){
        ll b;
        cin >> b;
        a.push(b);
    }
    ll sum = 0;
    
    while(m!=0){
        ll mx = a.top();
        a.pop();
        //cout << mx << endl;
        mx = mx/2;
        a.push(mx);
        m--;
    }
    
    REP(i, n){
        sum += a.top();
        a.pop();
    }
    cout << sum << endl;
    

}

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

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

long long N, M, a[100009][3], maxn = -(1LL << 60);

int main(){
    cin >> N >> M;
    for(int i = 1; i <= N; i++){
        for(int j = 0; j < 3; j++) cin >> a[i][j];
    }
    for(int i = 0; i < 8; i++){
        vector<long long> vec;
        for(int j = 1; j <= N; j++){
            long long S = 0;
            for(int k = 0; k < 3; k++){
                if ((i / ( 1 << k)) % 2 == 0)
                    S += a[j][k];
                else 
                    S -= a[j][k];
                }
            vec.push_back(S);
        }
        sort(vec.begin(), vec.end());
        reverse(vec.begin(), vec.end());
        long long ans = 0;
        for(int j = 0; j < M; j++)
        ans += vec[j];
        maxn = max(maxn, ans);
    }
    cout << maxn << endl;
    return 0;
}

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

#define LL long long
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ALL(x) (x).begin(),(x).end()
const int IINF = 1e9;
const LL LINF = 1e18;
const LL mod = 1e9+7;

bool match(string s, string t) {
    if(s.size() != t.size())
        return false;
    REP(i, s.size()) {
        if(s[i] != t[i] && s[i] != '?')
            return false;
    }
    return true;
}

string replace(string s) {
    REP(i, s.size()) {
        s[i] = s[i] == '?' ? 'a' : s[i];
    }
    return s;
}

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

    bool p = false;
    string res = "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz";
    FOR(i, 0, s.size() - t.size() + 1) {
        if(match(s.substr(i, t.size()), t)) {
            p = true;
            string x = s;
            res = min(res, replace(x.replace(i, t.size(), t)));
        }
    }
    if(p) {
        cout << res << endl;
    }else{
        cout << "UNRESTORABLE" << endl;
    }
    return 0;
}



Measured memory_bytes: 256
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctype.h>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>

using namespace std;
int top = 0;
stack<int> S;
int a,b,x,y;
char s[1000];

int main(){
	while(scanf("%s",s) != EOF){
		if(s[0] == '+'){
			a = S.top();
			S.pop();
			b = S.top();
			S.pop();
			y = a + b;
			S.push(y);
		}else if(s[0] == '-'){
			a = S.top();
			S.pop();
			b = S.top();
			S.pop();
			y = b - a;
			S.push(y);
		}else if(s[0] == '*'){
			a = S.top();
			S.pop();
			b = S.top();
			S.pop();
			y = a * b;
			S.push(y);
		}else{
			x = atoi(s);
			S.push(x);
		}
	}
	cout << S.top() << endl;
}

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

int is_taisyou(char a,char b) {
	if(a=='i' && b=='i')return 1;
	if(a=='w' && b=='w')return 1;
	if(a=='(' && b==')')return 1;
	if(a==')' && b=='(')return 1;
	return 0;
}

int main(void) {
	char input[12];
	int count;
	int i,length,length2;
	scanf("%s",input);
	length=strlen(input);
	length2=(strlen(input)+1)/2;
	count=0;
	for(i=0;i<length2;i++) {
		if(!is_taisyou(input[i],input[length-i-1]))count++;
	}
	printf("%d\n",count);
	return 0;
}

Measured memory_bytes: 0
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define ld double 
#define rep(i,a,b) for(ll i=a; i<b; ++i)
#define BOOST std::ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb push_back
#define all(v) v.begin(),v.end()
#define sl(a) a.size()
#define mod 1000000007 
#define lcm(a,b) (a*b)/__gcd(a,b)
#define MAX1 100006
#define f first
#define s second
#define pi 2*acos(0.0)
void solve()
{
    ll ans=0;
    string str;  cin>>str;
    rep(i,0,sl(str)) ans+=(str[i]-'0');
    cout<<(ans%9==0?"Yes":"No");
}
int main()
{
    #ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input.txt","r",stdin);
    //for getting error from error.txt
    freopen("error.txt", "w", stderr);
    // for writing output to output.txt
    freopen("output.txt","w",stdout);
    #endif
    BOOST
    int T=1;  //cin>>T;
    while(T--) solve();
    cerr<<"Time taken : "<<(float)clock()/CLOCKS_PER_SEC<<" secs"<<"\n";
    cerr<<"My CLOCKS_PER_SEC= "<<CLOCKS_PER_SEC<<"\n";
    return 0;
}


Measured memory_bytes: 3900
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <numeric>
#include <queue>
#include <vector>
#include <cmath>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <set>
#include <map>
#include <stack>

using namespace std;

typedef long long LL;
typedef pair<int, int> PII;

#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repl(i, n) for(LL i = 0; i < (LL)(n); i++)

int main(void){
  LL a, b, x;
  cin >> a >> b >> x;

  if (a > 0) {
    cout << (b / x) - ((a-1) / x) << endl;
  } else {
    cout << b / x + 1 << endl;
  }

  return 0;
}

Measured memory_bytes: 256
n=int(input())
arr=list(map(int,input().split()))
if n==1:
  print('YES')
else:
  sum1=sum(arr)
  sum2=(n*(n+1))//2
  moves=sum1//sum2
  cnt=0
  if sum1%sum2!=0:
    print('NO')
  else:
    flag=True
    arr2=[]
    for i in range(n-1):
      tmp=arr[i]+moves
      if arr[i+1]==tmp:
        continue
      else:
        diff=tmp-arr[i+1]
        if diff%n!=0:
          flag=False
        else:
          arr2.append(n-i)
          cnt+=diff//n
          tmp=arr[i+1]-diff//n
          if tmp>n*(moves-diff//n):
            flag=False
    if flag==False:
      print('NO')
    else:
      if len(arr2)==moves:
        if arr[0]==sum(arr2):
          print('YES')
        else:
          print('NO')
      elif len(arr2)>moves:
        print('NO')
      else:
        if 1*(moves-len(arr2))<=arr[0]-sum(arr2)<=n*(moves-len(arr2)):
          print('YES')
        else:
          print('NO')

Measured memory_bytes: 14996
#include <iostream>
 using std::cin;
 using std::cout;
 using std::endl;

 #include <map>
 using std::map;

 #include <string>
using std::string;

 map<string, int> memo;

 int main (void) {
 int n;

 scanf("%lld", &n);
 for (int i = 0; i < n; i++) {
 string s;
 cin >> s;

 memo[s] += 1;
 }


 int maxv = 0;
 for (const auto& x : memo) {
 int v = x.second;
 if (v > maxv) maxv = v;
 }
 for (auto it = memo.begin(); it != memo.end(); it++) {
 if (it->second == maxv) {
 cout << it->first << endl;

 }
 }

 return 0;
 }


Measured memory_bytes: 25216
/**
 * File    : E.cpp
 * Author  : Kazune Takahashi
 * Created : 2018-3-11 21:22:55
 * Powered by Visual Studio Code
 */

#include <iostream>
#include <iomanip>   // << fixed << setprecision(xxx)
#include <algorithm> // do { } while ( next_permutation(A, A+xxx) ) ;
#include <vector>
#include <string> // to_string(nnn) // substr(m, n) // stoi(nnn)
#include <complex>
#include <tuple>
#include <queue>
#include <stack>
#include <map> // if (M.find(key) != M.end()) { }
#include <set>
#include <random> // random_device rd; mt19937 mt(rd());
#include <cctype>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
using namespace std;

#define DEBUG 0 // change 0 -> 1 if we need debug.

typedef long long ll;

// const ll dx[4] = {1, 0, -1, 0};
// const ll dy[4] = {0, 1, 0, -1};

// const ll C = 1e6+10;
// const ll M = 1000000007;

ll N, A, B;

bool ok()
{
  return (1 <= A && A <= N && 1 <= B && B <= N && A + B <= N+1 && A * B >= N);
}

vector<ll> V;
vector<ll> W;
map<ll, ll> M;

int main()
{
  cin >> N >> A >> B;
  if (!ok())
  {
    cout << -1 << endl;
    return 0;
  }
  ll now = 0;
  for (auto j = 0; j < A; j++)
  {
    if ((ll)V.size() >= N)
      break;
    V.push_back(now);
    now++;
  }
  now -= N * N * N;
  for (auto i = 0; i < B-1; i++)
  {
    if ((ll)V.size() >= N)
      break;
    V.push_back(now);
    now--;
  }
  now = -4 * A;
  for (auto i = 0; i < B-1; i++)
  {
    for (auto j = 0; j < A-1; j++)
    {
      if ((ll)V.size() >= N)
        break;
      V.push_back(now);
      now++;
    }
    if ((ll)V.size() >= N)
      break;
    now -= 4 * A;
  }
  W = V;
  sort(W.begin(), W.end());
  for (auto i = 0; i < N; i++)
  {
    M[W[i]] = i+1;
  }
  for (auto i = 0; i < N; i++)
  {
    V[i] = M[V[i]];
  }
  for (auto i = 0; i < N; i++)
  {
    cout << V[i];
    if (i < N-1)
    {
      cout << " ";
    }
    else
    {
      cout << endl;
    }
  }
}

Measured memory_bytes: 26348
#include "bits/stdc++.h"
using namespace std;
#define Rep(i,n) for(int i=0;i<n;i++)
#define For(i,n1,n2) for(int i=n1;i<n2;i++)
#define REP(i,n) for(ll i=0;i<n;i++)
#define RREP(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,n1,n2) for(ll i=n1;i<n2;i++)
#define put(a) cout<<a<<"\n"
#define all(a)  (a).begin(),(a).end()
#define SORT(a) sort((a).begin(),(a).end())
#define oorret 0
#define oor(x) [&](){try{x;} catch(const out_of_range& oor){return oorret;} return x;}()
typedef long long ll;
typedef pair<int, int> P;
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;}

int main(){
    int a;
    cin >> a;
    put(48-a);
    return 0;
}


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

using ll = long long;

#define mod 1000000007
#define REP(i, n) for (int i = 0; i < n; i++)
#define INF (1 << 29)

using namespace std;

//long C(long n, long r);
//long long gcd(long long a, long long b);
//long long lcm(long long a, long long b);


void solve()
{
    string t;
    cin >> t;
    char opt[2] = {'+', '-'};
    for(int i = 0; i <= 1; i++){
        for(int j = 0; j <= 1; j++){
            for(int k = 0; k <= 1; k++) {
                if((t[0]-'0') + (int)pow(-1, i) * (t[1]-'0') + (int)pow(-1, j) * (t[2]-'0') + (int)pow(-1, k) * (t[3]-'0') == 7){
                    cout << t[0]-'0' << opt[i] << t[1]-'0' << opt[j] << t[2]-'0' << opt[k] << t[3]-'0' << "=7" << endl;
                    return;
                }
            }
        }
    }
}

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

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		String[] str = new Scanner(System.in).nextLine().replace(',', ' ').replace('.', ' ').split(" ");
		boolean isF = true;
		for (String s : str) {
			int l = s.length();
			if (3 <= l && l <= 6) {
				if (!isF) {
					System.out.print(' ');
				}
				System.out.print(s);
				isF = false;
			}
		}
		System.out.println();
	}
}

Measured memory_bytes: 12000
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop
from itertools import permutations, accumulate
from math import sqrt, ceil, floor
from bisect import bisect_left, bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
import sys
def I(): return int(input())  # '123' -> 123
def Is(): return map(int, input().split())  # '123 456' -> 123, 456
def LI(): return list(map(int, input().split()))  # '123 456' -> [123, 456]
def TI(): return tuple(map(int, input().split()))  # '123 456' -> (123, 456)
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def TIR(n): return [TI() for _ in range(n)]
def S(): return input()
def Ss(): return input().split()  # 'aa bb' -> 'aa','bb' or ['aa','bb']
def LS(): return list(input())  # 'abc123' -> ['a','b','c','1','2','3']
def SR(n): return [S() for _ in range(n)]
def SsR(n): return [Ss() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
sys.setrecursionlimit(1000000)
MOD = 1000000007
INF = float('inf')

N, K = Is()
S = [0]*N

for _ in range(K):
    d = I()
    A = LI()
    for i in A:
        S[i-1] += 1


ans = 0
for s in S:
    if s == 0:
        ans += 1

print(ans)

Measured memory_bytes: 72908
#include<iostream>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
#include<math.h>
#include<cstring>
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
 
int main()
{
	
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
     int x,y,z;
     cin>>x>>y>>z;
     
     swap(x,y);
     swap(x,z);
     
     cout<<x<<" "<<y<<" "<<z<<endl;
     
 
 
    
    return 0;
    
}

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

typedef long long ll;

const int MOD = 1e9 + 7;

class Mod
{
private:
    int mod;

public:
    Mod();
    Mod(int n) {
        mod = n;
    }

    ll add(ll a, ll b) {
        return (a + b) % mod;
    }

    ll mul(ll a, ll b) {
        return (a * b) % mod;
    }

    ll pow(ll a, ll n) {
        ll ret;
        if (n == 0) ret = 1;
        else if (n == 1) ret = a;
        else {
            ll sq = pow(a, n / 2);
            ret = mul(sq, sq);
            if (n % 2 != 0) ret = mul(ret, a);
        }
        return ret % mod;
    }

    ll div(ll a, ll b) {
        return mul(a, pow(b, mod - 2));
    }
};

string s;
int n;
vector< vector<ll> > dp;
Mod mod(13);

int ctoi(char c) {
    return (int) c - 48;
}

void fill_dp(int i, int d) {
    int v = mod.mul(d, mod.pow(10, i - 1));
    for (int j = 0; j < 13; j++) {
        dp[i][(j + v) % 13] += dp[i - 1][j];
        dp[i][(j + v) % 13] %= MOD;
    }
}

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

    cin >> s;
    reverse(s.begin(), s.end());

    n = s.size();

    for (int i = 0; i <= n; ++i) {
        vector<ll> row(13, 0);
        dp.push_back(row);
    }
    dp[0][0] = 1;

    for (int i = 1; i <= n; ++i) {
        char c = s[i - 1];
        if (c == '?') {
            for (int d = 0; d <= 9; ++d) {
                fill_dp(i, d);
            }
        } else {
            int d = ctoi(c);
            fill_dp(i, d);
        }
    }

    cout << dp[n][5] << endl;

    return 0;
}

Measured memory_bytes: 14336
#include <iostream>
#include <iomanip>
#include<vector>
#include <algorithm>
#include <queue>
#include<string>
#include <map>
#include <cmath>
#include <deque>
#include <list>
#include <stack>
#include <queue>
#include <utility>
typedef long long ll;
typedef long double ld;

#define REP(i,s,n)for(ll i=s;i<(n);++i)
#define rep(i,n) REP(i,0,n)
using namespace std;
ll S[1000] = { 0 };
int N,M,Q;



int main() {
	cin >> N;
	vector<int>A(N);
	rep(i, N)cin >> A[i];
	cin >> Q;
	rep(i, Q) {
		int b, e ,t;
		cin >> b >> e >> t;
		swap_ranges(A.begin() + b, A.begin() + e, A.begin() + t);
	}
	rep(i, N - 1) {
		cout << A[i] << " ";
	}
	cout << A[N - 1]<<endl;
	return 0;
}





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

typedef long long ll;

int main () {
	ll N;
	vector <char> v;
	cin >> N;
	v.push_back ('a'+(N-1)%26);
	ll n = 26;
	N -= n;
	while (N>0) {
		v.push_back ('a'+((N-1)%(n*26))/n);
		n *= 26;
		N -= n;
	}
	for (int idx=v.size(); idx>0; idx--) {
		cout << v[idx-1];
	} 
	cout << endl;
	return 0;
}

Measured memory_bytes: 3624
#include <iostream>

using namespace std;
int a, b;
int main()
{
	cin >> a >> b;
	if (a == b){
		cout << "Draw";
	}else if(a == 1){
		cout << "Alice";
	}else if(b == 1){
		cout << "Bob";
	}else if (a < b){
		cout << "Bob";
	}else if(a > b){
		cout << "Alice";
	}
    return 0;
}


Measured memory_bytes: 256
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author otsuhata
 */
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        
        int count = 0;
        int x = 1;
        
        Scanner sc = new Scanner(System.in);            
        
        for(int i = 0; i < 10000; i ++) {
            x = sc.nextInt();
            
            if(x == 0 || x < 1 || x > 10000) {
                break;
            }else {
                System.out.println("Case " + (i + 1) + ": " + x);
            }
        }
        
//        while(x != 0) {
//            x = sc.nextInt();
//            count ++;
//            System.out.println("Case " + count + ": " + x);
//        }
    }
    
}

Measured memory_bytes: 42712
package main

import (
  "bufio"
  "os"
  "strings"
  "fmt"
)

func main() {
  sc := bufio.NewScanner(os.Stdin)
  sc.Scan()
  strArr := strings.Split(sc.Text(), " ")
  if strArr[0][len(strArr[0])-1] == strArr[1][0] && strArr[1][len(strArr[1])-1] == strArr[2][0] {
    fmt.Println("YES")
  } else {
    fmt.Println("NO")
  }
}


Measured memory_bytes: 640
import java.util.Scanner;

public class Main {
	static Scanner in = new Scanner(System.in);
	public static void main(String[] args){
		int r = in.nextInt(), g = in.nextInt(), b = in.nextInt();
		if((r * 100 + g *10 + b) % 4 == 0){
			System.out.println("YES");
		}else{
			System.out.println("NO");
		}
	}
	

}


Measured memory_bytes: 22612
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
main()
{
    long long N,h,n,t1,t2;int s=0;
    scanf("%lld",&N);
    for(h=1;h<=N;h++)
    {
        for(n=1;n<=3500;n++)
        {
            t1=N*h*n;
            t2=4*h*n-N*n-N*h;
            if(t2>0&&t1%t2==0)
            {
                printf("%lld %lld %lld\n",h,n,t1/t2);
                s=1;break;
            }
        }
        if(s)break;
    }
}


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

namespace ABC050
{
	class Q1
	{
		static void Main()
		{
			string[] buff = Console.ReadLine().Split(' ');
			int a = int.Parse(buff[0]);
			int b = int.Parse(buff[2]);
			string op = buff[1];
			switch (op)
			{
				case "+":
					Console.WriteLine(a + b);
					break;
				case "-":
					Console.WriteLine(a - b);
					break;
			}
		}
	}
}


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

using namespace std;


int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int a = 0, b = 0;
  string str;
  cin >> str;
  for (int i = 0; i < str.length(); ++i) {
      if (i % 2 == 0) {
          a += str[i] != '0';
          b += str[i] != '1';
      } else {
          a += str[i] != '1';
          b += str[i] != '0';
      }
  }
  cout << min(a, b);
  return 0;
}

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

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

using namespace std;
using ll = long long;

int main(void)
{
    int s;
    int cnt = 1;
    cin >> s;
    if (s == 4 || s == 2 || s == 1)
    {
        cout << 4 << endl;
        return 0;
    }
    while (s != 1)
    {
        if (s % 2 == 0)
        {
            s /= 2;
        }
        else if (s % 2 == 1)
        {
            s = 3 * s + 1;
        }
        cnt++;
    }
    cnt++;
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
object Main extends App{
    // Your code here!
    import scala.io.Source.stdin
    def sort(nums: Array[Int]): (Array[Int],Int) = {
        var times = 0
        def swap(x: Int, y: Int) {
            if(x != y) {times+=1}
            val tmp = nums(x)
            nums(x) = nums(y)
            nums(y) = tmp
        }
        for(i <- 0 until nums.length) {
            var min_index = i
            for(j <- i until nums.length) {
                min_index = if(nums(j) < nums(min_index)) j else min_index
            }
            swap(i,min_index)
        }
        (nums,times)
    }
    /*val input = {for(line <- io.Source.stdin.getLines()) yield {
        line
    }}.toSeq*/
    scala.io.StdIn.readLine
    val inputarr = scala.io.StdIn.readLine.split(" ").map{_.toInt}
    val sorted = sort(inputarr)
    println(sorted._1.mkString(" ") + "\n" + sorted._2)
}



Measured memory_bytes: 44128
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import numpy as np
from numba import njit

MOD = 10**9 + 7

N = int(readline())
S = np.array(list(read().rstrip()), np.int8)

R = np.sum(S == ord('R'))
B = np.sum(S == ord('B'))
G = np.sum(S == ord('G'))

@njit
def f(S):
    N = len(S)
    ret = 0
    for i in range(N):
        for j in range(i + 1, N):
            k = j + j - i
            if k >= N:
                break
            if S[i] != S[j] and S[i] != S[k] and S[j] != S[k]:
                ret += 1
    return ret

answer = R * B * G - f(S)
print(answer)

Measured memory_bytes: 109716
package main 
import ("fmt")

func main(){

  var a,b,c int;

  fmt.Scanf("%d %d %d", &a, &b, &c );
  
  if b>=(a%(b+c)){
    fmt.Println(b*(a/(b+c)) + (a%(b+c)));
  }else if b<(a%(b+c)){
    fmt.Println(b*(a/(b+c)) + b);
  }else{
          fmt.Println(b*(a/(b+c)));
  }
  
}

Measured memory_bytes: 512
from collections import defaultdict
from itertools import product
from sys import stdin
def gen_b(x,B):
	if x < 3: lb = 2
	else: lb = x - 1
	if x > B-2: ub = B-1
	else: ub = x + 1
	return xrange(lb,ub+1)
def solve():
	count = defaultdict(int)
	ans = [0]*10
	L = map(lambda x:map(int,x.split()),stdin.readlines())
	H,W,N = L[0]
	for i in xrange(1,N+1):
		for x,y in product(gen_b(L[i][0],H),gen_b(L[i][1],W)):
			count[x+(y<<34)] += 1
	for v in count.itervalues():ans[v] += 1
	ans[0] = (H-2)*(W-2) - sum(ans[1:])
	for c in ans: print c
solve()

Measured memory_bytes: 113920
import sys
input = sys.stdin.readline

#n = int(input())
#l = list(map(int, input().split()))

'''
a=[]
b=[]
for i in range():
    A, B = map(int, input().split())
    a.append(A)   
    b.append(B)'''
def cal(n,li):
    lis=[True]*(n+1)
    for item in li:
        if lis[item]:
            for i in range(item*2,n+1,item):
                lis[i]=False
    return lis
from collections import Counter

n=int(input())
a=list(map(int,input().split()))
a.sort()
l=cal(a[-1],a)
ll=Counter(a)
#print(l,ll)
ans=0
for i in range(n):
    if ll[a[i]]==1:
        if l[a[i]]:
            ans+=1

print(ans)


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

int main(int argc, char *argv[]) {
  ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);

  int n;
  cin>>n;
  std::vector<int> v(n);
  for(int i=0;i<n;i++){
    cin>>v[i];
  }
  //+
  ll res = 0;
  ll sum=v[0];
  if(v[0]<=0){
    sum=1;
    res=1-v[0];
  }
  for(int i=1;i<n;i++){
    ll sum2=sum+v[i];
    if(sum<0){
      if(sum2<=0){
        res+=1-sum2;
        sum2=1;
      }
    }else{
      if(sum2>=0){
        res+=sum2+1;
        sum2=-1;
      }
    }
    sum=sum2;
  }
  ll res2=0;
  sum=v[0];
  if(v[0]>=0){
    sum=-1;
    res2=v[0]+1;
  }
  for(int i=1;i<n;i++){
    ll sum2=sum+v[i];
    if(sum<0){
      if(sum2<=0){
        res2+=1-sum2;
        sum2=1;
      }
    }else{
      if(sum2>=0){
        res2+=sum2+1;
        sum2=-1;
      }
    }
    sum=sum2;
  }
  //-
  cout<<min(res, res2)<<endl;

  return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
#include<algorithm>
using namespace std;
#define cool ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) 
#define ll long long
#define MAX 1000001
#define mod 1000000007
void solve()
{
	int k;
	cin>>k;
	string s;
	cin>>s;
	if(s.size()<=k)
	cout<<s;
	else{
		string str="";
		for(int i=0;i<k;i++)
		str+=s[i];
		cout<<str<<"...";
	}
}
int main()
{ 
    cool;
    int t;
    //cin>>t;
    t=1;
    while(t--){
    	solve();
	}
    return 0;
}


Measured memory_bytes: 3616
N, M = list(map(int, input().split(' ')))
A = list(map(lambda x: -x, map(int, input().split(' '))))

# q(m) = q(m-1) - max(A) / 2

# 優先度付きキューをつかう
# 逆ヒープとか? => 要素全部に-1かけてやれば楽

import heapq
heapq.heapify(A)

for i in range(M):
  m = A[0]
  heapq.heappushpop(A, (-1) * ((m * (-1))  // 2))

print(sum(A) * (-1))


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

typedef long long ll;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define each(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); ++itr)
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define fi first
#define se second

const ll mod=1e9+7;

int N,X,Y,Z;

int S;

bool nx[1<<16][11]={0};
ll dp[41][1<<16];

ll dfs(int now, int state)
{
    if(dp[now][state]>=0) return dp[now][state];
    if(now==N) return 1;

    ll ret=0;
    //次に選ぶ数
    for(int i=1; i<=10; ++i)
    {
        if(nx[state][i])
        {
            ret+=dfs(now+1, ((state<<i)+(1<<(i-1)))%(1<<S));
            ret%=mod;
        }
    }

    return dp[now][state]=ret;
}

int main()
{
    cin >>N >>X >>Y >>Z;
    S=X+Y+Z-1;

    //状態maskの時に，次の数iが来ていいかチェックしておく
    rep(mask,1<<S)
    {
        //直前の状態を復元
        vector<int> b;
        int st=0;
        rep(i,S)
        {
            if(mask>>i&1)
            {
                b.pb(i-st+1);
                st=i+1;
            }
        }

        int B=b.size();
        //jを次に選んだ時にXYZを含まないかチェック
        for(int i=1; i<=10; ++i)
        {
            bool ok=true;
            //直前から順番に見ていき貪欲に足していく
            int x=0,y=0,z=i;
            int bidx=0;
            while(bidx<B && z<Z) z+=b[bidx++];
            while(bidx<B && y<Y) y+=b[bidx++];
            while(bidx<B && x<X) x+=b[bidx++];
            if(x==X && y==Y && z==Z) ok=false;

            nx[mask][i]=ok;
        }
    }

    //全体は10^N通り
    ll p10=1;
    rep(i,N) p10=(p10*10)%mod;

    memset(dp,-1,sizeof(dp));
    //XYZを含まない数列の個数
    ll r=dfs(0,0);
    //全体から引く
    ll ans=(p10-r+mod)%mod;
    cout << ans << endl;
    return 0;
}


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

int main() {
  int a,b,d=0;
  cin>>a>>b;
  vector<int> c(a);
  for(int i=0;i<a;i++)
    cin>>c[i];
  for(int i=0;i<a;i++){
    d+=c[i];
    if(d>b){
      cout<<i+1<<endl;
      break;
    }
    else if(i==a-1)
      cout<<a+1<<endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <vector>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <climits>
#include <stack>
#include <queue>
#include <set>
#include <cctype>
#include <bitset>
#include <type_traits>

#include <list>
using namespace std;

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define YES(j) cout << (j ? "YES" : "NO") << endl;
#define Yes(j) std::cout << (j ? "Yes" : "No") << endl;
#define yes(j) std::cout << (j ? "yes" : "no") << endl;

int main(void)
{
    string s;
    cin >> s;
    if (s[0] == s[1] || s[1] == s[2] || s[2] == s[3])
    {
        cout << "Bad" << endl;
    }
    else
    {
        cout << "Good" << endl;
    }
}

Measured memory_bytes: 256
import Data.List
import Data.Ord
import Data.Char
import Data.Ratio
import Data.Maybe

main = do
  n <- readLn :: IO Int
  s <- map words . lines <$> getContents
  let restaurants = restaurant s
  let index = map (`elemIndex` restaurants) (guide s)
  putStrLn $ unlines $ map (show . maybe 0 (+1)) index

guide = sortBy(comparing fst) . sortBy(flip compare) . restaurant
restaurant [] = []
restaurant ([city,score]:xs) = (city, (read::String->Int) score):restaurant xs


Measured memory_bytes: 4800
type arr=array[0..200001]of longint;
var n,q,m,i,j,a,b:longint;
    v,d,c,max,cl,head,next,start,endd:arr;
    bb,bc:array[0..200001]of boolean;
procedure dfs(k,dis,col:longint);
var i:longint;
begin
    bb[k]:=true;
    if(max[k]>=dis)and(bc[k])then begin
        bb[k]:=false;
        exit;
    end;
    max[k]:=dis;
    if not bc[k]then begin
        cl[k]:=col;
        bc[k]:=true;
    end;
    if dis>0 then for i:=start[k] to endd[k] do
    if not bb[next[i]]then dfs(next[i],dis-1,col);
    bb[k]:=false;
end;
procedure sort(l,r:longint);
var i,j,x,y:longint;
begin
    i:=l;j:=r;x:=head[(l+r) div 2];
    repeat
        while head[i]<x do inc(i);
        while x<head[j] do dec(j);
        if not(i>j) then begin
            y:=head[i];head[i]:=head[j];head[j]:=y;
            y:=next[i];next[i]:=next[j];next[j]:=y;
            inc(i);j:=j-1;
        end;
    until i>j;
    if l<j then sort(l,j);
    if i<r then sort(i,r);
end;
begin
    readln(n,m);
    fillchar(cl,sizeof(cl),0);
    fillchar(max,sizeof(max),0);
    fillchar(bb,sizeof(bb),false);
    fillchar(bc,sizeof(bc),false);
    for i:=1 to m do begin
        readln(a,b);
        head[i]:=a;head[i+m]:=b;
        next[i]:=b;next[i+m]:=a;
    end;
    m:=m*2;sort(1,m);start[head[1]]:=1;
    for i:=2 to m do if head[i]<>head[i-1]then begin
        endd[head[i-1]]:=i-1;
        start[head[i]]:=i;
    end;
    endd[head[m]]:=m;
    readln(q);
    for i:=q downto 1 do readln(v[i],d[i],c[i]);
    for i:=1 to q do dfs(v[i],d[i],c[i]);
    for i:=1 to n do writeln(cl[i]);
end.

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

using namespace std;

#define pb push_back
const int maxi = 1e6 + 10;
int a[maxi];
string s[maxi];
int n;
string t;
int main()
{
    cin>>n;

   for (int i=1;i<=n;i++)
    cin>>s[i]>>a[i];

    cin>>t;
   int ans = 0;

   int ok = 0;
   for (int i=1;i<=n;i++)
    if (s[i]==t) ok = 1; else
        if (ok) ans+=a[i];


    cout<<ans<<endl;
    return 0;
}
//A ja bih se s tobom topila,
//al ne bih ti to priznala,
//da nisam popila.
//A ti,bas je dobro sto si tu,
//daj slobodno pokazi mi,
//taj skriveni tattoo.


Measured memory_bytes: 8448
#include<iostream>
#include<climits>
#include<math.h>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<stdio.h>
#include <string>
#include <complex>
#include <functional>
using namespace std;
//typedef pair<string,string> P;
//double dat[100][100];
//int dp[6][1010];//動的計画法
//int prime[10000001];
//char str[1010][1010];
//vector<pair<int,int> > pc[100001];
//int ABS(int a){return max(a,-a);}
//long long num[100000];
int main(){
	string s;
	cin>>s;
	int n=s.length(),ch,i;
	for(i=n-1;i>=1;i--){
		if(i%2==0) continue;
		ch=1;
		for(int j=0;j<i/2;j++){
			if(s[j]!=s[i/2+j]) {
				ch=0;
				break;
			}
		}
		if(ch) break;
	}
	cout<<i-1<<endl;
	return 0;
}

Measured memory_bytes: 256
// using bubble sort and selection sort
// input pairs of card and number, outout 2-way sorted pairs and "stable" or "not stable"
// bubble sort is always "stable"
#include<iostream>
typedef struct{
  char c;
  int i;
}card;
void BubbleSort(card*, int);
void SelectionSort(card*, int);
int main(){
  int i, N, flag;
  std::cin >> N;
  card B[N],S[N];
  for(i=0; i<N; i++){
    std::cin >> B[i].c >> B[i].i;
    S[i] = B[i];
  }
  BubbleSort(B, N);
  SelectionSort(S, N);
  bool boo=true;
  for(i=0,flag=1; i<N&&boo==true; i++)
  if(B[i].c != S[i].c) boo = false;
  std::cout << (boo ? "Stable\n" : "Not stable\n");
  return 0;
}
void BubbleSort(card *B, int N){
  card tmp;
  for(int i=0; i<N-1; i++) for(int j=N-1; j>i; j--) if(B[j].i < B[j-1].i) tmp = B[j], B[j] = B[j-1], B[j-1] = tmp;
  for(int i=0; i<N; i++) std::cout << B[i].c << B[i].i << (i < N-1 ? " " : "\n");
  std::cout << "Stable\n";
}
void SelectionSort(card *S, int N){
  card tmp;
  for(int i=0,min; i<N-1; i++){
    min = i;
    for(int j=i; j<N; j++) if(S[j].i < S[min].i) min = j;
    tmp = S[i], S[i] = S[min], S[min] = tmp;
  }
  for(int i=0; i<N; i++) std::cout << S[i].c << S[i].i << (i < N-1 ? " " : "\n");
}

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

using namespace std;
int main(){

    int n;
    string data;

    cin>>n;
    cin>>data;


    string before,after;

    before=data.substr(0,n/2);
    after=data.substr(n/2,n);

    if(before==after){
        cout<<"Yes";
    }
    else{
        cout<<"No";
    }


}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define pll pair<ll,ll>
#define pb push_back
#define f first
#define s second
#define MOD 998244353
 
using namespace std;


int main(){
 
	ios_base::sync_with_stdio(false);
	//cin.tie(0);
	cout<<fixed<<setprecision(12);
	//memset(dp,-1,sizeof(dp));
	ll n,a,b;
	cin>>n>>a>>b;
	cout<<a*(n/(a+b)) + min(n%(a+b),a);
	

	return 0;
}
 

Measured memory_bytes: 256