akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

#define LOG(...) fprintf(stderr, __VA_ARGS__)
//#define LOG(...)
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); ++i)
#define RFOR(i, a, b) for (int i = (int)(b - 1); i >= (int)(a); --i)
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define RREP(i, n) for (int i = (int)(n - 1); i >= 0; --i)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(RALL(c))
#define SZ(a) ((int)(a).size())
#define BIT(x, i) (((x) >> (i)) & 1)
#define SQ(x) ((x) * (x))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

class ProgramError {};

struct ArrayType {
    int size;
    map<int, int> value;
};

map<char, ArrayType> Array;

void declare_array(char name, int size) {
    ArrayType ary;
    ary.size = size;
    Array[name] = ary;
}

void set_array(char name, int idx, int value) {
    if (EXIST(Array, name)) {
        if (idx < Array[name].size) {
            Array[name].value[idx] = value;
            return;
        }
    }
    throw ProgramError();
}

int get_array(char name, int idx) {
    if (EXIST(Array, name)) {
        if (idx < Array[name].size) {
            if (EXIST(Array[name].value, idx)) {
                return Array[name].value[idx];
            }
        }
    }
    throw ProgramError();
}

int number(string& s, int& idx) {
    int n = 0;
    while (isdigit(s[idx])) {
        n *= 10;
        n += s[idx] - '0';
        idx++;
    }
    return n;
}

int expression(string& s, int& idx) {
    if (isdigit(s[idx])) {
        return number(s, idx);
    } else {
        char name = s[idx];
        idx++;
        idx++; // [
        int n = expression(s, idx);
        idx++; // ]
        return get_array(name, n);
    }
}

void assignment(string& s, int& idx) {
    char name = s[idx];
    idx++;
    idx++; // [
    int n = expression(s, idx);
    idx++; // ]
    idx++; // =
    int value = expression(s, idx);
    set_array(name, n, value);
}

void declaration(string& s, int& idx) {
    char name = s[idx];
    idx++;
    idx++; // [
    int n = number(s, idx);
    idx++; // ]
    declare_array(name, n);
}

void program(string& s, int& idx) {
    if (s.find('=') != string::npos) {
        assignment(s, idx);
    } else {
        declaration(s, idx);
    }
}

int main() {
    string s;
    while (cin >> s, s != ".") {
        Array.clear();
        int line = 1;
        do {
            try {
                int idx = 0;
                program(s, idx);
            } catch (ProgramError e) {
                while (cin >> s, s != ".");
                goto OUT;
            }
            line++;
        } while (cin >> s, s != ".");
        line = 0;
    OUT:
        cout << line << endl;
    }
}

Measured memory_bytes: 3148
use proconio::input;
use proconio::marker::Usize1;
 
fn main() {
  input! {
    n: usize,
    k: isize,
    q: isize,
    resolvers: [Usize1;q as usize] 
  }
  let mut lifes = vec![k - q;n];
  for i in resolvers {
    lifes[i] += 1;
  }
  
  for v in lifes {
    if v > 0 {
      println!("Yes");
    } else {
      println!("No");
    }
  }
}

Measured memory_bytes: 4036
#include <stdio.h>
#include <iostream>
#include <iomanip>
#include <vector>
#include <cstdlib>
#include <cmath>
#include <numeric>
#include <algorithm>
#include <sstream>
#include <string>
#include <map>
#include <set>
using namespace std;

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


int main() {
	int n, m;
	cin >> n >> m;

	vector<vector<int> > vec(n);
	rep(i, n) {
		int k;
		cin >> k;
		rep(j, k) {
			int a;
			cin >> a;
			vec.at(i).push_back(a);
		}
	}
	vector<int> cnt(m);
	rep(i, n) {
		rep(j, vec[i].size()) {
			cnt[vec.at(i).at(j) - 1] += 1;
		}
	}
	int res = 0;
	rep(i, cnt.size()) {
		if (cnt.at(i) == n) res++;
	}
	cout << res << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
	using namespace std;
	typedef long long int ll;
	#define PRINT(x,y) cout<<"Case #"<<(int)x<<": "<<(int)(y)<<endl;
	ll exp(ll x, ll y) {
		if(y==0) return 1;
		if(y==1) return x;
		if(y%2==0) return exp(x,y/2)*exp(x,y/2);
		else return x*exp(x,y/2)*exp(x,y/2);
	}
	ll gcd(ll a , ll b) {
		if(b==0) return a;
		return gcd(b , a%b);
	}
	ll lcm(ll a , ll b) {
		return (a*b)/gcd(a,b);
	}
	#define MOD (1e9+7);
	#define sq(a) (a)*(a);
	#define io ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	int l;
	ll fact(ll x) {
		if(x==1) return 1;
		else return x*fact(x-1);
	}
	bool isPrime(int x) {
		int ans  = 0;
		for(int i=2;i<=sqrt(x);++i) {
			if(x%i==0) {
				ans = 1; i=x;
			}  
		}
		if(ans==0) return true;
		else return false;
	}
	int min3(int a , int b, int c) {
		return min(min(a,b),c);
	}
	ll modulo = 1000000007;
	ll nCr(ll n , ll r) {
			ll ans = 1;
			for(ll i = 0;i<=r-1;++i) {
				ans = ans*(n-i)/(i+1);
				if(ans>modulo) ans = ans%modulo;
			}
			return ans;
		}
	void solve() {
		int k; cin>>k;
		string s = "ACL";
		for(int i=1;i<=k;++i) cout<<s;
		exit(0);
		
	}

	int main() {
		io
		// int t; cin>>t;
		// while(t--)
	   solve();
	   return  0 ;
	    
	}


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

int main()
{
	LL x, k, d;
	cin >> x >> k >> d;
	if(x < 0)
		x = abs(x);
	LL ans;
	if(x == d){
		if(k % 2 == 0)
			ans = x;
		else
			ans = 0;
	}
	else{
		LL cnt = x / d;
		LL num = x % d;
		if(k <= cnt)
			ans = x - k * d;
		else{
			LL tmp = d - num;
			if((k - cnt) % 2 == 0)
				ans = num;
			else
				ans = tmp;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3564
#include<bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
using ll=long long;
using ld=long double;
#define INF 1000000009
const ll INFll=1ll*INF*INF;
#define MOD 998244353
#define MODE 1000000007
const long double PI=3.141592653589793238462643383279502884197169399375105820974944;
#define pb push_back
#define mp make_pair
#define rep(i,n) for (ll i = 0; i < n; i++)
#define rev(i,n) for (ll i = n; i >= 0; i--)
#define REP(i,a,b) for (ll i = a; i < b; i++)
#define REV(i,a,b) for (ll i = a; i >= b; i--)
#define all(v) v.begin(),v.end()
#define F first
#define S second
#define vl vector<ll>
#define pll pair<ll,ll>
#define sz(a) (ll)a.size()
#define print(arr) for (auto it = arr.begin(); it != arr.end(); ++it) cout << *it << ' '; cout << endl;
#define printii(arr) for (auto it = arr.begin(); it != arr.end(); ++it) cout << it->f<<' '<<it->s << endl; cout << endl;
#define MID(i,j) ((i)+(j))/2
#define nl '\n' 
#define lcm(a,b) ((a)*(b))/gcd((a),(b))
ll gcd(ll a,ll b)  {return (b==0)? a:gcd(b,a%b);}

long long bpow(long long a, long long b, long long m) {
  a %= m;
  long long res = 1;
  while (b > 0) {
    if (b & 1)res = res * a % m;
    a = a * a % m;
    b >>= 1;
}
return res;
}

ll sum(ll x){
    return (x*(x+1))/2;
}

void bfs(vl &vis, vl &path, vector<vl> &g, ll x){
	queue<ll>q;
	vis[x] = 1;
	q.push(x);
	while(q.size() != 0){
		ll x = q.front();
		q.pop();
		rep(i, g[x].size()){
			if(!vis[g[x][i]]){
				q.push(g[x][i]);
				vis[g[x][i]] = 1;
				path[g[x][i]] = path[x]+1;
			}
		}
	}
}

void solve(){;
	ll n;
	cin >> n;
	vl v(n);
	rep(i, n)cin >> v[i];
	vl dp(n);
	rep(i, n){
		if(i == 0)dp[i] = 0;
		else if(i == 1)dp[i] = abs(v[i]-v[0]);
		else dp[i] = min(dp[i-1]+abs(v[i]-v[i-1]), dp[i-2]+abs(v[i]-v[i-2]));
	}
	cout << dp[n-1] << endl;
}

int main(){
    ll t = 1;
    // cin >> t;
    while(t--){
        solve();
    }
    return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int a,b,c;
int main()
{
	scanf("%d%d%d",&a,&b,&c);
	int ans=a*100+b*10+c;
	if (ans%4==0) printf("YES");
	else printf("NO");
	return 0;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=(n)-1;i>=0;i--)
#define VSORT(v) sort(v.begin(), v.end())
#define DVSORT(v) sort(v.begin(), v.end(),greater<int>())
#define SORT(v, n) sort(v, v+n)
#define DSORT(v,n) sort(v, v+n,greater<int>())
#define vi vector<int>
#define pb push_back
#define P pair<int,int>


template <class T> void chmin(T&a, const T&b) { a = min(a,b); }
template <class T> void chmax(T&a, const T&b) { a = max(a,b); }

const double EPS =1e-9;
const long INF =999999999;
const long MOD =1000000007; //10^9+7
#define PI 3.14159265258979

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

int main(void){
	int K,S,result=0;
	cin>>K>>S;

	REP(x,K+1)
		REP(y,K+1)
			if(0<=(S-x-y)&&(S-x-y)<=K) result++;

	cout<<result<<endl;
	}



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

int main()
{
    long long x,a,b,s,i,j;
    while (cin>>x>>a>>b)
    {
        s=x-a;
        i=s/b;
        j=s-(b*i);
        cout<<j<<endl;
    }
    return 0;
}


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

int main() {
    //input
    string c;
    cin >> c;

    if(c == "a" || c == "i" ||c == "u" ||c == "e" ||c == "o"){
        cout << "vowel";
    }else{
        cout << "consonant";
    }

    return 0;
}

Measured memory_bytes: 256
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int N, v[110];
long long W, w[110], w0[110], w1[110], w2[110], w3[110];

long long max(int len, ...) {
    long long i, _max, num;
    va_list ap;
    va_start(ap, len);
 
    _max = va_arg(ap, long long);
    for (i = 1; i < len; i++) {
        num = va_arg(ap, long long);
        if (num > _max)
            _max = num;
    }
    va_end(ap);
    return _max;
}

int llcmp(const void *a, const void *b) {
    if (*(long long *)a < *(long long *)b) return 1;
    else if (*(long long *)a > *(long long *)b) return -1;
    else return 0;
}

int main(void) {
    int a, b, c, d, i, j, k, l, m;
    long long res, weight;
    scanf("%d%lld", &N, &W);
    for (i=0;i<N;i++) scanf("%lld%d", &w[i], &v[i]);

    j = 0; k = 0; l = 0; m = 0;
    for (i=0;i<N;i++) {
        if (w[i] == w[0]) w0[++j] = v[i];
        else if (w[i] == w[0]+1) w1[++k] = v[i];
        else if (w[i] == w[0]+2) w2[++l] = v[i];
        else w3[++m] = v[i];
    }
    qsort(w0+1,j,sizeof(long long),llcmp);
    qsort(w1+1,k,sizeof(long long),llcmp);
    qsort(w2+1,l,sizeof(long long),llcmp);
    qsort(w3+1,m,sizeof(long long),llcmp);
    for (a=1;a<=j;a++) w0[a] += w0[a-1];
    for (b=1;b<=k;b++) w1[b] += w1[b-1];
    for (c=1;c<=l;c++) w2[c] += w2[c-1];
    for (d=1;d<=m;d++) w3[d] += w3[d-1]; 
    res = 0; weight = 0;
    for (a=0;a<=j;a++) for (b=0;b<=k;b++) for (c=0;c<=l;c++) for (d=0;d<=m;d++) {
        weight = w[0]*a + (w[0]+1)*b + (w[0]+2)*c + (w[0]+3)*d;
        if (weight <= W) res = max(2,res,w0[a]+w1[b]+w2[c]+w3[d]);
    }

    printf("%lld\n", res);

    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
using Graph = vector<vector<int>>;

int main() {
    int N, Q; cin >> N >> Q;

    Graph G(N);
    vector<bool> visited(N,false);
    vector<int> counter(N, 0);
    for (int i = 0; i < N-1; ++i) {
        int a, b;
        cin >> a >> b;
        a--;b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    for (int i=0;i<Q;i++){
      int p,x;
      cin >> p >> x;
      p--;
      counter[p]+=x;
    }
    queue<int> que;
    que.push(0);
    visited[0]=true;

    // BFS 開始 
    while (!que.empty()) {
        int v = que.front(); //front()は先頭を見るだけ、削除はしない
        que.pop();//pop()で先頭を削除する

        for (int nv : G[v]) {
            if (visited[nv]) continue;
            que.push(nv);
            counter[nv]+=counter[v];
            visited[nv]=true;
        }
    }
    for(int i=0;i<N;i++)
      cout << counter[i] << endl;
    return 0;
}


Measured memory_bytes: 15604
import sys

sys.setrecursionlimit(10 ** 8)
ini = lambda: int(sys.stdin.readline())
inm = lambda: map(int, sys.stdin.readline().split())
inl = lambda: list(inm())
ins = lambda: sys.stdin.readline().rstrip()
debug = lambda *a, **kw: print("\033[33m", *a, "\033[0m", **dict(file=sys.stderr, **kw))

X, Y = inm()


def solve():
    ans = 1 << 40
    for x, y, c in [(X, Y, 0), (-X, Y, 1), (X, -Y, 1), (-X, -Y, 2)]:
        if x <= y:
            ans = min(ans, c + y - x)

    return ans


print(solve())


Measured memory_bytes: 9216
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include <math.h>


int ASC(const void *a, const void *b) {
	return *(int *)b - *(int *)a;//降順
}


int main(void)
{
	long long  n, ans = 0;
	scanf("%lld",&n);
	for (int i = 0; i <= n; i++) {
		if (i % 3 != 0 && i % 5 != 0) {
			ans += i;
		}
	}
	printf("%lld",ans);
	return 0;
}

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

int main(){
    int H,N;
    cin >> H >> N;
    vector<int> A;
    rep(i,N){
        int a;
        cin >>a;
        A.push_back(a);
    }
    int sum =0;
    rep(i,N){
        sum += A[i];
    }

    if(sum >= H){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
}

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

int main() {
  int N;
  cin >> N;
  vector<int> vec(N);
  for (int i = 0; i < N; i++) {
    cin >> vec.at(i);
  }
  sort(vec.begin(),vec.end());
  reverse(vec.begin(),vec.end());
  
  int sumA = 0;
  int sumB = 0;
  for (int i = 0; i < N; i +=2) {
    sumA += vec.at(i);
  }
  for (int i = 0; i < N - 1; i +=2) {
    sumB += vec.at(i + 1);
  }
  cout << sumA - sumB << endl;
}

Measured memory_bytes: 256
while 1:
	n,m = map(int,raw_input().split())
	if n == 0: break
	tsd = sorted([map(int,raw_input().split()) for i in range(m)])
	inf = [0]*n
	inf[0] = 1
	for t,s,d in tsd:
		if inf[s-1] == 1:
			inf[d-1] = 1
	print sum(inf)

Measured memory_bytes: 12636
n = int(input())
A = list(map(int, input().split()))

cnt_even = 0
cnt_odd = 0

for v in A:
	if v % 2 == 0:
		cnt_even += 1
	else:
		cnt_odd += 1

add_even = cnt_odd // 2 # odd + odd = even
cnt_odd -= add_even * 2

print('YES') if cnt_odd == 0 else print('NO')

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

typedef long long ll;

int main() {
    int N, A;
    cin >> N;
    set<int> s;
    rep(i, N) {
        cin >> A;
        if (s.count(A)) {
            cout << "NO" << endl;
            return 0;
        }
        s.insert(A);
    }
    cout << "YES" << endl;
}

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

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

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

    int N;
    cin >> N;

    int A, ans;
    cin >> A;
    ans = A;

    for (int i=1; i<N; ++i) {
        cin >> A;
        ans = gcd(ans, A);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 384
#include <stdio.h>

int main(void)
{
    int i;
    char S[100];
    scanf("%s", S);
    for(i = 0; S[i]!='\0'; ++i);
    if(i % 2 == 0) printf("No\n");
    else {
        int L, LL, LR, a, RL, RR, b, R, m = 0;
        a = i - 1;
        L = a / 2;
        R = L + 2;
        b = L / 2 + 1;
        for(int j = 0; j < b; j ++){
            LL = j; LR = L - j - 1; RL = R + j - 1; RR = i - j - 1;
            if(S[LL] == S[LR]){
                if(S[RL] == S[RR]){
                    if(S[LL] == S[RL]) m++;
                };
            };
        };
        if(m == b) printf("Yes\n");
        else printf("No\n");
    };
    
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define fi first
#define se second
#define rep(i,s,n) for(int i = s;i<n;i++)
#define rrep(i,s,n) for(int i = (n)-1;i>=(s);i--)
#define all(v) (v).begin(),(v).end()
#define chmin(a,b) a=min((a),(b))
#define chmax(a,b) a=max((a),(b))
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0)
typedef long long ll;
typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
const ll MOD=1000000007,INF=1ll<<60;
 
#define MAX_S 1010
string s,t;
int ld(string s1,string s2){
	int dp[MAX_S+1][MAX_S+1];
	int l1=s1.size(),l2=s2.size();
	rep(i,0,l1+1)dp[i][0]=i;
	rep(i,0,l2+1)dp[0][i]=i;
	rep(i,1,l1+1){
		rep(j,1,l2+1){
			int cost = (s1[i-1]==s2[j-1])?0:1;
			dp[i][j]=min({dp[i-1][j]+1,       //Insertion
			              dp[i][j-1]+1,       //Deletion
						  dp[i-1][j-1]+cost});//Replace
		}
	}
	return dp[l1][l2];
}


signed main() {
    IOS();
    cin>>s>>t;
    cout<<ld(s,t)<<endl;
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    return 0;
}


Measured memory_bytes: 11076
s = list(map(int,input()))
n = len(s)
cnt1 = 0
cnt0 = 0
s1 = s[:]
s2 = s[:]
if s1[0] == 0:
    for i in range(n-1):
        if s1[i] == 0:
            if s1[i+1] == 1:
                pass
            else:
                s1[i+1] = 1
                cnt0 += 1
        else:
            if s1[i+1] == 0:
                pass
            else:
                s1[i+1] = 0
                cnt0 += 1
else:# if s[0] == "1"
    s1[0] = 0
    cnt0 += 1
    for i in range(n-1):
        if s1[i] == 0:
            if s1[i+1] == 1:
                pass
            else:
                s1[i+1] = 1
                cnt0 += 1
        else:
            if s1[i+1] == 0:
                pass
            else:
                s1[i+1] = 0
                cnt0 += 1
if s2[0] == 1:
    for i in range(n-1):
        if s2[i] == 0:
            if s2[i+1] == 1:
                pass
            else:
                s2[i+1] = 1
                cnt1 += 1
        else:
            if s2[i+1] == 0:
                pass
            else:
                s2[i+1] = 0
                cnt1 += 1
else:
    s2[0] = 0
    cnt1 += 1
    for i in range(n-1):
        if s2[i] == 0:
            if s2[i+1] == 1:
                pass
            else:
                s2[i+1] = 1
                cnt1 += 1
        else:
            if s2[i+1] == 0:
                pass
            else:
                s2[i+1] = 0
                cnt1 += 1


l = [cnt0,cnt1]
print(min(l))

Measured memory_bytes: 45128
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <fstream>
#include <sstream>
#include <iomanip>
#define ll long long

using namespace std;

long long MOD = 1000000007;

ll dfs(int node, ll cnt, int num, vector<vector<int> > &edge, vector<int> &group){
    if(group[node]!=-1){
        return cnt;
    }

    group[node]=num;
    cnt++;

    for(auto &x:edge[node]){
        cnt=dfs(x, cnt, num, edge, group);
    }
    return cnt;
}

ll dfs2(int node, ll cnt, vector<vector<int> > &edge, vector<int> &group, vector<int> &used){
    if(used[node]==1){
        return cnt;
    }

    used[node]=1;
    cnt++;

    for(auto &x:edge[node]){
        if(group[x]==group[node]){
            cnt=dfs2(x, cnt, edge, group, used);
        }
    }
    return cnt;
}

template<typename T>
void cout_vec(vector<T> &vec){
    for(int i=0; i<vec.size(); i++){
        if (i!=0){
            cout << ' ';
        }
        cout << vec[i];
    }
    cout << endl;
}

template<typename T>
void cout_mat(vector<vector<T>  > &mat){
    for(int i=0; i<mat.size(); i++){
        vector<T> vec = mat[i];
        cout_vec(mat[i]);
    }
}

int main(){
    int N, M, K;
    cin >> N >> M >> K;
    vector<vector<int> > friend_(N,vector<int>(0));
    vector<vector<int> > block_(N,vector<int>(0));

    for(int i=0; i<M; i++){
        int A, B;
        cin >> A >> B;
        A--;B--;
        friend_[A].push_back(B);
        friend_[B].push_back(A);
    }

    for(int i=0; i<K; i++){
        int C, D;
        cin >> C >> D;
        C--;D--;
        block_[C].push_back(D);
        block_[D].push_back(C);
    }

    vector<int> group(N,-1);
    vector<int> tmp(N,0);
    int g=0;
    vector<ll> ans(N,0);
    for(int i=0; i<N; i++){
        ll cnt = dfs(i, 0, g, friend_, group);
        if(cnt>0){
            tmp[g]=cnt;
            g++;
        }
        ans[i]=tmp[group[i]]-1;
    }
    /*
    cout_vec(ans);
    cout<< endl;
    cout_mat(friend_);
    cout<<endl;
    cout_mat(block_);
    */

    for(int i=0; i<N; i++){
        for(auto &x:friend_[i]){
            if(group[i]==group[x]){
                ans[i]--;
            }
        }
        for(auto &x:block_[i]){
            if(group[i]==group[x]){
                ans[i]--;
            }
        }
    }

    for(int i=0; i<N; i++){
        cout << ans[i];
        if(i!=N-1){
            cout << ' ';
        }else{
            cout << endl;
        }
    }
}

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

const int maxn  = 3123456;

int n;
vector < int > adj[maxn];
int mat[maxn];
bool ok = 0;
 
void dfs(int v , int par = 0){
    for(auto u : adj[v])
        if(u!=par){
            dfs(u, v);
            if(mat[u] == 0 and mat[v] == 0)
                mat[u] = 1 , mat[v] = 1;
        }
}
 
int main(){
    cin >> n;
    for(int i = 1 ; i < n ; i ++){
        int u , v;
        cin >> u >> v;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    for(int i = 1 ; i <= n ; i ++)
        if(adj[i].size()> 1 ){
            dfs(i);
            break;
        }
    ok = 1;
    for(int i = 1 ; i <= n ; i ++)
        ok&=(mat[i]!=0);
    if(n==2)ok=1;
    cout << ((!ok) ? "First" : "Second");
    return(0);
}

Measured memory_bytes: 80436
#include<bits/stdc++.h>
#include<string>
#include<cmath>

using namespace std;

#define ll long long int
#define loop(i, n) for (int i = 0; i < n; i++)
#define loops(i, s, n) for (int i = s; i < n; i++)
#define pb push_back
#define mp make_pair
#define all(v) v.begin(),v.end()
#define sz(x) ((int)(x).size())
#define fi first
#define se second
#define MOD 1000000007

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

    ll n;
    cin>>n;

    ll t= n;
    int ans = 0;
    for(ll i = 2; i*i<=n; i++){
        int c = 0;
        while(t%i == 0){
            t/=i;
            c++;
        }
        for(int j = 1; j<10000; j++){
            if(c < j){
                break;
            }
            ans++;
            c-=j;
        }
    }
    if(t>1){
        ans++;
    }
    cout<<ans;
}

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

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

#define INF 1000000000

using namespace std;

int main() {
    int X;
    cin >> X;

    int ureshisa = 0;

    ureshisa += 1000 * (X / 500);
    X %= 500;

    ureshisa += 5 * (X / 5);

    cout << ureshisa << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int gcd(int a, int b) {
    if (a < b) {
        int t = a;
        a = b;
        b = t;
    }

    while (b) {
        int t = a % b;
        a = b;
        b = t;
    }

    return a;
}

int main() {
    int n;
    cin >> n;

    int ans = 0;
    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;
        ans = gcd(ans, a);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define REP(i, n) for (int i = 0; i < n; ++i)
#define range(i,a,b) ((a)<=(i) && (i)<(b))
#define debug(x) cout << #x << ' ' << '=' << ' ' << (x) << endl;
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
typedef long long ll;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;
typedef vector<ll> vec;
typedef vector<P> pvec;
typedef vector<vector<ll>> vvec;
typedef vector<vector<P>> pvvec;
typedef priority_queue<ll> PQI;
typedef priority_queue<P> PQP;
typedef priority_queue<ll,vector<ll>,greater<ll>> PQIG;
typedef priority_queue<P,vector<P>,greater<P>> PQPG;
const vector<int> dx = {0, -1, 0, 1, 1, 1, -1, -1};
const vector<int> dy = {1, 0, -1, 0, 1, -1, 1, -1};
const int MOD = (1000000007);
// const int MOD = (998244353);
// const int INF = (1 << 30); // 1073741824
const int INF = (1LL << 60); // 1152921504606846976
const double EPS = (1 >> 30);
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return 1;} return 0;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return 1;} return 0;}
template< typename T1, typename T2 > istream &operator>>(istream &is, pair< T1, T2 > &p) { is >> p.first >> p.second; return is; }



signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(15);
    //---------------------------------------------
    
    double l;
    cin>>l;
    double x=l/3;
    cout<<x*x*x<<endl;
    
}

Measured memory_bytes: 256
package main

import (
	"fmt"
)

const mod = int(1e9 + 7)

var ifac, fac []int

func main() {
	const cmax = int(5e5 + 1)
	fac = make([]int, cmax)
	ifac = make([]int, cmax)
	inv := make([]int, cmax)
	fac[0], fac[1] = 1, 1
	ifac[0], ifac[1] = 1, 1
	inv[0], inv[1] = 1, 1
	for i := 2; i < cmax; i++ {
		fac[i] = (fac[i-1] * i) % mod
		inv[i] = (mod - inv[mod%i]*(mod/i)) % mod
		if inv[i] < 0 {
			inv[i] += mod
		}
		ifac[i] = (ifac[i-1] * inv[i]) % mod
	}

	var n, m int
	fmt.Scan(&n, &m)

	var pt int
	for fx := 0; fx <= n; fx++ {
		pt += comb(n, fx) * perm(m-fx, n-fx) * (fx%2*-2 + 1)
		pt %= mod
	}
	if pt < 0 {
		pt += mod
	}

	fmt.Println(perm(m, n) * pt % mod)
}

func comb(n, r int) int {
	if r > n {
		return 0
	} else if r == 0 || r == n {
		return 1
	}
	t := (ifac[n-r] * ifac[r]) % mod
	return (t * fac[n]) % mod
}

func perm(n, r int) int {
	if r > n {
		return 0
	} else if r == 0 {
		return 1
	}
	return (fac[n] * ifac[n-r]) % mod
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}


Measured memory_bytes: 14012
import sys
sys.setrecursionlimit(10 ** 7)
read = sys.stdin.buffer.read 
inp = sys.stdin.buffer.readline
def inpS(): return inp().rstrip().decode()
readlines = sys.stdin.buffer.readlines 

class UnionFind():  
    # 各要素の親要素の番号を格納するリスト
    # 要素が根（ルート）の場合は-(そのグループの要素数)を格納する
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    # 要素xが属するグループの根を返す
    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    # 要素xが属するグループと要素yが属するグループとを併合する
    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

    # 要素xが属するグループのサイズ（要素数）を返す
    def size(self, x):
        return -self.parents[self.find(x)]

    # 要素x, yが同じグループに属するかどうかを返す
    def is_same(self, x, y):
        return self.find(x) == self.find(y)

    # 要素xが属するグループに属する要素をリストで返す
    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()}

    # ルート要素: [そのグループに含まれる要素のリスト]を文字列で返す (print()での表示用)
    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

N, M, K = map(int, inp().split())
uf = UnionFind(N)
ans = [0]*N
not_friend = [1]*N # 自分自身

for _ in range(M):
  a, b = map(int, input().split())
  a -= 1
  b -= 1
  uf.union(a, b)
  not_friend[a] += 1
  not_friend[b] += 1
  
for _ in range(K):
  c, d = map(int, input().split())
  c -= 1
  d -= 1
  if uf.is_same(c, d):
    not_friend[c] += 1
    not_friend[d] += 1  
    
ans = [uf.size(i) - not_friend[i] for i in range(N)]    
print(*ans)

Measured memory_bytes: 14160
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string>
#include <iomanip>
#include <math.h>
#include <utility>
#include <vector>
#include <map>
#include <unordered_map>
#include <cstdlib>
#define div1 1000000007
const long long INF = 1LL << 60;
using namespace std;
using ll = long long;
// a>b -> a==b;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
// a<b -> a==b;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

template <class T> void swap(T& a, T& b) { T t = std::move(a); a = std::move(b); b = std::move(t); }

int main(void)
{
    ll N, K, i, j, A[2000], in=0, ex=0, ans;

    cin >> N >> K;

    for(i=0; i<=N-1; i++){
        cin >> A[i];
    }

    for(i=0; i<=N-2; i++){
        for(j=i+1; j<=N-1; j++){
            if(A[i] > A[j]){
                in++;
            }
        }
    }

    for(i=0; i<=N-1; i++){
        for(j=0; j<=N-1; j++){
            if(A[i] > A[j]){
                ex++;
            }
        }
    }

    ans = (in * K) % div1;
    ans += (K*(K-1)/2)%div1 * ex % div1;
    ans = ans % div1;
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
	int A[200010],i,j,n,a=0,b=0;
	scanf("%d",&n);
	for(i=1;i<=n;i++){
		scanf("%d",&A[i]);
		if(A[i]%4==0) b++;
		if(A[i]%2!=0) a++;
	}
	if(a+b==n){
		if(a<=b+1) printf("Yes\n");
		else printf("No\n");
	}
	else{
		if(a<=b) printf("Yes\n");
		else printf("No\n");
	}
	return 0;
}

Measured memory_bytes: 512
#include <stdio.h>

int main(void){
	int r,D,x;
	int ans[10000];

	scanf("%d%d%d",&r,&D,&x);


	for(int i=0;i<10;i++){
		if(i==0){
			ans[0] = x * r - D; 
		}else{
			ans[i] = ans[i-1] * r - D;
		}
		printf("%d\n",ans[i]);
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(ll i = n;i >= 0;--i)
#define FOR(i,m,n) for(ll i = m, i##_len=(n);i <i##_len; ++i)
#define all(x) (x).begin(),(x).end()
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; }
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
const int INF = 1e9;
const ll LLINF = 1e16;

ll modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}


int main(void)
{
    ll n;
    cin >> n;
    ll sum = 0;

    ll pow10 = 1;
    vector<vector<ll>> c(10,vector<ll>(10,0));
    FOR(i,1,n+1){
        if( i % (pow10*10) == 0){
            pow10*=10;
        }
        ll dh = i / pow10;
        ll de = i % 10;
        c[dh][de] ++;
    }

    FOR(i,1,10){
        FOR(j,1,10){
            sum += c[i][j] * c[j][i];
        }
    }


    cout << sum << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define rep(i, a, b) for(int i=(a); i<(b); i++)
#define sz(a) (int)a.size()
#define de(a) cout<<#a<<" = "<<a<<endl
#define dd(a) cout<<#a<<" = "<<a<<" "
typedef long long ll;
typedef double db;
typedef pair<int, int> pii;
typedef vector<int> vi;
//----
const int N=101010;
char s[N];
int main(){
	scanf("%s", s);
	int n=strlen(s);
	rep(i, 0, n-1)if(s[i]==s[i+1]){
		return 0*printf("%d %d\n", i+1, i+2);
	}
	rep(i, 0, n-2)if(s[i]==s[i+2]){
		return 0*printf("%d %d\n", i+1, i+3);
	}
	printf("-1 -1\n"); 
	return 0;
}
/*
needed
atcoder
*/

Measured memory_bytes: 384
import java.io.PrintWriter

fun next() = readLine()!!
fun nextInt() = next().toInt()
fun nextLong() = next().toLong()
fun nextDouble() = next().toDouble()
fun nextList() = next().split(" ")
fun nextIntList() = nextList().map(String::toInt)
fun nextLongList() = nextList().map(String::toLong)
fun nextDoubleList() = nextList().map(String::toDouble)

val pw = PrintWriter(System.out)
fun print(s: Any = "") = pw.print(s)
fun println(s: Any = "") = pw.println(s)

fun <T> Iterable<T>.join(separator: CharSequence = ", ", prefix: CharSequence = "", postfix: CharSequence = "") = joinToString(separator, prefix, postfix)
fun <T> Array<T>.join(separator: CharSequence = ", ", prefix: CharSequence = "", postfix: CharSequence = "") = joinToString(separator, prefix, postfix)

fun main(args: Array<String>) {
    main()
    pw.flush()
}

fun main() {
    val S = next()
    println(S.replace(","," "))
}

Measured memory_bytes: 37868
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n) for(ll i=0;i<n;++i)
#define INF (1ll<<60)
#define mod 1000000007
#define P pair<ll,ll>
#define Graph vector<vector<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; }

//これだと、書き換えられた先に対して変更できない

bool check(vector<ll> &vec,ll n,ll caution){
    vector<vector<bool>> exist(4010,vector<bool>(16010,false));
    exist[0][8005]=true;
    ll num=vec.size();

    if(caution==0){
        exist[1][8005+vec[0]]=true;
    }else{
        exist[1][8005+vec[0]]=true;
        exist[1][8005-vec[0]]=true;
    }

    rep(i,num){
        if(i==0) continue;
        rep(j,16010){
            if(exist[i][j]==false) continue;
            exist[i+1][j+vec[i]]=true;
            exist[i+1][j-vec[i]]=true;
        }
    }

    return (exist[num][8005+n]==true);
}

int main(){
    string s;cin>>s;
    ll x,y;cin>>x>>y;
    
    vector<ll> proc;
    ll sum=0;
    rep(i,s.size()){
        if(s[i]=='F'){
            sum++;
            if(i==s.size()-1) proc.push_back(sum);
        }else{
            proc.push_back(sum);
            sum=0;
        }
    }

    vector<ll> odd,even;
    rep(i,proc.size()){
        if(i%2==1) odd.push_back(proc[i]);
        else even.push_back(proc[i]);
    }

    bool yes=false;
    if(even.size()!=0 && odd.size()!=0){
        if(check(even,x,0)==true && check(odd,y,1)==true){
            yes=true;
        }
    }else if(even.size()!=0){
        if(check(even,x,0)==true && y==0){
            yes=true;
        }
    }else if(odd.size()!=0){
        if(check(odd,y,1)==true && x==0){
            yes=true;
        }
    }

    if(yes) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    
    return 0;
}

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

typedef long long LL;
typedef pair<int, int> II;

const int MAXN = 15;
int n;
vector<II> a[MAXN];

int compute(int mask) {
    for (int i = 0; i < n; ++i) {
        if ((mask >> i & 1) == 0) {
            continue;
        }
        for (int z = 0; z < (int)a[i].size(); ++z) {
            int x = a[i][z].first;
            int y = a[i][z].second;
            if ((mask >> x & 1) != y) {
                return -1;
            }
        }
    }

    int cnt = 0;
    for (int i = 0; i < n; ++i) {
        cnt += mask >> i & 1;
    }
    return cnt;
}

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

        for (int j = 0; j < k; ++j) {
            int x, y;
            cin >> x >> y;
            x -= 1;
            a[i].push_back(II(x, y));
        }
    }

    int ans = 0;
    for (int mask = 0; mask < 1 << n; ++mask) {
        ans = max(ans, compute(mask));
    }

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define ld long double
#define MOD 1000000007
#define endl "\n"
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define MAXX 9000000000000000000
#define pii pair<int,int>
#define vi vector<int>
#define vvi vector<vector<int> >
#define vpi vector<pair<int,int> > 
#define vvpi vector<vector<pair<int,int> > >

int h,w,k,x1,x2,yy1,y2;
vvi vis(1000006);

string s[1000006];

void dfs()
{
	queue<pii> lis;
	lis.push(mp(x1, yy1));
	vis[x1][yy1] = 0;
	int i,j;
	while(!lis.empty())
	{
		auto it = lis.front();
		
		int x = it.ff, y = it.ss;

		lis.pop();

		// cout << x << y << k << endl;

		for(i=1;i<=k;i++)
		{
	    // return;
			if(x + i >= h)
			{
				break;
			}
			if(s[x+i][y] == '@' || (vis[x+i][y] <= vis[x][y] && vis[x+i][y] != -1))
			{
				break;
			}
			if(vis[x+i][y] == -1)
			{
				lis.push(mp(x+i, y));
			}
			vis[x+i][y] = 1+ vis[x][y];
		}
		for(i=1;i<=k;i++)
		{
			if(x - i < 0)
			{
				break;
			}
			if(s[x-i][y] == '@' || (vis[x-i][y] <= vis[x][y] && vis[x-i][y] != -1))
			{
				break;
			}
			if(vis[x-i][y] == -1)
			{
				lis.push(mp(x-i, y));
			}
			vis[x-i][y] = 1+ vis[x][y];

			// lis.push(mp(x-i, y));
		}
		for(i=1;i<=k;i++)
		{
			if(y + i >= w)
			{
				break;
			}
			if(s[x][y+i] == '@' || (vis[x][y+i] <= vis[x][y] && vis[x][y+i] != -1))
			{
				break;
			}
			if(vis[x][y+i] == -1)
			{
				lis.push(mp(x, y+i));
			}
			vis[x][y+i] = 1+ vis[x][y];

			// lis.push(mp(x, y+i));
		}
		for(i=1;i<=k;i++)
		{
			if(y - i < 0)
			{
				break;
			}
			if(s[x][y-i] == '@' || (vis[x][y-i] <= vis[x][y] && vis[x][y-i] != -1))
			{
				break;
			}
			if(vis[x][y-i] == -1)
			{
				lis.push(mp(x, y-i));
			}
			vis[x][y-i] = 1+ vis[x][y];

			// lis.push(mp(x, y-i));
		}
	}
}

int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	#ifndef ONLINE_JUDGE
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif

	int i,j;
	
	cin >> h >> w >> k;
	cin >> x1 >> yy1 >> x2 >> y2;

	x1--;
	x2--;
	yy1--;
	y2--;

	for(i=0;i<h;i++)
	{
		cin >>s[i];
		for(j=0;j<w;j++)
		{
			vis[i].pb(-1);
		}
	}

	dfs();

	// for(i=0;i<h;i++)
	// {
	// 	for(j=0;j<w;j++)
	// 	{
	// 		cout << vis[i][j] << " ";
	// 	}
	// 	cout << endl;
	// }
	cout << vis[x2][y2];
	
	
	return 0;
}

Measured memory_bytes: 69148
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

// input scanner
var sc = bufio.NewScanner(os.Stdin)

const (
	initialBufSize = 10e4
	maxBufSize     = 10e6
)

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	a, _ := strconv.Atoi(next())
	return a
}

func nextInt64() int64 {
	a, _ := strconv.ParseInt(next(), 10, 64)
	return a
}

func nextFloat64() float64 {
	a, _ := strconv.ParseFloat(next(), 64)
	return a
}

func nextInts(n int) []int {
	ret := make([]int, n)
	for i := 0; i < n; i++ {
		ret[i] = nextInt()
	}
	return ret
}
func nextFloats(n int) []float64 {
	ret := make([]float64, n)
	for i := 0; i < n; i++ {
		ret[i] = nextFloat64()
	}
	return ret
}
func nextStrings(n int) []string {
	ret := make([]string, n)
	for i := 0; i < n; i++ {
		ret[i] = next()
	}
	return ret
}

// util
func max(l []int) (int, int) {
	idx := 0
	ans := l[idx]
	for i, n := range l {
		if n > ans {
			idx = i
			ans = n
		}
	}
	return idx, ans
}

func min(l []int) (int, int) {
	idx := 0
	ans := l[idx]
	for i, n := range l {
		if n < ans {
			idx = i
			ans = n
		}
	}
	return idx, ans
}

func reverse(s string) string {
	rs := []rune(s)
	for i, j := 0, len(s)-1; i < j; i, j = i+1, j-1 {
		rs[i], rs[j] = rs[j], rs[i]
	}
	return string(rs)
}

// main
func main() {
	buf := make([]byte, initialBufSize)
	sc.Buffer(buf, maxBufSize)
	sc.Split(bufio.ScanWords)
	s := next()
	q := nextInt()
	var v bool
	front := make([]string, q)
	var fi int
	fi = q - 1
	end := make([]string, q)
	var ei int
	for i := 0; i < q; i++ {
		t := nextInt()
		if t == 1 {
			v = !v
		} else {
			f := nextInt()
			c := next()
			if f == 1 {
				if v {
					end[ei] = c
					ei++
				} else {
					front[fi] = c
					fi--
				}
			} else {
				if v {
					front[fi] = c
					fi--
				} else {
					end[ei] = c
					ei++
				}
			}
		}
	}
	sf := strings.Join(front, "")
	se := strings.Join(end, "")
	s = sf + s + se
	if v {
		fmt.Println(reverse(s))
	} else {
		fmt.Println(s)
	}
}


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

int num[500010],n;
char s[500010];

inline int rd()
{
	int x=0;char ch=getchar();
	for (;ch<'0'||ch>'9';ch=getchar());
	for (;ch>='0'&&ch<='9';ch=getchar()) x=x*10+ch-'0';
	return x;
}

int main()
{
	scanf("%s",s+1);
	n=strlen(s+1);
	for (int i=1;i<=n;i++) num[i]=(s[n-i+1]-'0')*9;
	n+=2;
	for (int i=1;i<n;i++) num[i+1]+=num[i]/10,num[i]%=10;
	int sum=0;
	for (int i=1;i<=n;i++) sum+=num[i];
	for (int j=1;j<=n*10;j++)
	{
		sum++;num[1]++;
		int now=1;
		while (num[now]>=10) num[now+1]++,num[now]-=10,sum-=9,now++;
		if (sum<=j) { printf("%d\n",(j+8)/9);break; }
	}
	return 0;
}

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

int main(){
	stack<int> S1;
	stack<pair<int,int> > S2;
	char ch;
	int sum = 0;
	for (int i = 0; cin >> ch; i++){
		if (ch == '\\') S1.push(i);
		else if (ch == '/' && S1.size() > 0){
			int j = S1.top(); S1.pop();
			sum += i - j;
			int a = i - j;
			while (S2.size() > 0 && S2.top().first > j){
				a += S2.top().second; S2.pop();
			}
			S2.push(make_pair(j, a));
		}
	}

	vector<int> ans;
	int t = 0;
	while (S2.size() > 0){
		ans.push_back(S2.top().second);
		S2.pop();
	}
	reverse(ans.begin(), ans.end());
	cout << sum << endl;
	cout << ans.size();
	for (int i=0; i<ans.size(); i++){
		cout << " ";
		t += ans[i];
		cout << ans[i];
	}
	cout << endl;

	return 0;
	
}

Measured memory_bytes: 1284
#include <iostream>

int main()
{
	int m, f, r;
	while (std::cin >> m >> f >> r) {
		if (m == -1 && f == -1 && r == -1) {
			break;
		}
		int total = m + f;
		if (m == -1 || f == -1) {
			std::cout << 'F';
		} else if (total >= 80) {
			std::cout << 'A';
		} else if (total >= 65) {
			std::cout << 'B';
		} else if (total >= 50) {
			std::cout << 'C';
		} else if (total >= 30) {
			if (r >= 50) {
				std::cout << 'C';
			} else {
				std::cout << 'D';
			}
		} else {
			std::cout << 'F';
		}
		std::cout << std::endl;
	}

	return 0;
}


Measured memory_bytes: 3096
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <numeric>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;


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

  vector<vector<int>> A(N, vector<int>(3));
  REP(i, N){
    cin >> A[i][0] >> A[i][1] >> A[i][2];
  }


  int ans = 0;
  REP(bit, (1<<3)){
    vector<int> vec(N, 0);
    REP(i, N) REP(j, 3){
      if((bit >> j)&1) vec[i] += A[i][j];
      else vec[i] += -A[i][j];
    }
    sort(ALL(vec), greater<>());

    int ret = 0;
    REP(i, M) ret += vec[i];
    chmax(ans, ret);
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h> 
#define fo(i,a,b) for(i=a;i<=b;i++)
#define fd(i,a,b) for(i=a;i>=b;i--)
#define min(a,b) (a<b?a:b)
#define max(a,b) (a>b?a:b)
typedef long long ll;
using namespace std;
const int maxn=2e3+5,mo=1e9+7;
int a,i,j,l,n,m,k,ans,t,f[maxn<<1][maxn];
void mod(int &x){
	x-=(x>mo)?mo:0;
}
int main(){
	scanf("%d%d%d",&n,&m,&k);k--;
	a=n%k;
	f[0][0]=1;
	t=(max((n/k),(m/k))+1)*2;
	fo(i,0,t){
		fo(j,0,n)if (f[i][j]){
			int s=f[i][j];
			fo(l,!i,min(n-j,k)) mod(f[i+1][j+l]+=s);
		}
	} 
	fo(i,1,t){
		fo(j,0,n) if (j%k==a&&f[i][j]){
			if (i*k-j<m) mod(ans+=f[i][j]);
		}
	}printf("%d\n",ans);
} 

Measured memory_bytes: 30720
#include<iostream>
#include<array>

int main(){
    char s[4];
    int a = 0,b = 0;
    char c,d = 'a';
    std::cin>>s;
    c = s[0];
    for(int i = 1; i < 4; i++){
        if(c == s[i]){
            a++;
        }else if(d == 'a'){
            d = s[i];
        }else if(d == s[i]){
            b++;
        }else{break;}
    }
    if(a == 1 && b == 1){
        std::cout<<"Yes"<<std::endl;
    }else{
        std::cout<<"No"<<std::endl;
    }

}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main{

	
	static Scanner scan = new Scanner(System.in);
		public static void main(String[] args){
			
			int start = scan.nextInt();
			int end = scan.nextInt();
//			int start = Integer.parseInt(args[0]);
//			int end = Integer.parseInt(args[1]);
			int test =scan.nextInt();
			int count=0;
			for(int i = start;i <= end;i++ ){
				if( test % i== 0){
					count++;
				}
			}
			System.out.println(count);
		}
}



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

#define rep(i, n) for(int i = 0; i<(n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef long long ll;

const int MAX_DIGIT = 50;
ll dp[100][2]; // dp[上から i 桁まで][ smaller ]

int main() {
    int N;
    ll K;
    cin >> N >> K;
    vector<ll> A(N);
    rep(i, N) cin >> A[i];

    memset(dp, -1, sizeof(dp)); // DP 配列を -1 で初期化
    dp[0][0] = 0; // 初期条件
    rep(d, MAX_DIGIT) {
        ll mask = 1LL << (MAX_DIGIT - d - 1);

        // A で元々 d 桁目にビットが立っているものの個数
        int num = 0;
        rep(i, N) if (A[i] & mask) ++num;

        // X の d 桁目を 0, 1 にしたときのコスト
        ll cost0 = mask * num;
        ll cost1 = mask * (N - num);

        // smaller -> smaller
        if (dp[d][1] != -1) {
            chmax(dp[d + 1][1], dp[d][1] + max(cost0, cost1)); // 0 でも 1 でも自在に大きい方
        }

        // exact -> smaller
        if (dp[d][0] != -1) {
            if (K & mask) { // K の d 桁目が 1 だったら、X の d 桁目は 0 にする
                chmax(dp[d + 1][1], dp[d][0] + cost0);
            }
        }

        // exact -> exact (K にぴったり合わせる)
        if (dp[d][0] != -1) {
            if (K & mask) chmax(dp[d + 1][0], dp[d][0] + cost1);
            else
                chmax(dp[d + 1][0], dp[d][0] + cost0);
        }
    }

    cout << max(dp[MAX_DIGIT][0], dp[MAX_DIGIT][1]) << endl;
}


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

using namespace std;

int c[1000000];

int main(){
	long long int n,a,b;
	cin>>n>>a>>b;
	for(int i=1;i<=n;i++)
	cin>>c[i];
	long long int ans=0;
	for(int i=2;i<=n;i++)
	{
		long long int l=c[i]-c[i-1];
		long long int aa=l*a;
		ans+=min(aa,b);
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int main(){
  int m,mn,mx;
  while(cin>>m>>mn>>mx,m!=0||mn!=0||mx!=0){
    vector<int> p(m);
    for(int i=0;i<m;i++)
      cin>>p[i];
    int df=0,cnt=0;
    for(int i=mn-1;i<mx;i++){
      if(df<=p[i]-p[i+1]){
        df = p[i]-p[i+1];
        cnt=i+1;
      }
    }
    cout<<cnt<<endl;
  }
}


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

int main(){
  float x1,y1,x2,y2,x3,y3,xp,yp;
  float a1,b1,a2,b2,A,B;
  while(cin>>x1>>y1>>x2>>y2>>x3>>y3>>xp>>yp){
    a1=x2-x1;
    a2=y2-y1;
    b1=x3-x1;
    b2=y3-y1;
    xp=xp-x1;
    yp=yp-y1;
    A=(b1*yp-b2*xp)/(a2*b1-a1*b2);
    B=(a2*xp-a1*yp)/(a2*b1-a1*b2);
    if(A+B<1&&A>0&&B>0) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
  }
  return 0;
}

Measured memory_bytes: 1220