akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<string>
#include<vector>
#include<set>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<limits>
#include<list>
#include<math.h>
using namespace std;
#define ll long long
#define f(i,x,n) for (int i = x;i < n;++i)

vector<int> tr[2001];
int k, n, z;

pair<int,int> fn(int u, int l = 0, int p = -1) {
	pair<int, int> an = make_pair((l > (k >> 1)), l == (k >> 1) + 1);
	f(i, 0, tr[u].size())if (tr[u][i] != p) {
		pair<int,int> t = fn(tr[u][i], l + 1, u);
		if (p != -1)an.second += t.second;
		else an.second = max(an.second, t.second);
		an.first += t.first;
	}
	return an;
}

int main() {
	scanf("%d%d", &n, &k);
	f(i, 1, n) {
		int a, b;
		scanf("%d%d", &a, &b);
		tr[a].push_back(b);
		tr[b].push_back(a);
	}
	int an = 100000;
	f(i, 1, n + 1) {
		z = -1;
		pair<int,int> t = fn(i);
		if (k & 1)t.first -= t.second;
		an = min(an, t.first);
	}
	printf("%d", an);
}

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

const int INF = 1e9 + 1;

bool check(vector<int> w, int n, int k, int x) {
  int sum = 0;
  int cnt = 1;
  for ( int i = 0; i < n; i++ ) {
    if ( w[i] > x ) return false;
    if ( sum+w[i] > x ) {
      cnt++;
      sum = w[i];
    } else {
      sum += w[i];
    }
  }

  if ( cnt <= k ) return true;
  else return false;
}

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

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

  int l = -1, r = INF;
  while ( r-l > 1 ) {
    int mid = (l+r)/2;
    if ( check(w, n, k, mid) ) r = mid;
    else l = mid;
  }

  cout << r << endl;
  
  return 0;
}



Measured memory_bytes: 3672
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using G = vector<vector<int>>;
    
int main(){
    int n;
    cin >> n;
    vector<int> a(n), b(n);
    rep(i,n) cin >> a[i] >> b[i];

    sort(a.begin(), a.end());
    sort(b.begin(), b.end());

    int ans;
    if(n%2){
        ans = b[(n+1)/2-1] - a[(n+1)/2-1] + 1;
    } else{
        ans = b[n/2-1] + b[n/2] - a[n/2-1] - a[n/2] + 1;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4840
#include<bits/stdc++.h>
using namespace std;
int main(){
	int t[3][3];
	for(int i=0;i<3;i++)
		for(int j=0;j<3;j++)
			cin>>t[i][j];
	int N;
	cin>>N;
	while(N--){
		int tmp;
		cin>>tmp;
		for(int i=0;i<3;i++)
			for(int j=0;j<3;j++)
				if(t[i][j]==tmp)
					t[i][j]=0;
	}
	for(int i=0;i<3;i++){
		bool bingo=true;
		for(int j=0;j<3;j++)
			if(t[i][j]^0)
				bingo=false;
		if(bingo)
			return cout<<"Yes", 0;
	}
	for(int i=0;i<3;i++){
		bool bingo=true;
		for(int j=0;j<3;j++)
			if(t[j][i]^0)
				bingo=false;
		if(bingo)
			return cout<<"Yes", 0;
	}
	if(t[0][0]==0 && t[1][1]==0 && t[2][2]==0)
		return cout<<"Yes", 0;
	if(t[0][2]==0 && t[1][1]==0 && t[2][0]==0)
		return cout<<"Yes", 0;
	cout<<"No";
}


Measured memory_bytes: 256
ma = lambda :map(int,input().split())
ni = lambda:int(input())
import collections
import math
import itertools
gcd = math.gcd
n = ni()
A  = list(ma())
c = 0
for i in range(n):
    if i%2==0 and A[i] %2==1:
        c+=1
print(c)


Measured memory_bytes: 9408
import java.util.*;
 
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n= sc.nextInt();
    int[][] arr = new int[n][2];
    for(int i=0;i<n;i++){
      arr[i][0] = sc.nextInt();
      arr[i][1] = sc.nextInt();
    }
    boolean flag = false;
    
    for(int i=0;i<n-2;i++){
      if(arr[i][0] == arr[i][1] && arr[i+1][0]==arr[i+1][1] && arr[i+2][0]==arr[i+2][1]){
        flag = true;
        break;
      }
    }
    if(flag){
      System.out.println("Yes");
    }else{
      System.out.println("No");
    }
    
  }
}

Measured memory_bytes: 35964
#include <bits/stdc++.h>
#define BIT(n) (1LL << (n))
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPB(i, n) for (int i = 0; i < BIT(n); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORA(i, v) for (auto &&i : v)
#define FORS(i, m, n) for (int i = m; i <= n; i++)
#define INF 2e9
#define MOD (1000000007)
#define EPS 1e-9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long long int lli;
vector<vector<int>> graph;
vector<bool> visited;
vector<vector<pair<int, int>>> visitedList;
vector<pair<int, int>> ans;
vector<int> d;
int N, M;

//トポロジカル順序
/*
トポロジカル順序に関する問題であることは漠然とわかったが
その後が続かなかった。
特にグラフの辺を削除する部分にコストがかかると思ってしまった。
実際には、グラフを削除する必要はなかった。
stackを使うのが本質的なポイントかもしれない。
 */
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N >> M;
    graph.resize(N + 1, vector<int>());
    visited.resize(N + 1);
    //頂点とその親を保存する.
    visitedList.resize(N + 1, vector<pair<int, int>>());
    d.assign(N + 1, 0);
    REP(i, N - 1 + M)
    {
        int a, b;
        cin >> a >> b;
        graph[a].push_back(b);
        //入次数
        d[b]++;
    }

    stack<pair<int, int>> st;
    REPS(i, N)
    {
        if (d[i] == 0)
            st.push(make_pair(i, -1));
    }
    vector<pair<int, int>> ans;
    while (st.size())
    {
        int i = st.top().first;
        int j = st.top().second;
        //cout << i << " " << j << endl;
        st.pop();
        //me parent
        ans.emplace_back(i, j);
        for (auto &&v : graph[i])
        {
            d[v]--;
            if (d[v] == 0)
                st.push(make_pair(v, i));
        }
    }
    sort(ALL(ans));
    FORA(i, ans)
    {
        cout << ((i.second == -1) ? 0 : i.second) << "\n";
    }
}

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

int main() {
  int n,m,R;
  cin >> n >> m >> R;
  vector<int>r(R);
  rep(i,0,R){cin >> r[i];r[i]--;}
  vector<vector<int>>d(n,vector<int>(n,1e9+7));
  rep(i,0,m){
    int a,b,c;
    cin >> a >> b >> c;
    a--;b--;
    d[a][b] = d[b][a] = c;
  }
  for (int k = 0; k < n; k++){       // 経由する頂点
    for (int i = 0; i < n; i++) {    // 始点
      for (int j = 0; j < n; j++) {  // 終点
        d[i][j] = min(d[i][j],d[i][k]+d[k][j]);
      }
    }
  }
  sort(r.begin(),r.end());
  int ans = 1e9+7;
  do {
    int tmp = 0;
    rep(i,0,R-1) tmp += d[r[i]][r[i+1]];
    ans = min(ans,tmp);
  } while (std::next_permutation(r.begin(), r.end()));
  cout << ans << endl;
}

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

int main(){
	int n ; cin >> n ;
	string s ; cin >> s ;
	int cnt = 0 ;
	for(int i=0;i<n-2;i++){
		if(s.at(i)=='A'&&s.at(i+1)=='B'&&s.at(i+2)=='C'){
			cnt++ ;
		}
	}
	cout << cnt << endl ;
}





Measured memory_bytes: 256
def parent(i):
    return int(i/2)

def left(i):
    return 2*i

def right(i):
    return 2*i + 1

def main():
    H = int(raw_input())
    A = map(int,raw_input().split())
    for i in xrange(1,H+1):
        print "node {}: key = {},".format(i, A[i-1]),
        if parent(i) >= 1: 
            print "parent key = {},".format(A[parent(i)-1]),
        if left(i) <= H: 
            print "left key = {},".format(A[left(i)-1]),
        if right(i) <= H:
            print "right key = {},".format(A[right(i)-1]),
        print '',
        print 
    return 0

main()

        
        

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

ll query(int left, int now, char c) {
  if(now == 0) {
    return (c == 'o') ? left : (left+1) % 2;
  }

  return (c == 'x') ? left : (left+1) % 2;
}

int arr[100001];
const int dir[4][2] = {{0,0},{0,1},{1,0},{1,1}};

string solve(ll n, string s) {

  for(int x=0; x<4;x++) {
    for(int i=0; i< n; i++) {
      arr[i] = -1;
    }

    arr[0] = dir[x][0];
    arr[1] = dir[x][1];

    for(int i = 2; i < n; ++i) {
      arr[i] = query(arr[i-2], arr[i-1], s[i-1]);
    }

    // check
    if(arr[0] == query(arr[n-2], arr[n-1], s[n-1]) &&
       arr[1] == query(arr[n-1], arr[0],   s[0])) {
      string ret="";
      for(int i=0;i<n;++i) {
        ret += (arr[i]==0)? "S" : "W";
      }
      return ret;
    }
  }
  return "-1";
}
int main() {
  ll n;
  string s;
  cin >> n >> s;
  cout<< solve(n, s)<<endl;
}


Measured memory_bytes: 1152
#[test]
fn test_solve() {
    assert_eq!(solve("2 3 1\n"), "1.0000000000\n");
    assert_eq!(solve("1000000000 180707 0\n"), "0.0001807060\n");
}
fn solve(src: &str) -> String {
    let mut sc = Scanner::from_str(src);

    let n: f64 = sc.read();
    let m: f64 = sc.read();
    let d: f64 = sc.read();

    format!(
        "{:.10}\n",
        if d > 0. {
            (n - d) * 2. / (n * n)
        } else {
            1. / n
        } * (m - 1.)
    )
}
fn main() {
    let mut buf = String::new();
    use std::io::{Read, Write};
    std::io::stdin().read_to_string(&mut buf).unwrap();
    std::io::stdout().write_all(solve(&buf).as_bytes()).unwrap();
}
struct Scanner<'a>(std::str::SplitWhitespace<'a>);
impl<'a> Scanner<'a> {
    fn from_str(src: &str) -> Scanner {
        Scanner(src.split_whitespace())
    }
    fn get(&mut self) -> &str {
        self.0.next().unwrap()
    }
    fn read<T: std::str::FromStr>(&mut self) -> T {
        self.get().parse().ok().unwrap()
    }
}


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

int main(){
  int n,h[1000000],dp[1000000],a,b;
  cin >> n;
  for(int i=0;i<n;i++){
    cin >> h[i];
  }

  dp[0]=0;
  dp[1]=abs(h[0]-h[1]);
  for(int i=2;i<n;i++){
    a=abs(h[i-1]-h[i]);
    b=abs(h[i-2]-h[i]);
    dp[i]=min(a+dp[i-1],b+dp[i-2]);
  }
  cout << dp[n-1] << endl;
}


Measured memory_bytes: 4736
n,m = map(int, input().split())

bridges = []
for i in range(m):
    bridges.append([int(x) for x in input().split()])

def root(par, a):
    while par[a] != -1:
       a = par[a]
    return a 

def unite(par, npar, depth, ra, rb):
    if depth[ra] >= depth[rb]:
        npar[ra] = npar[ra] + npar[rb]
        par[rb] = ra
        if depth[ra] == depth[rb]:
            depth[ra] += 1
    else:
        npar[rb] = npar[rb] + npar[ra]
        par[ra] = rb

par = [-1 for _ in range(n+1)]
npar = [1 for _ in range(n+1)]
depth = [1 for _ in range(n+1)]

ans = []
unconf = n*(n-1)//2
ans.append(unconf)

for x in reversed(bridges):
    a,b = x
    ra = root(par, a)
    rb = root(par, b)
    if ra != rb:
        tmp = npar[ra] * npar[rb]
        unite(par, npar, depth, ra, rb)
        unconf -= tmp
    ans.append(unconf)

ans.reverse()
ans.pop(0)
for x in ans:
    print(x)

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

using namespace std;

int n;

char s[10000];
priority_queue<int>Q;
char ans[10000];
int main()
{
    scanf("%d",&n);
    scanf("%s",s);
    memcpy(ans,s,sizeof(s));
    int cnt=0;
    int k=n;
    for(int i=0;i<n;i++)
    {
        if(s[i]=='(')
        {
            Q.push(i);
            cnt++;
        }
        if(s[i]==')'&&!cnt)
        {
            for(int j=k-1;j>=0;j--)
            {
                ans[j+1]=ans[j];
            }
            k++;
            ans[0]='(';

        }
        if(s[i]==')'&&cnt)
        {
            Q.pop();
            cnt--;
        }
    }
    for(;cnt>0;cnt--)
    {
        ans[strlen(ans)]=')';
    }
    ans[strlen(ans)]='\0';
    printf("%s",ans);
    return 0;
}


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

#define p_yes (cout << "Yes" << endl)
#define p_no (cout << "No" << endl)

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

    int cnt_a = 0;  // 現在予選を通過した人数
    int cnt_o = 0;  // 海外の学生の人数
    for (int i = 0; i < n; i++) {
        char c;
        cin >> c;
        if (c == 'a') {
            if (cnt_a < a + b) {
                cnt_a++;
                p_yes;
            } else {
                p_no;
            }
        } else if (c == 'b') {
            cnt_o++;
            if (cnt_a < a + b && cnt_o <= b) {
                cnt_a++;
                p_yes;
            } else {
                p_no;
            }
        } else {
            p_no;
        }
    }
}

Measured memory_bytes: 640
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<utility>
#include<tuple>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>

using namespace std;

using ll = long long;
using pii = pair<int, int>;

#define bil ((ll)1e9)
#define mod ((ll)1e9+7)

int main(int argc,char* argv[]){
    ll n,k;
    cin >> n >> k;

    ll ans;
    for(int i=0;i<n;i++){
        if(i==0){
            ans=k;
            continue;
        }
        ans*=(k-1);
    }

    cout << ans << endl;

    return 0;
}


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

char S[ 5100 ];
char T[ 5100 ];
vector<string> A;

int main()
{
int i;
int j;
int K;
int iLen;
set<string> X;
char *p;

	ios::sync_with_stdio( false );
	cin.tie( 0 );

	cin >> S;
	cin >> K;

	i = 0;
	while( S[ i ] != '\0' )
	{
		A.push_back( S + i );
		i++;
	}

	iLen = i;
	sort( A.begin(), A.end() );
	for( i = 0; i < iLen; i++ )
	{
		p = (char*) A[ i ].c_str();

		j = 0;
		while( p[ j ] != '\0' )
		{
			j++;
			strcpy( T, p );
			T[ j ] = '\0';
			X.insert( T );
			if( X.size() == K )
			{
				cout << T << endl;

				return 0;
			}
		}
	}

	return 0;
}

Measured memory_bytes: 16128
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<cstring>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<deque>
#include<functional>
#include<algorithm>
#include<cstdio>
#include<ctime>
#include<cmath>
#include<cstdlib>
#include<utility>
#include<bitset>
using namespace std;
const int maxn=200010;
int n,k,cnt[maxn],ans=0;
vector<int> v;
int main()
{
	cin>>n>>k;
	for(int i=0;i<n;i++)
	{
		int x;
		cin>>x;
		cnt[x]++;
	}
	for(int i=1;i<=n;i++)
	{
		if(!cnt[i])
		{
			continue;
		}
		v.push_back(cnt[i]);
	}
	sort(v.begin(),v.end());
	for(int i=0;i<(int)v.size()-k;i++)
	{
		ans+=v[i];
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 2168
#include<bits/stdc++.h>
#define crap ios_base::sync_with_stdio(0);cin.tie(0)
#define ll long long
#define pb push_back
#define ff first
#define ss second
#define endl "\n"
#define int ll

using namespace std;



int32_t main()
{
   
   
    crap;
   
    int x,y,z;
    cin>>x>>y>>z;
    swap(x,y);
    swap(x,z);
    cout<<x<<" "<<y<<" "<<z<<endl;
}

Measured memory_bytes: 256
h,w,m=map(int,input().split())
hh=[[0,i]for i in range(h)]
ww=[[0,i]for i in range(w)]
hw=set()
for _ in range(m):
  a,b=map(int,input().split())
  a-=1
  b-=1
  hh[a][0]+=1
  ww[b][0]+=1
  hw.add((a,b))
ww.sort(reverse=1)
s=ww[0][0]
w=[]
for x,j in ww:
  if x==s:w.append(j)
hh.sort(reverse=1)
ans=0
t=max(hh)[0]
for j in w:
  for x,i in hh:
    if x!=t:break
    if (i,j) in hw:
      ans=s+x-1
    else:
      exit(print(s+x))
print(ans)


Measured memory_bytes: 175636
from heapq import heappush,heappop
from sys import setrecursionlimit
setrecursionlimit(10**6)
N,M,s,t=map(int,input().split())
table=[[] for i in range(N)]
rtable=[[] for i in range(N)]
for i in range(M):
    u,v,a,b=map(int,input().split())
    u,v=u-1,v-1
    table[u].append((a,v))
    table[v].append((a,u))
    rtable[u].append((b,v))
    rtable[v].append((b,u))
mod=pow(10,15)
def dijk(s,table):
    dij=[]
    heappush(dij,(0,s))
    val=[mod]*N
    val[s]=0
    while len(dij)>0:
        q,x=heappop(dij)
        if val[x]<q:
            continue
        for d,y in table[x]:
            if val[y]>val[x]+d:
                val[y]=val[x]+d
                heappush(dij,(val[y],y))
    return val
val=dijk(s-1,table)
rval=dijk(t-1,rtable)
score=[0]*N
for i in range(N):
    score[i]=mod-(val[i]+rval[i])
amax=[mod]*N
amax[-1]=score[-1]
for i in range(N-2,-1,-1):
    amax[i]=max(amax[i+1],score[i])
for i in range(N):
    print(amax[i])

Measured memory_bytes: 81064
import java.util.Scanner;

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

	public static void solve() {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		sc.close();

		double result = 0;
		int time = 100 * (n - m) + 1900 * m;
		double correctProb = Math.pow(0.5, m);
		for (int i = 0; i < 100000; i++) {
			result += time * (i + 1) * correctProb * Math.pow((1 - correctProb), i);
		}
		System.out.println((int)Math.round(result));
	}
}


Measured memory_bytes: 23764
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long a[] = new long[n];
        long b[] = new long[n];
        for (int i = 0; i <= n - 1; i++) {
            a[i] = sc.nextLong();
        }

        List<Long> resultList = new ArrayList();
        boolean minusFlg = false;
        for(int i = n - 1; i>=0; i--) {
            long temp = i + 1;
            int cnt = 0;
            int step = i+1;
            for(int j=i+step; j<n; j+=step) {
                if(b[j]==1) cnt++;
            }

            if (a[i] == 0) {
                if (cnt % 2L != 0l) {
                    b[i]=1;
                    resultList.add(temp);
                };
            } else {
                if (cnt % 2L == 0l) {
                    b[i]=1;
                    resultList.add(temp);
                };
            }
        }
        if(minusFlg) {
            System.out.print(-1);
        } else if (resultList.isEmpty()) {
            System.out.print(0);
        } else {
            System.out.println(resultList.size());
            resultList.stream().sorted().forEach(r-> System.out.print(r + " "));
        }
    }
}


Measured memory_bytes: 66588
#include <iostream>
#include <string>
#include <math.h>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;
typedef long long cc;

cc N, K, i, j, k, a[500000], sub = 0, n = 0;
cc judge = 0, Ans[500000], J[500000];

string S;


int main() {
	
	cin >> N;
	for (i = 1; i <= N; i++) {
		cin >> a[i];
		J[i] = 0;
	}
	for (i = 0; i < N; i++) {
		if (a[N - i] == 1) {
			for (j = 2; j <= N; j++) {
				if ((N - i)*j > N) 
					break;
				judge += J[(N - i)*j];
			}
			if (judge%2==0) {
				Ans[n] = N - i;
				n += 1;
				J[N - i] = 1;
			}
		}
		else{
			for (j = 2; j <= N; j++) {
				if ((N - i)*j > N)
					break;
				judge += J[(N - i)*j];
			}
			if (judge % 2 == 1) {
				Ans[n] = N - i;
				n += 1;
				J[N - i] = 1;
			}
		}
      judge=0;
	}
			cout << n << endl;
			for (i = 0; i < n; i++)
				cout << Ans[i] << " ";
		cout << endl;

	return 0;
}


Measured memory_bytes: 10624
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define MAX ((int)(1e7))
#define pi (2*acos(0))
#define mp make_pair
#define M ((int)(1e9 + 7))
#define xx first
#define yy second
#define NN ((int)(5e5+2))
#define N ((int)(1e5 + 5))
#define pq priority_queue
///#define Q queue
#define eps 0
#define log 20
#define pb push_back
#define MOD 998244353


using namespace std;
using namespace __gnu_pbds;

typedef long long int ll;
typedef unsigned long long int lu;

typedef tree < int ,  null_type ,  less < int > ,  rb_tree_tag ,  tree_order_statistics_node_update > o_set;

int main()
{
    int n, a, b;
    scanf("%d %d %d",&n,&a,&b);
    if((b-a-1)%2==1) printf("Alice\n");
    else printf("Borys\n");
    return 0;
}


Measured memory_bytes: 256
a,b = map(float,input().split())
b = round(b,2)
c = b - b // 1
c = round(c,2)
b = int(b)
#print(b,c)
c *= 100
#print(format(c, '.20f'))
a = round(a,0)
a =int(a)
#print(a,b)
ans = a * b
p = 0
c = int(c)
for i in range(c):
    p += a
#print(p)
ans += round(a * c // 100 ,3)
#print(format(c*a, '.20f'))
ans = int(ans)
print(ans)

Measured memory_bytes: 9148
s=gets.chomp
cnt=Hash.new(0)
s.each_char do |c|
  cnt[c] += 1
end
flag = true
cnt.keys.each do |key|
  if cnt[key] != 2
    flag = false
    break
  end
end
puts (cnt.keys.size == 2 && flag) ? 'Yes' : 'No'

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

using namespace std;
using ll = long long;

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

  int n;
  string s;
  cin >> n >> s;

  vector<int> v;
  string ans = s;
  int l = 0;
  for (auto c : s) {
    if (c == '(') {
      l++;
      continue;
    }
    if (l == 0) {
      ans = "(" + ans;
    } else {
      l--;
    }
  }
  if (l > 0)
    ans += string(l, ')');

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long 
#define inf 0x3f3f3f3f
#define infll 0x3f3f3f3f3f3f3f3f
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define ii pair<int,int>
#define vii vector<ii>
#define vi vector<int>

#define F_OR(i, a, b, s) for (int i=(a); (s)>0?i<(b):i>(b); i+=(s))
#define F_OR1(e) F_OR(i, 0, e, 1)
#define F_OR2(i, e) F_OR(i, 0, e, 1)
#define F_OR3(i, b, e) F_OR(i, b, e, 1)
#define F_OR4(i, b, e, s) F_OR(i, b, e, s)
#define GET5(a, b, c, d, e, ...) e
#define F_ORC(...) GET5(__VA_ARGS__, F_OR4, F_OR3, F_OR2, F_OR1)
#define FOR(...) F_ORC(__VA_ARGS__)(__VA_ARGS__)
#define EACH(x, a) for (auto& x: a)
 
// debug templates 
#define debug(x)       cerr<< #x <<" : "<< x << endl;
#define debuga(A,N)    cerr<< #A <<" : [";for(int i = 0; i<N;i++) cerr<<A[i]<<" "; cerr<<"]\n";
#define debuga2(A,N,M) cerr<< #A << " : \n"; for(int i=0;i<N;i++){cerr<<"[";for(int j=0;j<M;++j) cerr<<A[i][j]<<" ";cerr<<"]\n";}
#define debugp(p)      cerr<< #p <<" : "<<"("<<(p).first<<","<<(p).second<<")\n";
#define debugv(v)      cerr<< #v <<" : "<<"[";for(int i = 0; i< (v).size(); i++) cerr<<v[i]<<" "; cerr<<"]\n";
#define debugv2(v)     cerr<< #v << " : \n"; for(int i=0;i<v.size();i++){cerr<<"[";for(int j=0;j<(v[0].size());++j) cerr<<v[i][j]<<" ";cerr<<"]\n";}
#define debugs(m)      cerr<< #m <<" : [ "; for(auto itr = m.begin(); itr!=m.end();itr++) cerr<<*itr<<" "; cerr<<"]\n";
#define debugm(m)      cerr<< #m <<" : [ "; for(auto itr = m.begin();itr!=m.end(); itr++) cerr<<"("<<itr->first<<","<<itr->second<<") ";cerr<<"]\n";
 

void solve(){
	int n; cin >> n;
	// name, -val, idx
	set<pair<string,pair<int,int>>> s;
	FOR(i,1,n+1){
		string name; int val;
		cin >> name >> val;
		s.insert({name,{-val,i}});
	}
	for(auto xx : s) cout << xx.second.second << '\n';
}
 
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	solve();
	return 0;
}
 


Measured memory_bytes: 3596
import java.util.*;

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

        int N = sc.nextInt();
        Map<Integer, Integer> map1 = new TreeMap<>();
        Map<Integer, Integer> map2 = new TreeMap<>();
        for(int i = 0; i < N; i++){
            map1.put(sc.nextInt(), sc.nextInt());
        }
        for(int i = 0; i < N; i++){
            map2.put(sc.nextInt(), sc.nextInt());
        }
        sc.close();

        int[][] a1 = new int[2][N];
        int[][] c1 = new int[2][N];
        int i = 0;
        for(Integer key: map1.keySet()){
            a1[0][i] = key;
            a1[1][i] = map1.get(key);
            i++;
        }
        int j = 0;
        for(Integer key: map2.keySet()){
            c1[0][j] = key;
            c1[1][j] = map2.get(key);
            j++;
        }
        
        Map<Integer, Integer> map3 = new TreeMap<>();
        Map<Integer, Integer> map4 = new TreeMap<>();
        for(Integer key: map1.keySet()){
            map3.put(map1.get(key), key);
        }
        for(Integer key: map2.keySet()){
            map4.put(map2.get(key), key);
        }
        int[][] a2 = new int[2][N];
        int[][] c2 = new int[2][N];
        i = 0; 
        j = 0;
        for(Integer key: map3.keySet()){
            a2[0][i] = map3.get(key);
            a2[1][i] = key;
            i++;
        }
        for(Integer key: map4.keySet()){
            c2[0][j] = map4.get(key);
            c2[1][j] = key;
            j++;
        }

        int count1 = 0;
        loop1: for(int k = N-1; k >= 0; k--){
            for(int l = 0; l < N; l++){
                if(a1[0][k] < c2[0][l]){
                    if(a1[1][k] < c2[1][l]) {
                        count1++;
                        //System.out.println("(" + a1[0][k] + "," + a1[1][k] + "), (" + c1[0][l] + "," + c1[1][l] + ")");
                        c2[0][l] = -1;
                        continue loop1;
                    }
                }
            }
        }
        int count2 = 0;
        loop2: for(int k = N-1; k >= 0; k--){
            for(int l = 0; l < N; l++){
                if(a2[1][k] < c1[1][l]){
                    if(a2[0][k] < c1[0][l]) {
                        count2++;
                        //System.out.println("(" + a2[0][k] + "," + a2[1][k] + "), (" + c2[0][l] + "," + c2[1][l] + ")");
                        c1[1][l] = -1;
                        continue loop2;
                    }
                }
            }
        }
        System.out.println(Math.max(count1, count2));
    }
}

Measured memory_bytes: 22228
#include <bits/stdc++.h>
#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++)
using namespace std;
using P = pair<int, int>; 
using ll = long long;

int main()
{
  int n;
  cin >> n;
  n %= 10;
  if (n == 3) {
    cout << "bon" << endl;
  }
  else if(n == 0 || n == 1|| n == 6 || n == 8){
    cout << "pon" << endl;
  }
  else {
    cout << "hon" << endl;
  }
  return 0;
}


Measured memory_bytes: 3540
function Main(input) {
  input = input.split("\n");
  var N = parseInt(input[0].split(" ")[0]);
  var M = parseInt(input[0].split(" ")[1]);
  C=new Array(M);
  P=new Array(0);
  for(i=0;i<M;i++){
    tmp=input[i+1].split(" ");
    Csub=[parseInt(tmp[0]),parseInt(tmp[1]),i];
    C[i]=Csub;
  }
  C.sort(function(a, b) {
		if (a[0] < b[0]) return -1;
		if (a[0] > b[0]) return 1;
		if (a[1] < b[1]) return -1;
		if (a[1] > b[1]) return 1;
		return 0;
	});
  for(i=0;i<M;i++){
    var y="";
    c=`00000${C[i][0]}`.slice(-6);
    if(i==0){
      var cnt=1;
    }else if(C[i][0]!=C[i-1][0]){
      cnt=1;
    }else{
      cnt++;
    }
    y=`00000${cnt}`.slice(-6);
    P.push([`${c}${y}`,C[i][2]]);
  }
  P.sort(function(a,b){return a[1]-b[1]});
  var ans="";
  for(i=0;i<M;i++){
    if(i!=M-1){
      ans=ans+P[i][0]+"\n";
    }else{
      ans=ans+P[i][0];
    }
  }


  console.log('%s', ans);
}
  
// "実行する"ボタンを押した時に実行される関数 (デバッグ用)
function debug(){
  var input = document.getElementById("input").value;
  Main(input);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 82800
<?php

fscanf(STDIN, "%d", $n);
$X = []; $Y = []; $H = [];
for ($i = 0; $i < $n; ++$i) {
    fscanf(STDIN, "%d %d %d", $x, $y, $h);
    $X[] = $x; $Y[] = $y; $H[] = $h;
}

$ans;
for ($cx = 0; $cx <= 100; ++$cx) {
    for ($cy = 0; $cy <= 100; ++$cy) {
        $ch = [];
        for ($i = 0; $i < $n; ++$i) {
            $ch[] = abs($X[$i] - $cx) + abs($Y[$i] - $cy) + $H[$i];
        }

        $ch = array_unique($ch);
        foreach ($ch as $h) {
            $flg = true;
            for ($i = 0; $i < $n; ++$i) {
                if ($H[$i] !== max($h - abs($X[$i] - $cx) - abs($Y[$i] - $cy), 0)) {
                    $flg = false;
                    break;
                }
            }

            if ($flg) {
                $ans = $h;
                break 3;
            }
        }
    }
}

echo "$cx $cy $ans", PHP_EOL;


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


typedef long long ll;
vector<int> get_id(int h, int i) {
  vector<int> ret(h);
  int id = 0;
  ret[0] = id;
  for (int j = 0; j < h-1; ++j) { 
    int mask = 1<<j;
    if (mask&i) ++id;
    ret[j+1] = id;
  }
  return ret;
}

int main() {
  int h, w, K;
  cin >> h >> w >> K;
  vector<string> grid;
  for (int i = 0; i < h; ++i) {
    string s; cin >> s;
    grid.push_back(s);
  }
  int ans = h*w;
  for (int i = 0; i < (1<<(h-1)); ++i) {
    vector<int> choco(h);
    vector<int> ids = get_id(h, i);
    int ok1 = true;
    for (int k = 0; k < h; ++k) {
      if (grid[k][0] == '0') continue;
      ++choco[ids[k]];
      if (choco[ids[k]] > K) {
        ok1 = false;
        break;
      }
    }
    if (!ok1) continue;
    int cnt = ids[h-1];
    for (int j = 1; j < w; ++j) {
      vector<int> lc(h);
      bool ok = true;
      for (int k = 0; k < h; ++k) {
        if (grid[k][j] == '0') continue;
        ++lc[ids[k]];
        if (lc[ids[k]] > K) { ok = false; break; }
      }
      // for (int k = 0; k < h; ++k) {
      //   cerr << i << " " << j << " " << k << " " << lc[k] << endl;
      // }
      if (ok) {
        bool ok2 = true;
        for (int k = 0; k < h; ++k) {
          if (lc[k]+choco[k] > K) { 
            ok2 = false;
            break;
          }
        }
        if (ok2) {
          for (int k = 0; k < h; ++k) {
            choco[k] += lc[k];
          }
        }
        else {
          ++cnt;
          // cerr << "[c]" << i << " " << j <<  " " << cnt << endl;
          choco = lc;
        }
      }
      else {
        ok1 = false;
        break;
      }
    }
    if (ok1) {
      // cerr << i << " " << cnt << endl;
      ans = min(ans, cnt);
    }
    // cout << i << ":";
    // for (int id : ids) {
    //   cout << id << " ";
    // }
    // cout << endl;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
//BROWNIE TK

#include <bits/stdc++.h>
typedef long long int lli;
typedef unsigned long long int ulli;
typedef long double ldb;

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define pb push_back
#define popb pop_back()
#define pf push_front
#define popf pop_front()
#define si size()
#define be begin()
#define en end()
#define all(v) v.be, v.en
#define le length()
#define mp make_pair
#define mt make_tuple
#define acc(v) accumulate(all(v), 0)
#define F first
#define S second

#define forz(i, n) for (int i = 0; i < n; i++)
#define fore(i, m, n) for (int i = m; i <= n; i++)
#define rforz(i, n) for (int i = n - 1; i >= 0; i--)
#define rforzm(i, m, n) for (int i = n - 1; i >= m; i--)
#define deci(n) fixed << setprecision(n)
#define high(n) __builtin_popcount(n)
#define highll(n) __builtin_popcountll(n)
#define parity(n) __builtin_parity(n)
#define ctz(n) __builtin_ctz(n)
#define lb lower_bound
#define ub upper_bound
#define er equal_range
#define maxe *max_element
#define mine *min_element
#define mod 1000000007
#define mod2 998244353
#define gcd __gcd
#define kira ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)

#define endl "\n"
#define p0(a) cout << a << " "
#define p1(a) cout << a << endl
#define p2(a, b) cout << a << " " << b << endl
#define p3(a, b, c) cout << a << " " << b << " " << c << endl
#define p4(a, b, c, d) cout << a << " " << b << " " << c << " " << d << endl

#define oset tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define osetlli tree<lli, null_type, less<lli>, rb_tree_tag, tree_order_statistics_node_update>
//member functions :
//1. order_of_key(k) : number of elements strictly lesser than k
//2. find_by_order(k) : k-th element in the set
#define ofk order_of_key
#define fbo find_by_order
using namespace std;

/*STD fucntions*/
lli power(lli x, lli y, lli p)
{
    lli res = 1;
    x = x % p;
    while (y > 0)
    {
        if (y & 1)
            res = (res * x) % p;
        //y must be even now
        y = y >> 1; //y=y/2
        x = (x * x) % p;
    }
    return res;
}
lli modi(lli a, lli m)
{
    // fermat little thm where m is prime
    return power(a, m - 2, m);
}
/*CODE BEGINS*/
int main()
{
    kira;
    lli r;
    cin>>r;
    cout<<r*r;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define RREP(i,m,n) for(int i=int(n)-1;i>=int(m);--i)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long int;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;

//struct edge {int from, to, cost;};

constexpr double EPS = 1e-10;
//constexpr double PI  = acos(-1.0);
//constexpr int INF = INT_MAX;
constexpr int MOD = 1'000'000'007;
//inline void modAdd(LL &l, LL &r) {l = (l + r) % MOD;}

template<class T> inline T sqr(T x) {return x*x;}

void solve() {
    int a,b;
    cin >> a >> b;
    cout << max({a+b,a-b,a*b}) << endl;
}

int main() {
    solve();
    
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <string>
 
using namespace std;
typedef long long LL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
 
int main(){
  int a,b;
  scanf("%d%d", &a, &b);
  int ret = 1/2. * (a*a + b*b - 2*a*b - a - b);
  printf("%d\n", ret);
  return 0;
}

Measured memory_bytes: 128
// 失敗するからこそ そこから立ち向かって行く強さがあってそんな強さが本当の強さだと私は思うから
// ぜったいあきらめない
#if defined(DAIJOBU)
#include "/home/ichigo/includes.hpp"
#include "/home/ichigo/debug.hpp"
#define deb(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#include <bits/stdc++.h>
#define deb(x...)
#endif
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long lint;
typedef vector<lint> vlint;
typedef vector<vlint> vvlint;
typedef pair<lint, lint> plint;
typedef double ld;

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



int main() {
    ios::sync_with_stdio(false);
	cin.tie(0);
	
	int n, m;
	cin >> n >> m;
	vvi v;
	forn(i, n){
		vi x(m);
		forn(j, m)cin >> x[j];
		v.pb(x);
	}
	int ans = 0;
	forn(i, n){
		fore(j, i + 1, n - 1){
			vi x = v[i], y = v[j];
			int sum = 0;
			forn(i, x.size())sum += (x[i] - y[i]) * (x[i] - y[i]);
			int A  = sqrt(sum);
			if(A * A == sum)ans++;
		}
	}
	cout << ans << '\n';
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    int a,b,c;
    cin >> a>>b>>c;
    
    if(a>b) swap(a,b);
    if (b>c) swap(b,c);
    if (a>b) swap(a,b);
    
    cout << a <<" " << b<< " "<<c<<endl;
    
}


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

int main() {
    vector<int> index;
	string s;
	int count=0;
	cin>>s;
	for(int i=0; i<3; ++i) {
	    if(s[i]=='R') {
	        index.push_back(i);
	        ++count;
	    }
	}
	for(int i=1; i<index.size(); ++i) {
	    if( (index[i]-1)%3 != index[i-1] ) {
	        --count;
	    }
	}
	cout<<count;
	return 0;
}

Measured memory_bytes: 3628
#include <iostream>

#include <vector>

using namespace std;

#define REP(i, n) for (int i = 0; i < n; ++i)

int main() {
	int n, k, m;
	cin >> n >> k >> m;
	vector<vector<int>> dp(2 * n + 1, vector<int>(1 << k, 0));
	dp[0][0] = 1;
	REP(i, 2 * n) {
		REP(j, 1 << k) {
			int b = __builtin_popcount(j);
			int pos = (i + b) / 2;
			if (b == k) continue;
			if ((j & (1 << (k - 1))) == 0) {
				int next = (j << 1) + 1;

				dp[i + 1][next] += dp[i][j];
				dp[i + 1][next] %= m;
			}
			if (b > 0) {
				int next = j;
				for (int a = k - 1; a >= 0; --a) {
					if (j & (1 << a)) {
						next ^= (1 << a);
						break;
					}
				}
				next <<= 1;
				dp[i + 1][next] += dp[i][j];
				dp[i + 1][next] %= m;
			}
		}
	}

	int ans = dp[2 * n][0];
	if (n == k) ans++;
	if (ans == m) ans = 0;
	cout << ans << endl;
}



Measured memory_bytes: 3656
/*
ID: Aman Raj
LANG: C++
TASK: preface
*/
#include<iostream>
#include <stdio.h>
//#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
#include<math.h>
typedef  long long int ll;
#include <bits/stdc++.h>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <iomanip>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
//setbase - cout << setbase (16); cout << 100 << endl; Prints 64
//setfill -   cout << setfill ('x') << setw (5); cout << 77 << endl; prints xxx77
//setprecision - cout << setprecision (14) << f << endl; Prints x.xxxx
//cout.precision(x)  cout<<fixed<<val;  // prints x digits after decimal in val

using namespace std;
using namespace __gnu_pbds;

#define f(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) f(i,0,n)
#define fd(i,a,b) for(i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define vi vector< int >
#define vl vector< ll >
#define ss second
#define ff first
//#define ll long long
#define pii pair< int,int >
#define pll pair< ll,ll >
#define sz(a) a.size()
#define inf (1000*1000*1000+5)
#define all(a) a.begin(),a.end()
#define tri pair<int,pii>
#define vii vector<pii>
#define vll vector<pll>
#define viii vector<tri>
#define mod (1000*1000*1000+7)
#define pqueue priority_queue< int >
#define pdqueue priority_queue< int,vi ,greater< int > >
//#define flush fflush(stdout)
#define primeDEN 727999983
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#include <fstream>
// find_by_order()  // order_of_key
typedef tree<
	int,
	null_type,
	less<int>,
	rb_tree_tag,
	tree_order_statistics_node_update>
	ordered_set;

	   //vector<ll > vten(7),vfive(7),vfifty(7),vhundred(7),vfivehundred(7),vthousand(7);
	  ll ans=0;
	  //ll c;
	  vector<ll> dp;
	  vector<vector<ll> > v,v2;
	   ll aman(ll i,ll c)
	   {  if(dp[i]==-1)
	       {ll c=0;
	       // visited[i]=1;
	         ll b=0;
	        for(ll j=0;j<v[i].size();j++)
            {  c=1;ll a=v[i][j];
               b=max(b, aman(a,c));

            } dp[i]=c+b;ans=max(ans,dp[i]);
             }

            return dp[i];

	   }
  int main()
 {
      ifstream fin("tcase.txt");

       ll n,m;cin>>n>>m;
          v.resize(n);v2.resize(n);
          //vector<ll>dp(n,0);
          dp.resize(n,-1);
            for(ll i=0;i<m;i++)
            {
                ll a,b;cin>>a>>b;a--;b--;v2[b].push_back(a);v[a].push_back(b);
            }
            for(ll i=0;i<n;i++)
            {
                if(v2[i].size()==0)
                {  ll c=0;
                    //vector<ll> visited(n,0);
                    ll b=0;
                     for(ll j=0;j<v[i].size();j++)
                   {  c=1; ll a=v[i][j];
                      b=max(b,  aman(a,c));

                      }
                      dp[i]=b+c;
                      ans=max(ans,dp[i]);

                }
            }
            cout<<ans;



	return 0;
 }




Measured memory_bytes: 16640
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int l = sc.nextInt();
    int[] aji = new int[n];
    int abs = 2000;
    int total = 0;
    int p = -1;
    for(int i = 0;i<n;i++){
      aji[i] = l + i;
      total += aji[i];
      if(abs>Math.abs(aji[i])){
        p = i;
        abs = Math.abs(aji[i]);
      }
    }
    System.out.println(total-aji[p]);
  }
}


Measured memory_bytes: 35852
#include"bits/stdc++.h"
using namespace std;

const int INF = 1e9;

struct edge {
  int to;
  int cost;
};
vector<edge> G[100001];
vector<int> d(100001, INF);

bool exist = true;

void dfs(int x) {
  for (edge e: G[x]) {
    if (d[e.to] == INF) {
      d[e.to] = d[x] + e.cost;
      dfs(e.to);
    } else if (d[e.to] != d[x] + e.cost) {
      exist = false;
      return;
    }
  }
}

void Main() {
  int N, M;
  cin >> N >> M;

  for (int i = 0 ; i < M; i++) {
    int L, R, D;
    cin >> L >> R >> D;
    G[L - 1].push_back({ R - 1, D });
    G[R - 1].push_back({ L - 1, -D });
  }

  for (int i = 0; i < N; i++) {
    if (d[i] == INF) {
      d[i] = 0;
      dfs(i);
    }
  }

  if (exist) cout << "Yes" << endl;
  else cout << "No" << endl;
}

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  Main();
  return 0;
}



Measured memory_bytes: 11008
n = gets.chomp.to_i
house = Array.new(4).map{ Array.new(3).map{ Array.new(10,0)} }

n.times do
    b,f,r,v = gets.chomp.split(" ").map{|item| item.to_i}
    house[b-1][f-1][r-1]+=v
end

4.times do |b|
    if b!=0 then
        print("#"*20+"\n")
    end
    3.times do |f|
        10.times do |r|
            print(" ",house[b][f][r])
        end
        puts
    end
end

Measured memory_bytes: 8816
// C.cpp
#include <bits/stdc++.h>

using namespace std;

const int MAX_N = 3e6 + 200, mod = 998244353;

int fac[MAX_N], fac_inv[MAX_N], inv[MAX_N];

void preprocess()
{
	for (int i = fac[0] = 1; i < MAX_N; i++)
		fac[i] = 1LL * fac[i - 1] * i % mod;
	inv[0] = inv[1] = fac_inv[0] = 1;
	for (int i = 2; i < MAX_N; i++)
		inv[i] = 1LL * (mod - mod / i) * inv[mod % i] % mod;
	for (int i = 1; i < MAX_N; i++)
		fac_inv[i] = 1LL * fac_inv[i - 1] * inv[i] % mod;
}

int binomial(int n_, int k_) { return (n_ < k_) ? 0 : 1LL * fac[n_] * fac_inv[k_] % mod * fac_inv[n_ - k_] % mod; }

int calc(int n, int m, int o)
{
	int ret = 0;
	for (int i = 0; i <= o; i++)
		if (i % 2 == m % 2)
			ret = (0LL + ret + 1LL * binomial((m - i) / 2 + n - 1, n - 1) * binomial(n, i) % mod) % mod;
	return ret;
}

int main()
{
	int n, m;
	preprocess(), scanf("%d%d", &n, &m);
	printf("%lld\n", (0LL + calc(n, 3 * m, m) + mod - 1LL * n * calc(n, m - 1, m) % mod) % mod);
	return 0;
}

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

int main()
{
	int N, M;
	int a[51] = { 0 };

	cin >> N >> M;

	int n, m;
	for (int i = 1; i <= M; i++)
	{
		cin >> n >> m;
		a[n]++;
		a[m]++;
	}

	for (int i = 1; i <= N; i++)
	{
		cout << a[i] << endl;
	}

	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
 
  int X, N;
  cin >> X >> N;
  
  vector<int> P(N);
  vector<int> Q(N);
    
  for(int i=0; i < N ; i++){
  	cin >> P[i];
  }
  
  Q = P;
  
  if(N == 0){
  cout << X << endl;
  }
  else{
  for(int i=0; i < N ; i++){
  	Q[i]=abs(Q[i]-X);
  }
  		
  int M = *max_element(Q.begin(),  Q.end());
  
   for(int i=0; i<M+1 ; i++){
     
     auto F1 = find(P.begin(), P.end(), X-i);
     auto F2 = find(P.begin(), P.end(), X+i);
     
     if(F1 == P.end() ){
       X -= i;
    	break;
    } 
     
     else if(F2 == P.end()){
     	X += i;
        break;
     }
     
     if(i == M){
     	X -= (M+1);
     }
   }
  
  cout << X << endl;
  }
}

Measured memory_bytes: 3600
#include <stdio.h>
int main(void){
	char a[4];
	scanf("%s",a);
	int i;
	for(i=0;i<3;i++){
		if(a[i]=='1') a[i]='9';
		else if(a[i]=='9') a[i]='1';
	}
	printf("%c%c%c",a[0],a[1],a[2]);
	return 0;
}

Measured memory_bytes: 128
#include<stdio.h>
#include<stdlib.h>
 
 
int A[2000002],B[2000002];
int C[10001];
int n;
void Counting_Sort(int A[], int B[], int n);
 
int main(){
  int i;
  scanf("%d",&n);
  for(i=1;i<=n;i++){
 
    scanf("%d",&A[i]);
 
}
  Counting_Sort(A, B, 10000);
 
  for(i=1;i<n;i++){
    printf("%d ",B[i]);
}
  printf("%d\n",B[n]);
 
  return 0;
}
 
 
void Counting_Sort(int A[],int B[],int k){
  int i,j;
  for(i=0;i<=k;i++){
    C[i]=0;
  }
 
  for(j=1;j<=n;j++){
    C[A[j]]++;
  }
 for(i=1;i<=k;i++){
    C[i] =C[i]+ C[i-1];
  }
  
 for(j=n;j>=0;j--){
   B[C[A[j]]] = A[j];
   C[A[j]] = C[A[j]] -1;
 }
 
 return;
}

Measured memory_bytes: 16264
#include <bits/stdc++.h>
#define INF 5000000000000000000
#define ll long long
#define pll pair<ll, ll>
using namespace std;

int main()
{
  ll s, w;
  cin >> s >> w;
  if (w >= s) {
    cout << "unsafe" << endl;
  }
  else {
    cout << "safe" << endl;
  }
}


Measured memory_bytes: 3632
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate, product # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
s = input()
c = False
f = False
i = 0
while i < len(s):
    if s[i] == 'C':
        c = True
    elif s[i] == 'F' and c:
        f = True
        break
    i += 1
if f:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 10180
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
 
#整数input
def ii(): return int(sys.stdin.readline().rstrip()) #int(input())
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) #list(map(int,input().split()))
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]
#文字列input
def ss(): return sys.stdin.readline().rstrip() #input()
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) #list(input().split())
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]

#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？

a,b,c=mii()
if a==b and a==c and a%2==0:
    print("-1")
    exit()

if a%2==1 or b%2==1 or c%2==1:
    print(0)
    exit()

cnt=0
chk=True
while chk:
    a,b,c=b//2+c//2,a//2+c//2,b//2+a//2
    cnt+=1
    if a%2==0 and b%2==0 and c%2==0:
        pass
    else:
        chk=False

print(cnt)

Measured memory_bytes: 63596
use proconio::{input, fastout};
use std::collections::{HashMap, BTreeMap};

#[fastout]
fn main() {
    input! {
        _n: usize,
        m: usize,
        py: [(usize, usize); m],
    }

    let mut nums = vec![None; m];

    let mut prefectures = HashMap::new();
    
    for (i, (p, y)) in py.into_iter().enumerate() {
        prefectures.entry(p).or_insert_with(|| BTreeMap::new()).insert(y, i);
    }

    for (prefecture, cities) in prefectures {
        for (i, (_year, order)) in cities.into_iter().enumerate() {
            nums[order] = Some(format!("{:06}{:06}", prefecture, i+1));
        }
    }

    for num in nums {
        if let Some(num) = num {
            println!("{}", num);
        } else {
            unreachable!();
        }
    }
}


Measured memory_bytes: 31776
#include <iostream>
#include <cstring>
using namespace std;
int main(int argc, char *argv[])
{
	char s[105];
	long long k;
	int n=0;
	scanf("%s%lld",s,&k);
	for(int i=0;i<k;i++)
	{
		if(s[i]-'0'>1){printf("%c\n",s[i]);n=1;break;}
	}
	if(n==0)printf("1\n");
	return 0;
}

Measured memory_bytes: 256