akhauriyash/Code-Regression huggingface dataset:
main = do
    n <- getLine
    oCards <- getContents
    let cards = map words $ lines oCards
    let taro = (taroWin cards) * 3 + (draw cards)
    let hanako = (hanakoWin cards) * 3 + (draw cards)
    putStrLn $ (show taro) ++ " " ++ (show hanako)

draw :: [[String]] -> Int
draw = length . filter (\ws -> (ws!!0)==(ws!!1))

taroWin :: [[String]] -> Int
taroWin = length . filter (\ws -> (ws!!0)>(ws!!1))

hanakoWin :: [[String]] -> Int
hanakoWin = length . filter (\ws -> (ws!!0)<(ws!!1))


Measured memory_bytes: 4468
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<map>
#include<iostream>
using namespace std;
#define rep(i,n) for(int i=0;i<((int)(n));i++)
#define reg(i,a,b) for(int i=((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i=((int)(n))-1;i>=0;i--)
#define ireg(i,a,b) for(int i=((int)(b));i>=((int)(a));i--)
typedef long long int lli;
typedef pair<int,int> mp;
#define fir first
#define sec second
#define IINF INT_MAX
#define LINF LLONG_MAX
#define eprintf(...) fprintf(stderr,__VA_ARGS__)
#define pque(type) priority_queue<type,vector<type>,greater<type> >
#define memst(a,b) memset(a,b,sizeof(a))
#define iter(v,ite) for(auto ite=(v).begin();ite!=(v).end();ite++)
#define mimunum(v,x) distance((v).begin(),lower_bound((v).begin(),(v).end(),x))


int A[2005];

#define MOD ((lli)(1000000007))

int main(void){
	int n;
	lli k;
	scanf("%d%lld",&n,&k);
	rep(i,n){
		scanf("%d",&A[i]);
	}
	
	lli s=0;
	rep(i,n){
		rep(j,i){
			if(A[i]<A[j])s++;
		}
	}
	s = (s*k)%MOD;
	
	sort(A,A+n);
	int d=1,b=0;
	A[n]=A[n-1]+1;
	reg(i,1,n){
		if(A[i-1]!=A[i]){
			lli p = (d*b)%MOD;
			p = (p*(((k*(k-1))/2)%MOD))%MOD;
			s = (s+p)%MOD;
			b += d;
			d = 1;
		}
		else d++;
	}
	printf("%lld\n",s);
	return 0;
}






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

using namespace std; 

#define endl "\n"

int main()
{
   ios_base::sync_with_stdio(false);
   cin.tie(NULL);cout.tie(NULL);
   
  long long int a,b,c,d;
  cin>>a>>b>>c>>d;
  cout<<max(max((a*c),(b*d)),max((a*d),(b*c)));
   
  
     return 0;
}

Measured memory_bytes: 3652
#include <iostream>
#include <cstdlib>
using std::cout;
using std::cin;
using std::endl;

int main()
{
	int i, num, *list;
	cin >> num;
	list = (int *) calloc(num, sizeof(int));
	if (list == NULL) return 1;
	for (i = 0; i < num; i++) cin >> list[i];
	for (i = num - 1; i > 0; i--) cout << list[i] << " ";
	cout << list[0] << endl;
	free(list);
	return 0;	
}

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


Measured memory_bytes: 1728
#! /usr/bin/env python
# -*- coding: utf-8 -*-

import pdb
import sys
F = sys.stdin

H = int(F.readline().rstrip())
W = int(F.readline().rstrip())
N = int(F.readline().rstrip())

many = max(H, W)
ans = 0

ans = N // many + 1
if N % many == 0:
    ans = N // many

print(ans)


Measured memory_bytes: 5636
#include <iostream>
#include <math.h>

using namespace std;
int main(){
    int i,count=0,N,H,b_H=0,max=0;

    cin >> N;
    
    for(i=0;i<N;i++){
        cin >> H;
        if(b_H != 0){
            if(b_H >= H){
                count++;
                if(i == N-1){
                    if(count > max){
                        max = count;
                    }
                }
            }
            else{
                if(count > max){
                    max = count;
                }
                count = 0;
                b_H = 0;
            }
        }
        b_H = H;
    }
    cout << max << endl;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<P,int> pip;
typedef vector<pip> vip;
const int inf=1<<29;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

int a,b,c;

int main(){
	cin>>a>>b>>c;
	int m=max({a,b,c});
	int t=3*m-a-b-c;
	if(t%2==0) cout<<t/2<<endl;
	else cout<<(t+3)/2<<endl;
}

Measured memory_bytes: 256
import sys
import math
import bisect

def solve(s):
    n = len(s)
    val1 = 0
    # 010101...
    for i in range(n):
        if i % 2 == 0 and s[i] != '0':
            val1 += 1
        elif i % 2 == 1 and s[i] != '1':
            val1 += 1
    val2 = 0
    #1010...
    for i in range(n):
        if i % 2 == 0 and s[i] != '1':
            val2 += 1
        elif i % 2 == 1 and s[i] != '0':
            val2 += 1
    return min(val1, val2)

def main():
    print(solve(input()))

if __name__ == "__main__":
    main()


Measured memory_bytes: 40816
#include<cstdio>
#include<cstring>
using namespace std;
int main(){
  int n,k,a,max;
  int set[100001];
  while(1){
    scanf("%d %d",&n,&k);
  if(n==0 && k==0)break;
  max=0;
  for(int i=0;i<n;i++){
    scanf("%d",&set[i]);
  }
  for(int i=0,sum=0;i<n-k+1;i++,sum=0){
    if(set[i-1]<set[i+k-1] || i==0){
      for(int j=i,l=i+k-1;;j++,l--){
	sum += set[j]+set[l];
	if(l-j==1){
	  break;
	}else if(l==j){
	  sum-=set[j];
	  break;
	}
      }
    }
    if(max<sum || i==1){
      max=sum;
    }
  }
  printf("%d\n",max);
  }
}

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

#define mp make_pair
#define fst first
#define snd second
#define forn(i,n) for (int i = 0; i < int(n); i++)
#define forn1(i,n) for (int i = 1; i <= int(n); i++)
#define popcnt __builtin_popcount

using namespace std;

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,int> pli;
typedef pair<int,ll> pil;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;

template <typename T> T id(T b) {return b;};
template <class It> bool all(It f,It l){return std::all_of(f,l,id<bool>);}
template <class It> bool any(It f,It l){return std::any_of(f,l,id<bool>);}
template <typename T> void chmax(T &x, T y) {if (x < y) x = y;}
template <typename T> void chmin(T &x, T y) {if (x > y) x = y;}

const int MAX_N = 100000;
int n;
int dp[MAX_N][3];
int abc[MAX_N][3];

int main()
{
#ifdef FASTIO
  ios_base::sync_with_stdio(false); cin.tie(nullptr);
#endif

  cin >> n;

  forn(i,n) forn(j,3) cin >> abc[i][j];

  forn(i,3) dp[0][i] = abc[0][i];

  for (int i = 1; i < n; i++) {
    for (int j = 0; j < 3; j++) {
      dp[i][j] = dp[i-1][(j+1)%3] + abc[i][j];
      chmax(dp[i][j], dp[i-1][(j+2)%3] + abc[i][j]);
    }
  }

  cout << *max_element(dp[n-1],dp[n-1]+3) << endl;


  return 0;
}


Measured memory_bytes: 2560
import bisect
n,m =list(map(int,input().split()))
a = list(map(int,input().split()))
b = []
for i in range(m):
    c,d = list(map(int,input().split()))
    b.append([d,c])
a.sort()
a.reverse()
b.sort()
b.reverse()
c = []
i = 0
while True:
    if len(c)==n or i == m:
        break
    if b[i][1] >0:
        b[i][1] -=1
        c.append(b[i][0])
    else:
        i += 1
a+=c
a.sort()
a.reverse()
print(sum(a[0:n]))
# print(a)



Measured memory_bytes: 26744
#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() {
	string str;
	while(getline(cin,str)){
		string res="";
		int i;
		if(str.size()%2>0){
			cout<<"NA"<<endl;
			continue;
		}
		for(i=0;i<str.size();i+=2){
			if(str[i]<'1'||'6'<str[i]||str[i+1]<'1'||'5'<str[i+1]){
				cout<<"NA"<<endl;
				goto a;
			}
			if(str[i]!='6'){
				res+='a'+(str[i]-'1')*5+str[i+1]-'1';
			}else{
				switch(str[i+1]){
				case '1':
					res+="z";
					break;
				case '2':
					res+=".";
					break;
				case '3':
					res+="?";
					break;
				case '4':
					res+="!";
					break;
				case '5':
					res+=" ";
					break;
				}
			}
		}
		cout<<res<<endl;
		a:;
	}
	return 0;
}

Measured memory_bytes: 0
import numpy as np
A, B, H, M = map(int, input().split())

M_theta = 2.0 * np.pi * M / 60.0
H_theta = 2 * np.pi * ( H / 12.0  + (M / 60.0) / 12.0 ) 
print( (A**2 + B**2 - 2 * A * B * np.cos(M_theta - H_theta))**0.5 )

Measured memory_bytes: 27204
#include <bits/stdc++.h>
#define f first
#define s second
#define mp make_pair
#define pb push_back
#define lp(i,a,n) for(int i=a;i<=n;++i)
#define lpd(i,a,n) for(int i=a;i>=n;--i)
#define mem(a,b) memset(a,b,sizeof a)
#define all(v) v.begin(),v.end()
#define println(a) cout <<(a) <<endl
#define sz(x) ((int)(x).size())
#define readi(x) scanf("%d",&x)
#define read2i(x,y) scanf("%d%d",&x,&y)
#define read3i(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define mod 1000000007
#define eps 1e-9
#define infi 1000000000
#define infll 1000000000000000000ll
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef set<int> si;
typedef map<int,int> mii;

const int N = 100002;
int n;
ll m,a[4*N],c[4*N];

typedef complex<double> CD;

const double PI = acos(-1.);

inline void dft(CD out[], int n, int oper) {
  for (int i = 1, j = 0; i < n - 1; i++) {
    for (int s = n; j ^= s >>= 1, ~j & s;);
    if (i < j)
      swap(out[i], out[j]);
  }
  for (int d = 0; (1 << d) < n; d++) {
    int m = 1 << d, m2 = m << 1;
    double theta = PI / m * oper;
    CD u0 = CD(cos(theta), sin(theta));
    for (int i = 0; i < n; i += m2) {
      CD u = 1.;
      for (int j = i; j < i + m; j++) {
        CD p1 = out[j] + u * out[j + m];
        CD p2 = out[j] - u * out[j + m];
        out[j] = p1;
        out[j + m] = p2;
        u *= u0;
      }
    }
  }
}

// n = largest power + 1
inline void conv(ll a[], ll c[], int n) {
  while (n & (n - 1))
    n++;
  n *= 2;
  CD _a[n + 5], _c[n + 5];
  for (int i = 0; i < n; i++) {
    _a[i] = CD(a[i], 0);
  }
  dft(_a, n, 1);
  for (int i = 0; i < n; i++)
    _c[i] = _a[i] * _a[i];
  dft(_c, n, -1);
  for (int i = 0; i < n; i++)
    c[i] = (ll) (_c[i].real() / n + .5);
}

int main(){
    cin >>n >>m;
    lp(i,1,n){
        int x;
        readi(x);
        ++a[x];
    }
    conv(a, c, 100001);
    ll ans = 0;
    lpd(i,2*N,1){
        ans += min(c[i], m) * i;
        m -= c[i];
        if(m < 1) break;
    }
    cout <<ans;
}

/*
uniform_int_distribution<type>(l, r)(rng)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
*/


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

int main(){
    int H,W,count;
    count=0;
    cin>>H>>W;
    vector<vector<string>> snuke(H,vector<string>(W));

   for(int i=0;i<H;i++){
       for(int j=0;j<W;j++){
           cin>>snuke.at(i).at(j);
           char w = j + 'A';
           if(snuke.at(i).at(j)=="snuke")cout << w << i+1 << endl;
       }
   }
}

Measured memory_bytes: 256
s=input()
k=int(input())
n=len(s)
l=set()
for i in range(n):
    curr=''
    for j in range(i,min(i+7,n)):
        curr+=s[j]
        l.add(curr)
l=[i for i in l]
l.sort()
#print(l)
print(l[k-1])

Measured memory_bytes: 43116
import java.util.*;
//import java.util.PriorityQueue;

public class Main {
  public static void main(String[] args){
    PriorityQueue<Integer> pq = new PriorityQueue<Integer>(11, Collections.reverseOrder());
    Scanner sc = new Scanner(System.in);
    String com = sc.next();
    while(!com.equals("end")){
      switch(com){
        case "insert":
          int n = sc.nextInt();
          pq.add(n);
          break;
        case "extract":
          System.out.println(pq.poll());
          break;
        default:
          break;
      }
      com = sc.next();
    } 
  }   
}


Measured memory_bytes: 582528
using System;
using System.Linq;

class B
{
	static void Main()
	{
		var n = int.Parse(Console.ReadLine());
		var a = new int[n]
			.Select(_ => Console.ReadLine().Split().Select(int.Parse).ToArray())
			.Select(x => new { l = x[0] - x[1], r = x[0] + x[1] })
			.OrderBy(x => x.l);

		int M = 2000000000, j;
		var r = Enumerable.Range(M, n + 1).ToArray();
		r[0] = int.MinValue;
		foreach (var x in a)
		{
			if ((j = Array.BinarySearch(r, x.l + 1)) < 0) j = ~j;
			r[j] = Math.Min(r[j], x.r);
		}
		Console.WriteLine(r.Count(x => x <= M) - 1);
	}
}


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

int main() {
  int n,l,r;
  int ans = 0;
  cin >> n;
  for(int i = 0; i<n;i++){
    cin >> l >> r;
    ans+=r-l+1;
  }
  cout << ans << "\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define mod 1000000007
using namespace std;
/* AGC_1 E.BBQ Hard
   The answer is sigma(1<=i,j<=N,f(Ai+Aj,Bi+Bj)),
   while f(a,b)=C(a+b,a).
   Unfortunately,O(n^2) solution will get a TLE.
   So consider the geometric meaning for the answer.
   f(a,b) is equal to the way to go from (0,0) to (a,b).
   So f(Ai+Aj,Bi+Bj) equals to the way to go from (-Ai,-Bi) to (Aj,Bj).
   Do simple DP to solve it.
   And what's more,
   if the total answer is X,
   ans=(X-sigma(1<=i<=N,f(Ai*2,Bi*2)))/2,
   and f(Ai*2,Bi*2) can be got by pre-calculating the C(a,b).
*/
int a[200005],b[200005],n;
int f[8005][4006];
int main (){
	int i,j;
	scanf ("%d",&n);
	for (i=1;i<=n;i++)
	{scanf ("%d%d",&a[i],&b[i]);
	f[2005-a[i]][2005-b[i]]++;
	}
	for (i=1;i<=4005;i++)
	{for (j=1;j<=4005;j++)
	{f[i][j]=f[i][j]+f[i-1][j]+f[i][j-1];
	while (f[i][j]>=mod) {f[i][j]-=mod;}
	}
	}
	int ans=0;
	for (i=1;i<=n;i++)
	{ans+=f[2005+a[i]][2005+b[i]];
	while (ans>=mod) {ans-=mod;}
	}
	memset (f,0,sizeof(f));
	f[0][0]=1;
	for (i=1;i<=8000;i++)
	{f[i][0]=1;f[i][i]=1;
	for (j=1;j<i&&j<=4000;j++)
	{f[i][j]=f[i-1][j]+f[i-1][j-1];
	while (f[i][j]>=mod) {f[i][j]-=mod;}
	}
	}
	for (i=1;i<=n;i++)
	{ans-=f[2*(a[i]+b[i])][a[i]*2];
	while (ans<0) {ans+=mod;}
	}
	if (ans%2==1) {ans+=mod;}
	printf ("%d",ans/2);
	return 0;
}
	

Measured memory_bytes: 127104
#include<cstdio>
#include<cstring>
#include<valarray>
using namespace std;
pair<valarray<long long>,long long> f(long long n,long long l,const valarray<long long> &left,long long r,const valarray<long long> &right)
{
	valarray<long long> ans(26);
	if(l+r<=n)
	{
		auto x=f(n,l+r,left+right,l,left);
		ans+=x.first;
		n=x.second;
	}
	if(l<=n)ans+=left,n-=l;
	return make_pair(ans,n);
}
char s[300000];
long long cnt[300000][30],z[300000],n;
int main()
{
	scanf("%s",s+1);
	n=strlen(s+1)>>1;
	z[1]=n;
	long long l=1,r=1;
	for(long long i=2;i<=n;i++)
		if(i>r)
		{
			z[i]=0;
			while(z[i]+i<=n&&s[z[i]+i]==s[z[i]+1])z[i]++;
			if(z[i])l=i,r=i+z[i]-1;
		}
		else if(z[i-l+1]<r-i+1)z[i]=z[i-l+1];
		else
		{
			z[i]=r-i+1;
			while(z[i]+i<=n&&s[z[i]+i]==s[z[i]+1])z[i]++;
			l=i,r=i+z[i]-1;
		}
	for(long long i=1;i<=n;i++)
	{
		for(long long j=0;j<26;j++)cnt[i][j]=cnt[i-1][j];
		cnt[i][s[i]-'a']++;
	}
	long long k=0;
	for(long long i=n;i>1;i--)
		if(z[i]+i-1==n)k=z[i];
	scanf("%lld%lld",&l,&r);l--;
	if(!k)
	{
		for(long long i=0;i<26;i++)printf("%lld ",cnt[n][i]*(r/n)+cnt[r%n][i]-cnt[n][i]*(l/n)-cnt[l%n][i]);
		putchar('\n');
		return 0;
	}
	valarray<long long> left(26),right(26);
	for(long long i=0;i<26;i++)
	{
		left[i]=cnt[n-k][i];
		right[i]=cnt[n][i]-cnt[n-k][i];
	}
	auto lower=f(l,n-k,left,k,right),upper=f(r,n-k,left,k,right);
	for(long long i=0;i<26;i++)printf("%lld ",upper.first[i]-lower.first[i]+cnt[upper.second][i]-cnt[lower.second][i]);
	putchar('\n');
	return 0;
}

Measured memory_bytes: 26752
using System;
class Program
{
	static void Main(string[] args)
	{
		string t = Console.ReadLine();
		int N = int.Parse(t);
		string S = Console.ReadLine();
		string A = "abcdefghijklmnopqrstuvwxyz";
		int [] B = new int[26];
		int [] C = new int[26];
		for(var i=0;i<S.Length;i++){
			B[A.IndexOf(S.Substring(i,1))] += 1;
		}
		int countmax = 0;
		for(var i=0;i<S.Length-1;i++){
			B[A.IndexOf(S.Substring(i,1))] -= 1;
			C[A.IndexOf(S.Substring(i,1))] += 1;
			int count = 0;
			for(var j=0;j<26;j++){
				if(B[j] > 0 && C[j] > 0){
					count += 1;
				}
			}
			countmax = Math.Max(countmax,count);
		}
		Console.WriteLine(countmax);
	}
}

Measured memory_bytes: 11348
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
using namespace std;

typedef long long ll;

ll gcd(ll a, ll b){

    if(a < b) swap(a, b);

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

}

int main(){

    int n;
    cin >> n;

    vector<long long> v(n);
    for(int i = 0; i < n; i++){
        cin >> v[i];
    }

    long long ans = 0;
    for(int i = 0; i < n; i++){
        ans = gcd(ans,v[i]);
    }
    cout << ans << endl;

}

Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {
	static String s = "";

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		int K = sc.nextInt();

		int n = N;
		int count = 0;
		do {
			n = n / K;
			count++;
		}while(n != 0);

		System.out.println(count);
	}

}


Measured memory_bytes: 21588
n = int(input())

kuku = [1,  2,  3,  4,  5,  6,  7,  8,  9,
        2,  4,  6,  8, 10, 12, 14, 16, 18,
        3,  6,  9, 12, 15, 18, 21, 24, 27,
        4,  8, 12, 16, 20, 24, 28, 32, 36,
        5, 10, 15, 20, 25, 30, 35, 40, 45,
        6, 12, 18, 24, 30, 36, 42, 48, 54,
        7, 14, 21, 28, 35, 42, 49, 56, 63,
        8, 16, 24, 32, 40, 48, 56, 64, 72,
        9, 18, 27, 36, 45, 54, 63, 72, 81]

if n in kuku:
    print('Yes')
else:
    print('No')

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

int main(){
  int n;
  cin >> n;
  deque<int64_t > b;
  for(int i=0;i<n;i++){
    int64_t a;
    cin >> a;
    if(n%2==0){
      if(i%2==0){
        b.push_back(a);
      }else{
        b.push_front(a);
      }
    }else{
      if(i%2!=0){
        b.push_back(a);
      }else{
        b.push_front(a);

      }
    }
  }
  for(int i=0;i<n;i++){
    cout << b.at(i);
    if(i==n-1){
      cout << endl;
    }else{
      cout << " ";
    }
  }
  return 0;
}


Measured memory_bytes: 3840
// #define _GLIBCXX_DEBUG

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
void dump_func()
{
    cerr << endl;
}
template <class Head, class... Tail>
void dump_func(Head &&h, Tail &&... t)
{
    cerr << h << (sizeof...(Tail) == 0 ? "" : ", "),
        dump_func(forward<Tail>(t)...);
}
#define dump(...)                                                             \
    cerr << "/* " << #__VA_ARGS__ << " :[" << __LINE__ << ":" << __FUNCTION__ \
         << "]" << endl,                                                      \
        dump_func(__VA_ARGS__), cerr << "*/\n\n";
typedef long long ll;

const int MOD = 1000000007;
int main()
{
    string s;
    cin >> s;
    bool sn = !((s.find('S') < s.size()) ^ (s.find('N') < s.size()));
    bool we = !((s.find('W') < s.size()) ^ (s.find('E') < s.size()));
    dump(sn, we);
    if (sn && we) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 3572
#include <iostream>

int main(){
    int a,b;
    std::cin >> a >> b;
    if (a>b) std::cout << "a > b" << std::endl;
    if (a<b) std::cout << "a < b" << std::endl;
    if (a==b) std::cout << "a == b" << std::endl;
    return 0;
}


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


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

    int S, W;
    cin >> S >> W;
    if (W >= S){
        cout << "unsafe" << endl;
    }else{
        cout << "safe" << endl;
    }

    
}

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

int64_t solve();

int main()
{
	int N, M;
	scanf("%d%d", &N, &M);

	using pi = std::pair<int64_t, int>;
	using vpi = std::vector<pi>;
	using vvpi = std::vector<vpi>;
	vvpi edges(N);
	std::vector<std::vector<int>> rev_edges(N);
	for (int i{}; i < M; i++)
	{
		int a, b;
		int64_t c;
		scanf("%d%d%lld", &a, &b, &c);
		a--; b--;
		edges[a].push_back({c, b});
		rev_edges[b].push_back(a);
	}
	std::vector<int64_t> distance(N, LLONG_MIN);
	distance[0] = 0;
	for (int i{}; i < N; i++)
		for (int j{}; j < N; j++)
			if (distance[j] != LLONG_MIN)
				for (auto& e: edges[j])
					distance[e.second] = std::max(distance[e.second], distance[j] + e.first);
	
	std::vector<int64_t> check(distance);
	for (int i{}; i < N; i++)
		for (int j{}; j < N; j++)
			if (check[j] != LLONG_MIN)
				for (auto& e: edges[j])
					check[e.second] = std::max(check[e.second], check[j] + e.first);
	std::vector<bool> visited(N);
	std::queue<int> que;
	visited[N - 1] = true;
	que.push(N - 1);
	while (!que.empty())
	{
		auto now{que.front()};
		que.pop();
		if (check[now] != distance[now])
		{
			puts("inf");
			return 0;
		}
		for (auto& e: rev_edges[now])
		{
			if (visited[e]) continue;
			que.push(e);
			visited[e] = true;
		}
	}
	printf("%lld\n", distance[N - 1]);

	return 0;
}

Measured memory_bytes: 384
class UnionFind:
    def __init__(self, n):
        self.table = [-1] * n
 
    def _root(self, x):
        if self.table[x] < 0:
            return x
        else:
            self.table[x] = self._root(self.table[x])
            return self.table[x]
 
    def count(self, x):
        return -self.table[self._root(x)]
 
    def find(self, x, y):
        return self._root(x) == self._root(y)
 
    def union(self, x, y):
        r1 = self._root(x)
        r2 = self._root(y)
        if r1 == r2:
            return
        d1 = self.table[r1]
        d2 = self.table[r2]
        if d1 <= d2:
            self.table[r2] = r1
            self.table[r1] += d2
        else:
            self.table[r1] = r2
            self.table[r2] += d1

N, M, K = map(int, input().split())
ins_friend = UnionFind(N)
friends = [0 for i in range(N)]
blocks = [set() for _ in range(N)]
for _ in range(M):
    a, b = map(int, input().split())
    ins_friend.union(a-1, b-1)
    friends[a-1] += 1
    friends[b-1] += 1
for _ in range(K):
    c, d = map(int, input().split())
    blocks[c-1].add(d-1)
    blocks[d-1].add(c-1)
ans = [0 for i in range(N)]
for i in range(N):
    ans[i] = ins_friend.count(i) - 1 - friends[i]
    for x in blocks[i]:
        if ins_friend.find(i, x) == True:
            ans[i] -= 1
print(*ans)


Measured memory_bytes: 57452
fun main() {
    val (n, k) = readIntList()
    val have = BooleanArray(n) { false }
    repeat(k) {
        val d = readInt()
        val list = readIntList()
        list.forEach {
            have[it - 1] = true
        }
    }
    println(have.count { !it })
}

fun readString() = readLine()!!
fun readInt() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readIntList() = readLine()!!.split(" ").map(String::toInt)
fun readLongList() = readLine()!!.split(" ").map(String::toLong)
fun <T> Array<Array<T>>.print() {
    this.forEach {
        println(it.joinToString(" "))
    }
}

Measured memory_bytes: 38796
import java.util.Scanner;
public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int count = 0;
		int[] a = new int[n];
		for(int i = 0; i < n; i ++) {
			a[i] = sc.nextInt()-1;
		}
		for(int i = 0; i < n; i++) {
			if(i==a[a[i]] && i < a[i]) {
				count++;
			}
		}
		System.out.println(count);
	}
}

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


int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	string s;cin>>s;
	ll i;
	bool f=false;
	for(i=0;i<3;i++)
		if(s[i]=='7')
			f=true;

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

Measured memory_bytes: 3652
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <iomanip>


using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define shandom_ruffle random_shuffle

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy


int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cout << std::setprecision(9);
    cout << std::fixed;

    ll a,b;
    cin >> a >> b;
    ll x = ((b-a)*(b-a-1))/2 - a;
    cout << x<<endl;
    return 0;
}

// read the question correctly (ll vs int)
// template by super1 derived from bqi343


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <cstdio>
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
 
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=(n)-1;i>=0;i--)
#define VSORT(v) sort(v.begin(), v.end())
#define SORT(v, n) sort(v, v+n)
#define VREV(v) reverse(v.begin(),v.end())
#define REV(v,n) reverse(v,v+n)
#define vi vector<int>
#define pf push_front
#define pb push_back

template<class T, size_t N> size_t countof(const T (&array)[N]) { return N; }
template <class T> void chmin(T&a,const T&b) { a = min(a,b); }
template <class T> void chmax(T&a,const T&b) { a = max(a,b); }
 
void print(){cout<<"\n";}
template <class Head, class... Tail>
void print(Head&& h,Tail&&... t){ 
	if(sizeof...(t)==0)
		cout<<h;
	else
		cout<<h<<' ';
	print(move(t)...);
}

void mprint(auto *matrix,auto N){
	REP(i,N) cout<<matrix<<(i!=N-1?' ':'\n');
	return;
}

const double EPS =1e-9;
const int INF =2e+9;
const ll INFL =9e+18;
const long MOD =1e+9+7;
#define PI 3.14159265258979

#define P pair<int,int>
#define Pll pair<ll,ll>
int dy[]={0, 0, 1, -1, 1, 1, -1, -1};
int dx[]={1, -1, 0, 0, 1, -1, -1, 1};

inline int in(){int x; cin>>x; return x;}

struct UnionFind{
	vector<int> par; //データiが属する親の番号
	vector<int> sizes; //根ノードiの木に含まれるデータの数

	// 最初は全てのデータiがグループiに存在するものとして初期化
	UnionFind(int n):par(n),sizes(n, 1){
		REP(i,n) par[i] = i;
	}

	// 根を張り替えながら再帰的に根ノードを探す
	int find(int x){
		if(x==par[x]) return x;
		return par[x]=find(par[x]);
	}

	// 2つのデータx, yが属する木をマージする
	void unite(int x, int y) {
		// データの根ノードを得る
		x = find(x);
		y = find(y);

		// 既に同じ木に属しているならマージしない
		if (x == y) return;

		// xの木がyの木より大きくなるようにする
		if (sizes[x] < sizes[y]) swap(x, y);

		// xがyの親になるように連結する
		par[y] = x;
		sizes[x] += sizes[y];
		sizes[y] = 0;  // sizes[y]は無意味な値となるため
	}

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

	// データxが含まれる木の大きさを返す
	int size(int x) {
		return sizes[find(x)];
	}
};
int gcd(int n,int m){
	if(m>n) return gcd(m,n);
	if(m==0) return n;
	else return gcd(m,n%m); 
}

int main(void){
	int N,M,k,s,p[10];
	set<int> S[10];

	cin>>N>>M;
	REP(i,M){
		cin>>k;
		REP(j,k){
			cin>>s;
			S[i].insert(s);
		}
	}
	REP(i,M) cin>>p[i];

	int result=0,count=0;
	bool flug=false;
	REP(i,pow(2,N)){
		flug=true;

		stringstream ss;
		ss << static_cast<std::bitset<12>>(i);
		string tem=ss.str();
		reverse(tem.begin(), tem.end());;
		REP(j,M){
			count=0;
			REP(r,N)
				if(tem[r]=='1' && S[j].count(r+1)==1) count++;
			
			if(count%2!=p[j]){
				flug=false;
				break;
			}
		}
		if(flug) result++;
	}
	print(result);
	return 0;
}


Measured memory_bytes: 256
## xメートル地点で T-x*0.005

n = gets.chop.to_i
t, a = gets.chop.split.map(&:to_i)
h = gets.chop.split.map(&:to_i)

ans = 0

h.each_with_index{|height, index|
  
  ans = index if ((t - height * 0.006) - a).abs < ( (t-h[ans] * 0.006) - a ).abs
}


puts ans + 1


Measured memory_bytes: 1788
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define zero_pad(num) setfill('0') << std::right << setw(num)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;

int main() {
    chrono::system_clock::time_point start, end;
    start = chrono::system_clock::now();
    random_device seed_gen;
    mt19937_64 rnd(seed_gen());
    uniform_int_distribution<int> dist_d(0, 364), dist_q(0, 25);

    int d;
    cin >> d;
    vector<int> c(26);
    rep(i, 26)cin >> c[i];
    vector<vector<int>> s(d, vector<int>(26));
    rep(i, d)rep(j, 26)cin >> s[i][j];

    vector<int> t(d);
    rep(i, d){
        t[i] = dist_q(rnd);
    }

    int m = 1000000;

    vector<set<int>> last(26);
    rep(i, 26){
        last[i].insert(-1);
        last[i].insert(d);
    }
    rep(i, d)last[t[i]].insert(i);
    int sum = 0;
    rep(i, d){
        sum += s[i][t[i]];
        rep(j, 26){
            if(last[j].find(i) == last[j].end()){
                auto itr = lower_bound(last[j].begin(), last[j].end(), i);
                itr--;
                int day = i - *itr;
                sum -= c[j] * day;
            }
        }
    }
    double time = 0.0;
    while(true){
        int day = dist_d(rnd);
        int que = dist_q(rnd);
        int diff = 0;
        
        int cont;
        rep(j, 26){
            if(last[j].find(day) != last[j].end()){
                cont = j;
                break;
            }
        }
        diff += s[day][que] - s[day][cont];
        auto itr1 = last[cont].find(day);
        auto itr2 = lower_bound(last[que].begin(), last[que].end(), day);
        int x = *itr1;
        int y = *itr2;
        int dx = day - *(--itr1);
        int dy = day - *(--itr2);
        itr1++; itr1++;
        itr2++;
        diff -= c[cont] * dx * (*itr1 - day);
        diff += c[que] * dy * (*itr2 - day);
        if(diff > 0){
            last[cont].erase(day);
            last[que].insert(day);
            t[day] = que;
            sum += diff;
        }else{
            int p = dist_d(rnd);
            double prob = (1985 - time) / 1985 * 365;
            if(p + 1 < prob){
                last[cont].erase(day);
                last[que].insert(day);
                t[day] = que;
                sum += diff;
            }
        }
        end = chrono::system_clock::now();
        time = static_cast<double>(chrono::duration_cast<chrono::milliseconds>(end - start).count());
        if(time > 1985)break;
    }
    
    rep(i, d){
        cout << t[i] + 1 << endl;
    }
    
    
}

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

#define rep(i,x,y) for(int i=(x);i<(y);++i)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define dump(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define dump(x)
#endif

typedef long long int ll;
typedef pair<int,int> pii;
//template<typename T> using vec=std::vector<T>;

const int inf=1<<30;
const long long int infll=1LL<<58;
const double EPS=1e-9;
const int dx[]={1,0,-1,0},dy[]={0,1,0,-1};

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
	os << "[";
	for (const auto &v : vec) {
		os << v << ",";
	}
	os << "]";
	return os;
}

void dijkstra(vector<pii> graph[],vector<int> &dist,int start){ //distは初期化しておくこと
    typedef pair<int,int> pii;
    priority_queue<pii,vector<pii>,greater<pii>> que;
    dist[start]=0;
    que.push(make_pair(0,start));
    while(!que.empty()){
        pii p=que.top();
        que.pop();
        int v=p.second;
        if(p.first>dist[v]) continue;
        for(auto &e:graph[v]){
            int cost=e.first,u=e.second;
            if(dist[v]+cost<dist[u]){
                dist[u]=dist[v]+cost;
                que.push(make_pair(dist[u],u));
            }
        }
    }
}
void solve_(int n){
    vector<int> a,b;
    for(int i=0; i<n; ++i){
        int type=0;
        cin >> type;
        a.push_back(type);
    }
    for(int i=0; i<n; ++i){
        int type;
        cin >> type;
        b.push_back(type);
    }

    vector<pii> graph[201]; //[0,n):1つ目のビル,[n,2*n):2つ目のビル,2*n:ゴール
    rep(floor,0,n){
        int type=a[floor];
        vector<pii> &cur_node=graph[floor];
        if(floor==n-1&&type!=2) cur_node.push_back(make_pair(0,2*n));
        if(type==0||(type==1&&(floor==n-1||a[floor+1]!=1))){
            cur_node.push_back(make_pair(1,n+floor));
            if(floor+1<n) cur_node.push_back(make_pair(1,n+floor+1));
            if(floor+2<n) cur_node.push_back(make_pair(1,n+floor+2));
        }else if(type==1){
            cur_node.push_back(make_pair(0,floor+1));
        }else{
            cur_node.push_back(make_pair(0,floor-1));
        }
    }
    rep(floor,0,n){
        int type=b[floor];
        vector<pii> &cur_node=graph[n+floor];
        if(floor==n-1&&type!=2) cur_node.push_back(make_pair(0,2*n));
        if(type==0||(type==1&&(floor==n-1||b[floor+1]!=1))){
            cur_node.push_back(make_pair(1,floor));
            if(floor+1<n) cur_node.push_back(make_pair(1,floor+1));
            if(floor+2<n) cur_node.push_back(make_pair(1,floor+2));
        }else if(type==1){
            cur_node.push_back(make_pair(0,n+floor+1));
        }else{
            cur_node.push_back(make_pair(0,n+floor-1));
        }
    }

    int ans=inf;
    vector<int> dist(2*n+1,inf);
    dijkstra(graph,dist,0);
    ans=min(ans,dist[2*n]);
    fill(dist.begin(),dist.end(),inf);
    dijkstra(graph,dist,n);
    ans=min(ans,dist[2*n]);

    if(ans==inf) cout << "NA" << endl;
    else cout << ans << endl;
}

void solve(){
    dump(inf);
    int n;
    while(cin >> n,n) solve_(n);
}

int main(){
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	solve();
	return 0;
}

Measured memory_bytes: 1232
# vim: set fileencoding=utf-8 :
s = str(raw_input())

if s[0] == "A" and s[2:-1].count("C") == 1 and s.count("C") == 1 and s.count("A") == 1:
    s = s.replace("A", "a")
    s = s.replace("C", "c")
    if s.islower():
        print("AC")
    else:
        print"WA"
else:
    print("WA")


Measured memory_bytes: 2568
#include <iostream>
#include <string>
#include <cctype>
using namespace std;

int main(){

	string str;
	while(1){
		cin >> str;
		if(str == "0") break;
		int a = 0;
		for(int i = 0; i < str.length(); i++){
			a += str[i] - '0';
		}
		cout << a << endl;
	}

	return 0;
}

Measured memory_bytes: 1188
N = int(input())
S = input()

alphabet = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"]

newS = ""
for x in S:
  newS += alphabet[(alphabet.index(x)+N)%26]
print(newS)

Measured memory_bytes: 3064
import Control.Monad
f x = do
  hw_in <- (return . words) =<< getLine
  let h:w:[] = map (read::String->Int) hw_in
  if (h==0)&&(w==0)
    then return ()
    else do
      forM_ [1..h] (\i -> putStrLn [if (i+j)`mod`2==0 then '#' else '.'|j<-[1..w]])
      putStrLn ""
      f (x+1)
main = f 0


Measured memory_bytes: 4104
#include<stdio.h>
#include<stdlib.h>
#define MAX 10000
int main(){
	unsigned short *A,*B;
	int C[MAX+1];
	int n,i,j;
	scanf("%d",&n);
	A=malloc(sizeof(short)*n+1);
	B=malloc(sizeof(short)*n+1);
	 /*定义以及分配存储空间*/ 
	for(i=1;i<=n;i++){
		scanf("%hu",&A[i]);
	}
	for(i=0;i<=MAX;i++)
	C[i]=0;
	for(i=1;i<=n;i++)
		C[A[i]]++;
    for(i=1;i<=MAX;i++)
    C[i]=C[i]+C[i-1];
    for(i=n;i>0;i--){
    	B[C[A[i]]]=A[i];
    	C[A[i]]--;
	}//从A的末尾开始选择则稳定 
	for(i=1;i<=n;i++){
		if(i-1)
		printf(" ");
		printf("%d",B[i]);
	}
	printf("\n");
	return 0;
} 


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

class Program
{
    static void Main(string[] args)
    {
        long sum = 0;
        long n = long.Parse(Console.ReadLine());
        long[] arr = Console.ReadLine().Split(' ').Select(v => long.Parse(v)).ToArray();
        Dictionary<long, long> map = new Dictionary<long, long>();
        for(long i = 0; i < n; i++)
        {
            if (!map.ContainsKey(arr[i])) map.Add(arr[i], 1);
            else map[arr[i]]++;
        }
        foreach(long key in map.Keys)
        {
            sum += nCk(map[key], 2);
        }
        for(long i = 0; i < n; i++)
        {
            Console.WriteLine(sum - map[arr[i]] +1);
        }


        
        

    }

    public static long nCk(long n, long k)
    {
        if (n < k) return 0;
        if (n == k) return 1;

        long x = 1;
        for (long i = 0; i < k; i++)
        {
            x = x * (n - i) / (i + 1);
        }
        return x;
    }




}





Measured memory_bytes: 45908
#pragma region template
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const long long MOD = 1e9 + 7, MAX = 1e18, larg = 1e5, INF = -1e9;
long long A, B, C, D, E, F, G, H, I, J, K, L, N, M, O, P, Q, R, S, T, U, V, W, x, y, z;
long long max_value = INF, max_index = -1;
long long min_value = MAX, min_index = -1;
typedef long long ll;
typedef pair<ll, ll> Pa;

bool draw[9][9] = { false };

int main() {
	cin >> N >> M;
	rep(i, M) {
		cin >> A >> B;
		draw[A][B] = true;
		draw[B][A] = true;
	}
	vector<int> vec;
	rep(i, N - 1) {
		vec.push_back(i + 2);
	}
	int cnt = 0;
	do{
		bool flag = true;
		flag &= draw[1][vec[0]];
		rep(i, N - 2) {
			flag &= draw[vec[i]][vec[i + 1]];
		}
		if (flag) cnt++;
	} while (std::next_permutation(vec.begin(), vec.end()));
	cout << cnt;
}

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

using ll = long long int;

const int MAX = (int)(1e5 + 5);
const ll INF = (ll)(1e10 + 5);
const int MAX_S = (int)(1e6 + 5);

int s;

int a[MAX_S];

int f(int n) {
  if (n % 2 == 0) {
    return n / 2;
  }
  else {
    return 3 * n + 1;
  }
}

set<int> st;

int main(void) {
  // Here your code !
  scanf("%d", &s);

  a[1] = s;

  for (int i = 2; i < MAX_S; ++i) {
    a[i] = f(a[i - 1]);
  }

  for (int i = 1; i < MAX_S; ++i) {
    if (st.find(a[i]) != st.end()) {
      printf("%d\n", i);
      return 0;
    }
    st.insert(a[i]);
  }

  return 0;
}


Measured memory_bytes: 4096
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long a,b,c;
  cin >> a>>b>>c;
  long long sum = a*b*c;
  long long sum1 =  a/2*b*c;
  long long sum2 =  b/2*a*c;
  long long sum3 =  c/2*b*a;
  cout << min({sum-2*sum1,sum-2*sum2,sum-2*sum3});
}

Measured memory_bytes: 256
#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 printA(vector<T> &printArray, char between = ' ') {
   int paSize = printArray.size();
   for (int i = 0; i < paSize; i++) { cerr << printArray[i] << between;}
   if (between != '\n') {cerr << endl;}
}

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

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

   string s = to_string(n);
   if (count(all(s), s[0]) == 3) {
      cout << n << endl;
      return 0;
   }

   while (1) {
      n++;
      string t = to_string(n);
      if (count(all(t), t[0]) == 3) {
         break;
      }
   }

   cout << n << endl;

   return 0;
}

Measured memory_bytes: 256
N=int(input())
S=list(input())
K=int(input())

No_change=S[K-1]

out=[]
for s in S:
  s_temp=s
  if s != No_change:
    s_temp='*'
  out.append(s_temp)
  
out_str=''
for o in out:
  out_str+=o
  
print(out_str)

Measured memory_bytes: 3316
#include<stdio.h>
int main() {
	int N, K;
	scanf("%d %d", &N, &K);
	K -= 1;
	char S[N] = { 0 };
	scanf("%s", &S);
	char PV[1];
	PV[0] = S[K] -'A'+'a' ;
	S[K] = PV[K];
	printf("%s\n", S);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<long long> vll;
typedef vector<pair<int,int>> vp;
typedef pair<int,int> pii;
#define INF (int)(1e9)
#define MAXX 1.1529215e+18
#define inf 999999
#define EPS (1e-7)
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define REP(i,n) for(int i=1;i<=(int)(n);i++)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define ALL(a)  a.begin(),a.end()
#define RALL(a) a.begin(),a.end(),greater<int>()
#define ROT(a) a.begin(),a.begin()+1,a.end()
#define RROT(a) a.begin(),a.end()-1,a.end()
#define PB push_back
#define MP make_pair
#define PI acos(-1.0)
#define sz(a) a.size()
const ll MOD = 1e9+7;
const int MAX = 10000000;
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }
//cout << 'H' << endl;
//next_permutation(ALL(p));
//typedef priority_que<int> pque;//これは大きい順
//typedef priority_que<int, vector<int>, greater<int>> pque;//これは小さい順


int main(){
	int n;
	cin >> n;
	vector<string> s(n);
	rep(i,n) cin >> s[i];
	sort(ALL(s));

	map<string,int> mp;
	rep(i,n){
		mp[s[i]]++;
	}
	int max=0;
	rep(i,n){
		if(mp[s[i]]>max){
			max = mp[s[i]];
		}
	}
	s.erase(unique(ALL(s)), s.end());
	n = s.size();
	rep(i,n){
		if(mp[s[i]] == max){
			cout << s[i] << endl;
		}
	}

  return 0;
}


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

typedef long long ll;
const int maxn=1e6+7;
const int inf=INT_MAX;
const ll inff=1e18;
const ll mod=1e9+7;
#define pii pair<int,int>
#define mkp make_pair
#define F first
#define S second
#define pb push_back
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(),(v).end()
//#define int ll

#ifdef HNO2
#define IOS
#else
#define endl '\n'
#define IOS ios::sync_with_stdio(0); cin.tie(0);
#endif // HNO2

int h,n;
int sum=0,x;

int32_t main()
{
    IOS
    cin>>h>>n;
    for (int i=1;i<=n;i++)
    {
        cin>>x;
        sum+=x;
    }
    if (sum>=h) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}



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

const int mod = 1e9+7;
int f[4000 + 10][2000 + 10];

int N, M, K;

int main() {
	cin >> N >> M >> K;
	f[0][0] = 1;
	int ans = 0;
	for(int i = 1; i <= (N + M - 1) / (K - 1); ++i) {
		for(int j = 0; j <= (i - 1) * (K - 1); ++j) if(f[i-1][j]) {
			for(int k = 0; k < K; ++k) {
				int a = k + j, b = i * (K - 1) - a;
				if(a < N) (f[i][a] += f[i-1][j]) %= mod;
				if(k + 1 != K) {
					a = a + 1;
					if(N - a >= 0 && (M - b) >= 0)
					if((N - a) % (K - 1) == 0 && (M - b) % (K - 1) == 0)
						(ans += f[i-1][j]) %= mod;
				}
			}
		}
	}
	cout << ans << endl;
	return 0;
}


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

int main(){
    vector<int> a(10);
    for(int i=0;i<10;i++)cin>>a[i];
    sort(a.begin(),a.end());
    for(int i=9;i>=7;i--)cout<<a[i]<<endl;
    return 0;
}


Measured memory_bytes: 3152
using System;
using System.Text;
namespace Contest61
{
    public class Program
    {
        public static void Main(string[] args)
        {

            string a = Console.ReadLine();

            string[] aArray = a.Split(' ');

            Console.WriteLine(CalcString(aArray[0], aArray[1], aArray[2]));
        }


        public static string CalcString(string a, string b, string c)
        {
            int a1 = int.Parse(a);
            int b1 = int.Parse(b);
            int c1 = int.Parse(c);

            if(a1 <= b1 && c1 <= b1)
            {
                return "Yes";
            }
            else
            {
                return "No";
            }
        }

    }
}


Measured memory_bytes: 13140
#include <bits/stdc++.h>
using namespace std;
int kind[5] = {' ','A','C','G','T'};
typedef struct{
  vector<int>data;
}H;
H hash[2500000];

int convertion(string s){
  int d = 1;
  int sum = 0;
  for(int i = s.size() - 1;i >= 0;i--){
    for(int j = 1;j < 5;j++){
      if(kind[j] == s[i]){sum += d * j;break;}
    }
    d *= 5;
  }
  return sum;
}

int main(){
  string q,s;
  int n;
  cin >> n;
  while(n--){
    cin >> q >> s;
    if(q == "insert"){
      int sum = convertion(s);
      hash[sum / 100].data.push_back(sum);
    }
    if(q == "find"){
      int sum = convertion(s);
      bool flag = false;
      for(int i = 0;i < hash[sum / 100].data.size();i++){
	if(hash[sum / 100].data[i] == sum){cout << "yes" << endl;flag = true;break;}
      }
      if(!flag)cout << "no" << endl;
    }
  }
  return 0;
}

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

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int INF = 1e9;

int main() {
  ll n, ans = 0;
  string s, t;
  cin >> s >> t;
  rep(i, s.size()) if (s[i] != t[i]) ans++;

  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3852
#include <stdio.h>

int main(void)
{
	char n,a,b;
  	scanf("%hhd %hhd %hhd",&n,&a,&b);
  	printf("%hhd %hhd",((a<b)?a:b),(b-(n-a)<0)?0:(b-(n-a)));
	return 0;
}

Measured memory_bytes: 256
let n = Scanf.scanf " %d" (+) 0
let a_s = Array.init n @@ fun _ -> Scanf.scanf " %d" pred
let rs = Array.make n 0
let _ = Array.(iteri (fun i a -> rs.(a) <- i + 1) a_s; iteri (fun i r -> Printf.printf (if i = 0 then "%d" else " %d") r) rs; print_newline ())

Measured memory_bytes: 6784
#include <algorithm>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using namespace std;

int main()
{
	int n;
	cin>>n;
	int *stair = new int[n];
	for(int i =0; i < n; i++){
		int num;
		cin>>num;
		stair[i] = num;
	}
	bool canMakeStair = true;
	for(int i = 0; i < n-1; i++){
		if(stair[i] <= stair[i+1]){
			//do nothing
		}else if(stair[i+1] == stair[i] - 1){
			stair[i+1] += 1;
		}else{
			canMakeStair = false;
			break;
		}
	}
	if(canMakeStair == true){
		cout<<"Yes"<<endl;
	}else{
		cout<<"No"<<endl;
	}
	return 0;
}



Measured memory_bytes: 640
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE BinaryLiterals #-}
{-# LANGUAGE MultiWayIf #-}
{-# LANGUAGE NumDecimals #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TupleSections #-}

import Control.Applicative
import Control.Arrow
import Control.Monad
import Control.Monad.ST

import Data.Char
import Data.List
import Data.Maybe

import qualified Data.ByteString.Char8 as B

import Data.Array.ST.Safe
import Data.STRef

import Debug.Trace
import Text.Printf

readInt = readLn :: IO Int
readInts = map ( fst . fromJust . B.readInt ) . B.words <$> B.getLine
readNInts = readInt >>= flip replicateM readInt

which a b f = if f then a else b
mp [ a, b ] = ( a, b )

main = do
	[ n, t ] <- readInts
	cs <- map fst . filter ( ( <= t ) . snd ). map mp <$> replicateM n readInts
	if null cs
		then putStrLn "TLE"
		else print $ minimum cs

Measured memory_bytes: 508