akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
 
int main() {
  char ch[250]={0};
  char a[250] ={0};
  int h;
  int i,j,k,l,n,m;
 
 
  while(1){
    i=0;
    while(1){
       
      scanf("%c",&ch[i]);
      if(ch[i] == '\n') {    
    break;
      }
       
      i++;
    }
    
    if ( i == 1 && ch[0] == '-' ) break;
 
    //  printf("%d",i);
     
    scanf("%d",&m);
     
    for(j=0;j<m;j++){
      scanf("%d", &h );
       
      for(k=0;k<i-h;k++) {
    a[k] = ch[h+k];
    //    printf("a[%d] = ch[%d]の%c\n",k ,h+k,ch[h+k]);
      }
      for(k=0;k<h;k++){
    a[i-h+k] = ch[k];
    //   printf("a[%d] = ch[%d]の%c\n",i-h+k,k,ch[k]);
      }
      for(k=0; k<i; k++){
    ch[k] = a[k];
    // printf("ch[%d] = a[%d]の%c\n",k,k,a[k]);
      }
    }
    for(k=0;k<i;k++) {
      printf("%c",ch[k]);
    }
    printf("\n");
      scanf("%c",&ch[0]);
  }
   
   
  return 0;
   
}



Measured memory_bytes: 2144
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<map>
#include<string>

using namespace std;

#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define repn(i, n) for(int (i) = 1; (i) <= (n); (i)++)
#define repr(i, n) for(int (i) = (n-1); (i) >= 0; (i)--)
#define all(x) (x).begin(), (x).end()
#define lint long long


int main(){
    string s; cin >> s; int res = 0;
    rep(i, 4){
        if(s[i] == '+') res++;
        else res--;
    }
    cout << res << endl;
}

Measured memory_bytes: 888
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
 
const double EPS = 1e-10;
const ll INF = 100000000;
const ll MOD = 1000000007;

ll n, m, a, b, p, q;
ll X[41];
ll nX;
ll x[(1<<21)], y[(1<<21)];
ll nx, ny;

int main() {
    cin >> n >> m >> a >> b >> p >> q;
    if (a == 1 && b == 1) {
        if ((p+q) <= m/n) cout << m - n*(p+q) << endl;
        else cout << min(m % (p+q), p+q - m%(p+q)) << endl;
        return 0;
    }
    {
        ll pre = p, pos = q;
        rep(i,n) {
            X[i] = pre + pos;
            nX++;
            if (pre + pos >= m) {
                break;
            }
            pre *= a; pos *= b;
        }
    }
    nx = nX/2;
    ny = nX - nx;
    rep(i,(1<<nx)) {
        ll pos = 0;
        rep(j,nx) {
            if (i&(1<<j)) pos += X[j];
            if (pos > m) break;
        }
        x[i] = pos;
    }
    rep(i,(1<<ny)) {
        ll pos = 0;
        rep(j,ny) {
            if (i&(1<<j)) pos += X[nx+j];
            if (pos > m) break;
        }
        y[i] = pos;
    }
    sort(x, x+(1<<nx));
    sort(y, y+(1<<ny));
    ll ans = INF*INF;
    rep(i,(1<<nx)) {
        int p = lower_bound(y, y+(1<<ny), m-x[i]) - y;
        ans = min(ans, abs(y[p]+x[i]-m));
        if (p != 0) ans = min(ans, abs(y[p-1]+x[i]-m));
    }
    cout << ans << endl;
}




Measured memory_bytes: 27588
#include <iostream>
#include <cmath>

using namespace std;

int main() {
	int hyou[102];
	for (int i = 0; i < 102; i++) {
		hyou[i] = i*i*i;
	}
	int e;
	while (cin >> e) {
		if (e == 0) {
			break;
		}
		int a, b, c;
		for (int i = 1; ; i++) {
			if (hyou[i] > e) {
				c = i-1;
				break;
			}
		}
		for (int i = 1; ;i++) {
			if (i*i > e-hyou[c]) {
				b = i-1;
				break;
			}
		}
		for (int i = 1; ;i++) {
			if (i > e-hyou[c]-b*b) {
				a = i-1;
				break;
			}
		}
		int MIN = a+b+c;
		for (int i = c-1; i >= 0; i--) {
			for (int j = b+1; ; j++) {
				if (j*j > e-hyou[i]) {
					b = j-1;
					break;
				}
			}
			int q = e-hyou[i]-b*b;
			MIN = min(MIN, b+q+i);
		}
		cout << MIN << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7

a, b, k = MAP()
for _ in range(k // 2):
    if a % 2 == 1:
        a -= 1
    b += a // 2
    a //= 2
    if b % 2 == 1:
        b -= 1
    a += b // 2
    b //= 2
if k % 2 == 1:
    if a % 2 == 1:
        a -= 1
    b += a // 2
    a //= 2
print(a, b)

Measured memory_bytes: 5176
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		double a;
		double b;
		double x;
		Scanner sc = new Scanner(System.in);
		a = sc.nextDouble();
		b = sc.nextDouble();
		x = (a + b) / 2;
		x = Math.ceil(x);
		System.out.println((int)x);
		sc.close();
	}

}


Measured memory_bytes: 24916
#include <iostream>
using namespace std;
int a[10000];
int main()
{
	int i,n;
	long long sum=0;
	cin >> n;
	for(i=0;i<n;i++)
		cin >> a[i];
	for(i=0;i<n-1;i++)
		if(a[i]<a[i+1])
			swap(a[i],a[i+1]);
	cout << a[n-1] << " ";
	for(i=0;i<n-1;i++)
		if(a[i]>a[i+1])
			swap(a[i],a[i+1]);
	cout << a[n-1] << " ";
	for(i=0;i<n;i++)
		sum += a[i];
	cout << sum << endl;
	return 0;
}



Measured memory_bytes: 3156
#pragma warning(disable: 4996)
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <string>
#include <vector>
#include <set>
#include <map>
#define MOD 1000000007

using namespace std;

int X, A;

int main() {
	
	cin >> X >> A;
	if(X < A) {
		cout << "0";
	} else {
		cout << "10";
	}

	return 0;
}




Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <functional>
#include <algorithm>
#include <numeric>
#include <string>
#include <map>
#include <queue>
#include <bitset>
#include <sstream>
#include <iomanip>

using namespace std;
typedef long long ll;


int main(){
        ll N;
        cin >> N;
        vector<ll> A(N);
        for(ll i=0; i<N; i++){
                cin >> A[i];
        }
        ll Count_4=0, Count_2=0;
        for(ll i=0; i<N; i++){
                if(A[i]%4 == 0)Count_4++;
                else if(A[i] %2 == 0) Count_2++;
        }
if(Count_2==0) Count_2 = 1;
        if(Count_2-1 + Count_4*2 >= N-1) cout << "Yes";
        else cout << "No";
}


Measured memory_bytes: 1024
#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<ll,ll>;
//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
//xにはvectorなどのコンテナ
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define inf 2147483647 //int値の最大値
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素
#define CST(x) cout<<fixed<<setprecision(x)//小数点以下の桁数指定
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 gcd(int a, int b) {
    if (b==0) return a;
    else return gcd(b, a%b);
}
int lcm(int a, int b) {
    return a * b / gcd(a, b);
}
int two(int n){
	ll ans=1;
	rep(i,n){
		ans*=2;
	}
	return ans;
}
int main() {
	cin.tie(0);
	cout.tie(0);
	ios::sync_with_stdio(false);
	int l,r,d;cin>>l>>r>>d;
	int ans=0;
	FOR(i,l,r){
	    if(i%d==0)ans++;
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned int uint;
typedef unsigned char uchar;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;

#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();i++)
#define RFOR(i,c) for(__typeof((c).rbegin())i=(c).rbegin();i!=(c).rend();i++)
#define ALL(container) (container).begin(), (container).end()
#define RALL(container) (container).rbegin(), (container).rend()
#define SZ(container) ((int)container.size())
#define mp(a,b) make_pair(a, b)
#define pb push_back
#define eb emplace_back
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define __builtin_popcount __builtin_popcountll

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {
    os<<"["; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"]"; return os;
}
template<class T> ostream& operator<<(ostream &os, const set<T> &t) {
    os<<"{"; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"}"; return os;
}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}
template<class S, class T> pair<S,T> operator+(const pair<S,T> &s, const pair<S,T> &t){ return pair<S,T>(s.first+t.first, s.second+t.second);}
template<class S, class T> pair<S,T> operator-(const pair<S,T> &s, const pair<S,T> &t){ return pair<S,T>(s.first-t.first, s.second-t.second);}

const int INF = 1<<28;
const double EPS = 1e-8;
const int MOD = 1000000007;


int T, n, m;
vi a, memo;
ll solve(int m) {
    if (memo[m] != -1) return memo[m];
    int ans = 0;
    for (int x : a) {
        if (x <= m) {
            ans |= !solve(m - x);
        }
    }
    return memo[m] = ans;
}

int main(int argc, char *argv[]){
    ios::sync_with_stdio(false);
    while(cin >> n >> m){
        a = vi(n); memo = vi(m + 1, -1);
        REP(i, n) cin >> a[i];
        cout << (solve(m) ? "First" : "Second") << endl;
    }
    return 0;
}


Measured memory_bytes: 5376
import Control.Monad
import Data.Maybe
import qualified Data.ByteString.Char8 as BS
import Data.List

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine

main = do
    [t, x] <- getIntList
    print $ (fromIntegral t) / (fromIntegral x)

Measured memory_bytes: 636
#include <iostream>
using namespace std;
int main() {
	int g[6] = {2,3,5,10,12,15};
	int p[6] = {380,550,850,1520,1870,2244};
	int dp[66];
	for (int &i : dp) i = 10e6;
	dp[0] = 0;
	for (int i=0; i<6; ++i) {
		for (int j=0; j<51; ++j) {
			int k = j+g[i];
			if (dp[j]!=10e6) {
				dp[k] = min(dp[k], dp[j]+p[i]);
			}
		}
	}
	int n;
	while (cin >> n && n!=0) {
		cout << dp[n/100] << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#include<iostream>
#include<vector>
#include<map>
#include<numeric>
using namespace std;

int mypow(int x, int y);
vector<int> my_bit(int n, int keta);


int main(){
    map<int, vector<pair<int, int>>> shogen;
    int N, A, x, y, n, sum_;
    int ans = 0;
    pair<int, int> p;

    //インプット
    std::cin >> N;
    vector<int> pattern(N);

    for(int i = 0; i < N; i++){
        //この時点で人名は-1されていく
        std::cin >> A;
        shogen[i] = {};

        for(int j = 0; j < A; j++){
            std::cin >> x >> y;
            p = std::make_pair(x - 1, y);

            if(shogen.count(i)){
                shogen[i].push_back(p);
            }
        }
    }
    //インプット終了


    // std::cout << N;

    std::map<int, vector<pair<int, int>>>::iterator iter;
    // std::cout << shogen.size() << "\n";
    // for(int i = 0 ; shogen.size(); i++){
    //     std::cout << iter->first << "\n";
    //     for(int j = 0; j < iter->second.size(); j++){
    //         std::cout << iter->second[j].first << " " << iter->second[j].first << "\n";
    //     }
    //     iter++;
    // }

    for(int i = 0; i < mypow(2, N); i++){
        pattern = my_bit(i, N);
        iter = shogen.begin();
        for(int j = 0; j < N; j++){
            //全員の証言を見ていく
            n = iter->second.size();
            for(int k = 0; k < n; k++){
                //証言を順番に見ていく
                if(iter->second[k].second != pattern[iter->second[k].first]){
                    //ここに入ると嘘つき
                    if(pattern[j] == 1){
                        //なのにいい人だとおかしいのでそのパターンはなし。
                        goto ptn_end;
                    }
                }
            }
            iter++;
        }
        //やり終えたら次のパタンに行く前に集計、いい人が保持値より多ければ答えを更新
        sum_ = std::accumulate(pattern.begin(), pattern.end(),0);
        if(sum_ > ans){
            ans = sum_;
        }

        ptn_end:
        ;
    }
    std::cout << ans;

}

vector<int> my_bit(int n, int keta){
    int n_loop = 0;//桁数
    int bit_buff;
    double d_n = (double)n;
    //最大桁を算出
    while(d_n >= 1.0){
        n_loop++;
        d_n = d_n/2.0;
    }

    vector<int> ans(n_loop);

    //割ってこう
    for(int i =0; i < n_loop; i++){
        bit_buff = mypow(2, (n_loop - 1 -i));
        if(n >= bit_buff){
            ans[i] = 1;
            n = n - bit_buff; 
        }
    }

    ans.insert(ans.begin(), keta - ans.size(), 0);
    return ans;
}

int mypow(int x, int y){
    int ans = 1;
    for(int i = 0; i < y; i++){
        ans = ans * x;
    }
    return ans;
}

Measured memory_bytes: 3564
import java.util.Scanner;


public class Main {
	
	Scanner sc = new Scanner(System.in);
	
	void run() {
		
		int n = sc.nextInt();
		
		for (int i=0;i<n;i++) {
			double[] x = new double[3];
			double[] y = new double[3];
			
			for (int j=0;j<3;j++) {
				x[j] = sc.nextDouble();
				y[j] = sc.nextDouble();
			}
			
			double a1 = 2 * ( x[1] - x[0] );
			double b1 = 2 * ( y[1] - y[0] );
			double c1 = x[0] * x[0] - x[1] * x[1] + y[0] * y[0] - y[1] * y[1];
			double a2 = 2 * ( x[2] - x[0] );
			double b2 = 2 * ( y[2] - y[0] );
			double c2 = x[0] * x[0] - x[2] * x[2] + y[0] * y[0] - y[2] * y[2];
			
			double xp = (b1*c2-b2*c1)/(a1*b2-a2*b1);
			double yp = (c1*a2-c2*a1)/(a1*b2-a2*b1);
			double r = Math.sqrt( (xp-x[0])*(xp-x[0]) + (yp-y[0])*(yp-y[0]) );
			
			System.out.printf("%.3f %.3f %.3f\n",xp,yp,r);
			
			
		}
		
	}
	
	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 12000
#include <iostream>
#include <algorithm>

using namespace std;

long long add(long long x,long long y)
{
          if(x>y)
          {
                    if(x%y==0)
                    {
                              return x*2-y;
                    }
                    return x/y*y*2+2*(x%y)+add(x%y,y-x%y);
          }
          else
          {
                    if(y%x==0)
                    {
                              return y*2-x;
                    }
                    return y/x*x*2+add(x,y%x);
          }
}

int main()
{
          long long a,x;
          cin>>a>>x;
          long long y=a-x;
          long long ans=x+y+add(x,y);
          cout<<ans;

}


Measured memory_bytes: 764
n, m = map(int, input().split())
PSs = [list(input().split()) for i in range(m)]

for i in range(len(PSs)):
    PSs[i][0] = int(PSs[i][0])

is_ac = [False for i in range(n)]

ac = int()
wa = [0 for i in range(n)]
for i in range(len(PSs)):
    if PSs[i][1] == 'AC' and not is_ac[PSs[i][0]-1]:
        ac += 1
        is_ac[PSs[i][0]-1] = True
    
    if PSs[i][1] == 'WA' and is_ac[PSs[i][0]-1] == False:
        wa[PSs[i][0]-1] += 1

#print(ac)
#print(is_ac)
#print(wa)

pen = int()
for i in range(n):
    if is_ac[i] == True:
        pen += wa[i]
        #print(i, i, i)

print(ac, pen)



Measured memory_bytes: 30752
# N = gets.chomp.to_i
A, B, C = gets.chomp.split.map(&:to_i)
# S = gets.chomp.chars

if A == B && B != C
  print "Yes\n"
elsif B == C && C != A
  print "Yes\n"
elsif C == A && A != B
  print "Yes\n"
else
  print "No\n"
end


Measured memory_bytes: 1788
#include<stdio.h>
int main(void){
	int a,b,i,j,c[1000];
	scanf("%d %d",&a,&b);
	for(i=0;i<1000;i++){c[i]=(i+1)*(i+2)/2;}
	for(i=1;;i++){
		for(j=0;j<1000;j++){
			if(c[j]==a+i&&c[j+1]==b+i){printf("%d",i);return 0;}
		}
	}
}

Measured memory_bytes: 128
/*
  Motto - try hard to become an expert
*/
#include <bits/stdc++.h>
#include <map>
#include <algorithm>
#include <vector>
#include <string.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <chrono>
#include <thread>
#include <iomanip>
 
//define
#define rep(i,n)    for(int i=0;i<n;i++)
#define repu(i,k,n) for(int i=k;i<=n;i++)
#define repd(i,k,n) for(int i=k;i>=n;i--)
#define se second
#define fi first
#define pb push_back
#define mp make_pair
#define INF (int)INT_MAX
#define all(v)  v.begin(), v.end()
#define endl "\n"
 
//typedef
typedef long long int ll;
typedef long double ld;
typedef std::pair<int, int> pii;
typedef std::vector<int> vi;
typedef std::vector< pii > vii;
typedef std::vector< ll > vll;
typedef std::vector< std::pair < pii, int > > vpp;
 
const int N = 1*1e5 +5 ;
const long long MOD = 1e9 + 7;
const long long inf = 1e18;
 
using namespace std;
 

ll modpow(ll x,ll n){
    ll res=1;
    while(n>0){
        if(n&1) res=res*x%MOD;
        x=x*x%MOD;
        n>>=1;
    }
    return res;
}
 
ll modFact(ll n, ll p) 
{ 
    if (n >= p) 
        return 0; 
  
    ll result = 1; 
    for (ll i = 1; i <= n; i++) 
        result = (result * i) % p; 
  
    return result;  
} 
 
bool isPrime(int x)
{
    if(x%2==0)
        return 0;
    for(int i=3;i<=sqrt(x);i+=2)
    {
        if(x%i==0)
            return 0;
    }
    return 1;
}
 
ll binomialCoeff(ll n, ll k) 
{ 
    ll C[n + 1][k + 1]; 
    ll i, j; 


    for (i = 0; i <= n; i++) 
    { 
        for (j = 0; j <= min(i, k); j++) 
        { 
            
            if (j == 0 || j == i) 
                C[i][j] = 1; 

            else
                C[i][j] = (C[i - 1][j - 1] + 
                                        C[i - 1][j])%MOD; 
        } 
    } 

    return C[n][k]; 
}
bool compare(const string &a , const string&b){
    //set<pair<int,int> , decltype(&compare)>s(&compare) ;
}

// struct compare{
//     // for priority_queue
//     bool operator()(const int &a , const int&b){
//         return a<b ;
//     }
// };
vector<pair<int,int>>g[N] ;
vector<int>color(N);
vector<bool>vis(N) ;
void dfs(int ver , int oc){
    int cc ;
    vis[ver] = 1 ;
    color[ver] = oc%2 ? 0 : 1 ;
    for(auto node : g[ver]){
        if(!vis[node.fi]){
            cc = node.se%2 ? 1 : 0 ;
            int tc = oc+ cc ;
            dfs(node.fi  , tc);
        }
    }
}
void solve()
{
    int n;
    cin>>n;
    rep(i , n-1){
        int u , v , w ;
        cin>>u>>v>>w ;
        g[u].pb({v , w}) ;
        g[v].pb({u , w}) ;
    }
    dfs(1 ,0) ;
    repu(i  ,1 , n){
        cout<<color[i]<<endl;
    }
}
 
int main() {
    #ifndef ONLINE_JUDGE
        // for getting input from input.txt
        freopen("input.txt", "r", stdin);
        // for writing output to output.txt
        freopen("output.txt", "w", stdout);
    #endif
    
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    int t = 1;
    //cin>>t;
    while(t--)
    {
        solve();
    } 
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
}

Measured memory_bytes: 11304
#include <iostream>
#include <fstream>
#include <sstream>
#include <algorithm>
#include <cstdio>
#include <cassert>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <string>
#include <deque>
#include <queue>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <bitset>
#include <stack>
#include <iomanip>
#include <utility>
#include <functional>
using namespace std;
//orz hxr
#define ll long long
#define ull unsigned ll
const int N=105;
int n, a[N];
int main() {
	scanf("%d", &n);
	for (int i=0; i<n; i++)
		scanf("%d", &a[i]);
	int sum=0;
	for (int i=0; i<n; i++)
		sum+=a[i];
	if (sum%10!=0) {
		printf("%d\n", sum);
		return 0;
	}
	int x=1000000;
	for (int i=0; i<n; i++) {
		if (a[i]%10==0)
			continue;
		x=min(x, a[i]);
	}
	if (x==1000000)
		puts("0");
	else
		printf("%d\n", sum-x);
	return 0;
}

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

int main() {
  long long N, M, K;
  cin >> N >> M >> K;
  vector<long long> A(N + 1);
  A.at(0) = 0;
  for (int i = 1; i < N + 1; i++) {
    cin >> A.at(i);
  }
  
  vector<long long> cumsum_B(M + 1);
  cumsum_B.at(0) = 0;
  long long b;
  for (int j = 1; j < M + 1; j++) {
    cin >> b;
    cumsum_B.at(j) = cumsum_B.at(j - 1) + b;
  }
  
  int max_num = 0;
  int b_num = M;
  long long a_time;
  for (int i = 0; i < N + 1; i++) {
    a_time += A.at(i);
    if (a_time > K) {
      break;
    }
    while (cumsum_B.at(b_num) + a_time > K) {
      b_num--;
    }
    max_num = max(max_num, i + b_num);
  }
  cout << max_num << endl;
}


Measured memory_bytes: 6428
s = input()

l = 0
r = len(s)-1
cnt = 0

while l < r:
    lx = 0
    while s[l] == "x" and l < len(s)-1:
        lx += 1
        l += 1

    rx = 0
    while s[r] == "x" and r > 0:
        rx += 1
        r -= 1

    if s[l] == s[r]:
        cnt += abs(rx-lx)

        l += 1
        r -= 1
    else:
        cnt = -1
        break

print(cnt)

Measured memory_bytes: 9192
#include <iostream>
#include <bits/stdc++.h>
#include<sstream>
using namespace std;
const int N = 1e5 + 7, M = 1e7, OO = 0x3f3f3f3f;
#define endl '\n'
#define  ll long long
#define loop(i,n) for(int i = 0;i < int(n);++i)
#define rloop(i,n) for(int i = int(n);i >= 0;--i)
#define range(i,a,b) for(int i = int(a);i <= int(b);i++)
#define p(a) printf("%d ",a)
#define S(n) scanf("%d",&n)
int main () {
    map<string,int>mp;
    mp["AC"]=0;
    mp["WA"]=0;
    mp["TLE"]=0;
    mp["RE"]=0;
    int n;S(n);
    string s;
    loop(i,n) {
        cin >> s;
        mp[s]++;
    }
    printf("AC x %d\n",mp["AC"]);
    printf("WA x %d\n",mp["WA"]);
    printf("TLE x %d\n",mp["TLE"]);
    printf("RE x %d\n",mp["RE"]);

    return 0;
}

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

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef pair<LL, LL> PLL;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

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

#define FF first
#define SS second
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;

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

  string S; cin >> S;
  set<int> ans;
  REP(d,10){
	string tmp = S;
	REP(i,12) if(tmp[i] == '?') tmp[i] = d+'0';
	int chk = 0;
	FOR(i,1,12){
	  int p = tmp[11-i]-'0';
	  int q = 0;
	  if(i <= 6) q = i+1;
	  else q = i - 5;
	  chk += p*q;
	}
	chk %= 11;
	chk = 11 - chk;
	if(chk >= 10) chk = 0;
	if(chk == tmp[11]-'0') ans.insert(d);
  }

  if(SZ(ans) == 1)
	cout << *ans.begin() << endl;
  else
	cout << "MULTIPLE" << endl;
  
  return 0;
}

Measured memory_bytes: 3212
a,b,k = map(int, input().split())

for i in range(1,k+1):
    if i % 2 != 0:
        if a % 2 != 0:
            a = a-1
        a = a/2
        b = b + a
    else:
        if b % 2 != 0:
            b = b - 1
        b = b/2
        a = a + b
print(int(a),int(b))

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,x,n) for(int i=x;i<n;i++)
#define mod 1000000007 //10^9+7
#define INF 1000000000000 //10^12
#define F first
#define S second
#define P pair<int,int>
#define all(vec) vec.begin(),vec.end()
//library begin
int gcd(int a,int b){
    if(a%b==0)return b;
    return gcd(b,a%b);
}
int lcm(int a,int b){
    return a*b/gcd(a,b);
}
int log(int a){
    int b=a;
    int cnt=0;
    while(b%2==0){
        b/=2;
        cnt++;
    }
    return cnt;
}
int mypow(int a,int b){
    if(b==0)return 1;
    if(b==1)return a;
    int t=mypow(a,b/2);
    if(b%2==0)return t*t;
    return t*t*a;
}
//library end
vector<int>vec;
int dig(int n){
    int cnt=0;
    while(n){
        cnt++;
        n/=10;
    }
    return cnt;
}
void dfs(int s){
    if(dig(s)==10){
        vec.push_back(s);
        return;
    }
    if(s!=0)vec.push_back(s);
    dfs(s*10+3);
    dfs(s*10+5);
    dfs(s*10+7);
    return;
}
int n,ans=0;
signed main(){
    cin>>n;
    dfs(0);
    sort(all(vec));
    rep(i,vec.size()){
        if(vec[i]>n)break;
        bool t=false,f=false,s=false;
        int x=vec[i];
        while(x){
            int last=x%10;
            if(last==3)t=true;
            if(last==5)f=true;
            if(last==7)s=true;
            x/=10;
        }
        if(t&&f&&s)ans++;
    }
    cout<<ans<<endl;
    return 0;
}



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

int main()
{
    int n,k;
    cin >> n >> k;
    vector<int> a(n);

    for (int i = 0; i < k; i++) {
        int d;
        cin >> d;

        for (int j = 0; j < d; j++) {
            int m;
            cin >> m;
            a.at(m-1) = 1;
        }
    }

    int ans = 0;
    for (int i = 0; i < n; i++) {
        if (a.at(i) == 0)
            ans++;
    }

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

Measured memory_bytes: 3624
#include<iostream>
#include<algorithm>
#include<cstdio>
using namespace std;
int n;
struct node{
	int index;
	int Zhi;
}A[100005];
bool cmp(node A, node B){ return A.Zhi < B.Zhi; }
int main(){
	cin >> n;
	for(int i = 0; i < n; i++){
		cin >> A[i].Zhi;
		A[i].index = i+1;
	}
	sort(A, A + n, cmp);
	for(int i = 0; i < n; i++) cout << A[i].index << " ";
}

Measured memory_bytes: 1536
n=int(input())
t = [[0 for _ in range(10)] for _ in range(10)]
for i in range(1,n+1):t[int(str(i)[0])][int(str(i)[-1])]+=1
g=0
for i in range(1,10):
    for j in range(1,10):
        g+=t[i][j]*t[j][i]
print(g)

Measured memory_bytes: 3060
#include <stdio.h>

int main(void){
  int a,b,c;
  scanf("%d",&a); scanf("%d",&b); scanf("%d",&c);
  if(a==b+c || b==a+c || c==a+b){
    printf("Yes");
  }else{
    printf("No");
  }
  
  return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h> 
using namespace std;
typedef long long ll;
template<typename T1,typename T2> bool chmin(T1 &a,T2 b){if(a<=b)return 0; a=b; return 1;}
template<typename T1,typename T2> bool chmax(T1 &a,T2 b){if(a>=b)return 0; a=b; return 1;}


signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);

    int n;
    cin>>n;
    int ans[n]={};
    for(int i=1;i<n;i++){
        int a;
        cin>>a;
        a--;
        ans[a]++;
    }
    for(int i=0;i<n;i++){
        cout << ans[i] << "\n";
    }    
}

Measured memory_bytes: 4368
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rrep(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(x) (x).begin(),(x).end()
#define pb push_back
#define mp make_pair
#define INF9 1000000000 //10^9
#define MOD 1000000007 //10^9+7
#define fi first
#define sc second
using ll=long long;
using pii=pair<ll,ll>;
using vi=vector<int>;

int main() {
    string s,ans; cin >> s;
    int t = stoi(s);
    int a = t / 100; int b = t % 100;
    
    bool a_MM_flag = 1<=a && a<=12;
    bool b_MM_flag = 1<=b && b<=12;

    if(a_MM_flag && b_MM_flag) ans = "AMBIGUOUS";
    else if(a_MM_flag) ans = "MMYY";
    else if(b_MM_flag) ans = "YYMM";
    else ans = "NA";

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


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define T 100005
#define N 105
using namespace std;
int n,m,t,a[N],A[T],ans;

int main(){
  cin>>n>>m>>t;
  for(int i=0;i<n;i++){
    cin>>a[i];
    A[a[i]-m]++;
    A[a[i]+m+1]--;
  }
  for(int i=1;i<=t;i++)
    A[i]+=A[i-1];
  int f=0;
  for(int i=0;i<=t;i++){
    if(!A[i])ans++;
    else if(i&&f&&!A[i-1])ans++;
    if(A[i])f=1;
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 3148
// B - Chocolate
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
#define rp(i,s,e) for(int i=(s);i<(e);++i)
#define rpz(i,e) rp(i,0,e)

int main(){
	int N,D,X; cin>>N>>D>>X;
	vi days(D+1);
	rpz(i, N){
		int a; cin>>a;
		rpz(j, D){
			int day = j*a + 1;
			if(day > D) break;
			days[day]++;
		}
	}
	int ans = X;
	rpz(i, D+1) ans += days[i];
	cout<< ans <<endl;
}

Measured memory_bytes: 256
#include <stdio.h>          // putchar(), printf(), fprintf(), scanf()
#define MAX_N 100

int
main(int argc, char **argv)
{
	int p, q;
	int r[MAX_N];
	int i, j;

	while (scanf("%d %d", &p, &q) != EOF)
	{
		p %= q;

		int n = 0;
		while (p != 0)
		{
			p *= 10;

			if (n >= MAX_N)
			{
				fprintf(stderr, "r area overflow. size:%d\n", MAX_N);
				return 0;
			}

			for (j = 0; j < n; ++j)
			{
				if (r[j] == p)
					break;
			}

			if (j < n)
				break;

			printf("%d", p / q);
			r[n] = p;
			n++;
			p %= q;
		}

		putchar('\n');
		if (p != 0)
		{
			for (i = 0; i < j; ++i)
				putchar(' ');

			for (; i < n; ++i)
				putchar('^');

			putchar('\n');
		}
	}

	return 0;
}

Measured memory_bytes: 596
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MOD 1000000007
#define INF 1e9
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;

// 素数判定O(√n)
bool is_prime(int n){
for(int i=2;i*i<=n;i++){
    if(n%i==0) return false;
}
return n!=1; //1の場合は除外
}

// 約数の列挙O(√n)
vector<ll> divisor(ll n){
vector<ll> res;
for(ll i=1LL;i*i<=n;i++){
    if(n%i==0){
        res.push_back(i);
        if(i!=n/i) res.push_back(n/i);
    }
}
sort(res.begin(), res.end());
return res;
}

// 素因数分解O(√n)
map<int,int> prime_factor(int n){
    map<int,int> res;
    for(int i=2;i*i<=n;i++){
        while(n%i==0){
            ++res[i];
            n/=i;
        }
    }
    if(n!=1) res[n]=1;
    return res;
}

int prime[100010];     // i番目の素数
bool isprime[100010];   // isprime[i]がtrueならiは素数

// n以下の素数の数を返す
int eratos(int n){
    int p=0;
    for(int i=0;i<=n;i++) isprime[i]=true;
    isprime[0]=isprime[1]=false;
    for(int i=2;i<=n;i++){
        if(isprime[i]){
            prime[p++]=i;
            for(int j=2*i;j<=n;j+=i) isprime[j]=false;
        }
    }
    return p;
}

int main(){
	ll n;
    cin>>n;
    vector<ll> a=divisor(n);
    ll ans=n;
    rep(i,a.size()){
        ans=min(ans,a[i]-1+n/a[i]-1);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 384
h,w=map(int,input().split())
lis=[list(input()) for i in range(h)]

ans=[[0]*w for i in range(h)]

for i in range(h):
  for j in range(w):
    x,y=0,0
    if lis[i][j]=="#":
      ans[i][j]=1
      for a in range(-1,2):
        if 0<=i+a<h and lis[i+a][j]=="#" and a!=0:
          x+=1
      ans[i][j]+=x
      for b in range(-1,2):
        if 0<=j+b<w and lis[i][j+b]=="#" and b!=0:
          y+=1
      ans[i][j]+=y
      if ans[i][j]==1:
        print("No")
        exit()
    else:
      ans[i][j]=0
      
print("Yes")

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

int main(){
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  int l = a+b;
  int r = c+d;
  string s;
  if(l < r) s = "Right";
  else if(l > r)  s = "Left";
  else  s = "Balanced";
  cout << s << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG 
#define rep(i, n) for (int i = 0; i < n; i++)
#define reps(i, s, n) for (int i = s; i < n; i++)
#define all(v) v.begin(), v.end() // sort(all(array))
#define INF 1000000000
#define mod 1000000007
#define EPS 0.0001
using namespace std;
using ll = long long;
using vi = vector<int>; //vi array(要素数, 初期値)
using pll = pair<ll, ll>;
using pii = pair<int, int>;
using vc = vector<char>;
using vs = vector<string>;
using vb = vector<bool>;
using vvi = vector<vi>; //vvi table(行数, vi(列数, 初期値))
using vvc = vector<vc>;
using vvs = vector<vs>;
using vvb = vector<vb>;

int main() {
    int x; cin >> x;
    if (x == 0) {
        cout << 1 << endl;
    } else {
        cout << 0 << endl;
    }
}


Measured memory_bytes: 3612
#include <iostream>
#include <string>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <map>
#include <cmath>
#include <queue>
#include <utility>
#include <functional>
#include <deque>
#include <cctype>
#include <stack>
#include <bitset>

using ll = long long;
typedef unsigned long long ull;
typedef std::pair<ll, ll>P;

ll min(ll a, ll b) {
	if (a >= b)return b;
	else return a;
}
ll max(ll a, ll b) {
	if (a >= b)return a;
	else return b;
}
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a%b);
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}

const ll Z = 1000000007;
const ll INF = 1 << 30;
const ll INF2 = 9000000000000000000LL;
bool flag = true;
bool fl = true;
int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
std::string abc = "abcdefghijklmnopqrstuvwxyz";
struct edge { ll to, cost; };

int main() {
	int n, ans = 0;
	std::cin >> n;
	std::vector<P>r(n), b(n);
	for (int i = 0;i < n;i++) {
		int x, y;
		std::cin >> x >> y;
		r[i] = std::make_pair(x, y);
	}
	for (int i = 0;i < n;i++) {
		int x, y;
		std::cin >> x >> y;
		b[i] = std::make_pair(y, x);
	}
	std::sort(r.begin(), r.end());
	std::sort(b.begin(), b.end());
	bool used[1000];
	for (int i = 0;i < 1000;i++)used[i] = true;
	for (int i = 0;i < n;i++) {
		int x = b[i].second, y = b[i].first, minit = -1;
		for (int j = 0;j < n;j++) {
			if (!used[j])continue;
			if (r[j].first < x&& r[j].second < y) {
				minit = j;
			}
		}
		if (minit != -1) {
			ans++;
			used[minit] = false;
		}
	}
	std::cout << ans << std::endl;
}

Measured memory_bytes: 256
arr = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]

print(arr[int(input())-1])

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

int solve(int n, int k){
    if(n==1) return 0;
    return (solve(n-1,k)+k)%n;
}

int main(){
    int n,k,m;
    while(cin>>n>>k>>m){
        if(n==0) break;
        cout<<(solve(n-1,k)+m)%n+1<<endl;
    }
}


Measured memory_bytes: 3328
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <functional>
#include <climits>
#include <cstring>

using namespace std;

#define int long long
#define rep(i, n) for (int i=0;i<(int)n;++i)
#define rep1(i, n) for (int i=1;i<=(int)n;++i)
#define unless(a) if(!(a))
#define all(a) begin(a),end(a)
#define fst first
#define scd second
#define PB emplace_back
#define PPB pop_back

using vi=vector<int>;
using pii=pair<int, int>;

bool chmin(int&a,int b){return a>b?(a=b,true):false;}
bool chmax(int&a,int b){return a<b?(a=b,true):false;}
int read(){int a;scanf("%lld",&a);return a;}

struct UF {
	vi data;
	void init(int n)
	{
		data.resize(n);
		fill(all(data), -1);
	}
	int root(int x)
	{
		return data[x] < 0 ? x : data[x] = root(data[x]);
	}
	void unite(int x, int y)
	{
		x = root(x);
		y = root(y);
		if (x == y) return;
		if (size(x) < size(y)) swap(x, y);
		data[x] += data[y];
		data[y] = x;
	}
	bool same(int x, int y)
	{
		return root(x) == root(y);
	}
	int size(int x)
	{
		x = root(x);
		return -data[x];
	}
	bool is_root(int x)
	{
		return x == root(x);
	}
};

int N, M;
vector<pii> edges; // undirected
UF uf;

signed main()
{
	cin >> N >> M;

	rep(i, M) {
		int a, b; cin >> a >> b;
		--a, --b;
		edges.PB(pii(a, b));
	}

	vector<vector<int>> G(N);

	int ans = 0;

	rep(i, M) {
		uf.init(N);
		rep(j, N) G[j].clear();
		rep(j, M) {
			if (i == j) continue;
			int u = edges[j].fst, v = edges[j].scd;
			G[u].PB(v);
			G[v].PB(u);
			uf.unite(u, v);
		}

		if (not uf.same(edges[i].fst, edges[i].scd)) ans++;
	}

	cout << ans << endl;
}



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

const ll MAX = 200000;
const ll INF = 1001001001;
const ll MOD = 1000000007;

ll N, M1, M2, ans=0, tmp=0;
vector<ll> A, B, C;
vector<vector<ll>> DP;

signed main(){
    cin >> N >> M1 >> M2;
    DP.resize(N);
    for(int i=0;i<N;i++) {
        DP[i].resize(4000, INF);
    }
    for(int i=0;i<N;i++) {
        ll a, b, c;
        cin >> a >> b >> c;
        A.push_back(M2*a-M1*b);
        DP[i][2000+M2*a-M1*b] = c;
        C.push_back(c);
    }
    for(int i=1;i<N;i++) {
        for(int j=0;j<4000;j++) {
            DP[i][j] = min(DP[i][j], DP[i-1][j]);
            if(j-A[i]>=0) DP[i][j] = min(DP[i][j], DP[i-1][j-A[i]]+C[i]);
        }
    }
    if(DP[N-1][2000]>=INF) cout << -1 << endl;
    else cout << DP[N-1][2000] << endl;
    return 0;
}

Measured memory_bytes: 4876
#include <algorithm>
#include <iostream>

namespace rika
{
	template <typename T>
	class edge
	{
	public:
		int to;
		T cost;

		edge() = default;
		edge( const edge<T>& ) = default;
		edge( edge<T> && ) = default;
		edge& operator =( const edge<T>& ) = default;
		edge& operator =( edge<T> && ) = default;

		~edge() = default;

		edge( int _to, T _cost ) : to( _to ), cost( _cost ) {}
	};
}

namespace rika
{
	namespace internal
	{
		template <typename TValue, typename TGraph>
		std::pair<TValue, int> visit( int from, int v, const TGraph &g )
		{
			auto r = std::make_pair( TValue(), v );
			try
			{
				for( auto it = g[v].begin(); it != g[v].end(); ++it )
				{
					if( it->to == from )
						continue;
					auto r2 = visit<TValue>( v, it->to, g );
					if( r2.first + it->cost >= r.first )
						r = std::make_pair( r2.first + it->cost, r2.second );
				}
			}
			catch ( bool x ) {
				std::cout << "hoge" << std::endl;
			}
			return r;
		}
	}

	template <typename TValue, typename TGraph>
	TValue tree_diameter( const TGraph &g )
	{
		using namespace internal;
		auto r1 = visit<TValue>( -1, 0, g );
		auto r2 = visit<TValue>( -1, r1.second, g );
		return r2.first;
	}
}

#include<bits/stdc++.h>
using namespace std;
using namespace rika;
int main()
{
	int N;
	cin >> N;
	vector<vector<edge<int>>> g( N * 10 );
	for( int i = 0; i < N - 1; i++ )
	{
		int s, t, w;
		cin >> s >> t >> w;
		g[s].push_back( edge<int>( t, w ) );
		g[t].push_back( edge<int>( s, w ) );
	}
	cout << tree_diameter<int>( g ) << endl;
}

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

int main(int argc, char const *argv[])
{
	ll a, b, k; cin >> a >> b >> k;
	if (a + b <= k) {
		cout << "0 0" << endl;
	} else if (a <= k) {
		cout << "0 " << b - (k - a) << endl;
	} else {
		cout << a - k << " " << b << endl;
	}
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

class Dice{
	public int Top;
	public int Front;
	public int Right;
	public int left;
	public int Back;
	public int Bottom;

	public Dice() {
		// TODO 自動生成されたコンストラクター・スタブ
	}
	public void W() {
		int Topch = Top;
		int leftch = left;
		Top = Right;
		Right = Bottom;
		left = Topch;
		Bottom = leftch;
	}
	public void E() {
		int Topch = Top;
		int Rightch = Right;
		Top = left;
		Right = Topch;
		left = Bottom;
		Bottom = Rightch;
	}

	public void S() {
		int Topch  =Top;
		int Frontch = Front;
		Top = Back;
		Front = Topch;
		Back = Bottom;
		Bottom = Frontch;
	}

	public void N() {
		int Topch = Top;
		int Backch = Back;
		Top = Front;
		Front = Bottom;
		Back = Topch;
		Bottom = Backch;
	}


}


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

		a.Top = sc.nextInt();
		a.Front = sc.nextInt();
		a.Right = sc.nextInt();
		a.left = sc.nextInt();
		a.Back = sc.nextInt();
		a.Bottom = sc.nextInt();
		String str = sc.next();

		char data[] = new char[str.length()];
		data = str.toCharArray();
		for(int i=0;i<str.length();i++) {
			switch(data[i]) {
			case 'W':
				a.W();
				break;
			case'S':
				a.S();
				break;
			case'N':
				a.N();
				break;
			case'E':
				a.E();
				break;
			default:
				break;
			}
		}


		System.out.println(a.Top);

		sc.close();
	}
}





Measured memory_bytes: 26236
import java.util.*;
import java.io.*;
class Main {
    public static void main(String[] args) {
        FastScanner sc = new FastScanner();
        int N = sc.nextInt();
        String str = sc.next();
        String s = str.replaceAll("ABC","XX");
        p(str.length()-s.length());
    }
    public static <T> void p(T element) {
	System.out.println(element);
    }
    public static <T> void pe(T element) {
        System.err.println(element);
    }
    public static int min(int a, int b, int c) {
	int min = Math.min(a,b);
	min = Math.min(min,c);
	return min;
    }
    public static int max(int a, int b,int c) {
	int max= Math.max(a,b);
	max = Math.max(max,c);
        return max;
    }
}
class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        } else {
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
 
    private int readByte() {
        if (hasNextByte())
            return buffer[ptr++];
        else
            return -1;
    }
 
    private boolean isPrintableChar(int c) {
        return 33 <= c && c <= 126;
    }
 
    public boolean hasNext() {
        while (hasNextByte() && !isPrintableChar(buffer[ptr]))
            ptr++;
        return hasNextByte();
    }
 
    public String next() {
        if (!hasNext())
            throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while (isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
 
    public long nextLong() {
        if (!hasNext())
            throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while (true) {
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            } else if (b == -1 || !isPrintableChar(b)) {
                return minus ? -n : n;
            } else {
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
 
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
            throw new NumberFormatException();
        return (int) nl;
    }
    public int[] nextIntArray(int N) {
        int[] a = new int[N];
        for(int i = 0; i<N; i++) {
            a[i] = nextInt();
        }
        return a;
    }
 
    public double nextDouble() {
        return Double.parseDouble(next());
    }
}

Measured memory_bytes: 22612
#include <bits/stdc++.h>
#define rep(i,n) for(int i=(0);i<(n);i++)

using namespace std;

typedef long long ll;

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

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

	int n;
	cin >> n;

	vector<ll> x(n), y(n), f0(n), f1(n);
	rep(i, n){
		cin >> x[i] >> y[i];
		f0[i] = x[i] - y[i];
		f1[i] = x[i] + y[i];
	}

	ll mx0 = LLONG_MIN, mx1 = LLONG_MIN;
	ll mn0 = LLONG_MAX, mn1 = LLONG_MAX;

	rep(i, n){
		chmax(mx0, f0[i]);
		chmax(mx1, f1[i]);
		chmin(mn0, f0[i]);
		chmin(mn1, f1[i]);
	}

	cout << max(mx0 - mn0, mx1 - mn1) << endl;
}


Measured memory_bytes: 9516
n=int(input())
#a,b=map(int,input().split())
#l=list(map(int,input().split()))
#l=[list(map(int,input().split())) for i in range(n)]
s=list(input())
mx=0
for i in range(1,n):
    l1=s[0:i];l2=s[i:n]
    mx=max(mx,len(set(l1) & set(l2)))

print(mx)


Measured memory_bytes: 2940
#include <iostream> // cout, endl, cin
#include <cmath> //sqrt pow
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // dequef
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower

#define rep(i,n) for(int i = 0; i < n; i++)
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define all(a) (a).begin(), (a).end()
#define mod 1000000007
using ll = long long;
using namespace std;
int movex[] = {0,0,-1,1};
int movey[] = {-1,1,0,0};
int warpx[] = {-2,-1,0,1,2, -2,-1,0,1,2, -2,-2,-2, 2,2,2, -1,1, -1,1};
int warpy[] = {-2,-2,-2,-2,-2, 2,2,2,2,2, -1,0,1, -1,0,1, -1,-1, 1,1};
int main(){
  int inf = 100000000;
  int h,w,ch,cw,dh,dw;
  cin >> h >> w >> ch >> cw >> dh >> dw;
  ch--; cw--; dh--; dw--;
  vvi cnt(h, vi(w, inf));
  rep(i, h){
    rep(j, w){
      char t;
      cin >> t;
      if(t == '#') cnt[i][j] = -1;
    }
  }
  deque<pii> que;
  cnt[ch][cw] = 0;
  que.push_back(make_pair(ch, cw));
  while(que.size()){
    auto num = que.front(); que.pop_front();
    int posy = num.first, posx = num.second;
    rep(i, 4){
      int y = posy + movey[i], x = posx + movex[i];
      if(y >= 0 && x >= 0 && y < h && x < w){
        if(cnt[y][x] > cnt[posy][posx]){
          cnt[y][x] = cnt[posy][posx];
          que.push_front(make_pair(y, x));
        }
      }
    }
    rep(i, 20){
      int y = posy + warpy[i], x = posx + warpx[i];
      if(y >= 0 && x >= 0 && y < h && x < w){
        if(cnt[y][x] > cnt[posy][posx] + 1){
          cnt[y][x] = cnt[posy][posx] + 1;
          que.push_back(make_pair(y, x));
        }
      }
    }
  }
  if(cnt[dh][dw] == inf) cout << -1 << endl;
  else cout << cnt[dh][dw] << endl;
}

Measured memory_bytes: 7644
/*氏名：保坂優介, 学籍番号：200441141
  概要：大小に並び替える*/

#include<stdio.h>

int main(void)
{
    int x, y;       //変数の宣言

    scanf("%d %d", &x, &y);     //入力

    while(x != 0 || y != 0)     //X&y=0が入力されるまで繰り返す
    {
        if (x <= y)     //x <= yの場合
        {
            printf("%d %d\n", x, y);        //出力
        }

        else
        {
            printf("%d %d\n", y, x);
        }

        scanf("%d %d", &x, &y);     //出力
    }

    return 0;
}


Measured memory_bytes: 2024
import java.util.*;

class Main {

	public static void main(String args[]){
		Scanner in = new Scanner(System.in);
		for(;;){
			int n = in.nextInt();
			if(n==0) return ;
			int total = 0;
			for(int i=0; i<n*(n-1)/2; i++){
				total += in.nextInt();
			}
			System.out.println(total/(n-1));
		}
	}
	
}

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

using namespace std;

int main()
{
    long long N;
    cin >> N;
    long long A[N];
    long long C[1000000] = {0};
    for (int i = 0; i < N; i++)
    {
        cin >> A[i];
        C[A[i]]++;
    }
    long long sum = 0;
    for (int i = 0; i < 1000000; i++)
    {
        if (C[i] < 2)
            continue;
        sum += C[i] * (C[i] - 1) / 2;
    }
    for (int i = 0; i < N; i++)
    {
        long long ans = sum - C[A[i]] * (C[A[i]] - 1) / 2 + (C[A[i]] - 1) * (C[A[i]] - 2) / 2;
        cout << ans << endl;
    }
}

Measured memory_bytes: 11904