akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
const long long MOD = 1000000007;
using namespace std;
typedef long long ll;
map<ll, int> mp;
signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin >> n;
	vector<int> a(n);
	rep(i, n) cin >> a[i];
	ll ans = 1e20;
	ll sum = 0;
	rep(i, n) {
		sum += a[i];
	}
	ll tmp = 0;
	for (int i = 0; i < n; i++) {
		tmp += a[i];
		if (i + 1 < n) ans = min(ans, abs(sum - 2 * tmp));
	}
	cout << ans << endl;
	return 0;
}

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<int, int>;

int main(){
    int h, w, k;
    cin>>h>>w>>k;
    string c[h];
    rep(i, h){
        cin>>c[i];
    }

    deque<int> qh;
    deque<int> qw;

    rep(i, h) qh.push_back(0);
    int ans=0;
    while(!(qh.empty())){
        for(int i=qh.size(); i<h; i++) qh.push_back(0);
        rep(i, w) qw.push_back(0);
        while(!(qw.empty())){
            int sum=0;
            for(int i=qw.size(); i<w; i++) qw.push_back(0);
            rep(i, h)rep(j, w){
                if(c[i][j]=='#'){
                    if(qh[i]!=1 && qw[j]!=1) sum++;
                } 
            }
            while(qw.back()==1){
                qw.pop_back();
                if(qw.empty()) break;
            }
            if(!(qw.empty())){
                qw.pop_back();
                qw.push_back(1);
            }
            if(sum==k) ans++;
        }

        while(qh.back()==1){
            qh.pop_back();
            if(qh.empty()) break;
        }
        if(!(qh.empty())){
            qh.pop_back();
            qh.push_back(1);
        }
    }
    cout<<ans<<endl;
    return 0;
}

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

#define N 50

int main() {
	int n, m;
	cin >> n >> m;
	int A[N+1][N+1], B[N+1][N+1];
	for(int i = 0; i < n; i++)
	{
		for(int j = 0; j < n; j++)
		{
			char x;
			cin >> x;
			A[i][j] = x=='#';
		}
	}
	for(int i = 0; i < m; i++)
	{
		for(int j = 0; j < m; j++)
		{
			char x;
			cin >> x;
			B[i][j] = x=='#';
		}
	}
	for(int i = 0; i < n-m+1; i++)
	{
		for(int j = 0; j < n-m+1; j++)
		{
			int total = 0;
			for(int ii = 0; ii < m; ii++)
			{
				for(int jj = 0; jj < m; jj++)
				{
					if(A[i+ii][j+jj]==B[ii][jj]) 
					{
						total++;
					}
				}
			}
			if(total==m*m)
			{
				cout << "Yes";
				return 0;
			}
		}
	}
	cout << "No";
	return 0;
}

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

using namespace std;

using ll = long long;
constexpr int mo = 1e9+7;
constexpr int inf = 1<<30;
constexpr ll infl = 1ll<<60;

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    string s;
    cin>>s;
    int n = (int)s.size();
    string ret;
    for(int i=0;i<n;++i)ret+="x";
    cout << ret << endl;
    return 0;
}

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

int main() {
    int N;
    cin >> N;
    vector<int> P(N), Q(N);
    rep(i,N) cin >> P.at(i);
    rep(i,N) cin >> Q.at(i);
    vector<int> num(N);
    rep(i,N) num.at(i) = i + 1;
    int a, b;
    int i = 1;
    do {
        if (P == num) a = i;
        if (Q == num) b = i;
        ++i;
    } while (next_permutation(num.begin(), num.end()));
    cout << abs(a - b) << endl;
}


Measured memory_bytes: 3548
n = int(input())
f = n//100
s = n % 100
ans = "NA"
v = 0
if f in range(1, 13) and s in range(0, 100):
	v += 1
	ans = "MMYY"

if s in range(1, 13) and f in range(0, 100):
	v += 1
	ans = "YYMM"

if v > 1 :
	ans = "AMBIGUOUS"

print(ans)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main() {
	ios::sync_with_stdio(false);
	int n;
	cin>>n;
	string s;
	cin>>s;
	if(s.length()<=n){
		cout<<s<<'\n';
	}
	else{
		for(int i=0;i<n;++i)
			cout<<s[i];
		cout<<"..."<<'\n';
	}
	return 0;
}


Measured memory_bytes: 3652
#include<iostream>

using namespace std;

int sd[31];
int main(){
  int a;
  
  for(int i = 0; i < 28; i++){
    cin >> a;
    sd[a] = 1;
  }
  for(int i = 1; i <= 30; i++){
    if(sd[i] == 0) cout << i << endl;
  }
}

Measured memory_bytes: 1160
i=list(map(int,input().split()))

N=i[0]
D=i[1]

points = [list(map(int,input().split())) for i in range(N)]

count=0

for i in range(N):
    if (points[i][0]**2+points[i][1]**2<=D**2):
        count += 1

print(count)

Measured memory_bytes: 45296
N = int(input())
an = map(int, input().split())


def main():
    ar = [0] * 3
    for ai in an:
        if ai % 4 == 0:
            ar[2] += 1
        elif ai % 2 == 0:
            ar[1] += 1
        else:
            ar[0] += 1

    if 0 < ar[1]:
        ar[0] += 1

    print("Yes" if ar[0] - 1 <= ar[2] else "No")
    return


main()


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

#define INF 1e18
#define REP(i, n) for (int i=0; i<n; i++)
#define print(x) cout << x << endl
#define debug(x) cout << #x << " = "<< x << endl

const double PI=3.141592653589793238462643383279502884197169399375105820974944;

typedef long long ll;

using namespace std;

void solve() {
    int N;
    cin >> N;

    int ans = 0;
    for (int i = 1; i <= N; i++) {
        int cnt = 0;
        if (i % 2 == 0) continue;
        for (int j = 1; j <= i; j++) {
            if (i % j == 0) cnt++;
        }
        if (cnt == 8) {
            ans++;
        }
    }
    print(ans);
}

signed main() {
    solve();
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using P   = pair<ll, ll>;
using mat = vector<vector<ll>>;

void IOS() { ios::sync_with_stdio(false), cin.tie(0); }

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

ll mod(ll a) {
	if (a > 0) return a % MOD;
	if (a % MOD == 0) return 0;
	ll x = -a / MOD + 1;
	a += x * MOD;
	return a % MOD;
}

template <typename T> void dump(T x) { cout << x << endl; }
void dumpf(double x, int t) { cout << setprecision(t) << fixed << x << endl; }
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
	fill((T *)array, (T *)(array + N), val);
}
// int dx[4]    = {1, 0, -1, 0};
// int dy[4]    = {0, 1, 0, -1};
// ll pas[5001][5002];

int main() {
	IOS();
	ll k, a, b;
	cin >> k >> a >> b;
	if (a > b || k <= a) {
		dump(k + 1);
		return 0;
	}
	ll ans;
	if ((k - a + 1) % 2 == 0) {
		ll p = (k - a + 1) / 2;
		ans  = max(p * (b - a) + a, k + 1);
	} else {
		ll p = (k - a + 1) / 2;
		ans  = max(p * (b - a) + a + 1, k + 1);
	}
	dump(ans);
}

Measured memory_bytes: 256
#include<iostream>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<limits>
#include<sstream> 
#include<unordered_map>      

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;
typedef vector<int> vi;
typedef vector<ll> vl;

const int inf = numeric_limits<int>::max() >> 2;
const ll linf = numeric_limits<ll>::max() >> 2;
const ull ulinf = numeric_limits<ull>::max() >> 2;
const double pi = acos(-1);
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int dx8[8]={-1,0,1,-1,1,-1,0,1};
const int dy8[8]={-1,-1,-1,0,0,1,1,1};

#define p_queue(i) priority_queue<i> 
#define rp_queue(i) priority_queue<i, vector<i>, greater<i>> 
#define umap(i,j) unordered_map<i,j>
#define P(p) cout<<(p)<<endl
#define PS(p) cout<<(p)<< " "
#define IN cin >> 
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i = (m-1); i >= (int)(n); i--)
#define inrep(n,a) for(int i = 0; i < (int)(n); i++)cin >> a[i];
#define mod(i) ((i)%(ll)(1e9 + 7))
#define divm(a,b) (mod(a * modpow((ll)b,(ll)(1e9+5))))
#define rsort(a,b,c) sort(a, b, greater<c>())
#define vsort(v) sort(v.begin(), v.end())
#define rvsort(v) sort(v.begin(), v.end(), greater<c>()) 
#define ft first
#define sd second
#define pb push_back
#define it insert
#define sz(x) ((int)(x).size())
#define lb(a,n,k) (lower_bound(a,a+n,k) - a) 
#define vlb(a,k)  (lower_bound(a.begin(),a.end(),k) - a.begin())
#define ub(a,n,k) (upper_bound(a,a+n,k) - a) 
#define vub(a,k)  (upper_bound(a.begin(),a.end(),k) - a.begin())
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return

ll modpow(ll i,ll j){ ll tmp=1; while(j){ if(j%2)tmp=mod(tmp*i);i=mod(i*i);j/=2;}return tmp;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

vector<string> split(const string &str, char sep){
    vector<string> v;
    stringstream ss(str);
    string buffer;
    while( getline(ss, buffer, sep) ) {
        v.push_back(buffer);
    }
    return v;
}

//ll ncr[100][100];
//ll nCr(int n, int r){if(n==r) ret ncr[n][r] = 1; if(r==0) ret ncr[n][r] = 1; if(r==1) ret ncr[n][r] = n;if(ncr[n][r]) ret ncr[n][r]; ret ncr[n][r] = nCr(n-1,r) + nCr(n-1,r-1);}

//ll npr[100][100]={};
//ll nPr(int n,int r){if(npr[n][r])ret npr[n][r];if(r==0)ret npr[n][r] = 1;if(r==1)ret npr[n][r] = n;ret npr[n][r] = n * nPr(n-1,r-1);}

//ll nHr(int n,int r){ret nCr(n+r-1,r);}

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


int main(){
    
    int n,k;
    cin >> n >> k;
    int x[n] = {};
    inrep(n,x);

    ll ans = 0;
    rep(i,0,n){
	ans += min( x[i]*2 , abs(x[i]-k)*2 );
    }
    P(ans);
    return  0;
}


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

int main(){
	int N,X,Y;
	cin >> N >> X >> Y;
	vector<int> c(N+1);
	for(int i=1; i<=N; i++){
		for(int j=i+1; j<=N; j++){
			int m = min(abs(i-j), abs(X-i)+1+abs(Y-j));
			c[m]++;
		}
	}

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


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	
	public void exec() {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		String output;
		if(a<b){
			if(b<c){
				output = makeOutputString(a,b,c);
			} else {
				if(a<c){
					output = makeOutputString(a,c,b);
				} else{
					output = makeOutputString(c,a,b);
				}
			}
		}else{
			if(a<c){
				output = makeOutputString(b,a,c);
			}else{
				if(b<c){
					output = makeOutputString(b,c,a);
				}else{
					output = makeOutputString(c,b,a);
				}
			}
		}
		System.out.println(output);
		sc.close();
	}
	private String makeOutputString(int min1, int min2, int min3) {
		return new StringBuilder().append(min1).append(" ").append(min2).append(" ").append(min3).toString();
	}

	public static void main(String[] args)  {
		new Main().exec();
	}
}

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

if n == 1:
  print(0)
  exit()

def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

F = factorization(n)

cnt = 0 
for i in range(len(F)):
  m = 1
  while F[i][1] >= m*(m+1)/2:
    cnt += 1
    m += 1

print(cnt)

Measured memory_bytes: 63364
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <stack>
#include <climits>
#include <map>
#include <set>

using namespace std;

typedef long long ll;
typedef pair<int, int> P;

const ll mod = 1000000007;
const int inf = 1e9;
const long long INF = 1LL << 60;


int main()
{
    int n; cin >> n;
    int a[n];
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    int q; cin >> q;
    int m[q];
    for(int i = 0; i < q; i++){
        cin >> m[i];
    }
    vector<bool>ans(q);
    for(int i = 0; i < q; i++){
        ans[i] = false;
    }
    for(int bit = 0; bit < (1 << n); bit++){
        int tmp = 0;
        for(int i = 0; i < n; i++){
            if(bit & (1<<i)) tmp += a[i];
        }
        bool find = false;
        for(int i = 0; i < q; i++){
            if(tmp == m[i]){
                ans[i] = true; 
            }
        }
    }
    for(int i = 0; i < q; i++){
        if(ans[i]) cout << "yes" << endl;
        else cout << "no" << endl;
    }
}


Measured memory_bytes: 3104
#include<cstdio>
const int MOD = 998244353;
const int MAXN = 2000000;
int fct[MAXN + 5], ifct[MAXN + 5];
int pow_mod(int b, int p) {
	int ret = 1;
	while( p ) {
		if( p & 1 ) ret = 1LL*ret*b%MOD;
		b = 1LL*b*b%MOD;
		p >>= 1;
	}
	return ret;
}
void init() {
	fct[0] = 1;
	for(int i=1;i<=MAXN;i++)
		fct[i] = 1LL*fct[i-1]*i%MOD;
	ifct[MAXN] = pow_mod(fct[MAXN], MOD-2);
	for(int j=MAXN-1;j>=0;j--)
		ifct[j] = 1LL*ifct[j+1]*(j+1)%MOD;
}
int comb(int n, int m) {
	return 1LL*fct[n]*ifct[m]%MOD*ifct[n-m]%MOD;
}
int main() {
	init();
	int ans = 0, N, M;
	scanf("%d%d", &N, &M);
	for(int i=M&1;i<=M&&i<=N;i+=2) {
		int tmp = comb((3*M-i)/2+(N-1), N-1);
		tmp = (tmp + MOD - 1LL*(N-i)*comb((M-i-2)/2+(N-1), N-1)%MOD)%MOD;
		tmp = (tmp + MOD - 1LL*i*comb((M-i)/2+(N-1), N-1)%MOD)%MOD;
		ans = (ans + 1LL*tmp*comb(N, i)%MOD)%MOD;
	}
	printf("%d\n", ans);
}

Measured memory_bytes: 15744
#include <cstdio>
#include <iostream>
#define max_n 55555
#define INF 1000000
using namespace std;

int prime[max_n];
int ans[max_n];
bool is_prime[max_n+1];
int main(){
    for(int i=0; i<max_n; i++){
        prime[i] = INF;
        is_prime[i]=true;
    }
    int p = 0;
    int q = 0;
    is_prime[1]=false;
    is_prime[0]=false;
    for(int i=2;i<max_n;i++){
        if(is_prime[i]){
            prime[p++] = i;
            if(i%5==1){
                ans[q++] = i;
            }
            for(int j=2*i;j<max_n;j+=i)is_prime[j]=false;
        }
    }
    int n;
    cin >> n;
    for(int i = 0; i<n; i++){
        cout << ans[i] <<" ";
    }
    cout << "\n";
    
    return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <string>
using namespace std;
int main(void){
  int n, k, q;
  cin >> n >> k >> q;

  int v[100005] = {0};
  for (int i = 0; i < q; i++) {
	int a;
    cin >> a;
    v[a]++;
  }
  
  for (int i = 0; i < n; i++) {
    string ans;
    int tmp = k - q + v[i+1];
    if (tmp > 0) {
      ans = "Yes";
    }
    else {
      ans = "No";
    }
    cout << ans << endl;
  }

  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define pii pair<int,int>
using namespace std;
int main(){
    int n;
    while(cin >> n,n){
        vector<pii> v;
        v.emplace_back(make_pair(-1,1000000000));
        for(int i=0;i<n;i++){
            char c;cin >> c;
            if(c == 'W'){
                int i,s;cin >> i >> s;
                for(auto it=v.begin();it!=v.end();it++){
                    if(it->first == -1){
                        if(s <= it->second){
                        	it->second -= s;
                            v.insert(it,make_pair(i,s));
                            break;
                        } else {
                            it->first=i;
                            s -= it->second;
                        }
                    }
                }
            }
            if(c == 'D'){
                int i;cin >> i;
                for(auto it=v.begin();it!=v.end();it++){
                    if(it->first == i) it->first = -1;
                }
            }
            if(c == 'R'){
                int p;cin >> p;
                int i=0;
                auto it=v.begin();
                for(;it!=v.end();it++){
                    i += it->second;
                    if(p < i){
                        cout << it->first << endl;
                        break;
                    }
                }
                if(it == v.end()) cout << -1 << endl;
            }
        }
        cout << endl;
    }
    return 0;
}

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

const int N = 55;

int n, a[N];
int pos = 1;
vector< pair<int,int> > ans;

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0);
	cin >> n;
	for (int i = 1; i <= n; ++i) {
		cin >> a[i];
		if (abs(a[i]) > abs(a[pos])) pos = i;
	}
	for (int i = 1; i <= n; ++i) if (i != pos) {
		ans.push_back(make_pair(pos, i));
		a[i] += a[pos];
	}
	if (a[1] > 0) {
		for (int i = 2; i <= n; ++i) {
			ans.push_back(make_pair(i - 1, i));
		}
	} else {
		for (int i = n - 1; i >= 1; --i) {
			ans.push_back(make_pair(i + 1, i));
		}
	} 
	printf("%d\n", ans.size());
	for (auto e : ans) printf("%d %d\n", e.first, e.second);
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
    int x;
    int a;
    int b;
    cin >> x >> a >> b;
    if(-a + b <= 0){
        cout << "delicious" << endl;
    }
    else if(-a + b <= x){
        cout << "safe" << endl;
    }
    else{
        cout << "dangerous" << endl;
    }
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
 
int main(void) {
 
  // 入力
  int a,b,c,d;
  scanf("%d",&a);
  scanf("%d",&b);
  
  c=b-a+1;
  d=a+b;
  while(c<d){
    printf("%d ",c);
    c+=1;
  }
    printf("\n");
  return 0;
}

Measured memory_bytes: 128
#!/usr/bin/env python3

import sys
from pprint import pprint
sys.setrecursionlimit(300000)


def solve(H: int, W: int, A: "List[List[int]]", B: "List[List[int]]"):
    diffs = [[0] * (W + 1) for _ in range(H + 1)]
    for i in range(H):
        for j in range(W):
            diffs[i][j] = abs(A[i][j] - B[i][j])
    dp = [[[0] * 6401 for _ in range(W + 1)] for _ in range(H + 1)]
    dp[0][0][diffs[0][0]] += 1
    for i in range(H):
        for j in range(W):
            tmp = dp[i][j]
            for val, flg in enumerate(tmp):
                if not flg:
                    continue
                if val + diffs[i + 1][j] <= 6400:
                    dp[i + 1][j][abs(val + diffs[i + 1][j])] += 1
                if val + diffs[i][j + 1] <= 6400:
                    dp[i][j + 1][abs(val + diffs[i][j + 1])] += 1
                dp[i + 1][j][abs(val - diffs[i + 1][j])] += 1
                dp[i][j + 1][abs(val - diffs[i][j + 1])] += 1
                #dp[i + 1][j].add(abs(val + diffs[i + 1][j]))
                #dp[i + 1][j].add(abs(val - diffs[i + 1][j]))
                #dp[i][j + 1].add(abs(val + diffs[i][j + 1]))
                #dp[i][j + 1].add(abs(val - diffs[i][j + 1]))
    #ret = min(dp[H - 1][W - 1])
    ret = 0
    for val, flg in enumerate(dp[H - 1][W - 1]):
        if flg:
            ret = val
            break
    print(ret)
    return

def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    H = int(next(tokens))  # type: int
    W = int(next(tokens))  # type: int
    A = [[int(next(tokens)) for _ in range(W)] for _ in range(H)]  # type: "List[List[int]]"
    B = [[int(next(tokens)) for _ in range(W)] for _ in range(H)]  # type: "List[List[int]]"
    solve(H, W, A, B)

if __name__ == '__main__':
    main()


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

int main(int argc, char const *argv[]) {
    int n;
    cin >> n;
    vector<int> a(n), b(n), c(n-1);
    for (size_t i = 0; i < n; i++) cin >> a[i];
    for (size_t i = 0; i < n; i++) cin >> b[i];
    for (size_t i = 0; i < n-1; i++) cin >> c[i];

    int ans = 0;
    int pre = -1;
    for (size_t i = 0; i < n; i++) {
        ans += b[a[i]-1];
        if (a[i]-1 == pre) ans += c[a[i]-2];
        pre = a[i];
    }

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


Measured memory_bytes: 3600
using System;

namespace A___Trangle
{
    class Program
    {
        static void Main(string[] args)
        {
            long S = long.Parse(Console.ReadLine());
            long x2, y2, x3, y3;
            x2 = (long)Math.Ceiling((decimal)Math.Sqrt(S));
            y3 = x2;
            if (x2 * y3 < S)
            {
                x2 += 1;
                y3 += 1;
            }
            x3 = x2 * y3 - S;
            y2 = x3 == 0 ? 0 : 1;
            Console.WriteLine($"0 0 {x2} {y2} {x3} {y3}");
        }
    }
}


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

int bubblesort(int *A, int N){
  int cnt = 0;
  for(int i = 0; i < N - 1; i++){
    for(int j = N - 2; j >= i; j--){
      if(A[j] > A[j+1]){
	int tmp = A[j];
	A[j] = A[j+1];
	A[j+1] = tmp;
	cnt++;
      }
    }
  }
  return cnt;
}

int main(){
  int A[100], n, cnt;
  cin >> n;
  for(int i = 0; i < n; i++) cin >> A[i];
  cnt = bubblesort(A, n);
  for(int i = 0; i < n; i++) cout << A[i] << (i == n - 1 ? '\n' : ' ');
  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 3104
import java.io.InputStream;
import java.io.PrintStream;
import java.util.*;

public class Main {

  public static void main(String[] args) {
    solve(System.in, System.out);
  }

  static void solve(InputStream is, PrintStream os) {
    Scanner sc = new Scanner(is);

    /* read */
    int n = sc.nextInt();

    int q = sc.nextInt();
    String s = sc.next();

    // zero-origin
    int[] l = new int[q];
    int[] r = new int[q];

    for (int i = 0; i < q; i++) {
      l[i] = sc.nextInt() - 1;
      r[i] = sc.nextInt() - 1;
    }

    List<Integer> acLeftIndexes = new ArrayList<>();

    // number of occurrence of AC [0.. i)
    int[] occurrences = new int[n];

    int occurrence = 0;
    for (int i = 1; i < n; i++) {
      if (s.charAt(i - 1) == 'A' && s.charAt(i) == 'C') {
        occurrence++;
      }
      occurrences[i] = occurrence;
    }

    for (int i = 0; i < q; i++) {
      os.println(occurrences[r[i]] - (occurrences[l[i]]));
    }
  }

}

Measured memory_bytes: 81812
#include<stdio.h>
main(){
  int n;
  int i,j;
  int s[1000],p[1000];
  int count,count2=0;
  int zikko;
  int a=1;
  while(1){
    scanf("%d",&n);
    if(n==0) break;
    for(i=0;i<n;i++){
      scanf("%d",&s[i]);
    }
    zikko=0;
    a=1;
    while(a){
      for(i=0;i<n;i++){
	count=1;
	for(j=0;j<n;j++){
	  if(s[i]==s[j] && i!=j) count++;
	}
	p[i]=count;
      }
      for(i=0;i<n;i++){
	if(s[i]==p[i]) count2++;
      }
      if(count2==n) a=0;
      else{
	for(i=0;i<n;i++){
	  s[i]=p[i];
	}
	zikko++;
      }
      count2=0;
    }
    printf("%d\n",zikko);
    for(i=0;i<n-1;i++){
      printf("%d ",s[i]);
    }
    printf("%d\n",s[n-1]);
  }
  return 0;
}

    

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

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;

char s[100005];

int main() {
    scanf("%s", s);
    int n = strlen(s);
    int repaint0 = 0, repaint1 = 0;
    for (int i = 0; i < n; ++i) {
        int v = s[i] - '0';
        if ((i & 1) == v) {
            ++repaint1;
        } else {
            ++repaint0;
        }
    }
    printf("%d\n", min(repaint0, repaint1));
    return 0;
}



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

#ifdef LOCAL
#include "../lib/dump.hpp"
#else
#define dump(...)
#define dumpv(...)
#endif

typedef long long ll;
typedef pair<int, int> P;
const int MOD = 1e9 + 7;
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;

void solve()
{
  int N, M;
  cin >> N >> M;
  vector<vector<int>> w(100005);
  for (int i = 0; i < N; i++) {
    int a, b;
    cin >> a >> b;
    w[a].push_back(b);
  }
  priority_queue<int> q;
  ll ans = 0;
  for (int i = 0; i < M; i++) {
    for (int j = 0; j < w[i + 1].size(); j++) {
      q.push(w[i + 1][j]);
    }
    if (!q.empty()) {
      ans += q.top();
      q.pop();
    }
  }
  cout << ans << endl;
}

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  // freopen("temp.1", "r", stdin);
  solve();
  return 0;
}

Measured memory_bytes: 5632
#include <bits/stdc++.h>
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.rbegin(), a.rend()
#define REP(i, a) for (ll i(0), _##i(a); i < _##i; ++i)
#define FOR(i, a, b) for (ll i(a), _##i(b); i <= _##i; ++i)

#ifdef LOCAL
#define _NTH_ARG(_1, _2, _3, _4, _5, _6, N, ...) N
#define _FE_1(_CALL, x) _CALL(x)
#define _FE_2(_CALL, x, ...) _CALL(x) _FE_1(_CALL, __VA_ARGS__)
#define _FE_3(_CALL, x, ...) _CALL(x) _FE_2(_CALL, __VA_ARGS__)
#define _FE_4(_CALL, x, ...) _CALL(x) _FE_3(_CALL, __VA_ARGS__)
#define _FE_5(_CALL, x, ...) _CALL(x) _FE_4(_CALL, __VA_ARGS__)
#define _FE_6(_CALL, x, ...) _CALL(x) _FE_5(_CALL, __VA_ARGS__)
#define FOR_EACH_MACRO(MACRO, ...)                                             \
  _NTH_ARG(__VA_ARGS__, _FE_6, _FE_5, _FE_4, _FE_3, _FE_2, _FE_1)              \
  (MACRO, __VA_ARGS__)
#define watch(x) cerr << "\033[1;32m" #x " = \033[1;34m" << (x) << "\033[0m; ";
#define debug(...)                                                             \
  cerr << "\033[2;31mLine " << __LINE__ << ": \033[0m";                        \
  FOR_EACH_MACRO(watch, __VA_ARGS__)                                           \
  cerr << endl
#else
#define debug(...)
#endif

using namespace std;

template <class T1, class T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) {
  return os << '{' << p.first << ", " << p.second << '}';
}

template <class T, class = decltype(begin(declval<T>())),
          class = enable_if_t<!is_same<T, string>::value>>
ostream &operator<<(ostream &os, const T &c) {
  os << '[';
  for (auto it = begin(c); it != end(c); ++it)
    os << (it == begin(c) ? "" : ", ") << *it;
  return os << ']';
}
using ll = long long;

void solve() {
  int n;
  cin >> n;
  vector<ll> a(n);
  for (ll &x : a)
    cin >> x;

  const ll INF = 1e18;

  vector<vector<ll>> dp(n, vector<ll>(n, INF));

  function<ll(int, int)> bt = [&](int i, int j) -> ll{
    if (i == j) return 0;
    ll &res = dp[i][j];
    if (res != INF) return res;
    ll sum = 0;
    FOR(k, i, j) sum += a[k];
    for (int k = i; k < j; ++k) {
      res = min(res, bt(i, k) + bt(k + 1, j) + sum);
    }
    return res;
  };

  cout << bt(0, n - 1) << "\n";

}

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

  int T = 1;
  // cin >> T;
  while (T--) {
    solve();
  }
}


Measured memory_bytes: 1536
#include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <numeric>

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
#define repi(i, start, end) for(int i = start; i < end; i++)
#define all(x) (x).begin(), (x).end()
#define debug(x) cout << (x) << endl;
typedef long long ll;
const int MAX = 999999999;

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

    int cnt = 0;
    rep(i, a + 1){
        rep(j, b + 1){
            rep(k, c + 1) if(i * 500 + j * 100 + k * 50 == x) cnt ++;
        }
    }

    cout << cnt << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <bitset>
#include <numeric>
#include <complex>
#include <cassert>
#include <random>
using namespace std;
using ll = long long;


int main() {
	int a, b, c; cin >> a >> b >> c;
	swap(a, b);
	swap(a, c);
	cout << a << " " << b << " " << c << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
namespace FAST_IO
{
	template<typename T> void read(T &a)
	{
		a=0;
		int f=1;
		char c=getchar();
		while(!isdigit(c))
		{
			if(c=='-')
			{
				f=-1;
			}
			c=getchar();
		}
		while(isdigit(c))
		{
			a=a*10+c-'0';
			c=getchar();
		}
		a=a*f;
	}
	template <typename T> void write(T a)
	{
		if(a<0)
		{
			a=-a;
			putchar('-');
		}
		if(a>9)
		{
			write(a/10);
		}
		putchar(a%10+'0');
	}
	template <typename T> void writeln(T a)
	{
		write(a);
		puts("");
	}
}
int n,q;
string m;
int dp[100001];
int main()
{
	cin>>n>>q>>m;
	for(int i=1;i<n;i++)
	{
		dp[i]=dp[i-1];
		if(m[i-1]=='A'&&m[i]=='C')
		{
			++dp[i];
		}
	}
	while(q--)
	{
		int l,r;
		cin>>l>>r;
		cout<<dp[r-1]-dp[l-1]<<endl;
	}
}

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

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

using namespace std;
using ll = long long;
using P = pair<int, int>;

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; }

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

int main(){
    int N, Q; cin >> N >> Q;
    string s; cin >> s;
    vector<int> sum( N + 1 );
    REP( i, sum.size() ){
        if( i >= 1 && s[i - 1] == 'A' && s[i] == 'C' ) sum[i + 1]++;
        sum[i + 1] += sum[i];
    }

    REP( i, Q ){
        int l, r; cin >> l >> r;
        l--, r--;
        cout << sum[r + 1] - sum[l + 1] << endl;
    }
}


Measured memory_bytes: 1408
n,m=map(int,input().split())
lmax=0
rmin=float('inf')
for i in range(m):
    l,r=map(int,input().split())
    lmax=max(lmax,l)
    rmin=min(rmin,r)

print(0 if rmin-lmax+1<=0 else rmin-lmax+1)


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

const int mod = 1000000007;
ll dp[1000000][13];

int main() {
    string S; cin >> S;
    int s = S.size();
    dp[0][0] = 1;
    int mul = 1;
    rep(i, s){
        char c = S[s-1-i];
        if(c != '?'){
            int x = c - '0';
            x *= mul;
            x %= 13;
            rep(j, 13){
                dp[i+1][(j+x)%13] += dp[i][j];
            }
        } else {
            rep(k, 10){
                int x = k*mul;
                x %= 13;
                rep(j, 13){
                dp[i+1][(j+x)%13] += dp[i][j];
                }
            }
        }
        rep(j, 13){
            dp[i+1][j] %= mod;
        }
        mul *= 10;
        mul %= 13;
    }

    cout << dp[s][5] << endl;

    /*rep(i, s+1){
        rep(j, 13){
            cout << "dp" << i << j << "=" << dp[i][j] << endl;
        }
    }*/



    return 0;
}

Measured memory_bytes: 10752
/*
 * Author : Andrew J
*/
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
using ll = long long;
using ii = pair <int , int>;
const int N = 305;
int n;
int a[N];
double dp[N][N][N];
bool vis[N][N][N];

double ddiv(double a , double b) {
  return a / b;
}

double f(int three , int two , int one) {
  int zero = n - three - two - one;
  if (zero == n) return 0;
  double &sol = dp[three][two][one];
  if (vis[three][two][one]) return sol;
  sol = 1, vis[three][two][one] = 1;
  if (three) {
    sol += f(three - 1 , two + 1 , one) * ddiv(three , n);
  }
  if (two) {
    sol += f(three , two - 1 , one + 1) * ddiv(two , n);
  }
  if (one) {
    sol += f(three , two , one - 1) * ddiv(one , n);
  }
  sol *= ddiv(n , n - zero);
  return sol;
}

int main() {
  scanf("%d" , &n);
  int one = 0, two = 0, three = 0;
  for (int i = 0, x ; i < n ; i++) {
    scanf("%d" , &x);
    if (x == 1) one++;
    if (x == 2) two++;
    if (x == 3) three++;
  }
  printf("%.10lf\n" , f(three , two , one));
  return 0;
}


Measured memory_bytes: 127112
# -*- coding: utf-8 -*-

def get_input() -> tuple:
    """
    標準入力を取得する.

    Returns:\n
        tuple: 標準入力
    """
    a, b, c, d = list(map(int, input().split()))

    return a, b, c, d


def main(a: int, b: int, c: int, d: int) -> None:
    """
    メイン処理.

    Args:\n
        a (int): 整数(-10**9 <= a <= b <= 10**9)
        b (int): 整数(-10**9 <= a <= b <= 10**9)
        c (int): 整数(-10**9 <= c <= d <= 10**9)
        d (int): 整数(-10**9 <= c <= d <= 10**9)
    """
    # 求解処理
    ans = max([a * c, a * d, b * c, b * d])

    # 結果出力
    print(ans)


if __name__ == "__main__":
    # 標準入力を取得
    a, b, c, d = get_input()

    # メイン処理
    main(a, b, c, d)


Measured memory_bytes: 9148
import java.util.*;
public class Main {
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int n=Integer.parseInt(sc.next());
HashSet<String> U=new HashSet<>();
for(int i=0;i<n;i++){U.add(sc.next());}
String ans="";
if(U.size()==3){ans="Three";}else{ans="Four";}
System.out.println(ans);
}}

Measured memory_bytes: 21844
def solve(n, a_list, s):

    for i in range(n - 1, -1, -1):
        if s[i] == "0":
            if a_list[i] == 0:
                continue
            r = 2 ** (a_list[i].bit_length() - 1)
            for j in range(i):
                if a_list[j] & r > 0:
                    a_list[j] = a_list[i] ^ a_list[j]
        else:
            if a_list[i] > 0:
                return 1
    return 0


def main():
    t = int(input())
    res_list = []
    for _ in range(t):
        n = int(input())
        a_list = list(map(int, input().split()))
        s = input()
        res = solve(n, a_list, s)
        res_list.append(res)
    for res in res_list:
        print(res)


def test():
    assert solve(2, [1, 2], "10") == 1
    assert solve(2, [1, 1], "10") == 0
    assert solve(6, [2, 3, 4, 5, 6, 7], "111000") == 0


if __name__ == "__main__":
    test()
    main()


Measured memory_bytes: 9220
#include <bits/stdc++.h>
using namespace std;
// マクロ
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
// 型エイリアス
using ll = long long;
using vi = vector<int>;
using vs = vector<string>;
using vvi = vector<vi>;
using vvs = vector<vs>;
const int m = 10000;
int main() {
    int a, b;
    cin >> a >> b;
    ll ans = 0;
    for(int i = a; i <= b; i++) {
        if(i / m % 10 == i % 10 && i / 10 % 10  == i / 1000 % 10) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import qualified Data.ByteString.Char8 as B
import qualified Data.Vector.Unboxed as VU
import qualified Data.Vector.Unboxed.Mutable as VUM
import Data.Char
import Control.Monad

solve vec n x = do
        vec' <- VU.unsafeThaw vec
        res <- forM [0..n-2] $ \i -> adjust vec' (i,i+1) x
        return $ sum res
    where
        adjust vec (i,j) x = do
            iv <- VUM.read vec i
            jv <- VUM.read vec j
            let diff = max (iv+jv-x) 0
            unless (diff == 0) $ do
                if (jv >= diff)
                    then do
                        VUM.write vec j (jv-diff)
                    else do
                        VUM.write vec j 0
                        VUM.write vec i (iv + (jv-diff))
            return diff

main = do
    [n, x] <- map read . words <$> getLine 
    as <- VU.unfoldrN n (B.readInt . B.dropWhile isSpace) <$> B.getLine
    solve as n x >>= print

Measured memory_bytes: 10876
import java.util.*;

class Main{
public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int a = n / 1000;
    int b = (n % 1000) / 100;
    int c = (n % 100) / 10;
    int d = n % 10;
    if(a + b + c + d == 7) {
    	System.out.println(String.valueOf(a) + "+" + String.valueOf(b) + "+" + String.valueOf(c) + "+" + String.valueOf(d) + "=7");
    } else if(a - b + c + d == 7) {
    	System.out.println(String.valueOf(a) + "-" + String.valueOf(b) + "+" + String.valueOf(c) + "+" + String.valueOf(d) + "=7");
    } else if(a - b - c + d == 7) {
    	System.out.println(String.valueOf(a) + "-" + String.valueOf(b) + "-" + String.valueOf(c) + "+" + String.valueOf(d) + "=7");
    } else if(a - b - c - d == 7) {
    	System.out.println(String.valueOf(a) + "-" + String.valueOf(b) + "-" + String.valueOf(c) + "-" + String.valueOf(d) + "=7");
    } else if(a + b - c + d == 7) {
    	System.out.println(String.valueOf(a) + "+" + String.valueOf(b) + "-" + String.valueOf(c) + "+" + String.valueOf(d) + "=7");
    } else if(a + b + c - d == 7) {
    	System.out.println(String.valueOf(a) + "+" + String.valueOf(b) + "+" + String.valueOf(c) + "-" + String.valueOf(d) + "=7");
    } else if(a - b + c - d == 7) {
    	System.out.println(String.valueOf(a) + "-" + String.valueOf(b) + "+" + String.valueOf(c) + "-" + String.valueOf(d) + "=7");
    } else if(a + b - c - d == 7) {
    	System.out.println(String.valueOf(a) + "+" + String.valueOf(b) + "-" + String.valueOf(c) + "-" + String.valueOf(d) + "=7");
    }
}
}

Measured memory_bytes: 23252
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
 
using namespace std;

typedef long long LL;

const int N = 10;

int a[N], b[N], p[N], n;

bool check(int a[])
{
    for(int i = 0; i < n; i ++)
        if(a[i] != p[i])  return false;
    return true;
}

int main()
{
    scanf("%d", &n);
    for(int i = 0; i < n; i ++)  scanf("%d", &a[i]);
    for(int i = 0; i < n; i ++)  scanf("%d", &b[i]);
    
    for(int i = 0; i < n; i ++)  p[i] = i + 1;
    
    int r1 = -1, r2 = -1, num = 0;
    
    do{
        if(r1 == -1 and check(a))  r1 = num;
        if(r2 == -1 and check(b))  r2 = num;
        num ++;
    }while(next_permutation(p, p + n));
    
    printf("%d\n", abs(r1 - r2));
    return 0;
}

Measured memory_bytes: 504
#include <bits/stdc++.h>
using namespace std;
#define REP(i, s, n) for (int i = s; i < n; ++i)
#define rep(i, n) REP(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG true
// sort(a.begin(), a.end(), std::greater<int>());

/*
std::vector<std::string> split(const std::string &input, char delimiter)
{
    std::istringstream stream(input);

    std::string field;
    std::vector<std::string> result;
    while (std::getline(stream, field, delimiter))
    {
        result.push_back(field);
    }
    return result;
}
*/

int main()
{
    int n;
    cin >> n;
    pair<int, int> minpair;
    minpair.first = INT_MAX;
    minpair.second=INT_MAX;
    int a, b;
    rep(i, n)
    {
        cin >> a >> b;
        if (b < minpair.second)
        {
            minpair.first = a;
            minpair.second = b;
        }
    }
    cout << minpair.first + minpair.second << endl;
    return 0;
}

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

#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = (n)-1; i >= 0; i--)
#define rep1(i,n) for(int i = 1; i <= (n); i++)
#define rrep1(i,n) for(int i = (n); i > 0; i--)

#define ll long long
#define pi pair<int, int>
#define pll pair<ll, ll>

#define MOD 1000000007
#define INF 1000000000000000LL

using namespace std;

int w,h;
vector<pi> g[31][31];
int d[31][31];

void connect(pi l, pi r){
  g[l.first][l.second].push_back(r);
  g[r.first][r.second].push_back(l);
}

void clear_all(){
  rep(i, 31)rep(j, 31){
    g[i][j].clear();
    d[i][j]=0;
  }
}

int main(){
  while(true){
    cin>>w>>h;
    if(w==0)break;

    rep(y, 2*h-1){
      if(y%2==0){
        rep(x, w-1){
          int wall;cin>>wall;
          if(!wall){
            connect({y/2, x}, {y/2, x+1});
          }
        }
      }else{
        rep(x, w){
          int wall;cin>>wall;
          if(!wall){
            connect({y/2, x}, {y/2+1, x});
          }
        }
      }
    }

    queue< pair<pi, int> > q;
    q.push( {{0,0},1} );
    while( !q.empty() ){
      auto cp = q.front();q.pop();
      auto c = cp.first;
      int y = c.first, x = c.second;
      if(d[y][x]>0)continue;

      int cost = cp.second;
      d[y][x] = cost;
      for(auto p: g[y][x]){
        q.push({p, cost+1});
      }
    }
    cout<<d[h-1][w-1]<<endl;

    clear_all();
  }

  return 0;
}



Measured memory_bytes: 3172
L, R = map(int,input().split())
l , r = L//2019, R//2019
if R - L >= 2019:
    print(0)

else:
    Amari=[]
    for i in range(L,R):
        for j in range(i+1,R+1):
            k = i*j
            Amari.append(k%2019)
    print(min(Amari))


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

using namespace std;


bool G[10][10];

void solve() {
    int N, M; cin >> N >> M;
    for (int i = 0; i < M; i++) {
        int a, b; cin >> a >> b; a--; b--;
        G[a][b] = G[b][a] = true;
    }

    vector<int> ord(N);
    for (int i = 0; i < N; i++) ord[i] = i;

    int res = 0;
    do {
        if (ord[0] != 0) break;

        bool ok = true;
        for (int i = 0; i < N - 1; i++) {
            int from = ord[i];
            int to = ord[i+1];
            if (!G[from][to]) ok = false;
        }
        if (ok) res++;
    } while (next_permutation(ord.begin(), ord.end()));

    cout << res << endl;
}


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

Measured memory_bytes: 256
#include<stdio.h>
int main(void){
	int number[6],i,temp;
	char order[100];

	for(i = 0; i < 6; i++){
	  scanf("%d",&number[i]);
	}

	scanf("%s",order);
	for(i = 0; order[i] != '\0'; i++){
	  if(order[i] == 'N'){
		temp = number[0];
	    number[0] = number[1];
		number[1] = number[5];
		number[5] = number[4];
		number[4] = temp;
	  }

	  if(order[i] == 'S'){
		temp = number[0];
	    number[0] = number[4];
		number[4] = number[5];
		number[5] = number[1];
		number[1] = temp;
	  }

	  if(order[i] == 'E'){
		temp = number[0];
		number[0] = number[3];
		number[3] = number[5];
		number[5] = number[2];
		number[2] = temp;
	  }

	  if(order[i] == 'W'){
		temp = number[0];
		number[0] = number[2];
		number[2] = number[5];
		number[5] = number[3];
		number[3] = temp;
	  }
	}
    printf("%d\n",number[0]);	
	return 0;
}



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

const ull MOD = 1000000007;

int main(){
  ll n;cin >> n;
  vector<ll> a(n);
  ll sum = 0;
  rep(i,n){
    cin >> a.at(i);
    sum += a.at(i);
    sum %= MOD;
  }

  ll ans = 0;

  for(ll i=0;i<n-1;++i){
    sum -= a.at(i);
    if( sum < 0 ) sum += MOD;
    ans += sum*a.at(i);
    ans %= MOD;
  }
  cout << ans%MOD << endl;
  return 0;

}

Measured memory_bytes: 4844
#include<bits/stdc++.h>
using namespace std;
const int maxn=3e5+9;
const double ep=1e-7;
const int mod=998244353;
const int INF=0x3f3f3f3f;
const double pi=acos(-1);
#define debug1 puts("?");
#define debug(x) cout<<"##"<<(x)<<endl;
#define mk make_pair
#define PII pair<int,int>
#define PIII pair<int,PII >
#define PIII1 pair<PII,int>
#define PIL pair<int,ll>
#define PLL pair<ll,ll>
#define eb emplace_back
#define fi first
#define se second
#define rep(i,a,b) for(register int i=(a);i<=(b);++i)
#define dep(i,a,b) for(register int i=(a);i>=(b);--i)
#define sd(x) scanf("%d",&(x))
#define slld(x) scanf("%lld",&(x))
#define sdd(x,y) scanf("%d%d",&(x),&(y))
#define sc(s) scanf("%s",(s))
#define pd(x) printf("%d\n",(x))
#define plld(x) printf("%lld\n",(x))
#define pdk(x) printf("%d ",(x))
#define plldk(x) printf("%lld ",(x))
#define pdd(x,y) printf("%d %d\n",(x),(y))
typedef long long ll;
int n,q;
ll b1[maxn],b2[maxn];
//b1 1111 b2 10000
void init()
{
	ll base1=1,base2=1;
	rep(i,1,n)
	{
		b1[i]=base1;
		b2[i]=base2;
		base1=(base1*10+1)%mod;
		base2=(base2*10)%mod;
	}
}
struct node{
	int l,r;
	ll val;
	int lazy;
}a[maxn<<2];
void pushup(int k)
{
	a[k].val=(a[k<<1].val+a[k<<1|1].val)%mod;
}
void build(int k,int l,int r)
{
	a[k].l=l;a[k].r=r;
	if(l==r)
	{
		a[k].val=b2[n-l+1];
		return;
	}
	int mid=(l+r)>>1;
	build(k<<1,l,mid);
	build(k<<1|1,mid+1,r);
	pushup(k);
}
void pushdown(int k)
{
	if(a[k].l==a[k].r)
	{
		a[k].lazy=0;return;
	}
	a[k<<1].val=a[k].lazy*b1[a[k<<1].r-a[k<<1].l+1]%mod*b2[n-a[k<<1].r+1]%mod;
	a[k<<1|1].val=a[k].lazy*b1[a[k<<1|1].r-a[k<<1|1].l+1]%mod*b2[n-a[k<<1|1].r+1]%mod;
	a[k<<1].lazy=a[k].lazy;
	a[k<<1|1].lazy=a[k].lazy;
	a[k].lazy=0;
}
void update(int k,int l,int r,int c)
{
	if(a[k].l>=l&&a[k].r<=r)
	{
		a[k].val=c*b1[a[k].r-a[k].l+1]%mod*b2[n-a[k].r+1]%mod;
	//	cout<<"?"<<a[k].l<<' '<<a[k].r<<' '<<a[k].val<<endl;
	//	cout<<b1[a[k].r-a[k].l+1]<<' '<<b2[n-a[k].r+1]<<endl;
		a[k].lazy=c;
		return;
	}
	if(a[k].lazy)pushdown(k);
	int mid=(a[k].l+a[k].r)>>1;
	if(l<=mid)update(k<<1,l,r,c);
	if(r>mid)update(k<<1|1,l,r,c);
	pushup(k);
}
void solve()
{
	sdd(n,q);
	init();
	build(1,1,n);
	while(q--)
	{
		int l,r,c;
		sdd(l,r);sd(c);
		update(1,l,r,c);
		plld(a[1].val);
	}
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int T=1;
//	sd(T);
	while(T--)solve();
} 

Measured memory_bytes: 19176
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0;i<n;i++)
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0;}


int main() {
    string s;
    cin >> s;
    int ans = 0;
    for(int i = 0;i<s.size();i++) {
        for(int j = 1;j<=s.size();j++) {
            string tmp = s.substr(i,j);
            rep(k,tmp.size()) {
                if(tmp[k] != 'A' && tmp[k] != 'G' && tmp[k] != 'C' && tmp[k] != 'T') break;
                ans = max(ans,k+1);
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<numeric>
#include<cmath>
#include<vector>
#include<iomanip>
#include<map>
#include<set>
#include<utility>
#include<iterator>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define t ll t;cin>>t;while(t--)
#define nn cout<<endl;
#define ff(a,n) for(ll i=a;i<n;i++)
#define cY cout<<"YES\n"
#define cN cout<<"NO\n"
#define cy cout<<"Yes\n"
#define cn cout<<"No\n"
#define an ll n;cin>>n;ll a[n];ff(0,n)cin>>a[i]
#define sc second
#define fs first
#define c(a) cout<<a<<endl

void solve()
{
	string s; cin>>s;
	ll h=0,y=0;
	ff(0,s.length())
	{
		if(s[i]=='R') y++;
		else
		{
			h=max(y,h);
			y=0;
		}
	}
	h=max(y,h);
	cout<<h;
}

int main()
{

		solve();
}

Measured memory_bytes: 3632
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#define int long long
#define mod 1000000007
#define for0(i, n) for(int i = 0; i < (n); i++)
#define for1(i, n) for(int i = 1; i <= (n);i++)
using namespace std;
int n, m, a[123456], p, ans=0;
signed main() {
	cin>>n>>m>>p;
	for0(i, m-1){
		int p1;cin>>p1;
		a[max(p,p1)]--;
		a[min(p,p1)]++;
		p=p1;
	}
	for(int i=2;i<=n;i++)a[i]+=a[i-1];
	for1(i,n-1){
		int a1,b,c;cin>>a1>>b>>c;
		ans+=min(a1*a[i],c+b*a[i]);
	}
	cout<<ans<<endl;
	return 0;
}


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

char s[6];
int is_kaibunn(int i) {
	sprintf(s,"%d",i);
	if ((s[0] == s[4]) && (s[1] == s[3]))
		return 1;
	else
		return 0;
}
int main(void) {
	int A,B;
	int count = 0;
	cin >> A >> B;
	for (int i = A;i <= B;i++)
		count += is_kaibunn( i );
	cout << count << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cassert>
#include <cctype>
#include <cstdio>
#include <math.h>
#include <map>
#include <queue>
#include <string>
#include <vector>
using namespace std;

int n,a[100],b[100],c[201],m;

int main(){
	while(cin>>n){
		if(n==0)return 0;
		fill(c,c+200,0);
		for(int i=0;i<n;i++){
			cin>>m;
			a[i]=m;
			c[m]=1;
		}
		sort(a,a+n);
		int p=0;
		for(int i=1;i<=2*n;i++){
			if(c[i]==0)b[p++]=i;
		}
		int x=n,y=n,z=0;
		while(1){
			int f=-1;
			for(int i=0;i<n;i++)if(a[i]>z){f=i;break;}
			if(f>-1){
				z=a[f];a[f]=0;x--;
				if(x==0){cout<<y<<endl<<0<<endl;break;}
			}
			else z=0;
			f=-1;
			for(int i=0;i<n;i++)if(b[i]>z){f=i;break;}
			if(f>-1){
				z=b[f];b[f]=0;y--;
				if(y==0){cout<<0<<endl<<x<<endl;break;}
			}
			else z=0;
		}
	}
}

Measured memory_bytes: 0