akhauriyash/Code-Regression huggingface dataset:
// g++ macro.cpp -std=c++14
#include <bits/stdc++.h>
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
using namespace std;
 
#define dump(x)  cout << #x << " = " << (x) << endl;
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) << endl
#define possible(n) cout << ((n) ? "possible" : "impossible"  ) << endl
 
#define SANKOU(n,a,b) cout << ((n) ? (#a) : (#b) ) << endl
 
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
 
#define FOREACH(x,a) for(auto& (x) : (a) )
 
#define WFA(d,v) REP(k,v)REP(i,v)REP(j,v)d[i][j]=min(d[i][j],d[i][k]+d[k][j])
 
#define SCOUT(x) cout<<(x)<<" "
#define ENDL cout<<endl
 
#define VECCIN(x) for(auto&youso_: (x) )cin>>youso_
#define VECIN2(x,y) REP(i,x.size())cin>>x[i]>>y[i]
#define VECCOUT(x) if(1){for(auto tt=x.begin();tt!=x.end();tt++){if(tt!=x.begin())cout<<" ";cout<<(*tt);}cout<<endl;}
 
#define ALL(obj) (obj).begin(),(obj).end()
 
#define EXIST(n,x) (find(ALL(n),x)!=n.end())
#define UNIQUE(obj) sort(ALL( obj )); obj.erase(unique(ALL(obj)),obj.end())
#define EN(x) if(1){cout<<#x<<endl;return 0;}
#define COUT(x) cout<<(x)<<endl
void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail){
    cin>>head;
    CINT(move(tail)...);
}
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)
 
template <class T = ll>
T IN(){T x;cin>>x;return (x);}
 
template <class Head>
void VT(Head head){}
template <class Head,class Seco,class... Tail>
void VT(Head&& head,Seco&& seco,Tail&&... tail){
    seco.resize(head);
    VT(head,move(tail)...);
}
void VT2(){}
template <class Head,class... Tail>
void VT2(Head&& head,Tail&&... tail){
  VECCIN(head);
  VT2(move(tail)...);
}
 
template <class Head>
void VT3(Head&& head){}
template <class Head,class Seco,class... Tail>
void VT3(Head&& head,Seco&& seco,Tail&&... tail){
  seco[head]=IN();
  VT3(head,move(tail)...);
}
 
#define VC1(n,...) V __VA_ARGS__;VT(n,__VA_ARGS__);VT2(__VA_ARGS__); //aaabbbccc
#define VC2(n,...) V __VA_ARGS__;VT(n,__VA_ARGS__);REP(i,n)VT3(i,__VA_ARGS__); //abcabcabc
 
// #include <boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision; // cpp_int
 
#define P pair<ll,ll>
#define V vector<ll>
#define M map<ll,ll>
#define S set<ll>
 
#define pb(a) push_back(a)
#define mp make_pair


int main(){
  CIN(n);
  auto calc = [](int p){
    S s;
    FOR(i,1,p+1)
      if(p%i==0){
        s.insert(p/i);
        s.insert(i);
      }
      return (s.size() == 8);
  };
  int cnt = 0;
  FOR(i,1,n + 1){
    cnt += i%2 && calc(i);
  }
  COUT(cnt);


  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int (i)=0;(i)<(n);i++)
#define INF 1001001001
#define LLINF 1001001001001001001
#define MOD 1000000007
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; }
#define ALL(v) v.begin(), v.end()
typedef long long ll;



int main(){
int n;cin >> n;
int a[n];rep(i,n)cin>>a[i];
bool ok=true;
rep(i,n){
    if(a[i]%2==0){
        if(a[i]%3==0 or a[i]%5==0)ok =true;
        else {
            ok =false;
            break;
        }
    }
}

if(ok)cout << "APPROVED" << endl;
else cout << "DENIED" << endl;
return 0;
}





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

int main(){
	int n, m;
  	cin >> n >> m;
  	vector<int> h(n);
  	rep(i, n) cin >> h[i];	
  	
  	vector<int> ans(n, 1);
  	rep(i, m){
    	int a, b;
      	cin >> a >> b;
      	a--, b--;
      	if(h[a] == h[b]){
          ans[a] = 0;
          ans[b] = 0;
        } else if(h[a] < h[b]) ans[a] = 0;
      	else ans[b] = 0;
    }
  	
  	int cnt = 0;
  	rep(i, n) cnt += ans[i];
  	cout << cnt << endl;
}

Measured memory_bytes: 3972
N = int(input())
A = list(map(int, input().split()))

key = 0
for a in A:
    if abs(a) > abs(key):
        key = a
key_i = A.index(key)

m = 0
ans = []
if key > 0:
    for i in range(N):
        if A[i] < 0:
            m += 1
            A[i] += key
            ans.append([key_i+1, i+1])

    for i in range(1, N):
        if A[i-1] > A[i]:
            A[i] += A[i-1]
            m += 1
            ans.append([i, i+1])

    print(m)
    for x, y in ans:
        print(x, y)

elif key < 0:
    for i in range(N):
        if A[i] > 0:
            m += 1
            A[i] += key
            ans.append([key_i+1, i+1])

    for i in range(N-1, 0, -1):
        if A[i-1] > A[i]:
            A[i-1] += A[i]
            m += 1
            ans.append([i+1, i])

    print(m)
    for x, y in ans:
        print(x, y)

else:
    print(0)

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <algorithm>
#include <map>
#include <math.h>
#include <iomanip>
#include <vector>
#include <queue>
#include <functional>
#include <random>
#include <time.h>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
int main() {
	ll a, b;
	cin >> a >> b;
	cout << (a <= b ? a : a - 1) << endl;
	return 0;
}


Measured memory_bytes: 256
#[allow(unused_macros)]
macro_rules ! read_value {($ next : expr , ($ ($ t : tt ) ,* ) ) => {($ (read_value ! ($ next , $ t ) ) ,* ) } ; ($ next : expr , [$ t : tt ; $ len : expr ] ) => {(0 ..$ len ) . map (| _ | read_value ! ($ next , $ t ) ) . collect ::< Vec < _ >> () } ; ($ next : expr , chars ) => {read_value ! ($ next , String ) . chars () . collect ::< Vec < char >> () } ; ($ next : expr , usize1 ) => {read_value ! ($ next , usize ) - 1 } ; ($ next : expr , $ t : ty ) => {$ next () . parse ::<$ t > () . expect ("Parse error" ) } ; }
#[allow(unused_macros)]
macro_rules ! input_inner {($ next : expr ) => {} ; ($ next : expr , ) => {} ; ($ next : expr , $ var : ident : $ t : tt $ ($ r : tt ) * ) => {let $ var = read_value ! ($ next , $ t ) ; input_inner ! {$ next $ ($ r ) * } } ; }
#[allow(unused_macros)]
macro_rules ! input {(source = $ s : expr , $ ($ r : tt ) * ) => {let mut iter = $ s . split_whitespace () ; let mut next = || {iter . next () . unwrap () } ; input_inner ! {next , $ ($ r ) * } } ; ($ ($ r : tt ) * ) => {let stdin = std :: io :: stdin () ; let mut bytes = std :: io :: Read :: bytes (std :: io :: BufReader :: new (stdin . lock () ) ) ; let mut next = move || -> String {bytes . by_ref () . map (| r | r . unwrap () as char ) . skip_while (| c | c . is_whitespace () ) . take_while (| c |! c . is_whitespace () ) . collect () } ; input_inner ! {next , $ ($ r ) * } } ; }

fn main() {
    input! {
        n: i32,
    }
    println!("{}", n / 3);
}


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

public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String line1 = br.readLine();
        String[] params = line1.split(" ");
        int N = Integer.parseInt(params[0]);
        int X = Integer.parseInt(params[1]);
        int sum = 0;
        int count = 1;
        String[] L = br.readLine().split(" ");
        for(String l : L) {
            sum += Integer.parseInt(l);
            count = sum <= X ? ++count : count;
        }
        System.out.println(count);
    }
}


Measured memory_bytes: 21204
import bisect
for e in iter(input,'0'):
 n=int(e)
 c=[sorted(int(input())for _ in[0]*n)]
 c+=[sorted(set(range(1,2*n+1))-set(c[0]))]
 t=f=0
 while 1:
  x=bisect.bisect(c[t],f)
  if not c[t]:break
  f=c[t].pop(x)if x<len(c[t])else 0
  t^=1
 print(len(c[1]))
 print(len(c[0]))


Measured memory_bytes: 5652
N,M = map(int,input().split())
ret = ['a']*N
for _ in range(M):
  s,c = map(int,input().split())
  if ret[s-1] not in ['a', c]:
    print(-1)
    exit()
  ret[s-1] = c
if ret[0] == 0:
  if N != 1:
    print(-1)
    exit()
ans = ''
for i in range(N):
  if ret[i] != 'a':
    ans += str(ret[i])
  else:
    if i == 0 and N > 1:
      ans += '1'
    else:
      ans += '0'
print(int(ans))

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

int main() {
  int N, Q;
  scanf("%d%d", &N, &Q);
  string S;
  cin >> S;

  vector<int> a(N, 0);
  for (int i = 0; i < N - 1; i++) {
    a.at(i + 1) = a.at(i);
    if (S.at(i) == 'A' && S.at(i + 1) == 'C') a.at(i + 1)++;
  }

  for (int i = 0; i < Q; i++) {
    int left = 0, right = 0;
    scanf("%d%d", &left, &right);
    printf("%d\n", a.at(right - 1) - a.at(left - 1));
  }
  return 0;
}


Measured memory_bytes: 1408
#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 <iomanip>
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <stdlib.h>
#include <stdio.h>
using namespace std;
using Graph = vector<vector<int>>;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
const int INF = 1000000000;
const int MOD = 1000000007;

typedef pair<int, int> P;
int myAbs(int num) {
    if (num > 0)
        return num;
    else
        return -num;
}

long long gcd(long long a, long long b) {
    if (b == 0) return a;
    else return gcd(b, a % b);
}
long long lcm(long long a, long long b) {
    return a * b / gcd(a, b);
}
/*
vector<bool> seen;
void dfs(const Graph& G, int v, int count) {
    seen[v] = true;
    count = 0;
    for (auto next_v : G[v]) {
        if (seen[next_v]) continue;
        if (count > 2) continue;
        count++;
        cout << count << ":" << next_v << endl;
        dfs(G, next_v, count);
    }
}*/

typedef pair<int, int> P;

int main() {
    int N; cin >> N;
    vector<int> retu(N);
    for (int i = 0; i < N; i++) cin >> retu.at(i);
    int Q; cin >> Q;
    vector<int> wa(Q);
    for (int i = 0; i < Q; i++) cin >> wa.at(i);
    bool ans = false;
    set<int> S;

    for (int tmp = 0; tmp < (1 << N); tmp++) {
        bitset<20> B(tmp);
        int sum = 0;
        for (int k = 0; k < N; k++) {
            if (B.test(k)) sum += retu.at(k);
        }
        S.insert(sum);
    }
    for (int i = 0; i < Q; i++) {
        if (S.count(wa.at(i))) cout << "yes" << endl;
        else cout << "no" << endl;
    }
}



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

string s,t;

int main(){
    ios_base::sync_with_stdio(0);
    //freopen("input.txt","r",stdin);

    cin>>s>>t;
    int n = s.size();
    int res=0;
    for(int i=0;i<n;i++)
    {
        res += (s[i]!=t[i]);
    }
    cout<<res;
}


Measured memory_bytes: 3808
import sys


def solve():
    input = sys.stdin.readline
    mod = 10 ** 9 + 7
    n, a, b = list(map(int, input().rstrip('\n').split()))
    d, m = divmod(n, (a + b))
    print(d * a + min(m, a))


if __name__ == '__main__':
    solve()


Measured memory_bytes: 38384
// Copyright 2020 yaito3014
#include <bits/stdc++.h>

int main() {
  using namespace std;
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  bool ok = true;
  set<string> s;
  char c;
  for (int i = 0; i < N; ++i) {
  	string W;
  	cin >> W;
  	if (i > 0 && (c != W.front() || s.find(W) != s.end())) {
  		ok = false;
  		break;
  	}
  	s.insert(W);
  	c = W.back();
  }
  cout << (ok ? "Yes" : "No") << '\n';
}


Measured memory_bytes: 3648
from math import floor,ceil,sqrt,factorial,log
from collections import Counter, deque
from functools import reduce
import numpy as np
def S(): return input()
def I(): return int(input())
def MS(): return map(str,input().split())
def MI(): return map(int,input().split())
def FLI(): return [int(i) for i in input().split()]
def LS(): return list(MS())
def LI(): return list(MI())
def LLS(): return [list(map(str, l.split() )) for l in input()]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def LLSN(n: int): return [LS() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]

def is_prime(n):
    if n == 1:
        return False
    for i in range(2,int(n**0.5)+1):
        if n % i == 0:
            return False
    return True

x = I()

max = 10**9

for i in range(x, max):
    if is_prime(i):
        print(i)
        break


Measured memory_bytes: 12184
#include <iostream>
#include <vector>
#include<list>
#include <algorithm>
#include <string>
#include <math.h>
#include<map>
#include <utility>
#include <iomanip>
#include<queue>
#include<set>
using namespace std;
#define REP(i,k,n) for(int i=k;i<n;i++)
 
//#define INF 1844674407370955161
typedef long long int ll;
#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))
#define MOD 1000000007

template<typename T>
std::vector<T> enum_div(T n)//nの約数を列挙
{
	std::vector<T> ret;
	for(T i=1 ; i*i<=n ; ++i)
	{
		if(n%i == 0)
		{
			ret.push_back(i);
			if(i!=1 && i*i!=n)
			{
				ret.push_back(n/i);
			}
		}
	}
	return ret;
}


int N;
string S;
vector<vector<int>> li;
vector<int> siz;
bool judge(int len){
	map<string,int> s;
	string now=S.substr(0,len);
	REP(i,0,N-len+1){
		if(s.find(now)!=s.end()){
			int t=s.find(now)->second;
			if(t+len<=i){
				return true;
			}
		}else{
			s[now]=i;
		}
		now=S.substr(i+1,len);
	}
	return false;
}



template< typename T >
struct edge {
  int src, to;
  T cost;

  edge(int to, T cost) : src(-1), to(to), cost(cost) {}

  edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}

  edge &operator=(const int &x) {
    to = x;
    return *this;
  }

  operator int() const { return to; }
};

template< typename T >
using Edges = vector< edge< T > >;
template< typename T >
using WeightedGraph = vector< Edges< T > >;
using UnWeightedGraph = vector< vector< int > >;
template< typename T >
using Matrix = vector< vector< T > >;

template< typename T >
vector< T > dijkstra(WeightedGraph< T > &g, int s) {
  const auto INF = numeric_limits< T >::max();
  vector< T > dist(g.size(), INF);

  using Pi = pair< T, int >;
  priority_queue< Pi, vector< Pi >, greater< Pi > > que;
  dist[s] = 0;
  que.emplace(dist[s], s);
  while(!que.empty()) {
    T cost;
    int idx;
    tie(cost, idx) = que.top();
    que.pop();
    if(dist[idx] < cost) continue;
    for(auto &e : g[idx]) {
      auto next_cost = cost + e.cost;
      if(dist[e.to] <= next_cost) continue;
      dist[e.to] = next_cost;
      que.emplace(dist[e.to], e.to);
    }
  }
  return dist;
}
int main()
{
	int N;
	string S;
	cin>>N>>S;

	bool dp1[N][10];
	bool dp2[N][10];
	REP(i,0,10){
		dp1[0][i]=false;
		dp2[N-1][i]=false;
	}
	REP(i,0,N){	
		REP(j,0,10){
			if(i>=1){
			dp1[i][j]=dp1[i-1][j];
			}
		}
		int s=S[i]-'0';
		dp1[i][s]=true;
	}
	for(int i=N-1;i>=0;i--){
		REP(j,0,10){
			if(i<=N-2){
			dp2[i][j]=dp2[i+1][j];
			}
		}
		int s=S[i]-'0';
		//cout<<s<<endl;
		dp2[i][s]=true;
	}
	bool table[1000];
	REP(i,0,1000){
		table[i]=false;
	}
	REP(i,1,N-1){
		REP(j,0,10){
			REP(k,0,10){
				if(dp1[i-1][j]&&dp2[i+1][k]){
					int s=S[i]-'0';
					//cout<<j*100+s*10+k<<endl;
					table[j*100+s*10+k]=true;
				}
			}
		}
	}
	int ans=0;
	REP(i,0,1000){
		if(table[i]){
			ans++;
			//cout<<i<<endl;
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 896
import java.util.*

fun main(args: Array<String>) {
    val scanner = Scanner(System.`in`)
    var str = scanner.nextLine()
    val q = scanner.nextInt()
    (1..q).forEach {
        val command = scanner.next()
        str = when(command) {
            "print" -> {
                val a = scanner.nextInt()
                val b = scanner.nextInt()
                println(str.substring(a, b + 1))
                str
            }
            "reverse" -> {
                val a = scanner.nextInt()
                val b = scanner.nextInt()
                str.substring(0, a) + str.substring(a, b + 1).reversed() + str.substring(b + 1)
            }
            "replace" -> {
                val a = scanner.nextInt()
                val b = scanner.nextInt()
                val p = scanner.next()
                str.substring(0, a) + p + str.substring(b + 1)
            }
            else -> str
        }
    }
}


Measured memory_bytes: 29964
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <queue>
#include <stack>

using namespace std;

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

const ll mod = 1000000007;

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

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

  vector<int> distU(n), distV(n);

  queue<Pii> que;
  vector<bool> visited(n);
  que.emplace(u, 0);
  while (!que.empty()) {
    auto now = que.front();
    que.pop();
    if (visited[now.first]) continue;
    visited[now.first] = true;
    distU[now.first] = now.second;
    for (auto &x: edge[now.first]) {
      if (visited[x]) continue;
      que.emplace(x, now.second + 1);
    }
  }

  visited = vector<bool>(n);
  que.emplace(v, 0);
  while (!que.empty()) {
    auto now = que.front();
    que.pop();
    if (visited[now.first]) continue;
    visited[now.first] = true;
    distV[now.first] = now.second;
    for (auto &x: edge[now.first]) {
      if (visited[x]) continue;
      que.emplace(x, now.second + 1);
    }
  }

  int ans = 0;
  int uNow = u, uLast = u, vNow = v, vLast = v;
  while (uNow != vNow) {
    uLast = uNow;
    vLast = vNow;
    for (auto &x: edge[uNow]) {
      if (distV[x] < distV[uNow]) {
        uNow = x;
        break;
      }
    }
    if (uNow == vNow) break;
    for (auto &x: edge[vNow]) {
      if (distU[x] < distU[vNow]) {
        vNow = x;
        break;
      }
    }
    ans++;
  }

  int banVertex = vNow;
  uNow = uLast;
  vNow = vLast;

  int longest = 0;
  visited = vector<bool>(n);
  visited[banVertex] = true;
  que.emplace(uNow, 0);
  while (!que.empty()) {
    auto now = que.front();
    que.pop();
    if (visited[now.first]) continue;
    visited[now.first] = true;
    if (now.second > longest) longest = now.second;
    for (auto &x: edge[now.first]) {
      if (visited[x]) continue;
      que.emplace(x, now.second + 1);
    }
  }

  ans += longest;

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 6784
#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>;
const ll INF = ll(1e18)+1;

int main(){
  int n;
  cin >> n;
  string s;
  cin >> s;
  vector<int> a(n);
  rep(i,n){
    if(s[i]=='R') a[i] = 0;
    if(s[i]=='G') a[i] = 1;
    if(s[i]=='B') a[i] = 2;
  }
  vector<int> cnt(3);
  rep(i,n) cnt[a[i]]++;
  ll ans = 1;
  rep(i,3) ans *= cnt[i];
  rep(j,n){
    rep(i,j){
      int k = (j-i) + j;
      if(k<n){
        if(a[i]==a[j]) continue;
        if(a[j]==a[k]) continue;
        if(a[k]==a[i]) continue;
        ans--;
      }
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 3596
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
const int INF=1145141919,MOD=1e9+7;
const int64_t LINF=8931145141919364364,LMOD=998244353;
// const int dy[]={0,-1,0,1,1,-1,-1,1};
// const int dx[]={1,0,-1,0,1,1,-1,-1};

int main() {
	int a[3]; rep(i,3) cin >> a[i];
	int sum = 0;
	rep(i,3) sum += a[i];
	string ans = "win";
	if(sum >= 22) ans = "bust";
	cout << ans << '\n';
	return 0;
}

Measured memory_bytes: 256
'use strict'

const main = (input) => {
    const N = input.split('\n')[0]
    const sum = N.split('').map(i => parseInt(i)).reduce((t, c) => t + c)
    if(N % sum === 0){
        console.log('Yes')
    }else{
        console.log('No')
    }
}

main(require('fs').readFileSync('/dev/stdin', 'utf-8'))

Measured memory_bytes: 7372
#include <bits/stdc++.h>
using namespace std;
int main() {

  int n,m;
  cin >> n >> m;
  vector<vector<char>> A(n,vector<char>(n));
  vector<vector<char>> B(m,vector<char>(m));
  
  for (int i=0; i<n; i++) {
    for (int j=0; j<n; j++) {
      cin >> A.at(i).at(j);
    }
  }
  for (int i=0; i<m; i++) {
    for (int j=0; j<m; j++) {
      cin >> B.at(i).at(j);
    }
  }
  
  for (int i=0; i<=n-m; i++) {
    for (int j=0; j<=n-m; j++) {
      int count = 0;
      for (int k=0; k<m; k++) {
        for (int l=0; l<m; l++) {
          if (A.at(i+k).at(j+l) == B.at(k).at(l)) {
            count++;
            if (count >= m*m) {
              cout << "Yes" << endl;
              return 0;
            }
          }
        }
      }
    }
  }
  cout << "No" << endl;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		String[] s = new String[n];
		int m = Integer.MAX_VALUE;
		for (int i = 0; i < s.length; i++) {
			s[i] = sc.next() + "," + (m - sc.nextInt()) + "," + (i + 1);
		}
		Arrays.sort(s);
		for (String a : s) {
			System.out.println(a.split(",")[2]);
		}
		
	}
}


Measured memory_bytes: 21844
//#pragma GCC optimize ("Ofast")
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC target("avx,avx2,fma")


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
#define pb push_back
#define F first
#define S second
#define ins insert
#define mp make_pair
#define bit __builtin_popcount
#define md (l + ((r - l) / 2))
#define all(x) x.begin(),x.end()
//#define all(x , n) x+1,x+n+1
#define eb emplace_back
#define ub upper_bound
#define lb lower_bound
#define sz(x) (int)x.size()
#define ios ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define file(s) if (fopen(s".in", "r")) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout)

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;


using ll = long long;

//#define int ll

const int N = 1e7+54, mod = 1e9 + 7, mod1 = 998244353;
const int MAX = 1e5 + 11 , T = 2000;
const int INF1 = 2e9 + 11;
const ll INF2 = 2e18 + 11;
const long double INF3 = 1e8 + 11;
const int base = 500;
const int P = 31;
const int dx[] = {1, -1, 0, 0, 1, 1, -1, -1};
const int dy[] = {0, 0, 1, -1, 1, -1, 1, -1};
const int LOG = 20;
const double EPS = 1e-4;
const double PI = acos(-1.0);

template<typename T> using ordered_set = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }


typedef pair <int, int> pii;        // #include <ext/pb_ds/assoc_container.hpp>
typedef pair <ll, ll> pll;         // #include <ext/pb_ds/tree_policy.hpp>
typedef vector <int> vi;          // #include <ext/rope>
                // #include <ext/rope>
                                 // #include <ext/rope>
bool prime(int n) {             // template<typename T> using ordered_set = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>;
    for(int i=2;i<=sqrt(n);i++){
        if(n%i==0){return 0;}
    }return 1;}
bool query = 0;
ll bp(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
///////////////////////////////////////////////////////////

void solve() {
    string s;
    cin >> s;
    cout << s[0] << s[1] << s[2];
}

/*
8 1
1 10 1 1 1 2 8 2
1 1
*/

main() {
    ios;
    int tt = 1;
    if(query)
        cin >> tt;
    while(tt --) {
        solve();
    }
    return 0;
}


Measured memory_bytes: 3672
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <bits/stdc++.h>
/*#pragma GCC optimize("Ofast","unroll-loops","omit-frame-pointer","inline") //Optimization flags
#pragma GCC option("arch=native","tune=native","no-zero-upper") //Enable AVX
#pragma GCC target("avx2")  //Enable AVX*/

using namespace std;

using ll = long long;

#define mp make_pair

const int p = 786433;


int mul(int a, int b) {
    return (1LL * a * b) % p;
}

int add(int a, int b) {
    int s = (a+b);
    if (s>=p) s-=p;
    return s;
}

int sub(int a, int b) {
    int s = (a+p-b);
    if (s>=p) s-=p;
    return s;
}

int po(int a, int deg)
{
    if (deg==0) return 1;
    if (deg%2==1) return mul(a, po(a, deg-1));
    int t = po(a, deg/2);
    return mul(t, t);
}

int inv(int n)
{
    return po(n, p-2);
}

/*struct DSU {
    vector<int> sz;
    vector<int> parent;

    void make_set(int v) {
        parent[v] = v;
        sz[v] = 1;
    }

    int find_set(int v) {
        if (v == parent[v])
            return v;
        return parent[v] = find_set(parent[v]);
    }

    void union_sets(int a, int b) {
        a = find_set(a);
        b = find_set(b);
        if (a != b) {
            if (sz[a] < sz[b])
                swap(a, b);
            parent[b] = a;
            sz[a] += sz[b];
        }
    }

    DSU(int n) {
        sz.resize(n);
        parent.resize(n);
        for (int i = 0; i < n; i++) make_set(i);
    }
};*/

/*const int N = 1000000;

vector<int> facs(N), invfacs(N);

void init()
{
    facs[0] = 1;
    for (int i = 1; i<N; i++) facs[i] = mul(facs[i-1], i);
    invfacs[N-1] = inv(facs[N-1]);
    for (int i = N-2; i>=0; i--) invfacs[i] = mul(invfacs[i+1], i+1);
}

int C(int n, int k)
{
    return mul(facs[n], mul(invfacs[k], invfacs[n-k]));
}*/



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

    int n;
    cin>>n;
    string s;
    cin>>s;
    vector<int> a(n);
    for (int i = 0; i<n; i++) a[i] = s[i]-'1';

    //for (auto it: a) cout<<it<<' ';

    int tot = 0;
    for (int i = 0; i<n; i++) if (((n-1)&i) == i) tot+=a[i];
    if (tot%2) {cout<<1; return 0;}
    bool even = true;
    for (int i = 0; i<n; i++) if (a[i]==1) even = false;
    if (!even) {cout<<0; return 0;}
    tot/=2;
    cout<<2*(tot%2);

}




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

int main(){
	string S;
	cin >> S;
	vector<int> alp(26);
	rep(i,S.size()) alp[S[i]-'a']++;
	rep(i,26) if (alp[i] == 0) {
		S += (char)('a'+i);
		cout << S << endl;
		return 0;
	}

	for (int i = S.size()-1; i >0; i--) {
		if (S[i-1] > S[i]) continue;
		for (int j = S.size()-1; j >i-1; j--) {
			if (S[i-1] > S[j]) continue;
			swap(S[i-1], S[j]);
			break;
		}
		S = S.substr(0, i);
		cout << S << endl;
		return 0;
	}
	cout << -1 << endl;

	return 0;
}


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

#define rep(i,n) for(long long i=0; i<(long long)(n);i++)
#define rep2(i,s,n) for(long long i=(s); i<(long long)(n);i++)
#define mod 1000000007
typedef long long ll;

int main() {
    int n,x;cin>>n>>x;
    
    vector<int>l(n);
    rep(i,n){
        cin>>l[i];
    }
    int ans=1,d=0;

    rep(i,n){
        d=d+l[i];
        if(d>x){
            break;
        }
        ans++;
    }

    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string a;
    cin>>a;
    for(int i=0;i<a.size();i++)
    {
        if(a[i]=='1') a[i]='9';
         else if(a[i]=='9') a[i]='1';
        cout<<a[i];
    }
    cout<<endl;
    return 0;
}

Measured memory_bytes: 256
from collections import Counter


def main():
    N = int(input())
    counter = Counter(map(int, input().split()))

    a = 0
    b = 0

    def sort_func(t):
        return t[0]
    for length, n in sorted(counter.items(),
                            key=sort_func,
                            reverse=True):
        if n < 2:
            continue
        if a == 0:
            a = length
            if n >= 4:
                b = length
                break
        else:
            b = length
            break
    print(a * b)

if __name__ == '__main__':
    main()


Measured memory_bytes: 24224
package main

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

const INPUT_MAX = 1000000000

func main() {
	sc := bufio.NewScanner(os.Stdin)
	for sc.Scan() {
		l := sc.Text()
		h := strings.Split(l, " ")
		o := [2]int{INPUT_MAX, INPUT_MAX}

		// Only check all odd number
		for _, tmp := range h {
			n, _ := strconv.Atoi(tmp)
			if n%2 == 0 {
				o = [2]int{}
				break
			}

			if len(o) < 2 {
				o[len(o)-1] = n
			} else {
				if o[0] < o[1] {
					if o[1] > n {
						o[1] = n
					}
				} else {
					if o[0] > n {
						o[0] = n
					}
				}
			}
		}

		if len(o) == 2 {
			fmt.Println(o[0] * o[1])
		} else {
			fmt.Println(0)
		}
	}
}

Measured memory_bytes: 640
#include<stdio.h>
#include<stdlib.h>
#include<math.h>

typedef long long int int64;

#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define ABS(a) ((a)>(0)?(a):-(a))

void run(void){
  int a,b;
  scanf("%d%d",&a,&b);
  printf("%s\n",a*b%2==0?"No":"Yes");
}

int main(void){
  run();
  return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<stdlib.h>
#include<vector>
#include<algorithm>
#include<stdio.h>
#include<string>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<limits.h>
#define rep(i,n) for(ll i = 0; i < (ll)n; i++)
#define swap(a,b) a^=b;b^=a;a^=b;
#define chmax(a,b) {if(a < b) a = b;}
#define chmin(a,b) {if(a > b) a = b;}
using namespace std;
typedef long long ll;
ll gcd(ll, ll);
vector<bool> to_binary(int);
int sum(vector<int>);
int min(vector<int>);
int max(vector<int>);
ll nCr(ll n, ll r);

const ll INF = 1LL << 60;

ll nCr(ll n, ll r) {
 ll res = 1;
 for (int i = 0; i < r; i++) {
   res *= (n - i);
 }
 for (int i = 1; i <= r; i++) {
   res /= i;
 }
 return res;
}

int vsum(vector<int> v) {
 int res = 0;
 for (auto it = v.begin(); it != v.end(); it++)
   res += *it;
 return res;
}
int vmin(vector<int> v) {
 int min = INT32_MAX;
 for (auto it = v.begin(); it != v.end(); it++)
   min = std::min(min, *it);
 return min;
}
int vmax(vector<int> v) {
 int max = 0;
 for (auto it = v.begin(); it != v.end(); it++)
   max = std::max(max, *it);
 return max;
}

ll gcd(ll A, ll B) {
 int r = A % B;
 while (r != 0) {
   A = B;
   B = r;
   r = A % B;
 }

 return B;
}

vector<bool> to_binary(int x) {
 vector<bool> res;
 while (x != 0) {
   res.push_back(x % 2);
   x /= 2;
 }
 return res;
}


typedef tuple<ll,ll> mtp;

bool mycomp(mtp x, mtp y) {
	return get<0>(x) < get<0>(y);
}


int main(void) {
  ll N,M;
  cin >> N >> M;

  vector<mtp> Stores(N);
  int a,b;
  rep(i,N){
    cin >> a >> b;
    Stores[i] = (mtp)make_pair(a,b);
  }

  sort(Stores.begin(),Stores.end(),mycomp);

  ll ans = 0;
  for(auto v : Stores) {
    ans += get<0>(v) * std::min(get<1>(v),M);
    M -= get<1>(v);

    if(M <= 0) break;
  }

  cout << ans << endl;
}


Measured memory_bytes: 1792
#include<iostream>

using namespace std;

#define IOS ios::sync_with_stdio(0);cin.tie(0);

int main(){
	long long int a,b;
	IOS;
	while(cin>>a>>b){
		if((a+b)%2 == 0){
			cout<<(a+b)/2<<endl;
		}
		else{
			cout<<(a+b)/2+1<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include <atcoder/all>
#define ll long long int
#define MOD 1000000007
#define P pair<ll,ll>
#define INF 1000000000000000000

//using namespace atcoder;
using namespace std;

int main(void){
  int x[5];
  for (int i = 0; i < 5; i++){
    cin >> x[i];
  }

  for (int i = 0; i < 5; i++){
    if (x[i] == 0)
      cout << i + 1 << endl;
  }

  return 0;
}


Measured memory_bytes: 3572
#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>;
 
string f(ll n) {
  if (n == 0) return "";
  // 扱いやすいようにデクリメントして
  n--;
  return f(n/26) + string(1,'a'+n%26);
}
 
int main() {
  ll n;
  cin >> n;
  cout << f(n) << endl;
  return 0;
}

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

const int MAX = 100010;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i-1] * i % MOD;
		inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
		finv[i] = finv[i-1] * inv[i] % MOD;
	}
}

long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n-k] % MOD) % MOD;
}

int main() {
	int n;
	cin >> n;
	vector<int> a(n+1);
	for (int i = 0; i < n+1; i++) {
		cin >> a[i];
		a[i]--;
	}
	
	vector<int> pos(n, -1);
	int pos1, pos2;
	for (int i = 0; i < n+1; i++) {	
		if (pos[a[i]] == -1) {
			pos[a[i]] = i;
		}
		else {
			pos1 = min(i, pos[a[i]]);
			pos2 = max(i, pos[a[i]]);
			break;
		}
	}

	COMinit();
	cout << n << endl;
	for (int i = 0; i <= n-1; i++) {
		long long ans = COM(n+1, i+2);
		int num = pos1 + n - pos2;
		if (num >= i+1)
			ans -= COM(num, i+1);
		if (ans < 0)
			ans += MOD;
		cout << ans << endl;
	}
}		

Measured memory_bytes: 4352
def ini(): return int(input())
def inli(): return list(map(int, input().split()))
def inf(): return float(input())
def inlf(): return list(map(float, input().split()))
def inl(): return list(input())
def pli(): return "".join(list(map(str, ans)))

n =ini()
a=[]
b = [0 for i in range(n)]
for i in range(n):
    a.append(ini())

j = 1
ans = 0
while j !=2:
    if b[j-1] !=0:
        ans = -1
        break
    ans +=1
    b[j-1] +=1
    j = a[j-1]

print(ans)

Measured memory_bytes: 7860
#![allow(unused_imports)]
use std::cmp::*;
use std::collections::*;
use itertools::Itertools;
use proconio::{input, marker::*};
use superslice::*;
fn main() {
    input! {
        n: i64,
        k: i64,
    }
    let divisor = 10i64.pow(9)+7;

    let mut sums = Vec::new();
    sums.push(0);
    for i in 1..=n+1 {
        let min = i*(i-1)/2;
        let max = i*(n-i+1 + n)/2;
        let sum = (max - min + 1) % divisor;
        sums.push(sum);
    }

    let mut total = 0;
    for i in k..=n+1 {
        total += sums[i as usize];
        total %= divisor;
    }
    println!("{}", total);

}


Measured memory_bytes: 3684
#pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using P = pair<ll,ll>;
using um = unordered_map<ll,ll>;
#define fl cout<<flush;
#define endl '\n'
template <typename T> inline void prt(T v){cout<<v<<'\n';}
template <typename T> inline bool chmax(T &a, const T &b){if (a<b){a=b;return 1;}return 0;}
template <typename T> inline bool chmin(T &a, const T &b){if (a>b){a=b;return 1;}return 0;}
const ll INF=1LL<<60;
const ll MOD=1e9+7;
const ll MOD2=998244353;
const ld pi=3.14159265358979323846;
const ld eps=1e-10;

signed main(void){
    cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    ll K;
    cin >> K;
    vector<ll> P(N,0);
    for(ll i=0;i<N;++i)cin>>P[i];
    sort(P.begin(), P.end());
    ll ans=0;
    for(ll i=0;i<K;++i)ans+=P[i];
    prt(ans);

    return 0;
}



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

int main(){

    int l,r;
    cin >> l >> r;
    
    int ans = r;

    if(l < 10){
        ans += 100 * (10 - l);
    }

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




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

int main(){
  ll n;
  cin >> n;
  map<ll,ll> c;
  for(ll i=0; i<n; i++){
    ll tmp;
    cin >> tmp;
  	if(c.count(tmp) != 0){
      cout << "NO" << endl;
      return 0;
    }
    c[tmp] = 1;
  }
  cout << "YES" << endl;
}


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

#define ull unsigned long long
#define endl '\n'
#define ll long long
const int N = 1e5 + 5;
ll a[N];
int main(){
        ios_base::sync_with_stdio(false);
        cin.tie(0);
        cout.tie(0);
        //freopen("test.txt", "r", stdin);
        ll n, m;
        cin >> n >> m;
        ll cnt = 0, need;
        for (int i = 1; i <= n; i++){
                cin >> a[i];
                a[i] = a[i] / 2;
                if (i == 1){
                        need = a[1];
                        while (a[i] % 2 == 0){
                                cnt++;
                                a[i] = a[i] / 2;
                        }
                }
        }
        for (int i = 2; i <= n; i++){
                ll cur = 0;
                need = need * a[i] / __gcd(need, a[i]);
                while (a[i] % 2 == 0) {
                        cur++;
                        a[i] /= 2;
                }
                if (cur != cnt){
                        cout << 0; return 0;
                }
        }
        cout << m / need - m / (need * 2);
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back((a))
#define all(x) (x).begin(),(x).end()
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

#define INF 2147483600
#define long long long // for codeforces

int cnt[510][510];

int main(){
  int h,w;
  while(cin>>h>>w, h|w){
    vector<string> vec(h);
    rep(i,h) cin>>vec[i];
    fill(cnt[0], cnt[h], 0);
    rep(j,w) if(vec[0][j]=='.') cnt[0][j]=1;
    repl(i,1,h)rep(j,w){
      if(vec[i][j]=='.') cnt[i][j]=cnt[i-1][j]+1;
    }

    int res=0;
    rep(i,h){
      stack<pair<int,int>> s;
      s.push(mp(-1,-1)); //???????????§?¨?
      rep(j,w+1){
        if(s.top().fi < cnt[i][j]){
          s.push(mp(cnt[i][j], j));
        } else {
          int pos = j;
          while(!s.empty() && cnt[i][j] < s.top().fi){
            auto p = s.top(); s.pop();
            res = max(res, p.fi*(j-p.se));
            pos = p.se;
          }
          s.push(mp(cnt[i][j], pos));
        }
      }
    }
    cout << res << endl;

  }

  return 0;
}

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

int main(){
  int i,j,k,n,x,count = 0;

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

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
//map<key,value>


int main(){
  int n,te;
  cin >> n;
  int a[n];
  vector<int> m(100001,0);
  for(int i=0;i<n;i++)cin >> a[i];
  for(int i=0;i<n;i++){
    m[a[i]+2]++;
    m[a[i]]++;
    m[a[i]+1]++;
  }
  sort(m.begin(),m.end());
  cout << m[100000];
}

Measured memory_bytes: 1024
# coding: utf-8

def generator():
    for s in input():
        yield s

def main():
    N = int(input())

    slimes = 0
    pre_slime = None
    for s in generator():
        if s == pre_slime:
            continue
        slimes += 1
        pre_slime = s
    print(slimes) 

main()

Measured memory_bytes: 3316
n, mw = gets.chomp.split.map(&:to_i)
sum = []
w, v = gets.chomp.split.map(&:to_i)
v_sum = v
v.times do |i|
  sum[i+1] = w
end

(n-1).times do
  w, v = gets.chomp.split.map(&:to_i)
  v_sum += v
  v_sum.downto(1) do |i|
    if !sum[i] && i > v
      sum[i] = sum[i-v] + w
    elsif i > v
      sum[i] = sum[i-v] + w if sum[i-v] + w < sum[i]
    elsif !sum[i]
      sum[i] = w
    else
      sum[i] = w if w < sum[i]
    end
  end
end

#p sum

v_sum.downto(1) do |i|
  if sum[i] <= mw
    puts i
    exit
  end
end


Measured memory_bytes: 2684
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
#include <cctype>
using namespace std;
int n, a, b, c;
int l[10];
int ans = 1000000007;
void dfs(vector<int>v) {
	if (v.size() == n) {
		int sa = 0, sb = 0, sc = 0, co = 0;
		bool bo = false, bo1 = false, bo2 = false;
		for (int i = 0; i < n; i++) {
			if (v[i] == 1) {
				sa += l[i];
				if (bo) {
					co += 10;
				}
				bo = true;
			}
			if (v[i] == 2) {
				sb += l[i];
				if (bo1) {
					co += 10;
				}
				bo1 = true;
			}
			if (v[i] == 3) {
				sc += l[i];
				if (bo2) {
					co += 10;
				}
				bo2 = true;
			}
		}
		if (bo && bo1 && bo2) {
			if (abs(sa - a) + abs(sb - b) + abs(sc - c) + co < ans) {
				ans = abs(sa - a) + abs(sb - b) + abs(sc - c) + co;
			}
		}
		return;
	}
	for (int i = 0; i < 4; i++) {
		v.emplace_back(i);
		dfs(v);
		v.pop_back();
	}
}
int main() {
	cin >> n >> a >> b >> c;
	for (int i = 0; i < n; i++) {
		cin >> l[i];
	}
	vector<int> vec;
	dfs(vec);
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
#define ll long long
#define rep(i,a,b) for(i=a;i<b;i++)
#define pb push_back
#define all(v) v.begin(),v.end()
#define F first
#define S second
#define vi vector < ll  int >
#define CLR(a) memset((a),0,sizeof(a))
#define mp make_pair
#define hell 1000000007`
using namespace std;
vector < int > g[200005];
vector < int > cnt(200005),fans(200005);

 void bfs()
   {
       int s,i;
       bool vis[200005];
       memset(vis,false,sizeof(vis));
       queue < int > qu;
       qu.push(1);
       //fans[1]=cnt[1];
       //cout<<fans[1]<<" ";
       vis[1]=true;
       while(!qu.empty())
       {

           int x=qu.front();
           qu.pop();
           rep(i,0,g[x].size())
              {    if(!vis[g[x][i]]){
                  cnt[g[x][i]]+=(cnt[x]);
                //  cout<<fans[g[x][i]]<<" i ";
                  vis[g[x][i]]=true;
                  qu.push(g[x][i]);
              }
              }
       }


   }
void solve()
{
 ll i,j,k,y=0,ans=0,n,m=0,x,z,a,b,q;
 cin>>n>>q;
 rep(i,0,n-1)
 {
     cin>>a>>b;
     g[a].pb(b);
     g[b].pb(a);
 }
 while(q--)
 {
     cin>>a>>b;
    cnt[a]+=b;
 }
 //rep(i,0,n+1) cout<<cnt[i]<<" ";
  bfs();
  rep(i,1,n+1) cout<<cnt[i]<<" ";
}



   signed main()
        {
            ios::sync_with_stdio(false);
            cin.tie(0);
            cout.tie(0);
            int t=1;
            //cin>>t;
            while(t--)
             solve();
        }


Measured memory_bytes: 16500
n = int(input())
ga, sa, ba = map(int, input().split())
gb, sb, bb = map(int, input().split())
dp = [0] * (n + 1)
for i in range(n):
    if i + ga <= n:
        dp[i + ga] = max(dp[i + ga], dp[i] + gb)
    if i + sa <= n:
        dp[i + sa] = max(dp[i + sa], dp[i] + sb)
    if i + ba <= n:
        dp[i + ba] = max(dp[i + ba], dp[i] + bb)
ans = 0
for i in range(n + 1):
    ans = max(ans, dp[i] + n - i)
p = min(25000024, ans)
dp = [0] * (p + 1)
for i in range(p):
    if i + gb <= p:
        dp[i + gb] = max(dp[i + gb], dp[i] + ga)
    if i + sb <= p:
        dp[i + sb] = max(dp[i + sb], dp[i] + sa)
    if i + bb <= p:
        dp[i + bb] = max(dp[i + bb], dp[i] + ba)
res = 0
for i in range(p + 1):
    res = max(res, dp[i] + ans - i)
print(res)


Measured memory_bytes: 230680
#include <bits/stdc++.h>
using namespace std;
 
 
typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef long double ld;
 
typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
typedef vector<int>::iterator vit;
 
const int INF = 1e9 + 7;
const int MOD = 1e9 + 7;
const int MAXN = 1e6 + 3;
 
#define _  %  MOD
#define __ %= MOD
 
#define      each(it,s)        for(auto it = s.begin(); it != s.end(); ++it)
#define      sortA(v)          sort(v.begin(), v.end())
#define      sortD(v)          sort(v.begin(), v.end(), greater<auto>())
#define      fill(a)           memset(a, 0, sizeof (a))
 
#define      swap(a,b)        {a=a+b;b=a-b;a=a-b;}
#define      rep(i, n)         for(ll i = 0; i < (n); ++i)
#define      repA(i, a, n)     for(ll i = a; i <= (n); ++i)
#define      repD(i, a, n)     for(ll i = a; i >= (n); --i)
#define watch(x) cout << (#x) << " is " << (x) <<endl
 
#define fi first
#define se second
#define mp make_pair
#define pb push_back
 
#define fbo find_by_order
#define ook order_of_key
 
ll gcd(ll a,ll b){if(b==0) return a; else return gcd(b,a%b);}
ll power(ll x,ll y){ll res=1; while(y>0){if(y&1) res=res*x;y=y>>1;x=x*x;}return res;} // modular exponent
 
int main()
{
    ios_base::sync_with_stdio(false); // don't use printf and scanf
    cin.tie(NULL); // cout<<fixed<<setprecision
   	string s,t;
   	cin>>s>>t;
	ll n=s.length();
	ll l=t.length();
	ll ans=1e18;
	rep(i,n-l+1)
	{
		string temp=s.substr(i,l);
		ll val=0;
		rep(j,temp.length()) if(temp[j]!=t[j]) val++;
		ans=min(ans,val);
	}	
	cout<<ans<<'\n';
	return 0;
}
// JUST ASK YOURSELF DID YOU GIVE YOUR BEST ? ISSE ZYADA
// KUCH KAR BHI NAHI SAKTE !! ENJOY AND GIVE YOUR BEST!!



Measured memory_bytes: 3648
## import sys

class queue:
    def __init__(self, length):
        self.max = length + 2
        self.v = list(range(self.max))
        self.head = 0
        self.tail = 0
        
    def enqueue(self, x):
        self.v[self.tail] = x
        self.tail = (self.tail+1) % self.max
        
    def dequeue(self):
        a = self.v[self.head]
        self.head = (self.head+1) % self.max
        
        return a
    
    
    def isEmpty(self):
        return self.head == self.tail
    
    def isFull(self):
        return (self.tail - self.head) == self.length
    
    
def main():
    n, q = list(map(int,input().split()))
    que = queue(n)
    for _ in range(n):
        lis = input().split()
        lis[1] = int(lis[1])
        
        que.enqueue(lis)
    
    time = 0
    while n > 0:
        now = que.dequeue()
        if now[1] > q:
            now[1] -= q
            que.enqueue(now)
            time += q
            
        else:
            time += now[1]
            print(now[0], time)
            n -= 1
            
if __name__ == '__main__':
    main()


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

// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

// forループ
#define REP(i,n) for(ll i=0; i<(ll)(n); ++i)

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

// グラフ表現
using Graph = vector<vector<int>>;

// グラフの辺表現
using Edge = map<pair<int,int>,int>;

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

// 最大公約数
ll gcd(ll a,ll b){
   if (a%b == 0) return(b);
   else return(gcd(b, a%b));
}

// 最小公倍数
ll lcm(ll a, ll b){
    return a/gcd(a, b) * b;
}

int main()
{
    cout << fixed << setprecision(15);
    ll D, T, S;
    cin >> D >> T >> S;

    if(D <= T*S){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 3628
#include <cstdio>

int main(){
  int a,b,c,n=0,m=0;
  while(~scanf("%d,%d,%d",&a,&b,&c)){
    if(a*a+b*b==c*c) n++;
    if(a==b) m++;
  }
  printf("%d\n%d\n",n,m);
}

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

using namespace std;

int main() {
    int n, r;

    for (;;) {
        cin >> n >> r;
        if (n == 0 && r == 0) break;

        // init
        vector<int> cards(n);
        for (int i = 0; i < n; i++) cards[i] = n - i;

        // cutting operation
        for (int i = 0; i < r; i++) {
            int p, c;
            cin >> p >> c;

            vector<int> cards_(cards);
            for (int j = 0; j < c; j++) cards[j] = cards_[j + p - 1];
            for (int j = 0; j < p - 1; j++) cards[j + c] = cards_[j];

        }

        cout << cards[0] << endl;
    }
}

Measured memory_bytes: 1212