akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <climits>
#include <queue>

using namespace std;

const int WHITE = 0, GRAY = 1, BLACK = 2;

struct BFS {
    int n;
    vector<vector<int>> g;
    vector<int> depth;
    vector<int> state;
    int time = 0;

    BFS(int n) : n(n) {
        g.assign(n, vector<int>());
        depth.assign(n, -1);
        state.assign(n, WHITE);
    }

    void addEdge(int u, int v) {
        g[u].push_back(v);
    }

    void bfs(int s) {
        queue<int> q;
        state[s] = GRAY;
        depth[s] = 0;
        q.push(s);

        while (!q.empty()) {
            int u = q.front();
            q.pop();
            if (state[u] == BLACK) {
                return;
            }
            for (int v : g[u]) {
                if (state[v] == WHITE) {
                    state[v] = GRAY;
                    depth[v] = depth[u] + 1;
                    q.push(v);
                }
            }
            state[u] = BLACK;
        }
    }

    void print() {
        for (int i = 0; i < n; i++) {
            cout << i << ":";
            for (int v : g[i]) {
                cout << v << " ";
            }
            cout << endl;
        }
    }
};

int main() {
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    BFS dfs(n);
    for (int i = 0; i < n; i++) {
        int u, k;
        cin >> u >> k;
        u--;
        for (int j = 0; j < k; j++) {
            int v;
            cin >> v;
            v--;
            dfs.addEdge(u, v);
        }
    }

    //dfs.print();

    dfs.bfs(0);

    for (int i = 0; i < n; i++) {
        cout << (i + 1) << " " << dfs.depth[i] << endl;
    }

    return 0;
}

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

int main() {
	int N, i;
	cin >> N >> i;
	int ans = N - i + 1;
	cout << ans << endl;
	return 0;
}


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


def main():
    N, M = map(int, input().split())
    H = list(map(int, input().split()))
    isGood = [1] * N

    for m in range(M):
        a, b = map(int, input().split())
        h_a, h_b = H[a-1], H[b-1]
        if h_a == h_b:
            isGood[a-1] *= 0
            isGood[b-1] *= 0
        elif h_a > h_b:
            isGood[a-1] *= 1
            isGood[b-1] *= 0
        else:
            isGood[a-1] *= 0
            isGood[b-1] *= 1

    print(sum(isGood))


if __name__ == '__main__':
    main()

Measured memory_bytes: 20344
#
# Written by NoKnowledgeGG @YlePhan
# ('ω')
#
#import math
#mod = 10**9+7
#import itertools
#import fractions
#import numpy as np
#mod = 10**4 + 7
"""def kiri(n,m):
  r_ = n / m
  if (r_ - (n // m)) > 0:
    return (n//m) + 1
  else:
    return (n//m)"""
 
def main():
  a,b,k = map(int,input().split())
  L = []
  R = []
  for i in range(k):
    if a<=a+i<=b:
      L.append(a+i)
  for j in range(-k+1,1,1):
    if a<=b+j<=b:
      R.append(b+j)
  L[len(L):len(L)] = R
  W = sorted(list(set(L)))
  for i in range(len(W)):
    print(W[i])
if __name__ == '__main__':
  main()

Measured memory_bytes: 3064
import sys

s = input()
k = int(input())
cnt = 0
for i in range(len(s)):
    if s[i] != "1":
        break
    cnt += 1
if cnt >= k:
    print("1")
    sys.exit()

for i in range(len(s)):
    if s[i] != "1":
        ans = s[i]
        print(s[i])
        break


Measured memory_bytes: 3060
#include <stdio.h>

int main(void){
  int a;
  scanf("%d",&a);
  
  char s[4] = {'\0'};
  
  sprintf(s, "%d", a);
  
  int i;
  int c = 0;
  
  for (i = 0; i < 3; i++){
    if(s[i]=='1')
      c++;
  }
  
  printf("%d",c);
  
  return 0;
}


Measured memory_bytes: 128
def main():
    n = int(input())
    A = list(map(int, input().split()))

    if 0 in A:
        print(0)
        return

    ans = 1
    for item in A:
        ans = ans * item
        if ans > 1000000000000000000:
            print(-1)
            return

    print(ans)


main()


Measured memory_bytes: 21708
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <iomanip> // fixed, setprecision 
#include <math.h> // double sqrt
#define rep(i,n) for(int i=0;i<(n);++i)
#define ll long long
using namespace std;
int gcd(int a, int b)
{
   if (a%b == 0)
   {
       return(b);
   }
   else
   {
       return(gcd(b, a%b));
   }
}
int main(){
    int x;
    cin>>x;
    int ans=x/gcd(x,360);
    cout<<ans*360/x;
    return 0;
    }

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

int a[200010];

void fail(){
	cout<<-1<<endl;
	exit(0);
}

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin>>n;
	for(int i=1;i<=n;i++)
		cin>>a[i];
	long long int ans = 0;
	if(a[1]!=0)	fail();
	for(int i=2;i<=n;i++){
		if(a[i]-a[i-1]>1)	fail();
		if(a[i]==a[i-1]+1)	ans++;
		else	ans+=a[i];
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 1024
#include <iostream> 
#include <string>
#include <vector>
#include <algorithm>

using std::cin;
using std::cout;
using std::endl;
using std::string;

int main() 
{
    int k;
    string s;
    cin >> k >> s;
    if (s.length() <= k)
        cout << s << endl;
    else cout << s.substr(0,k) << "..." << endl;

    

}

Measured memory_bytes: 3616
import heapq

v, e, r = map(int, input().split())
g = [[] for _ in range(v)]
for i in range(e):
    s, t, d = map(int, input().split())
    g[s].append((d, t))#(重み, 次の頂点)

dist = [float("inf")] * v
visited = [False] * v
dist[r] = 0
visited[r] = True
candidate = []
for i in g[r]:
    heapq.heappush(candidate, i)
while len(candidate):
    #まだ使われていない頂点から最小のものを探す
    minedge = heapq.heappop(candidate)#(重み, 頂点)
    if visited[minedge[1]]:
        continue
    c = minedge[1]
    dist[c] = minedge[0]
    visited[c] = True
    for i in g[c]:
        if not visited[i[1]]:
            heapq.heappush(candidate, (dist[c] + i[0], i[1]))

for i in dist:
    if i == float("inf"):
        print("INF")
    else:
        print(i)


Measured memory_bytes: 96952
n = int(input())
s = input()
c = [[0,0,0] for _ in range(n+1)]
if n<3:
    result = 0
else:
    for i in range(1, n+1):
        if s[-i]=="R":
            c[i][0] += 1
        elif s[-i]=="G":
            c[i][1] += 1
        else:
            c[i][2] += 1
        for j in range(3):
            c[i][j] += c[i-1][j]
    c = c[::-1]
    s = s+"0"*(n+1)
    result = 0
    for i in range(n-1):
        if s[i]=="R":
            for j in range(i+1, n):
                if s[j]=="G":
                    result += c[j][2] - ("B"==s[2*j-i])
                elif s[j]=="B":
                    result += c[j][1] - ("G"==s[2*j-i])
        if s[i]=="G":
            for j in range(i+1, n):
                if s[j]=="R":
                    result += c[j][2] - ("B"==s[2*j-i])
                elif s[j]=="B":
                    result += c[j][0] - ("R"==s[2*j-i])
        if s[i]=="B":
            for j in range(i+1, n):
                if s[j]=="G":
                    result += c[j][0] - ("R"==s[2*j-i])
                elif s[j]=="R":
                    result += c[j][1] - ("G"==s[2*j-i])
print(result)

Measured memory_bytes: 74828
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        PriorityQueue<Double> queue = new PriorityQueue<>();
        for(int i=0;i<n;i++){
            queue.add((double)Integer.parseInt(sc.next()));
        }
        Double a,b;
        while(queue.size() > 1){
            a = queue.poll();
            b = queue.poll();
            queue.add((a+b)/2.0);
        }
        System.out.println(queue.poll());
        sc.close();
    }
}

Measured memory_bytes: 21972
import collections

N = int(input())
ans = []
for _ in range(N):
    ans.append(input())

c = collections.Counter(ans)

if 'AC' in c:
    print('AC x', c['AC'])
else:
    print('AC x', 0)

if 'WA' in c:
    print('WA x', c['WA'])
else:
    print('WA x', 0)

if 'TLE' in c:
    print('TLE x', c['TLE'])
else:
    print('TLE x', 0)

if 'RE' in c:
    print('RE x', c['RE'])
else:
    print('RE x', 0)


Measured memory_bytes: 16592
n,x=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
ans=0

for i in range(n):
    if x>=a[i]:
        x-=a[i]
        ans+=1
    else:
        print(ans)
        exit()

if x==0:
    print(ans)
else:
    print(ans-1)

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

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define repr(i,a,b) for(int i=(int)(a-1);i>=b;i--)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout << #x" = " << x << endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt(x) bitset<32>(x).count()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;

#define INF INT_MAX/3

int imos[200001][30];
bool channel[100001][30];

int main(){
    cin.sync_with_stdio(false);
    int n, c;
    cin >> n >> c;
    memset(imos, 0, sizeof(imos));
    memset(channel, 0, sizeof(channel));
    rep(i, n) {
        int s, t, r;
        cin >> s >> t >> r;
        if (imos[s * 2][r - 1] == -1) {
            imos[s * 2][r - 1]++;
            imos[t * 2][r - 1]--;
        } else {
            imos[s * 2 - 1][r - 1]++;
            imos[t * 2][r - 1]--;
        }
    }
    int maxi = 0;
    repl(i, 1, 200001) {
        int tmp = 0;
        rep(j, c) imos[i][j] += imos[i - 1][j], tmp += (imos[i][j] > 0);
        maxch(maxi, tmp);
    }
    cout << maxi << endl;
    return 0;
}

Measured memory_bytes: 26624
while line = gets.chomp
    x,o,y=line.split(' ')
    case o
    when "?"
        break
    when "+"
        puts "#{x.to_i + y.to_i}"
    when "-"
        puts "#{x.to_i - y.to_i}"
    when "*"
        puts "#{x.to_i * y.to_i}"
    when "/"
        puts "#{x.to_i / y.to_i}"
    end
end

Measured memory_bytes: 6100
#include <stdio.h>

int main(void){
   char str[51];
   int point,n=0,strl;

   scanf("%d",&strl);
   scanf("%s",str);

   for(point=0;point<strl;point++){
      if((str[point]=='A') && (str[point+1] == 'B') && (str[point+2]== 'C')){
         n++;
         point+=2;
      }

   }

   printf("%d\n",n);
   return 0;
}

Measured memory_bytes: 128
//
//  main.cpp
//

#include <iostream>
#include <algorithm>
#include <vector>
#include <limits>
#include <math.h>
#include <queue>
#include <tuple>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include "string.h"
#include <unordered_map>
#include <unordered_set>
#include <array>
#include <set>
#include <memory>
#include <exception>

using namespace std;
using ll = int64_t;
using ull = uint64_t;

#define rep(i,a,b) for(ll i=a;i<b;i++)

int main() {
	ll N;
	cin >> N;
	vector<ll> ais(N);
	rep(i,0,N) {
		cin >> ais[i];
	}
	vector<ll> sorted = ais;
	sort(sorted.begin(), sorted.end());
	unordered_map<ll, ll> map;
	rep(i,0,N) {
		map[sorted[i]] = i;
	}
	ll cnt = 0;
	rep(i,0,N) {
		if (i % 2 == 0 && map[ais[i]] % 2 == 1) {
			cnt++;
		}
	}
	cout << cnt << endl;
}


Measured memory_bytes: 5924
bill_count, total_money = map(int, input().split())
patterns = [
  (x, y, bill_count - x - y) 
    for x in range(bill_count + 1) 
      for y in range(bill_count - x + 1) 
    if 10000*x + 5000*y + 1000*(bill_count - x - y) == total_money
]
print(" ".join(map(str, patterns[0])) if len(patterns) > 0 else '-1 -1 -1')

Measured memory_bytes: 3060
#include<stdio.h>


int main( void )
{
	int x1 ,x2 ,x3 ,x4 ;
	int y1 ,y2 ,y3 ,y4 ;

	scanf( "%d %d %d %d" ,&x1 ,&y1 ,&x2 ,&y2 ) ;

	const int mx = y2 - y1 ;
	const int py = x2 - x1 ;

	x3 = x2 - mx ; x4 = x1 - mx ;
	y3 = y2 + py ; y4 = y1 + py ;

	printf( "%d %d %d %d\n" ,x3 ,y3 ,x4 ,y4 ) ;

	return 0 ;
}

Measured memory_bytes: 128
#include <cstdio>
#include <utility>
using namespace std;

#define gcu getchar_unlocked
int in(int c){int n=0;bool m=false;if(c=='-')m=true,c=gcu();
	do{n=10*n+(c-'0'),c=gcu();}while(c>='0');return m?-n:n;} //&&c<='9'
int in() {return in(gcu());}
bool scan(int &n){int c=gcu();return c==EOF?false:(n=in(c),true);}
bool scan(char &c){c=gcu();gcu();return c!=EOF;}
//bool scan(string &s){int c;s="";
//	for(;;){c=gcu();if(c=='\n'||c==' ')return true;else if(c==EOF)return false;s+=c;}}
template <typename head, typename... tail>
bool scan(head &h, tail&&... t){return scan(h) && scan(t...);}
#define pcu putchar_unlocked
#define vo inline void out
template <typename T>
vo(T n){static char buf[20];char *p=buf;
	if(n<0)pcu('-'),n*=-1;if(!n)*p++='0';else while(n)*p++=n%10+'0',n/=10;
	while (p!=buf)pcu(*--p);}
vo(const char *s){while(*s)pcu(*s++);}
vo(char c){pcu(c);}
//vo(string &s){for (char c: s) pcu(c);}
template <typename head, typename... tail> vo(head&& h, tail&&... t){out(h);out(move(t)...);}
//template <typename T> vo(vector<T> &v){for(T &x:v)out(&x == &v[0]?"":" "),out(x);out('\n');}
#undef vo

struct T {
	int a[101];
	constexpr T() : a() {
		int s[10] = {0, 125, 140};
		for (int i = 3; i < 10; i++) s[i] = 160;
		for (int i = 0; i < 101; i++)
			a[i] = i <= 10 ? 1150 : a[i - 1] + s[(i - 1) / 10];
	}
};

int main() {
	constexpr T t;
	for (int w; ~(w = in());)
		out(4280 - t.a[w], '\n');
}


Measured memory_bytes: 2348
#include <bits/stdc++.h>
using namespace std;
long long MOD = 1000000007;
int main(){
  int N;
  cin >> N;
  string S1;
  cin >> S1;
  string S2;
  cin >> S2;
  string S;
  for (int i = 0; i < N; i++){
    if (S1[i] == S2[i]){
      S += 'a';
    } else {
      S += 'b';
      i++;
    }
  }
  int M = S.size();
  long long ans = 1;
  if (S[0] == 'a'){
    ans = 3;
  } else {
    ans = 6;
  }
  for (int i = 1; i < M; i++){
    if (S[i - 1] == 'a'){
      ans *= 2;
    } else if (S[i] == 'b'){
      ans *= 3;
    }
    ans %= MOD;
  }
  cout << ans << endl;
}

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

#define FOR(i,N) for(int i=0;i<N;i++)
#define ROF(i,N) for(int i=N-1;i>=0;i--)
#define ROF1(i,a,b) for(int i=(b);i>=(a);i--)
#define FOR1(i,a,b) for(int i=(a);i<=(b);i++)
#define FORi(i,a,b,c) for(int i=(a);i<=(b);i+=(c))

#define read freopen("IN.txt","r",stdin)
#define write freopen("OT.txt","w",stdout)
#define fastread {ios_base::sync_with_stdio(false);cin.tie(NULL);}
#define mem(a,b)          memset(a,b,sizeof(a))
#define EPS 1e-9
#define PI              acos(-1.0)
#define INF             2e16

#define ll              long long
#define ull             unsigned long long
#define ft              first
#define sd              second
#define bn              begin
#define en              end
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define pll             pair<LL,LL>
#define all(x) x.begin(), x.end()


#define dbg(args...) {cerr<<"-->";debugger::call(#args,args);cerr<<"\n";}
struct debugger {
    static void call(const char* it) {}
    template<typename T, typename ... aT>
    static void call(const char* it, T a, aT... rest) {
        string b;
        for (; *it&&*it != ','; ++it) if (*it != ' ')b += *it;
        cerr << b << "=" << a << " ";
        call(++it, rest...);
    }
};

int main()
{
#ifdef SunWalker
    //read;
   //write;
#endif

     ll n,c=0;
     string str;
     map<string,ll>hs;
     cin>>n;
     FOR(i,n)
     {
          cin>>str;
          sort(all(str));
          c+=(hs[str]++);
     }
     cout<<c<<"\n";

return 0;
}



Measured memory_bytes: 11136
fun main(args: Array<String>) {
    val (w, h, n) = readLine()!!.split(' ').map { it.toInt() }
    val field = Array(h) { BooleanArray(w) { true } }
    repeat (n) {
        val (x, y, a) = readLine()!!.split(' ').map { it.toInt() }
        when (a) {
            1 -> {
                field.forEach {
                    for (i in 0 until x) {
                        it[i] = false
                    }
                }
            }
            2 -> {
                field.forEach {
                    for (i in x until w) {
                        it[i] = false
                    }
                }
            }
            3 -> {
                for (i in 0 until y) {
                    for (j in 0 until w) {
                        field[i][j] = false
                    }
                }
            }
            4 -> {
                for (i in y until h) {
                    for (j in 0 until w) {
                        field[i][j] = false
                    }
                }
            }
        }

    }
    println(field.map{ it.count{ it } }.sum())
}


Measured memory_bytes: 42148
// AtCoder Regular Contest 071
// D - 井井井 / ###

#include <cstdio>
#define MOD ((ll)1e9 + 7)
using namespace std;
typedef long long int ll;


int N, M;
ll ans;

int main() {

  ll x, y;
  ll sx, ssx, sy, ssy;

  scanf("%d%d", &N, &M);
  sx = 0; ssx = 0;
  for (int i = 0; i < N; i++) {
    scanf("%lld", &x);
    sx += x; sx %= MOD;
    ssx += x * (i + 1) - sx + MOD; ssx %= MOD;
  }
  ans = 0; sy = 0;
  for (int k = 0; k < M; k++) {
    scanf("%lld", &y);
    sy += y; sy %= MOD;
    ans += ((y * (k + 1) - sy + MOD) % MOD) * ssx % MOD; ans %= MOD;
  }
  printf("%lld\n", ans);

  return 0;

}




Measured memory_bytes: 128
#include <bits/stdc++.h>
#define ll long long
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = 1; i <= n; i++)
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); }
using P = pair <int, int>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
 
ll MOD = 1000000007;
ll INF =1<<30;

int main(){
   int n;
   cin >> n;
   vector<int> A(n);
   rep(i,n) cin >> A[i];
   ll cnt = 1000;
   rep(i,n-1){
      if(A[i]>=A[i+1]) continue;
      ll s = cnt/A[i];
      cnt += (A[i+1]-A[i])*s;
   }
    cout << cnt <<endl;
}

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

using namespace std;

int main() {
	
	int n,m; cin >> n >> m;
	vector<string> v(n);
	
	for(int i = 0; i < n; i++)cin >> v[i];
	sort(v.begin(),v.end());
	
	for(auto e : v)
	cout << e;
	cout << '\n';
	
	return 0;
}

Measured memory_bytes: 256
#include<iostream>

long long gcd(long long a, long long b){
  if(!b)
    return a;
  return gcd(b, a%b);
}

int main(){
  long long N; std::cin >> N;
  for(auto h=1LL; h<=3500; ++h)
    for(auto n=1LL; n<=3500; ++n){
      auto num = 4*h*n-N*n-N*h;
      auto denom = N*h*n;
      auto gcd1 = gcd(num, denom);
      // std::cerr << num << ' ' << denom << ' ' << gcd1 << '\n';
      num/=gcd1;
      denom/=gcd1;
      if(num == 1 and denom > 0){
	std::cout << h << ' ' << n << ' ' << denom << '\n';
	return 0;
      }
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <cstdlib>
#include <cmath>
#define rep(i,n) for(int i=0;i<(n);++i)
using namespace std;
using ll = long long;
int ctoi(const char c){
  switch(c){
    case '0': return 0;
    case '1': return 1;
    case '2': return 2;
    case '3': return 3;
    case '4': return 4;
    case '5': return 5;
    case '6': return 6;
    case '7': return 7;
    case '8': return 8;
    case '9': return 9;
    default : return -1;
  }
}
int main(){
  string N,ans;
  cin >> N;
  int sum=0;
  rep(i,N.size()){
    //cout << sum << endl;
    sum+=ctoi(N[i]);
    //cout << N[i] << endl;
    sum=sum%9;
    //cout << sum << endl;
  }
  if(sum==0) ans="Yes";
  else ans="No";
  
  cout << ans << endl;
  return 0; 
}

Measured memory_bytes: 3732
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
using vll = vector<vl>;
using Pll = pair<ll, ll>;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(v) v.begin(), v.end()
#define sz(x) ((int) x.size())
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
const int MOD = 1e9+7;
const int INF = 2e9;
template<class T> void print(const T& t){ cout << t << endl; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}

int main(){
  ll n, z, w;
  cin >> n >> z >> w;
  vl a(n);
  rep(i,n){
    cin >> a[i];
  }
  if(n==1){
    print(abs(a[0] - w));
    return 0;
  }
  ll sam1 = abs(a[n - 1] - w);
  ll sam2 = abs(a[n - 2] - a[n - 1]);
  ll ans = max(sam1, sam2);
  print(ans); 
}

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

int main() {
    int n;
    cin >> n;
    vector<bool> s(13,false);
    vector<bool> h(13,false);
    vector<bool> c(13,false);
    vector<bool> d(13,false);
    char a;
    int x;
    for (int i = 0; i < n; i++) {
        cin >> a;
        cin >> x;
        if(a=='S'){
            s[x-1] = true;
        }else if(a=='H'){
            h[x-1] = true;
        }else if(a=='C'){
            c[x-1] = true;
        }else if(a=='D'){
            d[x-1] = true;
        }
    }
    for (int i = 0; i < 13; i++) {
        if (s[i]==false) {
            cout << "S " << i+1 << endl;
        }
    }
    for (int i = 0; i < 13; i++) {
        if (h[i]==false) {
            cout << "H " << i+1 << endl;
        }
    }
    for (int i = 0; i < 13; i++) {
        if (c[i]==false) {
            cout << "C " << i+1 << endl;
        }
    }
    for (int i = 0; i < 13; i++) {
        if (d[i]==false) {
            cout << "D " << i+1 << endl;
        }
    }
    return 0;
}



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

int main(){
  int n, x, limit;
  int count;

  while(1){
    count = 0;
    cin >> n >> x;
    if(n==0 && x==0){
      break;
    }
    if(n > x){
      limit = n;
    }else{
      limit = x;
    }
    for(int i=1; i<=n; i++){
      for(int j=i+1; j<=n; j++){
        if(j < x-i-j && x-i-j <= n){
           count++;
        }
      }
    }
    cout << count << endl;
  }
  return 0;
}


Measured memory_bytes: 3096
#[allow(dead_code)]
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}
#[allow(dead_code)]
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}
#[allow(dead_code)]
fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}
#[allow(dead_code)]
fn yn(result: bool) {
    if result {
        println!("Yes");
    } else {
        println!("No");
    }
}

fn main() {
    let n = read::<usize>();
    let mut v = Vec::new();
    let mut ans = true;
    for i in 0..n {
        let s = read::<String>();
        if i != 0 {
            let last: String = v.pop().unwrap();
            if last.chars().last().unwrap() != s.chars().nth(0).unwrap() {
                ans = false;
                break;
            }
            v.push(last);
            if v.contains(&s) {
                ans = false;
                break;
            }
        }
        v.push(s);
    }
    yn(ans);
}


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

int main()
{
    int n;
    std::cin>>n;
    std::vector<int> a(n);
    for(int i=0;i<n;i++)std::cin>>a[i];

    //先頭要素から見ていく
    int res =a[0];
	for (int i = 0; i < n - 1; i++) {
		if (a[i+1] > a[i]) res += a[i+1] - a[i];
	}
    std::cout<<res<<std::endl;

}

Measured memory_bytes: 256
s = input()
t = input()

result = []
for i in range(len(s)-len(t)+1):
    temp = '?'*i + t + '?'*(len(s)-len(t)-i)
    
    ans = ''
    flag = True
    for j in range(len(s)):
        if s[j] == '?' or s[j] == temp[j]:
            ans += temp[j]
        elif s[j] != '?' and temp[j] == '?':
            ans += s[j]
        else:
            flag = False

    if flag:
        result.append(ans.replace('?', 'a'))

if result:
    result.sort()
    print(result[0])
else:
    print("UNRESTORABLE")

Measured memory_bytes: 3064
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <functional>
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 10000000000000000
#define int long long

typedef pair<int, int> P;
const int MAX_N = 2510;
const int MAX_M = 5010;
vector<P> G1[MAX_N];
vector<P> G2[MAX_N];
bool okfrom1[MAX_N];
bool oktoN[MAX_N];
int n, m, p; 
void dfsfrom1(int v = 0, int p = -1) {
    okfrom1[v] = true;
    for(auto to: G1[v]) {
        if(to.first == p) continue;
        if(okfrom1[to.first]) continue;
        dfsfrom1(to.first, v);
    }
}
void dfstoN(int v = n - 1, int p = -1) {
    oktoN[v] = true;
    for(auto to: G2[v]) {
        if(to.first == p) continue;
        if(oktoN[to.first]) continue;
        dfstoN(to.first, v);
    }
}
int V, E;
int d[100110];
struct edge { int from, to, cost; };
vector<edge> es;
bool shortest_path(int s) {
    for (int i = 0; i < V; i++) d[i] = INF2;
    d[s] = 0;
    int cnt = 0;
    
    while (true) {
        bool update = false;
        for (int i = 0; i < es.size(); i++) {
            
            edge e = es[i];
            if (d[e.from] != INF2 && d[e.to] > d[e.from] + e.cost) {
                d[e.to] = d[e.from] + e.cost;
                update = true;
            }
        }
        if (!update) break;
        if(cnt >= 10000 && update) return false;
        cnt++;
    }
    return true;
}
signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n >> m >> p;
    V = n, E = m;
    int a[100110], b[100110], c[100110];
    rep(i, m) {
        cin >> a[i] >> b[i] >> c[i];
        a[i]--; b[i]--;
        G1[a[i]].push_back({b[i], -c[i]});
        G2[b[i]].push_back({a[i], -c[i]});
    }
    dfsfrom1();
    dfstoN();
    rep(i, m) {
        if(okfrom1[a[i]] && oktoN[b[i]]) {
            es.push_back({a[i], b[i], -c[i] + p});
            //cout << a[i] << " " << b[i] << endl;
        }
    }
    //cout << es.size() << endl;
    if(!shortest_path(0)) {
        cout << -1 << endl;
    } else {
        cout << max(0LL, -d[n - 1]) << endl;
    }



    return 0;
}


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

int main(void){
    int a[3];
    int count = 0, ma = 0;

    cin >> a[0] >> a[1] >> a[2];

    sort(a, a + 3);

    int b[2];
    b[0] = a[2] - a[0];
    b[1] = a[2] - a[1];

    int check = 0;

    if(b[0] % 2 == 1 && b[1] % 2 == 1){
        check = 1;
        b[0]--;
        b[1]--;
    }else if(b[0] % 2 == 1){
        check = 1;
        b[0]++;
    }else if(b[1] % 2 == 1){
        check = 1;
        b[1]++;
    }

    cout << b[0] / 2 + b[1] / 2 + check << endl;
    return 0;

}


Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)
#define VL vector<ll>
#define VS vector<string>

int main(){
    string s;
    cin >> s;
    string ans;
    rep(i,0,s.size()){
        if(s[i]=='0' || s[i]=='1') ans.push_back(s[i]);
        else if(ans.size()!=0 && s[i]=='B') ans.pop_back();
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3508
#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, m, n) for(int i=(m); i<(n); ++i)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define Cout(x) cout << (x) << endl
#define Cout2(x, y) cout << (x) << " " << (y) << endl
#define dump(x) cout << #x << " = " << (x) << endl;
#define forauto(i, a) for(auto i : a)cout << i << " "; puts("");
typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PII;
const int inf = 1e9;
const double pi = acos(-1.0);

int main() {
	vector<vector<pair<double, int>>> a(3, vector<pair<double, int>>(8));
	rep(i, 24)cin >> a[i / 8][i % 8].second >> a[i / 8][i % 8].first;
	rep(i, 3)sort(all(a[i]));
	//rep(i, 6)Cout2(a[i / 2][i % 2].second, a[i / 2][i % 2].first);
	rep(i, 6) { cout << a[i / 2][i % 2].second; printf(" %.2f\n", a[i / 2][i % 2].first); }

	vector<pair<double, int>> b;
	rep(i, 18)b.pb(a[i / 6][i % 6 + 2]);
	sort(all(b));
	//rep(i, 2)Cout2(b[i].second, b[i].first);
	rep(i, 2) { cout << b[i].second; printf(" %.2f\n", b[i].first); }
}


Measured memory_bytes: 3108
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <chrono>
#define _USE_MATH_DEFINES
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

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

const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007; // 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
/*-------------------------------------------------*/
int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  // freopen("input.txt", "r", stdin);

  int n; cin >> n;
  int ans = 0;
  FOR(i, 1, n + 1) {
    string s = to_string(i);
    if (s.length() & 1) ++ans;
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <utility>
#define llint long long

using namespace std;

llint n;

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n;
	llint q, x, a = 1, b = 0;
	for(int i = 0; i < n; i++){
		cin >> q >> x;
		if(q == 1) a *= x, b *= x;
		if(q == 2) b += x;
		if(q == 3) b -= x;
	}
	cout << -b << " " << a << endl;
	
	return 0;
}


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

typedef long long ll;

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl

const int maxn = 1e6 + 5;
string s, t;
int n, m;

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

  cin>>s>>t;
  n = s.size(); m = t.size();
  sort(s.begin(), s.end());
  vector<bool> used(m, false);
  for (int i=0; i<n; i++) {
    int x=-1;
    for (int j=0; j<m; j++) {
      if (!used[j] && (s[i]<=t[j] && (x==-1 || t[x]<t[j]))) {
	x=j;
      }
    }
    if (x==-1) out("No");
    if (s[i]<t[x]) {
      out("Yes");
    }
    used[x] = true;
  }

  if (n==m) out("No");

  out("Yes");  

  return 0;
}


Measured memory_bytes: 256
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		solve();
	}

	public static void solve() {
        Scanner sc = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);
        int n = sc.nextInt();
        List<Integer> a = new ArrayList<>();
        for(int i = 0; i < n; i++){
            int t = sc.nextInt();
            t--;
            a.add(t);
        }
        int ans = 0;
        int now = 0;
        for(int i = 0; i < n+1; i++){
            if(now == 1)break;
            ans++;
            now = a.get(now);
        }
        if(ans > n) ans = -1;
        out.println(ans);
        out.flush();
	}
}

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

int main() {
  int N, Y;

  cin >> N >> Y;

  for(int i = 0; i <= N; i++){
    for(int j = 0; j <= N-i; j++){
      if(10000*i+5000*j+1000*(N-i-j) == Y){
        cout << i << " " << j << " " << N-i-j << endl;
        return 0;
      }
    }
  }

  cout << "-1 -1 -1" << endl;

  return 0;
}

Measured memory_bytes: 256
import sys


def main():
    tmp = str(input()).split(" ")
    n = int(tmp[0])
    m = int(tmp[1])
    p = []
    s = []
    for i in range(m):
        tmp = str(input()).split(" ")
        p.append(int(tmp[0]))
        s.append(str(tmp[1].replace("\n", "")))
    cnt = [[0, 0, False] for i in range(n)]
    for i, j in zip(p, s):
        if j == "WA" and not cnt[i-1][2]:
            cnt[i-1][1] += 1
        elif j == "AC" and not cnt[i-1][2]:
            cnt[i-1][0] = 1
            cnt[i-1][2] = True
    accnt = 0
    wacnt = 0
    for i in range(n):
        accnt += cnt[i][0]
        if cnt[i][2]:
            wacnt += cnt[i][1]
    print(str(accnt) + " " + str(wacnt))


if __name__ == '__main__':
    input = sys.stdin.readline
    main()


Measured memory_bytes: 23508
def gcd(a,b):
    if b == 0:
        return a
    else:
        return gcd(b,a%b)

n,x = map(int,input().split())
lstx = [int(i) for i in input().split()]
lstx.append(x)
dx = [abs(lstx[i]-lstx[i-1]) for i in range(1,n+1)]

g = dx[0]
for i in range(1,n): 
    g = gcd(g,dx[i])

print(g)


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

int main() {
  int N;
  cin >> N;
  string S;
  cin >> S;
  int L[N], R[N], res = INT_MAX; // L[i] is number of W from 0 to i. R[i] is number of E from i to N - 1.
  L[0] = S[0] == 'W' ? 1 : 0;
  R[N - 1] = S[N - 1] == 'E' ? 1 : 0;
  for (int i = 1; i < N; i++) {
    L[i] = L[i - 1] + (S[i] == 'W' ? 1 : 0);
  }
  for (int i = N - 2; i >= 0; i--) {
    R[i] = R[i + 1] + (S[i] == 'E' ? 1 : 0);
  }
  for (int i = 0; i < N; i++) {
    res = min(res, L[i] + R[i]);
  }
  cout << res - 1;
  return 0;
}

Measured memory_bytes: 6104
#include<stdio.h>
int dp[10002][10002];
int main(void)
{
	int n,w;
	int v,x;
	int i,j;
	int max=0;
	
	scanf("%d %d",&n,&w);
	for(i=0;i<=n;i++){
		for(j=0;j<=w;j++){
			dp[i][j]=-1;
		}
	}
	dp[0][0]=0;
	for(i=0;i<n;i++){
		scanf("%d %d",&v,&x);
		for(j=0;j<=w;j++){
			if(dp[i][j]!=-1){
				if(dp[i+1][j]<dp[i][j]){
					dp[i+1][j]=dp[i][j];
				}
				if(j+x<=w && dp[i+1][j+x]<dp[i][j]+v){
					dp[i+1][j+x]=dp[i][j]+v;
				}
			}
		}
	}
	for(i=0;i<=w;i++){
		if(max<dp[n][i]){
			max=dp[n][i];
		}
	}
	printf("%d\n",max);
	return 0;
}

Measured memory_bytes: 5112
def read_input():
    n = int(input())
    alist = list(map(int, input().split()))
    return n, alist


def submit():
    n, alist = read_input()

    count = {}
    count_t = 0
    for a in alist:
        if a not in count.keys():
            count[a] = False
        else:
            count[a] = not count[a]
            if count[a]:
                count_t += 1
            else:
                count_t -= 1

    if count_t % 2 == 0:
        print(len(count))
    else:
        print(len(count) - 1)




if __name__ == '__main__':
    submit()


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

int main() {
  int N;
  cin >> N;
  int count = 0;
  for (int i = 0; i < N; i++){
    char X;
    cin >> X;
    if (X == 'Y'){
      count++; 
    }
  }
  if (count == 0){
    cout << "Three";
  }
  else {
    cout << "Four";
  }
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
 
int rt[200000];
 
int main(){
    ios::sync_with_stdio(false);
    int n;
    int i , j;
    int max,min;
    cin>>n;
    max=0x80000000;
    for(i=0 ; i<n ; i++){
        cin>>rt[i];
    }
    min=rt[0];
    for(i=1 ; i<n ; i++){
        if((rt[i]-min)>max){
            max=rt[i]-min;
        }
        if((rt[i])<min){
            min=rt[i];
        }
    }
    cout << max << endl;
    return 0;
}

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

#define rep(i,s,n) for (int i = (int)s; i < (int)n; i++)
#define ll long long
#define ld long double
#define pb push_back
#define eb emplace_back
#define All(x) x.begin(), x.end()
#define Range(x, i, j) x.begin() + i, x.begin() + j
#define lbidx(x, y) lower_bound(x.begin(), x.end(), y) - x.begin()
#define ubidx(x, y) upper_bound(x.begin(), x.end(), y) - x.begin()
#define llbidx(x, y, z) lower_bound(x.begin(), x.end(), z) - lower_bound(x.begin(), x.end(), y) // 二要素間の距離
// #define M_PI 3.14159265358979323846 // CFでは定義しておく必要あり
#define deg2rad(deg) ((((double)deg)/((double)360)*2*M_PI))
#define rad2deg(rad) ((((double)rad)/(double)2/M_PI)*(double)360)
#define Find(set, element) set.find(element) != set.end()
#define Decimal(x) printf("%.10f\n", x) // 小数点を10桁まで表示
// debug用
#define PrintVec(x) for (auto elementPrintVec: x) { cout << elementPrintVec << " "; } cout << "\n";
#define debug(x) cerr << #x << ": " << (x) << "\n";
#define endl "\n"
// gcj print用
#define Case(x) printf("Case #%d: ", x);

typedef pair<int, int> PI;
typedef pair<ll, ll> PLL;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>> vvvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<int>>> vvvl;
typedef vector<PI> vpi;
typedef vector<vector<PI>> vvpi;
typedef vector<vector<vector<PI>>> vvvpi;
typedef vector<PLL> vpl;
typedef vector<vector<PLL>> vvpl;
typedef vector<vector<vector<PLL>>> vvvpl;

int POWINT(int x, int n) {
  int ret = 1;
  while (n > 0) {
    if (n & 1) ret *= x;
    x *= x;
    n >>= 1;
  }
  return ret;
};

ll POWLL(ll x, int n) {
  ll ret = 1;
  while (n > 0) {
    if (n & 1) ret *= x;
    x *= x;
    n >>= 1;
  }
  return ret;
};

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

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

void print() {
  cout << endl;
};

template <class T>
void print(vector<T> &vec) {
  for (auto& a : vec) {
    cout << a;
    if (&a != &vec.back()) cout << " ";
  }
  cout << endl;
};

template <class T>
void print(vector<T> &vec, ll k){
   ll n = vec.size();
   k = min(k, n);
   rep(i, 0, k-1) cout << vec[i] << " ";
   cout << vec[k-1] << endl;
};

template <class T>
void print(vector<vector<T>> &df) {
  for (auto& vec : df) {
    print(vec);
  }
};

template<class T, class U>
void print(pair<T,U> &p){
  cout << p.first << " " << p.second << "\n";
};

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

  int a, b;
  cin >> a >> b;
  cout << (a-1)*(b-1) << endl;

  return 0;
};


Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
typedef pair<int,int> Card;
typedef vector<Card> Cards;

pair<int,int> f(int x,Cards& c){
	int sum = 0;
	for(int i = 0 ; i < c.size() ; i++){
		int num = c[i].second - c[i].first + 1;
		if(sum + num <= x){
			sum += num;	
		}else{
			int a = x - sum;
			return make_pair(i,a);
		}
	}
}
Cards get(int x,int y,Cards& c){
	Cards g;
	pair<int,int> s = f(x,c) , e = f(y,c);
	if(s.first != e.first){
		g.push_back(make_pair(c[s.first].first+s.second,c[s.first].second));
		for(int i = s.first + 1 ; i <= e.first-1 ; i++){
			g.push_back(c[i]);
		}
		g.push_back(make_pair(c[e.first].first,c[e.first].first+e.second));
		
	}else{
		int S = s.second , E = e.second;
		//cout << S << "-" << E << endl;
		g.push_back(make_pair(c[s.first].first+S,c[s.first].first+E));
	}
	return g;
}
int main(){
	int n;
	while(cin >> n && n){
		Cards c(1,make_pair(0,n-1));
		int m; cin >> m;
		int p,q,r;
		cin >> p >> q >> r;
		p--,q--;
		for(int i = 0 ; i < m ; i++){
			int a,b;
			cin >> a >> b;
			a--,b--;
			Cards A = get(0,a,c) , B = get(a+1,b,c) , C = get(b+1,n-1,c);
			C.insert(C.end(),B.begin(),B.end());
			C.insert(C.end(),A.begin(),A.end());
			c = C;
		}
		int ans = 0;
		c = get(p,q,c);
		for(int i = 0 ; i < c.size() ; i++){
			//cout << c[i].first << " " << c[i].second << endl;
			if( c[i].first < r ){
				ans += min(c[i].second,r-1) - c[i].first + 1;
			}
		}
		cout << ans << endl;
	}
	
}

Measured memory_bytes: 1212
/// kazuki08
/*
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int long long
typedef long long ll;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<pi> vpi;
//#define inf 1000000000
#define mod 1000000007
#define dmp(x) cerr<<"line "<<__LINE__<<" "<<#x<<":"<<x<<endl
#define fs first
#define sc second
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define mt make_tuple
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
    return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
    o<<"{";
    for(const T& v:vc) o<<v<<",";
    o<<"}";
    return o;
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int n,x;
int sum = 0;

signed main(){
IOS;
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
  
  cin >> n >> x;
  int mn = mod;
  for(int i=1;i<=n;i++){
    int a;
    cin >> a;
    mn = min(mn,a);
    sum+=a;
  }
  x-=sum;
  cout << (n + x/mn) << endl;


return 0;
}
///....


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<utility>
#include<tuple>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>

using namespace std;

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

#define BIL ((ll)1e9)
#define MOD ((ll)1e9+7)
#define INF (1LL<<60)           //1LL<<63でオーバーフロー

int main(int argc,char* argv[]){
    ll x,k,d;
    cin >> x >> k >> d;

    ll ans=0;
    if((abs(x)/d)>=k){
        cout << abs(x)-d*k << endl;;
        return 0;
    }else{
        ll nk = k-abs(x)/d;
        ll nx;
        if(x>0){
            nx = x-d*(x/d);
        }else{
            nx = x+d*(abs(x)/d);
        }
        if(nk%2==0){
            ans=abs(nx);
        }else{
            ans=abs(abs(nx)-d);
        }
    }

    cout << ans << endl;

    return 0;
}


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

int main() {
  int N,L;
  cin >> N >> L;
  vector<string> S(N);
  for (int i=0; i<N; i++) {
    cin >> S[i];
  }
  sort(S.begin(),S.end());
  
  for (int i=0; i<N; i++) {
    cout << S[i];
  }
  cout << endl;
  
  return 0;
  
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <iomanip>
#include <string.h>

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

typedef long long lint;

using namespace std;

int main(){
  int N;
  cin>>N;
  lint P[N];
  REP(i,N)cin>>P[i];
  lint m=1e9;
  int ans=0;
  REP(i,N){
    if(P[i]<m)ans++;
    m=min(m,P[i]);
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int pow(int x){
    int p=1;
    for(int i=0;i<x;i++)p*=10;
    return p;
}
int main(){
    string s;
    cin>>s;
    int n=s.size();
    for(int i=0;i<n;i++){
        if(s[i]!='?')s[i]-='0';
    }
    long long dp[n+1][13]={};
    dp[0][0]=1;
    const int mod=1000000007;
    for(int i=0;i<n;i++){
        int m=n-1-i;
        for(int j=0;j<13;j++){
            if(s[m]!='?'){
                if(i%6<3)dp[i+1][(j+s[m]*pow(i%6))%13]+=dp[i][j]%mod;
                else dp[i+1][((j-s[m]*pow(i%6-3))%13+13)%13]+=dp[i][j]%mod;
            }
            else{
                for(int k=0;k<=9;k++){
                    if(i%6<3)dp[i+1][(j+k*pow(i%6))%13]+=dp[i][j]%mod;
                    else dp[i+1][((j-k*pow(i%6-3))%13+13)%13]+=dp[i][j]%mod;
                }
            }
        }
    }
    cout<<dp[n][5]%mod<<endl;
    return 0;
}

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

int main(){
  int x,y;
  while(true){
  cin >> x >> y;
  if(x == 0 && y == 0) break;
  if(x >= y) cout << y << " " << x << endl;
  if(x < y)  cout << x << " " << y << endl;
  }
  return 0;
}

Measured memory_bytes: 1160
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define MOD 1000000007
#define INF (1<<30)
#define LINF (lint)(1LL<<56)
#define endl "\n"
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(int (i)=(n-1);(i)>=0;(i)--)
#define Flag(x) (1<<(x))
#define Flagcount(x) __builtin_popcount(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
#define plint pair<lint,lint>
typedef long long lint;
int dx[8]={1,1,0,-1,-1,-1,0,1};
int dy[8]={0,1,1,1,0,-1,-1,-1};

int main(void){
    int x1,y1,x2,y2;
    cin >> x1 >> y1 >> x2 >> y2;
    int x=x2-x1,y=y2-y1;

    cout << x2-y << " " << y2+x << " " << x1-y << " " << y1+x << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pi 3.1415
#define ll long long
#define pii pair<int,int>
#define debug(a) cout<<a<<'\n'
#define maxn 1009
#define MOD 1000000007
#define inp freopen("input.txt", "r", stdin)
#define out freopen("out.txt", "w", stdout)
using namespace std;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin>>n;
    int stot=0;
    int vet[maxn];
    for(int i=0;i<n;i++){
        cin>>vet[i];
        stot+=vet[i];
    }
    int ans=stot;
    int acum=0;
    for(int i=0;i<n-1;i++){
        stot-=vet[i];
        acum+=vet[i];
        ans=min(ans,abs(stot-acum));
    }
    cout<<ans<<endl;
    return 0;
}   


Measured memory_bytes: 256
#include<stdio.h>

#define G 9.8


int main(void)
{

        int n = 0;
        double v = 0, y = 0, t = 0;

        while( scanf("%lf",&v) != EOF)
        {
                t = v / G;
                y = G / 2.0 * t * t;
                n = (y + 5.0) / 5.0;
                printf("%d\n",n+1);
                t = 0;
                y = 0;
                n = 0;
                v = 0;
        }
        return 0;
}

Measured memory_bytes: 628
#include"bits/stdc++.h"
#include<boost/multi_array.hpp>
#include<boost/optional.hpp>
#include<boost/range/irange.hpp>
#include<boost/range/algorithm.hpp>
#include<boost/range/adaptors.hpp>
using namespace std;
namespace adaptor = boost::adaptors;

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
typedef long long ll;

void Main()
{
	int X;
    cin >> X;
  	int ans;
  	if(X>=2000){ans= 1;}
  	else{
		int top = X/100;
      	if(top*100<=X && X<=top*105){ans= 1;}
  		else {ans = 0;}
    }
  	cout << ans << endl;
  	return;
}

int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
	return 0;
}

Measured memory_bytes: 256