akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int mod = 1e9+7;

void solve()
{
    int n; cin >> n;
    vector<int> v(n);
    vector<ll> suffix(n + 1);
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
    }
    for (int i = n - 1; i >= 0; --i) {
        suffix[i] = (v[i] + suffix[i + 1]) % mod;
    }
    ll ans = 0;
    for (int i = 0; i < n; ++i) {
        ans = ((ans % mod) + (v[i] * suffix[i + 1] % mod) % mod);
    }
    cout << ans << '\n';
}

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

Measured memory_bytes: 5556
n = int(input())
a, b, c, d = 0, 0, 0, 0
for i in range(n):
    s = input()
    if s == 'AC': a -= -1
    if s == 'WA': b -= -1
    if s == 'TLE': c -= -1
    if s == 'RE': d -= -1
print('AC x', a)
print('WA x', b)
print('TLE x', c)
print('RE x', d)

Measured memory_bytes: 69876
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(300000)


def solve(N: int, A: "List[int]", B: "List[int]", C: "List[int]"):
    ret = 0
    for i in range(N):
        ret += B[A[i] - 1]
        if i > 0 and A[i] == A[i - 1] + 1:
            ret += C[A[i] - 2]
    print(ret)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    B = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    C = [ int(next(tokens)) for _ in range(N-1) ]  # type: "List[int]"
    solve(N, A, B, C)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
template <typename X> ostream& operator << (ostream& x,const vector<X>& v){for(ll i=0;i<v.size();++i) x<<v[i]<<" ";return x;}
template <typename X> ostream& operator << (ostream& x,const set<X>& v){for(auto it:v) x<<it<<" ";return x;}
template <typename X, typename Y> ostream& operator << (ostream& x, const pair<X,Y>& v) {x<<v.ff<<" "<<v.ss;return x;}
template <typename T, typename S> ostream& operator << (ostream& os, const map<T, S>& v) { for (auto it : v) os << it.first << "=>" << it.second << endl; return os; }
struct pair_hash {inline std::size_t operator()(const std::pair<ll, ll> & v) const {return v.first*31+v.second;}};
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC targett("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define speed ios_base::sync_with_stdio(false);cin.tie(NULL)
#define pb push_back
#define fr first
#define sc second
#define prnt(m) for(auto it = m.begin() ; it != m.end() ; ++it){cout<<*it<<endl;}
#define tra(it,m) for(auto it=m.begin();it!=m.end();++it)
#define DBG(x) cout<<"# # #     "<<x<<'\n';
#define fri(i,s,n) for(ll i=s;i<n;i++)
#define mod 1000000007LL
#define mod2 998244353
#define vct2 vector<vector<ll>>
#define vct vector<ll>
#define pll pair<ll,ll>
#define rz(n) resize(n)
#define all(v) v.begin(),v.end()
#define mkp make_pair
#define arrin(a,n) for(ll i = 0; i < n ; i++){cin>>a[i];}
#define arrout(a,n) for(ll i = 0;i < n; i++){cout<<a[i]<<" ";}
#define ex(s) cout<<s<<endl,exit(0);
#define inf 2e18
#define h_p 1110111110111;
#define five 100005;
#define six 1000005;
#define printclock cerr<<"Time "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";
//_______________________________________________________________________________
vector<vector<int>> curr;
int m;
int n;
void f(int i,int st,vector<int> xx)
{
       if(i == n)
       {
              curr.pb(xx);
              return ;
       }
       fri(j,st,m+1){
              xx.pb(j);
              f(i+1,j,xx);
              xx.pop_back();
       }
}
int main()
{
       int q;
       cin>>n>>m>>q;
       vector<int> xx;
       f(0,1,xx);
       pair<pll,pll> qu[q];
       fri(i,0,q){
              cin>>qu[i].fr.fr>>qu[i].fr.sc>>qu[i].sc.fr>>qu[i].sc.sc;
              --qu[i].fr.fr;--qu[i].fr.sc;
       }
       ll ans = 0;
       fri(i,0,curr.size())
       {
              ll sum = 0;
              fri(j,0,q){
                     if(curr[i][qu[j].fr.sc]-curr[i][qu[j].fr.fr] == qu[j].sc.fr)
                     {
                            sum += qu[j].sc.sc;
                     }
              }
              ans = max(ans,sum);
       }
       cout<<ans<<endl;
}


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

std::string Count(int i) {
  int x = i % 10;
  if (x == 3) {
    return "bon";
  } else if (x == 0 || x == 1 || x == 6 || x == 8) {
    return "pon";
  } else {
    return "hon";
  }
}

int main() {
  int n;
  cin >> n;
  cout << Count(n) << endl;
}


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

#define ll long long
#define mod 1000000007
#define ff first
#define ss second
#define pii pair<int,int>
#define pb push_back
#define IOS ios_base::sync_with_stdio(false),cin.tie(NULL);
#define endl '\n'
void dfs(int u, vector<vector<int>> &g, vector<bool> &vis){
    vis[u]=1;
    for(int v:g[u]){
        if(!vis[v])
        dfs(v,g,vis);
    }
}
void tests(){
    int n,e,a,b;
    cin>>n>>e;
    vector<vector<int>> g(n+1, vector<int>());
    for(int i=0;i<e;i++){
        cin>>a>>b;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    int val=0;
    vector<bool> vis(n+1,0);
    for(int i=1;i<=n;i++){
        if(!vis[i]){
            val++;
            dfs(i,g,vis);
        }
    }
    cout<<val-1<<endl;
}
int main( int argc , char ** argv ){
	ios_base::sync_with_stdio(false) ; 
	cin.tie(NULL) ; 
	ll t = 1;
// 	cin>>t;
	while(t--){
		tests();
	}
 	return 0 ; 
}

Measured memory_bytes: 9536
import java.util.*;

public class Main {
	public static void main(String[] args) {
		@SuppressWarnings("resource")
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		if (a < b)
			System.out.println("a < b");
		else if (a > b)
			System.out.println("a > b");
		else
			System.out.println("a == b");
	}
}

Measured memory_bytes: 17320
#define _USE_MATH_DEFINES
#include <iostream>
#include <algorithm>
#include <queue>
#include <stack>
#include <deque>
#include <climits>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
//#include <tuple>

#define INF INT_MAX>>1 
#define SIZE 100010
#define MOD 1000000007
#define rep(i, n) for(int i=0; i<(int)(n); i++)
#define rep2(i, from, to) for(int i=(from); i<(int)(to); i++)
#define all(obj) (obj).begin(), (obj).end()
#define lpair pair<ll, ll>
#define vint vector<ll>
#define vinput(name) for(int i=0; i<(int)(name.size()); i++) cin >> name[i];
#define voutput(name) for(int i=0; i<(int)(name.size()); i++) cout << name[i] << endl;
typedef long long ll;

using namespace std;

int main(void){
	int n, m; cin >> n >> m;
	vint s(m), c(m);
	rep(i, m) cin >> s[i] >> c[i];
	rep(i, m-1){
		rep2(j, i+1, m){
			if(s[i] == s[j]){
				if(c[i] != c[j]){
					cout << -1 << endl;
					return 0;
				}
			}
		}
	}
	int ans[3] ={1, 0, 0};
	rep(i, m){
		ans[s[i]-1] = c[i];
	}
	if(n == 1 && m == 0){
		cout << 0 << endl;
		return 0;
	}
	rep(i, n){
		if(n != 1 && ans[0] == 0){
			cout << -1 << endl;
			return 0;
		} else{
			cout << ans[i];
		}
	}
	cout << endl;

	return 0;
}

Measured memory_bytes: 256
# https://atcoder.jp/contests/dp/submissions/13960132

def MAX(a, b):
    d = a + ms - b
    return b + ((((d & ms) >> (K - 1)) * tt) & d)

def tolist(n):
    sx = bin(n)[2:] + "_"
    return [int(sx[-(i+1) * K - 1:-i * K - 1], 2) for i in range((len(sx)+K-2) // K)]

K = 52
N, W = map(int, input().split())

ms = int(("1" + "0" * (K - 1)) * (W + 1), 2)
tt = (1 << K - 1) - 1
one = int(("0" * (K - 1) + "1") * (W + 1), 2)

s = 1 << K - 2 + (W * K)
for _ in range(N):
    w, v = map(int, input().split())
    s = MAX(s, (s >> w * K) + one * v)

print(max(tolist(s)) - (1 << K - 2))

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

int main()
{
    int n, cnt, sum = 0, min = 10000000, a[100];
    
    cin >> n;

    for( int i = 0; i < n; i++ )
    {
        cin >> a[i];
        if( a[i] % 2 == 1 )
        {
            cnt++;
            if( min > a[i] )
                min = a[i];
        }
        sum += a[i];
    }

    if( cnt % 2 == 0 )
        cout << sum / 2 << endl;
    else
        cout << ( sum - min ) / 2 << endl;

    return 0;
}


Measured memory_bytes: 3100
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;

long long N, i, j, ans;
vector<long long> A;
map<long long, long long> cntA;
long long pow2s[33];

int main(void) {
    pow2s[0] = 1;
    for (i=1; i<=32; i++) {
        pow2s[i] = pow2s[i-1] * 2;
    }
    cin >> N;
    long long tmp;
    for (i=0; i<N; i++) {
        cin >> tmp;
        A.push_back(tmp);
        cntA[tmp]++;
    }
    sort(A.begin(), A.end());
    reverse(A.begin(), A.end());
    
    ans = 0;
    for (i=0; i<N; i++) {
        if (cntA[A[i]] == 0) {
            continue;
        }
        //まず，作れる２べきを探す
        for (j=0; j<32; j++) {
            if (pow2s[j] <= A[i] && A[i] < pow2s[j+1]) {
                break;
            }
        }
        //このとき，pow2s[j+1]が作れる２べき
        long long pair_num = pow2s[j+1] - A[i];
        cntA[A[i]]--;
        if (cntA[pair_num] > 0) { //ペアがある
            cntA[pair_num]--;
            ans++;
        }
    }
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 26864
#include <iostream>
#include <cstring>

using namespace std;
int n, A[100];

void print() {
    for (int i = 0; i < n; i++) {
        cout << A[i];
        if (i != n - 1) cout << ' ';
    }
    cout << endl;
}

void insertionSort(int A[], int N) {
    for (int i = 1; i < N; i++) {
        //从第一个元素开始处理，到第n-1个元素结束
        int v = A[i], j = i - 1;
        while (j >= 0 && A[j] > v) {//当j>=0并且前一个元素大于当前元素的值时进入循环
            A[j + 1] = A[j];
            j--;
        }//前一个元素不大于当前元素的时退出循环
        A[j + 1] = v;
        print();
    }
}

int main() {
    cin >> n;
    memset(A, 0, sizeof(A));
    for (int i = 0; i < n; i++)
        cin >> A[i];
    print();
    insertionSort(A, n);
    return 0;
}


Measured memory_bytes: 3080
#include<bits/stdc++.h>
using namespace std;
#define ll long long int 
#define f first
#define s second
#define pb push_back
#define mod 1000000007
#define mp make_pair
#define fast 
#define f first
#define s second
#define endl "\n"
#define pie 3.1415926535

int main (){
    int a,b,c;
    cin >> a >> b >> c;
    cout << c <<" "<< a << " " << b <<endl;
}





Measured memory_bytes: 256
//2017-10-14
//miaomiao
//
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <map>

using namespace std;

#define LL long long
#define For(i, a, b) for(register int i = (a); i <= (int)(b); ++i)
#define Forr(i, a, b) for(register int i = (a); i >= (int)(b); --i)

#define MN (2200+5)
#define N (100000+5)

char chr;
inline void Read(LL &x){
	chr = getchar();
	while(chr < '0' || chr > '9') chr = getchar();
	x = 0;
	while(chr >= '0' && chr <= '9'){
		x = (x<<1) + (x<<3) + (chr^'0'); chr = getchar();
	}
}

bool vis[MN];
int pn, num[MN];
LL a[N], sqr3[MN], sqr[MN];

inline void Init(int nn){
	For(i, 1, nn) sqr3[i] = 1ll*i*i*i, sqr[i] = 1ll*i*i;
	For(i, 2, nn){
		if(!vis[i]) vis[i] = true, num[++pn] = i;
		For(j, 1, pn){
			if(i * num[j] > nn) break;
			vis[i*num[j]] = true;
			if(i % num[j] == 0) break;
		}
	}
}

struct node{
	LL x, y, tot;
}me[N];

map<LL, int> ms;
int mn;

int main(){
	int n, j;
	LL x, y, tmp, form;

	Init(2160);
	scanf("%d", &n);
	
	For(i, 1, n){
		Read(a[i]);
		Forr(dj, pn, 1){
			j = num[dj];
			while(!(a[i] % sqr3[j])) a[i] /= sqr3[j];
		}
		if(ms.count(a[i])){++me[ms[a[i]]].tot; continue;}

		form = a[i]; x = 1; y = 1;
		Forr(dj, pn, 1){
			j = num[dj];
			while(!(a[i] % sqr[j])) x *= j, a[i] /= sqr[j];
		}
		Forr(dj, pn, 1){
			j = num[dj];
			while(!(a[i] % j)) y *= j, a[i] /= j;
		}

		tmp = sqrt(a[i]);
		if(tmp*tmp == a[i]) x *= tmp;
		else y *= a[i];

		me[++mn] = (node){x, y, 1}; ms[a[i]=form] = mn;
	}
	
	int ans = 0, id;
	LL mv, ov;
	if(ms.count(1)) ++ans, ms[1] = -1;

	For(i, 1, n){
		if(ms[mv = a[i]] == -1) continue;	
		
		id = ms[mv]; ov = me[id].x * me[id].y * me[id].y;
		if(!ms.count(ov)){ans += me[id].tot; ms[mv] = -1; continue;}

		ans += max(me[id].tot, me[ms[ov]].tot);
		ms[mv] = ms[ov] = -1;
	}

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

	return 0;
}

Measured memory_bytes: 9600
#include<iostream>
#include<algorithm>
#include<string>
#define for0(i, n) for(int i = 0; i < (n); i++)
#define for1(i, n) for(int i = 1; i <= (n);i++)
using namespace std;
string map[1234];
int dp[1234][1234];
signed main() {
	int n; while (cin >> n, n) {
		int ans = 0;
		for0(i, n)cin >> map[i];
		for1(i, n)for1(j, n) {
			if (map[i - 1][j - 1] == '*')dp[i][j] = 0;
			else dp[i][j] = min({ dp[i - 1][j], dp[i - 1][j - 1],dp[i][j - 1] })+1;
			ans = max(ans, dp[i][j]);
		}
		cout << ans << endl;
	}
}


Measured memory_bytes: 8916
#include <stdio.h>
#include <algorithm>
#pragma warning(disable : 4996)
using namespace std;
int a, b, c, d; int sqr[30000];
int gcd(int p, int q) {
	if (p < q) swap(p, q);
	if (q == 0) return p;
	return gcd(q, p % q);
}
int main() {
	for (int i = 0; i < 30000; i++) sqr[i] = i * i;
	while (true) {
		scanf("%d%d%d", &a, &b, &c);
		if (a == 0 && b == 0 && c == 0) break;
		d = b * b - 4 * a * c;
		if (!binary_search(sqr, sqr + 30000, d)) {
			printf("Impossible\n");
		}
		else {
			int val1 = lower_bound(sqr, sqr + 30000, d) - sqr;
			int s1 = b - val1; int f1 = 2 * a; int r1 = gcd(abs(s1), f1);
			int s2 = b + val1; int f2 = 2 * a; int r2 = gcd(abs(s2), f2);
			s1 /= r1; f1 /= r1;
			s2 /= r2; f2 /= r2;
			if (f1 < f2 || (f1 == f2 && s1 < s2)) { swap(f1, f2); swap(s1, s2); }
			printf("%d %d %d %d\n", f1, s1, f2, s2);
		}
	}
	return 0;
}

Measured memory_bytes: 2720
N = int(input())
W = []
for i in range(N):
    W.append(str(input()))

for i, k in enumerate(W):
    if i == 0:
        continue
    
    if W.count(k) != 1:
        print('No')
        exit()
    elif k[0] != W[i-1][-1]:
        print('No')
        exit()

print('Yes')

Measured memory_bytes: 3060
#if 0

#endif

#include <bits/stdc++.h>
#define REP(i, n) for(int i=0;i<int(n);++i)
using namespace std;
template<class A>void p(A a){cout << (a) << endl;}
template<class A,class B>void p(A a,B b){cout << a << " "  ;p(b);}
template<class A,class B,class C>void p(A a,B b,C c){cout << a << " " ;p(b,c);}
template<class A,class B,class C,class D>void p(A a,B b,C c,D d){cout << a << " " ;p(b,c,d);}
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
int INF=numeric_limits<int>::max();
// for copy
// for(int i=0;i<N;++i) {
int min(int a,int b) {
  if (a<b) {
    return a;
  } else {
    return b;
  }
}

int main(void) {
  int N,X,Y;cin>>N>>X>>Y;
  int G[N+10][N+10];
  fill(G[0],G[N+10],0);
  REP(i,N) {
    int start = 1;
    for(int j=i+1;j<N;++j) {
      G[i][j] = start;
      start += 1;
    }
  }
  // REP(i,N) {
  //   for(int j=i+1;j<N;++j) {
  //     cout << G[i][j] << " ";
  //   }
  //   cout << endl;
  // }
  int x,y;
  for(int i=0;i<N;++i) {
    for(int j=i+1;j<N;++j) {
      x=abs(X-(i+1));
      y=abs(Y-(j+1));
      G[i][j] = min(G[i][j],x+y+1);
    }
  }
  // REP(i,N) {
  //   for(int j=i+1;j<N;++j) {
  //     cout << G[i][j] << " ";
  //   }
  //   cout << endl;
  // }
  int R[N]={};
  REP(i,N) {
    for(int j=i+1;j<N;++j) {
      R[G[i][j]-1]+=1;
    }
  }
  REP(i,N-1) {
    p(R[i]);
  }
  return 0;
}



Measured memory_bytes: 16000
/*#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<map>
#include<cstdio>
#include<stack>
#include<queue>
#include<fstream>
#include<cstdio>
#include<deque>
#include<iomanip>
#include <numeric>*/
#include<bits/stdc++.h>

using namespace std;
#define ok1 printf("ok1\n");
#define ok2 printf("ok2\n");
#define M 1000000000000000000LL
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);(i)--)
#define all(a) (a).begin(),(a).end()
#define reall(a) (a).rbegin(),(a).rend()
#define pb push_back
#define pf push_front
#define MIN(a,b) a=min((a),(b))
#define MAX(a,b) a=max((a),(b))
#define SIZE(v) (int)v.size()
const double pi = acos(-1.0);

typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef deque<ll> dll;
typedef pair<ll, ll> P;
const ll mod = 1e9 + 7;
ll dx[4] = {1,0,-1,0};
ll dy[4] = {0,1,0,-1};

int main(){
    string s,t;
	cin >> s >> t;
	if(s == t) cout << "EQUAL\n";
	if(s.size() > t.size()) cout << "GREATER\n";
	else if(s.size() < t.size()) cout << "LESS\n";
	else{
		rep(i,max(s.size(),t.size())){
			if(s[i] > t[i]) {
				cout << "GREATER\n";
				break;
			}
			else if(s[i] < t[i]) {
				cout << "LESS\n";
				break;
			}
			else continue;
		}
	}
	return 0;
}  


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <functional>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <deque>
#include <ctime>
  
using namespace std;
  
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define pb push_back
#define mp make_pair
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second
#define println(X) cout<<X<<endl;
#define DBG(X) cout<<#X<<" : "<<X<<endl;
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;
const double PI = acos(-1);

int main(){
	string s;
	cin>>s;
	int r = 0;
	for(int i = 1; i < s.size(); i++){
		if(s[i]!=s[i-1]) r++;
	}
	cout<<r<<endl;
}

Measured memory_bytes: 512
use proconio::marker::*;
use proconio::*;
use std::cmp::*;
use std::collections::*;
use std::ops::Bound::*;

// 左から貪欲に取っていけばサイズは分かる
// ダブリングでよい集合のサイズがlogで分かる
// Kは固定
// ダブリングじゃなくてセグ木でも可能 -> 嘘
//
// 和集合のサイズ?
// Q=1なら各要素の直近の右、左で最大サイズ作れるかで含まれるかが分かる
// 毎回これするのは無理
// 極大...というとアレだが各点から貪欲に構成した良い集合のサイズは最大か最大-1
// うーん
//
// 左から貪欲した点、右から貪欲した点で適切な範囲の点が答え
// ダブリングに和を持たせる？

#[fastout]
fn run() {
    input! {
        n: usize,
        k: i64,
        mut x: [i64; n],
        q: usize,
        ask: [(usize, usize); q],
    }
    let inf = 10i64.pow(10);
    x.insert(0, -inf);
    x.push(inf);
    let x = x;
    let mut right = vec![(n + 1, n + 1); n + 2];
    {
        let mut r = 0;
        for i in 1..=n {
            while x[r] - x[i] < k {
                r += 1;
            }
            right[i] = (r, i);
        }
//        println!("{:?}", right);
    }
    let mut left = vec![(0, 0); n + 2];
    {
        let mut l = n + 1;
        for i in (1..=n).rev() {
            while x[i] - x[l] < k {
                l -= 1;
            }
            left[i] = (l, i);
        }
//        println!("{:?}", left);
    }
    let mut memo_r = vec![];
    while right.iter().any(|p| p.0 < n + 1) {
        let mut next = right.clone();
        for (next, &(a, b)) in next.iter_mut().zip(right.iter()) {
            let (x, y) = right[a];
            *next = (x, y + b);
        }
        memo_r.push(right);
        right = next;
    }
    memo_r.push(right);
    let right = memo_r;
    let mut memo_l = vec![];
    while left.iter().any(|p| p.0 > 0) {
        let mut next = left.clone();
        for (next, &(a, b)) in next.iter_mut().zip(left.iter()) {
            let (x, y) = left[a];
            *next = (x, y + b);
        }
        memo_l.push(left);
        left = next;
    }
    memo_l.push(left);
    let left = memo_l;
    for (l, r) in ask {
        let mut cnt = 0;
        let mut sum = 0;
        let mut pos = r;
        for (i, x) in left.iter().enumerate().rev() {
            if x[pos].0 >= l {
                cnt += 1 << i;
                sum += x[pos].1;
                pos = x[pos].0;
            }
        }
        while left[0][pos].0 >= l {
            cnt += 1;
            sum += left[0][pos].1;
            pos = left[0][pos].0;
        }
        sum += pos;
        cnt += 1;
        let mut pos = l;
        for (i, x) in right.iter().enumerate().rev() {
            if x[pos].0 <= r {
                sum -= x[pos].1;
                pos = x[pos].0;
            }
        }
        while right[0][pos].0 <= r {
            sum -= right[0][pos].1;
            pos = right[0][pos].0;
        }
        sum -= pos;
        let ans = sum + cnt;
        println!("{}", ans);
        //        println!("{} {} {}", sum, cnt, ans);
    }
}

fn main() {
    run();
}


Measured memory_bytes: 130132
let rec gcd a b = if b = 0 then a else gcd b (a mod b)
let ans = ref 0;;
let () =
  Scanf.scanf "%d\n" @@ fun k ->
  for i = k downto 1 do
    for j = k downto 1 do
      for l = k downto 1 do
        ans := (gcd i (gcd j l)) + !ans
      done
    done
  done;
  Printf.printf "%d\n" !ans

Measured memory_bytes: 3832
#include <iostream>
#include <fstream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <cstdlib>
#include <cstdio>
#include <string>
#include <cstring>
#include <cassert>
#include <utility>
#include <iomanip>
#include <chrono>
#include <random>
#include <bitset>

using namespace std;

#define sz(x) (int) x.size()
#define unique(x) x.erase(unique(x.begin(), x.end()), x.end())
#define all(a) a.begin(), a.end()
#define sqr(x) ((x) * (x)) 
#define y1 aksjdaskdjksjfksdjf
#define left kdnvldvoiwejifejg
#define right lkdsjflksdjfdjfk
#define prev asdasfsadjkjsdfjs
#define tm aklsjdasjdasjdkdjjf
#define lcm hddalkwjeidjjhasda
#define random_shuffle asdasdd

const int MAXN = 2050;

bool eq(char a, char b) {
  if (a != '?' && b != '?' && a != b) {
    return false;
  }
  return true;
}

void calcCan(string a, string b, bool can[]) {
  for (int i = 0; i < sz(a); i++) {
    can[i] = true;
    for (int j = 0; j < sz(b); j++) {
      int cur = i + j;
      if (cur >= sz(a)) {
        break;
      }
      if (!eq(a[cur], b[j])) {
        can[i] = false;
        break;
      }
    }
  }
}

string s[5];
string a, b, c;
bool can1[MAXN], can2[MAXN], can3[MAXN];
int ans;

void solve() {
  calcCan(a, b, can1);
  calcCan(a, c, can2);
  calcCan(b, c, can3);

  int curAns = sz(a) + sz(b) + sz(c);
  int mnBc = sz(b) + sz(c);
  for (int i = 0; i < sz(b); i++) {
    if (can3[i]) {
      mnBc = max(sz(b), sz(c) + i);
      break;
    }
  }
  curAns = min(curAns, sz(a) + mnBc);

  // cerr << mnBc << endl;

  for (int i = 0; i < sz(a); i++) {
    if (!can1[i]) {
      continue;
    }
    if (i + sz(b) - 1 >= sz(a) - 1) {
      curAns = min(curAns, sz(b) + i + sz(c));
      for (int j = 0; j < sz(b); j++) {
        bool ok = can3[j];
        if (i + j < sz(a)) {
          ok &= can2[i + j];
        }
        if (ok) {
          curAns = min(curAns, i + max(sz(b), j + sz(c)));
        }
      }
      // curAns = min(curAns, i + mnBc);
    } else {
      curAns = min(curAns, sz(a) + sz(c));
      for (int j = i; j < sz(a); j++) {
        bool ok = can2[j];
        if (i + sz(b) - 1 >= j) {
          ok &= can3[j - i];
        }
        if (ok) {
          curAns = min(curAns, max(sz(a), j + sz(c)));
        }
      }
    }
  }

  // cerr << curAns << " " << a << " " << b << " " << c << endl;
  ans = min(ans, curAns);
}

int main() {

  getline(cin, s[0]);
  getline(cin, s[1]);
  getline(cin, s[2]);

  sort(s, s + 3);
  ans = sz(s[0]) + sz(s[1]) + sz(s[2]);

  do {
    a = s[0]; b = s[1]; c = s[2];
    solve();
  } while (next_permutation(s, s + 3));

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
let () =
  let n = Scanf.scanf "%d\n" (fun x->x) in
  let adj = Array.init n (fun x -> Array.make n 0) in
  let rec read = function
      0 -> ()
    | i ->
       let (u,k) = Scanf.scanf "%d %d " (fun x y -> (x,y)) in
       let rec loop = function
           0 -> ()
         | j ->
            let v = Scanf.scanf "%d " (fun x -> x) in
            adj.(u-1).(v-1) <- 1;loop (j-1)
       in loop k;read (i-1)
  in read n;
     for i = 0 to n-1 do
       for j = 0 to n-1 do
         print_int adj.(i).(j);
         if j <> n-1 then print_string " "
       done;
       print_newline ()
     done
;;

Measured memory_bytes: 2668
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _1_1_a
{
    class Program
    {
        static void Main(string[] args)
        {
            int i = int.Parse(Console.ReadLine());
            int x = i * i * i;
            Console.WriteLine(x);
        }
    }
}



Measured memory_bytes: 15984
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define fi first
#define se second
typedef pair<ll,ll> P;
using VP = vector<P>; using VVP = vector<VP>;
using VI = vector<ll>; using VVI = vector<VI>; using VVVI = vector<VVI>;
const int inf=1e9+7;
const ll INF=1LL<<61;
const ll mod=1e9+7;

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

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

int r,c;

int bitcountr(int x){
    int cnt=0;
    for(int i=0;i<r;i++){
        cnt+=((x>>i)&1);
    }
    return cnt;
}

int main(){
    int i,j;
    while(1){
        cin>>r>>c;
        if(r==0) break;
        VI a(c,0);
        for(i=0;i<r;i++){
            for(j=0;j<c;j++){
                int x;
                cin>>x;
                a[j]+=x<<i;
            }
        }
        int ans=0;
        for(i=0;i<(1<<(r-1));i++){
            int cnt=0;
            for(j=0;j<c;j++){
                cnt+=max(bitcountr(a[j]^i),r-bitcountr(a[j]^i));
            }
            //cout<<cnt<<" "<<i<<endl; 
            ans=max(ans,cnt);
        }
        cout<<ans<<endl;
        
    }

}


Measured memory_bytes: 3160
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<unordered_map>
#include<unordered_set>
#include<list>
#include<queue>
#include<functional>
#include<limits.h>
#include<string.h>
#include<algorithm> 
using namespace std;

double abs(double c) {
	if (c >= 0)return c;
	return -c;
}
int a[100];
signed main() {
	int n; cin >> n; double sum = 0;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		sum += a[i];
	}
	sum /= n;
	double MIN = 1000;
	for (int i = 0; i < n; i++) {
		MIN = min(MIN, abs(a[i] - sum));
	}
	for (int i = 0; i < n; i++) {
		if (abs(MIN - abs(a[i] - sum))==0){
		cout << i<< endl;
		break;
}
	}
}

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

int main()
{
  int H,N;scanf("%d %d\n",&H,&N);
  int A[N],B[N];
  vector<vector<int>> dp(N+1,vector<int>(H+1,INF));
  for(int i=0;i<N;i++)dp[i][0]=0;
  for(int i=0;i<N;i++)scanf("%d %d\n",&A[i],&B[i]);
  for(int i=0;i<N;i++)for(int j=0;j<H+1;j++)
  {
    if(j-A[i]<0)dp[i+1][j]=dp[i][j];
    else dp[i+1][j]=min(dp[i][j],dp[i+1][j-A[i]]+B[i]);
  }
  int ans=dp[N][H];
  for(int i=0;i<H+1;i++)for(int j=0;j<N;j++)if(i+A[j]>=H)ans=min(ans,dp[N][i]+B[j]);
  printf("%d",ans);
}

Measured memory_bytes: 42596
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
def main():
    h, w = map(int, input().split())
    # 「黒にするマス」の上下左右にも１つ以上の「黒にするマス」があればOK。
    # '#'を1、'.'を0にする。
    # グリッドの上下左右にダミーマスとして0を置く。
    grid = []
    grid.append([0] * (w + 2))
    for _ in range(h):
        row = list(input())
        row2 = [1 if c == '#' else 0 for c in row]
        grid.append([0] + row2 + [0])
    grid.append([0] * (w + 2))

    for i1 in range(1, h + 1):
        for i2 in range(1, w + 1):
            if grid[i1][i2] == 1:
                black = grid[i1-1][i2] + grid[i1][i2-1] + grid[i1][i2+1] + grid[i1+1][i2]
                if black == 0:
                    print('No')
                    sys.exit()
    print('Yes')

if __name__ == '__main__':
    main()


Measured memory_bytes: 9164
#include <iostream>

using namespace std;

int main()
{
    int a, b;

    cin >> a >> b;

    if (a >= b)
        for (int i = 0; i < a; i++)
            cout << b;
    else
        for (int i = 0; i < b; i++)
            cout << a;

    cout << endl;

    return 0;
}

Measured memory_bytes: 256
n,k=map(int,input().split())
s=list(input())

judge=[0]
max_=0
for i in range(n-1):
  if s[i]!=s[i+1]:
    judge.append(i+1)
judge.append(n)

if len(judge)//2<=k:
  print(len(s))
else:
  for i in range(len(judge)-1):
    if s[judge[i]]=='0':
      ans=judge[min(i+2*k,len(judge)-1)]-judge[i]
    else:
      ans=judge[min(i+2*k+1,len(judge)-1)]-judge[i]
    if ans>max_:
      max_=ans
  print(max_)

Measured memory_bytes: 7844
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringBuilder output = new StringBuilder();
        while(true){
            String data[] = br.readLine().split(" ");
            int x = Integer.parseInt(data[0]);
            int y = Integer.parseInt(data[1]);
            if(x == 0 && y == 0)
                break;
                
            output.append(Integer.toString(x<y?x:y)).append(" ").append(Integer.toString(x>y?x:y)).append("\n");
        }
        System.out.print(output);
    }
}

Measured memory_bytes: 26796
#include <iostream>

#include <cstdio>

#include <cmath>

using namespace std;



int main(){

	int n;

	double x1,y1,x2,y2,x3,y3,x1_2,x1_3,y1_2,y1_3,z1_2,z1_3,a,b,c,r;

	while(cin >> n){

		for(int i = 0;i < n;++i){

			cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;

			z1_2 = (((x1 * x1) + (y1 * y1)) * -1) - (((x2 * x2) + (y2 * y2)) * -1);

			z1_3 = (((x1 * x1) + (y1 * y1)) * -1) - (((x3 * x3) + (y3 * y3)) * -1);

			x1_2 = x1 - x2;

			x1_3 = x1 - x3;

			y1_2 = y1 - y2;

			y1_3 = y1 - y3;

			a = ((y1_2 * z1_3) - (y1_3 * z1_2)) / ((y1_2 * x1_3) - (y1_3 * x1_2));

			b = ((x1_2 * z1_3) - (x1_3 * z1_2)) / ((x1_2 * y1_3) - (x1_3 * y1_2));

			c = ((x1 * x1) + (y1 * y1) + (a * x1) + (b * y1)) * -1;

			r = sqrt((c * -1) + (a * a / 4.0) + (b * b / 4.0));

			printf("%.3f %.3f %.3f\n",a / -2.0,b / -2.0,r);

		}

	}

	return 0;

}

Measured memory_bytes: 0
N = int(input())
H = list(map(int,input().split()))
cur = 0
cmax = 0
for i in range(1,N):
    if H[i]<=H[i-1]:
        continue
    else:
        cmax = max(cmax,i-1-cur)
        cur = i
if cur<N-1:
    cmax = max(cmax,N-1-cur)
print(cmax)

Measured memory_bytes: 14252
#include<bits/stdc++.h>
//ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
//clock_t start=clock();clock_t end=clock();cout<<(double)(end-start)/CLOCKS_PER_SEC<<endl;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef pair<int,int> pii;
typedef pair<pii,int> ppii;
typedef pair<int,pii> pipi;
typedef pair<ll,ll> pll;
typedef pair<pll,ll> ppll;
typedef pair<ll,pll> plpl;
typedef tuple<ll,ll,ll> tl;
typedef pair<double,double> pdd;
ll mod=1000000007;
ll mod2=998244353;
ll mod3=1000003;
ll mod4=998244853;
ll mod5=1000000009;
ll inf=1LL<<60;
double pi=3.141592653589793238462643383279L;
double eps=1e-9;
#define rep(i,m,n) for(ll i=m;i<n;i++)
#define rrep(i,n,m) for(ll i=n;i>=m;i--)
#define srep(itr,st) for(auto itr=st.begin();itr!=st.end();itr++)
#define Max(a,b) a=max(a,b)
#define Min(a,b) a=min(a,b)
int dh[4]={1,-1,0,0};
int dw[4]={0,0,1,-1};
int ddh[8]={-1,-1,-1,0,0,1,1,1};
int ddw[8]={-1,0,1,-1,1,-1,0,1};
ll gcd(ll a,ll b){
    if(a<b)swap(a,b);
    if(b==0)return a;
    if(a%b==0)return b;
    return gcd(b,a%b);
}
ll Pow(ll n,ll k){
    ll ret=1;
    ll now=n;
    while(k>0){
        if(k&1)ret*=now;
        now*=now;
        k/=2;
    }
    return ret;
}
ll beki(ll n,ll k,ll md){
  ll ret=1;
  ll now=n;
  while(k>0){
    if(k%2==1){
      ret*=now;
      ret%=md;
    }
    now*=now;
    now%=md;
    k/=2;
  }
  return ret;
}
ll gyaku(ll n,ll md){
  return beki(n,md-2,md);
}
ll popcount(ll n){
    ll ret=0;
    ll u=n;
    while(u>0){
        ret+=u%2;
        u/=2;
        
    }
    return ret;
}
int main(){
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int k,q;cin>>k>>q;
    ll d[k];
    rep(i,0,k)cin>>d[i];
    rep(i,0,q){
        ll dd[k];
        ll n,x,m;cin>>n>>x>>m;
        rep(j,0,k)dd[j]=d[j]%m;
        x%=m;
        ll z=0;
        ll la=x;
        ll r=(n-1)%k;
        ll s=(n-1)/k;
        rep(j,0,k){
            if(j<r){
                la+=dd[j]*(s+1);
                if(dd[j]==0)z+=s+1;
            }
            else{
                la+=dd[j]*s;
                if(dd[j]==0)z+=s;
            }
        }
        ll u=la/m;
        cout<<n-1-u-z<<endl;
    }
}








Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
int m[505050];
int factor(int num){
	int ans=1;
	for(int i=2;i<=num;i++)
		ans=(long long)ans*i%MOD;
	return ans;
}
int inv[505050];
void initinv(int num){
	inv[1]=1;
	for(int i=2;i<=num;i++)
		inv[i]=(long long)(MOD-MOD/i)*inv[MOD%i]%MOD;
}
unsigned s[505050];
int main(){
	int N;scanf("%d",&N);
	for(int i=1;i<=N;i++)
		cin>>m[i];
	initinv(N);
	for(int i=1;i<=N;i++)
		s[i]=(s[i-1]+inv[i])%MOD;
	unsigned ans=0;
	for(int i=1;i<=N;i++)
		ans=(ans+(long long)(s[N-i+1]+s[i]-1)*m[i])%MOD;
	ans=(long long)ans*factor(N)%MOD;
	printf("%u\n",ans);
	return 0;
}

Measured memory_bytes: 2944
# -*- coding: utf-8 -*-
"""
Created on Tue Apr 28 21:57:22 2020
"""

import sys
#import numpy as np

sys.setrecursionlimit(10 ** 9)
#def input():
#    return sys.stdin.readline()[:-1]
mod = 10**9+7

S = input()

if S[2] == S[3] and S[4] == S[5]:
    ans = 'Yes'
else:
    ans = 'No'
print(ans)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define mo 1000000007
#define pi 3.1415926535898
#define eps 1e-9 
using namespace std;
long long read(){
    long long xx=0,flagg=1;
    char ch=getchar();
    while((ch<'0'||ch>'9')&&ch!='-')
        ch=getchar();
    if(ch=='-'){
        flagg=-1;
        ch=getchar();
    }
    while(ch>='0'&&ch<='9'){
        xx=xx*10+ch-'0';
        ch=getchar();
    }
    return xx*flagg;
}
void pus(long long xx,long long flagg){
    if(xx<0){
        putchar('-');
        xx=-xx;
    }
    if(xx>=10)
        pus(xx/10,0);
    putchar(xx%10+'0');
    if(flagg==1)
        putchar(' ');
    if(flagg==2)
        putchar('\n');
    return;
}
long long n,m,k,i,x,y,sd[55],min1[55],sum[55],sum2[55],jc[305],ny[305],ans;
long long ksm(long long u,long long v){
	long long o=1;
	while(v){
		if(v&1)
			o=o*u%mo;
		u=u*u%mo;
		v>>=1;
	}
	return o;
}
long long C(long long u,long long v){
	return jc[u]*ny[v]%mo*ny[u-v]%mo;
}
long long gcd(long long u,long long v){
	if(v==0) return u;
	return gcd(v,u%v);
}
long long top,nex[205],to[205],fir[55];
void lj(int u,int v){
	top++;
	nex[top]=fir[u];
	fir[u]=top;
	to[top]=v;
}
void cz(long long u,long long v){
	if(u!=v){
		ans=ans*C(v+k-1,k-1)%mo;		
	}
	else{
		long long sum=0;
		for(i=1;i<=u;i++)
			sum=(sum+ksm(k,gcd(u,i)))%mo;
		sum=sum*ksm(u,mo-2)%mo;
		ans=ans*sum%mo;
	}
}
void ss(int u,int v,int w){
	sd[v]=w;
	sum[v]=1;
	min1[v]=w;
	int min2=w,min3;
	for(int top1=fir[v];top1;top1=nex[top1])
		if(sd[to[top1]]==0){
			ss(v,to[top1],w+1);
			
			min1[v]=min(min1[to[top1]],min1[v]);
			if(min1[to[top1]]>=w){
				if(min1[to[top1]]==w)
					cz(sum[to[top1]]+1,sum2[to[top1]]);
				else
					ans=ans*k%mo;
			}
			else{
				sum[v]+=sum[to[top1]];
				sum2[v]+=sum2[to[top1]];
			}
		}
		else if(sd[to[top1]]<sd[v]){
			sum2[v]++;
			if(to[top1]!=u)
				min1[v]=min(min1[v],sd[to[top1]]);
		}
}
int main(){
	//freopen(".in","r",stdin);
    //freopen(".out","w",stdout);
    n=read();m=read();k=read();
    jc[0]=1;
    ny[0]=1;
    for(i=1;i<=n+m+k;i++){
    	jc[i]=jc[i-1]*i%mo;
    	ny[i]=ksm(jc[i],mo-2);
    }
    for(i=1;i<=m;i++){
		x=read();y=read();
		lj(x,y);
		lj(y,x);
	}
	ans=1;
	for(i=1;i<=n;i++)
		if(sd[i]==0)
			ss(i,i,1);
	pus(ans,2);
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <vector>
#include <utility>

using namespace std;

char s[100'009];

int main() {
  scanf("%s", s + 1);
  int n = (int)strlen(s + 1);
  if (s[1] == '0' || s[n] == '1') {
    puts("-1");
    return 0;
  }
  for (int i = 1; i <= n / 2; ++i) {
    if (s[i] != s[n - i]) {
      puts("-1");
      return 0;
    }
  }
  puts("2 1");
  int x = 2;
  int ne = 3;
  for (int i = 2; i <= n / 2; ++i) {
    printf("%d %d\n", ne, x);
    if (s[i] == '1') {
      x = ne;
    }
    ++ne;
  }
  while (ne <= n) {
    printf("%d %d\n", ne, x);
    ++ne;
  }
}


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

int main(){
  int N, K;
  cin >> N >> K;
  
  vector<int> A(N);
  for (int i = 0; i < N; i++){
    cin >> A.at(i);
  }
  
  
  for (int i = K + 1; i <= N; i++){
    if (A.at(i - K - 1) < A.at(i - 1)){
      cout << "Yes" << endl;
    }
    else{
      cout << "No" << endl;
    }
  }
  
}

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

int main() {
    int H, N;
    cin >> H >> N;

    //declare vec
    /*
    vector<int> vec(N);
    for (int i = 0; i < N; i++){
        cin >> vec.at(i);
    }
    */

   //not declare vec
   for (int i = 0; i < N; i++){
       int a;
       cin >> a;
       H -= a;
   }

   if (H <= 0) {
       cout << "Yes" << endl;
   } else {
       cout << "No" << endl;
   }
   
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int n;
  cin >> n;
  int b;
  cin >> b;
  int max = b;
  int min = b;
  for(int i = 0; i < n - 1; i++){
    int a;
    cin >> a;
    if(a <= min) min = a;
    if(a >= max) max = a;
  }
  cout << max - min << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int n;
main()
{
	while(cin>>n,n)
	{
		int cnt=0;
		for(int j=1;j<=n;j++)
		{
			for(int k=j+1;k<=n;k++)
			{
				cnt+=k*(k+1)/2-j*(j-1)/2==n;
			}
		}
		cout<<cnt<<endl;
	}
}



Measured memory_bytes: 3004
#include<iostream>
#include<cstdio>
#include<vector>
#include<queue>
using namespace std;
int Max;
int N;
int D[1000];
vector<int>G[300];
bool S[300];
bool T[300];
int main()
{
	while (true){
		bool F = true;
		for (int i = 0; i < 300; i++)G[i].clear();
		for (int i = 0; i < 300; i++)S[i] = false;
		scanf("%d", &Max);
		if (Max == 0)break;
		scanf("%d", &N);
		//graph
		for (int i = 1; i <= N; i++){
			scanf("%d", &D[i]);
		}
		for (int i = 0; i <= N; i++){
			for (int j = 1; j <= Max; j++){
				if (i + j >= N + 1){
					G[i].push_back(N + 1);
					break;
				}
				else{
					if (i + j + D[i + j] < 0)G[i].push_back(0);
					else if (i + j + D[i + j] >= N + 1)G[i].push_back(N + 1);
					else G[i].push_back(i + j + D[i + j]);
				}
			}
		}
		S[0] = true;
		/*for (int i = 0; i <= N + 1; i++){
			printf("%d:", i);
			for (int j = 0; j < G[i].size(); j++){
				printf("%d ", G[i][j]);
			}
			printf("\n");
		}*/
		priority_queue<int>que;
		que.push(0);
		while (!que.empty()){
			int e = que.top(); que.pop();
			for (int i = 0; i < G[e].size(); i++){
				if (S[G[e][i]])continue;
				S[G[e][i]] = true;
				que.push(G[e][i]);
			}
		}
		for (int s = 0; s <= N; s++){
			if (!S[s])continue;
			for (int i = 0; i <= N + 1; i++)T[i] = false;
			T[s] = true;
			priority_queue<int>que1;
			que1.push(s);
			while (!que1.empty()){
				int e = que1.top(); que1.pop();
				for (int i = 0; i < G[e].size(); i++){
					if (T[G[e][i]])continue;
					T[G[e][i]] = true;
					que1.push(G[e][i]);
				}
			}
			if (!T[N + 1])F = false;
		}
		if (F)printf("OK\n");
		else printf("NG\n");
	}
	return 0;
}
//scanf_S

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

using namespace std;

int n;
int a[200010],b[200010];

int main()
{
	int i,j;
	cin>>n;
	for (i=1;i<=n;i++){
		cin>>a[i];
		b[i]=a[i];
	}
	sort(a+1,a+n+1);
	for (i=1;i<=n;i++){
		if (b[i]<=a[n/2]) cout<<a[n/2+1]<<endl;
		else cout<<a[n/2]<<endl;
	}
	return 0;
}


Measured memory_bytes: 3712
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <functional>

#ifdef LOCAL
	#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
	#define eprintf(...) 42
#endif

#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; ++i)
#define repp(i, m, n) for(ll i = m, i##_len = (n); i < i##_len; ++i)
#define reprev(i, n) for(ll i = (n-1LL); i >= 0; --i)
#define all(x) (x).begin(), (x).end()
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; }
template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
using namespace std;

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

int main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n, cc, d[30][30] = {}, c[500][500] = {};
	cin >> n >> cc;
	rep (i, cc) rep (j, cc) cin >> d[i][j];
	rep (i, n) rep (j, n) cin >> c[i][j];
	ll dd[3][30] = {};
	rep (i, n) rep (j, n) dd[(i + j) % 3][c[i][j] - 1]++;
	ll ans = 250000001;
	rep (i, cc) {
		rep (j, cc) {
			rep (k, cc) {
				if (i != j && j != k && k != i) {
					ll tmp = 0, col[3] = {i, j, k};
					rep (p, 3) {
						rep (q, cc) {
							tmp += dd[p][q] * d[q][col[p]];
						}
					}
					chmin(ans, tmp);
					eprintf("(%lld,%lld,%lld): %lld\n", i, j, k, tmp);
				}
			}
		}
	}
	cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 2176
#include <iostream>
#include <stdio.h>
#include <vector>
#include <bits/stdc++.h>
#include <math.h>
using namespace std;

int main() {

  long long n=0, min=0, max=0, sum=0;

  cin >> n;

  vector<long long> x(n);

  for(long long i=0; i<n; i++) {

    cin >> x.at(i);

    sum = sum+x.at(i);
    
  }

  sort(x.begin(), x.end());

  min = x.at(0);
  max = x.at(n-1);

  cout << min << " " << max << " " << sum << endl;
  
}


Measured memory_bytes: 3164
/*input
101
1000000000000000000
*/

#include <functional>
#include <algorithm>
#include <iostream>
#include <string.h>
#include <utility> 
#include <iomanip>
#include <string>
#include <vector>
#include <math.h>
#include <map>
#include <set>

using namespace std;

using ll = long long;
using ld = long double;

const int SINF = 1000000009;
const ll INF =  1000000000000000018;

#define sp          cout << " "
#define nl          cout << "\n"
#define all(c)      (c).begin(),(c).end()
#define prec(n)     cout << fixed << setprecision(n)
#define PI          3.14159265358979323846264338327951
#define ifalse      ios_base::sync_with_stdio(false), cin.tie(NULL)

template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << p.first << " " << p.second;
  return os;
}

template <typename T, typename U>
istream &operator>>(istream &is, pair<T, U> &p) {
  is >> p.first >> p.second;
  return is;
}

template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  for(auto x: v) {
    os << x << " ";
  }
  return os;
}

template <typename T>
istream &operator>>(istream &is, vector<T> &v) {
  for (auto &x : v) is >> x;
  return is;
}

/******************************** START *********************************/
const int N = 100005;

int main()
{
  ifalse;
  ll x;
  cin >> x;
  ll a = 100LL;
  ll ans = 0;
  while(a < x) {
    ll d = a / 100LL;
    // if(a + 100 >= x) {
    //   ans += ((x - a) / d + 1);
    //   a = x;
    // } else {
      ll last = min(a + 100, x);
      while(last / 100 < d) {
        last += d;
      }
      while(last / 100 > d) {
        last -= d;
      }
      ll u = (last - a) / d + 1;
      ans += u;
      a += u * d;
    // }
  }
  if(x < 200) {
    ans --;
  }
  cout << ans,nl;
  return 0;
}

Measured memory_bytes: 3656
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

#define int 		long long
#define vi 			vector<int>
#define vec(x) 		vector<x>
#define matrix 		vector<vector<int>>
#define pii 		pair<int,int>
#define repf(i,s,e)  for(int i=s;i<e;i++)
#define repb(i,e,s) for(int i=e;i>=s;i--)
#define MOD			1000000007
#define pb 			push_back
#define ff 			first
#define ss 			second
#define w(x)		int x; cin>>x; while(x--)
const int INF = 1e18;

#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
	cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
	const char* comma = strchr(names + 1, ','); cerr.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...);
}
#else
#define trace(...)
#endif

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
// find_by_order(k-1)  returns iterator to kth element starting from 0; Returns the kth smallest element
// order_of_key(k) returns count of elements strictly smaller than k;Returns the number of elements less than k
// erase,insert same as normal set


void solve() {
	string s;
	cin>>s;

	int dp[2019];memset(dp,0,sizeof(dp));

	int n=s.length(),ans=0;
	for(int i=0;i<n;i++){
		int ndp[2019];memset(ndp,0,sizeof(ndp));
		for(int j=0;j<2019;j++){
			ndp[(10*j+(s[i]-'0'))%2019]+=dp[j];
		}
		ndp[s[i]-'0']++;
		ans+=ndp[0];
		swap(ndp,dp);
	}

	cout<<ans<<endl;
}

int32_t main() {
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	if (fopen("input.txt", "r")) {
		freopen("input.txt", "r", stdin),
		        freopen("output.txt", "w", stdout);
	}

	int t = 1;
	//cin>>t;
	while (t--) {
		solve();
	}
}

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

using namespace std;

typedef long long ll;

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

	int n;
	cin >> n;

	int t[n];
	int sm = 0;
	rep(i, n) {
		cin >> t[i];
		sm += t[i];
	}

	int m;
	cin >> m;

	rep(i, m){
		int p, x;
		cin >> p >> x;
		p--;

		cout << sm - t[p] + x << endl;
	}

}


Measured memory_bytes: 256
#include<stdio.h>
#define MAX 100000

int parent(int i)
{
  return i/2;
}

int left(int i)
{
  return 2*i;
}

int right(int i)
{
  return 2*i+1;
}

int main()
{

  int i,A[MAX+1],n;

  scanf("%d",&n);
  for(i=1;i<=n;i++)
    {
      scanf("%d",&A[i]);
    }

  for(i=1;i<=n;i++)
    {
      printf("node %d: key = %d, ",i,A[i]);
      if(parent(i) >= 1) printf("parent key = %d, ",A[parent(i)]);
      if(left(i)<= n) printf("left key = %d, ",A[left(i)]);
      if(right(i) <= n) printf("right key = %d, ",A[right(i)]);
      printf("\n");
    }

  return 0;
}



Measured memory_bytes: 2104