akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(i=0;i<(n);i++)
#define loop(i,a,n) for(i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;

int g[6][6][4]={};//top,bottom,left,right

int main(void) {
  int i,j;
  rep(i,9){
    string s;
    cin>>s;
    if(i%2){
      rep(j,5){
        g[i/2+1][j][3] = s[j] - '0';
        g[i/2+1][1+j][2] = g[i/2+1][j][3];
      }
    }else{
      rep(j,4){
        g[i/2+1][1+j][0] = s[j] - '0';
        g[i/2][1+j][1] = g[i/2+1][1+j][0];
      }
    }
  }

  char s[5] = {"LRDU"};
  int dx[4] = {0,0,1,-1};
  int dy[4] = {-1,1,0,0};

  int x=0,y=1,z=1;//(x,y)右手がz

  while(x+y){
    if(g[x][y][z]){
        cout<<s[z];
        if((z==1 && g[x][y][1] && g[x][y][3]) || (z==0 && g[x][y][0] && g[x][y][2]) ||
          (z==2 && g[x][y][2] && g[x][y][1]) || (z==3 && g[x][y][3] && g[x][y][0])){
            switch(z){
              case 0: z=2;break;
              case 1: z=3;break;
              case 2: z=1;break;
              case 3: z=0;break;
            }
        }else{
          x = x + dx[z];
          y = y + dy[z];
        }
    }else{
      switch(z){
        case 0: z=3;x--;break;
        case 1: z=2;x++;break;
        case 2: z=0;y--;break;
        case 3: z=1;y++;break;
      }
    }
  }
    cout<<endl;
}



Measured memory_bytes: 3136
#include <bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()
#ifdef _DEBUG_
	#define debug(...) printf(__VA_ARGS__)
#else
	#define debug(...) (void)0
#endif
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;

const int N_MAX=1e5+10;
int arr[N_MAX];
const int INF = 1e9+10;

int main() {
	int n, t;
	scanf("%d%d", &n, &t);
	int mi = INF, prf = 0, ans = 0;
	for(int i=0; i<n; i++) {
		scanf("%d", arr+i);
		if(arr[i] - mi > prf)
			prf = arr[i]-mi, ans=1;
		else if(arr[i] - mi == prf)
			ans ++;
		mi = min(mi, arr[i]);
	}
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 640
def main():
  import numpy as np
  import sys 
  input=sys.stdin.readline
  n,m,c=map(int,input().split())
  B=list(map(int,input().split()))
  B=np.array(B)
  cnt=0
  for i in range(n):
    A=np.array(list(map(int,input().split())))
    if (B*A).sum()+c>0:
      cnt+=1
  print(cnt)
if __name__=='__main__':
  main()
    

Measured memory_bytes: 21908
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,n) for(int i=0;i<n;i++)
#define why(n,x) int n;while(cin >>n,n!=x)
#define iFOR(i,x,n)for(int i=x;i<n;i++)
#define fin <<'\n'
#define __ <<" "<<
#define ___ <<" "
#define bash push_back
#define ALL(x) x.begin(),x.end()
#define SWAP(a,b) ((a != b) && (a += b,b = a - b,a -= b))
//#define int long long
typedef long long ll;
typedef pair < int , int >  pii;
typedef vector < int > vit;
typedef map < string , int > mstit;
typedef vector < pii > vpi ;
typedef greater < pii > gpi;
typedef priority_queue < pii , vpi , gpi > dijk ;
static const signed int INF = 0x3f3f3f3f;
static const signed long long LINF = 0x3f3f3f3f3f3f3f3fLL;
static const signed int SMOD = 1000000007;
static const signed int NMOD = 1000000009;
static const signed int dx[]={1,0,-1,0,1,1,-1,-1};
static const signed int dy[]={0,-1,0,1,-1,1,-1,1};

bool inside(int x,int y,int w,int h){return (x>=0 && y>=0 && x<w && y<h);}
template<class T>T abs(T &x){return x<0 ? -x : x;}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
int qp(int a,ll b,int mo){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
int gcd(int a,int b){return b?gcd(b,a%b):a;}


inline void solve(){

    int n,d,a[100005]={};
    int ret = 0;
    cin >> n;
    FOR(i,n){
        cin >> d;
        a[d]++;
    }
    iFOR(i,1,100005){
        a[i] += a[i-1];
        if(a[i] == n/2)
            ret++;
    }

    cout << ret fin;

}
struct xyz{ xyz(){ cin.tie(0), ios::sync_with_stdio(false); cout <<fixed<<setprecision(12);};}xyzzy;signed main(){solve();return 0;}


Measured memory_bytes: 640
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){
		
		Array.Sort(A);
		long sum = 0;
		for(int i=N;i<3*N;i+=2){ sum += A[i];}
		Console.WriteLine(sum);
		
	}
	int N;
	long[] A;
	public Sol(){
		N = ri();
		A = rla();
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}


Measured memory_bytes: 39628
#include<iostream>
#define ll long long
#define MOD 1000000007
using namespace std;
ll dfs(ll& d,int pos,bool flag,string& s,ll sum,ll int ***dp)
{
    if(pos>=s.length())
    {
        if((sum%d)==0)
        {
            
            return 1;
        }
        return 0;
    }
    int limit=s[pos]-'0';
    if(flag)
        limit=9;
    ll res=0;
    if(dp[pos][sum][flag]!=-1)
        return dp[pos][sum][flag];
    for(int g=0;g<=limit;g++)
    {
        if(flag||g<limit)
            res=(res%MOD+dfs(d,pos+1,1,s,(sum+g)%d,dp)%MOD)%MOD;
        else
            res=(res%MOD+dfs(d,pos+1,0,s,(sum+g)%d,dp)%MOD)%MOD;
    }
     dp[pos][sum][flag]=res;
    return res;
}
int main()
{
    string s;
    ll d;
    cin>>s>>d;
    int n=(int)s.length();
    ll int ***dp=new ll int**[n+1];
   
    for(int i=0;i<=n;i++)
    {
        dp[i]=new ll int*[d];
        for(int j=0;j<d;j++)
        {
            dp[i][j]=new ll int[2];
            dp[i][j][0]=-1;
             dp[i][j][1]=-1;
        }
        
    }
    cout<<(dfs(d,0,0,s,0,dp)-1+MOD)%MOD;
}


Measured memory_bytes: 43476
using System;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Diagnostics;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using static System.Math;

class P
{
    static void Main()
    {
        int[] nk = Console.ReadLine().Split().Select(int.Parse).ToArray();
        //mod k
        //a
        //b
        //a
        //a+b=k
        //a+a=k
        //全部同じmod
        //kが3の倍数
        long a = nk[0] / nk[1];
        long b = 0;
        if (nk[1] % 2 == 0)
        {
            b = a;
            if (nk[0] - a * nk[1] >= nk[1] / 2)
            {
                b++;
            }
        }
        Console.WriteLine(a * a * a + b * b * b);
    }
}

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

int main() {
int N,K;
cin>>K>>N;
int x=N*K;
for(int i=0; i<=K;i++){
x = std::pow(2,i)+N*(K-i);
if (std::pow(2,i)+N*(K-i)<std::pow(2,i+1)+N*(K-i-1)){
break;
}
}
cout<<x<<endl;
}



Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int N = sc.nextInt();
		int A = sc.nextInt();
		
		int s = N*N;
		int result = s - A;
			 System.out.println(result);	
		}
	}

Measured memory_bytes: 21844
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
using namespace std;

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }

int N;
int S[210];

int dp[210][21000];

int main() {
  while (cin >> N) {
	for (int i = 0; i < N; ++i) cin >> S[i];
	memset(dp, 0, sizeof(dp));
	dp[0][0] = 1;
	for (int i = 0; i < N; ++i) {
	  for (int j = 0; j <= 10000; ++j) {
		if (!dp[i][j]) continue;
		dp[i+1][j] = 1;
		dp[i+1][j + S[i]] = 1;
	  }
	}
	int res = 0;
	for (int j = 0; j < 20000; ++j) {
	  if (j % 10 == 0) continue;
	  if (dp[N][j]) chmax(res, j);
	}
	cout << res << endl;
  }
}


Measured memory_bytes: 17536
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>

using namespace std;


int main() {

	int N;
	cin >> N;
	vector<int> A(N), B(N), C(N-1);
	
	for(int i = 0; i < N; i++){
		cin >> A[i];
	}

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

	for(int i = 0; i < (N-1); i++){
		cin >> C[i];
	}

	int index, point = 0;
	for(int i = 0; i < N; i++){
		index = A[i];
		point += B[index-1];
		int point2 = B[index-1];
		if(i > 0){
			if((A[i] - A[i-1])==1){
				point += C[A[i-1]-1];

			}				
		}
		
	}
	
	cout << point << endl;





    return 0;
}


/*

for(int i = 0; i < N; i++){
	
}

for(int i = 0; i < N; i++){
	for(int j = 0; j < N; j++){
		
	}
}


*/


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
  int N, INF = 10000000;
  while(cin >> N, N){
    int T[N][N+1];
    for(int i = 0; i < N; ++i)
      for(int j = 0; j <= N; ++j)
	cin >> T[i][j];
    int M = (1<<N);
    int dp[M];
    fill(dp,dp+M,INF);
    dp[0] = 0;
    for(int i = 0; i < M; ++i){
      int t = dp[i];
      for(int j = 0; j < N; ++j){
	if(i & 1<<j){
	  t = min(t, dp[i-(1<<j)] + T[j][0]);	  
	  for(int k = 0; k < N; ++k){
	    if(k != j && (i & (1<<k)))
	      t = min(t, dp[i-(1<<j)] + T[j][k+1]);
	  }
	}
      }
      dp[i] = t;
    }
    cout << dp[M-1] << endl;
  }
  return 0;
}

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


int main(){
  int n;
  cin >> n;
  bool count=false;
  for(int i=0; i<15; ++i){
    for(int j=0; j<26; ++j){
      if(7*i+4*j==n)
        count=true;
      
    }
    
  }
  if(count)
  cout << "Yes" << endl;
  else
    cout <<"No" << endl;
}

Measured memory_bytes: 384
# -*- coding: utf-8 -*-
# 整数の入力
import sys
s = input()
k = int(input())
# print (s,k)
n=len(s)
# print (s[0],s[n-1])

skip=0
if n == 1: 
    print((k-1) // 2 + (k-1) % 2 )

else:
    flag=0
    for i in range(1,n):
        #print("loop",i)
       if s[i] != s[i-1]:
           flag =1
           break
    
    if flag == 0: 
        print((k*n-1) // 2 + (k*n-1) % 2 )
    else:
        p=0
        q=0
        if s[0] == s[n-1]:
            l=1 
            # Start 
            for i in range(1,n):
                #print("loop",i)
                if s[i] == s[i-1]:
                    p +=1
                else:
                    break
            if l < n:
                for i in range(n-2,0,-1):
                    if s[i] == s[i+1]:
                        q +=1
                    else:
                        break
            l = 1 + p + q
            # print("Ring ", l, p,q)
            op = ((l // 2) + (l % 2)) * (k-1)
            op += ((p // 2) + (p % 2)) 
            op += ((q // 2) + (q % 2))
        else: 
            op = 0     
        
        # print("OP",op)
        
        if s[0] == s[n-1]:
            s2 = s[p+1:n-1-q] 
        else:
            s2 = s
        #print("s2",s2)
        n=len(s2)
                    
        
        l = 0
        for i in range(1,n):
            # print(s2[i],i,l,op)
            if s2[i-1] != s2[i]:
                op += (l // 2 + l % 2) * k
                l = 0 
            else:
                l += 1 
        if l != 0:
            op += (l // 2 + l % 2) * k
        
                
        print(op)

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

using namespace std;

char s[10];

int main()
{
    scanf("%s",s);
    int flag = 0;
    for(int i = 0;i <= 2;i++)
    {
        if(s[i] == s[i + 1])
            flag = 1;
    }
    if(flag)
        printf("Bad\n");
    else
        printf("Good\n");
    return 0;
}


Measured memory_bytes: 256
from math import floor,ceil,sqrt,factorial,log
from collections import Counter, deque
def S(): return input()
def I(): return int(input())
def MS(): return map(str,input().split())
def MI(): return map(int,input().split())
def LS(): return list(MS())
def LI(): return list(MI())
def LLS(): return [list(map(str, l.split() )) for l in input()]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def LLSN(n: int): return [LS() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]

N = I()
S = S()


def check(i, j, k):
    return j-i != k-j

chars = list(S)
cnts = Counter(chars)

cnt = 0

for i in range(N):
    for j in range(i+1, N):
        k = j + j - i
        if k > N-1:
            continue
        if chars[i] != chars[j] and chars[i] != chars[k] and chars[j] != chars[k]:
                cnt += 1

print(cnts["R"] * cnts["G"] * cnts["B"] - cnt)

Measured memory_bytes: 9408
#include<stdio.h>
#include<stdlib.h>
int main(){
  int i,n,max_num=0,*A,*B,*C,*D;
  scanf("%d",&n);

  A = malloc(sizeof(int)*n);
  B = malloc(sizeof(int)*n);
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
    if(max_num < A[i]){
      max_num = A[i];
    }
  }

  C = malloc(sizeof(int)*max_num+1);
  D = malloc(sizeof(int)*max_num+1);
  for(i=0;i<=max_num;i++)C[i]=0;
  
  for(i=0;i<n;i++)C[A[i]]++;
  for(i=0;i<=max_num;i++){
    if(i==0)D[i]=C[i];
    else D[i]=C[i]+D[i-1];
  }

  for(i=n-1;i>=0;i--){
    B[D[A[i]]-1] = A[i];
    D[A[i]]--;
  }
  for(i=0;i<n;i++){
    if(i == n-1)printf("%d\n",B[i]);
    else printf("%d ",B[i]);
  }
  free(A);
  free(B);
  free(C);
  free(D);  
  return 0;
}


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

#define lli long long int

int main()
{
  int n;
  scanf("%d", &n);
  char str[n];
  scanf(" %s", str);
  lli cnt[3];
  memset(cnt, 0, sizeof(cnt));
  for (int i = 0; i < n; i++)
  {
    cnt[0] += (str[i] == 'R');
    cnt[1] += (str[i] == 'G');
    cnt[2] += (str[i] == 'B');
  }
  lli ans = cnt[0] * cnt[1] * cnt[2];
  lli take = 0;
  int i = 1;
  while (1)
  {
    int ii = 0, jj = i, kk = i + i;
    if (kk >= n)
      break;
    while (1)
    {
      if (kk >= n)
        break;
      else
      {
        if (str[ii] != str[jj] && str[jj] != str[kk] && str[kk] != str[ii])
          take++;
        ii += 1;
        jj += 1;
        kk += 1;
      }
    }
    i++;
  }
  printf("%lld\n", ans - take);
  return 0;
}


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

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	long long int N,A,B;
	cin>>N>>A>>B;
	if(N==1)
		cout<<(A==B)<<endl;
	else{
		if(A>B)	cout<<0<<endl;
		else	cout<<(B-A)*(N-2)+1<<endl;
	}
}


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

typedef long long ll;
#define PI 3.1415926535897932384626433
#define mod 1000000007

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

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

int main(){
    ll n;
    cin >> n;
    if(n % 10 == 0){
        cout << 10 << endl;
        return 0;
    }
    int ans = 0;
    while(n > 0){
        ans += n % 10;
        n /= 10;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		int n = s.nextInt();
		ArrayList<Integer> l = new ArrayList<Integer>();
		for (int i = 0; i < n; ++i) {
			l.add(s.nextInt());
		}
		Collections.reverse(l);
		for (int i = 0; i < n; ++i) {
			if (i != 0) System.out.print(' ');
			System.out.print(l.get(i));
		}
		System.out.println();
	}
}

Measured memory_bytes: 19668
import java.util.Scanner;


public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int sum = 1;
    int ans = 0;
    while(sum<b){
      ans++;
      sum+=a-1;
    }
    System.out.print(ans);
  }
}


Measured memory_bytes: 21972
/*input
30
384 8895
1725 9791
170 1024
4 11105
2 6
578 1815
702 3352
143 5141
1420 6980
24 1602
849 999
76 7586
85 5570
444 4991
719 11090
470 10708
1137 4547
455 9003
110 9901
15 8578
368 3692
104 1286
3 4
366 12143
7 6649
610 2374
152 7324
4 7042
292 11386
334 5720
*/
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout << (#x) << " is " << (x) << endl
#define debug cout << "hi" << endl

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

const int MOD = 1e9 + 7;
const int INF32 = 1<<30;
const ll INF64 = 1LL<<60;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n; cin >> n;
    ll t = 0;
    vector<pair<ll, ll>> job(n);
    for(int i = 0; i < n; i++) cin >> job[i].second >> job[i].first;
    sort(job.begin(), job.end());
    for(int i = 0; i < n; i++)
    {
    	ll a = job[i].second, b = job[i].first;
    	t += job[i].second;
    	if(t > job[i].first)
    	{
    		cout << "No";
    		return 0;
    	}
    }
    cout << "Yes";

    return 0;
}

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

using namespace std;

int main() {
  int t;
  cin >> t;
  const string s[4] = {"AC", "WA", "TLE", "RE"};
  vector<int> c(4, 0);
  while (t--) {
    string tc;
    cin >> tc;
    if (s[0] == tc)
      c[0]++;
    else if (s[1] == tc)
      c[1]++;
    else if (s[2] == tc)
      c[2]++;
    else
      c[3]++;
  }
  for (int i = 0; i < 4; i++) {
    cout << s[i] << " x " << c[i] << endl;
  }
}


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

#define rep(i,n) for(int i = 0; i < (n); i++)
#define ll long long

using namespace std;

int main(){
  int n;cin>>n;
  vector<ll> a(n), ra(n);
  rep(i,n){
    cin>>a[i];
    ra[i]=a[i];
  }

  ll result=0;
  ll c=0;
  rep(i, n){
    if(a[i]==0){
      result+=c/2;
      c=0;
    }else c+=a[i];
  }

  if(c>0)result+=c/2;

  cout<<result;

  return 0;
}

Measured memory_bytes: 1792
#include <queue>
#include <cstdio>
#include <iostream>
#include <math.h>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <sstream>
#include <algorithm>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define REP(i,n) for(int i=0;i<n;i++)


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

int N;
int K[110], P[110];

int main()
{
	cin >> N;
	REP(i, N) cin >> K[i] >> P[i];
	REP(i, N) {
		if (K[i] % P[i] == 0) {
			cout << P[i] << endl;
		}
		else {
			cout << K[i] % P[i] << endl;
		}
	}
}


Measured memory_bytes: 3100
#include <iostream>
#include <bits/stdc++.h>
#include <iomanip>
typedef long long int lli;
#define FAST ios_base::sync_with_stdio(false); cin.tie(NULL);
#define JUGAD freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#define pb push_back
#define pf push_front
#define mp make_pair
#define ff first
#define ss second
#define N 10001
#define mod 1000000007
using namespace std;

int main(){
    FAST;
    int k;cin>>k;
    while(k--){
        cout<<"ACL";
    }
}


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

int main(){
  
  int n;
  while(true){
    cin >> n;
    if(n == 0 )return 0;
    int sima[n];
    int hasi[n];
    
   
    for(int i = 0;i < n;i++){
      cin >> sima[i];
      cin >> hasi[i];//財宝
      //cin >> hasi[n];//橋の重さ
      
    }
    /*  for(int i = 0;i < n;i++){
      cout << sima[i]<< " " << hasi[i]<< endl;
      }*/
    set<int> array;
    for(int i = 0;i < n;i++){
      array.insert(hasi[i]);
    }
    //sort(array.begin(),array.end());
    
    int sum = 0;
    int flag = 0;
    set<int>::iterator it = array.begin();
    while(it != array.end() ){
      for(int j= 0;j < n;j++){
	if(*it== hasi[j]){
	  //cout << hasi[j] << "aaa"<< endl;
	  sum = sum + sima[j];
	  if(sum <= hasi[j]){}
	  else {
	    // cout << *it << " " << j << " " << hasi[j] << " " << sum << endl;
	    flag =1;
	    cout << "No" << endl;
	    break;
	  }
	}
	
      }
      it++;
      if(flag == 1)break;
    }
    if(flag != 1){
      cout << "Yes" << endl;
    }
    
  }
  
  
  return 0;
}

Measured memory_bytes: 1184
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

use std::cmp::min;

fn main() {
    input! {
        n: usize,
        m: usize,
        l: i64,
        abc: [(usize1, usize1, i64); m],
        q: usize,
        st: [(usize1, usize1); q],
    }

    const INF: i64 = 1_000_000_000_000_000;

    let mut g = vec![vec![INF; n]; n];

    for (a, b, c) in abc {
        g[a][b] = c;
        g[b][a] = c;
    }

    for i in 0..n {
        g[i][i] = 0;
    }

    for k in 0..n {
        for i in 0..n {
            for j in 0..n {
                g[i][j] = min(g[i][j], g[i][k] + g[k][j]);
            }
        }
    }

    let mut g2 = vec![vec![INF; n]; n];

    for i in 0..n {
        for j in 0..n {
            if i != j && g[i][j] <= l {
                g2[i][j] = 1;
            }
        }
    }

    for i in 0..n {
        g2[i][i] = 0;
    }

    for k in 0..n {
        for i in 0..n {
            for j in 0..n {
                g2[i][j] = min(g2[i][j], g2[i][k] + g2[k][j]);
            }
        }
    }

    for (s, t) in st {
        if g2[s][t] == INF {
            println!("-1");
        } else {
            println!("{}", g2[s][t] - 1);
        }
    }
}


Measured memory_bytes: 6652
#include <algorithm>
#include <iostream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <iomanip>
#include <numeric>
#include <tuple>
#define _USE_MATH_DEFINES
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef tuple<int, int, int> tiii;
double pi = 3.141592653589793;
ll mod = 1000000007;
int intmax = 2147483647;
int intmin = -2147483648;
ll llmax = 9223372036854775807;
ll llmin = -9223372036854775807;

int main() {
    ll N;
    cin >> N;
    ll a[N];
    ll sum = 0;
    for (int i = 0; i < N; i++) {
        cin >> a[i];
        sum += a[i];
    }
    ll take = (N + 1) * N / 2;
    bool ok = true;
    if (sum % take != 0) {
        ok = false;
    } else {
        ll div = sum / take;
        ll num = 0;
        for (int i = 0; i < N; i++) {
            ll prev = a[i];
            ll next = a[(i + 1) % N];
            ll diff = next - prev;
            ll m = div - diff;
            if (m % N != 0) {
                ok = false;
                break;
            } else {
                if (m / N > 0) {
                    num += m / N;
                }
            }
        }
        if (num != div) {
            ok = false;
        }
    }
    if (ok) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
}


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <sstream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <numeric>
#include <cctype>
#include <tuple>
#include <iterator>
#include <bitset>
#include <random>
#include <assert.h>
#include <unordered_map>
#include <array>
#include <ctime>

#ifdef _MSC_VER
#include <agents.h>
#endif

#define FOR(i, a, b) for(int i = (a); i < (int)(b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define REV(v) v.rbegin(), v.rend()
#define MEMSET(v, s) memset(v, s, sizeof(v))
#define X first
#define Y second
#define MP make_pair
#define umap unordered_map

using namespace std;

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

struct UnionFind{
	vector<int> par, dist, diff;
	UnionFind(int n){
		par = dist = diff = vector<int>(n);
		for (int i = 0; i < n; ++i) par[i] = i, dist[i] = diff[i] = 0;
	}
	int find(int x){
		if (x == par[x]) return x;
		int r = find(par[x]);
		dist[x] += dist[par[x]];
		return par[x] = r;
	}
	int calc(int x){
		int r = find(x);
		return dist[x] + diff[x] - diff[r];
	}

	void unite(int x, int y, int val){
		int px = find(x), py = find(y);
		dist[py] = val - dist[y] - diff[y] + dist[x] + diff[x];
		par[py] = px;
		diff[x] += val;
		diff[y] += val;
	}
	pair<bool, int> comp(int x, int y){
		if (find(x) != find(y)) return make_pair(false, 0);
		return make_pair(true, calc(y) - calc(x));
	}
};

int main(){
	ios::sync_with_stdio(false);

	int n, q;
	cin >> n >> q;
	UnionFind uf(n+1);
	while (q--){
		string s;
		cin >> s;
		if (s[0] == 'I'){
			int a, b, c;
			cin >> a >> b >> c;
			uf.unite(a, b, c);
		}
		else{
			int a, b, c;
			bool ret;
			cin >> a >> b;
			tie(ret, c) = uf.comp(a, b);
			if (ret) cout << c << '\n';
			else cout << "WARNING" << '\n';
		}
	}

	return 0;
}

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

int main(){
    vector<char> s(4);
    rep(i,4) cin >> s[i];
    sort(s.begin(),s.end());
    if(s[0] == s[1] && s[2] == s[3] && s[1] != s[2]) cout << "Yes" << endl;
    else cout << "No" << endl;
}


Measured memory_bytes: 256
N, C = map(int, input().split())
x = [0]
v = [0]
for _ in range(N):
    x_new, v_new = map(int, input().split())
    x.append(x_new)
    v.append(v_new)


def get_g(clockwise):
    g = []
    g_now = 0
    g.append(g_now)
    if clockwise:
        for i in range(1, N + 1):
            g_next = g_now + v[i] + x[i - 1] - x[i]
            g.append(g_next)
            g_now = g_next
    else:
        for i in range(1, N + 1):
            g_next = g_now + v[i] + 2 * x[i - 1] - 2 * x[i]
            g.append(g_next)
            g_now = g_next
    return g


def get_h(clockwise):
    h = []
    if clockwise:
        h_now = v[N] - 2 * (C - x[N])
        h.append(h_now)
        for i in range(N):
            h_next = v[N - i - 1] + h_now + 2 * (x[N - i - 1] - x[N - i])
            h.append(h_next)
            h_now = h_next
    else:
        h_now = v[N] - C + x[N]
        h.append(h_now)
        for i in range(N):
            h_next = v[N - i - 1] + h_now + x[N - i - 1] - x[N - i]
            h.append(h_next)
            h_now = h_next
    h = list(reversed(h))
    return [0] + h[1:]


def get_G(g):
    G = []
    max_g = -100000000
    for i in range(N + 1):
        max_g = max(max_g, g[i])
        G.append(max_g)
    return [G[-1]] + G[:-1]


answer = 0
for clockwise in [True, False]:
    g = get_g(clockwise)
    h = get_h(clockwise)
    G = get_G(g)
    answer = max(max([G[b] + h[b] for b in range(N + 1)]), answer)

print(answer)


Measured memory_bytes: 30648
// 10桁でdouble出力するパターン１ 
// printf("%.10f\n", ma);
// 10桁でdouble出力するパターン２
//cout << fixed << setprecision(10);
//  cout << ma << endl;

/*01 02 03 12 13 23　と６回見ていくパターン 
for(int i=0;i<n-1;i++){
  for(int j=i+1;j<n;j++){
    }
  }
*///vector<vector<int>> data(3, vector<int>(4));//int型の2次元配列(3×4要素の)の宣言
//int64_t a;
//10のi乗pow(10, i);
/*string s; stringでの文字列を数字型に変える方法
  cin >> s;
  rep(i,s.size()-2) {
  int a= (s.at(i)-'0')*100 + (s.at(i+1)-'0')*10+ s.at(i+2) -'0';
    */
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
  int64_t n,m;
  int64_t num;
  cin >> n >> m; 
  if(n==1 || m==1){
    if(n==1&&m==1)num=1;
    else if(n==1&&m>=3)num=m-2;
    else if(n==1&&m<3)num=0;
    else if(m==1&&n>=3)num=n-2;
    else if(m==1&&n<3)num=0;
    
  }
  else{
    num=(m-2) * (n-2);
  }
  if(num>=0)cout<<num<<endl;
  else cout<<0<<endl;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = int(A); I < int(B); ++I)
#define FORR(I,A,B) for(ll I = int((B)-1); I >= int(A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //xi>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //xi>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd(ll a,ll b){if(a<b)swap(a,b);if(a%b==0)return b;return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}//saisyo kobaisu
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=1e18+7;
const ll MOD=1e9+7;

int main(){
	ll N;
	cin >> N;
	double ans=0;
	FOR(i,0,N){
		string u;
		double x;
		cin >> x >> u;
		if(u=="JPY"){
			ans += x;
		}else{
			ans += x*380000.0;
		}
	}
	printf("%.10lf\n",ans);
}

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

struct Card {
    char suit;
    int value;
};

void bubbleSort(struct Card C[], int N) {
    for (int i = 0; i < N; i++) {
        for (int j = N-1; j > i; j--) {
            if (C[j].value < C[j-1].value) {
                Card t = C[j];
                C[j] = C[j-1];
                C[j-1] = t;
            }
        }
    }
}

void selectionSort(struct Card C[], int N) {
    for (int i = 0; i < N; i++) {
        int minj = i;
        for (int j = i; j < N; j++) {
            if (C[j].value < C[minj].value) minj = j;
        }
        Card t = C[i];
        C[i] = C[minj];
        C[minj] = t;
    }
}

void print(struct Card C[], int N) {
    for (int i = 0; i < N; i++) {
        if (i > 0) cout << " ";
        cout << C[i].suit << C[i].value;
    }
    cout << endl;
}

// バブルソートと選択ソートの結果を比較
bool isStable(struct Card C1[], struct Card C2[], int N) {
    for (int i = 0; i < N; i++) {
        if (C1[i].suit != C2[i].suit) return false;
    }
    return true;
}

int main() {
    Card C1[100], C2[100];
    int N;

    cin >> N;
    for (int i = 0; i < N; i++) {
        cin >> C1[i].suit >> C1[i].value;
    }

    for (int i = 0; i < N; i++) {
        C2[i] = C1[i];
    }

    bubbleSort(C1, N);
    selectionSort(C2, N);

    print(C1, N);
    cout << "Stable" << endl;
    print(C2, N);
    if (isStable(C1, C2, N)) {
        cout << "Stable" << endl;
    } else {
        cout << "Not stable" << endl;
    }
    return 0;
}


Measured memory_bytes: 3104
import Control.Monad
import Text.Printf
import Data.List

getInts :: IO [Int]
getInts = map read . words <$> getLine

main :: IO()
main = do
  [n] <- getInts
  sn <- replicateM n $ getLine
  printf "%d" $ slv sn

slv :: [String] -> Integer
slv sn = sum $ map (\x -> (x*(x-1)) `div` 2 ) $ map (fromIntegral.length) $ group $ sort $ map sort sn


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

#define int long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define uniqueV(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define dbg(x) cerr << #x << ": " << x << endl;
#define dbg2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define dbg3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define dbgB(value, size) cerr<<#value<<": "<<bitset<size>(value) << endl;
#define line() cerr << "---------------" << endl;

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

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

template<typename T>
void print1(T begin, T end) {
	while (begin != end) {
		cerr << (*begin) << " ";
		*begin++;
	}
	cerr << endl;
}

template<typename T>
void print2(T Array, int height, int width) {
	for (int i = 0; i < height; i++) {
		for (int j = 0; j < width; j++) {
			cerr << " " << Array[i][j];
		}
		cerr << endl;
	}
}

void print() { std::cerr << endl; }
template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
	std::cerr << head << " ";
	print(std::forward<Tail>(tail)...);
}

template<class T>
void Add(T &a, const T &b, const T &mod=1000000007) {
	int val = ((a % mod) + (b % mod)) % mod;
	if (val < 0) { val += mod; }
	a = val;
}

template <typename X, typename T> auto vectors(X x, T a) { return vector<T>(x, a); }
template <typename X, typename Y, typename Z, typename... Zs> auto vectors(X x, Y y, Z z, Zs... zs) { auto cont = vectors(y, z, zs...); return vector<decltype(cont)>(x, cont); }

// ------------------------------------------------------------------------------------------

signed main() {
	int n, k;
	cin >> n >> k;
	cout << n % k << endl;


	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define MAXN 101009
#define MAXT 8000009
#define MAXLOGN 18
#define MOD 998244353
#define INF 10000000000000009LL
#define EPS 1e-7
#define FOR(x,n) for(int x=0; x<n; x++)
#define FOR1e(x,n) for(int x=1; x<=n; x++)
#define pb push_back
#define sz(x) int(x.size())
#define all(x) x.begin(), x.end()
typedef pair<int, int> ii;
typedef long long ll;

char w1[5009], w2[5009];

int cnt1[30], cnt2[30];
set<vector<int> > used;

bool ok(int n, int t1, int t2) {
	if (n == 0) return true;

	used.clear();
	vector<int> freq;
	freq.assign(26, 0);

	FOR(k, n) { 
		int l = w1[k]-'a';

		freq[l]++;
	}

	FOR(i, t1-n+1) {
		used.insert(freq);

		if (i < t1) {
			int l = w1[i] - 'a';
			freq[l]--;;
		}
		if (i+n < t1) {
			int l = w1[i+n] - 'a';
			freq[l]++;
		}
	}

	freq.assign(26, 0);
	FOR(k, n) {
		int l = w2[k] - 'a';
		freq[l]++;
	}

	FOR(i, t2-n+1) {
		if(used.count(freq)) return true;
		if (i < t2) {
			int l = w2[i] - 'a';
			freq[l]--;
		}
		if (i+n < t2) {
			int l = w2[i+n] - 'a';
			freq[l]++;
		}
	}
	return false;
}

int main() {
	scanf("%s %s", w1, w2);
	int t1 = strlen(w1), t2 = strlen(w2);
	int hi = min(t1, t2);
	while (!ok(hi, t1, t2)) { hi--; }

	printf("%d\n", hi);
}


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

#define int long long
#define pb push_back 
#define mp make_pair
#define fr first
#define sc second
#define Rep(i, n) for( int i = 0; i < (n); i++ )
#define Rrep(i, a, n) for( int i = (a); i < (n); i++ )
#define All(v) v.begin(), v.end()

typedef pair<int, int> Pii; 
typedef pair<int, Pii> Pip;
const int INF = 1107110711071107;

int N, P;
int A[101];
int dp[51][5001];

int rec(int n, int sum)
{
  if ( dp[n][sum] >= 0 ) return dp[n][sum];
  
  if ( n == N ) {
    if ( sum % 2 == P ) return 1;
    else return 0;
  }

  int ret = rec(n + 1, sum + A[n]) + rec(n + 1, sum);
  return dp[n][sum] = ret;
}

signed main()
{
  cin >> N >> P;
  Rep(i, N) cin >> A[i];

  fill_n(*dp, 51*5001, -1);
  
  cout << rec(0, 0) << endl;
}


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

using namespace std;

int dp[100005];
char s[100005];

queue <int> que;
int main() {
	int n, m;
	scanf("%d%d", &n, &m);
	scanf("%s", s);
	
	que.push(n);
	
	for (int i = n - 1; i >= 0; i--) {
		if (s[i] == '1') {
			dp[i] = -1;
			continue;
		}
		
		while (que.size() && que.front() - i > m) que.pop();
		
		if (que.empty()) dp[i] = -1;
		else {
			dp[i] = dp[que.front()] + 1;
			que.push(i);
		}
	}
	
	if (dp[0] == -1) return 0 * printf("-1\n");
	
	vector <int> sol;
	
	int cur = 0;
	
	while (cur != n) {
		for (int i = cur + 1; ; i++) {
			if (dp[i] == dp[cur] - 1) {
				sol.push_back(i - cur);
				cur = i;
				break;
			}
		}
	}
	
	for (int i = 0; i < sol.size(); i++) {
		if (i == 0) printf("%d", sol[i]);
		else printf(" %d", sol[i]);
	}
	
	printf("\n");
}


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

sum1=0
sum2=0

for i,j in zip(a,b):
  if i>j:
    sum1+=(i-j)
  elif i<j:
    sum2+=(j-i)//2

print('Yes' if sum1<=sum2 else 'No')

Measured memory_bytes: 4596
#include <iostream>

using namespace std;

int main(){
    int a, b, c, divisor = 0;
    cin >> a;
    cin >> b;
    cin >> c;
    for(int i = a; i <= b; i++){
        if(c%i == 0){
            divisor++;
        }
    }
    cout << divisor << endl;

}


Measured memory_bytes: 3092
#include <iostream>
#include <string>
#include <string.h>
#include <math.h>
#include <cmath>
#include <vector>
#include <algorithm>

#define ll long long

using namespace std;

const long long mod = 1e9 + 7;

ll c(int x, int y){
    if(x == 1) return 0;

    ll ans = 1;
    for(int i = x; i > x-y; i--){
        ans *= i;
    }
    for(int i = 2; i <= y; i++){
        ans /= i;
    }

    return ans;
}

int main() {
    int n;
    cin >> n;
    string* text;
    text = new string[n];
    for(int i = 0; i < n; i++){
        char* word;
        word = new char[10];
        for(int j = 0; j < 10; j++){
            cin >> word[j];
        }
        sort(word, word+10);
        text[i] = word;
    }

    sort(text, text+n);

    ll count = 0;

    for(int i = 0; i < n-1; i++){
        for(int j = i; j < n; j++){
            if(j == n-1){
                count += c(j-i+1,2);
                i = j;
                break;
            }
            if(text[j] != text[j+1]){
                count += c(j-i+1,2);
                i = j;
                break;
            }
        }
    }

    cout << count << endl;
}

Measured memory_bytes: 8832
#include<stdio.h>
#include<algorithm>
#include<vector>
using namespace std;
vector<pair<int,int> >g[1000];
int p[1000];
int q[1000];
int sum;
int val;
pair<int,int> dfs(int a,int b){
	int m1=0;int m2=0;
	int has=0;
	for(int i=0;i<g[a].size();i++){
		if(g[a][i].first!=b){
			pair<int,int>t=dfs(g[a][i].first,a);
			has+=t.first;
			if(t.first>1){
				sum+=g[a][i].second*2;
				t.second+=g[a][i].second;
				if(m1<t.second){
					m2=m1;m1=t.second;
				}else if(m2<t.second){
					m2=t.second;
				}
			}
		}
	}
	val=max(val,m1+m2);
	//printf("%d: %d %d\n",a,m1,m2);
	return make_pair(has+1,m1);
}
int main(){
	int a;
	while(scanf("%d",&a),a){
		for(int i=0;i<a-1;i++)scanf("%d",p+i);
		for(int i=0;i<a-1;i++)scanf("%d",q+i);
		for(int i=0;i<a;i++)g[i].clear();
		int tmp=0;
		for(int i=0;i<a-1;i++){
			p[i]--;
			tmp+=q[i];
			g[i+1].push_back(make_pair(p[i],q[i]));
			g[p[i]].push_back(make_pair(i+1,q[i]));
		}
		int ret=999999999;
		for(int i=0;i<a;i++){
			sum=val=0;
			dfs(i,-1);
			ret=min(ret,tmp+sum-val);
		}
		printf("%d\n",ret);
	}
}

Measured memory_bytes: 1192
#include<bits/stdc++.h>
using namespace std;
int n,m,ans=0;
int a[100005],b[100005];
int main()
{
	cin>>n>>m;
	for(int i=0;i<m;i++)
	cin>>a[i];
	sort(a,a+m);
	for(int i=0;i<m-1;i++)
		b[i]=a[i+1]-a[i];
	sort(b,b+m-1);
	for(int i=0;i<m-n;i++)
	ans+=b[i];
	cout<<ans<<endl;
	return 0;
}


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



int main(){
    int K, X;

    cin >> K >> X;

    int lb, ub;
    lb = max(X-K+1, -1000000);
    ub = min(X+K-1, 1000000);
    for(int i=lb; i < ub+1; i++){
        cout << i << " ";
    }
    cout <<  endl;

}


Measured memory_bytes: 256
#include<stdio.h>

void trace(int A[], int N) {
    int i;
    for (i = 0; i < N; i++) {
        if (i > 0) {
            printf(" ");
        }
        printf("%d", A[i]);
    }
    printf("\n");
}

void insertionSort(int A[], int N) {
    int j, i, v;
    for (i = 1; i < N; i++) {
        v = A[i];
        j = i - 1;
        while (j >= 0 && A[j] > v) {
            A[j + 1] = A[j];
            j--;
        }
        A[j + 1] = v;
        trace(A, N);
    }
}

int main() {
    int N, i, j;
    int A[100];
    
    scanf("%d", &N);
    for (i = 0; i < N; i++) {
        scanf("%d", &A[i]);
    }
    
    trace(A, N);
    insertionSort(A, N);
    
    return 0;
}


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

using namespace std;

#define FOE(i, s, t) for (int i = s; i <= t; i++)
#define FOR(i, s, t) for (int i = s; i < t; i++)
#define FOD(i, s, t) for (int i = s; i >= t; i--)

#define LL long long
#define mp make_pair
#define pb push_back

string x;

int main() {
	cin >> x;
	int n = x.length();
	
	FOR(i, 0, n) {
		if (x[i] == '?') x[i] = 'D';
	}
	
	cout << x << endl;
}

Measured memory_bytes: 3752
#include<bits/stdc++.h>
#define rep(i,a) for(int i=0;i<(int)(a);i++)
#define pb push_back
#define sz size()
using namespace std;
typedef vector<int> vi;

const int INF = 1e8;

struct edge{
  int from,to,cap,rev;
  edge(int a,int b,int c,int e)
    :from(a),to(b),cap(c),rev(e){}
};

struct dinic{
  int n;
  vector< vector<edge> > graph;
  vi level,iter;

  dinic(int a=0):n(a){graph.resize(a);}

  void AddEdge(int s,int g,int p){
    graph[s].pb( edge(s,g,p,graph[g].sz) );
    graph[g].pb( edge(g,s,0,graph[s].sz-1) );
  }

  void bfs(int s){
    level = vi(n,-1);
    level[s] = 0;
    queue<int> q; q.push(s);
    while(q.sz){
      int v = q.front(); q.pop();
      for(edge e: graph[v]){
	if(e.cap > 0 && level[e.to] < 0){
	  level[e.to] = level[v] + 1;
	  q.push(e.to);
	}
      }
    }
  }
  
  int dfs(int v, int t, int f){
    if(v==t)return f;
    for(int &i = iter[v];i<(int)graph[v].sz;i++){
      edge &e = graph[v][i];
      if(e.cap > 0 && level[v] < level[e.to]){
	int d = dfs(e.to,t,min(f,e.cap));
	if(d > 0){
	  e.cap -= d;
	  graph[e.to][e.rev].cap += d;
	  return d;
	}
      }
    }
    return 0;
  }
  
  int max_flow(int s, int t){
    int res = 0;
    for(;;){
      bfs(s);
      if(level[t]<0)return res;
      iter = vi(n,0);
      int f;
      while((f=dfs(s,t,INF))>0)res += f;
    }
  }
};

int main(){
  int k,n,m;
  cin >> k >> n >> m;

  int v = k+n+2;
  dinic mf(v);
  rep(i,k) mf.AddEdge(v-1,i+1,INF);

  vector<int> a(m), b(m), c(m);
  rep(i,m){
    cin >> a[i] >> b[i] >> c[i];
    mf.AddEdge(a[i], b[i], c[i]);
    mf.AddEdge(b[i], a[i], c[i]);
  }

  //check overfuro
  rep(i,m){
    if(a[i] > b[i]) swap(a[i], b[i]);
    if( a[i] == 0 && (1 <= b[i] && b[i] <= k) ){
      cout << "overfuro" << endl;
      return 0;
    }
  }

  int ans = mf.max_flow(v-1,0);

  vi from_s(v,-1), to_t(v,-1);
  rep(i,v){
    dinic red(v);
    red.graph = mf.graph;
    from_s[i] = i==v-1 ? INF : red.max_flow(v-1,i);

    red.graph = mf.graph;
    to_t[i] = i==0 ? INF : red.max_flow(i,0);
  }

  int over = 0;
  rep(i,m){
    over = max( over, min(from_s[a[i]], to_t[b[i]]) );
    over = max( over, min(from_s[b[i]], to_t[a[i]]) );
  }

  cout << ans + over << endl;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#include <algorithm>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(x) (x).begin(), (x).end()
#define PB(x) push_back(x)
#define MP(x,y) make_pair(x,y)
using namespace std;
typedef long long ll;
 
int main() {

    int n,k;
    cin>>n>>k;
    vector<int> h(n);
    rep(i,n)  cin>>h[i];
 
    sort(all(h));
    int ans=1000000009;
    rep(i,n-k+1) {
          ans=min(ans,h[i+k-1]-h[i]);
    }
 
    cout<<ans<<endl;
    
 return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int main() {
  int h,w;
  while(1){
    cin >> h >> w;
    if(h == 0 && w == 0) break;
    for(int i = 0; i < h; i++){
      for(int j = 0; j < w;j++){
        cout << "#";
      }
      cout << endl;
    }
    cout << endl;
  }

  return 0;
}



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

//#define dump(i) cout << "[*] " #i ": " << i << endl;
#define dump(i)

int main() {
#define int long long int
  int n, t;
  cin >> n >> t;
  vector<int> h(n);
  for (int i = 0; i < n; ++i) {
    cin >> h[i];
  }
  vector<int> I(n);
  vector<int> L(n);

  I[0] = 0;
  L[0] = h[0];
  for (int i = 1; i < n; ++i) {
    I[i] = I[i-1] + h[i-1];
    L[i] = max(L[i-1], h[i]);
    dump(i);
    dump(I[i]);
    dump(L[i]);
  }

  for (int i = 0; i < n; ++i) {
    const int tmp = t - I[i];
    cout << ((tmp < 0) ? 1 : tmp / L[i] + 1 + !!(tmp % L[i] >= h[i])) << endl;
  }
  return 0;
}


Measured memory_bytes: 5220
/*

*/
#include<iostream>
#include<iomanip>
#include<ios>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<string>
#include<algorithm>
#include<utility>
#include<math.h>
#include<cstdlib>
#define rep(i, n) for(int i=0;i<n;i++)
#define repb(i, a, b) for(int i=a;i<b;i++)
#define MAX_N 10000

using namespace std;
typedef pair<int, int> P;
typedef long long int ll;

const int INF = 1<<30;
const ll MOD = ll(1e9+7);

int main(){
  string s;cin>>s;
  int q;cin>>q;
  bool dir=false;
  string l, r;
  while(q--){
    int t;cin>>t;
    if(t==1){
      dir=!dir;
    }else{
      int f;cin>>f;
      char c;cin>>c;
      if(bool(f==1)==dir){
        r=r+c;
      }else{
        l=c+l;
      }
    }
  }
  s=l+s+r;
  if(dir)reverse(s.begin(), s.end());
  cout<<s<<endl;
  // system("read -n 1 -s -p \"Press any key to continue...\"");
}


Measured memory_bytes: 1512