akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Linq;
using System.Collections.Generic;

namespace Algorithm
{
    class Program
    {
        static void Main(string[] args)
        {
            var line = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int D = line[0], G = line[1];

            var p = new int[D];
            var c = new int[D];

            for (var i = 0; i < D; i++)
            {
                var tmp = Console.ReadLine().Split().Select(int.Parse).ToArray();
                p[i] = tmp[0];
                c[i] = tmp[1];
            }

            var min = int.MaxValue;
            for (var bit = 0; bit < 1<<D; bit++)
            {
                var num = 0;
                var total = 0;
                for (var i = 0; i < D; i++)
                {
                    if ((bit & 1<<i) != 0)
                    {
                        total += p[i] * 100 * (i + 1) + c[i];
                        num += p[i];
                    }
                }

                if (total >= G)
                {
                    min = Math.Min(num, min);
                    continue;
                }

                for (var i = D - 1; i >= 0; i--)
                {
                    if ((bit & 1 << i) != 0) continue;
                    for (var j = 0; j < p[i]; j++)
                    {
                        total += (i + 1) * 100;
                        num++;
                        if (total >= G) break;
                    }
                    if (total >= G) break;
                }
                min = Math.Min(num, min);
            }

            Console.WriteLine(min);
        }
    }
}


Measured memory_bytes: 13268
p=print
r=range
def a(i,j,k,l=0):p("+<"[l],i,j,k)
def b(i):a(i,i,i)
def d(x):
	a(x,3,x)
	for t in r(30):b(x+4);a(x+4,3,6),*map(b,[6]*(29-t));a(6,x,T:=x*60+35+t,1);a(x+4,T,x+4)
p(3874)
a(0,1,3)
a(2,3,3,1)
d(0)
d(1)
for t in r(60):b(2);[t-31<s<30!=(a(34+t-s,95+s,5),a(3,5,6,1),a(2,6,2))for s in r(t)]

Measured memory_bytes: 9160
"""
01BFS: ステップ数が多ければ後ろに持っていく
"""
def main():
    from collections import deque
    H,W = map(int,input().split())
    Ch,Cw = map(int,input().split())
    Dh,Dw = map(int,input().split())
    maze = [list(input()) for _ in range(H)]

    que = deque([(Ch-1,Cw-1,0)])
    adjectns = [(1,0),(0,1),(-1,0),(0,-1)]
    for _ in range(100000000):
        if not que:
            break
        h,w,step = que.popleft()
        if h == Dh-1 and w == Dw-1:
            print(step)
            exit()
        else:
            if maze[h][w] == ".":
                maze[h][w] = step
                for a,b in adjectns:
                    x = h + a
                    y = w + b
                    if 0<=x<H and 0<=y<W and maze[x][y]==".":
                        que.appendleft((x,y,step))
                for i in range(-2,3):
                    for j in range(-2,3):
                        x = h+i
                        y = w+j
                        if 0<=x<H and 0<=y<W and maze[x][y]==".":
                            que.append((x,y,step+1))
    print(-1)
main()


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

int main()
{
    long long  N;
    cin>>N;
    int n=(int)sqrt(N)+1;
    long long k;
    for(int i=n;i>=1;i--)
    {
        if(N%i==0)
        {
            k=i;
            break;
        }
    }
    long long l=N/k;
    long long num=l+k-2;
    cout<<num;
    return 0;
}


Measured memory_bytes: 256
while 1:
	N,M = map(int,raw_input().split())
	if N == 0: break
	T = [[0]*1261 for i in range(N)]
	for i in range(input()):
		t,n,m,s = map(int,raw_input().split())
		for ti in range(t,1261):
			T[n-1][ti] = s*m
	for i in range(input()):
		ts,te,m = map(int,raw_input().split())
		print sum(1 if any(T[n][t] == m for n in range(N)) else 0 for t in range(ts,te))
	

Measured memory_bytes: 22052
#include <stdio.h>
int main(){
    int N[4];
    int yen=0;
    for (int i=0;i<4;i++){
        scanf("%d",&N[i]);
    }
    if(N[0]<N[1]){
    	yen+=N[0]*N[2];
    }
    else{
        yen+=N[1]*N[2]+(N[0]-N[1])*N[3];
    }   
    printf("%d",yen);
}


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

char ACGT[] = {'A', 'C', 'G', 'T'};

bool acgt(char c){
  for (int i = 0; i < 4; i++) {
    if (c == ACGT[i]) return true;
  }
  return false;
}

int main(){
  string s; cin >> s;
  int ans = 0;
  for (int i = 0; i < s.size(); i++) {
    int cnt = 0;
    int j = i;
    while (j < s.size() && acgt(s.at(j))) {cnt++; j++;}
    ans = max(ans, cnt);
  }
  cout << ans << endl;
  return 0;
} 

Measured memory_bytes: 256
S = input()
s = ''
s2 = ''
for i in range(len(S)):
    s += str(i % 2)
    s2 += str((i+1) % 2)
c = 0
c2 = 0
for i in range(len(S)):
    if S[i] != s[i]:
        c += 1
    if S[i] != s2[i]:
        c2 += 1
print(min(c, c2))


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

int main()
{
    string S;
    cin >> S;

    string before;
    string after;

    before = S.substr(0, S.size()/2);
    if (S.size()%2 == 0) {
        after = S.substr(S.size()/2);
    } else {
        after = S.substr(S.size()/2+1);
    }
    
    // cout << before << "\n";
    // cout << after << "\n";

    reverse(after.begin(), after.end());

    int count = 0;
    for (int i=0; i<before.size(); i++) {
        if (before[i] != after[i]) {
            count++;
        }
    }
    cout << count;
    
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string.h>
#include <vector>
#include <queue>
#include <functional>
#include <algorithm>
using namespace std;

const int MAXN = 100010;
const int MAXM = 100010;
const int INF = 0x3f3f3f3f;
typedef long long LL;
typedef pair<int, int> P;

int N, Q;
int father[MAXN];
bool vis[MAXN];

void Init() {
	for (int i = 0; i < MAXN; ++i) {
		father[i] = i;
	}
}
int Find(int x) {
	while (!vis[x])
		x = father[x];
	return x;
}

int main(int argc, char const *argv[]) {
#ifdef LOCAL
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	while (scanf("%d%d", &N, &Q) != EOF && !(N == 0 && Q == 0)) {
		int a, b;
		LL res = 0;
		char opt[5];
		Init();
		fill(vis, vis + MAXN, false);
		vis[1] = true;
		for (int i = 2; i <= N; ++i) {
			scanf("%d", &father[i]);
		}
		for (int i = 0; i < Q; ++i) {
			scanf("%s %d", opt, &b);
			if (opt[0] == 'Q') {
				res += Find(b);
			}
			else
				vis[b] = true;
		}
		printf("%lld\n", res);
	}
	//system("pause");
	return 0;
}



Measured memory_bytes: 3600
package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}

func main() {
	sc.Split(bufio.ScanWords)
	n := nextInt()
	s := nextLine()

	x, max := 0, 0
	for i := 0; i < n; i++ {
		if s[i] == 'I' {
			x++
		} else if s[i] == 'D' {
			x--
		}
		if x > max {
			max = x
		}
	}
	fmt.Println(max)
}


Measured memory_bytes: 640
#include <algorithm>
#include <cmath>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <cassert>
#include <functional>

using namespace std;

#define LOG(...) printf(__VA_ARGS__)
//#define LOG(...)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())
#define CLR(a) memset((a), 0 ,sizeof(a))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int dx[] = { -1, 0, 1, 0 }; const int dy[] = { 0, 1, 0, -1 };

int main() {
	int e;
	while (cin >> e, e){
		int minene = 1 << 15;
		REP(i, 101){
			REP(j, 1001){
				if (e < i*i*i + j*j)break;
				minene = min(i + j + e - (i*i*i + j*j), minene);
			}
			if (e < i*i*i)break;
		}
		cout << minene << endl;
	}
}

Measured memory_bytes: 1160
#include <iostream>
#include <vector>

using namespace std;

int main() {
    int h, w; cin >> h >> w;
    vector<vector<char>> z(h);
    for (int i = 0; i < h; i++) {
        z[i].resize(w);
        for (int j = 0; j < w; j++) cin >> z[i][j];
    }

    if (h == 1 and w == 1) {
        if (z[0][0] == '#') {
            cout << "No" << endl;
            return 0;
        }
        else {
            cout << "Yes" << endl;
            return 0;
        }
    }

    bool solvable = true;
    for (int i = 1; i < h - 1; i++) {
        for (int j = 1; j < w - 1; j++) {
            if (z[i][j] == '.') continue;
            if (z[i][j] == '#' and z[i][j] == z[i][j - 1]) continue;
            if (z[i][j] == '#' and z[i][j] == z[i][j + 1]) continue;
            if (z[i][j] == '#' and z[i][j] == z[i - 1][j]) continue;
            if (z[i][j] == '#' and z[i][j] == z[i + 1][j]) continue;

            solvable = false;
            break;
        }

        if (!solvable) break;
    }

    if (solvable) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


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

using namespace std;

int main(){
    int n;
    cin>>n;
    vector<int> a(n);
    for (int i = 0; i < n; ++i) {
        cin>>a[i];
    }
    sort(a.begin(),a.end());
    double ans=0;
    ans=a[0]+a[1];
    ans=ans/2;
    for (int i = 2; i < n; ++i) {
        ans+=a[i];
        ans=ans/2;
    }
    cout<<setprecision(10);
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 384
M=998244353;
char S[2001];
N;
d[4001][4001];
x,y;
i,j,k;
main(){
	N=strlen(gets(S));
	for(**d=1;i<2*N;++i){
		i<N?y=2*(i+1)-(x+=S[i]-48):0;
		for(j=0;j<=i;++j)
			for(k=0;k<2;++k)
				d[j+!k][i-j+k]+=j-k<x&&i-j+k<=y?d[j][i-j]%M:0;
	}
	printf("%d",d[x][y]%M);
}


Measured memory_bytes: 61952
n = int(input())
ans = list()

for i in range(n):
        line = input().split(" ")
        a = float(line[0])
        b = float(line[1])
        c = float(line[2])
        if ((a**2 + b**2) == c**2) or ((b**2 + c**2) == a**2) or ((c**2 + a**2) == b**2):
            ans.append("YES")
        else:
            ans.append("NO")

for j in range(n):
        print(ans[j])

Measured memory_bytes: 7676
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define loop(i,a,b) for (int i=a; i<b; ++i)
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int N;
    string s;
    cin >> N;
    cin >> s;
    
    if (N>=3200) cout << s << endl;
    else cout << "red" << endl;
    return 0;
}

Measured memory_bytes: 256
import math
import copy
import fractions
import numpy as np
from functools import reduce

# ===FUNCTION===

def getInputNum():
    inputNum = int(input())
    return inputNum

def getInputListInt():
    outputoData = []
    inputData = input().split()
    outputData = [int(n) for n in inputData]

    return outputData

def getSomeInputInt(n):
    outputDataList = []
    for i in range(n):
        inputData = int(input())
        outputDataList.append(inputData)

    return outputDataList

def getSomeInputListInt(n):
    inputDataList = []
    outputDataList = []
    for i in range(n):
        inputData = input().split()
        inputDataList = [int(n) for n in inputData]
        outputDataList.append(inputDataList)

    return outputDataList

# ===CODE===

n, = map(str, input().split())
data = list(n)

cntOne = 0
cntZero = 0

for i in range(len(data)):
    if data[i] == "0":
        cntZero += 1
    else:
        cntOne += 1

ans = int(2*min(cntOne, cntZero))
print(ans)

Measured memory_bytes: 14288
/*
  AOJ 1020
  Title:cleaning robot
  @kankichi573
*/
#include <stdio.h>
#include <string.h>
#include <float.h>
int n;
char s,t,b;

double matrix[9][9];
double myvector[9];
char rinsetu[24][2];
char rinsetu_org[12][2]=
  {"AB","BC","DE","EF","GH","HI",
   "AD","DG","BE","EH","CF","FI"};
void init_rinsetu()
{
  int i,j;
  for(i=0;i<12;i++)
    for(j=0;j<2;j++)
      rinsetu[i][j]=rinsetu_org[i][j];
}
void make_reverse()
{
  int i;
  for(i=0;i<12;i++)
    {
      rinsetu[i+12][0]=rinsetu[i][1];
      rinsetu[i+12][1]=rinsetu[i][0];
    }
}
void dump_rinsetu()
{
  int i;
  for(i=0;i<24;i++)
    printf("%c%c|",rinsetu[i][0],rinsetu[i][1]);
  printf("\n");
}
void delete_souko(char b)
{
  int i,j;
  for(i=0;i<24;i++)
    for(j=0;j<2;j++)
      if(rinsetu[i][j]==b)
	rinsetu[i][j]='X';
}

void make_matrix(char b)
{
  int i,j;
  double s;

  //printf("SOUKO=%c\n",b);
  init_rinsetu();
  make_reverse();
  //dump_rinsetu();
  delete_souko(b);
  //dump_rinsetu();

  for(i=0;i<9;i++)
    for(j=0;j<9;j++)
      matrix[i][j]=0.0;

  for(i=0;i<24;i++)
    if(rinsetu[i][0]!='X' && rinsetu[i][1]!='X')
      matrix[rinsetu[i][0]-'A'][rinsetu[i][1]-'A']=0.25;

  for(i=0;i<9;i++)
    {
      s=0;
      for(j=0;j<9;j++)
	{
	  if(i!=j)
	    s += matrix[i][j];
	}
      matrix[i][i]=1-s;
    }
}
void matrix_vector_product()
{
  int i,j;
  double work[9];
  for(i=0;i<9;i++)
    {
      work[i]=0.0;
      for(j=0;j<9;j++)
	{
	  work[i]+=myvector[j]*matrix[i][j];
	}
    }
  memcpy(myvector,work,9*sizeof(double));
}
int init_vector(char c)
{
  int i;
  for(i=0;i<9;i++)
    myvector[i]=0.0;
  myvector[c-'A']=1.0;
}
 void dump_matrix()
 {
   int i,j;
   for(i=0;i<9;i++)
     {
       for(j=0;j<9;j++)
	 printf("%0.2lf ",matrix[i][j]);
       printf("\n");
     }
 }
void dump_vector()
{
  int i;
  for(i=0;i<9;i++)
    printf("%0.3lf|",myvector[i]);
  printf("\n");
}
main()
{
  int i;

  while(scanf("%d ",&n) && n)
    {
      scanf("%c %c %c",&s,&t,&b);
      make_matrix(b);
      init_vector(s);
      //dump_matrix();
      //printf("--------------------\n");
      //dump_vector();
      for(i=0;i<n;i++)
	{
	  matrix_vector_product();
	  //dump_vector();
	}
      printf("%.7lf\n",myvector[t-'A']);
    }


  return(0);
}

Measured memory_bytes: 644
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli; 

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    lli n,temp1,temp2,t,x,y,m,k,b,temp,q,d,p;
	cin>>n>>k;
	
	vector<lli>v(n);
	
	for(int i =0;i<n;i++)
	{
		cin>>v[i];
	}
	sort(v.begin(),v.end());
	lli ans=0;
	for(int i =0;i<k;i++)
	{
		ans+=v[i];
	}
	cout<<ans<<endl;
}

	
	


Measured memory_bytes: 3652
#include <stdio.h>

int main(){
    int n;
    
    scanf("%d",&n);
    int nf=n;
    int sn=0;
    while(n>0){
        sn+=n%10;
        n/=10;
    }
    if(nf%sn==0){
        printf("Yes\n");
    }else{
        printf("No\n");
    }
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define MAXN 100100
#define pii pair<int, int>
#define pb push_back
typedef long long ll;

using namespace std;

int n, k, a[MAXN], dp[MAXN];

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
    cin >> n >> k;
    for(int i = 0; i < n; i++){
    	cin >> a[i];
    }
    for(int i = 1; i <= k; i++){
    	for(int j = 0; j < n; j++){
    		if(i - a[j] >= 0 and not dp[i - a[j]]){
    			dp[i] = true;
    		}
    	}
    }
    if(dp[k]) cout << "First";
    else cout << "Second";
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, sum = 0;
  cin >> N;
  int M = N;
 
  for (int i = 0; i < 9; i++) {
    sum += M % 10;
    M /= 10;
  }
  
  if (N % sum == 0) {
    cout << "Yes";
  } else {
    cout << "No";
  }
}

Measured memory_bytes: 256
n = int(input())
book = {}
array = [int(i) for i in input().split()]

for i in array:
    book[i] = book.get(i, 0) + 1

sum_val = 0
delta = {}
for k, v in book.items():
    t = (v * (v - 1)) // 2 if v > 0 else 0
    sum_val += t
    u = v - 1
    delta[k] = t - (u * (u - 1)) // 2 if u > 0 else 0

for i in range(n):
    print(sum_val - delta[array[i]])


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

int main(){
  int N;
  cin >> N;
  int c2=0;
  int c4=0;
  for(int i=0;i<N;i++){
    int64_t a;
    cin >> a;
    if(a%4==0){
      c4++;
    }else if(a%2==0){
      c2++;
    }
  }
  if(c2==0){
    if(c4>=N/2){
      cout << "Yes" << endl;
    }else{
      cout << "No" << endl;
    }
  }else if(c2==N){
    cout << "Yes" << endl;
  }else{
    if(c4>=(N-c2+1)/2){
      cout << "Yes" << endl;
    }else{
      cout << "No" << endl;
    }
  }
  return 0;
}


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

int main(){
int a,ans,num;
string b;
cin >> a;
ans =a;
while(1){
cin >> b;
if(b == "="){
cout << ans << endl;
 break;}
cin >> num;

if(b == "+") ans += num;
if(b == "-") ans -= num;
if(b == "*") ans *= num;
if(b == "/") ans /= num;
}

}
   


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

int main(){
  ll a,b,n,ans,c;
  cin >> a >> b >> n;
  if(n>=b){
    c=b-1;
  }
  else{
    c=n;
  }
  ans=a*c/b;
  cout << ans;
}

Measured memory_bytes: 3624
from collections import defaultdict
N, K = map(int, input().split())
dic = defaultdict(int)
m = 0

for i in range(1, N+1):
  if i%K==0:
    dic[0] += 1
  elif (2*i)%K==0:
    dic[i%K] += 1
    if m==0:
      m = i

ans = 0
for k in dic.keys():
  ans += dic[k]**3
print(ans)

Measured memory_bytes: 3572
def solve():
    N = int(input())
    A = list(map(int,input().split()))
    B = []
    for i in range(1,N+1):
        B.append(A[i-1] - i)
    B.sort()
    b = 0
    if N % 2 == 0:
        b = (B[N//2] + B[N//2-1]) // 2
    else:
        b = B[N//2]
    
    ans = 0
    for elem in B:
        ans += abs(elem - b)
    
    print(ans)

if __name__ == '__main__':
    solve()

Measured memory_bytes: 99540
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
int main()
{
  int n,t=0,i,res;
  string s;
  cin >> n >> s;
  res=n;
  for(i=1;i<n;i++)
    if(s[i]=='E') t++;
  res=t;
  for(i=1;i<n;i++){
    if(s[i-1]=='W') t++;
    if(s[i]=='E') t--;
    res=min(res,t);
  }
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 900
#include <iostream>
#include <cmath>
#include <algorithm>
#include <climits>
#include <vector>
#include <string>
#include <set>
#include <iomanip>
#include <map>
#define rep(i,n) for (int i=0;i<(n);++i)
#define REP(i,n) for (int i=0;i<=(n);++i)
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
const int INF = 10000000;

int gcd(int a,int b){return b?gcd(b,a%b):a;}


int main(){
    ll n;
    cin >> n;

    int i, j, flag;

    for(i = n; i <= 1000000; ++i){
        flag = 0;
        for(j = 2; j < i; ++j){
            if(i % j == 0){
                flag = 1;
                break;
            }
        }
        if(flag == 0 && n <= i){
            cout << i << endl;
            return 0;
        }
    }

    return 0;
}


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

int main(){
    int n1, n2 = 360, max;
    cin >> n1;
    if(360 % n1 == 0){
        cout << 360 / n1 << endl;
        return 0;
    }
    else {
        max = (n1 > n2) ? n1 : n2;

        do
        {
            if (max % n1 == 0 && max % n2 == 0)
            {
                cout << max/n1 << endl;
                break;
            }
            else
                ++max;
        } while (true);
    }
    return 0;
}

Measured memory_bytes: 3628
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		// 自分の得意な言語で
		// Let's チャレンジ！！

		Scanner sc = new Scanner(System.in);
		int num = sc.nextInt();
		int a=sc.nextInt();
		int b=sc.nextInt();
		int ans=0;
		if(a*num<b) ans=a*num;
		else ans=b;
						System.out.println(ans);
	}
}

Measured memory_bytes: 23764
import java.util.TreeSet;
import java.util.Arrays;
import java.util.SortedSet;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        SortedSet<Integer> k = new TreeSet<>(Arrays.asList(1, 4, 7, 9));
        SortedSet<Integer> m = new TreeSet<>();
        Scanner sc = new Scanner(System.in);
        for (int i = 0; i < 4; i++) {
            int z = sc.nextInt();
            if (k.contains(z)) {
                m.add(z);
            }
        }
        if (m.toArray().length == 4) {
            System.out.println("YES");
        } else {
            System.out.println("NO");
        }
    }
}


Measured memory_bytes: 21844
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <queue>
#include <string>
#include <set>
#include <map>
#define REP(i,n) for(ll i = 0; i < (ll)n; i++)
#define INF 1000000000000000
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;

ll gcd(ll a, ll b){
  if(a<b) swap(a,b);
  return (a%b==0) ? b : gcd(b,a%b);
}

int main(){
  int n;
  cin >> n;
  ll a[n];
  REP(i,n) cin >> a[i];
  ll ans = a[0];
  REP(i,n-1){
    ans = gcd(ans,a[i+1]);
  }
  cout << ans << endl;
  return 0;
}


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

ll dp[100100]; // -INFくらいで初期化
const ll INF = 100100100100100;
int N;
ll b[20][20];

ll bfs(int n){
    if(dp[n]!=-INF) {return dp[n];}
    if(n==0){return dp[0]=0;}
    ll res=-INF;
    for(int i=n; i>0 ; i=(i-1)&n){
        if(i==0 || i==n){
            ll a=0;
            for(int i=0; i<N; i++){
                for(int j=i+1; j<N; j++){
                    if( (n & (1<<i) )&& (n & (1<<j) ) ){
                        a += b[i][j];
                    }
                }
            }
            res = a;
        }
        else{
            ll a = bfs(i) + bfs(n-i);
            res = max(res, a);
        }
    }
    dp[n]=res;
    return dp[n];
}

int main(){
    cin >> N;
    for(int i=0; i<N; i++){
        for(int j=0; j<N; j++){
            cin >> b[i][j];
        }
    }
    for(int i=0; i<pow(2,N); i++){
        dp[i]=-INF;
    }

    cout << bfs( (int)pow(2,N)-1) << endl;
}

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

using pii = pair<int, int>;

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

using edges = vector<edge>;
using graph = vector<edges>;

void add_edge(graph& g, 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_flow(graph& g, int s, int t, int f) {
    constexpr int INF = 1e9;
    int res = 0;
    const int N = g.size();
    vector<int> h(N);
    vector<int> dist(N);
    vector<int> prevv(N), preve(N);
    while(f > 0) {
        priority_queue<pii, vector<pii>, greater<pii>> que;
        fill(dist.begin(), dist.end(), INF);
        dist[s] = 0;
        que.push(make_pair(0, s));
        while(!que.empty()) {
            pii p = que.top();
            que.pop();
            int v = p.second;
            if(dist[v] < p.first) {
                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 + h[v] - h[e.to]) {
                    dist[e.to] = dist[v] + e.cost + h[v] - h[e.to];
                    prevv[e.to] = v;
                    preve[e.to] = i;
                    que.push(make_pair(dist[e.to], e.to));
                }
            }
        }
        if(dist[t] == INF) {
            return -1;
        }
        for(int v=0; v<N; ++v) {
            h[v] += dist[v];
        }
        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*h[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 N;
    while(cin >> N, N) {
        graph g(366);
        for(int i=0; i<365; ++i) {
            add_edge(g, i, i+1, 2, 0);
        }
        for(int i=0; i<N; ++i) {
            int s, t, w;
            cin >> s >> t >> w;
            add_edge(g, s-1, t, 1, -w);
        }
        cout << -min_cost_flow(g, 0, 365, 2) << endl;
    }
}

Measured memory_bytes: 3172
#include <iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<map>
using namespace std;
int main()
{
	int num, count = 1, min;
	cin >> num;
	int *arr = new int[num];
	bool smaller = false;
	for (int i = 0; i < num; i++)
		cin >> arr[i];

	min = arr[0];
	for (int i = 1; i < num; i++)
	{
		if (arr[i] <= arr[i - 1] && arr[i] <= min)
		{
			count++;
			min = arr[i];
		}
		
	}
	cout << count << endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <stdlib.h>
#include <functional>
#include <sstream>
#include <bitset>

using namespace std;

typedef long long ll;
const ll InF = 1e13;
const string MININF = "-";

int weight[9] = {2,5,5,4,5,6,3,7,6};
string dp[10010];

string stringmax (string a, string b) {
  if (a == MININF) a = b;
  if (a.size() != b.size()) {
    if (a.size() > b.size()) return a;
    else return b;
  } else {
    if (a < b) return b;
  }
  return a;
}

int main() {
  int N,M;
  cin>>N>>M;
  vector<int> A(M);
  for (int i = 0; i < M; i++) cin>>A[i];
  for (int i = 0; i < N; i++) dp[i] = "-";
  dp[0] = "";
  for (int i = 0; i < N; i++) {
    if (dp[i]==MININF) continue;
    for (int j = 0; j < M; j++)  dp[i+weight[A[j]-1]] = stringmax(dp[i+weight[A[j]-1]],dp[i]+to_string(A[j]));
  }
  cout<<dp[N]<<endl;
  return 0;
}

Measured memory_bytes: 33024
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
//#include<bits/stdc++.h>
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int cm = 1 << 17;
char cn[cm], * ci = cn + cm, ct;
inline char getcha() {
	if (ci - cn == cm) { fread_unlocked(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}
inline int getint() {
	int A = 0;
	if (ci - cn + 16 > cm) while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';
	else while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
	return A;
}

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


	int N = getint(), K = getint();
	int P[200001];

	ll saidai = 0;
	ll ima = K;
	rep(i, K) {
		P[i] = getint();
		ima += P[i];
	}
	saidai = ima;

	int k = 0;
	for (int i = K; i < N; i++, k++) {
		if (k == K) k = 0;
		ima -= P[k];
		P[k] = getint();
		ima += P[k];
		chmax(saidai, ima);
	}

	double kotae = saidai * 0.5;

	printf("%.6f", kotae);

	Would you please return 0;
}

Measured memory_bytes: 1024
import sys
from collections import defaultdict
readline = sys.stdin.readline
N, = map(int, readline().split())
def con(ll,E):
    r = 0
    for u, v in zip(ll,ll[1:]):
        u, v = sorted([u,v])
        r += 1<<E[(u,v)]
    return r

def process():
    G = [[] for _ in range(N+1)]
    E = dict()
    for i in range(N-1):
        a, b = sorted(map(int, readline().split()))
        G[a].append(b)
        G[b].append(a)
        E[(a,b)] = i

    M, = map(int, readline().split())
    qes = dict()
    for _ in range(M):
        u, v = sorted(map(int, readline().split()))
        if u not in qes:
            qes[u] = list()
        qes[u].append(v)
    dep = []
    for i in qes:
        ms = qes[i]
        path = []
        stack = [i]
        vs = set([i])
        while stack:
            v = stack.pop()
            if v > 0:
                vs.add(v)
#                parent = path[-1]
                path.append(v)
                for u in G[v]:
                    if u in vs:
                        continue
                    if u in ms:
                        dep.append(con(path+[u],E))
                    stack += [-v, u]
            else:
                path.pop()
    r = 0
    for i in range(1,2**M):
        t = 0
        ns = 0
#        lns = 
        for j in range(M):
            if i % 2:
                ns = ns | dep[j]
                t += 1
            i = i>>1
        xx = (1 if t%2 else -1)*2**(N-1-bin(ns).count("1"))
        r += xx
    print(2**(N-1)-r)
if __name__ == '__main__':
    process()


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

#define MAX_N 100010

struct point {int id, x, y;};
point p[4][2 * MAX_N];

int r, c, n;
stack <int> s;

int boundary(int x, int y)
{
    if (x == 0) return 0;
    else if (y == c) return 1;
    else if (x == r) return 2;
    else if (y == 0) return 3;
    else return -1;
}

bool cmp0(point a, point b)
{
    return a.y < b.y;
}

bool cmp1(point a, point b)
{
    return a.x < b.x;
}

bool cmp2(point a, point b)
{
    return a.y > b.y;
}

bool cmp3(point a, point b)
{
    return a.x > b.x;
}

int main(void)
{
    scanf("%d%d%d", &r, &c, &n);
    int cnt[4] = {0};
    for (int i = 1; i <= n; i++) {
        int x1, y1, x2, y2;
        scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
        if ((x1 % r == 0 || y1 % c == 0) && (x2 % r == 0 || y2 % c == 0)) {
            int b1 = boundary(x1, y1), b2 = boundary(x2, y2);
            point p1 = {i, x1, y1}, p2 = {i, x2, y2};
            p[b1][cnt[b1]++] = p1;
            p[b2][cnt[b2]++] = p2;
        }
    }
    sort(p[0], p[0] + cnt[0], cmp0);
    sort(p[1], p[1] + cnt[1], cmp1);
    sort(p[2], p[2] + cnt[2], cmp2);
    sort(p[3], p[3] + cnt[3], cmp3);
    for (int i = 0; i < 4; i++) {
        for (int j = 0; j < cnt[i]; j++) {
            if (s.size() && s.top() == p[i][j].id)
                s.pop();
            else
                s.push(p[i][j].id);
        }
    }
    if (s.empty()) printf("YES\n");
    else printf("NO\n");
    return 0;
}


Measured memory_bytes: 7680
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<algorithm>
#include<functional>
#include<utility>
#include<bitset>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<cstdio>
using namespace std;
int a,b;
int main()
{
	cin>>a>>b;
	if(a<b)
	{
		cout<<0<<endl;
	}
	else
	{
		cout<<10<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
import numpy as np
n,m=map(int,input().split())
a=sorted(list(map(int,input().split())))
l=[list(map(int,input().split())) for i in range(m)]
l.sort(key=lambda x: x[1], reverse=True)
l=np.array(l)


nl=[]
k=0
i=0
while k<=n and i<m:
  nl.extend([l[i][1]]*l[i][0])
  k+=l[i][0]
  i+=1


for i in range(min(n,np.sum(l, axis=0)[0])):
  if nl[i]<=a[i]:
    print(sum(nl[0:i])+sum(a[i:n]))
    exit()
if n<np.sum(l, axis=0)[0]:
  print(sum(nl[0:n]))
else:
  print(sum(nl)+sum(a[np.sum(l, axis=0)[0]:n]))

Measured memory_bytes: 42628
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

int main() {
	ll n;
	cin>>n;
	for(ll i=0;i<=n;i++){
		if(ll(i*1.08)==n){
			cout <<i;
			return 0;
		}
	}
	cout <<":(";
	// your code goes here
	return 0;
}

Measured memory_bytes: 256
using System;

namespace ABC140B
{
    class Program
    {
        static void Main(string[] args)
        {
            int aa = int.Parse(Console.ReadLine());
            int[] b = new int[aa+1];
            int[] c = new int[aa];
            int[] d = new int[aa + 1];
            int v = 0;
            int x = 0;
            var a = Console.ReadLine().Split(' ');
            var ab = Console.ReadLine().Split(' ');
            var ac = Console.ReadLine().Split(' ');
            int n =int.Parse( a [aa - 1]);
            
            for (int i = 1;i <= aa;i++)
            {
                d[i] = int.Parse(a[i - 1]);
                b[i] = int.Parse(ab[i-1]);
                x += b[i];
               
            }
            for (int i = 1; i <= aa - 1; i++)
            {
                c[i] = int.Parse(ac[i-1]);
            }
            for (int i = 1; i <= aa - 1; i++)
            {

                if (d[i + 1] - d[i] == 1)
                    x += c[d[i]];
            }

            
            Console.WriteLine(x);
        }
    }
}

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

using namespace std;

string a;
string n="CODEFESTIVAL2016";
int sum=0;


int main()
{
     cin>>a;
     for(int i=0;i<16;i++)
     {
         if(a[i]!=n[i])
            sum++;
     }

   cout<<sum;







    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int h,m,s,h1,m1,s1,h2,m2,s2;
	int g,a,b;

	scanf("%d %d %d",&h,&m,&s);
	while(h!=-1 && m!=-1 && s!=-1){
		g=h*3600+m*60+s;
		a=7200-g;
		b=a*3;
		
		h1=a/3600;
		a=a%3600;
		m1=a/60;
		s1=a%60;

		h2=b/3600;
		b=b%3600;
		m2=b/60;
		s2=b%60;

		if(h1<10 && m1<10 && s1<10){
			printf("0%d:0%d:0%d\n",h1,m1,s1);
		}
		else if(m1<10 && s1<10){
			printf("%d:0%d:0%d\n",h1,m1,s1);
		}
		else if(h1<10 && s1<10){
			printf("0%d:%d:0%d\n",h1,m1,s1);
		}
		else if(h1<10 && m1<10){
			printf("0%d:0%d:%d\n",h1,m1,s1);
		}
		else if(s1<10){
			printf("%d:%d:0%d\n",h1,m1,s1);
		}
		else if(m1<10){
			printf("%d:0%d:%d\n",h1,m1,s1);
		}
		else if(h1<10){
			printf("0%d:%d:%d\n",h1,m1,s1);
		}
		if(h2<10 && m2<10 && s2<10){
			printf("0%d:0%d:0%d\n",h2,m2,s2);
		}
		else if(m2<10 && s2<10){
			printf("%d:0%d:0%d\n",h2,m2,s2);
		}
		else if(h2<10 && s2<10){
			printf("0%d:%d:0%d\n",h2,m2,s2);
		}
		else if(h2<10 && m2<10){
			printf("0%d:0%d:%d\n",h2,m2,s2);
		}
		else if(s2<10){
			printf("%d:%d:0%d\n",h2,m2,s2);
		}
		else if(m2<10){
			printf("%d:0%d:%d\n",h2,m2,s2);
		}
		else if(h2<10){
			printf("0%d:%d:%d\n",h2,m2,s2);
		}
		
		scanf("%d %d %d",&h,&m,&s);
	}
	return 0; 
}

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

typedef long long ll;

int main(){
    string s,t;
    cin>>s>>t;
    int idx = (int)t.size()-1;
    t.erase(idx,1);

    cout<<((s==t) ? "Yes" : "No")<<endl;

    return 0;
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
//io
#define s(x) scanf(" %d",&x)
#define si(x) scanf(" %d",&x)
#define sll(x) scanf(" %lld",&x)
#define sf(x) scanf(" %lf",&x)
#define ss(x) scanf(" %s",x)
#define sl(x) scanf(" %[^\n]",x)
#define sc(x) scanf("%c",&x)
#define p(x) printf(x)
#define pi(x) printf("%d",x)
#define ps(x) printf("%s",x)
#define pll(x) printf("%lld",x)
#define pf(x) printf("%lf",x)
#define pc(x) printf("%c",x)
#define endl "\n"
#define pn() printf("\n")
#define fio() ios_base::sync_with_stdio(false);cin.tie(NULL)
//loops
#define F(x,n) for(int i=x;i<n;i++)
#define Fr(x,n,c) for(int i=x;i<n;i+=c)
#define R(x,n) for(int j=x;j<n;j++)
#define Rr(x,n,c) for(int j=x;j<n;j+=c)
#define V(x,n) for(int k=x;k<n;k++)
#define Vr(x,n,c) for(int k=x;k<n;k+=c)
//ds
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
#define vi vector<int>
#define pb push_back
#define all(x) x.begin(),x.end()
#define test() int __T;scanf("%d",&__T);for(int __t=1;__t<=__T;__t++)
#define mem0(x) memset(x,0,sizeof(x))
#define memdp(x) memset(x,-1,sizeof(x))
#define mp(x,y) make_pair(x,y)
bool prime(int n) {
	if(n%2==0) return false;
	for(int i=3;i<=sqrt(n);i+=2)
	if(n%i==0) return false;
	return true;
}
#define int long long
int32_t main() {
	int n,k;
	cin>>n>>k;
	int a[n];
	F(0,n)cin>>a[i];
	sort(a,a+n);
	int m=0,j=n-1;
	while(k-- and j>=0) {
		a[j]=0;
		j--;
	}
	F(0,n) m+=a[i];
	cout<<m;
	return 0;
}























Measured memory_bytes: 1792
// qwq
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define Fast_IO ios::sync_with_stdio(false);
#define DEBUG fprintf(stderr,"Running on Line %d in Function %s\n",__LINE__,__FUNCTION__)
//mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#define fir first
#define sec second
#define mod 998244353
#define ll long long
#define inf 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f3f
inline int read()
{
	char ch=getchar(); int nega=1; while(!isdigit(ch)) {if(ch=='-') nega=-1; ch=getchar();}
	int ans=0; while(isdigit(ch)) {ans=ans*10+ch-48;ch=getchar();}
	if(nega==-1) return -ans;
	return ans;
}
typedef pair<int,int> pii;
#define N 200005
int a[N],b[N],n,m;
struct SMT
{
	#define ls (u<<1)
	#define rs (u<<1|1)
	#define mid ((l+r)/2)
	int t[N*4];
	void update(int u,int l,int r,int L,int R)
	{
		if(L<=l&&r<=R)
		{
			t[u]=1;
			return ;
		}
		if(mid>=L) update(ls,l,mid,L,R);
		if(mid<R) update(rs,mid+1,r,L,R);
		if(t[ls]&&t[rs]) t[u]=1;
	}
	int query(){return t[1];}
}smt;
struct SMT2
{
	#define ls (u<<1)
	#define rs (u<<1|1)
	#define mid ((l+r)/2)
	int t[N*4];
	void build(int u,int l,int r)
	{
		t[u]=inf;
		if(l==r) return ;
		build(ls,l,mid),build(rs,mid+1,r);
	}
	int tag[N*4];
	void pushdown(int u)
	{
		if(tag[u])
		{
			tag[ls]=tag[rs]=1;
			t[ls]=t[rs]=inf;
			tag[u]=0;
		}
	}
	void update(int u,int l,int r,int L,int R)
	{
		if(L<=l&&r<=R)
		{
			t[u]=inf,tag[u]=1;
			return ;
		}
		pushdown(u);
		if(mid>=L) update(ls,l,mid,L,R);
		if(mid<R) update(rs,mid+1,r,L,R);
		t[u]=min(t[ls],t[rs]);
	}
	void update2(int u,int l,int r,int pl,int v)
	{
		if(l==r) {t[u]=min(t[u],v); return ;}
		pushdown(u);
		if(pl<=mid) update2(ls,l,mid,pl,v);
		else update2(rs,mid+1,r,pl,v);
		t[u]=min(t[ls],t[rs]);
	}
	int query(){return t[1];}
}smt2;
set<pii> s;
signed main()
{
	cin>>n>>m;
	for(int i=1;i<=n;i++) a[i]=read(),b[i]=read();
	// int tmin=inf;
	for(int i=1;i<=m;i++) s.insert(mp(i,0));
	// smt2.build(1,1,m);
	for(int i=1;i<=n;i++)
	{
		int R=smt.query();
		smt.update(1,1,m,a[i],b[i]);
		smt2.update(1,1,m,a[i],b[i]);
		// for(auto [u,v]:s) printf("%d %d\n",u,v); cout<<"\n";
		{
			auto x=s.lower_bound(mp(a[i],0));
			vector<pii> er;
			int ans=smt2.query()+i,res=inf;
			while(x!=s.end()&&(*x).fir<=b[i])
			{
				auto [u,v]=*x;
				if(b[i]!=m) res=min(res,v+b[i]-u+1+i);
				er.eb(u,v);
				x++;
			}
			for(auto x:er) s.erase(x);
			ans=min(ans,res);
			printf("%d\n",ans>=inf?-1:ans);
			s.insert(mp(b[i]+1,res-i));
			// tmin=min(tmin,ans-i);
			if(b[i]!=m) smt2.update2(1,1,m,b[i]+1,res-i);
		}
	}
	return 0;
}


Measured memory_bytes: 20816
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll inf = 1e18;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define per(i, a, b) for (int i = b - 1; i >= a; i--)
#define int ll
using pint = pair<int, int>;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

signed main() {
    string s;
    int k;
    cin >> s >> k;
    int n = s.size();
    string t = s + s;
    int sum = 0, sum2 = 0;
    rep(i, 1, 2 * n) {
        if (t[i - 1] == t[i]) {
            sum++;
            t[i] = '1';
        }
    }
    // cout << t << "\n";
    // cout << t[2 * n - 1] << t[0] << "\n";
    if (t[2 * n - 1] == t[0]) {
        sum2++;
        t[2 * n - 1] = '1';
    }
    int cnt = 0, cnt2 = 0;
    rep(i, 1, n) {
        if (s[i - 1] == s[i]) {
            cnt++;
            s[i] = '1';
        }
    }
    int ans = 0;
    // cout << sum << " " << sum2 << "\n";
    if (k == 1) {
        ans = cnt;
    } else {
        if (k % 2 == 0) {
            ans = sum * (k / 2) + sum2 * (k / 2 - 1);
        } else {
            ans = sum * (k / 2) + cnt;
        }
    }
    // cout << t[2 * n - 1] << t[0] << "\n";
    cout << ans << "\n";
}

Measured memory_bytes: 3580
#include<stdio.h>
	int c[500];
	int s[500];
	int f[500];
	int n;
int solve(int i){
	int now=0;
	for(int j=i;j<n-1;j++){
		if(now<s[j]){
			now=s[j];
		}
		while(now%f[j]!=0){
			now++;
		}
		now+=c[j];
	}
	printf("%d\n", now);
	return 0;
}

int main(){
	scanf("%d",&n);
//	int c[500];
//	int s[500];
//	int f[500];
	for(int i=0;i<n-1;i++){
		scanf("%d %d %d",&c[i], &s[i], &f[i]);
	}
	for(int i=0;i<n-1;i++){
		solve(i);
	}
	printf("0\n");
}

	


/*int main(){
//	int n=100000;
	char s[15];
	int a=0;
	int b=0;
	scanf("%d %d",&a, &b);

	for(int i=0;i<15;i++){
		s[i]='x';
	}
	scanf("%s", s);
	int size=0;
	int hifn=0;
	for(int i=0;i<15;i++){
		if(s[i]!='x'){
//					printf("%d %c\n",i,s[i]);
 
			size++;
		}
	}
		for(int i=0;i<15;i++){
		if(s[i]=='-'){
//					printf("%d %c\n",i,s[i]);
 
			hifn++;
		}
	}
		size--;

	if(size==a+b+1&&hifn==1&&s[a]=='-'){
		printf("Yes\n");
	}else{
		printf("No\n");
	}
	//				printf("%d\n",size);
 

}*/

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

#define loop(i,a,b) for(int i=(a); i<int(b); i++)
#define rep(i,b) loop(i,0,b)
#define iter(it,c) for(auto it=c.begin(); it!=c.end(); it++)
typedef vector<int> vi;
typedef vector<vi> vvi;

void visit(const vvi &g, int v, vvi& scc,
           stack<int> &S, vector<bool> &inS,
           vector<int> &low, vector<int> &num, int& time) {
    low[v] = num[v] = ++time;
    S.push(v); inS[v] = true;
    iter(e, g[v]) {
        int w = *e;
        if (num[w] == 0) {
            visit(g, w, scc, S, inS, low, num, time);
            low[v] = min(low[v], low[w]);
        } else if (inS[w])
            low[v] = min(low[v], num[w]);
    }
    if (low[v] == num[v]){
        scc.push_back(vi());
        while (1) {
            int w = S.top(); S.pop(); inS[w] = false;
            scc.back().push_back(w);
            if (v == w) break;
        }
    }
}

void scc(vvi const& g, vvi& res) {
    int const n = g.size();
    vi num(n), low(n);
    stack<int> S;
    vector<bool> inS(n);
    int time = 0;
    rep(u,n)if(num[u]==0) visit(g, u, res, S, inS, low, num, time);
}

int main(){
    int n;
    while(cin>>n,n){
        vvi g(n*n);
        rep(i,n)rep(j,n){
            int x,y; cin>>x>>y;
            int u=i*n+j;
            int v=y*n+x;
            g[u].push_back(v);
        }
        vvi ans;
        scc(g,ans);
        int c=0;
        rep(i,ans.size()){
            if(ans[i].size()==1){
                if(g[ans[i][0]][0]!=ans[i][0]) c++;
            }
        }
        cout << ans.size()-c << endl;
    }
}

Measured memory_bytes: 2396
#include <bits/stdc++.h>
using namespace std;
int main(){
  long long N,a;
  int b;
  cin>>N;
  vector<char> ans(0);
  while(N>=1){
    a=N/26,b=N%26;
    if(b==0){b=26;}
    b+=96;
    char c=b;
    ans.push_back(c);
    N/=26;
    if(b==122){N--;}
  }
  for(int i=0;i<(int)ans.size();i++){
    cout<<ans.at((int)ans.size()-1-i);
  }
}

Measured memory_bytes: 3620
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
vector<int>v,a;
int vis[1000];
set<int>s;
int main(){
    ll n,k; cin>>n>>k;

    int cnt=0;
	  for(int i=1;i<=n;i++){
	       for(int j=i+1;j<=n;++j){
	           if(abs(i-j)>1){
	           		v.push_back(i);
	           		v.push_back(j);
	           }
	       }
	   }
	cnt=a.size();
	for(int i=0;i<v.size();++i)
		s.insert(v[i]);
	
	for(auto i:s)
		a.push_back(i);
	
	cnt=a.size();
    /*for(int i=0;i<a.size();++i){
    	cout<<a[i]<<endl;
    	for(int j=i+1;j<a.size();++j){
    		if(abs(a[i]-a[j])<=1){
    		   if(vis[a[i]]||vis[a[j]]) continue;
               else{
                   cnt--;
                   //vis[a[i]]=1;
                   vis[a[j]]=1;
               }
    		}
    	}
    }*/
    cnt=n;
    for(int i=1;i<n;i+=2) cnt--;
    //cout<<cnt;
    if(cnt>=k) cout<<"YES";
    else cout<<"NO";
       
   
}


Measured memory_bytes: 384
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

res = sum(B)
for i, (p, n) in enumerate(zip(A[:N-1], A[1:])):
    if n - p == 1:
        res += C[A[i]-1]
print(res)

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

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;

#define INF (1LL << 60)
#define MOD 1000000007
#define PI 3.14159265358979323846

#define REP(i,m,n) for(ll (i)=(m),(i_len)=(n);(i)<(i_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define PR(x) cout << (x) << endl
#define PS(x) cout << (x) << " "
#define SZ(x) ((ll)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define ASC(x) sort(ALL((x)))
#define DESC(x) sort(ALL((x)),greater<ll>())
#define pb push_back

struct edge {
    ll w, to;
};

void bfs(vector<vector<edge>> G, ll r, vec& f)
{
    queue<ll> Q;
    Q.push(r);
    f[r] = 0;
    while(!Q.empty()) {
        ll v = Q.front(); Q.pop();
        FORR(ne,G[v]) {
            ll nw = ne.w, nv = ne.to;
            if(f[nv] == -1) {
                Q.push(nv);
                if(nw % 2 == 0) f[nv] = f[v];
                else f[nv] = 1 - f[v]; 
            }
        }
    }
}

int main()
{
    ll N;
    cin >> N;
    vector<vector<edge>> G(N);
    ll u, v, w;
    REP(i,0,N-1) {
        cin >> u >> v >> w;
        --u; --v;
        G[u].pb((edge){w,v});
        G[v].pb((edge){w,u});
    }
    
    vector<ll> F(N, -1);
    bfs(G, 0, F);
    REP(i,0,N) PR(F[i]);


    return 0;
}

/*



*/

Measured memory_bytes: 15488
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define mp make_pair
#define pb push_back
#define ip pair<ll,ll>
#define ff first
#define ss second
#define MAX 100005
const ll MOD = 1000000007;

unordered_map<ll,ll> f;
ll d;
ll divs[3] = {2,3,5};
ll cost[3];
ll solve(ll n){
	if(n == 0)
		return 0;
	if(n == 1)
		return d;

	if(f.count(n))
		return f[n];


	ll best = MOD*MOD;
	if(MOD*MOD/n >= d)
		best = n*d;
	
	for(int j=0;j<3;j++){
		ll val = divs[j];
		ll i = n;
		while(i%val != 0)
			++i;
		best = min(best,(i-n)*d + cost[j] + solve(i/val));
		i -= val;
		best = min(best,(n-i)*d + cost[j] + solve(i/val));	
	}

	f[n] = best;
	return best;
}

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

	int t;
	cin>>t;
	while(t--){
		f.clear();
		ll n;
		cin>>n>>cost[0]>>cost[1]>>cost[2]>>d;
		cout<< solve(n) <<"\n";
	}
}

Measured memory_bytes: 4188
h, w = gets.split.map(&:to_i)
g = Array.new(h){gets.chomp.chars}
dp = Array.new(h){Array.new(w, 0)}
dp[0][0] = 1
h.times do |i|
  w.times do |j|
    dp[i][j] += dp[i-1][j] if 0 < i && g[i-1][j] == '.'
    dp[i][j] += dp[i][j-1] if 0 < j && g[i][j-1] == '.'
    dp[i][j] %= 10**9+7
  end
end
puts dp[h-1][w-1]


Measured memory_bytes: 89212
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
#define mp make_pair

template<class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }

int main() {
	int n=in();
	int i;
	Int sum=0;
	for(i=0;i<n;i++){
		sum+=in();
	}
	cout<<sum/n<<endl;
	return 0;
}

Measured memory_bytes: 0
require 'set'; require 'prime'; require 'pp'
INF=Float::INFINITY; MOD=10**9+7
n = gets.chomp.to_i
a = gets.chomp.split.map(&:to_i)

money = 1000
cur = INF
a.each do |yen|
  if cur >= yen
    cur = yen
  else
    suu = (money / cur)
    money = money + suu * (yen - cur)
    cur = yen
  end
  # p [yen, money]
end

puts money



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

const int MAX = 100;
int n;
int G[MAX + 1][MAX + 1];
int states[MAX + 1];
int d[MAX + 1];
queue<int> Q;

void bfs(int id) {
  d[id] = 0;
  states[id] = 1;
  Q.push(id);

  while (!Q.empty()) {
    id = Q.front(); Q.pop();
    for (int i = 0; i < n; i++) {
      if (G[id][i] == 1 && states[i] == 0) {
        Q.push(i);
        states[i] = 1;
        d[i] = d[id] + 1;
      }
    }
  }
}

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

  cin >> n;

  int u, v, k;

  for (int i = 0; i < n; i++) {
    d[i] = -1;
    states[i] = 0;
    for (int j = 0; j < n; j++) {
      G[i][j] = 0;
    }
  }

  for (int i = 0; i < n; i++) {
    cin >> u >> k;
    if (k > 0) {
      for (int j = 0; j < k; j++) {
        cin >> v;
        G[u - 1][v - 1] = 1;
      }
    }
  }

  bfs(0);

  for (int i = 0; i < n; i++) {
    cout << i + 1 << " " << d[i] << endl;
  }

  return 0;
}

Measured memory_bytes: 3192
var s:string;
i,j:longint;
begin
readln(s);
for i :=1 to length(s) do
  for j:=i+1 to length(s) do
    if (s[i]+s[j]='CF')then
      begin
      writeln('Yes');
      halt;
      end;
writeln('No');
end.

Measured memory_bytes: 128