akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize ("O3")
/*
    Prodigia comploratus,
    silens, oro:
    "Regnet exitium."
*/
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using db = long double;
const int N = 1e5 + 5, MOD = 1e9 + 7;
ll F[N], iF[N], inv[N];
ll C(int n, int k){
    if(n<k||k<0||n<0)return 0;
    return F[n] * (iF[n-k]*iF[k]%MOD)%MOD;
}
int head[N], tmp1, tmp2;
int main(){
    F[0] =iF[0]= iF[1] = F[1]=1;
    inv[1] = 1;

    for(int i = 2; i < N; i++){
        F[i] = F[i-1] * i % MOD;
        inv[i] = MOD-inv[MOD%i]*(MOD/i)%MOD;
        iF[i] = iF[i-1] * inv[i] % MOD;
    }
    int n;  cin >> n;
    memset(head,-1,sizeof head);

    for(int i = 0, v; i <= n; i++){
        cin >> v;
        if(head[v] == -1)head[v] = i;
        else {
            tmp1 = head[v];
            tmp2 = i;
        }
    }

    for(int i = 1; i <= n; i++){
        cout <<  (C(n,i) + C(n,i-1) - C(tmp1 + n - tmp2, i - 1)+MOD)%MOD << '\n';

    }
    cout << 1 << '\n';

    return 0;
}


Measured memory_bytes: 3968
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i,n) for (int i = 0; i<(n); i++)
#define in(n) cin >> (n)
#define out(ans) cout << (ans) << endl;
#define keta(n) cout << fixed << setprecision((n));
using ll = int64_t;
using v = vector<int>;


int main() {
  int h1, m1, h2, m2, k;
  cin >> h1 >> m1 >> h2 >> m2 >> k;
  cout << h2*60+m2-h1*60-m1-k << endl;
}

Measured memory_bytes: 3552
#include<stdio.h>
static const int MAX = 500;
static const int INFTY = (1<<21);
int main(void){
  int n, i, j;
  int M[MAX][MAX];
  int d[MAX];
  int tmp[MAX];
  int m;
  int u, k, c, v;
  scanf("%d", &n);
  for ( i = 0; i< n; i++ ){
    for ( j = 0; j < n; j++ ){
      M[i][j] = INFTY;
    }
  }
  for ( i = 0; i < n; i++ ){
    scanf("%d %d", &u, &k);
    for ( j = 0; j < k; j++ ){
      scanf("%d %d", &v, &c);
      M[u][v] = c;
    }
  }
  for( i=0; i<n; i++ ){
	  tmp[i]=0;
	  d[i]=INFTY;
  }
  d[0]=0;
  m=INFTY;
  while(1){
	  m=INFTY;
	  u=-1;
	  for( i=0; i<n; i++ ){
		  if(d[i]<m&&(tmp[i]==0)){
			  u=i;
			  m=d[i];
		  }
	  }
	  if(u==-1)break;
	  tmp[u]=1;
	  for( v=0; v<n; v++ ){
		  if(d[v]>=d[u]+M[u][v]) d[v]=d[u]+M[u][v];
	  }
  }
  for ( i = 0; i < n; i++ ) printf("%d %d\n", i, (d[i]==INFTY?-1:d[i]));
  return 0;
}

Measured memory_bytes: 804
#include <bits/stdc++.h>
//#define lop(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;

int main() {
#ifndef ONLINE_JUDGE
	freopen("input1.txt", "r", stdin);
	freopen("output1.txt", "w", stdout);
#endif
	ios::sync_with_stdio(false);
	cin.tie(0);
	int h, a;
	cin >> h >> a;
	if (h <= a) cout << "1" << "\n";
	else if (h > a) {
		if (h % a == 0) {
			cout << h / a;

		}
		else {
			cout << h / a + 1;
		}
	}

}

Measured memory_bytes: 3628
#include<stdio.h>
int main(void)
{
  int i,n,a[200];
  scanf("%d",&n);
  for(i=0;i<n;i++)
    {
      scanf("%d",&a[i]);
    }
  for(i=n-1;0<=i;i--)
    {if(i!=n-1){printf(" %d",a[i]);}
      else{printf("%d",a[i]);}
    }
  printf("\n");
  return 0;
}

Measured memory_bytes: 600
#include<bits/stdc++.h>
using namespace std;
 
#define fi first
#define se second
#define FOR(a, b, c) for(int a = b; a <= c; ++a)
#define FORW(a, b, c) for(int a = b; a >= c; --a)
#define pb push_back
#define SZ(a) ((int)a.size())
//#define TEST
 
const int oo = 1e9;
const int Maxn = 1e5;
const int N = 3e5 + 100;
const double PI = (-2.00) * asin(-1);
 
typedef pair<int, pair<int, int> > iii;
typedef pair<int, int> ii;    

bool check[200];

signed main()
{
    #ifdef TEST
        freopen("test.inp", "r", stdin);
    #endif // TEST  
     ios_base::sync_with_stdio(false);                                      
    cin.tie(0); cout.tie(0);
    int res = oo;
    int x, n; cin >> x >> n;
    FOR(i, 1, n) {
        int y; cin >> y;
        check[y] = 1;
    }

    FOR(i, 0, 101) if(!check[i]) {
        if(abs(res - x) > abs(i - x)) res = i;
    }
    cout << res;
}


Measured memory_bytes: 3628
# import itertools
# import math
# import fractions
# import functools
# import copy
# from collections import deque
# from functools import reduce
# from decimal import Decimal


def main():
    n = input()
    sum = 0
    for i in range(len(n)):
        sum += int(n[i])

    if sum % 9 == 0:
        print("Yes")
    else:
        print("No")


if __name__ == '__main__':
    main()


Measured memory_bytes: 67840
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <climits>
#include <iomanip>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
int main(){
  ll n = 0;
  cin >> n;
  vector<ll> a(n);
  for(int i = 0;i < n;i++)cin >> a[i];
  vector<vector<ll>> bit(n,vector<ll>(31));
  for(int i = 0;i < n;i++){
    for(int j = 30;j >= 0;j--){
      if(a[i] >= pow(2,j)){
        bit[i][j] = 1;
        a[i] -= pow(2,j);
      }
      else bit[i][j] = 0;
    }
  }
  //vector<ll> count(20);
  for(int i = 0;i < 31;i++){
    ll count = 0;
    for(int j = 0;j < n;j++){
      count += bit[j][i];
    }
    if(count % 2 == 1){
      for(int j = 0;j < n;j++){
        bit[j][i] = 1 - bit[j][i];
      }
    }
  }
  //for(int i = 0;i < 20;i++)
  vector<ll> res(n);
  for(int i = 0;i < n;i++){
    for(int j = 0;j < 31;j++){
      res[i] += pow(2,j) * bit[i][j];
    }
    if(i != n - 1)cout << res[i] << " ";
    else cout << res[i] << endl;
  }
}

Measured memory_bytes: 61396
var output;
var input = require("fs").readFileSync("/dev/stdin", "utf8").trim().split("\n");
var obj = {
  "list" : input,
  "index" : 0,
  "max" : input.length,
  "next" : function(){
    if(!this.hasNext()){throw "NoSuchElementException:次に要素は無いよ";}
    var returnObj = this.list[this.index];
    this.index++;
    return returnObj;
  },
  "hasNext" : function(){return (this.index < this.max);}
}
Main();
function next(){return obj.next();}
function hasNext(){return obj.hasNext();}
function myout(t){console.log(t);}//standard output
function myerr(t){console.error(t);}//standard error
//[no]要素の扱い。数値型
//不明値、異常時:引数そのまま返す
//1:数値へ変換 2:半角SPで分割 4:半角SPで分割し、数値配列へ
//6:1文字に分割 7:1文字に分割し、数値配列へ
//8:半角SPで結合 9:改行で結合 0:文字なしで結合
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(" ");case 4:return i.split(" ").map((a)=>Number(a));case 6:return i.split("");case 7:return i.split("").map((a)=>Number(a));case 8:return i.join(" ");case 9:return i.join("\n");case 0:return i.join("");default:return i;}}catch(e){return i;}}
function Main() {
  var one = myconv(next(),4);
  var N = one[0];
  var K = one[1];
  var list = myconv(next(),4);
  list.sort(function(a,b){
  	return b - a;
  });
  var output = 0;
  for(var i = 0; i < N; i++){
    if(i >= K){
       output += list[i];
    }
  }
  myout(output);
}

Measured memory_bytes: 48412
from collections import deque

H, W = map(int, input().split())
ch, cw = map(int, input().split())
gh, gw = map(int, input().split())

ch += 1
cw += 1
gh += 1
gw += 1

maze = ["#"*(W+4), "#"*(W+4)] + ["##" + input() + "##" for _ in range(H)] + ["#"*(W+4), "#"*(W+4)]
visited = [[-1]*(W+4) for _ in range(H+4)]
visited[ch][cw] = 0

walk = [[-1, 0], [1, 0], [0, -1], [0, 1]]
warp = [[-2, -2], [-2, -1], [-2, 0], [-2, 1], [-2, 2], [-1, -2], [-1, -1], [-1, 1], [-1, 2],
        [0, -2], [0, 2], [1, -2], [1, -1], [1, 1], [1, 2], [2, -2], [2, -1], [2, 0], [2, 1], [2, 2]]

queue = deque([[ch, cw]])

while queue:
    h, w = queue.popleft()
    for dh, dw in walk:
        h_next = h + dh
        w_next = w + dw
        if maze[h_next][w_next]==".":
            if visited[h_next][w_next]==-1 or visited[h_next][w_next] > visited[h][w]:
                visited[h_next][w_next] = visited[h][w]
                queue.appendleft([h_next, w_next])
    
    for dh, dw in warp:
        h_next = h + dh
        w_next = w + dw
        if maze[h_next][w_next]=="." and visited[h_next][w_next]==-1:
            visited[h_next][w_next] = visited[h][w] + 1
            queue.append([h_next, w_next])

print(visited[gh][gw])


Measured memory_bytes: 121432
import sys
K, X = map(int, input().split())

for i in reversed(range(K)):
    X -= i
    sys.stdout.write(str(X))
    sys.stdout.write(' ')
    X += i

for i in range(1, K):
    X += i
    sys.stdout.write(str(X))
    sys.stdout.write(' ')
    X -= i

Measured memory_bytes: 3060
#include<algorithm>
#include<cmath>
#include<iostream>
using namespace std;
int main() {
    string S;
    cin >> S;
    int N = (int)S.size();
    int ans = 999;
    for (int i = 0; i <= N - 3; ++i) {
        int num = (S[i] - '0') * 100 + (S[i+1] - '0') * 10 + (S[i+2] - '0');
        ans = min(ans, abs(num - 753));
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  map<string,int> v;
  int m=0;
  for(int i=0;i<n;i++){
    string s;
    cin>>s;
    v[s]++;
    m=max(m,v[s]);
  }
  vector<string> w;
  for(auto i:v)
    if(i.second==m)
      w.push_back(i.first);
  sort(w.begin(),w.end());
  for(int i=0;i<w.size();i++)
    cout<<w.at(i)<<endl;
}

Measured memory_bytes: 26868
#include <iostream>
#include <vector>
#include <cmath>
#include <iomanip>
#include <algorithm>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)


int main() {
	int n,k,d=1,t,ok;
	cin>>n>>k;
	int ans=n;
	vector<int>no(k);
	rep(i,k)cin>>no[i];
	while(d){
	    t=ans;
	    ok=1;
	    while(t){
	        rep(i,k)if(t%10==no[i])ok=0;
	        t/=10;
	    }
	    if(ok){
	        cout<<ans;
	        d=0;
	    }
	    ans++;
	}
	return 0;
}


Measured memory_bytes: 256
N, H = map(int, input().split())
AB = [list(map(int, input().split())) for i in range(N)]

A = sorted([ab[0] for ab in AB])
B = sorted([ab[1] for ab in AB])
aMax = A[-1]
import bisect
b = bisect.bisect_left(B, aMax)
sumB = sum(B[b:])
ans = 0
i = 0

if sumB < H:
    ans += N-b
    H -= sumB
    if H % aMax == 0:
        ans += H // aMax
    else:
        ans += H // aMax + 1
else:
    while H > 0:
        if N-i-1 >= b:
            H -= B[-(i+1)]
            i += 1
            ans += 1
        else:
            if H % aMax == 0:
                ans += H // aMax
            else:
                ans += H // aMax + 1

print(ans)

Measured memory_bytes: 30044
// In His Name

#include <bits/stdc++.h>

#define pb push_back
#define F first
#define S second
#define gcd __gcd
#define int long long
#define ull unsigned long long

using namespace std;

typedef pair<int, int> pii;

const int MAX = 1e5 + 10 , INF = 1e12;
int n, k, a[MAX], dp[MAX];

main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin >> n >> k;
	for (int i = 0 ; i < n ; i++){
		cin >> a[i];
		dp[i] = INF;
	}
	dp[0] = 0;
	for (int i = 1 ; i < n ; i++){
		for (int j = max (i - k , 1LL * 0) ; j < i ; j++){
			dp[i] = min (dp[i] , dp[j] + abs(a[i] - a[j]));
		}
	}
	cout << dp[n - 1];
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int MOD = 1000000007;
 //pair<pair<int,int>,int> p[100001];
signed main() {
char a,b;
cin>>a>>b;
if(a=='H'){
  if(b=='H')cout<<'H';
  else cout<<'D';
}else{
  if(b=='H')cout<<'D';
  else cout<<'H';
}

return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#define p 1000000007
using namespace std;
int n,cnt;
int fir[10101],nxt[10101],to[10101];
int siz[10101],g[10101],f[5050][5050][2];
int tmp[5050][2];
void add(int x,int y)
{
	nxt[++cnt]=fir[x];fir[x]=cnt;to[cnt]=y;
}
void dfs(int x,int fa)
{
	siz[x]=1;
	f[x][1][0]=1;
	for(int i=fir[x];i;i=nxt[i])
	if(to[i]!=fa)
	{
		dfs(to[i],x);
		for(int j=1;j<=siz[x];j++)
		for(int k=1;k<=siz[to[i]];k++)
		{
			(tmp[j+k][0]+=(1LL*f[x][j][0]*f[to[i]][k][0]+1LL*f[x][j][1]*f[to[i]][k][1])%p)%=p;
			(tmp[j+k][1]+=(1LL*f[x][j][1]*f[to[i]][k][0]+1LL*f[x][j][0]*f[to[i]][k][1])%p)%=p;
			(tmp[j][0]+=(1LL*f[x][j][0]*f[to[i]][k][1]%p*g[k]%p+1LL*f[x][j][1]*f[to[i]][k][0]%p*g[k]%p)%p)%=p;
			(tmp[j][1]+=(1LL*f[x][j][1]*f[to[i]][k][1]%p*g[k]%p+1LL*f[x][j][0]*f[to[i]][k][0]%p*g[k]%p)%p)%=p;
		}
		siz[x]+=siz[to[i]];
		for(int j=1;j<=siz[x];j++)
		f[x][j][0]=tmp[j][0],tmp[j][0]=0,f[x][j][1]=tmp[j][1],tmp[j][1]=0;
	}
}
int main()
{
	scanf("%d",&n);
	g[0]=1;
	for(int i=2;i<=n;i+=2) g[i]=1LL*g[i-2]*(i-1)%p;
	for(int i=1;i<n;i++)
	{
		int x,y;
		scanf("%d%d",&x,&y);
		add(x,y);add(y,x);
	}
	dfs(1,0);
	int ans=0;
	for(int i=1;i<=n;i++) (ans+=1LL*(f[1][i][0]-f[1][i][1]+p)*g[i]%p)%=p;
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 198656
#include<stdio.h>
#include <stdlib.h>
#define MAX 2000001
#define VMAX 10000


/*void CountingSort(unsigned short *A, unsigned short *B, int k){
  int i,j;
  unsigned short C[VMAX];
  
  for (i = 0 ; i <= k ; i++)
    C[i] = 0;

  
  for (j = 1; i <= n; i++)
    C[A[j]]++;

  
 for (i = 1 ;i <= k;i++)
    C[i] = C[i] + C[i-1];

  for (j = n; j >= 1;j--){
    B[C[A[j]]] = A[j];
      C[A[j]]--;
      }
}*/


int main(){
  unsigned short *A, *B;
  int C[VMAX+1];
  int  i, j,n, k=0;

  scanf("%d", &n);

  A = malloc(sizeof(short)*n+1);
  B = malloc(sizeof(short)*n+1);

  /* your code */

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

  for (i = 0 ; i < VMAX ; i++)
    C[i] = 0;

  /* C[i] に i の出現数を記録する */
  for (j = 1; j <= n; j++){
    C[A[j]]++;
    
  }
  /* C[i] に i 以下の数の出現数を記録する*/
   for (i = 1 ;i < VMAX;i++)
    C[i] = C[i] + C[i-1];

  for (j = n; j >= 1;j--){
    B[C[A[j]]] = A[j];
      C[A[j]]--;
      }

   for(i=1;i<=n;i++){
     if(i!=1)
      printf(" ");
      
    printf("%u",B[i]);
   }
  printf("\n");
  free(A);
  free(B);


  return 0;
}



Measured memory_bytes: 9120
#include <iostream>

using namespace std;
int main (int argc, const char * argv[]){
{
    int a,b,c;
    cin >>a>>b>>c;
    if(a<b&&b<c){
        cout <<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
    // insert code here...
    //cout << "Hello, World!\n";
    return 0;
}
}

Measured memory_bytes: 1156
N,M=map(int,input().split())
A=[list(map(int,input().split())) for i in range(N)]
g=[1]*M
G=M
I=[0]*N
R=N
def count(x):
    c=[0]*M
    r,ri=0,0
    for e in x:
        c[e]+=1
        if c[e]>r:
            r=c[e]
            ri=e
    return r,ri
while G>0:
    for l,a in enumerate(A):
        while g[a[I[l]]-1]==0:
            I[l]+=1
    r,ri=count([a[I[l]]-1 for l,a in enumerate(A)])
    R=min(R,r)
    g[ri]=0
    G-=1
print(R)

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

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

	int n,k;
	string s;
	vector <int> res;

	cin >> n >> k;
	cin >> s;

	int pos = n;

	while(pos)
	{
		bool ok = false;
		for(int next=max(0,pos-k);next<pos;next++)
		{
			int d = pos - next;
			if(s[next]=='0')
			{
				ok = true;
				res.push_back(d);
				pos = next;
				break;
			}
		}
		//cout << pos << '\n';
		if(!ok)
		{
			cout << -1 << '\n';
			return 0;
		}
	}

	for(int i=res.size()-1;i>=0;i--)
	{
		cout << res[i] << ' ';
	}
	cout << '\n';

	return 0;
}


Measured memory_bytes: 1096
#include<stdio.h>
int main()
{
    int a=0,b=0,c;
    int i,j,k;
    char x[202]={0},y[101]={0};
    for(i=0;;i++){
        scanf("%c",&x[i]);
        if(x[i]=='\n')break;
        a++;
    }
    for(i=0;i<a;i++){
        x[i+a]=x[i];
    }
    for(i=0;;i++){
        scanf("%c",&y[i]);
        if(y[i]=='\n')break;
        b++;
    }
    for(i=0;i<b;i++){
        for(j=0;j<a;j++){
            c=0;
            if(y[i]==x[j]){
                for(k=0;k<b;k++){
                    if(y[i+k]==x[j+k]){
                        c++;
                        if(c==b){
                            puts("Yes");
                            return 0;
                        }
                    }
                }
            }
        }
    }
    puts("No");
    return 0;
}

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

int main()
{
    int num[101]={0},n,max=0;
    while(cin>>n){
        num[n]++;
        if(max<num[n]){
            max=num[n];
        }
    }
    for(int i=1;i<101;i++){
        if(max==num[i]){
            cout<<i<<endl;
        }
    }
    return 0;
}

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

using namespace std;

#define REP(i,n) for(int i = 0; i < (int)(n); i++)

int main(){
  const int M = 1000000007;
  int n;
  cin >> n;
  vector<uint64_t> a(n);
  REP(i, n) cin >> a[i];
  sort(a.begin(), a.end());
  uint64_t r = 0;
  REP(i, n){
    r += a[n - i - 1] * (i + 2);
    r %= M;
  }
  REP(i, n - 1){
    r *= 4;
    r %= M;
  }
  cout << r << endl;
  return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define REP(i, a, n) for(ll i=a; i<n; i++)
#define RREP(i, a, n) for(ll i=n-1; i>=a; i--)
typedef long long ll;
const ll mod =1e9+7;
const ll inf =1e18;
using namespace std;

int a[3];
int main() {
    cin>>a[0]>>a[1]>>a[2];
    sort(a, a+3);
    cout<<a[2]-a[0]<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x ,n) for(int i = x; i < n; i++)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main(){
    int n,k;
    cin >> n >> k;
    int h[n];
    rep(i,n)cin >> h[i];
    int ans = 0;
    
    rep(i,n)if(h[i]>=k)ans++;
    
    cout << ans;

	return 0;
}

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

void reader(int *x) {
	int k = getchar_unlocked(); *x = k - '0';
	while (1) {
		k = getchar_unlocked();
		if (k < '0' || k > '9') break;
		*x = ((*x) << 1) + ((*x) << 3) + k - '0';
	}
}
vector<int>E[100000];
int u[200000], v[200000], r[200000], ans[200000], d[100000], cnt = 1;
char b[200000], ok[100000]{ 1 };
list<int>que;

void bfs(int u, int t) {
	que.emplace_back(u);
	while (!que.empty()) {
		int p = que.front(); que.pop_front();
		for (int v : E[p]) {
			if (t) {
				if (d[v] > d[p] && !ok[v]) {
					ok[v] = 1; cnt++; que.emplace_back(v);
				}
			}
			else if (!~d[v]) {
				d[v] = d[p] + 1; que.emplace_back(v);
			}
		}
	}
}
int main() {
	int n, m, q; reader(&n); reader(&m); reader(&q);
	rep(i, m) {
		reader(&u[i]); reader(&v[i]);
		u[i]--; v[i]--;
		E[u[i]].emplace_back(v[i]); E[v[i]].emplace_back(u[i]);
	}
	memset(d, -1, sizeof(d));
	d[0] = 0; bfs(0, 0);
	rep(i, m) {
		if (d[u[i]] > d[v[i]])swap(u[i], v[i]);
	}
	rep(i, n)E[i].clear();
	rep(i, q) {
		reader(&r[i]); r[i]--;
		b[r[i]] = 1;
	}
	rep(i, m) {
		if (!b[i]) {
			if (d[v[i]] > d[u[i]]) {
				E[u[i]].emplace_back(v[i]);
			}
		}
	}
	bfs(0, 1);
	for (int i = q - 1; i >= 0; i--) {
		ans[i] = n - cnt;
		if (d[v[r[i]]] > d[u[r[i]]] && !ok[v[r[i]]]) {
			E[u[r[i]]].emplace_back(v[r[i]]);
			if (ok[u[r[i]]]) {
				cnt++; ok[v[r[i]]] = 1;
				bfs(v[r[i]], 1);
			}
		}
	}
	rep(i, q)printf("%d\n", ans[i]);
}

Measured memory_bytes: 14628
import java.util.*;
public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int N = Integer.parseInt(sc.next());
		int A[][] = new int[N][N - 1];
		for(int i = 0; i < N; i++) {
			for(int j = 0; j < N - 1; j++) {
				A[i][j] = Integer.parseInt(sc.next()) - 1;
			}
		}
		
		int test = 0;
		for(int i = 1; i <= N - 1; i++) {
			test += i;
		}
		int cnt[] = new int[N];
		boolean flag[] = new boolean[N];
		Integer end[] = new Integer[N];
		Arrays.fill(end, 0);
		boolean end_f = false;
		long ans = 0;
		while(Arrays.asList(end).contains(0)) {
			if(ans > 10000) {
				System.out.println(test);
				return;
			}
			Arrays.fill(flag, false);
			end_f = true;
			ans++;
			in : for(int i = 0 ; i < N; i++) {
				if(flag[i] || cnt[i] >= N - 1) continue in;
				if(A[A[i][cnt[i]]][cnt[A[i][cnt[i]]]] == i && !flag[A[i][cnt[i]]]) {
					flag[A[i][cnt[i]]] = true;
					cnt[A[i][cnt[i]]]++;
					if(cnt[A[i][cnt[i]]] >= N - 1) {
						end[A[i][cnt[i]]] = 1;
					}
					flag[i] = true;
					cnt[i]++;
					if(cnt[i] >= N - 1) {
						end[i] = 1;
					}
					end_f = false;
				}
				if(i >= N - 1 && end_f) {
					System.out.println(-1);
					return;
				}
			}
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 108532
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using vi = vector<int>;
using vvi = vector<vi>;
#define ote(x) cout<<(x)<<endl
#define all(x) (x).begin(),(x).end()
#define rp(i,s,e) for(int i=(s);i<(e);++i)
#define rpz(i,e) rp(i,0,e)

int main(){
	int A,B; cin>>A>>B;
	string S; cin>>S;
	if(A+B+1 != S.size()){
		puts("No");
		return 0;
	}

	if(S[A] != '-'){
		puts("No");
		return 0;
	}

	rpz(i,S.size()){
		if(i==A) continue;
		int a = S[i]-'0';
		if(0<= a && a <=9) continue;
		puts("No");
		return 0;
	}

	puts("Yes");
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define inf INT_MAX
#define mod 1000000007
#define int long long

void solve() {
	int n;
	cin >> n;
	int a[n], b[n], c[n];
	int i;
	for (i = 0; i < n; i++) {
		cin >> a[i] >> b[i] >> c[i];
	}
	int dp[n][3];
	dp[0][0] = a[0];
	dp[0][1] = b[0];
	dp[0][2] = c[0];
	for (i = 1; i < n; i++) {
		dp[i][0] = a[i] + max(dp[i - 1][1], dp[i - 1][2]);
		dp[i][1] = b[i] + max(dp[i - 1][0], dp[i - 1][2]);
		dp[i][2] = c[i] + max(dp[i - 1][0], dp[i - 1][1]);
	}
	cout << max(dp[n - 1][0], max(dp[n - 1][1], dp[n - 1][2])) << endl;
	return;
}

int32_t main() {

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

Measured memory_bytes: 8304
var GET=(function(){function f(s){return new g(s);}function g(s){this._s=s.trim().split("\n");this._y=0;}g.prototype.a=function(f){var s=this._s, y=this._y, r;if(typeof s[y]==="string")s[y]=s[y].split(" ").reverse();r=s[y].pop();if(!s[y].length)this._y++;return f?r:+r;};g.prototype.l=function(f){var s=this._s[this._y++].split(" ");return f?s:s.map(a=>+a);};g.prototype.m=function(n,f){var r=this._s.slice(this._y,this._y+=n).map(a=>a.split(" "));return f?r:r.map(a=>a.map(a=>+a));};g.prototype.r=function(n,f){var r=this._s.slice(this._y,this._y+=n);return f?r:r.map(a=>+a);};return f;})();
var o=GET(require("fs").readFileSync("/dev/stdin","utf8"));

console.log(main());
function main(){
  var n = o.a();
  var a = o.a();
  var b = o.a();
  var c = Math.min(a,b);
  var d = Math.max(0,a+b-n)
  return c+" "+d;
}

Measured memory_bytes: 22076
#include <bits/stdc++.h>
#include <boost/range/irange.hpp>

using namespace std;
using namespace boost;

int main() {
    int h, w;
    cin >> h >> w;

    vector<vector<int32_t>> c(10, vector<int32_t>(10));
    for (auto i : irange(0, 10)) {
        for (auto j : irange(0, 10)) {
            cin >> c[i][j];
        }
    }

    for (auto i : irange(0, 10)) {
        for (auto j : irange(0, 10)) {
            for (auto k : irange(0, 10)) {
                c[j][k] = min(c[j][k], c[j][i] + c[i][k]);
            }
        }
    }

    vector<vector<int32_t>> a(h, vector<int32_t>(w));
    int64_t ans = 0;
    for (auto&& aa : a) {
        for (auto&& aaa : aa) {
            cin >> aaa;

            if (aaa >= 0) {
                ans += c[aaa][1];
            }
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 384
#include <iostream>

using namespace std;

int main(){
	int N, M;
	int *a = NULL;
	int *b = NULL;
	int toshi_num;

	cin >> N >> M;

	a = new int[M];
	b = new int[M];


	for(int i = 0; i < M; i++){
		cin >> a[i] >> b[i];
	}

	for(int i = 0; i < N; i++){
		toshi_num = 0;
		for(int j = 0; j < M; j++){
		if(i + 1 == a[j]){
			toshi_num++;
		}
		if(i + 1 == b[j]){
			toshi_num++;
		}
	}
		cout << toshi_num << endl;
	}


	delete[] a;
	delete[] b;
	return 0;

}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
#define MAX 100000
typedef long long llong;

int w[MAX];
int n, k;

int s1(llong P) {
	int j = 0;
	for ( int i = 0; i < k; i++ ) {
		llong s = 0;
		while ( s + w[j] <= P ) {
			s += w[j];
			j++;
			if ( j == n  ) return n;
		}
	}
	return j ;
}

llong s2() {
	llong left = 0;
	llong right = 100000 * 10000;
	llong  mid;
	while ( left < right - 1) {
		mid = (left + right)/2;
		llong P = mid;
		int i = s1(P);
		if ( i >= n) right = mid;
		else {
			left = mid;
		}
		//cout << P << endl;
	}
	return right;
}

int main() {
	cin >> n >> k;
	for ( int i = 0; i < n; i++ ) {
		cin >> w[i];
	}
	llong P = s2();
	cout << P << endl;
	return 0;
}


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

#define fi first
#define se second
#define sz(v) (int)((v).size())
#define pb push_back

typedef long long ll;

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

	int n; cin >> n;
	vector<int> a(n);
	set<int> s;
	string ans = "YES\n";
	for (int i=0; i<n; i++){
		cin >> a[i];
		if (s.find(a[i]) != s.end())
			ans = "NO\n";
		else
			s.insert(a[i]);
	}
	cout << ans ;

}


Measured memory_bytes: 13456
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
n,k = readInts()
A = readInts()
for i in range(n-k):
    if A[i] < A[i+k]:
        print('Yes')
    else:
        print('No')


Measured memory_bytes: 97060
//ヘッダー
#include<bits/stdc++.h>
using namespace std;

//型定義
typedef long long ll;

//定数
const int INF=1e+9;
const int MOD=1e+9+7;

//REPマクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define REP2(i,a,b) for(ll i=a;i<(ll)(b);i++)
#define REPD2(i,a,b) for(ll i=a;i>(ll)(b);i--)

// 多次元 vector 生成
template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

//vectorの扱い
#define ALL(x) (x).begin(),(x).end() //sortなどの引数省略
#define SIZE(x) ((ll)(x).size()) //size
#define MAX(x) *max_element(ALL(x)) //最大値
#define MIN(x) *min_element(ALL(x)) //最小値

int main(){
    ll M,K;
    cin>>M>>K;
    bool ok=false;
    ll idx;
   
    if(K==0){
        REP(i,pow(2,M)){
            cout<<i<<" "<<i;
            if(i!=pow(2,M)-1){
                cout<<" ";
            }else{
                cout<<endl;
            }
        }
    }else if(K>=pow(2,M)||M==1){
        cout<<-1<<endl;
    }else{
        deque<ll> ans;
        ans.push_back(K);
        REP(i,pow(2,M)){
            if(i==K) continue;
            ans.push_front(i);
            ans.push_back(i);
        }
        ans.push_back(K);
        REP(i,ans.size()){
            cout<<ans[i];
            if(i!=ans.size()-1){
                cout<<" ";
            }else{
                cout<<endl;
            }
        }    
    }
    // if(K>=pow(2,M)){
    //     cout<<-1<<endl;
    // }else{

    // }
}

Measured memory_bytes: 6232
#include <iostream>
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <cctype>
#include <string>
#include <map>
#include <set>
#include <math.h>
#include <cmath>
#define ll long long

using namespace std;

int main(){

  ll N, A;
  cin >> N;
  ll ans = 0;

  map<int ,int>m;
  for (int i = 0; i < N; i++) {
    cin >> A;
    m[A] += 1;
  }

  for(auto i = m.begin(); i != m.end(); i++) {
    if(i->second % 2 == 1) ans++;
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 4864
n = gets.to_s.to_i
a = [0] + gets.to_s.split.map{|i| i.to_i }

(n/2).downto(1) do |i|
  s = 0
  i.step(n,i).each{|j| s += a[j] }
  a[i] = s & 1
end

ans = (1..n).select{ |i| a[i] == 1 }
puts ans.size, ans * " "

Measured memory_bytes: 24316
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1000000007;

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;
}

/* mint、表示は変数名.x */
struct mint {
  ll x;
  mint(ll x = 0) : x((x % MOD + MOD) % MOD) {}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= MOD)
      x -= MOD;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += MOD - a.x) >= MOD)
      x -= MOD;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= MOD;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res -= a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res *= a;
  }
  /* 変数名.pow(n) */
  mint pow(ll t) const {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // 以降はMODが素数のみ
  mint inv() const { return pow(MOD - 2); }
  mint& operator/=(const mint a) { return (*this) *= a.inv(); }
  mint operator/(const mint a) const {
    mint res(*this);
    return res /= a;
  }
};

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

  if (abs(N - M) > 1) {
    cout << 0 << endl;
    return 0;
  }

  mint factorial[int(1e+5) + 1];
  factorial[1] = 1;
  repp(i, 2, int(1e+5)) {
    mint j = i;
    factorial[i] = j * factorial[i - 1];
  }

  mint ans = 1;
  if (N == M)
    ans *= 2;

  ans *= factorial[N];
  ans *= factorial[M];

  cout << ans.x << endl;
}

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

namespace ABC127
{
    class C
    {
        static void Main(string[] args)
        {
            int[] nm = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int[][] lr = new int[nm[1]][];
            int[] id = new int[2] { 1, nm[0] };
            for (int i = 0; i < nm[1]; i++)
            {
                lr[i] = Console.ReadLine().Split().Select(int.Parse).ToArray();
                id[0] = Math.Max(id[0], lr[i][0]);id[1] = Math.Min(id[1], lr[i][1]);
            }
            Console.WriteLine(Math.Max(id[1] - id[0] + 1,0));
        }
    }
}


Measured memory_bytes: 23868
N = STDIN.gets
a_ary = STDIN.gets.split.map(&:to_i)
alice_turn = true
alice = 0
bob = 0
a_ary.sort! {|a, b| b <=> a}
for a in a_ary do
    if alice_turn == true
        alice = alice + a.to_i
        alice_turn = false
    else
        bob = bob + a.to_i
        alice_turn = true
    end
end

puts alice.to_i - bob.to_i

Measured memory_bytes: 1788
#include <cstdio>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>

using namespace std;

int a[200000];

int main(){
	
	int N;
	cin >> N;
	
	for(int i = 0; i < 200000; i++){
		a[i] = 0;
	}
	
	for(int i = 0; i < N; i++){
		int num;
		cin >> num;
		a[num]++;
	}
	
	int ans = 0;
	
	for(int i = 0; i < 200000 - 2; i++){
		ans = max(ans, a[i] + a[i + 1] + a[i + 2]);
	}
	
	cout << ans << endl;
	
	return 0;
}



Measured memory_bytes: 1024
#include<stdio.h>
#include<string.h>
int strnum(char* a,char* b){
  int la=strlen(a),lb=strlen(b);
  if(la<lb)return -1;
  if(la>lb)return 1;
  return strcmp(a,b);
}//*/
int main(){
  char s[6][10]={"0","99999999","99999999","99999999","99999999","99999999"};
  char m[5][20]={"0","9999999999999999","9999999999999999","9999999999999999"};
  char d[20];
  int i,j,k,n;
  scanf("%d",&n);
  while(n--){
    scanf("%s",d);
    for(j=5;strnum(s[j-1],d)>0;j--)strcpy(s[j],s[j-1]);
    strcpy(s[j],d);
  }
  //for(i=0;i<5;i++)printf("%s\n",s[i]);
  for(i=1;i<5;i++){
    for(j=1;j<5;j++){
      if(i==j)continue;
      strcpy(d,s[i]);
      strcat(d,s[j]);//printf("%s\n",d);
      for(k=4;strnum(m[k-1],d)>0;k--)strcpy(m[k],m[k-1]);
      strcpy(m[k],d);
      //for(k=0;k<5;k++)printf("%s ",m[k]);printf("\n");
    }
  }
  printf("%s\n",m[3]);
  return 0;
}

  

Measured memory_bytes: 612
#include<bits/stdc++.h>
using namespace std;
int main(){
    std::cin.tie(nullptr);std::ios_base::sync_with_stdio(false);
    std::cout.setf(std::ios_base::fixed);std::cout.precision(15);
    double x;
    cin>>x;
    std::cout<<x*x*x/27<<endl;
}

Measured memory_bytes: 256
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, L = MAP()

azi = [L + i - 1 for i in range(1, N + 1)]

mi = INF
for i in range(N):
	if azi[i] < 0:
		d = azi[i]*-1
	else:
		d = azi[i]
	if d < mi:
		mi = d
		index = i

print(sum(azi[0:index]) + sum(azi[index + 1:N]))

Measured memory_bytes: 61676
// ~/SolverToBe/Developers/Corvus
// ~/sudo apt-get verdict Accpeted

#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <memory.h>
#include <limits.h>
#include <math.h>
#include <string.h>
#include <string>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <functional>
#include <assert.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
const int N = 100005, M = 1000005;
const ll MOD = 1e9 + 7;
const double eps = 1e-9;

int n, dp[N][2];
vector<vector<int> > g;

int dfs(int u,int p,int b) {
    int &r = dp[u][b];
    if(r!=-1)
        return r;
    vector<int> v;
    for(int i=0; i<g[u].size(); i++)
        if(g[u][i]!=p) 
            v.push_back((dfs(g[u][i],u,0) + (b ? 0 : dfs(g[u][i],u,1)))%MOD);
    if(!v.size()) r = 1;
    else {
        r = 1;
        for(int i=0; i<v.size(); i++)
            r = (1ll * r * v[i])%MOD;
    }
    return r;
}

int main() {
    scanf("%d",&n);
    g.resize(n);
    for(int i=1,a,b; i<n; i++) {
        scanf("%d%d",&a,&b);
        a--,b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    memset(dp,-1,sizeof dp);
    printf("%d\n", (dfs(0,-1,0) + dfs(0,-1,1))%MOD);
    return 0;
}

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

const ll MOD = 1e+9+7;
const int INF = 1e+9+7;

struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

int main(){
    int N,M;
    cin >> N >> M;
    vector<int> p(N);
    int tmp;
    rep(i,N){
        cin >> tmp;
        tmp--;
        p[i] = tmp;
    }
    UnionFind uf(N);

    int x,y;
    rep(i,M){
        cin >> x >> y;
        x--;
        y--;
        uf.unite(x,y);
    }

    int cnt=0;
    rep(i,N){
        if(uf.same(i,p[i])) cnt++;
    }
    cout << cnt << endl;
}

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

int main(){
  string S;
  cin>>S;
  int cnt=0;
  int ans=0;
  for(int i=0; i<S.size(); i++){
    if(S[i]=='A' || S[i]=='G' || S[i]=='C' || S[i]=='T'){
      cnt++;
      ans = max(cnt, ans);
      continue;
    }
    if(S[i] != S[i+1]){
          cnt = 0;
    }
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 256
N = int(input())
A = [0] + list(map(int, input().split())) + [0]

r = [0]

for i in range(1, len(A)):
	r += [r[-1] + abs(A[i - 1] - A[i])]

for i in range(1, len(A) - 1):
	print(r[i - 1] + abs(A[i + 1] - A[i - 1]) + (r[-1] - r[i + 1]))


Measured memory_bytes: 13920
#define __GLIBCXX_DEBUG

#include <iostream>
#include <iomanip>
#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 <random>
#include <queue>
#include <bitset>

#define pb push_back
#define int long long
#define dbl long double
#define str string
using namespace std;
const int M = 998244353;

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int n;
    cin >> n;
    string s;
    cin >> s;
    s = '-' + s;
    vector<int> R(n + 1), G(n + 1), B(n + 1);
    for (int i = 1; i <= n; i++) {
        R[i] = R[i - 1] + (s[i] == 'R');
        G[i] = G[i - 1] + (s[i] == 'G');
        B[i] = B[i - 1] + (s[i] == 'B');
    }
    int ans = 0;
    for (int i = 1; i <= n; i++) {
        for (int k = i + 1; k <= n; k++) {
            if (s[i] != s[k]) {
                for (auto c : {'R', 'G', 'B'}) {
                    if (s[i] != c && s[k] != c) {
                        if (c == 'R') ans += R[k] - R[i - 1];
                        if (c == 'B') ans += B[k] - B[i - 1];
                        if (c == 'G') ans += G[k] - G[i - 1];
                        if ((i + k) % 2 == 0 && s[(i + k) / 2] == c) ans--;
                    }
                }
            }
        }
    }
    cout << ans;
}

Measured memory_bytes: 3728
#include<bits/stdc++.h>
using namespace std;
#define int ll
#define ll long long

#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
// #define MOD 998244353 
#define MEM_SIZE 100010
#define DEBUG_OUT true
#define ALL(x) (x).begin(), (x).end()

template<typename T> void DEBUG(T e){if(DEBUG_OUT == false)return; std::cout << e <<" ";}
template<typename T> void DEBUG(const std::vector<T>& v){if(DEBUG_OUT == false)return;for(const auto& e : v){std::cout<< e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){if(DEBUG_OUT == false)return;for(const auto& v : vv){ DEBUG(v); } }
template<class T,class... Ts> void DEBUG(T d, Ts... e){if(DEBUG_OUT == false)return;DEBUG(d);DEBUG(e...);}
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; abort();}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }


void solve(void)
{
  int N;cin>>N;
  vector<int> vec (N,0);
  for (int i = 0; i < N; i++)
  {
     cin>>vec[i];
  }
  int NOW = INF;
  int M = 1000;
  for (int i = 0; i < N; i++)
  {
    if(NOW >= vec[i]) NOW = vec[i];
    else
    {

      M = M/NOW*vec[i] + M%NOW;
      NOW = vec[i];
    }
    // DEBUG(NOW,M,vec[i],"\n");
  }
  cout<<M<<endl;
  
  
  return;
}
int32_t main(int32_t argc, const char *argv[])
{
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  std::cout << std::fixed;
  std::cout << std::setprecision(11);
  solve();

  return 0;
}


Measured memory_bytes: 3660
#include <bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long ull;
typedef long double ld;
#define mp make_pair
#define F first
#define S second
#define pb push_back
#define pll pair<ll,ll>
#define pii pair<int,int>
#define all(v) v.begin(),v.end()
const ll INF = ll(1e9);
const int N = 2e5 + 5;
const ll mod = 1000000007 ;
using namespace std;

ll binpow(ll x, ll y) {
	ll z = 1;
	while (y) {
		if (y % 2) z = (z * x) % mod;

		y = y / 2;
		x = (x * x) % mod;
	}
	return z % mod;
}

int main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	ios_base::sync_with_stdio(false);
	cin.tie(NULL), cout.tie(NULL);


	ll tc = 1;

//	cin >> tc;

	while (tc--) {

		ll n, m, x;
		cin >> n >> m >> x;
		ll c[n];
		ll a[n][m];
		for (int i = 0; i < n; i++) {
			cin >> c[i];
			for (int j = 0; j < m; j++) {
				cin >> a[i][j];
			}
		}


		ll ans = LLONG_MAX;


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

			ll mx[m] = {0};
			ll cost = 0;

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

				if ((1 << j) & i) {

					cost += c[j];

					for (int k = 0; k < m; k++) {
						mx[k] += a[j][k];
					}


				}
			}


			bool f = 1;

			for (int j = 0; j < m; j++) {
				if (mx[j] < x) {
					f = 0;
					break;
				}
			}

			if (f) {
				ans = min(ans, cost);
			}
		}


		if (ans == LLONG_MAX)
			cout << -1 << endl;
		else
			cout << ans << endl;

	}

}

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

int main() {
  char a;
  cin >> a;

  if (a >= 97) {
    cout << "a" << endl;
  } else {
    cout << "A" << endl;
  }

  return 0;
}


Measured memory_bytes: 3588
#include "bits/stdc++.h"
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define vi vector<int>
#define all(a) a.begin(),a.end()
typedef pair<int,int> P;
const long long mod=1000000007;
const long long inf=1ll<<61;
int a[200006];
signed main(){
    int n,k;cin>>n>>k;
    rep(i,n)cin>>a[i];
    for(int i=k;i<n;i++){
        if(a[i-k]<a[i])puts("Yes");
        else puts("No");
    }
}

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

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

  long long int a,b,x;
  cin>>a>>b>>x;
   
   if(a%x==0)
   cout<<(b/x - a/x +1);
else
	cout<<(b/x - a/x);

  return 0;
}

Measured memory_bytes: 256
import math
a,b,h,m=map(int,input().split())
ad=((h*60+m)/2)%(12*60)
bd=m*6
p=min(abs(bd-ad),360-abs(bd-ad))
q=a**2+b**2-2*a*b*math.cos(p/180*math.pi)
print(abs(q**0.5))

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

typedef long long ll;

int main() {
	ios::sync_with_stdio(0);
	
	int n, h;
	cin >> n >> h;
	vector<int> a(n), b(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i] >> b[i];
	}
	sort(a.begin(), a.end(), greater<int>());
	sort(b.begin(), b.end(), greater<int>());
	int i = 0;
	int ans = 0;
	while (i < n && b[i] > a[0]) {
		h -= b[i];
		ans++;
		i++;
		if (h <= 0) {cout << ans; return 0;}
	}
	if (h % a[0] == 0) {ans += h/a[0];}
	else {ans += h/a[0] + 1;}
	cout << ans;
	
	return 0;
}

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

int main() {
  vector<int> v;
  int a;
  while(true){
    cin >> a;
    if (a == 0) break;
    v.push_back(a);
  }
  rep(i,v.size()) cout << "Case " << i +1 << ": " << v[i] << endl;
}


Measured memory_bytes: 3128
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long llong;
typedef unsigned long long ullong;

using namespace std;

int main()
{
	int w, s;
	cin >> s >> w;
	if( w >= s )
		cout << "unsafe";
	else
		cout << "safe";
	return 0;
}


Measured memory_bytes: 3632
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int d = sc.nextInt();
		int[] x = new int[n*d];
		int distanceBase = 0;
		double distance = 0;
		int ans = 0;
		
		for(int i=0;i<n*d;i++){
			x[i] = sc.nextInt();
		}
		for(int i=0;i<n;i++){
			for(int j=i+1;j<n;j++){
				for(int k=0;k<d;k++){
					distanceBase += (x[i*d+k]-x[j*d+k])*(x[i*d+k]-x[j*d+k]);
				}
				
				distance = Math.sqrt(distanceBase);
				if(distance - (int) distance == 0.0){
					ans ++;
				}
				distanceBase = 0;
			}
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 23252
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#define rep(i, n) for(i = 0; i < n; i++)
#define int long long
using namespace std;

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

int lcm(int a, int b) {
	return a / gcd(a, b) * b;
}

signed main() {
	int a, b;
	cin >> a >> b;
	cout << lcm(a, b) << endl;
	return 0;
}

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

Measured memory_bytes: 3624
#include <stdio.h>
int main(void)
{
          int n , rem ;
          scanf("%d", &n) ;
          while(n != 0 )
          {
                    rem = n % 10 ;
                    if( rem == 7)
                    {
                              printf("Yes") ;
                              return 0 ;
                    }
                    n = n / 10 ;
          }
          printf("No") ;
}


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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define ll long long 
#define F(n) for(int i = 0; i < n; ++i)
#define Debug cout<<endl<<"I AM IRONMAN"<<endl

int main ()
{
    fastio;
    int n,a[55],b[55];
    cin >> n;
    F(n)
    {
        cin >> a[i];
    }
    F(n)
    {
        cin >> b[i];
    }
    int sum=0;
    F(n)
    {
        if(a[i]-b[i]>0)
        {
            sum=sum+(a[i]-b[i]);
        }

    }
    cout << sum;


    return 0;
}

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

int M, N;
char A[50][51], B[50][51];

void solve() {
    bool match = false;
    for (int i = 0; i <= N-M; i++) {
        for (int j = 0; j <= N-M; j++) {
            bool f = true;
            for (int k = 0; k < M; k++) {
                for (int l = 0; l < M; l++) {
                    if (A[i+k][j+l] != B[k][l]) {
                        f = false;
                        break;
                    }
                }
                if (!f) break;
            }
            if (f) {
                match = true;
                break;
            }
        }
    }
    if (match) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

int main() {
    cin >> N >> M;
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            cin >> A[i][j];
        }
    }

    for (int i = 0; i < M; i++) {
        for (int j = 0; j < M; j++) {
            cin >> B[i][j];
        } 
    }

    solve();
}

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

using namespace std;
using ll =long long;
using vi = vector<int>; 
using vvi = vector<vi>; 
using vl = vector<ll>; 
using vvl = vector<vl>; 

#define rep(i,n) ;for( int i =0; i < n ; i ++)
#define all(a) a.begin(),a.end()
#define f(i,a,b) for(int i=a;i<b;i++)
#define MOD 1000000007
bool is_int_lround(double x){
  return std::lround(x)==x;
}
int ketasuu(int x){
  int n=0;
  while(x>0){
    x /=10 ;
    n ++;
  }
  return n;
}


ll conbi(int n,int m){
  
  cin>>n>>m;
  vector<ll> a(100);
  a[0] =1;
  for(int i=0;i<14;i++){
    a[i+1]=a[i]*(i+1);
  }
  return a[n] /(a[m] *a[n-m]);
}

int main(){
  int n;
  string s;
  cin>>n>>s;
  int ans =1;
  rep(i,s.size()-1) {
    if(s[i]!=s[i+1]) ans++;
  }
  cout<<ans<<endl;
}




Measured memory_bytes: 512
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int x = Integer.parseInt(sc.next());
        int ans = 0;
        ans = x / 500;
        if (ans == 0) {
            System.out.println((x / 5) * 5);
        } else {
            x %= 500;
            System.out.println(ans * 1000 + (x / 5) * 5);
        }
    }
}


Measured memory_bytes: 23380