akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
// iostream is too mainstream
#include <cstdio>
// bitch please
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <cmath>
#include <iomanip>
#include <time.h>
#define dibs reserve
#define OVER9000 1234567890
#define ALL_THE(CAKE,LIE) for(auto LIE =CAKE.begin(); LIE != CAKE.end(); LIE++)
#define tisic 47
#define soclose 1e-8
#define chocolate win
// so much chocolate
#define patkan 9
#define ff first
#define ss second
#define abs(x) ((x < 0)?-(x):x)
#define uint unsigned int
#define dbl long double
#define pi 3.14159265358979323846
using namespace std;
// mylittledoge

#ifdef DONLINE_JUDGE
	// palindromic tree is better than splay tree!
	#define lld I64d
#endif

int main() {
	cin.sync_with_stdio(0);
	cin.tie(0);
	cout << fixed << setprecision(10);
	int N,Q,L;
	cin >> N;
	vector<int> X(N);
	for(int i =0; i < N; i++) cin >> X[i];
	cin >> L >> Q;
	vector< vector<int> > lft(20,vector<int>(N)),rt(20,vector<int>(N));
	int akt =0;
	for(int i =0; i < N; i++) {
		while(akt < N && X[akt]-X[i] <= L) akt++;
		rt[0][i] =akt-1;}
	akt =N-1;
	for(int i =N-1; i >= 0; i--) {
		while(akt >= 0 && X[i]-X[akt] <= L) akt--;
		lft[0][i] =akt+1;}
	for(int k =1; k < 20; k++) for(int i =0; i < N; i++) {
		lft[k][i] =lft[k-1][lft[k-1][i]];
		rt[k][i] =rt[k-1][rt[k-1][i]];}
	for(int q =0; q < Q; q++) {
		int a,b;
		cin >> a >> b;
		a--, b--;
		int ans =0;
		for(int k =19; k >= 0; k--) {
			if(a < b && rt[k][a] < b) {
//				cout << a << " " << rt[]
				ans +=1<<k;
				a =rt[k][a];}
			else if(a > b && lft[k][a] > b) {
				ans +=1<<k;
				a =lft[k][a];}
			}
		if(a != b) ans++;
		cout << ans << "\n";}
	return 0;}

// look at my code
// my code is amazing


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

int main(void){
    // Your code here!
    long int N;
    cin >> N;
    long int sum = 0;
    for(int i=1; i<=N; i++){
        if(i%3!=0 && i%5!=0)
            sum+=i;
    }
    cout << sum;
    
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vin=vector<int>;
using vll=vector<long long>;
using vvin=vector<vector<int>>;
using vvll=vector<vector<long long>>;
using vstr=vector<string>;
using vvstr=vector<vector<string>>;
using vch=vector<char>;
using vvch=vector<vector<char>>;
using vbo=vector<bool>;
using vvbo=vector<vector<bool>>;
using vpii=vector<pair<int,int>>;
using pqsin=priority_queue<int,vector<int>,greater<int>>;
#define mp make_pair
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,s,n) for(int i=(s);i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define decp(n) cout<<fixed<<setprecision((int)n)
const ll inf=1e9+7;
const ll INF=1e18;

int main(){
    int h,w;cin>>h>>w;
    vvin a(h,vin(w)),b(h,vin(w)),c(h,vin(w));
    rep(i,h)rep(j,w)cin>>a[i][j];
    rep(i,h)rep(j,w){
        cin>>b[i][j];
        c[i][j]=abs(a[i][j]-b[i][j]);
    }
    const int num=80*160*2+1;
    vector<vvin> dp(2,vvin(w,vin(num)));//0,1
    dp[0][0][80*160+c[0][0]]=1;
    dp[0][0][80*160-c[0][0]]=1;
    int tmp;
    rep(i,h){
        tmp=i%2;
        if(i>0)rep(j,w)rep(k,num)dp[tmp][j][k]=0;
        rep(j,w)rep(k,num){
            if(j>0&&dp[tmp][j-1][k]){
                dp[tmp][j][k+c[i][j]]=1;
                dp[tmp][j][k-c[i][j]]=1;
            }
            if(i>0&&dp[(tmp+1)%2][j][k]){
                dp[tmp][j][k+c[i][j]]=1;
                dp[tmp][j][k-c[i][j]]=1;
            }
        }
    }
    rep(i,num/2+1){
        if(dp[(h-1)%2][w-1][80*160+i]||dp[(h-1)%2][w-1][80*160-i]){
            cout<<i<<endl;
            return 0;
        }
    }
}

Measured memory_bytes: 27544
from itertools import product
A, B, C, D = map(int, list(input()))
patterns = list(product(("+", "-"), ("+", "-"), ("+", "-")))
for pattern in patterns:
    if pattern[0] == "+":
        temp = A + B
    else:
        temp = A - B
    if pattern[1] == "+":
        temp = temp + C
    else:
        temp = temp - C
    if pattern[2] == "+":
        temp = temp + D
    else:
        temp = temp - D
    if temp == 7:
        print(str(A) + pattern[0] + str(B) +
              pattern[1] + str(C) + pattern[2] + str(D) + "=7")
        break


Measured memory_bytes: 3064
//Use valgrind once if the submission doesn't go through. It can detect uninitialized variables and see where they could be an issue.
#include <bits/stdc++.h>
using namespace std;

int main(){

	ios_base::sync_with_stdio(false);
    	cin.tie(NULL);

	long long n,sum{0};
	cin>>n;
	vector<long long> a(n);
	for(auto &i:a){
		cin>>i;
	}
	for(int i=1;i<a.size();++i){
		if(a[i]<a[i-1]){
			sum+=a[i-1]-a[i];
			a[i]=a[i-1];
		}
	}
	cout<<sum<<endl;
}


Measured memory_bytes: 4692
import math
h = int(input())
temp = 1
ans = 0


def calc(x):
    a = math.floor(x / 2)
    return a


if (h == 1):
    print('1')
else:
    while (h >= 1):
        h = calc(h)
        ans += temp
        temp *= 2
    print(ans)


Measured memory_bytes: 3060
#ifdef LOCAL
#define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>
using namespace std;

string s;
int t[110000];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    cin >> s;
    int n = s.size();
    int ans = 0;

    for (int i = 0; i < n; i++) {
        t[i+1] = t[i] + (s[i]-'0');
    }

    for (int k = 1; k <= n; k++) {
        int r = k-1;
        int l = n-k;
        if (l <= r) {
            if (t[r+1] - t[l] == r+1-l || t[r+1] == t[l]) {
                ans = max(ans,k);
            }
        }
        else {
            ans = max(ans, k);
        }
    }

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

Measured memory_bytes: 976
A, B, M = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
z = [list(map(int, input().split())) for i in range(M)]

price = min(a) + min(b)

for e in z:
    tmp_price = a[e[0]-1] + b[e[1]-1] - e[2]

    if(price > tmp_price):
        price = tmp_price

print(price)


Measured memory_bytes: 100584
A = [list(map(int, input().split())) for _ in range(3)]
C = [0] * 8
N = int(input())
flg = False
for _ in range(N):
    b = int(input())
    if flg:
        continue
    for i in range(3):
        for j in range(3):
            if A[i][j] == b:
                C[i] += 1
                C[j + 3] += 1
                C[6] += 1 if i + j == 2 else 0
                C[7] += 1 if i == j else 0
                for c in C:
                    if c >= 3:
                        flg = True
                        break
if flg:
    print('Yes')
else:
    print('No')


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

int main(){
   string S;
   cin>>S;
   bool ans=false;
  
   if(S.at(2)==S.at(3)&&S.at(4)==S.at(5)){
   ans=true;
   }
  
   if(ans==true){
   cout<<"Yes"<<endl;
   }
  
   if(ans==false){
   cout<<"No"<<endl;
   }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define DEBUG false
int main(){
    unsigned long long n;
    cin >> n;
    unsigned long long mod = pow(10,9)+7;
    vector <unsigned long long> a(n);
    unsigned long long maxA = 0;
    unsigned long long bit1Sum = 0;
    unsigned long long bit2Sum = 0;
    for(int i = 0; i < n; i++){
        cin >> a[i];
        maxA = max(a[i],maxA);
        if((a[i]&0x01)==0x01)bit1Sum++;
        if((a[i]&0x02)==0x02)bit2Sum++;
        //cout << bitset<60>(a[i])<<endl;
    }
    //cout << bit1Sum << " " << bit2Sum << endl;
    //cout << bitset<60>(maxA) << endl;
    //cout << bitset<60>(9375105820) << endl;
    if(DEBUG){
        long long ans = 0;
        vector <vector<int>> vv(n);
        for(int i = 0; i < n-1; i++){
            vv[i]=vector<int>(n,0);
            for(int j = i+1; j < n; j++){
                vv[i][j]++;
                ans+=a[i]^a[j];
                ans%=mod;
            }
        }
        cout << ans << endl;
    }
    vector <vector<unsigned long long>> bitnum;
    for(int i = 0; i < 62; i++){
        unsigned long long mask = (unsigned long long)0x01 << (unsigned long long)i;
        //cout << i << " " << mask << " " << maxA << endl;
        if(mask>maxA)break;
        bitnum.push_back(vector<unsigned long long>(n,0));
        for(unsigned long long j = 0; j < n; j++){
            if((a[j]&mask)==mask){
                if(j==0){
                    bitnum[i][j]=1;
                }else{
                    bitnum[i][j]=bitnum[i][j-1]+1;
                }
            }else{
                if(j==0){
                    bitnum[i][j]=0;
                }else{
                    bitnum[i][j]=bitnum[i][j-1];
                }
            }
        }
    }
    vector <unsigned long long> xorSum(bitnum.size(),0);
    for(unsigned long long i = 0; i < bitnum.size(); i++){
        for(unsigned long long j = 0; j < n-1; j++){
            //右辺の1の数を数える。
            unsigned long long num = bitnum[i][n-1];
            num -= bitnum[i][j];
            unsigned long long currentBit;
            if(j==0){
                currentBit = bitnum[i][j];
            }else{
                currentBit = bitnum[i][j]-bitnum[i][j-1];
            }
            if(currentBit==0){
                //左辺が0の時は右辺の1の数の総和がxorの総和
                xorSum[i]+=num;
            }else{
                unsigned long long maxNum = n-(j+1);
                xorSum[i]+=(maxNum-num);
            }
        }
    }
    // for(unsigned long long i = 0; i < bitnum.size(); i++){
    //     if(i%5==0)cout << endl;
    //     cout << bitnum[i].back() << " ";
    // }
    // cout << endl;

    unsigned long long ans = 0;
    for(unsigned long long i = 0; i < xorSum.size(); i++){
        if(xorSum[i]==0)continue;
        unsigned long long exp = i;
        unsigned long long tmp = xorSum[i];
        while(exp>0){
            tmp*=2;
            tmp%=mod;
            exp--;
        }
        ans+=tmp;
        ans%=mod;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 146352
use std::io::*;
use std::str::FromStr;

pub fn read<T: FromStr>() -> T {
  let stdin = stdin();
  let stdin = stdin.lock();
  let token: String = stdin
    .bytes()
    .map(|c| c.expect("failed to read char") as char)
    .skip_while(|c| c.is_whitespace())
    .take_while(|c| !c.is_whitespace())
    .collect();
  token.parse().ok().expect("failed to parse token")
}

use std::cmp::{max, min};
use std::collections::HashMap;

fn main() {
  let x = read::<i64>();
  let k = read::<i64>();
  let mut ans = 0;
  for i in 0..x {
    let j = read::<i64>();
    ans += min((k - j).abs(), j);
  }

  println!("{}", ans * 2);
}



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

int n,A;
pair<int,int> a[100000];

int main(){
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>A;
        a[i]=make_pair(A,i);
    }
    sort(a,a+n);
    for(int i=0;i<n;i++){
        if(i) cout<<" ";
        cout<<a[i].second+1;
    }cout<<endl;
    return 0;
}

Measured memory_bytes: 1536
#include<bits/stdc++.h>
#define rep(i, n) for(int i=0; i<int(n); i++)
#define ALL(a) (a).begin(), (a).end()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, P> PP;

const ll mod = 1e9 + 7;

long long gcd(ll x, ll y){
	if(x > y) swap(x, y);
	while(x != 0){
		y %= x;
		swap(x, y);
	}
	return y;
}

ll mpow(ll x, ll r){
	if(r == 0) return 1;
	if(r % 2 == 1){ return x * mpow(x, r-1) % mod; }
	else{ ll aa = mpow(x, r/2); return aa*aa%mod; }
}

int main(){
	ll N, K; cin >> N >> K;
	ll ans = 0, num[K+1];
	for(int g=K; g>=1; g--){
		if(g==K){
			num[K] = 1;
			ans += K;
		}else{
			ll xx = mpow(K/g, N);
			num[g] = xx;
			for(int j=2; j<=(K/g); j++){
				num[g] = (num[g] - num[j*g] + 10*mod) % mod;
			}
			ans = (ans + g*num[g]%mod) % mod;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 4352
#include<iostream>
using namespace std;
long long mini(long long a,long long b)
{
	return a>b?b:a;
}
int main()
{
	long long A,B,C;
	cin>>A>>B>>C;
	if(A%2&&B%2&&C%2)
	{
		cout<<mini(mini(A*B,B*C),C*A)<<"\n";
		return 0;
	}
	cout<<0<<"\n";
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rrep(i,n) for(int (i)=((n)-1);(i)>=0;(i)--)
#define itn int
#define all(x) (x).begin(),(x).end()
#define F first
#define S second
const long long INF = 1LL << 60;
const int MOD = 1000000007;
struct RollingHash{
    
    vector <int> hash, base_pow;
    int base = 1009, mod = 1e+7;
    
    RollingHash(string S = "",/*vector <int> S*/ int basetmp = -1, int modtmp = -1){
        if(modtmp != -1) mod = modtmp;
        if(basetmp != -1) base = basetmp;
        //cout<<mod<<' '<<base<<endl;
        //////
        int n = S.size();
        vector <int> z(n);
        rep(i,n) z[i] = S[i];
        hash.resize(n+1); base_pow.resize(n+1);
        hash[0] = 0, base_pow[0] = 1;
        for(int i=1;i<=z.size();i++){
            hash[i] = (hash[i-1] * base + z[i-1]) % mod;
            
            base_pow[i] = base_pow[i-1] * base % mod;
        }
        
    }
   /*void initialize(vector<int>& S){
        hash.resize(S.size()+1);
        base_pow.resize(S.size()+1);
        hash[0] = 0;
        base_pow[0] = 1;
        for(int i=1; i<=S.size(); i++){
            hash[i] = (hash[i-1] * base + S[i-1]) % mod;
            base_pow[i] = base_pow[i-1] * base % mod;
        }
    }*/
    int between(int a, int b){
        return (mod + hash[b] - hash[a] * base_pow[b-a] % mod) % mod;
    }
};
signed main(void){
    ///以下 https://atcoder.jp/contests/abc141/submissions/7525999 お借りします
    int N;
    string S;
    cin >> N >> S;
    int ok = 0, ng = N/2+1;
    RollingHash rh1(S, 1007, 1e9+7), rh2(S, 2009, 1e9+9);
 
    while(ng-ok>1){
        int len = (ng+ok)/2;
        set<pair<int64_t, int64_t>> val;
        vector<pair<int64_t, int64_t>> v(N);
        bool success = false;
        for(int i=0; i+len<=N; i++){
            if(i >= len) val.insert(v[i-len]);
            v[i] = {rh1.between(i, i+len), rh2.between(i, i+len)};
            if(val.count(v[i])){
                success = true;
                break;
            }
        }
        (success ? ok : ng) = len;
    }
    cout << ok << endl;
    return 0;
}


Measured memory_bytes: 828
#include<bits/stdc++.h>
using namespace std;
#define cs const
#define re register
#define pb push_back
#define pii pair<int,int>
#define ll long long
#define y1 shinkle
#define fi first
#define se second
#define bg begin
cs int RLEN=1<<20|1;
inline char gc(){
    static char ibuf[RLEN],*ib,*ob;
    (ib==ob)&&(ob=(ib=ibuf)+fread(ibuf,1,RLEN,stdin));
    return (ib==ob)?EOF:*ib++;
}
#define gc getchar
inline int read(){
    char ch=gc();
    int res=0;bool f=1;
    while(!isdigit(ch))f^=ch=='-',ch=gc();
    while(isdigit(ch))res=(res+(res<<2)<<1)+(ch^48),ch=gc();
    return f?res:-res;
}
inline ll readll(){
    char ch=gc();
    ll res=0;bool f=1;
    while(!isdigit(ch))f^=ch=='-',ch=gc();
    while(isdigit(ch))res=(res+(res<<2)<<1)+(ch^48),ch=gc();
    return f?res:-res;
}
inline int readstring(char *s){
	int top=0;char ch=gc();
	while(isspace(ch))ch=gc();
	while(!isspace(ch)&&ch!=EOF)s[++top]=ch,ch=gc();
	return top;
}
template<typename tp>inline void chemx(tp &a,tp b){a<b?a=b:0;}
template<typename tp>inline void chemn(tp &a,tp b){a>b?a=b:0;}
cs int N=1000006;
pii a[N],b[N];
char s[N];
int n,m,stk[N];
inline bool comp(pii x,pii y){
	return x.fi<y.fi;
	//return (x.se-x.fi)==(y.se-y.fi)?(x.fi<y.fi):(x.se-x.fi)>(y.se-y.fi);
}
int main(){
	n=read();int tot=0;
	for(int i=1;i<=n;i++){
		int len=readstring(s);
		int sm=0,top=0;
		for(int j=1;j<=len;j++){
			int vl=(s[j]=='('?1:-1);
			sm+=vl;
			if(top&&vl==-1&&stk[top]==1)top--;
			else stk[++top]=vl;
		}stk[0]=-1;stk[top+1]=1;tot+=sm;
		int x=0,y=0;
		for(int j=0;j<=top;j++){
			if(stk[j]==-1&&stk[j+1]==1){
				x=j,y=top-j;break;
			}
		}
	//	cout<<x<<" "<<y<<'\n';
		a[i]=pii(x,y);
	}if(tot!=0){
		puts("No");return 0;
	}
	sort(a+1,a+n+1,comp);
	for(int i=1,sm=0;i<=n;i++)if(a[i].se>=a[i].fi){
		if(sm<a[i].fi){
			puts("No");return 0;
		}sm+=a[i].se-a[i].fi;
	}
	for(int i=1;i<=n;i++)swap(a[i].fi,a[i].se);
	sort(a+1,a+n+1,comp);
	for(int i=1,sm=0;i<=n;i++)if(a[i].se>=a[i].fi){
		if(sm<a[i].fi){
			puts("No");return 0;
		}sm+=a[i].se-a[i].fi;
	}	
	puts("Yes");
}

Measured memory_bytes: 11364
import java.util.Arrays;
import java.util.Scanner;

class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        Trump[] a = new Trump[n];
        Trump[] b = new Trump[n];
        for (int i = 0; i < n; i++) {
            a[i] = new Trump(sc.next(), sc.nextInt());
            b[i] = a[i];
        }
        quickSort(a, 0, a.length - 1);
        mergeSort(b, 0, a.length);
        boolean isStable = Arrays.deepEquals(a, b);
        System.out.println(isStable ? "Stable" : "Not stable");
        printArray(a);
    }

    private static void quickSort(Trump[] a, int left, int right) {
        if (left < right) {
            int p = partition(a, left, right);
            quickSort(a, left, p - 1);
            quickSort(a, p + 1, right);
        }
    }

    private static int partition(Trump[] a, int left, int right) {
        int partition = a[right].num;
        int i = left;
        for (int j = left; j < right; j++) {
            if (a[j].num <= partition) {
                Trump tmp = a[i];
                a[i] = a[j];
                a[j] = tmp;
                i++;
            }
        }
        Trump tmp = a[i];
        a[i] = a[right];
        a[right] = tmp;
        return i;
    }

    private static void printArray(Trump[] array) {
        if (array.length == 0) {
            return;
        }
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < array.length; i++) {
            sb.append(array[i].type).append(" ").append(array[i].num).append("\n");
        }
        System.out.print(sb);
    }

    static class Trump {

        String type;
        int num;

        public Trump(String type, int num) {
            this.type = type;
            this.num = num;
        }
    }

    private static void mergeSort(Trump[] s, int left, int right) {
        if (left + 1 < right) {
            int mid = (left + right) / 2;
            mergeSort(s, left, mid);
            mergeSort(s, mid, right);
            merge(s, left, mid, right);
        }
    }

    private static void merge(Trump[] s, int left, int mid, int right) {
        Trump[] L = new Trump[mid - left + 1];
        Trump[] R = new Trump[right - mid + 1];
        System.arraycopy(s, left, L, 0, L.length - 1);
        System.arraycopy(s, mid, R, 0, R.length - 1);
        L[L.length - 1] = new Trump("", Integer.MAX_VALUE);
        R[R.length - 1] = new Trump("", Integer.MAX_VALUE);
        for (int i = 0, j = 0, k = left; k < right; k++) {
            if (L[i].num <= R[j].num) {
                s[k] = L[i];
                i++;
            } else {
                s[k] = R[j];
                j++;
            }
        }
    }
}

Measured memory_bytes: 101968
#include <iostream>

using namespace std;

int main(){
   int a,b;
   cin >> a;
   cin >> b;

   if(a < b)
      cout << "a < b" << endl;
   else if(a > b)
      cout << "a > b" << endl;
   else
      cout << "a == b" << endl;


   return 0;
}

Measured memory_bytes: 3076
#include <iomanip>
#include <iostream>
#include <algorithm>
using namespace std;
int n, w, v;
int main() {
	while (cin >> n >> w, w) {
		int m = 0, p = 0, d = 0, c[100] = { 0 };
		for (int i = 0; i < n; i++) cin >> v, m = max(m, v / w), c[v / w]++;
		for (int i = 0; i <= m; i++) d += (m - i) * c[i], p = max(p, c[i]);
		cout << fixed << setprecision(15) << 1.0 * d / m / p + 0.01 << endl;
	}
	return 0;
}

Measured memory_bytes: 3116
#include <stdio.h>

int main(int argc, const char * argv[]) {
    // insert code here...
    int i,n,a;
    long int max=-1000000, min=1000000, sum=0;
    
    scanf("%d",&n);
    
    for(i=0; i<n; i++){
        scanf("%d",&a);
        if(max<a){
            max = a;
        }
        if(min>a){
            min = a;
        }
        sum += a;
    }
    printf("%ld %ld %ld\n",min,max,sum);
    return 0;
}



Measured memory_bytes: 2108
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using System.Globalization;
using System.Diagnostics;
using System.Threading.Tasks;

class Sobaya
{
  static void Main(){
    new Sobaya().calc();
    return;
  }
    
  Scanner cin;
  
  void calc(){
    cin = new Scanner();
    int n = cin.nextInt();
    int d = cin.nextInt();
    
    Console.WriteLine(n/(2*d+1) + 1 * Convert.ToInt32(n%(2*d+1) != 0));
  }
    
  
  
}




class Scanner
{
    string[] s;
    int i;
 
    char[] cs = new char[] { ' ' };
 
    public Scanner()
    {
        s = new string[0];
        i = 0;
    }
 
    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }
 
    public int nextInt()
    {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextInt() + add;
        }
        return Array;
    }
 
    public long nextLong()
    {
        return long.Parse(next());
    }
 
    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextLong() + add;
        }
        return Array;
    }
 
    public double nextDouble()
    {
        return double.Parse(next());
    }
 
 
    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}

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

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

int N,M;
vector<vector<int> > G;
int dp[110000];

int rec(int v){
    if(dp[v]!=-1) return dp[v];

    int ret = 0;
    for(auto nv : G[v]){
        chmax(ret,rec(nv)+1);
    }

    return dp[v] = ret;
}


int main(){
    cin >> N >> M;
    G.assign(N,vector<int>());
    for(int i=0;i<M;++i){
        int v,e;
        cin >> v >> e;
        v--;e--;
        G[v].push_back(e);
    }

    for(int i=0;i<N;++i) dp[i] = -1;

    int ans = 0;
    for(int v=0;v<N;++v){
        chmax(ans,rec(v));
    }

    cout << ans << endl;
    return 0;

}



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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define SP << " " 
#define LLi long long int

using namespace std;

int imax=2147483647;
long long int llimax=9223372036854775807;

//int型vectorを出力
void PV(vector<int> pvv) {
	rep(i, pvv.size()) cout << pvv[i] SP;
	cout << endl;
}

//LLi型vectorを出力
void PVL(vector<LLi> pvv) {
	rep(i, pvv.size()) cout << pvv[i] SP;
	cout << endl;
}

int main(){

	int d, mans=-imax, ans;
	vector<int> c, t, ld, at;
	vector< vector<int> >s;

	cin>> d;

	c.resize(26);
	rep(i, 26) cin>> c[i];
	s.resize(d);
	rep(i, d){
		s[i].resize(26);
		rep(j, 26) cin>> s[i][j];
	}
	t.resize(d);
	at.resize(d);
	rep(i, d){
		int tmp=1, ma=-1;
		rep(j, 26){
			if(ma<s[i][j]){
				tmp=j;
				ma=s[i][j];
			}
		}
		at[i]=tmp+1;
	}

	rep(i, d){
		//cout<< t[i] <<endl;
	}

	ld.resize(26);

	/*int m;
	vector<int> qd, qq;
	cin>> m;
	qd.resize(m);
	qq.resize(m);
	rep(i, m) cin>> qd[i] >> qq[i];*/
	
  	std::random_device seed_gen;
  	std::mt19937 engine(seed_gen());
int cnt=0;
	int ti = clock();
    while (clock() - ti < 195 * CLOCKS_PER_SEC / 100){
		cnt++;
    	rep(i, d){
			int rs=engine();
			rs=abs(rs);
			//cout<< rs%26 <<endl;
			t[i]=rs%26;
		}
		ans=0;
		rep(i, 26) ld[i]=0;

		rep(i, d){
			ans+=s[i][t[i]];
			ld[t[i]]=i+1;
			rep(j, 26) ans-=(i-ld[j]+1)*c[j];
		}

		if(mans<ans){
			rep(i, d) at[i]=t[i]+1;
			mans=ans;
			//cout<< mans <<endl;
		}
	}
//cout<< cnt <<endl;
	rep(i, d) cout<< at[i] <<endl;
 
	return 0;
}

Measured memory_bytes: 3696
// C
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
// #include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif

using namespace std;
typedef long long int ll;
typedef unsigned long long ull;
typedef long double ld;
#define REP(i,n) for(ll i=0; i<(n); i++)
#define REPR(i, n) for(ll i = n;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define ALL(n) begin(n),end(n)
#define IN(a, x, b) (a<=x && x<b)
#define INIT std::ios::sync_with_stdio(false);std::cin.tie(0);
template<class T> inline T CHMAX(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T CHMIN(T & a, const T b) { return a = (a > b) ? b : a; }

const long double EPS = 1e-10;
const long long INF = 1e18;
const long double PI = acos(-1.0L);
const long long MOD = 1000000007;

int main(void){
    ll n;
    ll asum=0;
    ll bsum=0;
    ll ans =0;
    vector<ll> anum;
    vector<ll> bnum;
    vector<ll> diff;
    vector<ll> need_moved;
    ll tmp_val=0;
    cin >> n;
    REP(i,n){
        ll tmp;
        cin >>tmp;
        anum.push_back(tmp);
        asum+=tmp;
    }
    REP(i,n){
        ll tmp;
        cin >>tmp;
        bnum.push_back(tmp);
        bsum+=tmp;
        if(tmp > anum[i]){
            ans++;
            tmp_val+=tmp - anum[i];
        }else{
            need_moved.push_back(anum[i]- tmp);
        }
    }
    sort(ALL(need_moved), greater<ll>());
    if(bsum > asum){
        cout << -1 <<endl;
    }else{
        ll i=0;
        while(tmp_val>0){
            ans++;
            tmp_val -= need_moved[i];
            i++;
        }
        cout << ans <<endl;
    }
    return 0;
}

Measured memory_bytes: 5944
<?php
while($input = trim(fgets(STDIN))){
    $array =explode(" ", $input);
    
    $H = $array[0];
    $W = $array[1];

    if($H == 0 && $W == 0)
        break;
    
    for($i = 0; $i < $H; $i++){
        for($j = 0; $j < $W; $j++){
            if($i > 0 && $i < $H - 1 && $j > 0 && $j < $W - 1)
                echo ".";
            else 
              echo "#";
        }
        echo "\n";
    }
    echo "\n";
        
}


Measured memory_bytes: 9224
//! ----------------------------------------------
//! Framework <https://github.com/vain0x/procon>
//!
//! See the bottom of file for solution.
//! ----------------------------------------------

#![allow(unused_imports)]
#![allow(non_snake_case)]

use std::cell::RefCell;
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::fmt::{Debug, Display, Formatter, Write as FmtWrite};
use std::io::{stderr, stdin, BufRead, Write};
use std::mem::{replace, swap};
use std::ops::*;
use std::rc::Rc;

/// Print values to standard error if debug mode.
#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), stderr());
            writeln!(err, "\x1B[33m{}\x1B[0m = {:?}", e, $e).unwrap()
        })*
    };
}

/// Read from standard input and parse each word.
/// - `read!(T, U, ..)` parses a line as a tuple of words.
/// - `read![[T]]` parses a line as an array of words.
/// - `read![..; N]` parses `N` lines, using `read!(..)` repeatedly.
#[allow(unused_macros)]
macro_rules! read {
    ([$t:ty] ; $n:expr) =>
        ((0..$n).map(|_| read!([$t])).collect::<Vec<_>>());
    ($($t:ty),+ ; $n:expr) =>
        ((0..$n).map(|_| read!($($t),+)).collect::<Vec<_>>());
    ([$t:ty]) =>
        (rl().split_whitespace().map(|w| w.parse().unwrap()).collect::<Vec<$t>>());
    ($($t:ty),*) => {{
        let buf = rl();
        let mut w = buf.split_whitespace();
        ($(w.next().unwrap().parse::<$t>().unwrap()),*)
    }};
}

/// Read a line from standard input.
#[allow(dead_code)]
fn rl() -> String {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();

    #[allow(deprecated)]
    buf.trim_right().to_owned()
}

// -----------------------------------------------
// Solution
// -----------------------------------------------

struct Solver {
    K: usize,
    A: Vec<i64>,
    B: Vec<i64>,
    C: Vec<i64>,
    done: BTreeSet<(usize, usize, usize)>,
    heap: BinaryHeap<(i64, (usize, usize, usize))>,
}

impl Solver {
    fn push(&mut self, a: usize, b: usize, c: usize) {
        if a >= self.A.len() || b >= self.B.len() || c >= self.C.len() {
            return;
        }

        if self.done.insert((a, b, c)) {
            self.heap
                .push((self.A[a] + self.B[b] + self.C[c], (a, b, c)));
        }
    }

    fn solve(&mut self) {
        self.push(0, 0, 0);

        for _ in 0..self.K {
            let (sum, (a, b, c)) = self.heap.pop().unwrap();
            println!("{}", sum);

            self.push(a + 1, b, c);
            self.push(a, b + 1, c);
            self.push(a, b, c + 1);
        }
    }
}

fn main() {
    let (_, _, _, K) = read!(usize, usize, usize, usize);
    let mut A = read![[i64]];
    let mut B = read![[i64]];
    let mut C = read![[i64]];

    A.sort_by(|l, r| r.cmp(l));
    B.sort_by(|l, r| r.cmp(l));
    C.sort_by(|l, r| r.cmp(l));

    let done = BTreeSet::new();
    let heap = BinaryHeap::new();

    Solver {
        K: K,
        A: A,
        B: B,
        C: C,
        done: done,
        heap: heap,
    }
    .solve()
}


Measured memory_bytes: 4352
#include <cstdio>
#include <algorithm>
#include <cmath>

const int MAXN = 100000;
int ans[MAXN][3];
int a[MAXN], b[MAXN], c[MAXN];

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

    ans[0][0] = a[0];
    ans[0][1] = b[0];
    ans[0][2] = c[0];

    for (int i = 1; i < n; ++i)
    {
        ans[i][0] = a[i] + std::max(ans[i - 1][1], ans[i - 1][2]);
        ans[i][1] = b[i] + std::max(ans[i - 1][0], ans[i - 1][2]);
        ans[i][2] = c[i] + std::max(ans[i - 1][0], ans[i - 1][1]);
    }
    
    printf("%d\n", std::max(std::max(ans[n - 1][0], ans[n - 1][1]), ans[n - 1][2]));

    return 0;
}


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

int n, m, a, b;
int bio[100010];
vector<int> v[100010];

int dfs(int x) {
	for (int i = 0; i < v[x].size(); i ++) {
		if (bio[ v[x][i] ] == 0) bio[x] = max(bio[x], dfs(v[x][i]) + 1);
		else {
			bio[x] = max(bio[x], bio[ v[x][i] ] + 1);
		}
	}
	
	return bio[x];
}

int main () {
	
	cin >> n >> m;
	for (int i = 0; i < m; i ++) {
		cin >> a >> b;
		v[a].push_back(b);
	}
	
	int maxi = 0;
	for (int i = 1; i <= n; i ++) {
		if (bio[i] == 0) {
			dfs(i);
		}
		
		maxi = max(maxi, bio[i]);
	}
	
	cout << maxi;
	
	return 0;
}

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

signed main(){
	ll n; cin>>n;
	vl a(n);
	ll m=0,j;
	rep(i,0,n){
		ll b; cin>>b;
		if(m<b){
			m=b;
			j=i;
		}
		a[i]=b;
	}
	ll ans=0,v=-1;
	//cout<<"m:"<<m<<endl;
	rep(i,0,n){
		if(i==j) continue;
		ll k=m-a[i];
		ll l=min(k,a[i]);
		//cout<<"k:"<<k<<" a[i]:"<<a[i]<<" ans:"<<ans<<endl;
		if(v<l){
			v=l;
			ans=a[i];
		}
	}
	cout<<m<<" "<<ans;
	
	return 0;
}

Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
//		String s = sc.next();
//		int n = sc.nextInt();
		int n = sc.nextInt();

		double[] dArray = new double[n];
		for(int i=0;i<n;i++) {
			dArray[i] = sc.nextDouble();
		}

		double ans = 0;

		for(int i=1;i<=100;i++) {
			double sum = 0;
			for(int j=0;j<n;j++) {
				sum += Math.pow(dArray[j]-i, 2);
			}
			if(sum<ans || i==1) {
				ans = sum;
			}
		}

		System.out.println((int)ans);

	}
}


Measured memory_bytes: 25172
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++){
    cin >> A[i];
    A[i] -= i + 1;
  }
  sort(A.begin(), A.end());
  int b = A[N / 2];
  long long ans = 0;
  for (int i = 0; i < N; i++){
    ans += abs(A[i] - b);
  }
  cout << ans << endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main(void){
	int n;
	int a[11];
	cin>>n;
	int i;
	for(i=0;i<n;i++){
		cin>>a[i];
	}
	sort(a,a+n,greater<int>());
	a[0]/=2;
	int sum=0;
	for(i=0;i<n;i++){
		sum+=a[i];
	}
	cout<<sum<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second
 
const int mx=100010;
const ll mod=1e9+7;

int main(){
  int n,x,y;
  cin >> n >> x >> y; x--; y--;
  vector<int> a(n,0);
  rep(i,n)rep(j,i){
    int dist = i-j;
    dist = min(dist, abs(x-i)+1+abs(y-j));
    dist = min(dist, abs(y-i)+1+abs(x-j));
    a[dist]++;
  }
  REP(i,1,n){
    cout << a[i] << endl;
  }
  return 0;
}

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

int main(){
	int x,y,z;
	int ans=0;
	cin >> x >> y >> z;
	ans=(x-2*z)/(y+z);
	if((x-2*z)%(y+z)>=y)ans++;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;
 
  if (A + B > C + D) cout << "Left" << endl;
  else if (A + B == C + D) cout << "Balanced" <<endl;
  else cout << "Right" << endl;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;

public class Main {

    static BufferedReader in;
    static PrintWriter out;
    static StringTokenizer tok;

    void solve() throws IOException {
        int v = ni();
        int e = ni();
        int r = ni();

        ArrayList<ArrayList<Edge>> G = new ArrayList<>();
        for (int i = 0; i < v; i++) {
            G.add(new ArrayList<>());
        }

        for (int i = 0; i < e; i++) {
            int s = ni();
            int t = ni();
            int d = ni();

            G.get(s).add(new Edge(t, d));
        }

        PriorityQueue<Pair> Q = new PriorityQueue<>();
        Q.add(new Pair(r, 0));
        boolean[] used = new boolean[v];
        int[] dist = new int[v];
        int INF = Integer.MAX_VALUE;
        Arrays.fill(dist, INF);

        while (!Q.isEmpty()) {
            Pair p = Q.poll();
            if (used[p.x]) continue;
            used[p.x] = true;
            dist[p.x] = p.y;

            for (Edge edge : G.get(p.x)) {
                Q.add(new Pair(edge.to, p.y + edge.cost));
            }
        }

        for (int i = 0; i < v; i++) {
            if (dist[i] != INF) out.println(dist[i]);
            else out.println("INF");
        }
    }

    class Edge {
        int to;
        int cost;

        public Edge(int to, int cost) {
            this.to = to;
            this.cost = cost;
        }
    }

    public class Pair implements Comparable<Pair> {
    	int x, y;

    	public Pair(int x, int y) {
    		this.x = x;
    		this.y = y;
    	}

    	public int compareTo(Pair p) {
    		return y - p.y;
    	}
    }

    String ns() throws IOException {
        while (!tok.hasMoreTokens()) {
            tok = new StringTokenizer(in.readLine(), " ");
        }
        return tok.nextToken();
    }

    int ni() throws IOException {
        return Integer.parseInt(ns());
    }

    long nl() throws IOException {
        return Long.parseLong(ns());
    }

    double nd() throws IOException {
        return Double.parseDouble(ns());
    }

    String[] nsa(int n) throws IOException {
        String[] res = new String[n];
        for (int i = 0; i < n; i++) {
            res[i] = ns();
        }
        return res;
    }

    int[] nia(int n) throws IOException {
        int[] res = new int[n];
        for (int i = 0; i < n; i++) {
            res[i] = ni();
        }
        return res;
    }

    long[] nla(int n) throws IOException {
        long[] res = new long[n];
        for (int i = 0; i < n; i++) {
            res[i] = nl();
        }
        return res;
    }

    public static void main(String[] args) throws IOException {
        in = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        tok = new StringTokenizer("");
        Main main = new Main();
        main.solve();
        out.close();
    }
}

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

unsigned long long int gdb(unsigned long long int a,unsigned long long int b){
  unsigned long long int x = a * b;

if(a<b){
  unsigned long long int tmp = a;
  a = b;
  b = tmp;
}

unsigned long long int r = a % b;
while(r!=0){
  a = b;
  b = r;
  r = a % b;
}
return x/b;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  //ifstream in("input.txt");
  //cin.rdbuf(in.rdbuf());
  unsigned long long int a,b,c,d;
  string str;
  cin >> a >> b >> c >> d;
  unsigned long long int sa = b - a;
  unsigned long long int koubai = gdb(c,d);
  unsigned long long int koubai_num = b/koubai - (a-1)/koubai;
  unsigned long long int c_num = b/c - (a-1)/c;
  unsigned long long int d_num = b/d - (a-1)/d;
  //cout << c_num << " " << d_num << " " << koubai_num << endl;
  unsigned long long int ans = b-a+1 - (c_num+d_num) + koubai_num;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include<map>
#include<vector>
#include<queue>
using namespace std;

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

    /*
    vector<int> ans;
    map<int,int> x, y;
    int ng = 0;
    for(int i = 0; i < n; i++){
        int j = n-1-i;
        if(x[a[i]]==y[a[i]])  ng++;
        x[a[i]]++;
        if(x[a[i]] == y[a[i]])  ng--;
        if(x[a[j]]==y[a[j]])  ng++;
        y[a[j]]++;
        if(x[a[j]] == y[a[j]])  ng--;
        if(ng == 0) ans.push_back(i+1);
    }
    for(int i = 0; i < ans.size(); i++) cout << ans[i] << " \n"[i+1==ans.size()];
    */

    // editorial
    vector<int> ans;
    priority_queue<int> x, y;
    for(int i = 0; i < n; i++){
        int j = n-1-i;
        x.push(a[i]);
        y.push(a[j]);
        while(x.size() && x.top()==y.top())   x.pop(), y.pop();
        if(x.size() == 0)   ans.push_back(i+1);
    }
    for(int i = 0; i < ans.size(); i++) cout << ans[i] << " \n"[i+1==ans.size()];
    return 0;
}


Measured memory_bytes: 4084
from collections import Counter

n = int(input())
a= list(map(int,input().split()))

b=[]
c=[]
# enumerate()
for n,i in enumerate(a,1):
    b.append(n-i)
    c.append(n+i)

# print(b)
col = Counter(c)
ans=0

for bb in b:
    ans += col[bb]

print(ans)

Measured memory_bytes: 141072
#include <cstdio>
#include <queue>
#include <string>
#include <set>
#include <map>
#include <vector>
#include <string>
#include <sstream>
#include <iostream>
#include <bitset>
#include <cmath>
#include <algorithm>
#include <functional>
#include <string.h>
using namespace std;
const int INF = 1<<28;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i,start,end) for(int i=(start);i<(end);++i)
#define pint(i) printf("%d\n",(i))
#define pint2(i,j) printf("%d %d\n",(i),(j))
#define pint3(i,j,k) printf("%d %d %d\n",(i),(j),(k))
#define gint(i) scanf("%d",&(i))
#define gint2(i,j) scanf("%d %d",&(i),&(j))
#define gint3(i,j,k) scanf("%d %d %d",&(i),&(j),&(k))
#define init(tar,val) memset((tar),(val),sizeof((tar)))
#define show(tar,len) for(int i=0;i<(len);++i) \
	cout<<tar[i]<<' ';\
	cout<<endl;




int main(){
	//freopen("a.in", "r", stdin);
	int n;
	while (cin >> n && n){
		int cost[10][10];
		rep(i, 0, 10){
			rep(j, 0, 10){
				cost[i][j] = i == j ? 0 : INF;
			}
		}
		rep(i, 0, n){
			int a, b, c;
			cin >> a >> b >> c;
			cost[a][b] = cost[b][a] = c;
		}
		rep(k, 0, 10){
			rep(i, 0, 10){
				rep(j, 0, 10){
					cost[i][j] = min(cost[i][j], cost[i][k] + cost[k][j]);
				}
			}
		}
		int out = INF, id = 0;
		rep(i, 0, 10){
			int tmp = 0;
			rep(j, 0, 10){
				if (cost[i][j] < INF)
					tmp += cost[i][j];
			}
			if (tmp && tmp < out){
				out = tmp;
				id = i;
			}
		}
		cout << id << ' ' << out << endl;
	}
	return 0;
}

Measured memory_bytes: 3068
import java.util.Scanner;
import java.util.Arrays;

public class Main{
public static void main(String[] args){
Scanner scan=new Scanner(System.in);
int n=scan.nextInt();
String[] a=new String[n];

int i=0;
for(i=0;i<n;i++){
    a[i]=scan.next();
}
Arrays.sort(a);  
  
int[] b=new int[n];
for(i=0;i<n;i++){
    b[i]=1;
}
  
for(i=1;i<n;i++){
  if(a[i].equals(a[i-1])){
    b[i]=b[i-1]+1;
  }
}
  
int max=0;  
for(i=0;i<n;i++){
  if(b[i]>max){
    max=b[i];
  }
}
  
for(i=0;i<n;i++){
  if(b[i]==max){
    System.out.println(a[i]);
  }
}
  
}
}

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

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n, k;
    string s;
    cin >> n >> s >> k;
    
    string ans = "";
    rep(i, n){
        if(s[i] != s[k - 1]){
            ans += "*";
        }else{
            ans += s[k-1];
        }
    }
    
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <limits>
#include <numeric>
#include <queue>
#include <set>
#include <bitset>
#include <map>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<char> vc;
typedef vector<long long> vll;
typedef queue<int, int> qii;
typedef pair<int, int> pii;
typedef pair<string, int> psi;

#define PI 3.14159265359
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rept(i,n) rep(i,0,n)

//int型を受け取ってその桁数を返す
int check_digits(int n,int m) {
	int digits = 0;
	while (n != 0) {
		n /= m;
		digits++;
	}
	return digits;
}

//int型を受け取ってその各桁の和を返す
int sum_digits(int n) {
	int sum=0;
	int N = n;
	while (N) {
		sum += N % 10;
		N /= 10;
	}
	return sum;
}


//最大公約数を返す関数
int gcd(int n, int m) {
	while (n != 0) {
		if (n < m) swap(n, m);
		n = n % m;
	}
	return m;
}


//2点間の距離を返す
float dis(int x1, int y1, int x2, int y2) {
	return sqrt(pow(abs(x1 - x2), 2) + pow(abs(y1 - y2), 2));
}


//入力された文字列が回文か判断してboolを返す
bool is_kaibun(string s) {
	string s_r(s.rbegin(), s.rend());
	return (s == s_r);
}


void yes() {cout << "Yes" << endl;}
void no() {cout << "No" << endl;}


//問題文を落ち着いて読む！
//型に注意！！
//出力例もちゃんと全部見る！！！！！
int main() {
	vector<vector<pair<int, bool>>> card(3,vector<pair<int,bool>>(3));
	
	rept(i, 3) {
		rept(j, 3) {
			cin >> card[i][j].first;
			card[i][j].second = false;
		}
	}

	int n;
	cin >> n;
	vi b(n);
	rept(i, n)cin >> b[i];

	rept(i, 3) {
		rept(j, 3) {
			rept(k, n) {
				if (b[k] == card[i][j].first)card[i][j].second = true;
			}
		}
	}

	bool ans = false;

	//yoko
	rept(i, 3)if (card[i][0].second && card[i][1].second && card[i][2].second)ans = true;

	//tate
	rept(i, 3)if (card[0][i].second && card[1][i].second && card[2][i].second)ans = true;

	if (card[0][0].second && card[1][1].second && card[2][2].second)ans = true;
	if (card[0][2].second && card[1][1].second && card[2][0].second)ans = true;

	if (ans)yes();
	else no();

	system("pause");
	return 0;
}

Measured memory_bytes: 504
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <queue>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <climits>
//#include "h.h"
using namespace std;

#define MOD1097 1000000007

#define ll long long
#define pint pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define mp make_pair
#define pm(first, second) pb(mp(first, second))
#define SPACE " "
#define fpf first.first
#define fps first.second
#define spf second.first
#define sps second.second

#define all(X) (X).begin(), (X).end()

int main(){

	int N;
	ll X;
	cin >> N >> X;
	vector<ll> L(N);
	for(int i = 0; i < N; i ++){
		cin >> L[i];
	}
	ll D = 0, ans = 1;
	for(int i = 0; i < N; i ++){
		D = D + L[i];
		if(D <= X)ans ++;
	}
	cout << ans << endl;

//"Hiroakimm0415"

	return 0;
}

Measured memory_bytes: 256