akhauriyash/Code-Regression huggingface dataset:
N = int(input())
S = input()
AA = []
for i in range(len(S)):
    AA.append(S[i])

def change1(s):
    if s == 'A':
        return 1
    elif s == 'B':
        return 2
    elif s == 'C':
        return 3
    elif s == 'D':
        return 4
    elif s == 'E':
        return 5
    elif s == 'F':
        return 6
    elif s == 'G':
        return 7
    elif s == 'H':
        return 8
    elif s == 'I':
        return 9
    elif s == 'J':
        return 10
    elif s == 'K':
        return 11
    elif s == 'L':
        return 12
    elif s == 'M':
        return 13
    elif s == 'N':
        return 14
    elif s == 'O':
        return 15
    elif s == 'P':
        return 16
    elif s == 'Q':
        return 17
    elif s == 'R':
        return 18
    elif s == 'S':
        return 19
    elif s == 'T':
        return 20
    elif s == 'U':
        return 21
    elif s == 'V':
        return 22
    elif s == 'W':
        return 23
    elif s == 'X':
        return 24
    elif s == 'Y':
        return 25
    elif s == 'Z':
        return 26

for i in range(len(S)):
    AA[i] = change1(S[i])

for i in range(len(S)):
    AA[i] += N
    if AA[i] > 26:
        AA[i] -= 26
        
def change2(S):
    if S == 1:
        return 'A'
    elif S == 2:
        return 'B'
    elif S == 3:
        return 'C'
    elif S == 4:
        return 'D'
    elif S == 5:
        return 'E'
    elif S == 6:
        return 'F'
    elif S == 7:
        return 'G'
    elif S == 8:
        return 'H'
    elif S == 9:
        return 'I'
    elif S == 10:
        return 'J'
    elif S == 11:
        return 'K'
    elif S == 12:
        return 'L'
    elif S == 13:
        return 'M'
    elif S == 14:
        return 'N'
    elif S == 15:
        return 'O'
    elif S == 16:
        return 'P'
    elif S == 17:
        return 'Q'
    elif S == 18:
        return 'R'
    elif S == 19:
        return 'S'
    elif S == 20:
        return 'T'
    elif S == 21:
        return 'U'
    elif S == 22:
        return 'V'
    elif S == 23:
        return 'W'
    elif S == 24:
        return 'X'
    elif S == 25:
        return 'Y'
    elif S == 26:
        return 'Z'


for i in range(len(S)):
    AA[i] = change2(AA[i])

BB = "".join(AA)
print(BB)

Measured memory_bytes: 3316
#include<queue>
#include<stack>
#include<math.h>
#include<cmath>
#include<bitset>
#include<stdio.h>
#include<string>
#include<map>
#include<algorithm>
#include<vector>
#include<iostream>
#include<utility>
using namespace std;
int main(){
  long long int ans=0;
  int x,y,a,b,c,p[100010],q[100010],r[100010],i;
  priority_queue<int,vector<int>,greater<int> > que;
  scanf("%d %d %d %d %d\n",&x,&y,&a,&b,&c);
  for(i=0;i<a;i++){
    scanf("%d ",&p[i]);
  }
  for(i=0;i<b;i++){
    scanf("%d ",&q[i]);
  }
  for(i=0;i<c;i++){
    scanf("%d ",&r[i]);
  }
  sort(p,p+a,greater<int>());
  sort(q,q+b,greater<int>());
  sort(r,r+c);
  for(i=0;i<x;i++){
    que.push(p[i]);
  }
  for(i=0;i<y;i++){
    que.push(q[i]);
  }
  for(i=0;i<c;i++){
    if(que.top()<r[i]){
      que.pop();
      que.push(r[i]);
    }
  }
  for(i=0;i<x+y;i++){
    ans+=que.top();
    que.pop();
  }
  printf("%lld\n",ans);
  return 0;
}

Measured memory_bytes: 2552
N, M = map(int, input().split())
paths = [tuple(map(int, input().split())) for _ in range(M)]
e_vals = [0]*(N+1)
for u, v in paths:
    if u > v: u, v = v, u
    e_vals[u] += 1; e_vals[v] -= 1;
for i in range(1, N+1):
    e_vals[i] += e_vals[i-1]
    if e_vals[i] % 2 == 1: print('NO'); break;
else: print('YES')

Measured memory_bytes: 20568
#include <iostream>
#include <ios>
#include <iomanip>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <utility>
using namespace std;

#define MOD 1000000007
#define INF 1e9+7
#define INF_LONG 1e18
#define rep(i, n) for(int i=0; i<n; ++i)
#define rrep(i, m, n) for(int i=m; i<n; ++i)
typedef long long ll;

#define MAX_N 100000
#define MAX_M 100000
#define MAX_V 100
#define MAX_E 100
#define MAX_Q 100000

int dx[] = {-1, 0, 1, 0};
int dy[] = {0, -1, 0, 1};

int ddx[] = {-1, 0, 1, 0, -1, 1, -1, 1};
int ddy[] = {0, -1, 0, 1, 1, 1, -1, -1};

//--------------------------


int main() {

  int a, b;
  cin >> a >> b;

  cout << 6-a-b << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
void solve()
{
    long long n, k;
    cin >> n >> k;
    cout << min(n % k, abs((n % k) - k));
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    solve();
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
	#include <cstdio>
	#include <cstring>
	#include <cmath>
	#include <cstring>
	#include <chrono>
	#include <complex>
	#define endl "\n"	
	typedef long long LL;
	#define ld long double
	#define ll long long int
	#define vi vector<int>
	#define vll vector<ll>
	#define vvi vector < vi >
	#define pii pair<int,int>
	#define pll pair<long long, long long>
	#define mod 1000000007
	#define mod2 998244353
	#define INFINITE 1000000000000000001;
	#define all(c) c.begin(),c.end()
	#define sz(v) ((ll)(v).size())
	#define mp(x,y) make_pair(x,y)
	#define mem(a,val) memset(a,val,sizeof(a))
	#define eb emplace_back
	#define pb push_back
	#define f first
	#define s second
	#define dbg(a) cout<<#a<<" --> "<<(a)<<"\n";
	#define forn(i,n) for (ll i=0; i<(n); ++i)
	#define fornd(i,n) for (ll i=(n)-1; i>=0; --i)	
	#define forab(i,a,b) for (ll i=(a); i<=(b); ++i)
	#define read(a) ll a; cin >> a;
	#define reads(s) string s; cin >> s;
	#define readb(a, b) ll a, b; cin >> a >> b;
	#define readc(a, b, c) ll a, b, c; cin >> a >> b >> c;
	#define readarr(a, n) int a[(n) + 1] = {}; forab(i, 0, (n-1)) {cin >> a[i];}
	#define readmat(a, n, m) int a[n + 1][m + 1] = {}; forab(i, 1, n) {forab(j, 1, m) cin >> a[i][j];}
	#define readv(A,n) vll A(n,0); forn(i,n) cin>>A[i]; 
	#define print(a) cout << a << endl;
	#define printarr(a, n) forab (i, 1, n) cout << a[i] << " "; cout << endl;
	#define printv(v) for (int i: v) cout << i << " "; cout << endl;
	#define printmat(a, n, m) forab(i, 1, n) {forab (j, 1, m) cout << a[i][j] << " "; cout << endl;}
	#define precision(a) cout<<fixed<<setprecision(a);
	#define INF (1e18+5)
	#define inf (1e9+5)
	int dx[4] = { 0, 0, 1, -1 };
	int dy[4] = { 1, -1, 0, 0 };
	// 8-directions
	//int dx[]={1,1,1,0,0,-1,-1,-1};
	//int dy[]={-1,0,1,-1,1,-1,0,1};
	#define fast_io ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
	using namespace std;
	int begtime = clock();
	mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
	mt19937_64 rngb(chrono::steady_clock::now().time_since_epoch().count()); // can give negative values too
	bool isPowerOfTwo(int x) {
    return x && (!(x & (x - 1)));
	}
	int takemod(int x) {
    return (x % mod + mod) % mod;
	}
 
	ll fpow(ll base, ll power, ll MOD) {
    ll result = 1;
    base = base % MOD;
    while (power) {
        if (power & 1)
            result = (result * base) % MOD;
        base = (base * base) % MOD;
        power = power >> 1;
    }
    return result;
	}
 
	ll modinv(ll x,ll MOD) {return fpow(x, MOD - 2, MOD);}
	void solve()
	{
		string A;
		cin>>A;
		
		cout<<(A=="ABC"?"ARC":"ABC")<<endl;			
	}
	int main()
	{	
		#ifndef ONLINE_JUDGE
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
		#endif
		fast_io;
		int T=1;
	//	cin>>T;
		// cin.ignore(); must be there when using getline(cin, s)
		while(T--)
		{
			solve();
		}
		#ifndef ONLINE_JUDGE
    		cerr << "Time elapsed: " << (clock() - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n";
    		#endif
		return 0;
	}

	
	
	
	

Measured memory_bytes: 3636
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		while(true){
			int n = sc.nextInt();
			if(n==0)break;
			int[][] map = new int[21][21];
			int x, y;
			for(int i=0;i<n;i++){
				x = sc.nextInt();
				y = sc.nextInt();
				map[y][x]++;
			}
			int m = sc.nextInt();
			x = 10;
			y = 10;
			for(int i=0;i<m;i++){
				String s = sc.next();
				int len = sc.nextInt();
				if(s.compareTo("N")==0){
					for(int j=0;j<=len;j++){
						map[y+j][x]--;
					}
					y += len;
				}
				if(s.compareTo("S")==0){
					for(int j=0;j<=len;j++){
						map[y-j][x]--;
					}
					y -= len;
					
				}
				if(s.compareTo("E")==0){
					for(int j=0;j<=len;j++){
						map[y][x+j]--;
					}
					x += len;
				}
				if(s.compareTo("W")==0){
					for(int j=0;j<=len;j++){
						map[y][x-j]--;
					}
					x -= len;
				}
			}
			boolean exit = true;
			for(int i=0;i<21;i++){
				for(int j=0;j<21;j++){
					if(map[i][j]>0){
						exit=false;
						i=21;
						j=21;
					}
				}
			}
			if(exit==true){
				System.out.println("Yes");
			}else{
				System.out.println("No");
			}
						
		}

	}
}

Measured memory_bytes: 35056
//div 3 c
#include<bits/stdc++.h> 
using namespace std; 
#define ll long long int
int main()
{
ll n,x,y;
cin>>n>>x>>y;
ll dis[n+1][n+1];
ll ans[n]={0};
for(ll i=1;i<n;i++)
{
	for(ll j=i+1;j<=n;j++)
	{
		if(i<=x && j>=y)
		{
			dis[i][j]=min((x-i)+(j-y)+1,j-i);
			//ans[dis[i][j]]++;
		}
	     if(i<=x && j<=y)
	    {
	    dis[i][j]=min((x-i)+(y-j)+1,j-i);
	    //ans[dis[i][j]]++;
		}
		 if(i>=x && j>=y)
		{
			dis[i][j]=min(j-i,(i-x)+(j-y)+1);
			//ans[dis[i][j]]++;
		}
		 if(i>=x && j<=y)
		{
		   dis[i][j]=min(j-i,(i-x)+(y-j)+1);	
		   //ans[dis[i][j]]++;
		}
	}
}
for(ll i=1;i<n;i++)
{
	for(ll j=i+1;j<=n;j++)
	{
		ans[dis[i][j]]++;
	}
}
for(ll i=1;i<n;i++)
{
	cout<<ans[i]<<endl;
}
}

Measured memory_bytes: 31360
# -*- coding:utf-8 -*-
s = str(input())
s = s[::-1]
c = 0
bc = 0
abc = 0
_ = 1

mod = 10 ** 9 + 7

for i in range(len(s)):
    if s[i] == '?':
        abc = (abc * 3 + bc) % mod
        bc = (bc * 3 + c) % mod
        c = (c * 3 + _) % mod
        _ = _ * 3 % mod
    if s[i] == 'A':
        abc = (abc + bc) % mod
    if s[i] == 'B':
        bc = (bc + c) % mod
    if s[i] == 'C':
        c = (c + _) % mod


print(abc)

Measured memory_bytes: 3188
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        n: usize,
        t: i64,
        ct: [(i64, i64); n],
    }

    let ans = ct
        .iter()
        .filter_map(|&(ci, ti)| if ti <= t { Some(ci) } else { None })
        .min();

    if let Some(ans) = ans {
        println!("{}", ans);
    } else {
        println!("TLE");
    }
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pb push_back
#define pf push_front
#define all(t) t.begin(), t.end()
#define inrange(i, a, b) (((i)>= min((a), (b))) && ((i) <= max((a), (b))))
typedef vector<ll> vi;
typedef pair<ll, ll> pii;
#define fi first
#define se second
#define upb upper_bound
#define lwb lower_bound
#define show(x) cout << #x << " is " << x << "\n";
const ll inf = 2e18;
const ll mod = 1e9 + 7;
const ld pi = 3.141592653589793238462643383279502884;

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

void print(ll a[], ll n){for(ll i=0;i<n;i++){cout<<a[i]<<" ";}cout<<"\n";}
ll power(ll x, ll y){
    if(y<=0) return 1;
    ll ans = 1;
    x %= mod;
    while(y){
        if(y&1)
            ans = (x * ans) % mod;
        x = (x * x) % mod;
        y >>= 1;
    }
    return ans;
}
ll modInverse(ll n) {return power(n, mod-2);}
inline ll mul(ll a, ll b){ return (a * b) % mod; }
inline ll sub(ll a, ll b){ ll c = (a - b); if(c < 0) c += mod; return c; }
inline ll add(ll a, ll b){ ll c = (a + b); if(c >= mod) c -= mod; return c; }
inline ll divi(ll a, ll b){ return mul(a, modInverse(b)); }

//------------------------------------------------------------------------------------------

//const ll N = 2e5 + 1;
//vector<ll> adj[N];
//bool visited[N];

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    cout<<fixed<<setprecision(10);

	ll n, d;
	ll c=0;
	cin>>n>>d;
	for(int i=0;i<n;i++){
		ld x, y;
		cin>>x>>y;
		ld dis = sqrt(x*x+y*y);
		if(dis<=d)c++;
	}
	cout<<c;


    return 0;
}


Measured memory_bytes: 3836
def resolve():
    N, D = list(map(int, input().split()))
    X = [list(map(int, input().split())) for _ in range(N)]
    cnt = 0
    import itertools
    for i, j in itertools.combinations(list(range(N)), 2):
        dist = 0
        for d in range(D):
            dist += (X[i][d] - X[j][d])**2
        dist = dist**(0.5)
        if dist == int(dist):
            cnt += 1
    print(cnt)
    
if '__main__' == __name__:
    resolve()

Measured memory_bytes: 9356
from collections import deque
def insert(x,a):
    a.appendleft(x)
def delete(x,a):
    if x in a:
        a.remove(x)
    else:
        return
def deletefirst(a):
    a.popleft()
def deletelast(a):
    a.pop()
n=input()
a=deque()
for i in xrange(n):
    s=raw_input().split()
    if s[0]=="insert":
        insert(s[1],a)
    elif s[0]=="delete":
        delete(s[1],a)
    elif s[0]=="deleteFirst":
        deletefirst(a)
    else:
        deletelast(a)
print(" ".join(a))

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

int main() {
  int n , k;
  cin >> n >> k;
  
  int x, sum = 0;
  for (int i = 0; i < n; i++) {
    cin >> x;
    if (2 * x < k) {
      sum += 2 * x;
    } else {
      sum += 2 * (k - x);
    }
  }
  
  cout << sum << endl;
}

Measured memory_bytes: 3568
// URL : https://atcoder.jp/contests/abc162/tasks/abc162_d
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;

const char wall = '#';
vector<vector<char>> fields;
vector<vector<bool>> used;
vector<vector<ll>> dist;
const int dx[4] = {0, -1, 0, 1};
const int dy[4] = {1, 0, -1, 0};

ll N;
char S[4001];
vector<ll> A;

ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return b/gcd(a,b)*b;}
ll ans = 0;
map<char, ll> m;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  cin >>N;
  rep(i, N){
    cin >> S[i];
    m[S[i]]++;
  }
  ans = m['R'] * m['G'] * m['B'];

  rep(j, N) {
    rep(i, j) {
      int k = j + (j - i); // 余事象のそれ
      if (k < N) {
        if (S[i] == S[j]) continue;
        if (S[k] == S[j]) continue;
        if (S[i] == S[k]) continue; // 色の一致は母数に含まれていないからここででくりめんとすると駄目
        ans--;
      }
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3652
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
#include <cctype>
using namespace std;
long long a[200020];
long long sum = 0;
int main() {
	long long n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		sum += a[i];
	}
	sum %= 1000000007;
	long long ans = 0;
	for (int i = 0; i < n; i++) {
		long long co = sum - a[i];
		while (co < 0) {
			co += 1000000007;
		}
		ans += a[i] * co;
		ans %= 1000000007;
	}
	long long x = 2;
	n = 1000000005;
	long long ans1 = 1;
	while (n > 0) {
		if ((n & 1) == 1) {
			ans1 = ans1 * x % 1000000007;
		}
		x = x * x % 1000000007;
		n >>= 1;
	}
	ans *= ans1;
	ans %= 1000000007;
	cout << ans << endl;
}


Measured memory_bytes: 5180
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#include <functional>
#include <stack>
#include <numeric>
typedef long long ll;
using namespace std;
const int MOD = (int)1e9 + 7;
const ll INF = (ll)1e18 + 7;
#define int long long
#define vint vector<int>
#define pint pair<int,int>
#define pb(a) push_back(a)
#define all(v) v.begin(),v.end()
#define dbg(x) cerr << #x << " = " << (x) << endl
#define yn(b) cout << ((b) ? "Yes" : "No") << endl
#define YN(b) cout << ((b) ? "YES" : "NO") << endl

int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};

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

	int a, b, c;
	cin >> a >> b >> c;

	if(a==b&&b==c){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}

	return 0;
}

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

int a;
string s;

int main()
{
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	
	cin>>a>>s;
	if(a>=3200)
	{
		cout<<s;
	}
	else 
	{
		cout<<"red\n";
	}
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define all(x) x.begin(), x.end()
#define mod 1000000007
typedef long long ll;

int main(){
  ll n;
  cin >> n;
  map<ll, ll, greater<ll>> mp;
  rep(i, n){
    ll num;
    cin >> num;
    mp[num]++;
  }
  int cnt = 0;
  ll saved;
  for(auto p : mp){
    if(cnt == 0){
      if(p.second >= 4){
        cout << p.first*p.first << endl;
        return 0;
      }else if(p.second >= 2){
        saved = p.first;
        cnt++;
      }
    }else{
      if(p.second >= 2){
        cout << saved*p.first << endl;
        return 0;
      }
    }
  }
  cout << 0 << endl;
  return 0;
}

Measured memory_bytes: 9724
import java.util.*;

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

		Map<String, Long> s = new HashMap<>();
		for (int i = 0; i < n; i++) {
			char[] cs = sc.nextLine().toCharArray();
			Arrays.sort(cs);
			String string = new String(cs);
			s.put(string, s.getOrDefault(string, 0L) + 1L);
		}

		long answer = 0;
		for (String k : s.keySet()) {
			answer += s.get(k) * (s.get(k) - 1) / 2;
		}
		System.out.println(answer);
	}
}


Measured memory_bytes: 103688
#include <stdio.h>
#include <string.h>
int  main() {
	int leng, x = 0, y = 0;
	int counter = 0;
	int a1 = 0;
	int a2 = 0;
	char str[105];
	char str2[105];
	char str3[105];
	scanf("%d", &leng);
	scanf("%s", str);
	for(int j = leng/2; j < leng;j++){
		str2[x] = str[j];
		a1 += str2[x];
		x++;
		
	}
	for(int i = 0;i < leng/2;i++){
		str3[y] = str[i];
		a2 += str3[y];
		y++;
	}
if(a1 == a2 && (a1 != 0 && a2!= 0)){
	printf("Yes");
}else{
	printf("No");
}


   return 0;
}

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

class Cube{
    int[] f;
    Cube(int[] Dice){
        f = new int[6];
        for(int i=0;i<6;i++){
            f[i] = Dice[i];
        }
    }
    
    void roll_z(){
        roll(1,2,4,3);
    }
    void roll_y(){
        roll(0,2,5,3);
    }
    void roll_x(){
        roll(0,1,5,4);
    }
    void roll(int i,int j,int k,int l){
        int t = f[i];
        f[i] = f[j];
        f[j] = f[k];
        f[k] = f[l];
        f[l] = t;
    } 
}

class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int[] C = new int[6];
		for(int i=0;i<6;i++) 
			C[i] = sc.nextInt();
		
		Cube Alfa = new Cube(C);
		
		for(int i=0;i<6;i++) 
			C[i] = sc.nextInt();
		
		Cube Beta = new Cube(C);
		
		boolean Flag = false;
		for(int i=0;i<4;i++) {
			for(int j=0;j<4;j++) {
				for(int k = 0;k<4;k++) {
					if(Arrays.equals(Alfa.f,Beta.f)) {
						Flag = true;
						break;
					}
					Beta.roll_x();
				}
				Beta.roll_z();
			}
			Beta.roll_y();
		}
		if(Flag) 
			System.out.println("Yes");
		else
			System.out.println("No");
	}
}


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

using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(ll i=1;i<=n;i++)
#define FOR(i,a,b) for(ll i=a;i<b;i++)

int main(){
	ll H,W; cin>>H>>W;
    char P[501][501];
    char A[501][501];
    char B[501][501];
    /*
        ****.
        *....
        ****.
        *....

        ....*
        .****
        ....*
        .****

        ・min
        
        **. ..*
        *.. .**
        **. ..*
    */

    rep1(i,H){
        string tmp; cin>>tmp;
        rep1(j,W){
            P[i][j]=tmp[j-1];
        }
    }

    rep1(i,H)rep1(j,W){
        A[i][j]='.';
        B[i][j]='.';
    }
    rep1(i,H){
        if(i%2==1){
            rep1(j,W-1) A[i][j]='#';
            B[i][W]='#';
        }
        else{
            FOR(j,2,W+1) B[i][j]='#';
            A[i][1]='#';
        }
    }
    rep1(i,H)rep1(j,W){
        if(P[i][j]=='#'){
            if(i%2==0) A[i][j]='#';
            else B[i][j]='#';
        }
    }

    //ans
    rep1(i,H){
        rep1(j,W){
            cout<<A[i][j];
        }
        cout<<endl;
    }
    cout<<endl;
    rep1(i,H){
        rep1(j,W){
            cout<<B[i][j];
        }
        cout<<endl;
    }
}

Measured memory_bytes: 1536
using System;
using System.Linq;
using System.Collections.Generic;
public class Hello
{
    public static void Main()
    {
        // Your code here!
        string S = Console.ReadLine();
        string T = Console.ReadLine();
        int[] start = new int[26]; //変換の表
        int[] goal  = new int[26]; //逆変換の表
        for(int i = 0; i < 26; i++) //変換表を初期化
        {
            start[i] = -1;
            goal[i] = -1;
        }
        
        for(int i = 0; i < S.Length; i++)
        {
            if(start[S[i] - 'a'] != -1 || goal[T[i] - 'a'] != -1) //すでに変換または逆変換がおこなわれている場合
            {
                if(start[S[i] - 'a'] != T[i] - 'a' || goal[T[i] - 'a'] != S[i] - 'a')//今回の変換とは違う or 今回の逆変換とは違う場合
                {
                    Console.WriteLine("No");
                    return;
                }
            }
            else
            {
                start[S[i] - 'a'] = T[i] - 'a'; //変換
                goal[T[i] - 'a'] = S[i] - 'a';　//逆変換
            }
            
        }
        Console.WriteLine("Yes");
        
    }
    
}

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

struct st {
	int x, y, c, d;
};
bool operator<(st a, st b) {
	return a.c > b.c;
}
int dx[]{ 0,1,0,-1 }, dy[]{ 1,0,-1,0 };
int s[30][30], c[4];
int d[30][30][4];
int main() {
	int w, h;
	while (scanf("%d%d", &w, &h), w) {
		rep(i, h)rep(j, w)scanf("%d", &s[i][j]);
		rep(i, 4)scanf("%d", &c[i]);
		memset(d, 0x3f, sizeof(d));
		d[0][0][0] = 0;
		priority_queue<st>que;
		que.push({ 0,0,0,0 });
		while (!que.empty()) {
			st p = que.top(); que.pop();
			if (d[p.x][p.y][p.d] != p.c)continue;
			int nx, ny;
			rep(i, 4) {
				nx = p.x + dx[i]; ny = p.y + dy[i];
				int y = (i + 4 - p.d) % 4;
				if (0 <= nx&&nx < h && 0 <= ny&&ny<w&&d[nx][ny][i]>p.c + c[y]) {
					d[nx][ny][i] = p.c + c[y];
					que.push({ nx,ny,d[nx][ny][i],i });
				}
			}
			if (s[p.x][p.y] < 4) {
				nx = p.x + dx[(p.d + s[p.x][p.y]) % 4];
				ny = p.y + dy[(p.d + s[p.x][p.y]) % 4];
			}
			else continue;
			if (0 <= nx&&nx < h && 0 <= ny&&ny<w&&d[nx][ny][(p.d + s[p.x][p.y]) % 4]>p.c) {
				d[nx][ny][(p.d + s[p.x][p.y]) % 4] = p.c;
				que.push({ nx,ny,d[nx][ny][(p.d + s[p.x][p.y]) % 4],(p.d + s[p.x][p.y]) % 4 });
			}
		}
		int Min = INT_MAX;
		rep(i, 4)Min = min(Min, d[h - 1][w - 1][i]);
		printf("%d\n", Min);
	}
}

Measured memory_bytes: 3308
import java.util.*;
import java.io.*;

public class Main {
	static boolean reachableFrom1[], reachableToN[], ok[];
	static List<ArrayList<Integer>> to, rto;
	public static void main(String[] args) {
		FastScanner fs = new FastScanner(System.in);
		int N = fs.nextInt(), M = fs.nextInt();
		int edges[][] = new int[M][3];
		to = new ArrayList<>();
		rto = new ArrayList<>();
		for(int i=0;i<N;i++) {
			to.add(new ArrayList<Integer>()); 
			rto.add(new ArrayList<Integer>()); 
		}
		for(int i=0;i<M;i++) {
			int a = fs.nextInt()-1, b = fs.nextInt()-1, c = fs.nextInt();
			edges[i][0] = a;
			edges[i][1] = b;
			edges[i][2] = -c; //ここを負の数にすることで、最短経路問題にできる。
			//負閉路があった場合は、スコアをいくらでも大きくできるので、infと出力。
			to.get(a).add(b);
			rto.get(b).add(a);
		}
		//前処理：１からたどり着けないノードと、Nまでたどり着けないノードを取り除く
		reachableFrom1 = new boolean[N];
		reachableToN = new boolean[N];
		dfs(0);
		rdfs(N-1);
		ok = new boolean[N];
		for(int i=0;i<N;i++)ok[i] = reachableFrom1[i]&&reachableToN[i];
		
		//Bellman Ford
		long dp[] = new long[N];
		long INF = Long.MAX_VALUE/2;
		Arrays.fill(dp, INF);
		dp[0]=0;
		boolean upd = true;
		int cnt = 0;
		while(upd) {
			upd = false;
			for(int now[]:edges) {
				int from = now[0];
				int to = now[1];
				int dist = now[2];
				if(!(ok[from]&&ok[to]))continue;
				if(dp[from]+dist<dp[to]) {
					upd = true;
					dp[to]= dp[from]+dist;
				}
			}
			cnt++;
			if(cnt > N+3) {
				System.out.println("inf");
				return;
			}
		}
		System.out.println(-dp[N-1]);
	}
	static void dfs(int v) {
		if(reachableFrom1[v]==true)return;
		reachableFrom1[v]=true;
		for(int next:to.get(v)) {
			dfs(next);
		}
	}
	static void rdfs(int v) {
		if(reachableToN[v]==true)return;
		reachableToN[v]=true;
		for(int next:rto.get(v)) {
			rdfs(next);
		}
	}
}

//高速なScanner
class FastScanner {
	private BufferedReader reader = null;
	private StringTokenizer tokenizer = null;

	public FastScanner(InputStream in) {
		reader = new BufferedReader(new InputStreamReader(in));
		tokenizer = null;
	}

	public String next() {
		if (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				tokenizer = new StringTokenizer(reader.readLine());
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken();
	}

	public String nextLine() {
		if (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				return reader.readLine();
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken("\n");
	}

	public long nextLong() {
		return Long.parseLong(next());
	}

	public int nextInt() {
		return Integer.parseInt(next());
	}

	public double nextDouble() {
		return Double.parseDouble(next());
	}

	public int[] nextIntArray(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = nextInt();
		return a;
	}

	public long[] nextLongArray(int n) {
		long[] a = new long[n];
		for (int i = 0; i < n; i++)
			a[i] = nextLong();
		return a;
	}
}

Measured memory_bytes: 24788
#include <stdio.h>
struct trump{
  char moji;
  int num;
};

void bubble(struct trump *,int);
void insertion(struct trump *,int);
int judge(struct trump *,struct trump *,int);

void bubble(struct trump k1[],int n){
  int i,j;
  struct trump tmp;
  for(i=0;i<n;i++){
    for(j=n-1;j>=i;j--){
      if(k1[j].num < k1[j-1].num) {
	tmp = k1[j];
	k1[j] = k1[j-1];
	k1[j-1] = tmp;
      }
    }
  }
}

void insertion(struct trump k2[],int n){
  int i,j;
  struct trump tmp;
  int minj;
  for(i=0;i<n;i++){
    minj = i;
    for(j=i;j<n;j++){
      if(k2[minj].num > k2[j].num)minj = j;
    }
    tmp = k2[minj];
    k2[minj]=k2[i];
    k2[i] = tmp;
  }
}

int judge(struct trump k1[],struct trump k2[],int n){
  int i;
  for(i=0;i<n;i++){
    if(k1[i].moji != k2[i].moji) return 0;
  }
  return 1;
}

int main(){
  struct trump k[36], k2[36];
  int i,j,n;
  char ik;
  scanf("%d%c",&n,&ik);
  for(i=0;i<n;i++){
    scanf("%c%d%c",&k[i].moji,&k[i].num,&ik);
  }
  for(i=0;i<n;i++){
    k2[i]=k[i];
  }
  bubble(k,n);
  insertion(k2,n);
  for(i=0;i<n-1;i++){
    printf("%c%d ",k[i].moji,k[i].num);
  }
  
  printf("%c%d\nStable\n",k[i].moji,k[i].num);
  for(i=0;i<n-1;i++){
    printf("%c%d ",k2[i].moji,k2[i].num);
  }
  printf("%c%d\n",k2[i].moji,k2[i].num);
  if(judge(k,k2,n)) printf("Stable\n");
  else printf("Not stable\n");
  
  return 0;
}

Measured memory_bytes: 608
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

n,m=map(int,input().split())
uf=UnionFind(n)
for i in range(m):
  a,b=map(int,input().split())
  uf.union(a-1,b-1)
ans = uf.group_count()-1
print(ans)



Measured memory_bytes: 12940
#include<iostream>
using namespace std;
string s;
int cnt,ans;
main(){
    cin>>s;
    for(int i=0;i<s.size();i++){
        if(s[i]=='A')cnt++;
        else if(s[i]=='T')cnt++;
        else if(s[i]=='C')cnt++;
        else if(s[i]=='G')cnt++;
        else cnt=0;
        ans=ans>cnt?ans:cnt;
    }
    cout<<ans<<endl;
}

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


void solve(long long X){
    ll ans = 0;
    ans += X / 500 * 1000;
    X %= 500;
    ans += X / 5 * 5;
    cout<<ans<<endl;
}

int main(){
    long long X;
    scanf("%lld",&X);
    solve(X);
    return 0;
}


Measured memory_bytes: 256
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

k = int(readline())
s = read().rstrip().decode()
if len(s) <= k:
    print(s)
else:
    print(s[:k] + '...')


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

ll inf =1e9+7;

#define pi 3.14159265358979323846L
bool isprime(ll a)
{
	
	ll cnt=0;	
	for(ll i=1;i*i<a;i++)
	{
		
	 	if(a%i==0)
	 	{
	 		cnt+=2;
		 }
		
		
	}
	
		if(cnt==2)
		return true;
		else
		return false;
		
}
ll mod(ll a)
{
	if(a<inf)return a;
	else
	return a%inf;
}
void solve()
{

ll n,m;
cin>>n>>m;
ll ele[n];

for(ll i=0;i<n;i++)cin>>ele[i];


vector<set<ll> >path(n+1);
for(ll i=0,x,y;i<m;i++)
{
	cin>>x>>y;
	path[x].insert(y);
	path[y].insert(x);
}

ll good=0;
bool notgood[n+1]={false};

for(ll i=1;i<=n;i++)
{
	if(notgood[i])continue;
	ll cnt=0;
	
	for(auto p: path[i])
	{
		if(ele[i-1]>ele[p-1])
		{
			notgood[p]=true;
			cnt++;
		}
	}
	if(cnt==path[i].size())good++;
}

cout<<good;


}

int main()
{


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

		solve();
	
return 0;

		
	}
	
	
	


Measured memory_bytes: 18212
import java.util.*;

public class Main {
    static boolean[] visit;
	static boolean[][] graph;
	static int N;
	static int count = 0;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        N = sc.nextInt();
        int M = sc.nextInt();
        int[] a = new int[M + 1];
        int[] b = new int[M + 1];
        graph = new boolean[N + 1][N + 1];
        visit = new boolean[N + 1];

        for (int i = 1; i <= M; i++) {
            a[i] = sc.nextInt();
            b[i] = sc.nextInt();
            graph[a[i]][b[i]] = graph[b[i]][a[i]] = true;
        }
		DFS(1);
            
        System.out.println(count);
    }

    static void DFS(int n) {
		visit[n] = true;
		
		boolean flag = true;
		for (int i = 1; i <= N; i++) {
			if (visit[i] == false) {
				flag = false;
			}
		}
		
		if (flag) {
			count++;
			visit[n] = false;
		}
		
		for (int i = 1; i <= N; i++) {
			if (!graph[n][i]) continue;
			if (visit[i]) continue;
			
			DFS(i);
		}
		visit[n] = false;
    }
}


Measured memory_bytes: 21844
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace contest
{
    class Program
    {
        static void Main(string[] args)
        {
            string S = Console.ReadLine();

            string result = "";
            foreach(var s in S)
            {
                switch (s)
                {
                    case '0':
                        result += "0";
                        break;
                    case '1':
                        result += "1";
                        break;
                    case 'B':
                        if(result != "")
                        {
                            result = result.Substring(0, result.Length - 1);
                        }
                        break;
                }
            }

            Console.WriteLine(result);
            Console.ReadLine();
        }
    }
}


Measured memory_bytes: 11092
#include <iostream>

using namespace std;

int main(){
    int n;
    cin >> n;
    for(int i = 1; i < 10; i++){
        if(n % i || 9 < n / i){
            continue;
        }
        cout << "Yes\n";
        return 0;
    }
    cout << "No\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll MOD=(ll)1e9+7;
//const ll MOD=(ll)998244353;
const ll INF=(ll)1e18+10;
const double PI = 2.0*acos(0);
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
int dy[]={-1,1,0,0};
int dx[]={0,0,-1,1};

void solve(int ca){
    int N; cin>>N;
    vector<pair<int,int>> ans;
    if(N&1){
        for (int i = 1; i <= N-1; ++i) {
            for (int j = i+1; j <= N; ++j) {
               if(i+j==N) continue;
               ans.emplace_back(i,j);
            }
        }
    }else{
        for (int j = 1; j <= N-1 ; ++j) {
            for (int i = j+1; i <= N; ++i) {
                if(i+j==N+1) continue;
                ans.emplace_back(j,i);
            }

        }
    }
    cout<<ans.size()<<endl;
    for(auto path:ans){
        cout<<path.first<<" "<<path.second<<endl;
    }
}

//#define MULTI
int main() {
#ifdef MULTI
    int N; cin>>N;
    for (int i = 0; i < N; ++i) {
        solve(i+1);
    }
#else
    solve(0);
#endif
    return 0;
}


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

int main(){
  long long N;
  cin >> N;
  vector<long long> A(N);
  for(int i=0;i<N;i++) cin >> A[i];
  
  long long money = 1000;
  for(int i=0;i<N-1;i++){
    long long stock = 0;
    if(A[i+1]>A[i]){
      stock += money / A[i];
      money -= stock * A[i];
    }
    money += stock * A[i+1];
    stock = 0;
  }
  
  cout << money << endl;
  return 0;
}


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

#define MOD 10000

int M;
char A[503], B[503];
short dp[503][10][2][2][503];

void dec(char *t){
  int n = strlen(t);
  t[n - 1]--;

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

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

int solve(char *t){
  int n = strlen(t);

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

  memset(dp, 0, sizeof(dp));

  for(int i = 1; i <= t[0]; i++){
    dp[1][i][0][i == t[0]][i % M] = 1;
    if(n != 1){
      dp[1][i][1][i == t[0]][i % M] = 1;
    }
  }

  for(int i = 1; i < n; i++){
    for(int next = 1; next <= 9; next++){
      dp[i + 1][next][0][0][next % M]++;
      dp[i + 1][next][0][0][next % M] %= MOD;
      if(i != n - 1){
        dp[i + 1][next][1][0][next % M]++;
        dp[i + 1][next][1][0][next % M] %= MOD;
      }
    }

    for(int before = 0; before <= 9; before++){
      for(int up = 0; up < 2; up++){
        for(int eq = 0; eq < 2; eq++){
          int from = up ? 0 : before + 1;
          int to = up ? before - 1 : 9;
          if(eq) to = min(to, (int)t[i]);

          for(int rem = 0; rem < M; rem++){
            if(dp[i][before][up][eq][rem] == 0) continue;

            for(int next = from; next <= to; next++){
              int nextEq = eq && next == t[i];
              int nextRem = (rem * 10 + next) % M;
              dp[i + 1][next][!up][nextEq][nextRem] += dp[i][before][up][eq][rem];
              dp[i + 1][next][!up][nextEq][nextRem] %= MOD;
            }
          }
        }
      }
    }
  }

  int res = 0;

  for(int before = 0; before <= 9; before++){
    for(int up = 0; up < 2; up++){
      for(int eq = 0; eq < 2; eq++){
        if(dp[n][before][up][eq][0] == 0) continue;
        //printf("before:%d up:%d eq:%d = %d\n",before,up,eq,dp[n][before][up][eq][0]);
        res += dp[n][before][up][eq][0];
        res %= MOD;
      }
    }
  }

  return res;
}

int main(){
  while(scanf("%s%s%d", A, B, &M) != EOF){
    dec(A);
    printf("%d\n", (solve(B) - solve(A) + MOD) % MOD);
  }
}

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

// region template
#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define trav(a, x) for (auto &a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;

ll gcd(ll a, ll b) { return __gcd(a, b); }

ll euclid(ll a, ll b, ll &x, ll &y) {
    if (b) { ll d = euclid(b, a % b, y, x);
        return y -= a/b * x, d; }
    return x = 1, y = 0, a;
}

typedef unsigned long long ull;
typedef long double ld;
ull mod_mul(ull a, ull b, ull M) {
    ll ret = a * b - M * ull(ld(a) * ld(b) / ld(M));
    return ret + M * (ret < 0) - M * (ret >= (ll)M);
}
ull mod_pow(ull b, ull e, ull mod) {
    ull ans = 1;
    for (; e; b = mod_mul(b, b, mod), e /= 2)
        if (e & 1) ans = mod_mul(ans, b, mod);
    return ans;
}

const ll mod = 1000000007;
struct Mod {
    ll x;
    Mod(ll xx) : x(xx) {}
    Mod operator+(Mod b) { return Mod((x + b.x) % mod); }
    Mod operator-(Mod b) { return Mod((x - b.x) % mod); }
    Mod operator*(Mod b) { return Mod((x * b.x) % mod); }
    Mod operator/(Mod b) { return *this * invert(b); }
    Mod invert(Mod a) {
        ll x, y, g = euclid(a.x, mod, x, y);
        assert(g == 1); return Mod((x + mod) % mod);
    }
    Mod operator^(ll e) {
        if (!e) return Mod(1);
        Mod r = *this ^ (e / 2); r = r * r;
        return e & 1 ? *this * r : r;
    }
};
// endregion

int main() {
    cin.sync_with_stdio(0); cin.tie(0); cin.exceptions(cin.failbit);

    int n, m; cin >> n >> m;
    pii r;
    rep(i, 0, m) {
        if (i == 0) cin >> r.first >> r.second;
        else {
            pii p;
            cin >> p.first >> p.second;
            if (r > p) swap(r, p);
            r = {max(r.first, p.first), min(r.second, p.second)};
            if (r.first > r.second) {
                break;
            }
        }
    }
    cout << max(r.second - r.first + 1, 0) << endl;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
from collections import deque

N = int(input())
G = [[] for _ in range(N)] # 辺の相手を保存
for i in range(N-1):
    a, b = map(lambda x: int(x) - 1, input().split())
    G[a].append([b, i])
    G[b].append([a, i])

stack = deque([[0, 0]])
visited = [0] * N
visited[0] = 1
ans = [0] * (N-1)
while stack:
    i, pc = stack.pop()
    c = 1
    for ni, ln in G[i]:
        if not visited[ni]:
            visited[ni] = 1
            if c == pc:
                c += 1
            ans[ln] = c
            c += 1
            stack.append([ni, ans[ln]])

print(max(ans)) 
for c in ans:
    print(c)


Measured memory_bytes: 46204
#include "iostream"
#include "string"
using namespace std;

int main()
{
	int n, count = 0,min;
	string s;
	cin >> n >> s;
	for (int i = 1; i < n; i++) {
		if (s[i] == 'E')count++;
	}
	min = count;
	for (int i = 1; i < n; i++) {
		if (s[i - 1] == 'W')count++;
		if (s[i] == 'E')count--;
		if (min > count)min = count;
	}
	cout << min << endl;
	return 0;
}



Measured memory_bytes: 900
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <cmath>
#include <numeric>
#include <utility>
#include <iomanip>

using namespace std;
using int64 = long long;

struct aaa{aaa(){cin.tie(nullptr); ios::sync_with_stdio(false); cout<<fixed<<setprecision(20);};}aaa;

int main() {
    int n, a, b;
    cin >> n >> a >> b;
    int ans = 0;
    for (int i=1; i<=n; i++) {
        int sum = 0;
        int c = i;
        while (c) {
            sum += c%10;
            c /= 10;
        }
        if (a<=sum && sum<=b) ans += i;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3124
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
using namespace std;
#define MOD @
#define ADD(X,Y) ((X) = ((X) + (Y)%MOD) % MOD)
typedef long long i64; typedef vector<int> ivec; typedef vector<string> svec;

int N, A[202020];
int once[202020];

int main()
{
	scanf("%d", &N);
	for (int i = 0; i < N; ++i) scanf("%d", A + i);

	if (A[0] != 0) {
		puts("-1");
		return 0;
	}
	once[N - 1] = A[N - 1];
	for (int i = N - 2; i >= 0; --i) {
		once[i] = max(A[i], once[i + 1] - 1);
	}
	for (int i = 0; i < N; ++i) {
		if (A[i] > i || A[i] < once[i]) {
			puts("-1");
			return 0;
		}
	}

	i64 ret = 0;
	for (int i = 1; i < N; ++i) {
		if (A[i] == A[i - 1] + 1) ret += 1;
		else  if (A[i] != 0) ret += A[i];
	}
	printf("%lld\n", ret);

	return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long; 
int main(){
	int k;	string s;
  	cin >> k >> s;
  	if(s.size() <= k) cout << s << endl;
  	else cout << s.substr(0,k)+"..." << endl;

}

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

int main() {
    int a,b;
    cin >> a >> b;
    if(a*b==2)
        cout << 3;
    else
        if(a*b==6)
            cout << 1;
        else
            if(a*b==3)
                cout << 2;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (long long i = 0; i < (long long)n; i++)
//#define _GLIBCXX_DEBUG
using namespace std;
using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using Vl = vector<ll>;
using vi = vector<int>;
using Graph = vector<vi>;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  // std::cout << std::fixed << std::setprecision(15); //"for float-base
  // problem"

  int N, A, B;
  string S;
  cin >> A >> B;
  cout << A * B;
  return 0;
}


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


def main():
    n, m = map(int, input().split())
    c = [0 for _ in range(n)]

    # KeyInsight
    # https://www.youtube.com/watch?v=UHfTqvaD0pk：
    # とっかかりとして，根付き木を考える（最終的には，木の形状は関係ない）
    # 始点x，終点yとして，根をrとする．
    # x -> yを x -> r, y -> rの形に分解
    # 関心があるのは偶奇のみ，同じ操作が偶数回あるときは操作しないことと同じ
    # x, yの登場回数がすべて偶数ならYES，奇数が1つでもあればNO
    for i in range(m):
        ai, bi = map(int, input().split())
        # 0-index
        ai -= 1
        bi -= 1
        c[ai] += 1
        c[bi] += 1

    for ci in c:
        if ci % 2 == 1:
            print('NO')
            exit()

    print('YES')


if __name__ == '__main__':
    main()


Measured memory_bytes: 4272
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0;i < (int)(n);i++)
using ll = long long;
const ll MOD=1000000007;
//const ll MOD=998244353;
const long long INF = 1LL << 60;
const double pi=acos(-1.0);

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



int main()
{
  string S; cin>>S;
  ll N=S.size();
  string newS="";
  rep(i,N){
    if(i<N-1&&S.substr(i,2)=="BC") {newS+='D'; i++;}
    else newS+=S[i];
  }
  S=newS;
  
  //cout<<S<<endl;
  
  vector<string> vec(0);
  
  string str="";
  for(auto cha:S){
    if(cha=='B'||cha=='C'){
      if(str!="") vec.push_back(str);
      str="";
    }
    else{
      str+=cha;
    }
  }
  vec.push_back(str);
  
  ll ans=0;
  for(auto str:vec){
    //cout<<str<<endl;
    ll n=str.size();
    ll count=0,sum=0;
    rep(i,n) if(str[i]=='D') {count++; sum+=i;}
    ans+=sum-count*(count-1)/2;
  }
  
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 5636
#include <bits/stdc++.h>
#define FI first
#define SE second
#define EPS 1e-9
#define ALL(a) a.begin(),a.end()
#define SZ(a) int((a).size())
#define MS(s, n) memset(s, n, sizeof(s))
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORE(i,a,b) for (int i = (a); i >= (b); i--)
#define FORALL(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
#define WHATIS(x) cout << #x << " is " << x << endl;
#define ERROR(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
//__builtin_ffs(x) return 1 + index of least significant 1-bit of x
//__builtin_clz(x) return number of leading zeros of x
//__builtin_ctz(x) return number of trailing zeros of x

using namespace std;
using ll = long long;
using ld = double;
typedef pair<int, int> II;
typedef pair<ll, II> III;
typedef complex<ld> cd;
typedef vector<cd> vcd;

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cout << *it << " = " << a << endl;
    err(++it, args...);
}

const ll MODBASE = 1000000007LL;
const int MAXN = 100010;
const int MAXM = 100010;
const int MAXK = 510;
const int MAXQ = 200010;

int n, a[MAXN], b[MAXN];
vector<int> z[MAXN];
vector<ll> c[MAXN], cc[MAXN];

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    cin >> n;
    FOR(i,0,n-1) cin >> a[i];
    ll ans = 0;
    FOR(C,1,n-1) {
        int k = 0;
        ll res = 0;
        while (k * C <= n-1) {
            int A = n - 1 - k * C;
            if (A <= C) break;
            if (A <= k * C && A % C == 0) break;

            //cout << A << ' ' << C << endl;

            res = res + a[A] + a[k * C];
            ans = max(res, ans);

            k++;
        }
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 7808
import java.util.Scanner;
 
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        if(a < b){
            if(b < c){
                System.out.printf("%d %d %d\n", a, b, c);
            }else if(a < c){
                System.out.printf("%d %d %d\n", a, c, b);
            }else{
                System.out.printf("%d %d %d\n", c, a, b);
            }
        }else{
            if(a < c){
                System.out.printf("%d %d %d\n", b, a, c);
            }else if(b < c){
                System.out.printf("%d %d %d\n", b, c, a);
            }else{
                System.out.printf("%d %d %d\n", c, b, a);
            }
        }
    }
}
 
 


Measured memory_bytes: 26300