akhauriyash/Code-Regression huggingface dataset:
package main

import "fmt"

func main() {
	var n, y int
	fmt.Scan(&n, &y)


	for a := 0 ; a <= n ; a++ {
		for b := 0 ; a + b <= n ; b++ {
			for c := 0 ; a + b +c <= n ; c++ {
				// if y < 10000 * c{
				// 	break
				// }

				// if a + b + c  > n {
				// 	break
				// }
				if a + b + c == n {
					if y == 10000 * c + 5000* b + 1000* a {
						fmt.Println(c, b, a)
						return
					}
				}
			}
		}
	}

	fmt.Println("-1 -1 -1")
}



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

using namespace std;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    string x;
    int sum, len;
    while(cin>>x) {
        if(x=="0") break;
        sum=0;
        len = x.length();
        for(int i=0; i<len; i++) {
            sum+=x[i]-'0';
        }
        cout<<sum<<'\n';
    }
    return 0;
}

Measured memory_bytes: 1192
n, k = map(int, input().split())
P = list(map(int, input().split()))
ExP = list(map(lambda x: (x+1)/2, P))
ans = 0
prev = 0

#for i = 0
now = sum(ExP[0: k])
#print(0, now)
ans = max(ans, now)
prev = now

for i in range(1, n-k+1):
    now = prev - ExP[i-1] + ExP[i+k-1]
#    print(i, now)
    ans = max(ans, now)
    prev = now
print(ans)

Measured memory_bytes: 77448
import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 7)


class SegmentTree:
    def __init__(self, N, arr=None, op=None, unit=None):
        """
        INPUT
        N: 配列のサイズ
        segment tree: 1-indexedで構築
        original array: 0-indexed
                 1
           2           3
         4    5     6     7
        8 9 10 11 12 13 14 15
        ---------------------
        0 1 2  3  4  5  6  7
        """
        self.N = N
        self.unit = unit
        self.op = op
        self.tree = [unit] * (2 * N + 1)
        if arr is not None:
            self._build(arr)

    def _build(self, arr):
        op = self.op
        N = self.N
        for i, a in enumerate(arr, N):
            self.tree[i] = a
        for i in reversed(range(1, N)):
            self.tree[i] = op(self.tree[i << 1], self.tree[i << 1 | 1])

    def show(self):
        for i in range(self.N):
            print(self.tree[i+self.N], end=" ")
        print()

    def update(self, i, x):
        """
        arr[i]の値をxに変更する
        i: 0-indexed
        """
        i += self.N
        op = self.op
        self.tree[i] = x
        while i > 1:
            i >>= 1
            self.tree[i] = op(self.tree[i << 1], self.tree[i << 1 | 1])

    def query(self, L, R):
        """
        L,R: 0-indexed
        半開区間[L,R)の累積演算した値を返す
        """
        op = self.op
        res = self.unit
        L += self.N
        R += self.N
        while L < R:
            if L & 1:
                res = op(res, self.tree[L])
                L += 1
            if R & 1:
                R -= 1
                res = op(res, self.tree[R])
            L >>= 1
            R >>= 1
        return res


def op(a, b):
    return max(a, b)


unit = 0

U = 300000
N, K = map(int, input().split())
seg = SegmentTree(U+5, [0] * (U+5), op, unit)

for _ in range(N):
    a = int(input())
    l = max(0, a - K)
    r = min(U, a + K)
    val = seg.query(l, r + 1) + 1
    seg.update(a, val)

print(seg.tree[1])

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

#define int long long

vector<bool> sieve_of_eratosthenes(int n) {
  /* O(n log log n) */
  vector<bool> is_prime(n+1, true);
  is_prime[0] = is_prime[1] = false;
  for(int i=2; i<=n; i++)
    if(is_prime[i])
      for(int k=2; k * i <= n; k++)
        is_prime[k*i] = false;
  return is_prime;
}

vector<int> prime_list(int n) {
  /* O(n log log n) */
  auto is_prime = sieve_of_eratosthenes(n);
  vector<int> primes;
  for(int i=0; i<=n; i++)
    if(is_prime[i])
      primes.push_back(i);
  return primes;
}

map<int, int> prime_factorization(int n) {
  /* O(n log log n) */
  auto primes = prime_list((int)ceil(sqrt(n)));
  map<int,int> factors;
  for(auto i : primes) {
    while (n%i==0) {
      factors[i]++;
      n /= i;
    }
  }
  if(n!=1) factors[n]++;
  return factors;
}

int A,B;

signed main() {
  cin >> A >> B;

  auto fa = prime_factorization(A);
  auto fb = prime_factorization(B);
  map<int,int> f;
  for(auto p : fa) if(fb.count(p.first))
    f[p.first] = min(fb[p.first], p.second);
  for(auto p : fb) if(fa.count(p.first))
    f[p.first] = min(fa[p.first], p.second);

  for(auto p : f) cerr << p.first << ": " << p.second << endl;

  cout << f.size()+1 << endl;
}


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

public class Main{
  public static void main(String[] args) {
    try {
      Scanner sc = new Scanner(System.in);
      int a, b, c, k;

      a=Integer.parseInt(sc.next());
      b=Integer.parseInt(sc.next());
      c=Integer.parseInt(sc.next());
      k=Integer.parseInt(sc.next());

      if(a<=c && b<=c){
        for(int i=0; i<k; i++){
          c=c*2;
        }
        System.out.println(a+b+c);
      }
      if(a<=b && c<=b){
        for(int i=0; i<k; i++){
          b=b*2;
        }
        System.out.println(a+b+c);
      }
      if(b<=a && c<=a){
        for(int i=0; i<k; i++){
          a=a*2;
        }
        System.out.println(a+b+c);
      }

    }
    catch (Exception e) {

    }
  }
}


Measured memory_bytes: 20948
#include <bits/stdc++.h>
#pragma once
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;
typedef long double lb;
#define int long long
#define double long double
#define endn "\n"
typedef pair<int,int> P;
const int MOD = 1000000007;
const ll INF = 1e16;
const double EPS = 1e-10;
const double PI = 3.141592653589793;
template<class T> inline bool chmin(T& a, T b){if(a>b){a = b;return 1;}return 0;}
template<class T> inline bool chmax(T& a, T b){if(a<b){a = b;return 1;}return 0;}
const pair<int,int> fd[] = {make_pair(1,0),make_pair(-1,0),make_pair(0,1),make_pair(0,-1)}; 


////////////////////////////////////////////////////////////////////


signed main(){
  int n,k;cin>>n>>k;
  if(n < k){
    cout << min(n, k-n) << endl;
  }else{
    cout << min(n%k, k-(n%k)) << endl;
  }
}



Measured memory_bytes: 256
# -*- coding: utf-8

s = list(input())
count = 0

if s.count('W') == len(s) or s.count('B') == len(s):
    print('0')
else:
    turn = s[len(s) - 1]
    s.pop()
    while s:
        if s[len(s) - 1] == turn:
            s.pop()
        else:
            count += 1
            if turn == 'B':
                turn = 'W'
            else:
                turn = 'B'
    print(count)


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

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

const int MN = 100010;

int N;
vector<pii> adj[MN];
map<pii, int> wmap;
int par[MN], sz[MN];

void dfs0(int u, int p) {
    sz[u] = 1;

    for(int i = 0; i < adj[u].size(); i++) {
        int v = adj[u][i].first;
        if(v == p) continue;
        par[v] = u;
        dfs0(v, u);
        sz[u] += sz[v];
    }
}

int dfs1(int u, int p, int tot) {
    for(int i = 0; i < adj[u].size(); i++) {
        int v = adj[u][i].first;
        if(v == p) continue;
        if(sz[v] >= (tot + 1) / 2) return dfs1(v, u, tot);
    }
    return u;
}

ll ans;

void dfs2(int u, int p) {
    sz[u] = 1;
    for(int i = 0; i < adj[u].size(); i++) {
        int v = adj[u][i].first;
        int w = adj[u][i].second;
        if(v == p) continue;
        dfs2(v, u);
        sz[u] += sz[v];
        ans += 2LL * sz[v] * w;
    }
}

int main() {
    scanf("%d", &N);

    for(int i = 0; i < N - 1; i++) {
        int u, v, w; scanf("%d %d %d", &u, &v, &w);
        u--; v--;

        adj[u].push_back({v, w});
        adj[v].push_back({u, w});
        wmap[ {u, v} ] = w;
        wmap[ {v, u} ] = w;
    }

    dfs0(0, -1);
    int cent = dfs1(0, -1, N);

    if(par[cent] != -1 && sz[cent] == (N + 1) / 2) {
        dfs2(cent, par[cent]);
        dfs2(par[cent], cent);

        if(N % 2 == 0) ans += 1LL * (N - 1) * wmap[ {cent, par[cent]} ];
        else ans += 1LL * (N - 2) * wmap[ {cent, par[cent]} ];
    }
    else {
        dfs2(cent, -1);
        int mn = 2e9;
        for(int i = 0; i < adj[cent].size(); i++) {
            int w = adj[cent][i].second;
            mn = min(mn, w);
        }
        ans -= mn;
    }
    printf("%lld", ans);
}


Measured memory_bytes: 25728
def main():
    X, Y = map(int, input().split())

    for i in range(0, 101):
        for j in range(0, 101):
            if i + j == X and 2*i + 4*j == Y:
                print('Yes')
                exit()

    print('No')


if __name__ == "__main__":
    main()


Measured memory_bytes: 9172
#include "bits/stdc++.h"
using namespace std;
 
int main(){
	string s1,s2;
	cin>>s1>>s2;
	if(s1[0]==s2[2]&&
		s1[1]==s2[1]&&
	s1[2]==s2[0]){
		cout<<"YES"<<endl;
	}else{
		cout<<"NO"<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define MOD 1000000007
#define INF 1e18

using namespace std;

int main(void){
  ll s, w;
  cin >> s >> w;
  
  if (s <= w)
    cout << "unsafe" << endl;
  else
    cout << "safe" << endl;

  return 0;
}


Measured memory_bytes: 3588
#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

int main() {
  int n;
  cin >> n;
  
  int a1 = 0;
  int a2 = 0;
  int as[n];
  for (int i = 0; i < n; i++) {
    cin >> as[i];
    int a = as[i];
    if (a>a2) {
      swap(a,a2);
    }
    if (a2>a1) {
      swap(a1,a2);
    }
  }
  
  for (int i = 0; i < n; i++) {
    cout << (as[i] == a1 ? a2 : a1) << endl;
  }
 
  return 0;
}

Measured memory_bytes: 2432
#include <stdio.h>

int main(){
  char s[4];
  scanf("%s",s);
  int i,flag=0;
  
  for(i=0;i<3;i++){
    if(s[i]==s[i+1]){
      flag=1;
    }
  }
  if(flag==0)printf("Good\n");
  else printf("Bad\n");
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
 
 
void Sort(int* a){
int tmp;
for(int i=0;i<10;i++){
for(int j=0;j<9;j++){
if(a[j]<a[j+1]){
tmp = a[j+1];
a[j+1]=a[j];
a[j] = tmp;
}
}
}
}
 
 
 
int main(){
 
int a[10];
 
for(int i=0;i<10;i++){
std::cin >> a[i];
}
Sort(a);
 
std::cout << a[0] << std::endl;
std::cout << a[1] << std::endl;
std::cout << a[2] << std::endl;
 
 
}

Measured memory_bytes: 3092
#include<bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int N = 2e5 + 11;
int n, a[N];
int cnt[N], zo[N], s[N], D[N], invD[N];
inline int A(int x, int y){
	return x + y - (x + y >= mod ? mod : 0);
}
inline int M(int x, int y){
	return 1LL * x * y % mod;
}
struct bit{
	int tree[N];
	void add(int x, int v){
		for(;x <= n;x += -x & x)tree[x] = A(tree[x], v);
	}
	int query(int x){
		int ans = 0;
		for(;x;x -= -x & x)ans = A(ans, tree[x]);
		return ans;
	}
	void clear(){
		memset(tree, 0, sizeof(tree));
	}
}T, G;
int ksm(int base, int x){
	int ans = 1;
	while(x){
		if(x & 1)
			ans = M(ans, base);
		base = M(base, base);
		x >>= 1;
	}
	return ans;
}
int main(){
	cin>>n;
	for(int i = 1;i <= n; i++){
		scanf("%d", &a[i]);
		cnt[a[i]]++;
	}
	for(int i = n;i >= 1; i--)cnt[i] += cnt[i+1];
	int tot = 1;
	D[0] = s[0] = 1;
	for(int i = 1;i <= n; i++){
		cnt[i] -= n - i;
		if(cnt[i] <= 0){
			puts("0");
			return 0;
		}
		tot = M(tot, cnt[i]);
		int x = M(cnt[i] - 1, ksm(cnt[i], mod - 2));
		if(x == 0){
			zo[i] = zo[i-1] + 1;
			s[zo[i]] = i;
			D[i] = D[i-1];
		}
		else zo[i] = zo[i-1], D[i] = M(D[i-1], x);
		invD[i] = ksm(D[i], mod - 2);
	}
	tot = M(tot, ksm(2, mod - 2));
	int ans = 0;
	for(int i = 1;i <= n; i++){
		ans = A(ans, M(A(T.query(a[i]), mod - T.query(s[zo[a[i]]] - 1)), M(tot, D[a[i]])));
		T.add(a[i], invD[a[i]]);
	}
	T.clear();
	for(int i = n;i >= 1; i--){
		ans = A(ans, M(G.query(a[i] - 1), tot * 2 % mod));
		ans = A(ans, mod - M(M(tot, D[a[i]]), A(T.query(a[i] - 1), mod - T.query(s[zo[a[i]]] - 1))));
		T.add(a[i], invD[a[i]]);
		G.add(a[i], 1);
	}
	cout<<ans<<endl;
	return 0;
}


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

class Main{
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st  = new StringTokenizer(br.readLine());

        int N = Integer.parseInt(st.nextToken());
        
        long ans=0;
        HashMap<Integer, Integer> countMap = new HashMap();
        st  = new StringTokenizer(br.readLine());
        for (int i=1; i<=N; i++) {
            int x = Integer.parseInt(st.nextToken());
            countMap.put(x, countMap.getOrDefault(x, 0)+1);
            ans+=x;
        }

        st  = new StringTokenizer(br.readLine());

        int Q = Integer.parseInt(st.nextToken());

        while(Q--!=0){
            st  = new StringTokenizer(br.readLine());
            int a = Integer.parseInt(st.nextToken());
            int b = Integer.parseInt(st.nextToken());

            int ca = countMap.getOrDefault(a, 0);
            ans-=(long)a*(long)ca;
            ans+=(long)b*(long)ca;
            countMap.put(a, 0);
            countMap.put(b, countMap.getOrDefault(b, 0)+ca);
            System.out.println(ans);

        }


    }

}

Measured memory_bytes: 65276
#pragma GCC optimize("Ofast",3,"inline")
#include<bits/stdc++.h>
using namespace std;
#define fir first
#define sec second
#define m_p make_pair
#define y1 ygftgfgcdtfgxffgx
#define y2 yfdsesgvtyghftfvv
#define x1 xvyr6cf6fgcfgf676
#define x2 xcr6rfc5r66y6r6fr
#define up_bound upper_bound
#define low_bound lower_bound
#define next_per next_permutation
#define pb push_back
#define i_to_s to_string
typedef priority_queue<int> p_queue;
typedef priority_queue<int, vector<int>, greater<int> > min_p_queue;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
int mon[20]={0,31,28,31,30,31,30,31,31,30,31,30,31};
ll gcd(ll x,ll y){return ((y==0)?x:gcd(y,x%y));}
inline int read(){
	int x=0;char ch=getchar();
	while(ch<'0'||ch>'9')ch=getchar();
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x;
}
string s;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	cin>>s;
	cout << (s == "RRR" ? 3 : s.find("RR") != s.npos ? 2 : s == "SSS" ? 0 : 1);
	return 0;
}



Measured memory_bytes: 3612
#include<atcoder/dsu>
#include<iostream>
using namespace std;
using namespace atcoder;

int main() {
  int N, Q;
  cin >> N >> Q;
  int t, u, v;
  dsu d(N);
  for (int q = 0; q < Q; q++) {
    cin >> t >> u >> v;
    if (t == 0) {
      d.merge(u, v);
    } else {
      cout << d.same(u, v) << endl;
    }
  }
}

Measured memory_bytes: 4024
#include<iostream>
#include<cstdio>
#include<cstring>
#include <fstream>
#include<string>
#include<sstream>
#include<algorithm>
#include<bitset>
#include<vector>
#include<deque>
#include<queue>
#include<list>
#include<map>
#include<set>
#include<stack>
#include<cmath>
#include<iomanip>
#include <functional>
#include <math.h>
#include <assert.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const long long int MOD = 1000000007;
const int INF = 1000000007;
const double EPS = 1e-10;
const double PI = 3.14159265359;
const int N = 100005;
//cout << fixed << std::setprecision(9)
//--------------------------

ll dp[N][2];
vector<int> edge[N];
int n, u, v;

void dfs(int x, int last)
{
	dp[x][0] = dp[x][1] = 1;
	for (auto to : edge[x]) {
		if (to == last) continue;
		dfs(to, x);
		dp[x][0] = dp[x][0] * ((dp[to][0] + dp[to][1]) % MOD) % MOD;
		dp[x][1] = dp[x][1] * dp[to][0] % MOD;
	}
}

int main()
{
	cin >> n;
	for (int i = 0; i < n - 1; i++) {
		cin >> u >> v;
		edge[u].push_back(v);
		edge[v].push_back(u);
	}

	dfs(1, -1);
	cout << (dp[1][0] + dp[1][1]) % MOD << endl;

	return 0;
}


Measured memory_bytes: 17436
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long 
#define llinf 1e17
#define nllinf -4e18
 
#define vll vector<ll>
#define sll set<ll>
#define pll pair<ll,ll> 
#define vpll vector<pair<ll,ll > >
 
#define repup(a,b,i) for(i=a;i<=b;i++)
#define repdown(a,b,i) for(i=b; i>=a; i--)
#define repupx(a,b,i,x) for(i=a;i<=b;i+=x)
	
#define repit(v,it) for(it=v.begin(); it!=v.end(); it++)
#define itall(v) v.begin(),v.end()
#define pb push_back
#define pf push_front
#define mp make_pair
#define fr first
#define sc second

#define err(n) cout<<n<<" ";
#define t1 cout<<",";

 ll MOD= 1e9 +7;

void add_self (ll& a, ll b){
	a+= b;
	if(a>=MOD)a-=MOD;
}

void sub_self (ll& a, ll b){
	a-=b;
	a= ((a%MOD)+MOD)%MOD;
}

ll mul(ll a, ll b){
	a*=b;
	a%=MOD;
	return a;
}
const int nax= 1e5+5;
vll a[nax];
ll dp[nax][2];

pll dfs(ll vertex, ll parent){
	ll aw= 1;
	ll sib= 0;
	for(ll b:a[vertex]){
		if(b!=parent){
			pll q= dfs(b, vertex);
			ll temp= aw;
			aw= mul(aw, q.sc);
			sib= (mul(temp, q.fr)+ mul(sib, q.fr+q.sc))%MOD;
		}
	}
	return mp(aw, (sib+aw)%MOD);
}
int main(){
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
ll i,j,k;
ll n;cin>>n;

pll deg[n+1];

repup(0,n-2,i){
	ll x,y;cin>>x>>y;
	a[x].pb(y);
	a[y].pb(x);

}

 // number of ways to colour vertex i as white: dp[i][0], black:dp[i][1]

pll ans= dfs(1,-1);
cout<<(ans.fr+ans.sc)%MOD;
}

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

int main()
{
	char n[4];
	cin >> n;
	if((n[0] == n[1] && n[1] == n[2])||(n[1] == n[2] && n[2] == n[3])){
		cout << "Yes\n";
	}else{
		cout << "No\n";
	}

	return 0;
}


Measured memory_bytes: 256
from itertools import*
from math import*
from collections import*
from heapq import*
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf = float("inf")
mod = 10**9+7
from functools import reduce
import sys
sys.setrecursionlimit(10**7)

A,B,K = map(int,input().split())
for i in range(K):
    if i % 2== 0:
        if A % 2 == 0:
            C = A//2
            B += C
            A -= C
        else:
            A -=1
            C = A//2
            B += C
            A -=C
    else:
        if B % 2 == 0:
            C = B//2
            B -= C
            A += C
        else:
            B -=1
            C = B//2
            A += C
            B -= C

print(A,B)

Measured memory_bytes: 38384
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		printAChessboard();

	}

	public static void printAChessboard() {
		
		Scanner sc = new Scanner(System.in);
		
		while (true) {
			
			int H = sc.nextInt();
			int W = sc.nextInt();
			
			if (H == 0 && W == 0) {
				
				break;
			}
			
			for (int i = 0; i < H; i++) {
				
				for (int j = 0; j < W; j++) {
					
					if (i % 2 == 0) {
						
						if (j % 2 == 0) {
							
							System.out.print("#");
						} else {
							
							System.out.print(".");
						}
					} else {
						
						if (j % 2 == 0) {
							
							System.out.print(".");
						} else {
							
							System.out.print("#");
						}
					}
				}
				
				System.out.println("");
			}
			
			System.out.println("");
		}
	}
}


Measured memory_bytes: 32816
#include <iostream>
using namespace std;
int main() {

	long long int n, m, k;cin >> n >> m >> k;
	if (n < k) {
		long long int a = k - n;
		if (a >= m) {
			cout << 0 << " " << 0 << endl;
		}
		else {
			cout << 0 << " " << m - a << endl;
		}
	}
	else
		cout << n - k << " " << m << endl;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**7)

#debug = True
debug = False

def dprint(*objects):
    if debug == True:
        print(*objects)

def solve():
    N = int(input())
    ltask = []
    for i in range(N):
        a, b = map(int, input().split())
        ltask.append([a, b])

    from operator import itemgetter
    ltask.sort(key=itemgetter(1))

    ans = "Yes"
    time = 0
    for task in ltask:
        time += task[0]
        if time > task[1]:
            ans = "No"
            break

    print(ans)

solve()

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

int gcd(int a, int b)
{
	if(a==0)
		return b;
	return gcd(b%a, a);
}

int main()
{
	int i,guarantee,ans,n;
	cin >> n;
	int a[n];
	int forward[n];
	int backward[n];

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

	// forward[i] stores the gcd(a[0],a[1],...,a[i-1])
	forward[0] = 0;
	for(i=1; i<n; i++)
		forward[i] = gcd(a[i-1], forward[i-1]);

	// backward[i] stores the gcd(a[N-1],a[N-2],...,a[i+1])
	backward[n-1] = 0;
	for(i=(n-2); i>=0; i--)
		backward[i] = gcd(a[i+1], backward[i+1]);

	// for(i=0; i<n; i++)
	// 	cout << forward[i] << " " << backward[i] << endl;

	ans = -1;
	for(i=0; i<n; i++)
	{
		guarantee = gcd(forward[i], backward[i]);
		ans = max(ans, guarantee);
	}
	cout << ans << endl;

	return 0;
}


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

#define int long long

using namespace std;

const int mod = 1e9 + 7;

int32_t main() {
    cin.tie(0);
    ios_base::sync_with_stdio(0);
    int n;
    cin >> n;
    vector<vector<int>> a(n, vector<int>(n));
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            cin >> a[i][j];
        }
    }
    vector<int> score(1 << n);
    for (int mask = 0; mask < (1 << n); mask++) {
        for (int i = 0; i < n; i++) {
            if ((mask & (1 << i)) == 0) {
                continue;
            }
            for (int j = 0; j < i; j++) {
                if ((mask & (1 << j)) == 0) {
                    continue;
                }
                score[mask] += a[i][j];
            }
        }
    }
    vector<int> dp(1 << n, 0);
    for (int mask = 1; mask < (1 << n); mask++) {
        for (int submask = mask; submask > 0; submask--, submask &= mask) {
            dp[mask] = max(dp[mask], score[submask] + dp[mask ^ submask]);
        }
    }
    cout << dp[(1 << n) - 1] << endl;
    return 0;
}


Measured memory_bytes: 4256
#include <iostream>
#include <string>
#include <algorithm>

int main()
{
  std::string str;
  std::cin >> str;
  auto zeros = std::count(str.begin(), str.end(), '0');
  auto ones = std::count(str.begin(), str.end(), '1');
  std::cout << std::min(zeros, ones)*2;
}


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

int main(void){
    int n,k;
    cin >> n >> k;
    int d[k];
    for(int i = 0;i < k;i++)cin >> d[i];
    for(;;n++){
        string s = to_string(n);
        bool check = true;
        for(int i = 0;i < s.size();i++){
            for(int j = 0;j < k;j++)if(s[i]-'0' == d[j])check = false;
        }
        if(check == true)break;
    }
    cout << n << endl;
}


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

int main(void)
{
	char str[1000];
	int flag;
	int i;
	int len;
	
	while (fgets(str, 999, stdin) != 0){
		len = strlen(str);
		
		str[len - 1] = '\0';
		
		flag = 0;
		
		while (flag == 0){
			/*ここで復号してみる*/
			for (i = 0; i < len; i++){
				if ('a' <= str[i] && str[i] <= 'z'){
					if (str[i] == 'z'){
						str[i] = 'a';
					}
					else {
						str[i]++;
					}
				}
			}
			
			/*ここで判定*/
			for (i = 0; i < len; i++){
				if (strncmp("the", &str[i], 3) == 0){
					flag++;
					break;
				}
				if (strncmp("this", &str[i], 4) == 0){
					flag++;
					break;
				}
				if (strncmp("that", &str[i], 4) == 0){
					flag++;
					break;
				}
			}
		}
		
		printf("%s\n", str);
	}
	
	return (0);
}

Measured memory_bytes: 524
import java.util.Scanner;
public class Main{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
    	int n = scan.nextInt();
    	int q = scan.nextInt();
    	int[] tqueue = new int[n];
    	String[] nqueue = new String[n];
    	int start = 0;
    	int end = n - 1;
    	int now = 0;
    	int how = n;
    	
    	for(int i = 0; i < n; i++){
    		nqueue[i] = scan.next();
    		tqueue[i] = scan.nextInt();
    	}
    	
    	while(how > 0){
    		if(tqueue[start] <= q){
    			now += tqueue[start];
    			System.out.println(nqueue[start]+" "+now);
    			start = (start + 1)%n;
    			how--;
    		}else{
    			now += q;
    			end = (end + 1)%n;
    			tqueue[end] = tqueue[start] - q;
    			nqueue[end] = nqueue[start];
    			start = (start + 1)%n;
    		}
    	}
    }
}


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

int main(){
    int n, cnt = 0;
    cin >> n;
    for(int i=1;i<=n;++i){
        int p;
        cin >> p;
        if(p != i) ++cnt;
    }
    if(cnt <= 2) cout << "YES" << endl;
    else cout << "NO" << endl;
    
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Linq;


class Program
{
    static void Main(string[] args)
    {


        long kaisu = int.Parse(Console.ReadLine());
        long[] a = new long[kaisu * 2];
        for (long i = 0; i < kaisu; i++)
        {
            long[] y1 = Console.ReadLine().Split().Select(Int64.Parse).ToArray();
            a[i] = y1[0];
            a[kaisu + i] = y1[1];
        }
        long ans = 0;
        for (long i = kaisu; i > 0; i--)
        {
            long x, y;

            x = a[i - 1] + ans;

            y = a[kaisu-1 + i];
          if (x % y == 0)
            {  }
            else
            {
                ans += (((x / y) + 1) * y) - x;
            }
        }
        Console.WriteLine(ans);
    }

}

Measured memory_bytes: 8472
//#include<iostream>
//#include<algorithm>
//#include<string>
//#include <cmath>
//#include <vector>
#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define REP(x,n) for(int x=0;x<n;x++)

// vector 操作  vector<int> data(10,5) 5が10個　data(10) 要素数10
// v.size(), v.empty(), v.insert(itr,値), v.erase(itr) (first,last),
// sort(itr), find(all(x),値),reverse(itr),accumulate(itr,0) 積算,
//v.swap
// stringも同じ itrがただの数字になる
// s.substr(n,m)n番目以降m文字取り出す　erase(n,m)も  s.find
#define vei vector<int> 
#define velli vector<long long int> 
#define pb(x) push_back(x) // 末尾にxを加える
#define pb2 pop_back() // 末尾削除
#define all(x) (x).begin(),(x).end() //イテレーター
#define be(x) (x).begin()
//auto  auto begin = v.begin()とか

// map 操作  map<string,int> mp キー=string 値=int型  pair< , >型
// 代入:mp["abc"]=123  mp.erase(キー)
// itr = mp.begin()のとき　itr->first = key, itr->second = val
// mp.find(key) itrを返す
typedef pair<int,int> P;  //q(p.first,p.second)で定義できる？

// lcm( , ) gcd( , ) 最大公約数　最小公倍数
//if(cin.eof()) break; 入力数が決まってないとき
//ifstream  whilwee(ifs>>data)

// 浮動小数点
// cout << fixed; 以下と組fみ合わせで小数点以下n桁
// cout << setprecision(n) << 値; n桁表記
// defaultfloat
int main (){
    int x,y,z;
    cin >> x >> y >> z;

    swap(x,y);
    swap(x,z);
    cout << x << " ";
    cout << y << " ";
    cout << z << endl;

}

Measured memory_bytes: 256
#pragma comment(linker, "/stack:20000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")

#include <stdio.h>
#include <bits/stdc++.h>

using namespace std;

#include <x86intrin.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template <typename T> using ordered_set = tree<T, null_type, std::less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define all(x) x.begin(), x.end()

#define mp make_pair
#define in insert
#define er erase
#define con continue
#define pb push_back
#define sc scanf
#define pr printf
#define ub upper_bound
#define lb lower_bound
#define s second
#define f first
#define int long long

const long long infl = 1e18; 
const int N = 3e5 + 300, N2 = 2e3, inf = 1e9 + 200;

set <int> S;
vector <int> g;
int n, m, k;
int a[N];
string ss;

int ch(vector <int> &v){
	int sum = 0;
	for (int i = 0; i < n; i++) sum += v[i];
	for (int i = 0; i < n; i++){
		if (__gcd(v[i], sum) == 1) return 0;
	}
	int x = 0;
	for (int i = 0; i < n; i++){
		x = __gcd(x, v[i]);
	}
	if (x == 1) return 1;
	return 0;
}

main (){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	srand(time(0));
	cin >> n;
	/*if (n == 3){
		cout << "2 3 25";
		return 0;
	}*/
	/*if (n == 4){
		cout << "2 3 4 9";
		return 0;
	}*/
	/*if (n == 5){
		cout << "2 3 4 5 16";
		return 0;
	}*/
	vector <int> v;
	for (int i = 2; i <= 30000; i += 2) v.pb(i);
	for (int i = 3; i <= 30000; i += 6) v.pb(i);
	while (!ch(v)) random_shuffle(all(v));
	for (int i = 0; i < n; i++){
		cout << v[i] << " ";
	}
	return 0;
}












Measured memory_bytes: 640
#include <bits/stdc++.h>
#define MOD 1000000007
#define INF 1000000000
#define LINF 1000000000000000000
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define bit(n) (1LL<<(n))
using namespace std;

typedef pair<int, int> P;
typedef pair<long long, long long> LLP;

int main() {

    int H, W, K;
    cin >> H >> W >> K;
    string S[H];
    rep(i,H) cin >> S[i];

    int minimum = H * W;

    rep(N,bit(H-1)) {
        vector< vector<int> > count(H, vector<int>(W,0));
        vector<bool> cut(W,false);

        int sum = 0;
        rep(j,W) {
            rep(i,H) {
                count[i][j] += (i > 0 && ((N & bit(i-1)) == 0) ? count[i - 1][j] : 0);
                count[i][j] += (j > 0 && !cut[j] ? count[i][j - 1] : 0);
                count[i][j] -= (i > 0 && j > 0 && ((N & bit(i-1)) == 0) && !cut[j] ? count[i - 1][j - 1] : 0);
                if (S[i][j] == '1') count[i][j]++;
                if (count[i][j] > K) {
                    cut[j] = true;
                    count[i][j] = (j > 0 ? count[i][j] - count[i][j - 1] : 0);
                    if (j == 0 || count[i][j] > K) sum = INF;
                }
            }
            if (cut[j]) {
                rep(i,H) {
                    count[i][j] = 0;
                    count[i][j] += (i > 0 && ((N & bit(i-1)) == 0) ? count[i - 1][j] : 0);
                    count[i][j] += (j > 0 && !cut[j] ? count[i][j - 1] : 0);
                    count[i][j] -= (i > 0 && j > 0 && ((N & bit(i-1)) == 0) && !cut[j] ? count[i - 1][j - 1] : 0);
                    if (S[i][j] == '1') count[i][j]++;
                }
            }
        }

        rep(i,H) if ((N & bit(i-1)) > 0) sum++;
        rep(j,W) if (cut[j]) sum++;
        minimum = min(minimum, sum);
    }

    cout << minimum << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define REP(i,a,b) for(inti=a;i<=b;i++)

#define MOD 1000000009
typedef long long int ll;
typedef vector<int>vi;
typedef pair<int,int>pi;


vector<int>  v[200001];
int n ,m;
bool ans;

int main()
{

ans=false;
cin>>n>>m;

for(int index = 0;index < m;index++)
{
    int from ,to;
    cin>>from>>to;

    v[from].push_back(to);
    v[to].push_back(from);
}
for(int index = 0 ;index < v[1].size();index++)
{
    for(int i = 0 ;i< v[v[1][index]].size();i++)
    {
        if(v[v[1][index]][i]==n)
        {
            cout<<"POSSIBLE"<<endl;
            return 0;
        }
    }
}

cout<<"IMPOSSIBLE"<<endl;

 return 0;
}


Measured memory_bytes: 15004
#include <assert.h>
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
 
using ll = long long;
using P = std::pair<char, ll>;
 
#define rep(i, a, b) for (ll(i) = (a); i < (b); i++)
#define all(i) i.begin(), i.end()
#define debug(i) std::cerr << "debug " << #i <<" "<<i<<std::endl;
 
template <typename T1, typename T2>
std::ostream& operator<<(std::ostream& os, std::pair<T1, T2> pa) {
  return os << pa.first << " " << pa.second;
}
 
template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
  for (int i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  return os;
}
 
template<typename T1,typename T2>
inline bool chmax(T1& a,T2 b){return a<b && (a=b,true);}
 
template<typename T1,typename T2>
inline bool chmin(T1& a,T2 b){return a>b && (a=b,true);}
 
// const ll MOD = 998244353;
const ll MOD = 1e9 + 7;
 
int main() {
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);

  ll n,q;
  std::cin>>n>>q;

  std::string s;
  std::cin>>s;

  std::vector<P> query(q);
  rep(i,0,q){
    char t,d;
    std::cin>>t>>d;
    ll temp;
    if(d=='L')temp=-1;
    else temp=1;

    query[i]={t,temp};
  }

  ll left=-1,right=n;

  while(right-left>1){
    ll mid=left+(right-left)/2;

    ll now=mid;
    bool isok=true;

    rep(i,0,q){
      if(s[now]==query[i].first)now+=query[i].second;

      if(now<0){
        isok=false;
        break;
      }
    }

    if(isok)right=mid;
    else left=mid;
  }

  ll min=right;

  left=-1;right=n;

  while(right-left>1){
    ll mid=left+(right-left)/2;

    ll now=mid;
    bool isok=true;

    rep(i,0,q){
      if(s[now]==query[i].first)now+=query[i].second;

      if(now>=n){
        isok=false;
        break;
      }
    }

    if(isok)left=mid;
    else right=mid;
  }

  std::cout<<left-min+1;

  return 0;
}





Measured memory_bytes: 3732
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;

/**
 * @author:26019
 */
public class Main {


    public static void main(String[] args) throws Exception {
        solve();
    }

    private static void solve() throws Exception {
        //BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(new File("C:\\Users\\26019\\Downloads\\out.txt"))));
        FastScanner cin = new FastScanner();
//        Scanner cin = new Scanner(System.in);
        long left = 1, right = 1000000001;
        int n = cin.nextInt(), k = cin.nextInt();
        int[] arr = cin.readArray(n);
        while (left < right) {
            long m = (left + right) / 2;
            if (check(arr, m, k)) {
                right = m;
            } else {
                left = m + 1;
            }
        }
        System.out.println(left);
    }

    private static boolean check(int[] arr, long len, int k) {
        int times = 0;
        for (int value : arr) {
            times += value / len;
            //刚好够，不用切
            if (value % len == 0) {
                times--;
            }
        }
        return times <= k;
    }

    static class FastScanner {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        //BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(new File("C:\\Users\\26019\\Downloads\\P1190_9.in"))));
        StringTokenizer st = new StringTokenizer("");

        FastScanner() throws FileNotFoundException {
        }

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

        public String nextLine() { // 读取带空格的字符串
            String res = null;
            try {
                res = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return res;
        }

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

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

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

        public double nextDouble() {
            return Double.parseDouble(next());
        }

    }
}



Measured memory_bytes: 55916
n = int(input())

A = [int(x) for x in input().split()]
B = {}

for a in A:
    if a not in B:
        B[a] = 0
    B[a] += 1

for i in range(1, n + 1):
    if i in B:
        print(B[i])
    else:
        print(0)


Measured memory_bytes: 33492
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <numeric>
#include <cmath>
#include <cassert>
#include <iomanip>
#include <bitset>


using namespace std;

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

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

const ll mod = 1e9+7;
const ll INF = 1e9;

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

ll f(int x,vector<ll> &s){
	ll ret = 0;
	int n = s.size();
	ll ma = 0;

	for (int k = 1; k <= (n-1)/x; k++){
		if((n-1)%x==0 &&  n-1-(k-1)*x<=(k-1)*x) break;
		ret += s[n-1-(k-1)*x]+s[(k-1)*x];
		ma = max(ret,ma);
	}
	return ma;
}

int main()
{
	int n;
	cin>>n;
	vector<ll> s(n);
	rep(i,n) cin>>s[i];
	ll ans=0;
	for (int x = 1; x < n; x++){
		ans = max(ans,f(x,s));
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned int uint;
typedef unsigned char uchar;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;

#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();i++)
#define RFOR(i,c) for(__typeof((c).rbegin())i=(c).rbegin();i!=(c).rend();i++)
#define ALL(container) (container).begin(), (container).end()
#define RALL(container) (container).rbegin(), (container).rend()
#define SZ(container) ((int)container.size())
#define mp(a,b) make_pair(a, b)
#define pb push_back
#define eb emplace_back
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define __builtin_popcount __builtin_popcountll

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 (a>b) { a=b; return 1; } return 0; }
template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {
    os<<"["; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"]"; return os;
}
template<class T> ostream& operator<<(ostream &os, const set<T> &t) {
    os<<"{"; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"}"; return os;
}
template<class S, class T> ostream& operator<<(ostream &os, const map<S, T> &t) {
    os<<"{"; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"}"; return os;
}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}
template<class S, class T> pair<S,T> operator+(const pair<S,T> &s, const pair<S,T> &t){ return pair<S,T>(s.first+t.first, s.second+t.second);}
template<class S, class T> pair<S,T> operator-(const pair<S,T> &s, const pair<S,T> &t){ return pair<S,T>(s.first-t.first, s.second-t.second);}

const int INF = 1<<28;
const double EPS = 1e-8;
const int MOD = 1000000007;


int T, n, m;

int main(int argc, char *argv[]){
    ios::sync_with_stdio(false);
    string s;
    while(cin >> n){
        vector<ll> d;
        ll asum = 0, bsum = 0;
        REP(i, n) {
            int a, b;
            cin >> a >> b;
            d.emplace_back(a + b);
            asum += a;
            bsum += b;
        }
        sort(RALL(d));
        ll ans = 0;
        int i = 0, j = n;
        while(i < j) {
            ans += d[i ++];
            if (i < j) ans -= d[i ++];
        }
        cout << (asum - bsum + ans) / 2 << endl;
    }
    return 0;
}


Measured memory_bytes: 1400
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();

        int count = 0;
        while (count < 100) {
            int d = a;
            int e = b;
            int f = c;
            if (a % 2 == 0 && b % 2 == 0 && c % 2 == 0) {
                count++;
                a = (e + f) / 2;
                b = (f + d) / 2;
                c = (d + e) / 2;
                d = a;
                e = b;
                c = f;
            } else {
                break;
            }
        }

        if (count < 100) {
            System.out.println(count);
        } else {
            System.out.print(-1);
        }
    }

}


Measured memory_bytes: 22100
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
//#define ll long long
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 (a>b) { a=b; return 1; } return 0; }
#define rep(i, n) REP(i, 0, n)
#define rep_rev(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
#define all(x) (x).begin(),(x).end()
ll t1,t2,t3;
const ll mod = 998244353;
const int INF = 1e9;
const ll INFLONG = 1e18;

int main(){
  double a,b,h,m;
  cin >> a >> b >> h >> m;
  double ax,ay,bx,by;
  double s1,s2;
  s1 = 4 * asin(1) * (h * 60 + m) / 720;
  s2 = 4 * asin(1) * (m / 60);
  //cout << s1 << endl;
  ax = a * cos(s1);
  ay = a * sin(s1);
  bx = b * cos(s2);
  by = b * sin(s2);
  //cout << ax << ay << bx << by << endl;
  //cout << s2 << endl;
  double ans = sqrt((ax-bx) * (ax - bx) + (ay - by) * (ay - by));
  printf("%.20lf\n",ans);
}

Measured memory_bytes: 4164
////////////////////////////////////////////
///                                      ///
///         Template ver. 1 rapel        ///
/// Fear is Temporary, Regret is Forever ///
///          Must Try and Get AC         ///
///                                      ///
////////////////////////////////////////////
#include <stdio.h>
#include <iostream>
#include <sstream>
#include <iomanip>

#include <algorithm>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <utility>

#include <math.h>
#include <complex>

#include <assert.h>
#include <time.h>
//#include <chrono>
//#include <random>

#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <bitset>

#define FI first
#define SE second
#define MP make_pair
#define PB push_back
#define PF push_front
#define POB pop_back
#define POF pop_front
#define endl '\n'
using namespace std;

typedef long long LL;
typedef unsigned long long ULL;

void desperate_optimization(int precision){
  	ios_base::sync_with_stdio(false);
  	cin.tie(0);
  	cout.tie(0);
  	cout.setf(ios::fixed);
  	cout.setf(ios::showpoint);
  	cout.precision(precision);
}

const int N = 5000 * 5000;
LL arr[2][3];
LL dp[N + 5];

void hora(int tc) {
	int n;
	cin>>n;
	for(int i = 0;i < 2;i++) {
		for(int j = 0;j < 3;j++) cin>>arr[i][j];
	}
	dp[0] = 0;
	for(int i = 0;i < 3;i++) {
		for(int j = arr[0][i];j <= n;j++) {
			dp[j] = max(dp[j], dp[j - arr[0][i]] + arr[1][i]);
		}
	}
	LL nn = 0;
	for(int i = 0;i <= n;i++) nn = max(nn, dp[i] + n - i);
	memset(dp, 0, sizeof dp);
	for(int i = 0;i < 3;i++) {
		for(int j = arr[1][i];j <= nn;j++) {
			dp[j] = max(dp[j], dp[j - arr[1][i]] + arr[0][i]);
		}
	}
	LL nnn = nn;
	for(int i = 0;i <= nn;i++) nnn = max(nnn, dp[i] + nn - i);
	cout<<nnn<<endl;
}

int main(){
	desperate_optimization(10);
	int ntc = 1;
	//cin>>ntc;
	for(int tc = 1;tc <= ntc;tc++) hora(tc);
	return 0;
}

Measured memory_bytes: 195584
# -*- coding: utf-8 -*-
"""
Created on Sat May  9 14:24:12 2020

@author: shinba
"""

import itertools

n = int(input())
p = tuple(map(int,input().split()))
q = tuple(map(int,input().split()))

a = [i for i in range(1,n+1)]

cnt = 0
for i in itertools.permutations(a):
    cnt += 1
    if i == p:
        a = cnt
    if i == q:
        b = cnt

print(abs(a-b))



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

import static java.lang.Character.isUpperCase;

public class Main {

    public static void main(String[] args) {

        Scanner in = new Scanner(System.in);
        int N = in.nextInt();
        int bill = 1000;

        if (N%bill==0)
        {
            System.out.println(0);

        }
        else
            {
          int no_of_notes = N/bill+1;
          System.out.println(no_of_notes*1000-N);
        }

            }
    }

Measured memory_bytes: 35672
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
/* clang-format off */
#define INF 1000000000
#define REP(i, n) for (ll i = 0, i##_len = (n); i < i##_len; ++i)
#define ALL(a) (a).begin(), (a).end()
// #define __DEBUG__
#ifdef __DEBUG__
#define DEBUG(x) cout<<#x<<":"<<x<<"\n"
#define DEBUGS(v) cout << #v << ":";for(auto x:v){cout<<x<<" ";}cout<<"\n"
#endif
#ifndef __DEBUG__
#define DEBUG(x)
#define DEBUGS(v)
#endif
#define TIMER_S(start) chrono::system_clock::time_point start = chrono::system_clock::now();
#define TIMER_E(end) chrono::system_clock::time_point end = chrono::system_clock::now();
#define TIME(start, end) cout << static_cast<double>(chrono::duration_cast<chrono::microseconds>(end - start).count()) << "ms" << "\n";
/* clang-format on */

int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<int>> child(n, vector<int>(0));
  vector<int> ans(n, -1);
  REP(i, m) {
    int a, b;
    cin >> a >> b;
    child.at(a - 1).push_back(b - 1);
    child.at(b - 1).push_back(a - 1);
  }
  set<int> s;

  s.insert(0);
  while (!s.empty()) {
    set<int> next;
    for (auto x : s) {
      DEBUG(x);
      for (auto &c : child[x]) {
        DEBUG(c);
        if (ans[c] == -1) {
          ans[c] = x;
          next.insert(c);
        }
        DEBUGS(ans);
        if (!child[c].empty()) child[c].erase(find(ALL(child[c]), x));
        REP(i, n) { DEBUGS(child[i]); }
      }
      s.erase(x);
    }
    for (auto &ne : next) {
      s.insert(ne);
    }
  }

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


Measured memory_bytes: 19212
#include <bits/stdc++.h>
#define pb push_back
#define int long long
#define mp make_pair
#define inf 1000000007
#define LINF 1000000000000000007LL
#define ll long long
using namespace std;
signed main(){
	int n;
	cin>>n;
	vector<int> a;
	for(int i=0;i<n;i++){
		int x;
		cin>>x;
		a.pb(x);
	}
	int cur = 1;
	int ans = 0;
	for(int i=0;i<n;i++){
		if( cur == 1 ){
			ans += a[i]-1;
			cur++;
		}
		else if( a[i] > cur){
			ans += (a[i]-1)/cur;
		}
		else if( a[i] == cur){
			cur++;
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1400
use std::str::FromStr;
use std::fmt::Debug;
use std::cmp;

#[allow(dead_code)]
fn read_as_vec<T>() -> Vec<T>
where T: FromStr, <T as FromStr>::Err : Debug{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().split_whitespace().map(|c| T::from_str(c).unwrap()).collect()

}

#[allow(dead_code)]
fn read_as_string() -> String{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}


fn main(){
    let line: Vec<u64> = read_as_vec();
    let (r, d) = (line[0], line[1]);
    let mut x = line[2];
    for _ in 0..10{
        x = r*x-d;
        println!("{}", x);
    }
}


Measured memory_bytes: 4352