akhauriyash/Code-Regression huggingface dataset:
#include<set>  
#include<map>  
#include<stack>  
#include<cmath>  
#include<cstdio>  
#include<queue>  
#include<vector>  
#include<cstring> 
#include<climits>  
#include<iostream> 
#include<algorithm> 
using namespace std; 
#define INF 1000000000000000
#define MAXN 100
#define LL long long
int read(){ 
    int f=1,x=0; 
    char c=getchar(); 
    while(c<'0'||'9'<c){if(c=='-')f=-1;c=getchar();} 
    while('0'<=c&&c<='9'){x=x*10+c-'0';c=getchar();} 
    return f*x; 
}
int a[MAXN+5];
int main(){
	int ans=0;
	a[1]=read(),a[2]=read(),a[3]=read();
	sort(a+1,a+3+1);
	for(int i=2;i<=3;i++)
		ans+=a[i]-a[i-1];
	printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void) {
	int N;
	const int cake = 4;
	const int donut = 7;
	scanf("%d", &N);

	int i = 0;
	bool answer = false;
	while (!answer) {
		int donutPrice = donut * i;
		int j = 0;
		if (donutPrice == N) {
			answer = true;
		} else if (donutPrice > N) {
			break;
		}
		while (1) {
			int price = donutPrice + cake * j;
			if (price == N) {
				answer = true;
				break;
			} else if (price > N) {
				break;
			}
			j++;
		}
		i++;
	}
	if (answer) {
		printf("Yes");
	} else {
		printf("No");
	}
	return 0;
}



Measured memory_bytes: 128
#include<stdio.h>
#include<string.h>
int main(void){
  int n,l,i,j;
  char s[100][101],tmp[101];
  scanf("%d%d",&n,&l);
  for(i=0;i<n;i++)scanf("%s",s[i]);
  for(i=0;i<n;i++){
    for(j=n-1;j>i;j--){
      if(strcmp(s[j-1],s[j])>0){
        strcpy(tmp,s[j-1]);
        strcpy(s[j-1],s[j]);
        strcpy(s[j],tmp);
      }
    }
  }
  for(i=0;i<n;i++)printf("%s",s[i]);
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep1(i, n) for(int i = 1; i < n+1; i++)
#define sort(A) sort(A.begin(),A.end())
#define reverse(A) reverse(A.begin(),A.end());

typedef long long ll;

int main(){
  int x1,y1,x2,y2;
  cin >> x1 >> y1 >> x2 >> y2;
  int dx = x2 - x1;
  int dy = y2 - y1;
  int x3 = x2 - dy;
  int y3 = y2 + dx;
  int x4 = x3 - dx;
  int y4 = y3 - dy;
  cout << x3 << " " << y3 << " " << x4 << " " << y4 << endl;
}


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

using namespace std;

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

int main(){
    int n;cin>>n;
    int p[100001]={};
    REP(i,n){
        cin>>p[i];
    }
    int res=0;
    REP(i,n){
        cerr<<p[i]<<endl;
    }
    REP(i,n){
        if(p[i]==i+1){
            res++;
            swap(p[i],p[i+1]);
        }
    }
    REP(i,n){
        cerr<<p[i]<<endl;
    }
    cout<<res<<endl;
    return 0;
}


Measured memory_bytes: 640
// include
// ------------------------------------------------
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <math.h>

using namespace std;

// func
// ------------------------------------------------
int CalcSumOfDigit(int n);      // 各桁の和を計算する。
long long getDigit(long long n);      // 数字の桁数を取得する。
string upper(string str);       // 英字を大文字に変換する。
string lower(string str);       // 英字を小文字に変換する。

// define
// ------------------------------------------------
#define all(a)        (a).begin(),(a).end()
#define rall(a)       (a).rbegin(),(a).rend()
#define sz(a)         int((a).size())
#define rep(i,n)      for(int(i)=0;(i)<(n);(i)++)
#define repe(i,n)     for(int(i)=0;(i)<=(n);(i)++)
#define vsort(v)      sort((v).begin(),(v).end())
#define rvsort(v)     sort(rall((v)))
#define vi            vector<int>
#define GCD(a,b)      __gcd((a),(b))
#define LCM(a,b)      ((a)/GCD((a),(b))*(b))
#define kiriage(a,b)  ((a)+(b)-1)/(b)

const int INF = 1e9;

typedef long long ll;
typedef unsigned long long ull;

// code
// ------------------------------------------------
int main() {

  ll n,k;
  cin >> n >> k;

  vector<ll> p(n);
  ll m = 0;
  rep(i,n)
  {
    cin >> p[i];
    m = max(m,p[i]);
  }

  vector<ll> memo(m+1,0);
  for(ll i = 0;i < m;i++)
  {
    memo[i+1] = memo[i] + i + 1;
  }

  double kitai = 0;

  for(int i = 0;i < k;i++)
  {
    kitai += (double)memo[p[i]] / p[i];
  }

  double ans = kitai;

  for(ll i = k; i < n;i++)
  {
    kitai += (double)memo[p[i]] / p[i];
    kitai -= (double)memo[p[i-k]] / p[i-k];

    ans = max(ans,kitai);
  }

  cout << fixed << setprecision(10) << ans << endl;

  return 0;
}
// funcの実体
// ------------------------------------------------
ll getDigit(ll n)
{
  int i = 1;
  while(1)
  {
    n = n / 10;
    if(n == 0)
      break;
    i++;
  }
  return i;
}
ll CalcSumOfDigit(ll n)
{
  ll s = 0;
  while(n)
  {
    s += n % 10;
    n = n / 10;
  }
  return s;
}

string upper(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(97 <= *itr && *itr <= 122)
    {
      *itr = *itr - 32;
    }
  }
  return str;
}

string lower(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(65 <= *itr && *itr <= 90)
    {
      *itr = *itr + 32;
    }
  }
  return str;
}


Measured memory_bytes: 1792
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<utility>
#include<cstring>
#include<string>
#include<vector>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#define inf 0x3f3f3f3f
using namespace std;
typedef long long ll;
typedef pair<int,int> pll;
const int maxn=2e5+10;
const int mod =1e9+7;
const double EPS = 1e-6;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    string s;
    cin >> s;
    s='0'+s;
    ll ans=0;
    for(int i=s.size()-1;i>=1;i--)
    {
        if(s[i]>'5')
        {
            ans+=10-(s[i]-'0');
            s[i-1]++;
        }
        else if(s[i]=='5'&&s[i-1]>='5')
        {
            ans+=10-(s[i]-'0');
            s[i-1]++;
        }
        else
        {
            ans+=(s[i]-'0');
        }
    }
    if(s[0]!='0')
        ans++;
    cout << ans << endl;
    return 0;
}




Measured memory_bytes: 2332
#include<bits/stdc++.h>
#define int long long
using namespace std;
int n,m,a[5];
signed main()
{
	int x,y;
	scanf("%lld%lld",&n,&m);
	for(int i=1;i<=n;i++)
	a[i]=-1;
	for(int i=1;i<=m;i++)
	{
		scanf("%lld%lld",&x,&y);
		if(a[x]==-1)
		a[x]=y;
		else
		if(a[x]!=y)
		{
			printf("-1");
			return 0;
		}
	}
	if(n==1)
	{
		printf("%lld",max(a[1],0ll));
		return 0;
	}
	if(a[1]==0)
	printf("-1");
	else
	{
		a[1]=max(a[1],1ll);
		for(int i=2;i<=n;i++)
		a[i]=max(a[i],0ll);
		for(int i=1;i<=n;i++)
		printf("%lld",a[i]);
	}
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

typedef struct pp{
    char name[100];
    int time;
}P;

P Q[100005];
int head=1,tail,n;

P dequeue(){
    P x=Q[head];
    head=(head+1)%100005;
    return x;
}

void enqueue(P x){
    Q[tail]=x;
    tail=(tail+1)%100005;
}

int min(int a,int b){
    if(a>b)return b;
    else return a;
}

int main(){
    P a;
    int q,elaps=0,c;

    scanf("%d%d",&n,&q);

    for(int i=1;i<=n;i++){
        scanf("%s",Q[i].name);
        scanf("%d",&Q[i].time);
    }
    tail=n+1;

    while(head!=tail){

        a=dequeue();

        c=min(a.time,q);
        elaps+=c;
        a.time-=c;

        if(a.time>0)enqueue(a);
        else printf("%s %d\n",a.name,elaps);
    }
return 0;
}


Measured memory_bytes: 12748
import math
import sys

S=input()

if S == "SUN":
    print(7)
elif S == "MON":
    print(6)
elif S == "TUE":
    print(5)
elif S == "WED":
    print(4)
elif S == "THU":
    print(3)
elif S == "FRI":
    print(2)
elif S == "SAT":
    print(1)

Measured memory_bytes: 3060
#include <stdio.h>
#include <algorithm>
#include <math.h>

using namespace std;

int main(){
	double x1,x2,xp,y1,y2,yp,slope,ansx,ansy;
	int q;
	bool X_FLG = false,Y_FLG = false;

	scanf("%lf %lf %lf %lf",&x1,&y1,&x2,&y2);
	scanf("%d",&q);

	if(y1 == y2){
		X_FLG = true;
	}else if(x1 == x2){
		Y_FLG = true;
	}else{
		slope = (y2-y1)/(x2-x1);
	}

	for(int i=0;i<q;i++){
		scanf("%lf %lf",&xp,&yp);
		if(X_FLG){
			ansx = xp,ansy=y1;
			printf("%.10lf %.10lf\n",2*ansx-xp,2*ansy-yp);
		}else if(Y_FLG){
			ansx = x1,ansy = yp;
			printf("%.10lf %.10lf\n",2*ansx-xp,2*ansy-yp);
		}else{
			ansx = (yp*(x2-x1)*(y2-y1)+xp*(x2-x1)*(x2-x1)-y1*(y2-y1)*(x2-x1)+x1*(y2-y1)*(y2-y1))/((y2-y1)*(y2-y1)+(x2-x1)*(x2-x1));
			ansy = ((x1-x2)*ansx+yp*(y2-y1)+xp*(x2-x1))/(y2-y1);
			printf("%.10lf %.10lf\n",2*ansx-xp,2*ansy-yp);
		}

	}

	return 0;
}

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

using namespace std;

static const int INF = 1e9 + 7;

template<typename T>
using Vec = vector<T>;

template<typename T, typename T2>
using P = pair<T, T2>;

template<typename... Args>
using Tup = tuple<Args...>;

template<typename T>
using qp = priority_queue<T, Vec<T>, greater<T> >;

template<typename T>
using pq = priority_queue<T>;

using llong = long long;
using ullong = unsigned long long;
using uint = unsigned int;

template<typename T>
T gcd(T x, T y)
{
	return y ? gcd(y, x % y) : x;
}

void hawawa()
{
	int n;
	cin >> n;
	while (n--) {
		char c;
		cin >> c;
		if (c == 'Y') {
			cout << "Four\n";
			return;
		}
	}
	cout << "Three\n";
}


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


Measured memory_bytes: 256
// D - RGB Triplets
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)

int main(){
	int N; string S; cin>>N>>S;
	map<char,int> c;
	long long ng = 0;
	rep(i, N){
		c[S[i]]++;
		for(int j=i+1,k=i+2; k<N; k+=2,j++)
			if((S[i]^S[j]^S[k]) == ('R'^'G'^'B')) ng++;
	}
	cout<< (long long)c['R'] * c['G'] * c['B'] - ng <<endl;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
const int MAX = 1000099;
const int OO = 0x3f3f3f3f;

int n, h[MAX];
int dp[MAX];

int main()
{
	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++)
		dp[i] = min(dp[i - 1] + abs(h[i] - h[i - 1]), dp[i - 2] + abs(h[i] - h[i - 2]));
	cout << dp[n - 1] << '\n';

	return 0;
}

Measured memory_bytes: 4736
// ----- In the name of ALLAH, the Most Gracious, the Most Merciful -----

#include<bits/stdc++.h>
using namespace std;

#define NINJA ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define fo(i,n) for(int i=0;i<n;i++)
#define Fo(i,k,n) for(int i=k;i<n;i++)
#define for1(i,n) for(int i=1;i<=n;i++)
#define dloop(i,n) for(int i=n-1;i>=0;i--)
#define iii tuple<int,int,int>
#define vi vector<int>
#define ii pair<int,int>
#define vii vector<ii>
#define int long long
#define ld long double
#define pb push_back
#define endl "\n"
#define setbits __builtin_popcountll
#define mp map<int,int>
#define F first
#define S second
#define sz(v) (int)v.size()
#define mod 1000000007
#define inf (int)1e18

int32_t main(){
	NINJA;

	int n; cin >> n;
	map<string,int> m;
	fo(i,n){
		string s; cin >> s;
		m[s]++;
	}

	cout << "AC x " << m["AC"] << endl;
	cout << "WA x " << m["WA"] << endl;
	cout << "TLE x " << m["TLE"] << endl;
	cout << "RE x " << m["RE"] << endl;
 	
	return 0;
}

Measured memory_bytes: 3664
#include <bits/stdc++.h>
using namespace std;
#pragma GCC diagnostic ignored "-Wmissing-declarations"

#define FINAL_OUT(x) {cout << (x) << '\n'; exit(0);}


int const maxn = 200005;
int tree[4 * maxn];

int sz = 1;

inline int get(int l, int r)
{
    int ans = 0;
    for(l += sz, r += sz; l <= r; l >>= 1, r >>= 1)
    {
        if (l&1)
            ans = max(ans, tree[l++]);
        if (~r&1)
            ans = max(ans, tree[r--]);
    }
    return ans;
}

inline void upd(int ind, int val)
{
    for(tree[ind += sz] = val; ind > 1; ind >>= 1)
        tree[ind >> 1] = max(tree[ind], tree[ind ^ 1]);
}

int main()
{
//    freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    ios_base::sync_with_stdio(false);

    while (sz < maxn) sz <<= 1;

    pair<int,int> f;
    pair<int,int> s;
    cin >> f.first >> f.second;
    cin >> s.first >> s.second;


    pair<int,int> to = {abs(f.first - s.first), abs(f.second - s.second)};

    int n;
    cin >> n;
    vector<pair<int,int> > p;
    while (n-- )
    {
        pair<int,int> cur;
        cin >> cur.first >> cur.second;
        pair<int,int> tmp = {cur.first - f.first, cur.second - f.second};
        if (s.first < f.first) tmp.first *= -1;
        if (s.second < f.second) tmp.second *= -1;

        if (tmp.first >= 0 && tmp.first <= to.first && tmp.second >= 0 && tmp.second <= to.second)
            p.push_back(tmp);
    }

    sort(begin(p), end(p));

    vector<int> vals = {0};
    for(const auto& pa : p)
        vals.push_back(pa.second);

    sort(begin(vals), end(vals));

    for(const auto& pa : p)
    {
        int i = lower_bound(begin(vals), end(vals), pa.second) - begin(vals);
        int b = get(0, i - 1);
        upd(i, b + 1);
    }
    int best = get(0, vals.size());

    const double pi = 3.1415926535897938;


    double res = (to.first + to.second) * 100.0 - best * (20 - 5.0 * pi);
    if (best == 1 + min(to.first, to.second))
        res += 5.0 * pi;

    cout << fixed << setprecision(15);


    cout << res << endl;

}


Measured memory_bytes: 5232
#include <stdio.h>

int main (void)
{
	int n, i, j, numbers[10], temp;
	
	for (n = 0; n < 10; n++) 
		scanf("%d", &numbers[n]);
		
	for (i = 0; i < 9; i++) {
		for (j = 9; j > i; j--) {
			if (numbers[j-1] < numbers[j]) {
				temp = numbers[j-1];
				numbers[j-1] = numbers[j];
				numbers[j] = temp;
			}
		}
	}	
	
	printf("%d\n%d\n%d\n", numbers[0], numbers[1], numbers[2]);
	
	return 0;
	
}

Measured memory_bytes: 0
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<string>
#include<cmath>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<sstream>
#include<bitset>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;


int main()
{
    int N, H, W;
    scanf("%d%d%d", &N, &H, &W);
    int ans = 0;
    while(N--) {
        int a, b;
        scanf("%d%d", &a, &b);
        if(a>=H && b>=W) ++ans;
    }
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 256
# coding: utf-8
import numpy as np
n = int(input())
a = np.array(list(map(int, input().split())))
a = np.insert(a,0,0)
#print(a)
box = np.zeros(n+1,dtype="int32")
#print(box)

for i in range((n//2)+1,n+1):
    if a[i] == 1:
        box[i] = 1
        
for i in reversed(range(1,(n//2)+1)):
    # odd
    if a[i]==1:
        if np.sum(box[i::i])%2==0:
            box[i] = 1
        else:
            box[i] = 0
    # even
    else:
        if np.sum(box[i::i])%2==1:
            box[i] = 1
        else:
            box[i] = 0
m = np.sum(box)
ans_index = np.where(box==1)[0]
#print(ans_index)
ans_index = map(str, ans_index)
print(m)
if m!=0:
    ans = " ".join(ans_index)
    print(ans)

Measured memory_bytes: 23912
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner std = new Scanner(System.in);
		int n = Integer.parseInt(std.next());
		int max = -1000001;
		int min = 1000001;
		long sum = 0;
		for(int i=1; i<=n; i++ ){
			int nxt = Integer.parseInt(std.next());
			if (max<nxt) max = nxt;
			if (nxt<min) min = nxt;
			sum += nxt;
		}
		System.out.println(min+" "+max+" "+sum);
	}
}

Measured memory_bytes: 39784
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

public class Main{
  public static void main(String[] args) throws IOException {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    String[] str = in.readLine().split(" ");
    int A = Integer.parseInt(str[0]);
    int B = Integer.parseInt(str[1]);
    int C = Integer.parseInt(str[2]);
    System.out.println(C + " " + A + " " + B);
  }
}

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

#define rep(i,s,n) for (int i = (int)s; i < (int)n; i++)
#define ll long long
#define pb push_back
#define eb emplace_back
#define All(x) x.begin(), x.end()
#define Range(x, i, j) x.begin() + i, x.begin() + j
#define lbidx(x, y) lower_bound(x.begin(), x.end(), y) - x.begin()
#define ubidx(x, y) upper_bound(x.begin(), x.end(), y) - x.begin()
#define llbidx(x, y, z) lower_bound(x.begin(), x.end(), z) - lower_bound(x.begin(), x.end(), y) // 二要素間の距離
#define deg2rad(deg) ((((double)deg)/((double)360)*2*M_PI))
#define rad2deg(rad) ((((double)rad)/(double)2/M_PI)*(double)360)
#define Find(set, element) set.find(element) != set.end()
#define Decimal(x) printf("%.10f\n", x) // 小数点を10桁まで表示
// debug用
#define PrintVec(x) for (auto elementPrintVec: x) { cout << elementPrintVec << " "; } cout << endl;

typedef pair<int, int> PI;
typedef pair<ll, ll> PLL;

int POWINT(int x, int n) {
  int ret = 1;
  rep(i, 0, n) ret *= x;
  return ret;
};

ll POWLL(int x, int n) {
  ll ret = 1;
  rep(i, 0, n) ret *= x;
  return ret;
};

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

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

vector<PI> statement[16];

bool check(vector<int> T) {
  set<int> s;
  for (int p: T) {
    s.insert(p);
  }
  for (int p: T) {
    for (PI pi: statement[p]) {
      if (pi.second == 0) {
        if (Find(s, pi.first)) {
          return false;
        }
      }
      if (pi.second == 1) {
        if (!(Find(s, pi.first))) {
          return false;
        }
      }
    }
  }

  return true;
};

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

  int n;
  cin >> n;
  rep(i, 0, n) {
    int A;
    cin >> A;
    int x, y;
    rep(j, 0, A) {
      cin >> x >> y;
      x--;
      statement[i].pb(make_pair(x, y));
    }
  }

  int ans = 0;
  rep(i, 0, 1 << n) {
    vector<int> T;
    rep(j, 0, n) { // j人目が正直者かどうか
      if ((i >> j) & 1 == 1) {
        T.pb(j);
      }
    }
    // cout << "print: ";
    // PrintVec(T);
    if (T.empty()) continue;

    if (check(T)) {
      ans = max(ans, (int)T.size());
    }
  }

  cout << ans << endl;

  return 0;
};


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

int main()
{
  	int count = 0;
	string S, T;
  	cin >> S >> T;
  	for(int i = 0; i < S.length(); i++)
      if(S[i] == T[i])	count++;
  	cout << count << endl;
	return 0; 
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define MOD 1000000007
#define INF 100000000
#define MAX 100001
#define int ll
#define ll long long
#define ld long double
#define vi vector<int>
#define pa pair<int, int>
#define pb push_back
#define mp make_pair
 
#define INIT ios::sync_with_stdio(false);cin.tie(0);
#define VAR(type, ...)type __VA_ARGS__;MACRO_VAR_Scan(__VA_ARGS__);
template<typename T> void MACRO_VAR_Scan(T& t) { cin >> t; }
template<typename First, typename...Rest>void MACRO_VAR_Scan(First& first, Rest&...rest) { cin >> first; MACRO_VAR_Scan(rest...); }
#define VEC(type, c, n) vector<type> c(n);for(auto& i:c)cin>>i;
#define MAT(type, c, m, n) vector<vector<type>> c(m, vector<type>(n));for(auto& r:c)for(auto& i:r)cin>>i;
 
#define BR cout << "\n";
#define SP cout << " ";
#define ENDL cout<<endl;
#define OUT(d) cout<<(d);
#define OUTL(d) cout<<(d)<<endl;
#define YES OUTL("YES")
#define Yes OUTL("Yes")
#define NO OUTL("NO")
#define No OUTL("No")
#define RET return 0;
 
#define REP(i, n) for(int i=0;i<(n);i++)
#define RREP(i, n) for(int i=n-1;i>=0;--i)
#define FOR(i, m, n) for(int i = m;i < n; i++)
#define RFOR(i, a, b) for(int i=(a)-1;i>=(b);--i)
#define AREP(a, n) for(auto (a):(n))
#define ALL(a) (a).begin(),(a).end()
#define IN(n, a, b) ((a)<=(n)&&(n)<(b))

vector<pair<int, int>> g[100000];
int f[100000] = {}, c[100000] = {};

void dfs(int pos, int cost){
    // OUT(pos); SP; OUTL(cost);
    f[pos] = 1;
    c[pos] = cost;
    AREP(p, g[pos]) if(!f[p.first]) dfs(p.first, cost + p.second);
}

signed main(){ INIT;
    VAR(int, n, m);
    int l[m], r[m], d[m];
    REP(i, m){
        cin >> l[i] >> r[i] >> d[i];
        l[i]--; r[i]--;
        g[l[i]].push_back(make_pair(r[i],  d[i]));
        g[r[i]].push_back(make_pair(l[i], -d[i]));
    }
    REP(i, n){
        if(!f[i]){
            f[i] = 1; c[i] = 0;
            AREP(p, g[i]) if(!f[p.first]) dfs(p.first, p.second);
        }
    }
    REP(i, m){
        if(c[r[i]] - c[l[i]] != d[i]){
            No; RET;
        }
    }
    Yes;
RET;}


Measured memory_bytes: 20992
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
using namespace std;
int main() {
    long long int N, A, B;
    cin >> N >> A >> B;
    long long int ans = 0;
    ans +=  (N / (A + B)) * A;
    long long int R = N % (A + B);
    ans += min(R, A);
    cout << ans << endl;
}


Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;
 
public class Main {
	public static void main (String[] args) {
      Scanner sc = new Scanner(System.in); 
   
        // Character input 
       char c = sc.next().charAt(0); 
       if(c>='A' && c<='Z'){
         System.out.println("A");
       }else{
       	System.out.println("a");
       }
    }
}

Measured memory_bytes: 35292
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <utility>
#include <climits>
#include <bitset>

using namespace std;
#define li long long int
#define FOR(i, a, b) for (int i = a ; i < b ; ++i)
#define REP(i, n) for (int i = 0 ; i < n ; ++i)

li gcd(li a,li b) {
    return a % b == 0 ? b : gcd(b, a % b);
}

int main(void) {
    li N, A, B;
    cin >> N >> A >> B;

    string s;
    cin >> s;
    li foreignPassed = 0;
    li passed = 0;

    FOR(i, 0, s.length()) {
        if (s[i] == 'a') {
            // 国内
            if (passed < (A + B)) {
                cout << "Yes" << endl;
                passed += 1;
            } else {
                cout << "No" << endl;
            }
        } else if (s[i] == 'b') {
            // 海外
            if (passed < A + B && foreignPassed < B) {
                cout << "Yes" << endl;
                passed += 1;
                foreignPassed += 1;
            } else {
                cout << "No" << endl;
            }
        } else {
            // neither
            cout << "No" << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (ll i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define m1(x) memset(x,-1,sizeof(x))
const int INF = 1000000001;
const ll MOD = 1000000007;

int main(){
  int n ,k;
  cin >> n >> k;
  if(n%k == 0){
    cout << 0 <<endl;
  }else{
    cout << 1 <<endl;
  }
}

Measured memory_bytes: 256
import java.util.Scanner;

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

		int x = sc.nextInt();
		int a = sc.nextInt();

		if (x < a) {
			System.out.println("0");
		} else {
			System.out.println("10");
		}
		sc.close();
	}
}

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

int main()
{ 
  int n, d, ans = 0, sn, sqsn;
  vector<vector<int>> x(10, vector<int>(10));

  cin >> n >> d;
  for (int i = 0; i < n; i++)
  {
    for (int j = 0; j < d; j++)
      cin >> x[i][j];
  }
  for (int i = 0; i < n - 1; i++)
  {
    for (int j = i + 1; j < n; j++)
    {
      sn = 0;
      for (int k = 0; k < d; k++)
        sn += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
      sqsn = (int)sqrt(sn);
      if (sn == sqsn * sqsn)
        ans++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#ifdef _MSC_VER
#include <__msvc_all_public_headers.hpp>
#undef min
#undef max
#else
#define NDEBUG
#include <bits/stdc++.h>
#endif

using namespace std;
using large = long long;
constexpr int M = 1'000'000'007;

int main()
{
    int n;
    cin >> n;
    auto a = vector<large>(n);
    for (auto& a_i : a) {
        cin >> a_i;
    }
    auto a_sum = vector<large>(n + 1);
    a_sum[0] = 0;
    for (auto i = 0; i < n; ++i) {
        a_sum[i + 1] = a_sum[i] + a[i];
    }

    auto sum = 0LL;
    for (int i = 0; i < n-1; ++i) {
        auto tmp = (a_sum[n] - a_sum[i+1]) % M;
        sum += a[i] * tmp % M;
        sum %= M;
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 6428
#include <stdio.h>

int main(){
	int a,b,c;
	int N,i;

	scanf("%d",&N);
	for(i=0; i<N; i++){
		scanf("%d %d %d",&a,&b,&c);
			if((a*a==b*b+c*c) || (b*b==a*a+c*c) || (c*c==a*a+b*b)){
				printf("YES\n");
			}
			else{
				printf("NO\n");
			}
	}
	return 0;
}

Measured memory_bytes: 580
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+5;
vector<pair<int,int> >g[N];
int ans[N],tot,vis[N];
void dfs(int x,int pre){
	vis[x]=1;
	if(x==1)tot=max(tot,(int)g[x].size());
	 else tot=max(tot,(int)g[x].size());
	int cur=0;
	for(int i=0;i<g[x].size();i++){
		int v=g[x][i].first,id=g[x][i].second;
		if(vis[v])continue;
		++cur;
		if(cur==pre)
		 if(cur==tot)cur=1;
		 else cur++;
		  ans[id]=cur;
		 dfs(v,cur);
	}
}
int main(){
	int n;
	ios::sync_with_stdio(false);cin.tie(0);
	cin>>n;
	for(int i=1;i<n;i++){
		int x,y;
		cin>>x>>y;
	//	g[x].push_back({y,i});
	//	g[y].push_back({x,i});	
		g[x].push_back(make_pair(y,i));
		g[y].push_back(make_pair(x,i));
	}
	dfs(1,0);
	cout<<tot<<endl;
	for(int i=1;i<n;i++)cout<<ans[i]<<endl;
}

Measured memory_bytes: 7680
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//namespace mp = boost::multiprecision;

using namespace std;

const double PI = 3.14159265358979323846;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
typedef pair<ll, ll> P;
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

double equal(double a, double b) {
    return fabs(a - b) < DBL_EPSILON;
}

std::istream &operator>>(std::istream &in, set<int> &o) {
    int a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

typedef priority_queue<ll, vector<ll>, greater<ll> > PQ_ASK;

int main() {
    string s;
    cin >> s;
    int n = s.size();

    if (*max_element(s.begin(), s.end()) == *min_element(s.begin(), s.end())) {
        cout << n << endl;
        ret();
    }

    int ans = INT_MAX;
    rep(i, n - 1) {
        if (s[i] == s[i + 1]) continue;
        int l = i + 1;
        int r = n - i - 1;
        int ma = max(l, r);
        cmin(ans, ma);
    }
    cout << ans << endl;
}


Measured memory_bytes: 3716
#include <bits/stdc++.h>
using namespace std;
const int N = 405;
const int mod = 998244353;
inline void Add(int &x, int y) {
	x += y;
	if (x >= mod) x -= mod;
}
int fact[N], ifact[N], inv[N], C[N][N];
inline void init_fact(int n) {
	inv[1] = 1;
	for (int i = 2; i <= n; i++)
		inv[i] = 1ll * (mod - mod / i) * inv[mod % i] % mod;
	fact[0] = ifact[0] = 1;
	for (int i = 1; i <= n; i++) {
		fact[i] = 1ll * fact[i - 1] * i % mod;
		ifact[i] = 1ll * ifact[i - 1] * inv[i] % mod;
	}
	C[0][0] = 1;
	for (int i = 1; i <= n; i++) {
		C[i][0] = 1;
		for (int j = 1; j <= i; j++)
			C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]) % mod;
	}
}
int n, a[N], b[N], p[N];
int coef[N][N], tc[N][N];
int f[N], s[N];
int main() {
	init_fact(400);
	scanf("%d", &n);
	int sum_a = 0;
	for (int i = 0; i < n; i++) {
		scanf("%d%d", &a[i], &b[i]);
		Add(sum_a, a[i]);
	}
	for (int i = 0; i < n; i++) {
		p[i] = 1ll * inv[sum_a] * a[i] % mod;
	}
	coef[0][0] = 1;
	int sx = 0, sy = 0;
	for (int i = 0; i < n; i++) {
		memset(tc, 0, sizeof(tc));
		for (int j = 0; j <= sx; j++) {
			for (int k = 0; k <= sy; k++) if (coef[j][k]) {
				Add(tc[j][k + a[i]], coef[j][k]);
				for (int l = 0, prd = 1; l < b[i]; l++, prd = 1ll * prd * p[i] % mod) {
					Add(tc[j + l][k], 1ll * prd * ifact[l] % mod * (mod - 1) % mod * coef[j][k] % mod);
				}
			}
		}
		sx += b[i] - 1;
		sy += a[i];
		memcpy(coef, tc, sizeof(tc));
	}
	for (int i = 0; i <= sx; i++)
		for (int j = 0; j <= sy; j++)
			if (coef[i][j]) coef[i][j] = mod - coef[i][j];
	coef[0][sy] = (coef[0][sy] + 1) % mod;
	int ans = 0;
	for (int i = 0; i <= sx; i++) if (coef[i][0]) {
		Add(ans, 1ll * coef[i][0] * fact[i] % mod);
	}
	for (int j = 1; j <= sy; j++) if (coef[0][j]) {
		Add(ans, 1ll * coef[0][j] * sy % mod * inv[sy - j] % mod);
	}
	for (int j = 1; j < sy; j++) {
		f[0] = 1ll * sy * inv[sy - j] % mod;
		for (int i = 1; i <= sx; i++) {
			f[i] = 0;
			for (int k = 0; k < i; k++) {
				Add(f[i], 1ll * C[i][k] * f[k] % mod);
			}
			f[i] = 1ll * f[i] * j % mod * inv[sy - j] % mod;
		}
		memset(s, 0, sizeof(s));
		s[0] = 1;
		for (int i = 1; i <= sx; i++) {
			for (int k = i; k >= 0; k--) {
				s[k] = (1ll * s[k] * i % mod + (k ? s[k - 1] : 0)) % mod;
				Add(ans, 1ll * s[k] * f[k] % mod * coef[i][j] % mod);
			}
		}
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 2176
a,b,c,x,y = map(int, input().split())

ans = 0
if a > 2*c and x > 0:
  ans += x*2*c
  y -= x
  x = 0
if b > 2*c and y > 0:
  ans += y*2*c
  x -= y
  y = 0
if a+b >= 2*c and x > 0 and y > 0:
  ans += 2*c*min(x,y)
  if x < y:
    y -= x
    x = 0
  elif y < x:
    x -= y
    y = 0
  else:
    x,y = 0,0
if x > 0: ans += x*a
if y > 0: ans += y*b
print(ans)

Measured memory_bytes: 9200
import numpy as np
# 入力処理
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())

# 最後に注文する品を決める関数
def get_last_dish_index(order_list):
    """
    process: 10で割ったときの剰りが最も小さい要素のindexを求める
             (ただし、剰りが0の場合を除く)
    ===========
    input: int[]
    output: int
    """
    rem_list = list()
    for order in order_list:
        if order % 10 == 0:
            rem_list.append(0)
        else:
            rem_list.append(10 - order % 10)
    # print(rem_list)
    last_dish_index = rem_list.index(max(rem_list))
    return last_dish_index

order_list = [a, b, c, d, e]
ldi = get_last_dish_index(order_list)
last_order = order_list.pop(ldi)

time = 0
for order in order_list:
    if order % 10 == 0:
        time += order
    else:
        time += order + (10 - order % 10)

print(time+last_order)

Measured memory_bytes: 21140
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
*/

int main(){
    int X, Y, Z, K; cin >> X >> Y >> Z >> K;
    vector<ll> a(X);
    vector<ll> b(Y);
    vector<ll> c(Z);

    for(int i=0; i<X; i++) cin >> a[i];
    for(int i=0; i<Y; i++) cin >> b[i];
    for(int i=0; i<Z; i++) cin >> c[i];

    vector<ll> v;
    for(int i=0; i<X; i++) for(int j=0; j<Y; j++) v.push_back(a[i]+b[j]);
    sort(v.begin(), v.end(), greater<ll>());

    vector<ll> v2;
    for(int i=0; i<min((ll)K, (ll)v.size()); i++) for(int j=0; j<Z; j++) v2.push_back(v[i]+c[j]);
    sort(v2.begin(), v2.end(), greater<ll>());


    for(int i=0; i<K; i++) cout << v2[i] << endl;
}
    

Measured memory_bytes: 43112
import scala.collection.mutable.Queue

object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val n, m = sc.nextInt()
  val e = List.fill(m)((sc.nextInt()-1, sc.nextInt()-1))

  def isConnected(s: Int, t: Int, n: Int, edges: Seq[(Int, Int)]): Boolean = {
    val adj = Array.fill(n)(List[Int]())
    for ((u,v) <- edges if (u, v) != (s, t)) {
      adj(u) ::= v
      adj(v) ::= u
    }

    val visited = Array.fill(n)(false)
    visited(s) = true
    val queue = Queue(s)
    while (!visited(t) && queue.nonEmpty) {
      val u = queue.dequeue()
      for (v <- adj(u) if !visited(v)) {
        visited(v) = true
        queue.enqueue(v)
      }
    }
    visited(t)
  }

  val ans = e.count{case (a, b) => !isConnected(a, b, n, e)}
  println(ans)
}


Measured memory_bytes: 58444
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
	int n;
	long long k;

	cin >> n >> k;

	vector<int> a(n);
	vector<int> f(n);

	int i;

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

	for (i = 0; i < n; i++) {
		cin >> f[i];
	}

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

	long long l = -1;
	long long r = 1000000000000000000;
	long long c = 0;
	long long t = 0;

	while (l + 1 < r) {
		c = (l + r) / 2;
		t = 0;

		for (i = 0; i < n; i++) {
			t += max(0ll, a[i] - (c / f[n - i - 1]));
		}

		if (t > k) {
			l = c;
		}
		else {
			r = c;
		}
	}

	cout << r << endl;

	return 0;
}


Measured memory_bytes: 1792
/*
 * atcoder/abc130/a.cpp
 */

// C++ 14
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstring> // memset
#include <cassert>

using namespace std;

#define ll long long

#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)
template <class T> bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false; }
template <class T> bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false; }

int N, P[11];

void input() {
  cin >> N;
  int max_ = 0;
  int total = 0;
  loop(n,0,N) {
    cin >> P[n];
    chmax(max_, P[n]);
    total += P[n];
  }

  total -= max_ / 2;
  cout << total << endl;
}

int main() {
  // cout.precision(15);
  input();
  return 0;
}


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

int N, T, ans;

int main(void) {
    cin >> N >> T;
    int nowTime[200000];
    for (int i = 0; i < N; i++) {
        cin >> nowTime[i];
    }
    for (int i = 1; i < N; i++) {
        ans += min(T, nowTime[i]-nowTime[i-1]);
    }
    cout << ans+T << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>
#include <string.h>

int main(void)
{
	long long ans[100][21];
	int i, j;
	int n, num[100];
	
	scanf("%d", &n);
	memset(num, 0, sizeof(num));
	memset(ans, 0, sizeof(ans));
	for (i = 0; i < n; i++){
		scanf("%d", &num[i]);
	}
	ans[0][num[0]] = 1;
	for (i = 1; i < n - 1; i++){
		for (j = 0; j < 21; j++){
			if (0 <= j + num[i] && j + num[i] <= 20){
				ans[i][j + num[i]] += ans[i - 1][j];
			}
			if (20 >= j - num[i] && j - num[i] >= 0){
				ans[i][j - num[i]] += ans[i - 1][j];
			}
		}
	}
	
	printf("%lld\n", ans[n - 2][num[n - 1]]);
	
	return (0);
}

Measured memory_bytes: 0
program shift_and_flip
  implicit none
  character(2000) :: a, b
  integer :: n, x(2000) = 0, y(2000) = 0, i, ans = 1e9
  read(*,*) a
  read(*,*) b
  n = len_trim(a)
  do i = 1, n
    if (a(i:i) == "1") x(i) = 1
    if (b(i:i) == "1") y(i) = 1
  end do
  if (all(y(1:n) == 0)) then
    if (any(x(1:n) == 1)) then
      write(*,'(i0)') -1
    else
      write(*,'(i0)') 0
    end if
    stop
  end if
  call solve()
  x(1:n) = x(n:1:-1)
  y(1:n) = y(n:1:-1)
  call solve()
  write(*,'(i0)') ans
contains
  integer function idx(i)
    integer, intent(in) :: i
    idx = modulo(i-1,n)+1
  end
  subroutine solve()
    integer :: i, j, l(n), r(n), m(0:n-1), cnt, tmp
    cnt = 0
    do i = 1, n
      l(i) = 0
      do while (y(idx(i-l(i))) == 0)
        l(i) = l(i)+1
      end do
      r(i) = 0
      do while (y(idx(i+r(i))) == 0)
        r(i) = r(i)+1
      end do
    end do
    do i = 0, n-1
      m = 0
      cnt = 0
      do j = 1, n
        if (x(j) /= y(idx(j+i))) then
          m(l(j)) = max(m(l(j)),r(j))
          cnt = cnt+1
        end if
      end do
      tmp = 0
      do j = n-1, 0, -1
        ans = min(ans,2*j+tmp+abs(tmp-i)+cnt)
        tmp = max(tmp,m(j))
      end do
    end do
  end
end program shift_and_flip

Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var (
		n int
		s string
	)
	fmt.Scan(&n, &s)

	ans := "No"
	if len(s)%2 == 0 {
		half := len(s) / 2
		if s[:half] == s[half:] {
			ans = "Yes"
		}
	}
	fmt.Println(ans)
}


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

#define rep(i, a, b) for (int i = int(a); i < int(b); i++)
#define rrep(i, a, b) for (int i = int(a) - 1; i >= b; i--)
#define sz(x) (int)(x).size()

using namespace std;
using ll = long long;

const ll INF = 1e18;
const ll MOD = 1e9 + 7;

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

  ll ok = true;
  rep(i, 0, n) {
    if (a[i] % 2 == 0) {
      if (a[i] % 3 == 0 || a[i] % 5 == 0) {
      } else {
        ok = false;
      }
    }
  }
  if (ok) {
    cout << "APPROVED" << endl;
  } else {
    cout << "DENIED" << endl;
  }
}

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

void solve() {
    ll K, X;
    cin >> K >> X;
    ll mn = X - K + 1;
    ll mx = X + K - 1;
    if (mn < -1000000) mn = -1000000;
    if (mx > 1000000) mx = 1000000;
    for ( int i = mn; i <= mx; i++ ) {
        cout << i << " ";
    }
    cout << "\n";
}

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

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

a = [int(i) for i in input().split()]

a.sort(reverse=True)
mod = 10**9+7
ans = 1

for i in range(n):
    #print(i,i%2)
    if a[i] != n - 1 - 2*int(i*0.5):
        print(0)
        exit()
    elif i % 2 == 1:
        #print(ans)
        ans = ans * 2 % mod
        
        
print(ans)

Measured memory_bytes: 13880
#include <stdio.h>
#include <stdlib.h>

typedef struct dice{
  int pip[6];
  int top, front, right;
}Dice;

Dice *createDice(int *a);              /* ?????????????????? */
int DiceRight(Dice *D, int t, int f);  /* ????????????????????´?????°??? */


int main(void){
  Dice *D;
  int i, n, a[6], t, f, ans;

  for(i = 0; i< 6; i++){
    scanf("%d", &a[i]);
  }
  D = createDice(a);
  scanf(" %d", &n);
  for(i = 0; i < n; i++){
    scanf("%d%d", &t, &f);
    ans = DiceRight(D, t, f);
    printf("%d\n", ans);
  }
  free(D);
  return 0;
}


Dice *createDice(int *a){
  Dice *p;
  int i;

  p = (Dice *)malloc(sizeof(Dice));
  if(p == NULL){
    printf("?????¢????¢??????¨??????\n");
    return NULL;
  }
  for(i = 0; i < 6; i++){
    p->pip[i] = a[i];
  }
  p->top = 0;
  p->front = 1;
  p->right = 2;
  return p;
}

int DiceRight(Dice *D, int t, int f){
  int i, tj = 0, fj = 0;
  static int check[6][6] = {{-1, 2, 4, 1, 3, -1},
			    {3, -1, 0, 5, -1, 2},
			    {1, 5, -1, -1, 0, 4},
			    {4, 0, -1, -1, 5, 1},
			    {2, -1, 5, 0, -1, 3},
			    {-1, 3, 1, 4, 2, -1}};
  for(i = 0; i < 6; i++){
    if(D->pip[i] == t){
      tj = i;
    }
    if(D->pip[i] == f){
      fj = i;
    }
  }
  return D->pip[check[tj][fj]];
}

Measured memory_bytes: 596
class Dice:
    def __init__(self, a, b, c, d, e, f):
        # サイコロの現在一番上にある面
        self.a = a
        self.b = b
        self.c = c
        self.d = d
        self.e = e
        self.f = f

    def move(self, move_str):
        for i in move_str:
            if i == "N":
                self.move_N()
            elif i == "E":
                self.move_E()
            elif i == "W":
                self.move_W()
            elif i == "S":
                self.move_S()

    def move_N(self):
        tmp1 = self.a
        tmp2 = self.e
        self.a = self.b
        self.b = self.f
        self.e = tmp1
        self.f = tmp2

    def move_E(self):
        tmp1 = self.a
        tmp2 = self.c
        self.a = self.d
        self.c = tmp1
        self.d = self.f
        self.f = tmp2

    def move_W(self):
        tmp1 = self.a
        tmp2 = self.d
        self.a = self.c
        self.c = self.f
        self.d = tmp1
        self.f = tmp2

    def move_S(self):
        tmp1 = self.a
        tmp2 = self.b
        self.a = self.e
        self.b = tmp1
        self.e = self.f
        self.f = tmp2
    """
    def debug(self):
        print("--------")
        print(f"{self.a=}")
        print(f"{self.b=}")
        print(f"{self.c=}")
        print(f"{self.d=}")
        print(f"{self.e=}")
        print(f"{self.f=}")
        print("--------")
    """

a, b, c, d, e, f = map(int, input().split())
dice = Dice(a, b, c, d, e, f)
li = list(input())
dice.move(li)
print(dice.a)



Measured memory_bytes: 5620
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin, log, log10
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 debug(*args):
    if debugmode:
        print(*args)
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def FLOAT(): return float(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()))
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7
dx = [0, 0, 1, -1, 1, -1, -1, 1]
dy = [1, -1, 0, 0, 1, -1, 1, -1]
debugmode = False

a = LIST()
a.sort()
to = a[-1]
if 3 * to % 2 != sum(a) % 2:
    to += 1
plus = [0, 0, 0]
for i in range(3):
    plus[i] = to - a[i]
debug(plus)
ans = 0
if plus[2]:
    ans += 1
    plus[2] = 0
    mx = max(plus[:2])
    plus[plus.index(mx)] -= 1
debug(plus)
plus = plus[:2]
ans += min(plus) + (max(plus) - min(plus)) // 2
print(ans)

Measured memory_bytes: 60012
import java.util.*;

class Main {
  public static final int MOD = 1000000007;
  public static final int INF = 1000000000;
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int M = sc.nextInt();
    Integer A[] = new Integer[N];
    Integer D[][] = new Integer[M][2];
    for(int i=0; i<N; i++) A[i] = sc.nextInt();
    for(int i=0; i<M; i++){
      D[i][0] = sc.nextInt();
      D[i][1] = sc.nextInt();
    }
    Arrays.sort(A);
    Arrays.sort(D, (a,b) -> Integer.compare(a[1], b[1]));
    int j = 0;
    int k;
    boolean check = true;
    for(int i=M-1; i>=0; i--){
      if(check == false) break;
      k = 0;
      while(k < D[i][0]){
        if(j >= N){
          check = false;
          break;
        }
        if(A[j] < D[i][1]){
          A[j] = D[i][1];
          j++;
          k++;
        }else{
          check = false;
          break;
        }
      }
    }
    long ans = 0L;
    for(int i=0; i<N; i++){
      ans += A[i];
    }
    System.out.println(ans);
  }

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

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

ll patty(int x){
    if(x==0) return 1;
    else return patty(x-1)*2+1;
}

ll burger(int n){
    if(n==0) return 1;
    else return burger(n-1)*2+3;
}

int main(void){
    ll n,x; cin >> n >> x;
    ll ans = 0;
    ll layer = burger(n)/2+1;
    // cout << layer*2-1 << endl;
    while(true){
        // cout << ans << endl;
        if(n==0){
            if(layer <= x){
                ans++;
            }
            break;
        }
        ll add_layer = burger(n-1)/2+1;
        if(layer == x){
            ans += patty(n-1)+1;
            break;
        }
        else if(layer < x){
            layer += add_layer;
            ans += patty(n-1)+1; 
            n--;
        }else{
            layer -= add_layer;
            n--;
        }
    }
    cout << ans << endl;
    return 0;
}

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

int main() {
    int n;
    string s;
    bool ans = true;
    cin >> n >> s;
    if (n % 2 == 0) {
        for (unsigned int i = 0, len = n / 2; i < len; i++) {
            if (s.at(i) != s.at(len + i))
                ans = false;
        }
    } else {
        ans = false;
    }
    cout << (ans ? "Yes" : "No") << endl;
}


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

int main() {
    int n, a, b; cin >> n >> a >> b;
    deque<int> ans;
    if ((long long) a * b < (long long) n) {
        cout << -1 << endl;
        return 0;
    }
    if (max(a, b) == n && min(a, b) != 1) {
        cout << -1 << endl;
        return 0;
    }
    if (a + b > n+1) {
        cout << -1 << endl;
        return 0;
    }
    for (int i = 0; i < b; i++) {
        ans.push_back(b-i);
    }
    a--; int cur = b; int end = n-a;
    while (a) {
        ans.push_back(n-a+1);
        int t = min(b-1, end-cur);
        while (t) {
            ans.push_back(cur+t);
            t--;
        }
        cur += min(b-1, end-cur);
        a--;
    }
    for (int i = 0; i < n; i++) {
        if (i) cout << " ";
        cout << ans[i];
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 3456
#include <stdio.h>

int N, M, x[1123], y[1123];
int now = 0, ans;

int main(void) {
	while (true) {
		scanf("%d%d", &N, &M);
		if (N == 0 && M == 0) { break; }
		for (int i = 0; i < N; ++i) { scanf("%d", &x[i]); }
		for (int i = 0; i < M; ++i) { scanf("%d", &y[i]); }

		now = 0;
		for (int i = 0; i <= M; ++i) {
			if (N - 1 <= now) {
				ans = i;
				break;
			}
			now += y[i];
			now += x[now];
		}
		printf("%d\n", ans);
	}

	return 0;
}

Measured memory_bytes: 2548
#include <iostream>
#include <vector>
#include <queue>

using namespace std;
int main(){
	long long n,m;
	cin >> n >> m;
	if(n == 1){
		if(m == 1){
			cout << 1 << endl;
		}else{
			cout << m-2 << endl;
		}
	}else if(m == 1){
		cout << n-2 << endl;
	}else{
		cout << (n-2)*(m-2) << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
int cmp(const void *a,const void *b){
    if(*(int*)a>*(int*)b){return 1;}
    else if(*(int*)a<*(int*)b){return -1;}
    else {return 0;}
}


int gcd(int a,int b){
    int aa=a;
    int bb=b;
    int cc;
for(;;){
    if(aa%bb==0){return bb;}
    else{cc=aa%bb;aa=bb;bb=cc;}
}

}

int main(void){
int k;
int sum=0;
scanf("%d",&k);
for(int i=1;i<=k;i++){
    for(int j=1;j<=k;j++){
        for(int m=1;m<=k;m++){
            sum=sum+gcd(gcd(i,j),m);
        }
    }
}
printf("%d\n",sum);
}


Measured memory_bytes: 1732
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i < b; i++)
#define Rep(i, a, b) for(int i = a; i <= b; i++)
#define _GLIBCXX_DEBUG
#define Vl vector<ll>
#define Vs vector<string>
#define Vp vector<pair<ll, ll>>
#define P pair<ll, ll>
using ll = long long;
#define ALL(v) (v).begin(),(v).end()
#define endl "\n"
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define co(x) cout << x << endl
#define coel cout << endl
#define pb push_back
#define sz(v) ((ll)(v).size())
using namespace std;  
const double pi = acos(-1.0);
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
#define pp pair<ll, pair<ll, ll>> 




////////////////////////////////////////////////////////


int main() {
    ll n; cin >> n;
    Vl l(2*n);
    rep(i, 0, 2*n) cin >> l[i];
    sort(ALL(l));
    ll ans = 0;
    rep(i, 0, n){
        ans += min(l[2*i], l[2*i+1]);
    }
    co(ans);

    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<iostream>

using namespace std;

int main()
{
	int r, g, b;
	cin >> r >> g >> b;

	int cou = r*100 + g*10 + b;

	if (cou % 4 == 0) {
		cout << "YES" << "\n";
	}
	else cout << "NO" << "\n";

	return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <vector>

using namespace std;

template<typename T>
void swap(T *a, T *b) {
	T tmp = *a;
	*a = *b;
	*b = tmp;
}

template<typename T>
void showArray(T A[], int N) {
	for (int i = 0; i < N - 1; i++) {
		cout << A[i] << " ";
	}
	cout << A[N - 1] << endl;
}

template<typename T>
void insertionSort(T A[], int N) {
	showArray<T>(A, N);
	for (int i = 1; i < N; i++) {
		int tmp = A[i];
		int j = i-1;
		while (j >= 0 && A[j] > tmp) {
			A[j + 1] = A[j];
			j--;
		}
		A[j + 1] = tmp;
		showArray<T>(A, N);
	}
}



int main() {

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

	insertionSort<int>(A, N);

	return 0;
}

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

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

const int INF = 1e9 + 7;

using namespace std;

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

	int n;
	cin >> n;

	vector<int> a(n);
	vector<vector<pair<int, int>>> v(n);
	rep (i, 0, n) {
		cin >> a[i];
		rep (j, 0, a[i]) {
			int x, y;
			cin >> x >> y;

			v[i].push_back(make_pair(x, y));
		}
	}

	int res = 0;
	rep (i, 0, (1 << n)) {
		int n_honest = 0;
		rep (j, 0, n) {
			if ((1 << j) & i)
				n_honest++;
		}

		bool judge = true;
		rep (j, 0, n) {
			if (!((1 << j) & i))
				continue;

			rep (k, 0, a[j]) {
				int x = v[j][k].first;
				int y = v[j][k].second;

				int bit = (((1 << (x - 1)) & i) > 0 ? 1 : 0);
				if (bit != y)
					judge = false;
			}
		}
		if (judge)
			res = max(res, n_honest);
	}

	cout << res << endl;
	return 0;
}


Measured memory_bytes: 256