akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <unordered_map>
#include <vector>

using namespace std;

int main()
{
    int n, m;

    while (cin >> n >> m, n) {
        vector<string> winning_num(n);
        unordered_map<string, int> hash;

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

            cin >> s >> m;
            winning_num[i] = s;
            hash[s] = m;
        }

        int sum = 0;
        for (int i = 0; i < m; ++i) {
            string s;

            cin >> s;
            for (int j = 0; j < n; ++j) {
                bool flag = true;

                for (int k = 0; k < 8; ++k) {
                    if (winning_num[j][k] != '*' && winning_num[j][k] != s[k]) {
                        flag = false;
                        break;
                    }
                }
                if (flag) {

                    sum += hash[winning_num[j]];
                    break;
                }
            }
        }

        cout << sum << endl;
    }

    return 0;
}

Measured memory_bytes: 1244
#include<bits/stdc++.h>
#define fastio 	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
using namespace std;
typedef long long int ll;

int mod = 1e9 + 7;
char mat[1001][1001];
int n, m;
int dp[1001][1001];

int find(int i, int j) {
	if (i == n - 1 && j == m - 1)
		return 1;

	if (i >= n || j >= m)
		return 0;

	if (mat[i][j] == '#')
		return 0;

	if (dp[i][j] != -1)
		return dp[i][j];

	dp[i][j] = (find(i + 1, j) + find(i, j + 1)) % mod;
	return dp[i][j] % mod;
}

int main() {
	cin >> n >> m;
	memset(dp, -1, sizeof dp);
	for (int i = 0; i < n; i++)
		for (int j = 0; j < m; j++)
			cin >> mat[i][j];
	cout << find(0, 0);
	return 0;
}



Measured memory_bytes: 8608
#include <iostream>
#include<iomanip>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#include <queue>
#define INF 1e9+7
#define rep(i,n) for(int i=0;i<n;i++)
#define NO cout<<"NO"<<endl;
#define YES cout << "YES"<<endl;
#define No cout << "No"<<endl;
#define Yes cout << "Yes"<<endl;
#define all(a) a.begin(),a.end()
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;


//(int)'a'は97 (int)'A'は65 (int)'1'は49
//おまじない


int main() {

	ull a, b, c;
	cin >> a >> b >> c;
	if (a % 2 == 1 && b % 2 == 1 && c % 2 == 1) {
		cout << min(a*b, min(a*c, b*c)) << endl;
	}
	else {
		cout << 0 << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

void merge(int *a, int a_size, int *b, int b_size);
void merge_sort(int *a, int size);

int works[1000000], a[100000];

int main(void)
{
	int n, i, j;
	long sum;
	
	while (1){
		sum = 0;
		scanf("%d", &n);
		if (n == 0)return (0);
		
		for (i = 0; i < n; i++)scanf("%d", &a[i]);
		merge_sort(a, n);
		
	//	for (i = 0; i < n; i++)printf("a[%d] = %d\n", i, a[i]);
		
		for (i = 1; i < n; i++)a[i] += a[i - 1];
	//	for (i = 0; i < n - 1; i++)printf("a[%d]2 = %d\n", i, a[i]);
		for (i = 0; i < n - 1; i++)sum += a[i];
		printf("%ld\n", sum);
		
	}
}

void merge_sort(int *a, int size)
{
	if (size == 1)return;
	
	merge_sort(&a[0], size / 2);
	merge_sort(&a[size / 2], size - size / 2);
	merge(&a[0], size / 2, &a[size / 2], size - size / 2);
}

void merge(int *a, int a_size, int *b, int b_size)
{
	int ah = 0, bh = 0, ch = 0, i;
	
	while (ah < a_size && bh < b_size){
		if (a[ah] < b[bh])works[ch] = a[ah++];
		else works[ch] = b[bh++];
		ch++;
	}
	
	while (ah < a_size)works[ch++] = a[ah++];
	while (bh < b_size)works[ch++] = b[bh++];
	for (i = 0; i < a_size + b_size; i++)a[i] = works[i];
	
}

Measured memory_bytes: 684
import java.util.Scanner;

public class Main {
	static int ans = 0;
	static long N;

	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		N = sc.nextInt();
		dfs(0, 0, 0, 0);
		System.out.println(ans);
	}

	private static void dfs(long x, int x3, int x5, int x7) {
		if (x3 > 0 && x5 > 0 && x7 > 0 && x <= N)
			ans++;
		if (x * 10 < N) {
			dfs(x * 10 + 3, x3 + 1, x5, x7);
			dfs(x * 10 + 5, x3, x5 + 1, x7);
			dfs(x * 10 + 7, x3, x5, x7 + 1);
		}
	}
}

Measured memory_bytes: 21844
#include<bits/stdc++.h>
#define reg register int
#define il inline
#define fi first
#define se second
#define mk(a,b) make_pair(a,b)
#define numb (ch^'0')
#define pb push_back
#define solid const auto &
#define enter cout<<endl
#define pii pair<int,int>
using namespace std;
typedef long long ll;
template<class T>il void rd(T &x){
    char ch;x=0;bool fl=false;while(!isdigit(ch=getchar()))(ch=='-')&&(fl=true);
    for(x=numb;isdigit(ch=getchar());x=x*10+numb);(fl==true)&&(x=-x);}
template<class T>il void output(T x){if(x/10)output(x/10);putchar(x%10+'0');}
template<class T>il void ot(T x){if(x<0) putchar('-'),x=-x;output(x);putchar(' ');}
template<class T>il void prt(T a[],int st,int nd){for(reg i=st;i<=nd;++i) ot(a[i]);putchar('\n');}
namespace Modulo{
const int mod=1e9+7;
il int ad(int x,int y){return x+y>=mod?x+y-mod:x+y;}
il int sub(int x,int y){return ad(x,mod-y);}
il int mul(int x,int y){return (ll)x*y%mod;}
il void inc(int &x,int y){x=ad(x,y);}
il void inc2(int &x,int y){x=mul(x,y);}
il int qm(int x,int y=mod-2){int ret=1;while(y){if(y&1) ret=mul(x,ret);x=mul(x,x);y>>=1;}return ret;}
template<class ...Args>il int ad(const int a,const int b,const Args &...args) {return ad(ad(a,b),args...);}
template<class ...Args>il int mul(const int a,const int b,const Args &...args) {return mul(mul(a,b),args...);}
}
using namespace Modulo;
namespace Miracle{
const int N=3003;
int n,m;
int f[N][N][2];
int main(){
    rd(n);rd(m);
    for(reg i=0;i<=n;++i) f[0][i][0]=1;
    //f[0][0][1]=1;
    for(reg i=1;i<=m;++i){
    	for(reg j=0;j<=n;++j){
    		/*f[i][j][0]=ad(f[i-1][j][0],(j!=0)*f[i-1][j][0]);
    		f[i][j][1]=ad(f[i-1][j][1],(j!=0)*f[i-1][j][1]);
    		if(j!=n){
    			if(j==0){
  					inc(f[i][j][1],ad(f[i-1][j+1][0],f[i-1][j+1][1]));
    			}else{
    				inc(f[i][j][0],f[i-1][j+1][0]);
    				inc(f[i][j][1],f[i-1][j+1][1]);
    			}
    		}
    		if(j){
    			inc(f[i][j][0],f[i-1][j-1][0]);
    			inc(f[i][j][1],f[i-1][j-1][1]);
    		}
    		if(j==0){
    			inc(f[i][j][1],f[i-1][j][1]);
    			inc(f[i][j][1],ad(f[i-1][j+1][0],f[i-1][j+1][1]));
    		}else if(j==n){
    			inc(f[i][j][1],f[i-1][j][1]);
    			inc(f[i][j][0],f[i-1][j][0]);
    			inc(f[i][j][1],f[i-1][j-1][1]);
    			inc(f[i][j][0],f[i-1][j-1][0]);
			}else{
				for(reg o=0;o<=1;++o){
					inc(f[i][j][o],mul(2,f[i-1][j][o]));
					inc(f[i][j][o],f[i-1][j-1][o]);
					inc(f[i][j][o],f[i-1][j+1][o]);
				}
			}*/
			
			
			inc(f[i][j][0],ad((j!=n)*f[i-1][j][0],(j!=1&&j!=0)*f[i-1][j][0]));
			inc(f[i][j][1],ad((j!=n)*f[i-1][j][1],(j!=0)*f[i-1][j][1],(j==1)*(f[i-1][j][0])));
			inc(f[i][j][0],ad((j!=n)*f[i-1][j+1][0],(j!=0&&j!=1)*f[i-1][j-1][0]));
			inc(f[i][j][1],ad((j!=n)*f[i-1][j+1][1],(j!=0)*f[i-1][j-1][1],(j==1)*f[i-1][j-1][0]));
			
//			inc(f[i][j][0],ad(
		}
	}	
	int ans=0;
	inc(f[m][0][1],f[m][0][0]);
	for(reg j=0;j<=n;++j){
		//cout<<" j "<<j<<" : [1] "<<f[m][j][1]<<" [0] "<<f[m][j][0]<<endl;
		inc(ans,f[m][j][1]);
	}
	ot(ans);
	return 0;
}

}
signed main(){
    Miracle::main();
    return 0;
}

/*
   Author: *Miracle*
*/

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

int main() {
  long n;
  cin >> n;
  vector<long>data;
  long c = 1,ans = 0;
  for(int i = 0;i < n;i++){
    long ai;
    cin >> ai;
    if(ai != c){
      ans++;
    }
    else{
      data.push_back(c);
      c++;
    }
  }
  if(data.size() == 0){
    cout << -1 << endl;
  }
  else{
    cout << ans << endl;
  }
}


Measured memory_bytes: 2420
A, B, K = map(int, input().split())

upstart = max(B - K + 1, 0)
uplim = min(upstart + K, B)
ans = set([a for a in range(A, min(A + K, B))] + [b for b in range(upstart, uplim + 1)])
ans = sorted(list(ans))
for a in ans:
    if a < A:
        continue
    print(a)


Measured memory_bytes: 9172
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <vector>
#include <queue>
#include <algorithm>
using namespace std;

int main(){
	int n;
	long long a[100000];
    scanf("%d", &n);
	for(int i=0;i<n;i++){
		scanf("%lld", &a[i]);
	}
	sort(a,a+n);
	long long p = a[n-1];
	long long r = 0;
	if(p%2==0){
		long long p2 = a[n-1]/2;
		for(int i=0;i<n-1;i++){
			if(abs(r-p2) > abs(a[i]-p2)) r = a[i];
		}
	}else{
		double p2 = (double)a[n-1]/2;
		for(int i=0;i<n-1;i++){
			if(abs((double)r-p2) > abs((double)a[i]-p2)) r = a[i];
		}
	}
	printf("%lld %lld\n", p, r);
 
	return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
#include<string>
#include<stack>
#include<queue>
using namespace std;

string d;
int n;
int A = 0;
queue<int> L1;
stack<int> L2;
bool s = false;
int depth = 0;
int b = 0;
int area = 0;
bool e = false;
int k = 0;

int main(){
	cin >> d;
	n = d.size();
	for (int i = 0; i < n; i++){
		if (s){
			if (d[i] == '\\'){
				depth--;
				area += -depth;
			}
			else if (d[i] == '/'){
				depth++;
				area += -depth;
				e = true;
				if (depth == 0)
				{
					b = i + 1;
					L1.push(area);
					A += area;
					k++;
					area = 0;
					s = false;
					e = false;
				}
			}
			else{
				area += -depth;
			}
		}
		else if (d[i] == '\\'){
			s = true;
			depth--;
			area += -depth;
		}
	}
	if (e)
	{
		s = false;
		depth = 0;
		area = 0;
		for (int i = n - 1; i >= b; i--){
			if (s){
				if (d[i] == '/'){
					depth--;
					area += -depth;
				}
				else if (d[i] == '\\'){
					depth++;
					area += -depth;
					if (depth == 0)
					{
						L2.push(area);
						A += area;
						k++;
						area = 0;
						s = false;
					}
				}
				else{
					area += -depth;
				}
			}
			else if (d[i] == '/'){
				s = true;
				depth--;
				area += -depth;
			}
		}
	}
	cout << A << endl;
	cout << k;
	while (!L1.empty()){
		cout << " " << L1.front();
		L1.pop();
	}
	while (!L2.empty())
	{
		cout << " " << L2.top();
		L2.pop();
	}
	cout << endl;
	cin >> A;
	return 0;
}

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

  int main() {
    int A,B;
    cin >> A >> B ;  //A==8,B==9を代入

    int C=A-1; //C==7
    int D=1;  

    for(int i=0; i<100; i++){
     
     
      if(D>=B){
        cout << i << endl;
       break;
      }
      D+=C; //D==8
     
    }
  }


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

int main() {
	int N,T,n,t,m,all,l;
	m = 0;
	cin >> N >> T;
	cin >> m;
	all = T;
	for (n = 1; n < N; ++n) {
		cin >> t;
		l = t - m;
		if (l < T) {
			all = all + l ;
			m = t;
		}
		else {
			all = all + T;
			m = t;
		}
	}
	cout << all << endl;
		
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long a,b,c,d;
  cin >> a >> b >> c >> d;
  long long ac,ad,bc,bd;

  ac = a * c;
  ad = a * d;
  bc = b * c;
  bd = b * d;

  cout << max({ac,ad,bc,bd}) <<endl;
}

   
    


Measured memory_bytes: 3632
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <utility>
using namespace std;
typedef long long ll;

ll MOD = 1e9+7;

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

class segtree
{
	public:
	vector<ll> v;
	int size;
	int depth;

	//コンストラクタ
	segtree(int s)
	{
		size=1;
		depth=0;
		while(size<s)
		{
			size*=2;
			depth++;
		}
		size*=2;
		vector<ll> tmp(size);
		v=tmp;
	}

	//初期化関数
	void initialize(vector<ll> t)
	{
		for(int i=0;i<t.size();i++)
			v[(1<<depth)+i]=t[i];
		for(int i=t.size();i<(1<<depth);i++)
			v[(1<<depth)+i]=0;//余った部分を埋める
		
		//下からセグ木の各ノードを確定させる
		for(int d=depth-1;d>-1;d--)
		{
			for(int i=0;i<(1<<d);i++)
			{
				int index=(1<<d)+i;
				v[(1<<d)+i]=gcd(v[index*2],v[index*2+1]);
			}
		}
		return;
	}

	//元の数列の指定の区間から値を取ってくる
	ll pick(int l,int r)
	{
		l+=(1<<depth);
		r+=(1<<depth);//セグ木上の位置に読み替える
		ll nowl=v[l];
		ll nowr=v[r];
		cerr<<nowl<<" "<<nowr<<endl;
		//下から区間クエリを確定する
		for(int d=depth-1;d>-1;d--)
		{
			//lとrが同じ区間に乗ったら終わり
			if(l/2==r/2)
				break;
			//左側はより右側の更新
			if((l&1)==0)
				nowl=gcd(nowl,v[l+1]);
			//右側はより左側の更新
			if((r&1)==1)
				nowr=gcd(nowr,v[r-1]);
			l/=2;
			r/=2;
		}
		cerr<<nowl<<" "<<nowr<<endl;
		return gcd(nowl,nowr);
	}
};

int main()
{
	int n;
	ll ans=0;
	cin>>n;
	segtree seg=segtree(n);
	vector<ll> a(n);
	for(int i=0;i<n;i++)
		cin>>a[i];
	seg.initialize(a);
	ans=max(seg.pick(1,n-1),seg.pick(0,n-2));
	for(int i=1;i<n-1;i++)
	{
		ll tmp=gcd(seg.pick(0,i-1),seg.pick(i+1,n-1));
		ans=max(ans,tmp);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 4352
from collections import Counter

N, M = map(int, input().split())
A = list(map(int, input().split()))

B = [0]
for i in range(N):
  B.append((B[-1]+A[i])%M)

C = Counter(B)
ans = 0

for mod, c in C.most_common():
  ans += c*(c-1)//2

print(ans)

Measured memory_bytes: 24748
#include<stdio.h>
#define WHITE 0
#define GRAY 1
#define BLACK 2

int color[100];
int n,M[100][100];
int S[1000],top=0;
int open[100],close[100],time;
int nt[100];

void push(int x){
  S[++top]=x;
}

int pop(){
  top--;
  return S[top+1];
}

int empty(){
  return top==0;
}

int next(int u){
  int v;
  for(v=nt[u];v<n;v++){
    nt[u]=v+1;
    if(M[u][v])return v;
  }
  return -1;
}

void dfs_visit(int r){
  int i,u,v;
  for(i=0;i<n;i++) nt[i]=0;
  push(r);
  color[r]=GRAY;
  open[r]=++time;

  while(!empty()){
    u=S[top];
    v=next(u);
    if(v!=-1){
      if(color[v]==WHITE){
	color[v]=GRAY;
	open[v]=++time;
	push(v);
      }
    }
    else{
      pop();
      color[u]=BLACK;
      close[u]=++time;
    }
  }
}

void dfs(){
  int i;
  for(i=0;i<n;i++){
    color[i]=WHITE;
    nt[i]=0;
  }
  time=0;

  int u;

  for(u=0;u<n;u++){
    if(color[u]==WHITE) dfs_visit(u);
  }
  for(i=0;i<n;i++){
    printf("%d %d %d\n",i+1,open[i],close[i]);
  }
}

int main(){
  int u,k,v;
  int i,j;
  
  scanf("%d",&n);

  for(i=0;i<n;i++){
    for(j=0;j<n;j++) M[i][j]=0;
  }

  for(i=0;i<n;i++){
    scanf("%d%d",&u,&k);
    u--;
    for(j=0;j<k;j++){
      scanf("%d",&v);
      v--;
      M[u][v]=1;
    }
  }
  dfs();
  return 0;
}



Measured memory_bytes: 2112
#include <iostream>
#include <algorithm>
#include <tuple>
#include <vector>
#include <string>
#include <queue>
#include <cmath>
#include <set>
#include <map>
#include <cassert>

using namespace std;
using ll = long long;

int main()
{
    int a, b, c, k;
    cin >> a >> b >> c >> k;
    for(int i = 0; i < k; i++){
        if(a >= b){
            b *= 2;
        }else if(b >= c){
            c *= 2;
        }
    }
    if(a < b && b < c){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    
    return 0;
}

Measured memory_bytes: 3632
H,W = map(int,input().strip().split())
lines = []
for i in range(H):
    lines.append(input().strip())
chars = {}
for line in lines:
    for c in line:
        if c not in chars:
            chars[c]=0
        chars[c]+=1

def judge(H,W,chars):
    if H%2 + W%2==2:
        ones = 1
        twos = (H + W - 2)//2
    elif H%2 + W%2==0:
        ones = 0
        twos = 0
    elif H%2 == 1:
        ones = 0
        twos = W//2
    else:
        ones = 0
        twos = H//2
    for c in chars:
        if ones<0 or twos<0:
            return False
        chars[c] %= 4
        if chars[c]==0:
            continue
        if chars[c] == 2:
            twos-=1
        elif chars[c] == 3:
            twos-=1
            ones-=1
        else:
            ones-=1
    return True


if judge(H, W, chars):
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (long long i = j; i < (long long)(n); i++)
#define _GLIBCXX_DEBUG
#define MOD 1000000007
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
//name[i][j]-> vvl name(i,vl(j))
//map<int,int>mp
//余りを切り上げる =>  (a + b - 1) / b 

signed main(){
	int a,b; cin>>a>>b;
	if(a*b%2==0) cout<<"No"<<endl;
	else cout<<"Yes"<<endl;
	
	return 0;
}

Measured memory_bytes: 3552
import java.util.ArrayList;
import java.util.Comparator;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		new Main().solve();
	}
	static int N,W;
	static int w0;
	static ArrayList<Integer>[] v=new ArrayList[4];
	
	static void solve(){
		Scanner sc = new Scanner(System.in);
		N = sc.nextInt();
		W = sc.nextInt();
		
		for (int i = 0; i < v.length; i++) {
			v[i]=new ArrayList<Integer>(N);
		}
		w0=sc.nextInt();
		v[0].add(sc.nextInt());
		
		for(int i=1;i<N;i++){
			int w=sc.nextInt();
			v[w-w0].add(sc.nextInt());
		}
		for(int i=0;i<v.length;i++){
			v[i].sort(Comparator.reverseOrder());
		}
		
		System.out.println(solve2(0,N,0));
	}
	static int solve2(int startIndex,int numLeft,int totalW){
		
		if(startIndex>=v.length){
			return 0;
		}
		
		int vi=0;
		int wi=totalW;
		int max_v=0;
		
		for(int n=0;n<=numLeft && n<=v[startIndex].size();n++){
			if(n>=1){
				vi+=v[startIndex].get(n-1);
				wi+=w0+startIndex;
			}
			if(wi>W)break;
			
			max_v=Integer.max(max_v, vi+solve2(startIndex+1,numLeft-n,wi));
		}
		return max_v;
	}
}


Measured memory_bytes: 23764
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <functional>
#include <map>

int main() {
	int n, m;
	std::cin >> n >> m;
	int i = 1;
	int max = 1;
	while (i * i <= m) {
		if (m % i == 0) {
			if (i >= n && max < m / i) {
				max = m / i;
			}
			if (m / i >= n && max < i) {
				max = i;
			}
		}
		++i;
	}
	std::cout << max << std::endl;
}

Measured memory_bytes: 256
#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 = 1e9 + 7;

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

map<ll, ll> prime_factor(ll n) {
  map<ll, ll> res;
  for (ll i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      ++res[i];
      n /= i;
    }
  }
  if (n != 1) res[n] = 1;
  return res;
}

int main() {
  int N;
  cin >> N;
  vector<int> a(N);
  rep(i, N) cin >> a[i];

  int ans = 0;
  rep(i, N) {
    map<ll, ll> p = prime_factor(a[i]);
    ans += p[2];
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
// #include <math.h>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <map>

//#include <bits/stdc++.h>
using namespace std;
#define print(x) cout<<(x)<<endl
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define ll long long int
#define pb push_back

int main() {
  string s, t, u;
  cin >> s >> t >> u;

  cout << char(s[0] - 'a' + 'A') << char(t[0] - 'a' + 'A') << char(u[0] - 'a' + 'A') << endl;

}


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

int store[200007];

int main()
{
    int n, t;
    cin >> n >> t;

    for (int i = 0; i < n; i++) {
        scanf("%d", &store[i]);
    }

    ll cnt = 0;
    for (int i = 1; i < n; i++) {
        ll interval = store[i] - store[i-1];
        if (interval > t) interval = t;
        cnt += interval;
    }

    cnt += t;
    cout << cnt << "\n";
}


Measured memory_bytes: 1024
#include <float.h>
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

// 内部定数
#define D_MOD			1000000007								// 除数(10の9乗+7)
#define D_STEP_MAX		100005									// 最大段数

// 内部変数
static FILE *szpFpI;											// 入力
static int si1MPtn[D_STEP_MAX];									// 移動パターン[段]
static int siSCnt;												// 段数

// 内部変数 - テスト用
#ifdef D_TEST
	static int siRes;
	static FILE *szpFpA;
	static int siTNo;
#endif

// 出力
int
fOut(
	char *pcpLine				// <I> １行
)
{
	char lc1Buf[1024];

#ifdef D_TEST
	fgets(lc1Buf, sizeof(lc1Buf), szpFpA);
	if (strcmp(lc1Buf, pcpLine)) {
		siRes = -1;
	}
#else
	printf("%s", pcpLine);
#endif

	return 0;
}

// 実行メイン
int
fMain(
)
{
	int i;
	char lc1Buf[1024];

	// 段数・破損数 - 取得
	int liBCnt;
	fgets(lc1Buf, sizeof(lc1Buf), szpFpI);
	sscanf(lc1Buf, "%d%d", &siSCnt, &liBCnt);

	// 破損 - 取得
	for (i = 0; i < liBCnt; i++) {
		int liSNo;
		fgets(lc1Buf, sizeof(lc1Buf), szpFpI);
		sscanf(lc1Buf, "%d", &liSNo);
		si1MPtn[liSNo] = -1;
	}

	// 移動パターン - セット
	si1MPtn[0] = 1;
	for (i = 0; i < siSCnt; i++) {
		if (si1MPtn[i] < 0) {
			continue;
		}

		if (si1MPtn[i + 1] >= 0) {
			si1MPtn[i + 1] += si1MPtn[i];
			si1MPtn[i + 1] %= D_MOD;
		}

		if (si1MPtn[i + 2] == 0) {
			si1MPtn[i + 2] = si1MPtn[i];
		}
	}

	return si1MPtn[siSCnt];
}

// １回実行
int
fOne(
)
{
	int liRet;
	char lc1Buf[1024];

	// データ - 初期化
	memset(si1MPtn, 0, sizeof(si1MPtn));						// 移動パターン

	// 入力 - セット
#ifdef D_TEST
	sprintf(lc1Buf, ".\\Test\\T%d.txt", siTNo);
	szpFpI = fopen(lc1Buf, "r");
	sprintf(lc1Buf, ".\\Test\\A%d.txt", siTNo);
	szpFpA = fopen(lc1Buf, "r");
	siRes = 0;
#else
	szpFpI = stdin;
#endif

	// 実行メイン
	liRet = fMain();

	// 出力
	sprintf(lc1Buf, "%d\n", liRet);
	fOut(lc1Buf);

	// 残データ有無
#ifdef D_TEST
	lc1Buf[0] = '\0';
	fgets(lc1Buf, sizeof(lc1Buf), szpFpA);
	if (strcmp(lc1Buf, "")) {
		siRes = -1;
	}
#endif

	// テストファイルクローズ
#ifdef D_TEST
	fclose(szpFpI);
	fclose(szpFpA);
#endif

	// テスト結果
#ifdef D_TEST
	if (siRes == 0) {
		printf("OK %d\n", siTNo);
	}
	else {
		printf("NG %d\n", siTNo);
	}
#endif

	return 0;
}

// プログラム開始
int
main()
{

#ifdef D_TEST
	int i;
	for (i = D_TEST_SNO; i <= D_TEST_ENO; i++) {
		siTNo = i;
		fOne();
	}
#else
	fOne();
#endif

	return 0;
}



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

// types
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;

// macros
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

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

  ll h,w;
  cin >> h >> w;
  vector<vector<char>> a(h, vector<char>(w));


  REP(i, h){
    REP(j, w)
      cin >> a[i][j];
  }

  REP(j, w+2)
    cout << "#";
  cout << endl;

  REP(i, h){
    cout << "#";
    REP(j, w)
      cout << a[i][j];
    cout << "#" << endl;

  }

  REP(j, w+2)
    cout << "#";
  cout << endl;


}


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

using namespace std;

int main()
{
	int n, m, a, b, c[9][9]{};
	cin >> n >> m;
	for (int i = 0; i < m; ++i)
	{
		cin >> a >> b;
		c[a][b] = c[b][a] = 1;
	}

	int p[8], ans = 0;
	iota(begin(p), begin(p) + n, 1);
	do 
	{
		bool ok = true;
		for (int i = 0; i < n - 1; i++)
			if (!c[p[i]][p[i+1]])
				ok = false; 
		if (ok)
			ans++;
	} while (next_permutation(begin(p) + 1, begin(p) + n));

	cout << ans << endl;

}


Measured memory_bytes: 3568
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

using namespace std;
#define ll long long
#define rep(i,n) for (int i = 0; i < n; i++)
#define rrep(i,n) for (int i = n-1; i >= 0; i--)
#define MOD (1000000007)
#define vi vector<int>
#define vl vector<ll>
#define vb vector<bool>
#define vvi vector<vi>
#define vvl vector<vl>
#define pii pair<int, int>
#define pli pair<ll, int>a
#define pb push_back
#define sz(x) int(x.size())

#define mp make_pair
#define all(a) (a).begin(),(a).end()

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

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

const ll INF = 1LL << 60;

const int dh[4] = {1,0,-1,0};
const int dw[4] = {0,1,0,-1};

class UnionFind{
  public:
  vi Parent;
  UnionFind(int n){
    Parent = vi(n,-1);
  }

  int root(int a){
    if(Parent[a] < 0) return a;
    else return Parent[a] = root(Parent[a]);
  }

  int size(int a){
    return -Parent[root(a)];
  }

  bool merge(int a, int b){
    a = root(a);
    b = root(b);
    if(a == b) return false;

    if(size(a) < size(b)) swap(a,b);
    Parent[a] += Parent[b];
    Parent[b] = a;

    return true;
  }
};

class Factrial{
  public:
  vl Fac;
  Factrial(int MAX){
    Fac = vl(MAX+1);
    rep(i,MAX) {
      if(i == 0) Fac[i+1] = 1;
      else Fac[i+1] = ((i+1)*Fac[i])%MOD;
    }
  }
};

int main(){
  string s; int w; cin >> s >> w;
  string ans;
  for(int i = 0; i < sz(s); i += w) {
    ans += s[i];
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
#include <cassert>
#include <queue>
#include <set>
#include <map>
#include <valarray>
#include <bitset>
#include <stack>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
const int INF = 1<<29;

int main() {
  int n, k, m;
  while(cin>>n>>k>>m,n||k||m) {
    vector<int> v(n);
    REP(i, n) v[i] = i;
    m--;
    int now = m;
    while(v.size()>1) {
      //cout << now << " " << v[now] << endl;
      v.erase(v.begin() + now);
      now = (now+k-1)%v.size();
    }
    cout << v[0]+1 << endl;
  }
}

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

#define MAXLEN 100010

int main()
{
	int n;
	
	while (cin >> n)
	{
		vector <int> count(MAXLEN);
		
		for (int i = 0; i < n; i++)
		{
			int num;
			cin >> num;
			count[num+1]++;
		}
		
		int maxi = 0;
		
		for (int i = 1; i < MAXLEN - 1; i++)
		{
			int sum = count[i-1] + count[i] + count[i+1];
			
			if (maxi < sum)
				maxi = sum;
		}
		
		cout << maxi << endl;
	}
	
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
/* constant */
const int INF = 1 << 30;
const int NIL = -1;
const int MAX = 10000;
const int mod = 1000000007;
const double pi = 3.141592653589;
struct mint {
    ll x;
    mint(ll x = 0):x((x % mod + mod) % mod) {}
    mint operator-() const { return mint(-x); }
    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;
    }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }

    // for prime 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;
    }
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
struct combination {
    // vector size : n + 1
    vector<mint> fact, ifact;
    // precaliculation O(n)
    combination(int n):fact(n+1), ifact(n+1) {
        assert(n < mod);
        // 0! = 1;
        fact[0] = 1;
        // 1! = 0! * 1 ... n! = (n-1)! * n
        for (int i = 1; i <= n; i++) fact[i] = fact[i-1] * i;
        // 1/n! = n!^(-1)
        ifact[n] = fact[n].inv();
        // (n-1)!^(-1) = n!^(-1) * n ... 0!^(-1) = 1!^(-1) * 1
        for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i] * i;
    }
    // combination O(1)
    // nCk = n! / (k! * (n-k)!)
    //     = n! * k!^(-1) * (n-k)!^(-1)
    mint operator()(int n, int k) {
        if (k < 0 || k > n) return 0;
        return fact[n] * ifact[k] * ifact[n-k];
    }
};
struct Partition {
    vector<vector<mint> > P;
    Partition(int m) : P(m + 1, vector<mint>(m + 1, 0)) {
        for (int k = 0; k <= m; ++k) P[0][k] = 1;
        for (int n = 1; n <= m; ++n) {
            for (int k = 1; k <= m; ++k) {
                P[n][k] = P[n][k-1] + (n-k >= 0 ? P[n-k][k] : 0);
            }
        }
    }
    mint operator()(int n, int k) {
        if (n < 0 || k < 0) return 0;
        return P[n][k];
    }
};
/* global variables */
/* function */
/* main */
int main() {
    int n, k;
    cin >> n >> k;
    Partition p = Partition(max(n, k));
    cout << p(n, k) << '\n';
}


Measured memory_bytes: 10688
H,W=map(int,input().split())
ans=[[] for i in range(H+2)]
ans[0]=["#"]*(W+2)
ans[H+1]=["#"]*(W+2)
for i in range(1,H+1):
  ans[i]="#"+input()+"#"
for i in range(H+2):
  print("".join(ans[i]))

Measured memory_bytes: 3060
#include <iostream>
// #include string
int s;
int one;
int ten;
int hund;
int thou;
bool difficult;
std::string goodbad;

int main() {
    std::cin >> s;
    one = s % 10;
    ten = (s % 100) / 10;
    hund = (s % 1000) / 100;
    thou = s / 1000;

    difficult = (one == ten) || (ten == hund) || (hund == thou);
    if (difficult) {
        goodbad = "Bad";
    } else {
        goodbad = "Good";
    }

    std::cout << goodbad;
}

Measured memory_bytes: 3612
#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, a_, b_, a, b, ...) for (int i = (a), i##_len = (b); i < i##_len; ++i)
#define rep(i, ...) rep_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define reprev_(i, a_, b_, a, b, ...) for (int i = (b-1), i##_min = (a); i >= i##_min; --i)
#define reprev(i, ...) reprev_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#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, k; cin >> n >> k;
    vector<ll> a(n); 
    rep (i, n) {
        cin >> a[i];
        a[i]--;
    }
    vector<int> next(n + 1);
    map<int, int> m;
    m[0] = 1; // +1
    ll shuki; bool flg = false;
    rep (i, n) {
        next[i + 1] = a[next[i]];
        if (m[next[i + 1]] != 0) {
            shuki = i + 2 - m[next[i + 1]];
            flg = true;
            // break;
        }
        m[next[i + 1]] = i + 2;
    }
    rep (i, n + 1) eprintf("%d ", next[i]); eprintf("\n");
    if (k <= n) cout << next[k] + 1<< "\n";
    else {
        ll z = k - n;
        ll y = (z - 1) / shuki + 1;
        eprintf("%lld %lld %lld\n", y, shuki, k - y * shuki);
        cout << next[k - y * shuki] + 1<< "\n";
    }
    return 0;
}

Measured memory_bytes: 14640
#!python3

import sys
iim = lambda: map(int, sys.stdin.readline().rstrip().split())

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

    dp = [0]*(N+1)
    for i in range(1, N+1):
        for i in range(0, N+1, i):
            dp[i] += 1
    ans = 0
    for i in range(1, N+1):
        ans += i*dp[i]
    print(ans)

if __name__ == "__main__":
    resolve()


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

using namespace std;

const long long maxn = 3e5+7, mod = 1e9+7, inf = 1e9;
long long n, dp_help[maxn], dp[maxn], a[maxn], ans;

int main() {
	
	ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	
	cin >> n;
	for (int i = 1; i <= n; i ++) cin >> a[i];
	dp[0] = 1;
	for (int i = 1; i <= n; i ++) {
		if (a[i] != a[i - 1]) dp_help[a[i]] += dp[i - 1] , dp[i] = dp_help[a[i]];
		else dp[i] = dp[i - 1];
		dp[i] %= mod , dp_help[a[i]] %= mod;
	}
	cout << dp[n] << endl;

	return 0;

}

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

n = int(input())
l = [list(map(int, input().split())) for _ in range(n) ]
l = sorted(l, key=lambda x:(x[1]))

ans = 0
for x in l:
    ans += x[0]
    if ans > x[1]:
        print('No')
        exit()
print('Yes')

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

int main() {
  string s;
  cin >>s;
  int cnt = 0;
  string t,u;
  for(int i  = 0; i<s.size();i++){
    t += s[i];
    if(t!=u){
      cnt++;
      u = t;
      t = "";
    }
  }
  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){return o<<"("<<p.fs<<","<<p.sc<<")";}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){o<<"sz = "<<vc.size()<<endl<<"[";for(const T& v:vc) o<<v<<",";o<<"]";return o;}
int H,W;
typedef pair<int,int> P;
int ids[500*500];
bool ok(vector<P> vp){
	rep(i,H*W) ids[i]=0;
	int N=vp.size();
	rep(i,N){
		int in=vp[i].fs,out=vp[i].sc;
		if(in>out) swap(in,out);
		ids[in]=i+1;
		ids[out]=-(i+1);
	}
	stack<int> st;
	rep(i,H*W) if(ids[i]!=0){
		int x=ids[i];
		if(x>0){
			st.push(x);
		}else{
			int y=st.top();st.pop();
			if(-x!=y) return 0;
		}
	}
	return 1;
}
int p[500*500];
bool solve(){
	cin>>H>>W;
	rep(i,H*W){
		int a;
		cin>>a;
		p[a]=i;
	}
	vector<P> vp[2];
	rep(i,H) rep(j,W-1){
		vp[j%2].pb(P(p[i*W+j],p[i*W+j+1]));
	}
	if(!ok(vp[0])||!ok(vp[1])) return 0;
	vp[0].clear(),vp[1].clear();
	rep(j,W) rep(i,H-1){
		vp[i%2].pb(P(p[i*W+j],p[(i+1)*W+j]));
	}
	if(!ok(vp[0])||!ok(vp[1])) return 0;
	return 1;
}
int main(){
	if(solve()) puts("YES");
	else puts("NO");
}

Measured memory_bytes: 8796
/*
　　こんにちは。あたしはｶｳｶﾞｰﾙ。
　　redcoderになるためAtCoderを巡る旅をしてます。

　　　 　 ＿_
　　　 ヽ|＿_|ノ　　　　ﾓｫ
　　　　||‘‐‘||ﾚ　　_)_, ―‐ 、
　　　　/(Ｙ (ヽ＿ /・ ヽ　　 ￣ヽ
　　　　∠ ＿ ゝ　 ｀^ヽ ﾉ.::::_(ノヽ
　　　　 _/ヽ　 　　  /ヽ￣￣/ヽ
*/

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define dump(x) cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl

#define rep(i, n) REP(i, 0, n)                  // 0, 1, ..., n-1
#define REP(i, x, n) for(int i = x; i < n; i++) // x, x + 1, ..., n-1
#define FOREACH(x, a) for(auto &(x) : (a))

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()

#define COUT(x) cout << (x) << endl

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

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

    int r;
    cin >> r;
    COUT(pow(r, 2));
}


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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit(b) (1ll << (b))
#define uniq(v) (v).erase(unique(all(v)), (v).end())
#define rsort(v) sort(all(v)); reverse(all(v))

using namespace std;

using i32 = int;
using i64 = long long;
using f80 = long double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << '\n'; exit(0); }
inline void no() { cout << "No" << '\n'; exit(0); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { return a / gcd(a, b) * b; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }
template<typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template<typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template<typename T> inline void amax(T &x, T y) { if (x < y) x = y; }
template<typename T> inline void amin(T &x, T y) { if (x > y) x = y; }
template<typename T> inline T power(T x, i64 n) { T r = 1; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template<typename T> istream& operator>>(istream &is, vector<T> &v) { for (auto &x : v) is >> x; return is; }
template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }

void solve() {
  int N; cin >> N;
  vi32 A(N); cin >> A;
  i64 ans = 1e18;
  {
    i64 cnt = 0;
    i64 sum = A[0];
    if (sum <= 0) cnt += abs(sum) + 1, sum = 1;
    for (int i = 1; i < N; i++) {
      i64 nsum = sum + A[i];
      if (nsum == 0 || ((sum > 0) == (nsum > 0))) {
        cnt += abs(nsum) + 1;
        sum = sum > 0 ? -1 : 1;
      } else {
        sum = nsum;
      }
    }
    amin(ans, cnt);
  }
  {
    i64 cnt = 0;
    i64 sum = A[0];
    if (sum >= 0) cnt += abs(sum) + 1, sum = -1;
    for (int i = 1; i < N; i++) {
      i64 nsum = sum + A[i];
      if (nsum == 0 || ((sum > 0) == (nsum > 0))) {
        cnt += abs(nsum) + 1;
        sum = sum > 0 ? -1 : 1;
      } else {
        sum = nsum;
      }
    }
    amin(ans, cnt);
  }
  cout << ans << '\n';
}


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

int main(){
  int n;
  cin >> n ;
  if (n %2 ==0){
    cout <<  n << endl;
  }
  else{
    
  for (int k = n/2+1; k <=n ; k++){
    if (2 * k % n == 0  ){
      cout << 2 * k << endl;
      break;
    }
    else
      continue;
  }
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define rep(i, n) ;for (int i = 0;i < (int)(n);i++)
#define rep2(i, s, n) ;for (int i = s; i < (int)(n);i++)
#define ALL(vec)  (vec).begin(),(vec).end()
#define pi 3.1415926535897932384626433832795
#define MAX_INF 9223372036854775807
#define MIN_INF (922337203685477587+1)
#define sosuu 1000000007

int main() {
  unsigned long long X;
  cin >> X;
  unsigned long long kane=100;
  int ans=0;
  if(X>=100000000000000000)
  {ans=3529;
  kane=100837569714320080;
    while(kane<X){
      int keep=kane%100;
  kane/=100;
    kane*=101;
      kane+=keep;
    ans++;
  }
  }
  while(kane<X){
  kane*=101;
    kane/=100;
    ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3640
#pragma region
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <list>
#include <iomanip>
#include <cstdint>
#include <bitset>

using namespace std;
typedef long long ll;
//#define rep(i, s, e) for (int(i) = (s); (i) < (e); ++(i))
#define rep(i, e) for (int(i) = 0; (i) < (e); ++(i))
#define rrep(i, s) for (int(i) = (s) - 1; (i) >= 0; --(i))
#define all(x) x.begin(),x.end()

#pragma region UnionFind
struct UnionFind
{
	vector<int> par;

	UnionFind(int n) : par(n, -1) {}
	void init(int n) { par.assign(n, -1); }

	int root(int x)
	{
		if (par[x] < 0) return x;
		else return par[x] = root(par[x]);
	}

	bool issame(int x, int y)
	{
		return root(x) == root(y);
	}

	bool merge(int x, int y)
	{
		x = root(x); y = root(y);
		if (x == y) return false;
		if (par[x] > par[y]) swap(x, y);
		par[x] += par[y];
		par[y] = x;
		return true;
	}

	int size(int x)
	{
		return -par[root(x)];
	}
};
#pragma endregion
#pragma region GCD
ll gcd(ll a, ll b)
{
	if (b == 0)return a;
	return gcd(b, a%b);
}
#pragma endregion
#pragma region LCM
ll lcm(ll a, ll b)
{
	return a / gcd(a, b) * b;
}
#pragma endregion
#pragma region chmin
template<class T> inline bool chmin(T& a, T b)
{
	if (a > b)
	{
		a = b;
		return true;
	}
	return false;
}
#pragma endregion
#pragma region chmax
template<class T> inline bool chmax(T& a, T b)
{
	if (a < b)
	{
		a = b;
		return true;
	}
	return false;
}
#pragma endregion
#pragma endregion


int main()
{
	int n, k; cin >> n >> k;
	vector<int> p(n + 1); rep(i, n)cin >> p[i + 1];
	vector<ll> c(n + 1); rep(i, n)cin >> c[i + 1];
	ll res = -1e18;
	for (int i = 1; i <= n; ++i)
	{
		int now = i;
		int loop_size = 0;
		ll loop_score = 0;
		while (true)
		{
			now = p[now];
			++loop_size;
			loop_score += c[now];
			if (now == i)break;
		}
		ll cur_score = 0;
		int cnt = 0;
		while (true)
		{
			++cnt;
			if (cnt > k)break;
			now = p[now];
			cur_score += c[now];
			chmax(res, cur_score);
			chmax(res, cur_score + ((k - cnt) / loop_size)*loop_score);
			if (now == i)break;
		}
	}
	cout << res << endl;
}

Measured memory_bytes: 3696
#include<iostream>
#include<string>
#include<cmath>
#include <stdexcept>
#include<algorithm>
using namespace std;

int main(){

	string S,st;
	int ans=99999999;

	int temp;
	cin >>S;

	for(int i=0; i<S.size()-2; i++){
		st=(S.substr(i,3));
		temp=stoi(st );
		
		
		temp=abs(temp-753);
//cout << S.size()<< " " <<temp<<" " <<temp <<" " <<st<<endl;
		ans=min(ans,temp);

	}
	cout << ans<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
signed main()
{
	 ios_base::sync_with_stdio(false);
	 cin.tie(NULL);
	 cout.tie(NULL);
	 char c;
	 cin>>c;
	 string s="aeiou";
	 if(s.find(c)==string::npos)
	 	cout<<"consonant"<<endl;
	 else
	 	cout<<"vowel"<<endl;
	 return 0;
}

Measured memory_bytes: 256
#pragma region Macros
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i, n) for(int i=(n); i>=0; --i)
#define FOR(i, n, m) for(int i=(m), i##_len=(n); i<i##_len; ++i)
#define EACH(i, v) for(const auto& i : v)
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
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 Value>using vec = vector< Value >;
using ll = long long;
using P = pair< long long, long long >;
#define fi first
#define se second
#define el endl
#pragma endregion

void Main();

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


void Main(){
    string S, T;
    cin >> S >> T;
    int cnt = 0;
    REP(i, 3){
        if(S[i] == T[i])
            cnt++;
    }
    cout << cnt << el;
}



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

class UnionFind {
private:
  vector<int> data;

  bool isSame(int x, int y) {
    return find(x) == find(y);
  }

  bool doUnite(int x, int y) {
    x = find(x), y = find(y);
    if (x == y) return (false);
    if (data[x] > data[y]) swap(x, y);
    data[x] += data[y];
    data[y] = x;
    return (true);
  }

  int getFind(int k) {
    if (data[k] < 0) return (k);
    return (data[k] = find(data[k]));
  }

  int getSize(int k) {
    return (-data[find(k)]);
  }

public:
  UnionFind(int N) {
    data.resize(N, -1);
  }

  int same(int x, int y) { return isSame(x, y); }
  bool unite(int x, int y) { return doUnite(x, y); }
  int find(int k) { return getFind(k); }
  int size(int k) { return getSize(k); }
};

signed main() {
  int n, q;
  cin >> n >> q;

  UnionFind uf(n);

  while (q--) {
    int com, x, y;
    cin >> com >> x >> y;

    if (com == 0) {
      uf.unite(x, y);
    } else if (com == 1) {
      if (uf.same(x, y)) {
        cout << 1 << endl;
      } else {
        cout << 0 << endl;
      }
    }
  }

  return 0;
}



Measured memory_bytes: 3184
#define LOCAL
#define _USE_MATH_DEFINES
#include <array>
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>
#include <random>
#include <ctime>

using namespace std;

template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
  out << "(" << a.first << "," << a.second << ")";
  return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
  out << "["; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
  return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
  out << "["; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
  return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
  out << "{"; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
  return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
  out << "{"; bool first = true;
  for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
  return out;
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << 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...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;
mt19937 mrand(random_device{}());
int rnd(int x) { return mrand() % x; }

struct fast_ios {
  fast_ios() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
  };
} fast_ios_;

int n;
void search(int pos, int used, string s) {
  if (pos == n) {
    cout << s << endl;
    return;
  }
  for (int i = 0; i < used; ++i) {
    search(pos + 1, used, s + (char)('a' + i));
  }
  search(pos + 1, used + 1, s + (char)('a' + used));
}

int main() {
  cin >> n;
  search(0, 0, "");
  return 0;
}


Measured memory_bytes: 1536