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

int main() {
    int n, a, b, p1, p2;

    cin >> n >> a >> b;
    p1 = a * n;
    p2 = b;
    if (p1 < p2) {
        cout << p1 << endl;
    } else {
        cout << p2 << endl;
    }

    return 0;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
hist_a = [0 for _ in range(n)]
tmp_sum = 0
for i in range(n):
  hist_a[a[i]-1] += 1
for i in range(n):
  tmp_sum += hist_a[i] * ( hist_a[i] - 1 ) // 2

for k in range(n):
  num_ak = hist_a[a[k]-1]
  sum_val = tmp_sum - num_ak * ( num_ak - 1 ) // 2 + ( num_ak - 1 ) * ( num_ak - 2 ) // 2
  print(sum_val)

Measured memory_bytes: 26140
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int MAX_V = 100;
const int INF = 1e9;

struct edge
{
	int to,cap,cost,rev;
};

int V;
vector<edge> G[MAX_V];
int dist[MAX_V];
int prevv[MAX_V],preve[MAX_V];

void add_edge(int from,int to, int cap, int cost)
{
	G[from].push_back((edge){to,cap,cost,(int)G[to].size()});
	G[to].push_back((edge){from,0,-cost,(int)G[from].size()-1});
}

int min_cost_frow(int s,int t,int f)
{
	int res = 0;
	while(f>0)
	{
		fill(dist,dist+V,INF);
		dist[s] = 0;
		bool update = true;
		while(update)
		{
			update = false;
			for(int v = 0;v<V;v++)
			{
				if(dist[v] == INF)continue;
				for(int i = 0;i<G[v].size();i++)
				{
					edge &e = G[v][i];
					if(e.cap>0&&dist[e.to]>dist[v] + e.cost)
					{
						dist[e.to] = dist[v]+e.cost;
						prevv[e.to] = v;
						preve[e.to] = i;
						update = true;
					}
				}
			}
		}
		if(dist[t]==INF)
		{
			return -1;
		}
		int d = f;
		for(int v = t;v != s;v = prevv[v])
		{
			d = min(d,G[prevv[v]][preve[v]].cap);
		}
		f -=d;
		res += d*dist[t];
		for(int v= t;v !=s;v=prevv[v])
		{
			edge &e = G[prevv[v]][preve[v]];
			e.cap -= d;
			G[v][e.rev].cap += d;
		}
	}
	return res;
}

int main()
{
	int E,F;
	cin >> V >> E >> F;
	for(int i = 0;i<E;i++)
	{
		int u,v,c,d;
		cin >> u >> v >> c >> d;
		add_edge(u,v,c,d);
	}
	cout<<min_cost_frow(0,V-1,F)<<endl;
}


Measured memory_bytes: 3196
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
const int MAX_N = 1<<17;
const ll INF = INT_MAX;

/*
  RMQ and RUQ
  ?????????????°?????????????(RMQ)
  ????????????????????´??????(RUQ)
 */

class RMQ2{
public : 
  struct data{
    bool type; //0 - empty   , 1 - update
    ll value;
  };
  ll n,dat[2*MAX_N-1];
  data td[2*MAX_N-1];
  
  RMQ2(){
    n=MAX_N;
    memset(td,0,sizeof(td));
    for(int i=0;i<2*n-1;i++)dat[i]=INF;
  }
  RMQ2(int n_){
    n=1;
    while(n<n_)n*=2;
    memset(td,0,sizeof(td));
    for(int i=0;i<2*n-1;i++)dat[i]=INF;
  }

  //[a,b)?????????x????????´???update(a,b,x)
  ll update(int a,int b,int x,bool flg=true,int k=0,int l=0,int r=-1){
    if(r==-1) r=n;
    if(r<=a||b<=l)return flg? dat[k]:INF;
    if(a<=l&&r<=b){
      if(flg==true){
	td[k]=(data){1,x};
	dat[k]=x;
      }
      return dat[k];
    }

    if(td[k].type){
      dat[k*2+1]=dat[k*2+2]=td[k].value;
      td[k*2+1]=td[k*2+2]=(data){1,td[k].value};
      td[k].type=0;
    }
    
    ll vl=update(a,b,x,flg,k*2+1,l,(l+r)/2);
    ll vr=update(a,b,x,flg,k*2+2,(l+r)/2,r);
    if(flg==true)dat[k]=min(vl,vr);
    return min(vl,vr);
  }
  
  //[a,b)???????°????????????????find(a,b);
  ll find(int a,int b){return update(a,b,0,false);};
};


int main(){
  int q,n;
  cin>>n>>q;
  RMQ2 T(n);
  while(q--){
    int cmd,s,t,x;
    cin>>cmd>>s>>t;
    if(cmd==0)cin>>x,T.update(s,t+1,x);
    else cout <<T.find(s,t+1)<<endl;
  }
  return 0;
}

Measured memory_bytes: 9264
using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using E = System.Linq.Enumerable;

class Program
{
    static void Main(string[] args)
    {
        //入力を受け取る
        var NM = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
        var N = NM[0];
        var M = NM[1];
        
        var P = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
        var UF = new UnionFind(N+1);
      
        for(int i = 0;i < M;i++){
          var XY = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
          var X = XY[0];
          var Y = XY[1];
          UF.Union(X,Y);
        }
        var ans = 0;
        for(int i = 0;i < N;i++){
          if(UF.Same(P[i],i+1)){
            ans++;
          }
        }
        Console.WriteLine(ans);
    }
  
class UnionFind
{
    // 親要素のインデックスを保持する
    // 親要素が存在しない(自身がルートである)とき、マイナスでグループの要素数を持つ
    public int[] Parents { get; set; }
    public UnionFind(int n)
    {
        this.Parents = new int[n];
        for (int i = 0; i < n; i++)
        {
            // 初期状態ではそれぞれが別のグループ(ルートは自分自身)
            // ルートなのでマイナスで要素数(1個)を保持する
            this.Parents[i] = -1;
        }
    }

    // 要素xのルート要素はどれか
    public int Find(int x)
    {
        // 親がマイナスの場合は自分自身がルート
        if (this.Parents[x] < 0) return x;
        // ルートが見つかるまで再帰的に探す
        // 見つかったルートにつなぎかえる
        this.Parents[x] = Find(this.Parents[x]);
        return this.Parents[x];
    }

    // 要素xの属するグループの要素数を取得する
    public int Size(int x)
    {
        // ルート要素を取得して、サイズを取得して返す
        return -this.Parents[this.Find(x)];
    }

    // 要素x, yが同じグループかどうか判定する
    public bool Same(int x, int y)
    {
        return this.Find(x) == this.Find(y);
    }

    // 要素x, yが属するグループを同じグループにまとめる
    public bool Union(int x, int y)
    {
        // x, y のルート
        x = this.Find(x);
        y = this.Find(y);
        // すでに同じグループの場合処理しない
        if (x == y) return false;

        // 要素数が少ないグループを多いほうに書き換えたい
        if (this.Size(x) < this.Size(y))
        {
            var tmp = x;
            x = y;
            y = tmp;
        }
        // まとめる先のグループの要素数を更新
        this.Parents[x] += this.Parents[y];
        // まとめられるグループのルートの親を書き換え
        this.Parents[y] = x;
        return true;
    }
}  


}


Measured memory_bytes: 27744
// AtCoder ABC140: D - Face Produces Unhappiness 
// 2019.9.7 bal4u

#include <stdio.h>

#if 1
int getchar_unlocked(void);
#define gc() getchar_unlocked()
#else
#define gc() getchar()
#endif

int in() {  // 整数の入力
	int n = 0, c = gc();
	do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');
	return n;
}

void ins(char *s) { // 文字列の入力
	char *p = s--;
	do *++s = gc();
	while (*s > ' ');
	*s = 0;
}

int N, K;
char S[100005];

int main()
{
	int ans; char *s;
	
	N = in(), K = in(), ins(S);
	ans = 0, s = S+1; while (*s) {
		while (*s == *(s-1)) s++, ans++;
		if (*s == 0) break;
		s++; while (*s == *(s-1)) s++, ans++;
		if (*s == 0) { if (K) ans++; break; }
		if (K) K--, ans+=2;
		s++;
	}
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>

using namespace std;

#define ll long long
ll a,b,ans = 0;
int main(){
	cin >> a;
	for(int i = 1; i <= a; i++){
		cin >> b;
		while(b % 2 == 0){
			b /= 2;
			ans++;
		}
	}
	cout << ans;
}

Measured memory_bytes: 256
import java.util.Scanner;
import java.util.ArrayList;
import java.util.List;
public class Main{

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		List<String> list=new ArrayList<String>();
		Scanner scanner=new Scanner(System.in);
		String string=scanner.next();
		int count=0;
		for(int i=0;i<string.length();i++) {
			list.add(string.substring(i,i+1));
		}
		int a=list.size()/2;
		for(int i=0;i<a;i++) {
			if(list.get(i).equals(list.get(list.size()-i-1))) {
				
			}
			else {
				count++;
			}
		}
      System.out.print(count);
	}

}

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

using namespace std;
using ll = long long;

int main() {
    int A, B, C, D, E;
    cin >> A >> B >> C >> D >> E;
    if(A+B <= 2*C) {
        cout << A*D+B*E << endl;
    } else {
        int ans = 0;
        ans += min(D,E)*2*C;
        if (D==E)
        {
            cout << ans << endl;
        }
        else if (D>E)
        {
            D -= E;
            if (A>2*C)
            {
                ans += 2*C*D;
                cout << ans << endl;
            }
            else
            {
                ans += A*D;
                cout << ans << endl;
            }
            
        }
        else
        {
            E -= D;
            if (B>2*C)
            {
                ans += 2*C*E;
                cout << ans << endl;
            }
            else
            {
                ans += B*E;
                cout << ans << endl;
            }
        }
        
    }
    return 0;
}

Measured memory_bytes: 3560
import fractions

n = int(input())
a_list = [int(a) for a in input().split()]

left = [0]
right = [0]
for a in a_list:
    left.append(fractions.gcd(left[-1], a))
    
a_list.reverse()
for a in a_list:
    right.append(fractions.gcd(right[-1], a))

right.reverse()

m = []
for i in range(len(a_list)):
    m.append(fractions.gcd(left[i], right[i + 1]))
    
print(max(m))

Measured memory_bytes: 16160
/*
* @Author: Kabid
* @Date:   2020-04-26 18:01:07
* @Last Modified by:   Kabid
* @Last Modified time: 2020-05-03 19:31:09
*/
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<cstdlib>
#include<set>
#include<map>
#include<algorithm>
#define ll long long
#define  in(x) scanf("%d",&x);
#define out(x) printf("%d",x);
#define  ins(x)  scanf("%s",x);
#define outs(x) printf("%s",x);
#define lin puts("");
#define _ putchar(' ');
using namespace std;

int t;       //test cases
ll  n=0, k,m; //variables
long long w,x;
ll  a, b, d;
ll c;
ll p=100.0;
string s;
set<ll>st;
ll i,j;
int main() {
	cin>>x;
	for(i=-6207;i<=6207;i++){
		st.insert(ceil(pow(i,5)));
	}
	for(i=6207;i>=-6207;i--){
		a=ceil(pow(i,5));
		if(st.count(a-x)){
			for(j=-6207;j<=6207;j++){
				if((long long)ceil(pow(j,5))==a-x){
					cout<<i<<' '<<j;
					break;
				}
			}
			break;
		}
	}
	

	return 0;
	}
	



Measured memory_bytes: 4816
n,a,b=map(int,input().split())
if (a+b)%2==0:
    print(abs(a-b)//2)
else:
    
    temp=min(b-1,n-a)
    if temp==b-1:
        ans=(b+a-1)//2
    else:
        
        ans=(n+1-b+n+1-a-1)//2
    print(ans)

Measured memory_bytes: 38384
#include <bits/stdc++.h>
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define reprrev(i,a,b) for(int i=b-1;i>=a;i--) // [a, b)
#define reprev(i,n) reprrev(i,0,n)
#define _GLIBCXX_DEBUG

using ll = long long;
using ull = unsigned long long;
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; }
const ll mod = 1e9+7;
void chmod(ll &M){
  if(M >= mod) M %= mod;
  else if(M < 0){
     M += (abs(M)/mod + 1)*mod;
    M %= mod;
}
}
ll modpow(ll x, ll n){
   if(n==0) return 1;
  ll res=modpow(x, n/2);
 if(n%2==0) return res*res%mod;
else return res*res%mod*x%mod;
}
int getl(int i, int N) { return i==0? N-1:i-1; };
int getr(int i, int N) { return i==N-1? 0:i+1; };
long long GCD(long long a, long long b) {
  if (b == 0) return a;
  else return GCD(b, a % b);
}

using namespace std;
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
int main()
{
    ll N, D;
    cin >> N >> D;
    int count = 0;
    rep(i, N) {
        ll a, b;
        cin >> a >> b;
        // cout << a*a + b*b << " " << D*D << endl;
        if(a*a + b*b <= D*D) count++;
    }
    cout << count << endl;
}

Measured memory_bytes: 3596
s = input()
t = input()

def compare(a, b):
    ans = 0
    for i in range(len(a)):
        if a[i] != b[i]:
            ans += 1
    return ans

ans = float('inf')
for i in range(len(s) - len(t) + 1):
    num = compare(s[i:(i+len(t))], t)
    if num < ans:
        ans = num

print(ans)

Measured memory_bytes: 67060
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string>
#include <iomanip>
#include <math.h>
#include <utility>
#include <vector>
#include <map>
#include <unordered_map>
#include <cstdlib>
#include <stack>
#include <queue>
#define div1 1000000007
const long long INF = 1LL << 60;
using namespace std;
using ll = long long;
using ld = long double;
// a>b -> a==b;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
// a<b -> a==b;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

int main(void)
{
    string S, T;
    ll i, j, k, judge=0, a=0;

    cin >> S >> T;

    for(i=S.size()-1; i>=0; i--){
        if(S[i]=='?' || S[i]==T[0]){
            j = i;
            while(i<S.size() && i-j<T.size() && (S[i]=='?' || S[i]==T[i-j])){
                if(i-j==T.size()-1){
                    a = 1;
                    break;
                }
                i++;
            }
            if(i-j==T.size()-1 && a==1){
                judge = 1;

                for(k=j; k<j+T.size(); k++){
                    S[k] = T[k-j];
                }
                break;
            }
            i = j;
        }
    }

    for(i=0; i<S.size(); i++){
        if(S[i]=='?'){
            S[i] = 'a';
        }
    }

    if(judge==0){
        cout << "UNRESTORABLE" << endl;
    }

    else{
        cout << S << endl;
    }

    return 0;
}

Measured memory_bytes: 256
n = input()
s, t = [], []
for i in range(n):
    v = input()
    if v % 10 == 0:
        s.append(v)
    else:
        t.append(v)
ans = sum(s) + sum(t)
if ans % 10 != 0:
    print ans
elif len(t) > 0:
    ans -= sorted(t)[0]
    print ans
else:
    print 0

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

#define ll long long
#define ld long double

ll ceil(ll a, ll b) {
    if(a % b) return a/b + 1LL;
    return a/b;
}

void solve() {
    ll n, x, t;
    cin >> n >> x >> t;
    ll ans = ceil(n, x) * t;
    cout << ans << "\n";
    
}

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

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define ll long long
#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))
#define INF = 1001001001
#define pi = acos(-1)
using namespace std;
int gcd(int x, int y) { return (x % y)? gcd(y, x % y): y; }
int main(){
    int n,q; cin >> n;
    vector<ll> a(100000, 0);
    ll sum = 0;

    for (int i = 0; i < n; ++i) {
        ll b; cin >> b;
        a[b-1]++;
        sum += b;
    }

    cin >> q;

    for (int j = 0; j < q; ++j) {
        ll b, c; cin>>b>>c;
        sum -= b*a[b-1];
        sum += c*a[b-1];
        a[c-1] += a[b-1];
        a[b-1] = 0;
        cout << sum << endl;
    }

    return 0;
}

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

using ll = long long;

const int N = 1e5 + 10, INF = 1e9 + 5;

int a[N];

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

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

    vector<int> dp(n, INF);

    dp[0] = 0;
    for (int i = 0; i < n; i++)
    {
        for (int j = i + 1; j <= i + k; j++)
        {
            if (j < n)
                dp[j] = min(dp[j], abs(a[i] - a[j]) + dp[i]);
        }
    }

    printf("%d\n", dp[n - 1]);
}


Measured memory_bytes: 1024
def resolve():
    a, b, k = list(map(int, input().split()))
    s = set()
    for i in range(a, min(a + k, b + 1)):
        s.add(i)
    for i in range(max(a, b - k + 1), b + 1):
        s.add(i)
    for i in sorted(s):
        print(i)


if __name__ == "__main__":
    resolve()


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

int a[4];

int main(void){
    string str;
    cin>>str;
    a[0]=str[0]-'0';
    a[1]=str[1]-'0';
    a[2]=str[2]-'0';
    a[3]=str[3]-'0';
    string s=to_string(a[0]);
    int check=a[0];
    for(int bit=0;bit<(1<<3);++bit){
        for(int i=0;i<3;i++){
            if(bit&(1<<i)){
                check+=a[i+1];
                s+="+";
                s += to_string(a[i+1]);
            }else{
                check-=a[i+1];
                s+="-";
                s += to_string(a[i+1]);
            }
        }
        if(check==7){
            s += "=7";
            cout << s << endl;
            break;
        }else{
            s=to_string(a[0]);
            check=a[0];
        }
        }
        return 0;
}


Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
limit = 1000000000000000000
ans = 1
for i in range(N):
    if A[i] == 0:
        ans = 0

flag = False
for i in range(N):
    ans *= A[i]  
    if ans > limit:
        flag = True
        break
print(-1) if flag else print(ans)

Measured memory_bytes: 21648
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int lsn = 65;
        int ssn = 97;

        char large[] = new char[26];
        char small[] = new char[26];
        char sign[] = {' ', ',', '.'};

        for (int i = 0; i < 26; i++) {
            large[i] = (char) lsn++;
            small[i] = (char) ssn++;
        }

        String str = sc.nextLine();
        StringBuilder ans = new StringBuilder();

        for (int i = 0; i < str.length(); i++) {
            String s = String.valueOf(str.charAt(i));
            if (s.matches("[A-Z]")) {
                ans.append(s.toLowerCase());
            } else if (s.matches("[a-z]")) {
                ans.append(s.toUpperCase());
            } else {
                ans.append(str.charAt(i));
            }
        }
        System.out.println(ans);
    }
}

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

#define MAX 100
#define NIL -2

int n, G_list[MAX+1];
int G[MAX+1][MAX+1];
int d[MAX+1][2];

void init(void){
  for(int i=0; i<=MAX; i++){
    d[i][0]=-1;
  }
}

void make_graph(void){
  scanf("%d", &n);

  for(int i=0; i<n; i++){
    int cnt, num, m;

    scanf("%d %d", &num, &cnt);
    G_list[i]=num;

    for(int j=0; j<cnt; j++){
      scanf("%d", &m);
      G[num][m]=1;
    }
  }
}

void check_depth(void){
  queue<int> Q;
  Q.push(G_list[0]);
  d[G_list[0]][0]=0;
  d[G_list[0]][1]=NIL;
  
  while(!Q.empty()){
    int top=Q.front();
    Q.pop();
    
    for(int j=0; j<n; j++){
      if(G[top][G_list[j]] == 1 && d[G_list[j]][1] != NIL){
	d[G_list[j]][0]=d[top][0]+1;
	d[G_list[j]][1]=NIL;
	Q.push(G_list[j]);
      }
    }
  }
}

void print(void){

  for(int i=0; i<n; i++){
    printf("%d %d\n", G_list[i], d[G_list[i]][0]);
  }
}

int main(void){

  init();
  make_graph();
  check_depth();
  print();
  
  return 0;
}



Measured memory_bytes: 3220
def main():
    n, x, y = map(int,input().split())
    ans = [0] * n
    dp = [[0] * (n - 1) for i in range(n)]
    for i in range(1,n+1):
        for j in range(i,n+1):
            dirct = abs(i-j)
            mid_x = abs(x-i) + 1 + abs(y - j)
            mid_y = abs(y-i) + 1 + abs(x - j)
            ans[min(dirct, mid_x, mid_y)] += 1
    for i in range(1, n ):
        print(ans[i])


if __name__ == '__main__':
    main()


Measured memory_bytes: 34804
import java.util.*;
public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		long N = sc.nextLong();
		ArrayList<Long> ary = new ArrayList<Long>();
		long temp = (long)Math.sqrt(N);
		long ans1 = Long.MAX_VALUE / 3;
		long ans2 = Long.MAX_VALUE / 3;
		for(long i = 1; i <= temp; i++) {
			if(N % i == 0) {
				if((ans1 - 1) + (ans2 - 1) > (i - 1) + (N / i - 1)) {
					ans1 = i;
					ans2 = N / i;
				}
			}
		}
		System.out.println((ans1 - 1) + (ans2 - 1));
	}
}


Measured memory_bytes: 23764
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <stack>
#include <set> 
#include <map>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstring>
#include <iomanip>
#define REP(i,n) for(int i=0; i<(n); ++i)
#define FOR(i,a,b) for(int i=(a); i<(b); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 100100100;
const ll INFLL = 1001001001001001001;  // > 10^18
const int MOD = (int)1e9 + 7;
const ll MODLL = (ll)1e9 + 7;
const double EPS = 1e-9;

int main () {

    string s; cin >>s;

    int mn;
    for (int i = 0; i < s.length(); i++) {
        if (s[i] == 'A') {
            mn = i;
            break;
        } 
    }

    int mx;
    for (int i = 0; i < s.length(); i++) {
        if (s[i] == 'Z') {
            mx = i;
        } 
    }

    cout << mx - mn + 1 << endl;

    return 0;
}




Measured memory_bytes: 640
function bomb(name){
   var min=obj[name];
   M.forEach(function(v){
      if(name==v[0]){
         var sum=0;
         v[1].forEach(function(value){
            sum+=bomb(value);
         });
         min=Math.min(min,sum);
      }
   });
   return min;
}
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var arr=input.trim().split("\n");
while(true){
   var n=arr.shift()-0;
   if(n==0)break;
   var obj={};
   for(var i=0;i<n;i++){
      var data=arr.shift().split(" ");
      obj[data[0]]=data[1]-0;
   }
   var m=arr.shift()-0;
   var M=[];
   for(var i=0;i<m;i++){
      var data=arr.shift().split(" ");
      var name=data.shift();
      data.shift();
      M.push([name,data]);
   }
   var item=arr.shift();
   console.log(bomb(item));
}

Measured memory_bytes: 17648
//#include<cstdio>
//#include<cassert>
//#include<iostream>
//#include<cstring>
//#include<algorithm>
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define MAX ((int)1e6 + 5)
#define MAXL ((ll)1e18 + 5)
#define MAX_X ((ll)1e5 + 2)
#define pi (2.0*acos(0))
#define M ((int)1e6 + 7)
#define MOD ((int)1e9 + 7)
#define NN ((int)1e6 + 7)
#define N ((int)2e5 + 7)
#define eps (0)
#define fastio ios_base::sync_with_stdio(false),cin.tie(NULL)
#define logn 29
#define endl "\n"
#define mp make_pair
#define BUCK 105
#define LEF (idx<<1)
#define RIG ((idx<<1)|1)
//#define int ll


using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef unsigned long long ull;

/*fast io
ios_base::sync_with_stdio(false);
cin.tie(NULL);
*/




typedef tree < pair < ll, pair < ll, ll > >,  null_type,  less < pair < ll, pair < ll, ll > > >,  rb_tree_tag,  tree_order_statistics_node_update > o_set;
/// o_set s;
/// s.order_of_key(k) : Number of items strictly smaller than k .
/// *(s.find_by_order(k)) : K-th element in a set (counting from zero).

int arr[N] , tmp[N];

int main()
{
    fastio;
    int n , k;
    cin>>n>>k;
    for(int i = 1 ; i<=n ; i++) cin>>arr[i];
    for(int i = 1 ; i<=k ; i++){
        bool flag = 1;
        for(int i = 1 ; i<=n ; i++){
            if(arr[i] < n){
                flag = 0;
                break;
            }
        }
        if(flag) break;
        memset(tmp,0,sizeof tmp);
        for(int i = 1 ; i<=n ; i++){
            int lef = max(1,i - arr[i]) , rig = min(n+1,i + arr[i]+1);
            tmp[lef]++;
            tmp[rig]--;
        }
        for(int i = 1 ; i<=n ; i++) tmp[i] += tmp[i-1];
        for(int i = 1 ; i<=n ; i++) arr[i] = tmp[i];
    }
    for(int i = 1 ; i<=n ; i++) cout<<arr[i]<<" ";
    return 0;
}


Measured memory_bytes: 5184
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define F first
#define S second
#define mkp make_pair
#define pii pair<int,int>
typedef long long ll;
const int inf=0x3f3f3f3f;
const int maxn=1e5+5;

int main(){
	ll n,a,b;
	cin>>n>>a>>b;
	cout<<(n/(a+b)*a+min(a,n%(a+b)));
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n=0;
    while(cin>>n,n){
        int people[10000];
        for(int i=0;i<n;i++)cin>>people[i];
        sort(people,people+n);
        long long int ans=0,now=0;
        for(int i=0;i<n;i++){
            ans+=now;
            now+=people[i];
        }
        cout<<ans<<endl;
    }
}

Measured memory_bytes: 1208
using System;
using System.Collections.Generic;
using System.Linq;

public static partial class Program
{
    public static void Main()
    {
        var sstt = CRL().SpTInts();
        var s = new int[2] {sstt[0], sstt[1]};
        var t = new int[2] {sstt[2], sstt[3]};

        var xd = Diff(s[0], t[0]);
        var yd = Diff(s[1], t[1]);
        for (int i = 0; i < yd; i++)
        {
            Console.Write("U");
        }

        for (int i = 0; i < xd; i++)
        {
            Console.Write("R");
        }

        for (int i = 0; i < yd; i++)
        {
            Console.Write("D");
        }

        for (int i = 0; i < xd; i++)
        {
            Console.Write("L");
        }

        Console.Write("L");
        for (int i = 0; i < yd + 1; i++)
        {
            Console.Write("U");
        }

        for (int i = 0; i < xd + 1; i++)
        {
            Console.Write("R");
        }
        Console.Write("D");
        Console.Write("R");
        for (int i = 0; i < yd + 1; i++)
        {
            Console.Write("D");
        }

        for (int i = 0; i < xd + 1; i++)
        {
            Console.Write("L");
        }
        Console.WriteLine("U");
    }
}

public static partial class Program
{
    //テンプレここから
    private static int ToInt(this string str) => int.Parse(str);
    private static long ToLong(this string str) => long.Parse(str);
    private static int[] ToInt(this IEnumerable<string> strs) => strs.Select(x => x.ToInt()).ToArray();
    private static long[] ToLong(this IEnumerable<string> strs) => strs.Select(x => x.ToLong()).ToArray();
    public static int[] SpTInts(this string str, char opr = ' ') => str.Split(opr).ToInt();
    public static long[] SpTLongs(this string str, char opr = ' ') => str.Split(opr).ToLong();
    public static string CRL() => Console.ReadLine();
    public static void CWL(object obj) => Console.WriteLine(obj);
    public static int Diff(int a, int b) => Math.Abs(Math.Max(a, b) - Math.Min(a, b));
    public static long Diff(long a, long b) => Math.Abs(Math.Max(a, b) - Math.Min(a, b));
    public static int Sign(this int i) => Math.Sign(i);
    public static bool IsEven(this int i) => i % 2 == 0;
    public static int[] dx = new int[] { 0, -1, 0, 1 };
    public static int[] dy = new int[] { -1, 0, 1, 0 };
    public static string alphabet = "abcdefghijklmnopqrstuvwxyz";
    public static int ToInt(this char c) => c.ToString().ToInt();
    public static long ToLong(this char c) => c.ToString().ToLong();
    //テンプレここまで
}


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

using namespace std;

int main(int argc, char const *argv[]) {
    int r, c;
    while (cin>>r>>c, r||c) {
        if (r % 2 == 0 || c % 2 == 0) cout<<"yes"<<endl;
        else cout<<"no"<<endl;
    }
    return 0;
}

Measured memory_bytes: 2992
#include<iostream>
#include<sstream>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<complex>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cassert>

#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define mp make_pair
#define pb push_back
#define each(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define dbg(x) cerr<<__LINE__<<": "<<#x<<" = "<<(x)<<endl

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
const int inf = (int)1e9;
const double INF = 1e12, EPS = 1e-9;

int n, m;
double l[20], a[20], b[20];
double dp[1 << 20], d[20][20];

int main(){
	cin >> n >> m;
	rep(i, n) cin >> l[i] >> a[i] >> b[i];
	rep(i, n) rep(j, n){
		d[i][j] = (l[i] - l[j]) * (l[i] - l[j]) + (a[i] - a[j]) * (a[i] - a[j]) +
			(b[i] - b[j]) * (b[i] - b[j]);
	}
	
	double ans = 0;
	rep(i, 1 << n){
		rep(j, n) if(!(i & 1 << j)){
			double next = dp[i];
			rep(k, n) if(i & 1 << k) next += d[j][k];
			dp[i | 1 << j] = max(dp[i | 1 << j], next);
		}
		if(__builtin_popcount(i) == m) ans = max(ans, dp[i]);
	}
	printf("%.9f\n", ans);
	return 0;
}

Measured memory_bytes: 9448
// D - Candidates of No Shortest Paths
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;

// void vprn(vector<int> &v){ for(int i=0;i<v.size();i++) cout<<v[i]<<(i<v.size()-1?",\t":"\n"); }
// void vvprn(vector<vector<int>> &vv){ for(auto v:vv) vprn(v);cout<<"----\n"; }

#define INF (INT_MAX/2)

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

	vi a(M), b(M), c(M);
	for(int e=0; e<M; e++){
		cin>>a[e]>>b[e]>>c[e];
		a[e]--; b[e]--;
	}

	vvi dist(N,vi(N, INF));//dist[from][to] from->to: cost of shortest path
	for(int v=0; v<N; v++) dist[v][v] = 0;
	// vvprn(dist);//

	for(int e=0; e<M; e++){//set cost of edge
		dist[a[e]][b[e]] = min(dist[a[e]][b[e]], c[e]);
		dist[b[e]][a[e]] = min(dist[b[e]][a[e]], c[e]);
	}
	// vvprn(dist);//

	// Warshall Floyd (set cost of shortest path)
	for(int r=0; r<N; r++)//relay point
		for(int s=0; s<N; s++)//start point
			for(int t=0; t<N; t++)//terminal point
				dist[s][t] = min(dist[s][t], dist[s][r] + dist[r][t]);
	// vvprn(dist);//

	// int ans = 0;
	// for(int e=0; e<M; e++) if(dist[a[e]][b[e]] < c[e]) ans++;

	int ans = M;
	for(int e=0; e<M; e++){
		bool shortest = false;
		for(int v=0; v<N; v++) if(dist[v][a[e]]+c[e] == dist[v][b[e]]) shortest = true;
		if(shortest) ans--;
	}
	cout<< ans <<endl;
}

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

int main()
{
	int n;
	std::cin >> n;
	std::vector<int> a[3];
	std::vector<int> dp[3];
	for (int i = 0; i < 3; ++i)
	{
		a[i] = std::vector<int>(n);
		dp[i] = std::vector<int>(n, std::numeric_limits<int>::min());
	}
	for (int i = 0; i < n; ++i)
	{
		for (int j = 0; j < 3; ++j)
		{
			std::cin >> a[j][i];
		}
	}
	dp[0][0] = dp[1][0] = dp[2][0] = 0;
	for (int i = 0; i < n; ++i)
	{
		for (int j = 0; j < 3; ++j)
		{
			dp[j][i] += a[j][i];
			for (int k = 0; k < 3 && i + 1 < n; ++k)
			{
				if (j != k)
				{
					dp[k][i + 1] = std::max(dp[k][i + 1], dp[j][i]);
				}
			}
		}
	}
	std::cout << std::max({ dp[0][n - 1], dp[1][n - 1], dp[2][n - 1] }) << '\n';
	return 0;
}

Measured memory_bytes: 5580
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair <int, int>;
const double PI = acos(-1);
const ll MOD = 1000000007;

int main() {
  int N;
  string c;
  cin >> N >> c;
  int cnt_r = 0;
  int cnt_w = 0;
  rep(i,N){
    if(c[i] == 'R') cnt_r++;
  }
  rep(i,cnt_r){
    if(c[i] == 'W') cnt_w++;
  }
  //cout << cnt_w << endl;
  cout << cnt_w << endl;


}


Measured memory_bytes: 3732
n,m=map(int,input().split())
pys=[0]*m
for i in range(m):
    p,y=map(int,input().split())
    pys[i]=(p,y,i)
pys.sort(key=lambda x: x[1])

cnt=[0]*n
ans=[0]*m
for p,y,i in pys:
    cnt[p-1]+=1
    ans[i]=str(p).zfill(6)+str(cnt[p-1]).zfill(6)

for i in ans:
    print(i)

Measured memory_bytes: 29764
#include<bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
#define pb push_back
int dy[]={0, 0, 1, -1, 1, 1, -1, -1};
int dx[]={1, -1, 0, 0, 1, -1, -1, 1};

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define mp make_pair
#define fi first
#define sc second
int n,a,b,c,d[200];
int main(){
    scanf("%d%d%d%d",&n,&a,&b,&c);
    REP(i,n)
        scanf("%d",d + i);

    int maxi = 0;

    sort(d,d + n, greater<int>());

    REP(i,n + 1){
        int s = 0;
        REP(j,i){
            s += d[j];
        }
        maxi = max(maxi,(c + s) / (a + i * b));
    }
    printf("%d\n", maxi);
    return 0;
}

Measured memory_bytes: 3204
N, K = map(int, input().split())
A = list(map(lambda x: int(x)-1, input().split()))
now = 0
route = [now]
visited = set()
visited.add(now)
while A[now] not in visited:
    route.append(A[now])
    visited.add(A[now])
    now = A[now]
L = len(route)
looplen = L-route.index(A[now])
if K < L:
    print(route[K]+1)
else:
    print(route[L-looplen+(K-L)%looplen]+1)

Measured memory_bytes: 131764
#include<algorithm>//sort(all(変数),greater<型名>())　で降順に
#include<cmath>//切り上げceil(値)
#include<deque>
#include<iomanip>//setprecision(数字)
#include<iostream>
#include<list>
#include<map>
#include<numeric> //xとyの最大公約数は__gcd(x,y),xとyの最小公倍数は(x*y)/__gcd
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<vector>

#include<bits/stdc++.h>
#include<cstdio>
#include<cstdlib>
#include<tuple>
#include<utility>
#define rep(i,n) for(ll i=0; i<n; i++)
#define vll vector<ll>
#define vi vector<int>
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
using ll = long long;
using namespace std;

int main(){
  string s;  cin >> s;
  string t[4] ={"dream","dreamer","erase","eraser"};
  reverse(all(s));
  rep(i,4){
    reverse(all(t[i]));
  }
  bool can = true;
  for(int i = 0; i < s.size();){
    bool div = false;
    rep(j,4){
      if(s.substr(i,t[j].size()) == t[j]){
        i += t[j].size();
        div = true;
      }
    }
    if(!div){
      can = false;
      break;
    }
  }
  if(can){
    cout << "YES";
  }else{
    cout << "NO";
  }
  return 0;
}


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

int a[100100];
int dp[100100];

int main() {

	int n;
	cin >> n;

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

	dp[1] = abs(a[1] - a[0]);
	for (int i = 2; i < n; i++)
		dp[i] = min(dp[i - 1] + abs(a[i] - a[i - 1]), dp[i - 2] + abs(a[i] - a[i - 2]));

	cout << dp[n - 1];

	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#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)
#define bit(n) (1LL << (n))
#define len(x) ((ll)(x).size())
#define debug(var) cout << "[" << #var << "]\n" << var << endl
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1000000007;
const double EPS = 1e-9;

template <typename T>
ostream& operator<<(ostream& s, const vector<T>& v) {
  int len = v.size();
  for (int i = 0; i < len; ++i) {
    s << v[i];
    if (i < len - 1)
      s << ' ';
  }
  return s;
}

template <typename T>
ostream& operator<<(ostream& s, const vector<vector<T>>& vv) {
  int len = vv.size();
  for (int i = 0; i < len; ++i) {
    s << vv[i];
    if (i != len - 1)
      s << '\n';
  }
  return s;
}

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

__attribute__((constructor)) void initial() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}

signed main() {
  int N;
  cin >> N;
  vector<string> S(N);
  rep(i, N) {
    cin >> S[i];
  }

  map<string, int> m;
  rep(i, N) {
    m[S[i]]++;
  }

  int mx = 0;
  for (auto item : m) {
    auto Fi = item.fi;
    auto Se = item.se;
    chmax(mx, Se);
  }

  for (auto item : m) {
    auto Fi = item.fi;
    auto Se = item.se;
    if (Se == mx)
      cout << Fi << endl;
  }
}

Measured memory_bytes: 25472
#include <stdio.h>
#include <math.h>

#define M_PI 3.14159265359

int main(void){
	
	int a, b, C;
	scanf("%d %d %d",&a, &b, &C);
	double rad, S, L, h;
	rad = ((double)C/180)*M_PI;
	h = b*sin(rad);
	S = a*b*sin(rad)/2;
	L = a+b+sqrt(a*a+b*b-2*a*b*cos(rad));
	printf("%f %f %f\n",S, L, h);
	return 0;
}	

Measured memory_bytes: 636
def solve():
    n, d = map(int, input().split())
    x = [list(map(int, input().split())) for _ in range(n)]
    count = 0
    for i in range(n):
        for j in range(n):
            dis2 = 0
            if i != j:
                for k in range(d):
                    dis2 += (x[i][k] - x[j][k]) ** 2
                if (dis2 ** 0.5).is_integer():
                    count += 1
    print(count//2)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();
int main()
{
    int N, K;
    string S;
    cin >> N >> K >> S;
    int count = N - 1;
    int score = 0, score1 = 0, score2 = 0;

    for(int i = 0; i < N - 1; i++){
        if(S[i] == S[i + 1]){
            score++;
        }
    }
   int start = -1, end = -1;
   for(int i = 0; i < N - 1; i++){
       if(S[0] != S[i + 1] && start < 0){
           start = 1;
           end = -1;
       } 
       else if(S[0] == S[i + 1] && start >= 0){
           score2++;
           start = -1;
           end = 1;
       }
   } 
   if(start > 0 && end < 0) score1++;

   for(int i = 0; i < K; i++){
       if(score2 > 0){
           score2--;
           score += 2;
       }
       else if(score1 > 0){
           score1--;
           score += 1;
       }
   }
   cout << score << endl;
   return 0;
}

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

int main(){
    int N, L;
    cin >> N >> L;
    int ans = 0;
    int minabs = 1e4;
    int hugou = 1;

    for(int i=1;i<=N;i++){
        ans += L + i - 1;
        if(minabs > abs(L + i - 1)){
            minabs = abs(L + i -1);
            if(L + i - 1 >= 0){
                hugou = 1;
            }
            else{
                hugou = -1;
            }
        }
    }

    cout << ans - hugou * minabs << "\n";

    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<cctype>
#include<cstring>
#include<iostream>
#include<vector>
#include<cmath>

using namespace std;

#define bomb exit(1)
#define INF 1061109567
#define LINF 4557430888798830399ll
#define pprint(x) print(x),putchar(' ')
#define fprint(x) print(x),putchar('\n')
#define EE(x); struct edge { int nxt,to;ll w; }e[M << 1]; int head[N],ecnt = 1;\
	void add(int u,int v,ll w = 0) { e[++ecnt].w = w,e[ecnt].to = v,e[ecnt].nxt = head[u];head[u] = ecnt; }\
	void add_edge(int u,int v,ll w = 0) { add(u,v,w),add(v,u,w * x); }
#define ll long long
const double pi = acos(-1);
int mod = 1000000007;
ll Mod(ll x) { return x >= mod ? x - mod : x; }
#define eps 0.0000000001
#define sqr(x) ((x) * (x))
#define iter iterator
#define fi first
#define se second
//#define getchar() (SS == TT && (TT = (SS = BB) + fread(BB,1,1 << 15,stdin),TT == SS) ? EOF : *SS++)
//char BB[1 << 15],*SS = BB,*TT = BB;
ll read()
{
	ll x = 0;int f = 1;char ch = getchar();
	for(;!isdigit(ch);ch = getchar()) if(ch == '-') f = -1;
	for(;isdigit(ch);ch = getchar()) x = x * 10 + (ch ^ 48);
	return x * f;
}
void print(ll x)
{
	if(x < 0) putchar('-'),x = -x;
	if(x > 9) print(x / 10);putchar(x % 10 + '0');
}

const int N = 510;
int n,x[N],c[N],a[N * N];

int main()
{
	n = read();
	for(int i = 1;i <= n;i++) x[i] = read();
	for(int i = 1;i <= n * n;i++)
	{
		for(int j = 1;j <= n;j++) if(x[j] == i)
		{
			c[j]++;
			if(c[j] ^ j) { puts("No");return 0; }
			a[i] = j;
			break;
		}
		if(!a[i])
		{
			int p = 0,lc = n * n + 2;
			for(int j = 1;j <= n;j++) if(c[j] < j - 1)
				if(x[j] < lc)
					lc = x[j],p = j;
			if(p)
				a[i] = p,c[p]++;
		}
		if(!a[i])
			for(int j = 1;j <= n;j++) if(c[j] < n && x[j] < i)
			{
				a[i] = j;
				c[j]++;
				break;
			}
		if(!a[i]) { puts("No");return 0; }
	}
	puts("Yes");
	for(int i = 1;i <= n * n;i++) pprint(a[i]);
}

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

using namespace std;

int main()
{
	for(int d,n,m;cin>>d>>n>>m,d;){
		vector<int> ds(n+1);
		for(int i=1;i<n;i++)
			cin>>ds[i];
		ds[n]=d;
		sort(ds.begin(),ds.end());
		int res=0;
		while(m--){
			int k; cin>>k;
			int i=upper_bound(ds.begin(),ds.end(),k)-ds.begin();
			res+=min(ds[i]-k,k-ds[i-1]);
		}
		cout<<res<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 1328
#include <stdio.h>

int main(void){

   int i,j,a,n;

   scanf("%d",&n);
   

   int day[n];
    j = 1;
    while(1){
        if(j == n+1)break;
        scanf("%d",&a);
        day[j] = a;
        j++;
    }
    
    
   

   for(i = n;i > 0; i--){
       if(i>1){
           printf("%d ",day[i]);
       }else{
           printf("%d\n",day[i]);
       }
       
   }
   
   return 0;
   
}


Measured memory_bytes: 2044
#include<iostream>
#include<algorithm>
#include<math.h>
#include<queue>
#include<vector>
#include<climits>
#include<map>
#include<string>
#include<functional>
#include<iomanip>

using namespace std;
typedef long long ll;

ll N, u, v, w;
ll color[100001] = {};
bool flag[100001] = {};
vector<vector<pair<ll, ll>>> node(100001, vector<pair<ll, ll>>(0, make_pair(0, 0)));

void DFS(ll cur) {
	for (int i = 0; i < node[cur].size(); i++) {
		if (flag[node[cur][i].first])continue;
		if (node[cur][i].second % 2 == 0) {
			color[node[cur][i].first] = color[cur];
		}
		else {
			color[node[cur][i].first] = !color[cur];
		}
		flag[cur] = true;
		DFS(node[cur][i].first);
	}
}

int main() {
	cin >> N;
	for (int i = 1; i < N; i++) {
		cin >> u >> v >> w;
		node[u].push_back(make_pair(v, w));
		node[v].push_back(make_pair(u, w));
	}
	DFS(1);
	for (int i = 1; i <= N; i++)cout << color[i] << endl;
	return 0;
}

Measured memory_bytes: 9472
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
#include <cstdio>
#include <queue>
#include <stack>
#include <set>
#include <cmath>

typedef long long ll;
using namespace std;

#define FALSE printf("false\n");
#define TRUE printf("true\n");
#define all(x) (x).begin(),(x).end()
#define print(x) cout<<x<<endl
#define rep(i,n) for(int i = 0;i < ((int)(n));++i)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define SUM(vec) accumulate(all(vec),0)
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define test(a) cout<<#a<<':'<<a<<endl

const ll INF = 1e9+7;

template<typename T>inline T digit(T num){T sum = 0;while(num){sum+=num%10;num/=10;}return sum;} // 各桁の和
template<typename T>inline T gcd(T a,T b){if(b == 0)return a;return gcd(b,a%b);}
template<typename T>inline T lcm(T a, T b){T g = gcd(a,b);return a/g*b;}
template<typename T>inline T power(T a,T b){T tmp=1;rep(i,b){tmp*=a;}return tmp;}


int main() {
  cin.tie(0); ios::sync_with_stdio(0);
  int n; cin>>n;
  vector<int> a(n+1),b(n);
  rep(i,n+1)cin>>a[i];
  rep(i,n)  cin>>b[i];
  ll ans = 0;
  rep(i,n){
    int minus = min(a[i],b[i]);
    a[i] -= minus;
    b[i] -= minus;
    ans  += minus;
    
    if(a[i+1] >= b[i]){
      ans    += b[i];
      a[i+1] -= b[i];
    }else{
      ans    += a[i+1];
      a[i+1] = 0;
    }

  }
  print(ans);
  return 0;
} 

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

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

    int n;
    cin >> n;
    int ans = 0;
    ans += (n/500)*1000;
    n %= 500;
    ans += (n/5)*5;
    cout << ans;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
int main()
{
    int s;
    scanf("%d",&s);
    int a[10000];
    a[1]=s;
    for(int i=2;i<200;i++)
    {
        if((a[i-1])%2==0)
        {
            a[i]=a[i-1]/2;
        }
        else
        {
            a[i]=a[i-1]*3+1;
        }
    }
    int flag=1;
    for(int i=2;i<200;i++)
    {
        for(int j=1;j<i;j++)
        {
            if(a[j]==a[i])
            {
                printf("%d",i);
                return 0;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 128
n = int(input())
a = list(map(int,input().split()))

d = 0
c = 0
for i in a:
    if i % 2 == 0:
        if i % 3 == 0 or i % 5 ==0:
            c += 1
        else:
            print('DENIED')
            quit()
        d += 1
if c == d:
    print('APPROVED')

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
#define re(i,n,a) for(int i=a;i<n;i++)
using namespace std;
typedef pair<int,int>P;
int w,h,a[16][16],md=14,b[16][16],s1,s2;
bool used[16][16];
string s[16];
int dx[]={-1,-1,-1,0,0,0,1,1,1};
int dy[]={-1,0,1,-1,0,1,-1,0,1};
vector<P>v;
map<int,int>m;
int greedy(){
  int res=0,sum=0;
  memset(a,0,sizeof(a));
  memset(used,0,sizeof(used));
  r(i,h){
      r(j,w){
        if(s[i][j]=='0'){
        r(k,9){
          int y=i+dy[k];
          int x=j+dx[k];
          if(y<0||x<0||y>=h||w>=x)continue;
          used[y][x]=1;
        }
      }
      else if(s[i][j]=='.')used[i][j]=1;
      else if(isdigit(s[i][j]))a[i][j]=s[i][j]-'0',res+=a[i][j];
      }
    }
    while(res>0){
      memset(b,0,sizeof(b));
      int f=0;
      r(i,h)r(j,w)if(!used[i][j]){
        int p=0;
        r(k,9){
          int y=i+dy[k];
          int x=j+dx[k];
          if(y<0||x<0||y>=h||x>=w)continue;
          if(a[y][x])p++;
        }
        b[i][j]=p;
        f=max(p,f);
      }
      int i=0,j=0;
      r(kk,h*w){
        i=(i+1)%h;
        j=(j+1)%w;
        if((unsigned int)rand()%5==0)i=(unsigned int)rand()%h;
        if((unsigned int)rand()%5==0)j=(unsigned int)rand()%w;
        if(used[i][j])continue;
        if(b[i][j]==f){
          int p=0;
          r(k,9){
          int y=i+dy[k];
          int x=j+dx[k];
          if(y<0||x<0||y>=h||x>=w)continue;
          if(a[y][x])p++;
        }
        if(p==f){
          r(k,9){
            int y=i+dy[k];
            int x=j+dx[k];
            if(y<0||x<0||y>=h||x>=w)continue;
            if(used[y][x])continue;
            if(a[y][x])a[y][x]--;
          }
          sum++;
          res-=f;
          used[i][j]=1;
        }
      } 
    }}
    m[sum]++;
    return sum;
}
int main(){
  while(cin>>h>>w,w){
    int ans=1e9;
    r(i,h)cin>>s[i];
    r(t1,2){
      r(i,h/2)swap(s[i],s[h-1-i]);
      r(t2,2){
        r(i,h)reverse(s[i].begin(),s[i].end());
        r(t3,2){
          string t[16];
          r(i,16)t[i]="";
          r(i,w)r(j,h)t[i]+=s[j][i];
          swap(h,w);
          r(i,w)s[i]="";
          r(i,h)s[i]=t[i];
          int pp;
          set<int>st;
          m.clear();
          r(t4,130){
            //srand((unsigned int)time(NULL));
            pp=greedy();
            st.insert(pp);
            ans=min(ans,pp);
          }
          //cout<<m[ans]<<endl;
          if(st.count(ans)&&ans%md==0)
            if(rand()%2&&ans)ans--;
        }
      }
    }
    cout<<ans<<endl;
  }
}

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

int main() {
	int n; cin >> n;
	rep(i, n) {
		string s; cin >> s;
		sort(s.begin(), s.end());
		int Min = stoi(s);
		reverse(s.begin(), s.end());
		cout << stoi(s) - Min << endl;
	}
	return 0;
}

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


int main() {

    string s, t;
    cin >> s >> t;
    string w = s + s;
    int len = s.size();
    rep(i, len) {
        if (t == w.substr(len-i, len)) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}

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

int main()
{
  int n[3];
  int a;
  cin >> n[0]>>n[1]>>n[2];
  for(int i = 0 ;i <= 2; i++)
  {
      for(int j = 2;j>i;j--)
      {
          if(n[j-1]>n[j])
          {
              a = n[j-1];
              n[j-1] = n[j];
              n[j] = a;
          }
      }
  }
  cout << n[0]<<" " << n[1]<<" " << n[2]<< endl;
  return 0;
}



Measured memory_bytes: 3120