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

using namespace std;

#define sqr(x) ((x) * (x))
#define pb push_back
#define mp make_pair
#define ins insert
#define er erase
#define bg begin()
#define ed end()
#define X first
#define Y second
#define fin(name) freopen(name, "r", stdin)
#define fout(name) freopen(name, "w", stdout)
#define files(name) fin(name".in"); fout(name".out")
#define enter cout << "\n"
#define space cout << " "
#define endl "\n"
#define fi(st,n) for (int i = (st); i <= (n); ++i)
#define fj(st,n) for (int j = (st); j <= (n); ++j)
#define fk(st,n) for (int k = (st); k <= (n); ++k)
#define fq(st,n) for (int q = (st); q <= (n); ++q)
#define fw(st,n) for (int w = (st); w <= (n); ++w)
#define ff(i, st, n) for (int (i) = (st); (i) <= (n); ++(i))
#define ei(st,n) for (int i = (st); i >= (n); --i)
#define ej(st,n) for (int j = (st); j >= (n); --j)
#define ek(st,n) for (int k = (st); k >= (n); --k)
#define ef(i, st, n) for (int (i) = (st); (i) >= (n); --(i))
#define ri(st,n) for (int i = (st); i < (n); ++i)
#define rj(st,n) for (int j = (st); j < (n); ++j)
#define rk(st,n) for (int k = (st); k < (n); ++k)
#define rq(st,n) for (int q = (st); q < (n); ++q)
#define rf(i, st, n) for (int (i) = (st); (i) < (n); ++(i))
#define clean(a) memset((a),0,sizeof (a))
#define sync ios_base::sync_with_stdio(0);cin.tie(0)
#define y1 dsklmlvmd

typedef long long ll;
typedef unsigned long long ull;
typedef double dbl;
typedef long double ldbl;
typedef pair<int, int> pii;
typedef vector<int> vi;

const int inf = (int)1e9;
const dbl eps = (dbl) 1e-8;
const int mod = (int) 10000007;
const int maxn = (int) 1e5 + 5;
//const dbl M_PI = (dbl)2 * (dbl)acos(0);

//cout<<fixed<<setprecision(10);
//srand(time(0));

int n, fl;
string st, s, t;

int main() {
//    fin("t.in");
    sync;
    cin >> n;
    cin >> s;
    cin >> t;
    st = "";
    fi(0, n) {
        st = "";
        rj(0, n)
            st += s[j];
        rj(n - i, n)
            st += t[j];
        fl = 1;
        rj(0, n)
            if (st[j] != s[j])
                fl = 0;
        rj(0, n)
            if (st[i + j] != t[j])
                fl = 0;

        if (fl) {
            cout << st.size() << endl;
            return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 256
// Author : Sarthak Kapoor
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define rep(i,n) for(int i=0;i<n;++i)
#define repa(i,a,n) for(int i=a;i<n;++i)
#define repr(i,n) for(int i=n-1;i>=0;--i)
#define repba(i,b,a) for(int i=b;i>=a;--i)
#define repab(i,a,b) for(int i=a;i<b;++i)
#define ll long long
#define ull unsigned long long
#define vi vector<int>
#define msi map<string,int>
#define mii map<int,int>
#define viip vector<pair<int,pair<int,int> > > 
#define mp make_pair
#define vip vector<pair<int,int> >
#define pb push_back 
#define po pop_back
#define fi first
#define sec second
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define s(v) v.size()
ll mod = 1000000007;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());//use rng()%n for numbers in range [0,n-1]
ll gcd(ll a,ll b){
	if(b==0)return a;
	return gcd(b,a%b);
}
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	int n;
	cin>>n;
	vi v(n);
	rep(i,n){
		cin>>v[i];
	}	
	sort(all(v));
	int m = n/2;
	int ans = v[m] - v[m-1];
	cout<<ans;
	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
#include <numeric>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cerr<<*i<<" "; cerr<<endl; }
inline bool valid(int x, int y, int W, int H){ return (x >= 0 && y >= 0 && x < W && y < H); }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
/*
bool ok(vector<int>& L, int X){
  int idx = L.size();
  int first = 0;
  while(true){
    int cnt = 1;
    int now = first;
    bool ok = true;
    REP(i, idx){
      if(now + L[i] <= X){
        now += L[i];
      }else{
        now = L[i];
        cnt++;
      }
      if(cnt > M || now > X){
        ok = false;
        break;
      }
    }
    if(ok) return true;

    idx--;
    assert(idx >= 0);
    first += L[idx];
    if(first > X) break;
  }
  return false;
}
*/
int N, M;
vector<int> L;
bool ok(int X){
  REP(i, N) if(L[i] > X) return false;

  int firstsum = 0;
  for(int b = 0; b < N; b++){
    if(firstsum > X) break;
    int rest = M - 1;
    int partial = 0;
    for(int i = b; i < N; i++){
      if(partial + L[i] > X){
        partial = L[i];
        assert(partial <= X);
        rest --;
      }else{
        partial += L[i];
      }
    }
    //printf("rest = %d partial = %d firstsum = %d X = %d\n", rest, partial, firstsum, X);
    if(rest >= 0 && partial + firstsum <= X) return true;

    firstsum += L[b];
  }
  return false;
}

int main(){
  while(cin>>N>>M && N){
    L.assign(N, 0);
    REP(i, N) scanf("%d", &L[i]);
    int S = accumulate(L.begin(), L.end(), 0);
    int lb = ceil(double(S) / M) - 1;
    int ub = S;
    while(ub - lb > 1){
      int mid = (ub + lb) / 2;
      if(ok(mid)){
        ub = mid;
      }else{
        lb = mid;
      }
    }
    cout<<ub<<endl;
  }
  return 0;
}

Measured memory_bytes: 1284
class StarrySkyTree:
    def __init__(self,num):
        leaf=1<<(num-1).bit_length()
        self.leaf=leaf
        self.data=[0]*leaf*2
        self.lazy=[0]*leaf*2
    def indices(self,l,r):
        L,R=l+self.leaf,r+self.leaf
        lm=(L//(L&-L))>>1
        rm=(R//(R&-R))>>1
        while L<R:
            if R<=rm:
                yield R
            if L<=lm:
                yield L
            L>>=1; R>>=1
        while L:
            yield L
            L>>=1
    def zeroindices(self,k):
        K=k+self.leaf
        limit=(K//(K&-K))>>1
        while K:
            if K<=limit:
                yield K
            K>>=1
    def _propagates(self,*ids):
        for i in reversed(ids):
            v=self.lazy[i-1]
            if v==0:
                continue
            self.lazy[2*i-1]+=v; self.lazy[2*i]+=v
            self.data[2*i-1]+=v; self.data[2*i]+=v
            self.lazy[i-1]=0
    def add(self,l,r,x):
        L,R=l+self.leaf,r+self.leaf
        while L<R:
            if L&1:
                self.lazy[L-1]+=x; self.data[L-1]+=x
                L+=1
            if R&1:
                R-=1
                self.lazy[R-1]+=x; self.data[R-1]+=x
            L>>=1; R>>=1
        for i in self.indices(l,r):
            self.data[i-1]=max(self.data[2*i-1],self.data[2*i])+self.lazy[i-1]
    def add1(self,k,x):
        k+=self.leaf
        self.data[k-1]+=x
        while k:
            k>>=1
            self.data[k-1]=max(self.data[2*k-1],self.data[2*k])+self.lazy[k-1]
    def query0(self,k):
        self._propagates(*self.zeroindices(k))
        L,R=self.leaf,k+self.leaf
        ret=0
        while L<R:
            if L&1:
                ret=max(ret,self.data[L-1])
                L+=1
            if R&1:
                R-=1
                ret=max(ret,self.data[R-1])
            L>>=1; R>>=1
        return ret

import sys
input=sys.stdin.readline
n,m=map(int,input().split())
sst=StarrySkyTree(n+1)
R=[[] for _ in range(n+1)]
for _ in range(m):
    l,r,a=map(int,input().split())
    R[r].append((l,a))
for i in range(1,n+1):
    v=sst.query0(i)
    sst.add1(i,v)
    for l,a in R[i]:
        sst.add(l,i+1,a)
print(sst.query0(n+1))

Measured memory_bytes: 104292
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define debug(x) cerr<<#x<<": "<<x<<endl
#define trav(a,x) for(auto &a:x)
#define all(x) x.begin(),x.end()
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    string s;
    cin >> s;
    ll numl = 0;
    ll sum=0;
    ll x=0;
    char last='.';
    for(char c:s) {
        if(c=='>') {
            sum += numl;
            if(x==0) ++sum;
            else --x;
            ++numl;
        }
        else {
            if(last=='>') x = 0;
            numl = 0;
            ++x;
            sum += x;
        }
        last = c;
    }
    cout<<sum<<endl;
}


Measured memory_bytes: 1172
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;

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

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int main(void){
    int n, k;
    cin >> n >> k;
    VI a(n);
    REP(i,n) cin >> a[i];

    sort(ALL(a));
    int d = a[0];
    REP(i,n){
        d = __gcd(d, a[i]);
    }

    if (k <= a[n-1] && k % d == 0){
        cout << "POSSIBLE" << endl;
    }else{
        cout << "IMPOSSIBLE" << endl;
    }
}

Measured memory_bytes: 640
from sys import stdin
n,k = map(int,stdin.readline().rstrip().split())
li = list(map(int,stdin.readline().rstrip().split()))
nai = 0
ato = 0
point = 0
for i in range(n):
    for s in range(i+1,n):
        if li[i] > li[s]:
            nai += 1
    for v in range(n):
        if li[i] > li[v]:
            ato += 1
point += (nai*k)+(ato*k*(k-1)//2)
print(point%(10**9+7))

Measured memory_bytes: 3188
import  math

x1, y1, x2, y2 = [int(i) for i in input().split()]

height = y2-y1
width = x2-x1

x3 = x2 - height
x4 = x1 - height
y3 = y2 + width
y4 = y1 + width

print(x3, y3, x4, y4)

Measured memory_bytes: 3060
#include <iostream>
#include <string>

int main(void)
{
  std::string S;
  std::cin >> S;

  long long count = 0;
  int whites = 0;
  for(int i=S.length()-1; 0<=i; i--)
  {
    if(S[i]=='W') { whites += 1; continue; }
    else
    {
      count += whites;
    }
  }
  std::cout << count ;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
// #define int long long
#define endl '\n'
#define pb push_back
#define fi first
#define se second
#define all(c) (c).begin(),(c).end()
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define TRACE
#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

const ll inf = 2e18;
const int mod = 1e9 + 7;
const int N = 1e6 + 10;

int tr[N][26], cnt[N][26];

signed main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);

	int n;
	cin >> n;
	string s[n];
	int lev = 0;
	for(int i = 0; i < n; i++) {
		cin >> s[i];
		reverse(all(s[i]));
		int val[26] = {0};
		for(auto it : s[i]) {
			val[it - 'a']++;
		}
		int cur = 0;
		for(auto it : s[i]) {
			for(int j = 0; j < 26; j++) {
				if(val[j]) {
					cnt[cur][j]++;
				}
			}
			if(tr[cur][it - 'a'] == 0) {
				lev++;
				tr[cur][it - 'a'] = lev;
			}
			cur = tr[cur][it - 'a'];
			val[it - 'a']--;
		}
	}
	ll ans = 0;
	for(int i = 0; i < n; i++) {
		int cur = 0;
		for(int j = 0; j < (int)s[i].length() - 1; j++) {
			cur = tr[cur][s[i][j] - 'a'];
		}
		ans += (ll)cnt[cur][s[i].back() - 'a'];
		ans--;
	}
	cout << ans;

	return 0;
}

Measured memory_bytes: 207364
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
using namespace std;
int main() {
	vector<int> a(3);
	cin >> a[0] >> a[1] >> a[2];
	sort(a.begin(), a.begin() + 3);
	cout << a[0] << ' ' << a[1] << ' ' << a[2] << endl;
	return 0;
}

Measured memory_bytes: 1204
#include <iostream>
#include <string>
#include <map>

using namespace std;

int main(void){
    // Your code here!
    while(true){
        int N;
        cin >> N;
        if(N == 0){
            break;
        }
        map<char , char> change;
        for(int i=0;i<N;i++){
            char before ,after;
            cin >> before >> after;
            change[before] = after;
        }
        
        int M;
        cin >> M;
        for(int i=0;i<M;i++){
            char c;
            cin >> c;
            if(change.count(c)){
                c = change[c];
            }
            cout<< c;
        }
        cout<<endl;
    }
    return 0;
}



Measured memory_bytes: 3016
#include <bits/stdc++.h>
using namespace std;
//NOT TO SUBMIT IN WRONG PLACE OR BY WRONG COMPILER
//ABC, task d, 2020/04/19
//ms, ac
/*
*/

int main(void){
  int64_t N;
  int K;
  int64_t ans=0;

  cin >>N >>K;

  for(int64_t i=K;i<N+2;i++){
    ans += i*(2*N-i+1)/2 - i*(i-1)/2 + 1;
    //cout <<i <<" " <<ans <<endl;
    ans %= 1000000007;
  }

  cout <<ans <<endl;

  return 0;
}

Measured memory_bytes: 3636
#include<algorithm>
#include<iostream>
#include<vector>
#include<string>
#include<cstring>
#include<utility>
#include<queue>
#include<cmath>
#include<cstdio>
using namespace std;
#define REP(i, a,b) for(i=a;i<b;i++) 
#define REP1(i,b,a) for(i=b-1;i>=a;i--)
#define output(x) cout<<x<<endl;
#define pb(x) push_back(x);
typedef long long int ll;
typedef pair<int, int> P;
// ConsoleApplication69.cpp : アプリケーションのエントリ ポイントを定義します。
//



int par[100001];
ll kosu[100001];

void init(int n) {
	for (int i = 0; i < n; i++) {
		par[i] = i;
		kosu[i] = 1;
	}
}
//木の根を求める
int root(int x) {
	if (par[x] == x)
		return x;
	else {
		return par[x] = root(par[x]);
	}
}
//find
bool same(int x, int y) {
	return root(x) == root(y);

}
//union
void unite(int x, int y) {
	x = root(x);
	y = root(y);
	if (x == y) return;
	par[x] = y;
	kosu[y] += kosu[x];
}



int main() {
	ll i, j, k, l, m, n, sum, flag, cc, M, X, H, W, N, K;
	cin >> N >> M;
	vector<int>A(M);
	vector<int>B(M);
	vector<ll>C(M+1);
	
	init(N);
	REP(i, 0, M) {
		cin >> A[i] >> B[i];
	}
	reverse(A.begin(), A.end());
	reverse(B.begin(), B.end());
	C[0] = (N * (N - 1)) / 2;
	REP(i, 0, M) {
		if (root(A[i]) == root(B[i])) {
			C[i + 1] = C[i];
		}
		else {
			C[i + 1] = C[i] - kosu[root(A[i])] * kosu[root(B[i])];
		}
		unite(A[i], B[i]);
		
	}
	reverse(C.begin(), C.end());
	for (i = 1; i <= M; i++) {
		output(C[i]);
	}
	
	return 0;
}



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

using namespace std;

typedef long ll;


vector<pair<int,bool>> st[100001];
bool mk[100001];

int n;

#define DB

int main(int, char**)
{
	ll n, k;
	cin >> n >> k;

	if (k >= pow(2, n)) {
		cout << -1 << endl;
		return 0;
	}

	if (n == 1) {
		if (k==0) {
			cout << "0\n0\n1\n1" << endl;
		} else {
			cout << -1 << endl;
		}
		return 0;
	}

	for (int i = 0; i < pow(2,n); i++) {
		if (i != k)
			cout << i << "\n";
	}
	cout << k << "\n";
	for (int i = pow(2,n)-1; i >= 0; i--) {
		if (i != k)
			cout << i << "\n";
	}
	cout << k << "\n";

	return 0;
}



Measured memory_bytes: 4224
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
using namespace std;

int main(){
    int a,b,p,q,r;
    cin >> a >> b >> p >> q >> r;
    cout << fixed << setprecision(10);
    cout << (double)(p*b -(b-a)*q) /(q+r) +b << endl;
    return 0;
}



Measured memory_bytes: 3288
package main
import (
    "fmt"
    "os"
    "bufio"
    "strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	n, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return n
}


func main(){
    sc.Split(bufio.ScanWords)
    
    n := nextInt()
    m := nextInt()
    
    // cango := make(map[int][]int)
    cango := make([][]int, n+1)
    
    for i := 0; i < m; i++ {
        a := nextInt()
        b := nextInt()
        
        cango[a] = append(cango[a], b)
        cango[b] = append(cango[b], a)
    }
    
    var q Queue
    q.Add(1)
    
    // togo := make(map[int]int)
    togo := make([]int, n+1)
    
    for len(q) > 0 {
        now := q.Remove()
        for i := 0; i < len(cango[now]); i++ {
            if togo[cango[now][i]] == 0 {
                togo[cango[now][i]] = now
                q.Add(cango[now][i])
            }
        }
    }
    
    var ans []int
    for i := 2; i <= n; i++ {
        if x := togo[i]; x != 0 {
            ans = append(ans, x)
        } else {
            fmt.Println("No")
            return
        }
    }
    
    fmt.Println("Yes")
    for i := 0; i < len(ans); i++ {
        fmt.Println(ans[i])
    }
}

type Queue []int

func (q *Queue) Add (n int) {
    *q = append(*q, n)
}

func (q *Queue) Remove () int {
    temp := *q
    *q = temp[1:]
    return temp[0]
}

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

using namespace std;


int main()
{
	int n,cnt=0,min,min_i;
	cin >> n;
	
	vector<int> a(n),v(0);
	
	for(int i=0;i<n;i++){
		cin >> a[i];
	}
	
	v.push_back(a[0]);
	min = a[0];
	min_i = 0;
	
	for(int i=1;i<n;i++){
		if(min >= a[i]){
			v.push_back(a[i]);
			min_i = v.size() - 1;
			min = a[i];
		}
		else{
			for(int j=0;j<v.size();j++){
				if(a[i] > v[j]){
					if(v[j] == min && j == min_i){
						min = a[i];
					}
					v[j] = a[i];
					break;
				}
			}
		}
	}
	
	cout << v.size() << endl;
			

	return 0;
}

Measured memory_bytes: 1276
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int main(){
    IOS;
    long long n,a,b;
    cin >> n >> a >>b;
    if(a==b && a==0){
        cout << 0 <<endl;
    }else{
        long long ans = n/(a+b);
        cout << a*ans + min(a,n-(ans*(a+b))) <<endl;
    }
}

Measured memory_bytes: 3580
package main

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

var sc = bufio.NewScanner(os.Stdin)

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

func nextInt() int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}

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

func nextInts(n int) []int {
	slice := make([]int, n)
	for i := 0; i < n; i++ {
		slice[i] = nextInt()
	}
	return slice
}

func main() {
	sc.Split(bufio.ScanWords)
	a, op, b := nextInt(), next(), nextInt()
	var ans int
	switch op {
	case "+":
		ans = a + b
	case "-":
		ans = a - b
	}
	fmt.Println(ans)
}


Measured memory_bytes: 640
/*
 * 3つの整数を読み込み、それらを小さい順に並び替えて出力する
 * プログラム。
 *
 * Input
 * a b c
 *
 * Constraints
 * 1<=a,b,c<=10000
 */

#include <stdio.h>

int main()
{
	int a,b,c,tmp;
	scanf("%d %d %d", &a, &b, &c);

	if (a > b) {
		tmp = a;
		a = b;
		b = tmp;
	}
	if (b > c) {
		tmp = b;
		b = c;
		c = tmp;
	}
	if (a > b) {
		tmp = a;
		a = b;
		b = tmp;
	}
	
	printf("%d %d %d\n", a, b, c);
	return 0;
}


Measured memory_bytes: 1988
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;

using static Input;
using static Util;
class Program
{
    static string S;
    static int Q;
    static int[] T, F;
    static char[] C;
    static void INPUT()
    {
        S = NextString();
        Q = NextInt();
        T = new int[Q];
        F = new int[Q];
        C = new char[Q];
        for (var i = 0; i < Q; i++)
        {
            var t = NextInt();
            T[i] = t;
            if (t == 2)
            {
                F[i] = NextInt();
                C[i] = NextString().First();
            }
        }
    }

    static void OUT()
    {
        var list = new LinkedList<char>(S);
        var rev = false;
        for (var i = 0; i < Q; i++)
        {
            switch (T[i])
            {
                case 1:
                    rev = !rev;
                    break;
                case 2:
                    var b = F[i] == 1;
                    if (rev)
                        b = !b;
                    if (b)
                        list.AddFirst(C[i]);
                    else
                        list.AddLast(C[i]);

                    break;
            }
        }

        var s = string.Join("",list);
        if (rev)
            s = string.Join("",s.Reverse());

        Console.WriteLine(s);
    }
    static void Main(string[] args)
    {
#if DEBUG  
        //TESTINPUT();
        INPUT();

#else
        INPUT();
#endif
        OUT();
    }

    static void TESTINPUT()
    {
    }

}

public class Input
{
    public const long MOD = 1000000007;
    public const int INF = 1000000007;
    private static Queue<string> q = new Queue<string>();
    private static void Confirm() { if (q.Count == 0) foreach (var s in Console.ReadLine().Split(' ')) q.Enqueue(s); }
    public static int NextInt() { Confirm(); return int.Parse(q.Dequeue()); }
    public static long NextLong() { Confirm(); return long.Parse(q.Dequeue()); }
    public static string NextString() { Confirm(); return q.Dequeue(); }
    public static double NextDouble() { Confirm(); return double.Parse(q.Dequeue()); }
    public static int[] LineInt() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); }
    public static long[] LineLong() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); }
    public static string[] LineString() { return Console.ReadLine().Split(' ').ToArray(); }
    public static double[] LineDouble() { return Console.ReadLine().Split(' ').Select(double.Parse).ToArray(); }
}

class Util
{

}




Measured memory_bytes: 37900
#include<bits/stdc++.h>
using namespace std;
class BIT{
public:
  int n,bit[500010];
  BIT(){fill(bit,bit+500010,0);}
  void add(int i,int x){
    while(i<=n){
      bit[i]+=x;
      i+=i&-i;
    }
  }
  int sum(int i){
    int s=0;
    while(i>0){
      s+=bit[i];
      i-=i&-i;
    }
    return s;
  }
};
int n,c=1;
BIT b=BIT();
int calc(int x){
  int res=0;
  if(c+x>n) {
    res=b.sum(n)-b.sum(c)+b.sum((c+x)-n);
  }else{
    res=b.sum(c+x)-b.sum(c);
  }
  return res;
}
int calc2(int x){
  int res=0;
  if(c-x<=0){
    res=b.sum(n)-b.sum(c-x+n-1)+b.sum(c-1);
  }else{
    res=b.sum(c-1)-b.sum(c-x-1);
  }
  return res;
}
 
int next(){
  int l=0,r=n,mid;
  while(l+1<r){
    mid=(l+r)/2;
    if(calc(mid)<1) l=mid;
    else r=mid;
  }
  //cout << l << endl;
  if(c+l+1>n) c-=n;
  return c+l+1;
}
int main(){
  int m,Q,a,q,i,j,x,l,r,mid;
  cin>>n>>m>>Q,x=n;
  bool f[n+1],s;
  memset(f,0,sizeof(f));
  b.n=n;
  for(i=0;i<n;i++) b.add(i+1,1);
  for(i=0;i<m;i++){
    scanf("%d",&a);
    s=a%2;a%=x;
    if(a){
      if(!s){
        l=0;r=n;
        while(l+1<r){
          mid=(l+r)/2;
          if(calc(mid)<a) l=mid;
          else r=mid;
        }
        //cout << a << l << calc(l) << calc(l+1) << endl;
        c=c+l+1;
        if(c>n) c-=n;
      }else{
        l=0;r=n;
        while(l+1<r){
          mid=(l+r)/2;
          if(calc2(mid)<a) l=mid;
          else r=mid;
        }
        //cout << a << l << calc2(l) << calc2(l+1) << endl;
        c=c-l-1;
        if(c<=0) c+=n;
      }
    }
    //cout << c << " ";
    f[c]=1;
    b.add(c,-1);
    //for(j=0;j<n;j++) cout<<f[j+1];cout<<endl;
    //for(j=0;j<n;j++) cout<<b.sum(j+1)-b.sum(j);cout<<endl;
    c=next();
    //cout << c << endl;
    x--;
  }
   
  while(Q--) cin>>q,cout<<!f[q+1]<<endl;
}

Measured memory_bytes: 5288
#include<bits/stdc++.h>
#include<string>
using namespace std;
int main(){
	long long  max=0;
	int n;
	cin>>n;
	long long  a[n];
	long long  s=0;
	for(int i=0;i<n;i++){
		cin>>a[i];
		if(a[i]>max)
		max =a[i];
		if(a[i]<max)
		s += max -a[i];
	}
	cout<<s;
}

Measured memory_bytes: 5180
#include<iostream>
#include<vector>

using namespace std;

int main() {
	int n;
	cin >> n;
	vector<int> a(n), b(n), c(n - 1);

	for (int i = 0; i < n; i++) {
		cin >> a.at(i);
	}
	for (int i = 0; i < n; i++) {
		cin >> b.at(i);
	}
	for (int i = 0; i < n-1; i++) {
		cin >> c.at(i);
	}

	int point = 0;

	for (int i = 0; i < n; i++) {
		point += b.at(i);
	}

	for (int i = 0; i < n-1; i++) {
		if (a.at(i) + 1 == a.at(i + 1)) {
			point += c.at(a.at(i)-1);
		}
	}

	cout << point << endl;
}

Measured memory_bytes: 256
#!/usr/bin/perl
my ($a,$b) = map { $_ - 0 } split(/\s+/,<STDIN>);

my $x1 = $a + $b;
my $x2 = $a - $b;
my $x3 = $a * $b;

$x1 = $x2 if( $x1 < $x2 );
$x1 = $x3 if( $x1 < $x3 );
print "$x1\n";




Measured memory_bytes: 512
#include<bits/stdc++.h> 
using namespace std;
typedef long long ll;
template<typename T1,typename T2> bool chmin(T1 &a,T2 b){if(a<=b)return 0; a=b; return 1;}
template<typename T1,typename T2> bool chmax(T1 &a,T2 b){if(a>=b)return 0; a=b; return 1;}
int dx[4]={0,1,-1,0};
int dy[4]={1,0,0,-1};
long double eps = 1e-6;
long double pi = acos(-1);

ll mod = 998244353;
template<typename T> void add(T &a,T b){a=(a+b)%mod;}
template<typename T> void sub(T &a,T b){a=(a+mod-b)%mod;}

ll dp[333][333][333];

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

    string s;
    int k;
    cin>>s>>k;
    int n = s.size();
    int sum[n+1]={};
    int z = 0;
    int o = 0;
    for(int i=0;i<n;i++){
        if(s[i] == '0'){
            z++;
            sum[z+1] = sum[z];
        }
        else o++;
        sum[z+1] = o;
    }
    
    dp[0][0][0] = 1;
    for(int i=0;i<z;i++){
        for(int y=0;y<=min(k,o);y++){
            for(int j=sum[i];j<=min(o,sum[i]+k);j++){
                if(dp[i][j][y] == 0)continue;
                if(j-sum[i] > y)break;
                for(int p=max(j,sum[i+1]);p<=min(sum[i+1]+k,o);p++){
                    ll ret = dp[i][j][y];
                    int cnt = y;
                    int dif = p - j;
                    dif -= sum[i+1] - sum[i];
                    dif = max(0,dif);
                    cnt += dif;
                    if(cnt <= k){
                        add(dp[i+1][p][cnt],ret);
                    }
                    else break;
                }
            }
        }
    }
    ll ans = 0;
    for(int i=sum[z];i<=o;i++){
        for(int y=0;y<=min(o,k);y++){
            add(ans,dp[z][i][y]);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 33720
#include<stdio.h>

int main()
{
	int a, b, c, d;
	scanf("%d%d%d%d",&a,&b,&c,&d);
	if (a - c <= 0)
	{
		if (b <= c) printf("0");
		else if (b > c&&b < d) printf("%d", b - c);
		else printf("%d", d - c);
	}
	else 
	{
		if (a >= d) printf("0");
		else {
			if (b <= d)printf("%d", b - a);
			else  printf("%d", d - a);
		}
	}
		 return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
#include <stdlib.h>
#define N 100000
#define Q 1000

typedef struct{
  char name[10];
  int time;
} Data;

int main(){
  int n, t, i, count = 0, head = 0, tail;
  Data data[N];

  scanf("%d%d", &n, &t);
  tail = n;

  for(i = 0; i < n; i++){
    scanf("%s%d", data[i].name, &data[i].time);
  } 

  while(head != tail){
    if(data[head].time > t){
      data[head].time -= t;
      data[tail] = data[head];
      tail++;
      count += t;
    }
    else{
      count += data[head].time;
      printf("%s %d\n", data[head].name, count);
    }
    head++;
    if(head >= N) head = 0;
    if(tail >= N) tail = 0;
  }

  return 0;
}

Measured memory_bytes: 2160
/*------------------------------------
........Bismillahir Rahmanir Rahim....
..........created by Abdul Aziz.......
------------------------------------*/
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <cmath>
#include <vector>
#include <set>
#include <list>
#include <stack>
#include <map>
#include <cstring>
#include <unordered_map>
#include <queue>
#define   mod  998244353
#define   int  long long 
#define   ld   long double
#define   pb   push_back
#define   vi   vector<int> 
#define   co(x)  cout << x  
#define   dbg(x)  cerr << #x << " = " << x << '\n'
#define   sz(x)  (int)x.size()
#define   all(a) (a.begin(),a.end())
#define   ff   first
#define   ss   second
#define   pii  pair<int,int> 
#define   lcm(a,b) (a*b)/__gcd(a,b) 
using namespace std;


int n=55555;
bool  p[55559];

void  seive(){
    p[0]=p[1]=true;
    for (int i=4;i<=n;i+=2) p[i]=true;
    for (int i=3;i*i <= n;i += 2){
        if (p[i] == false)
        for (int j=i*i;j<=n;j+= i*2)
                p[j] = true;
    }
}


inline void solve(){
    seive();
    int n,s=28; cin>>n; 
    for (int i=10;i<=55555 and n>0;i++){
        if (p[i] == false and i%5==4){
            cout << i << " ";
            n--;
        }
    }
    cout << endl;
}

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


Measured memory_bytes: 3580
#include <bits/stdc++.h>
using namespace std;
struct Fast {Fast() {std::cin.tie(0); ios::sync_with_stdio(false);}} fast;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define mp make_pair
#define MOD 1000000007

vector<pii> graph[100005]; //graph[i]の要素<j,w>は、iとjが隣接し距離wであることを表す
vi color(100005);
int B = 1, W = 0, yet = -1;

void dfs(int n, int s) {
    color[n] = s;
    for (auto val : graph[n]) {
        int m = val.first;
        int d = val.second;
        if (color[m] == (1 & (color[n] + d))) {
            continue;
        }
        else if (color[m] == -1) {
            dfs(m, (1 & (color[n] + d)));
        }
    }
}


int main() {
    int N;
    cin >> N;
    rep(i, N - 1) {
        int u, v, w;
        cin >> u >> v >> w;
        graph[u - 1].pb(mp(v - 1, (1 & w)));
        graph[v - 1].pb(mp(u - 1, (1 & w)));
    }
    color.assign(N, -1);

    rep(i, N) {
        if (color[i] != -1) {
            continue;
        }
        dfs(i, 0);
    }
    rep(i, N) cout << color[i] << endl;

}



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

constexpr double const_pi() { return std::atan(1)*4; }

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int R;
    cin >> R;
    cout << 2 * R * const_pi() << endl;
    return 0;
}

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

using ll = long long;
using ull = unsigned long long;

#define MOD 1000000007

int main(void) {
    ll X, C;
    cin >> X;
    C = X / 100;
    cout << (C * 100 <= X && X <= C * 105) << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;
public class Main{
	public static void main(String[]args) {
		Scanner sc=new Scanner(System.in);
	    String str=sc.next();
	    String ss="";
	    for(int i=0;i<str.length();i++) {
	    	ss=ss+"x";
	    }
		System.out.println(ss);
	}
	
}

Measured memory_bytes: 21588
# import math
a, b= map(int,input().split())
def lcm(x, y):
    return (x * y) // gcd(x, y)

def gcd(a,b):
  while b!=0:
    a,b=b,a%b
  return a
 # print(gcd(a,b))

print(lcm(a,b))


Measured memory_bytes: 38748
#include<bits/stdc++.h>//头文件
using namespace std;
string a,b="CODEFESTIVAL2016";
int c=16;//全错
int main(){
    cin>>a;
    for(int i=0;i<16;i++)//循环16次，逐个判断
    c-=(a[i]==b[i])?1:0;//问号运算符
    cout<<c<<endl;//输出答案
    return 0;//完美结束
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl; 
#define INF 1000000000
#define mod 1000000007
typedef long long ll;
const ll LINF = 1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
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 (b<a) { a=b; return 1; } return 0; }

//O(NKlogN)が通らないの険しすぎる
//スライド最小値
//配列vの幅kごとの最小値を返す。返す配列のサイズはv.size()-k+1になる
//pop_back,push_back,pop_frontそれぞれN回しかないからO(N)
template<typename T>
vector<T> slide_min(const vector<T> &v,int k){
    //idxとvalueが昇順になるようにdequeに入れる
    deque<int> dq;
    vector<T> ret;
    for(int i=0;i<v.size();i++){
        //不等号: <=ならslide max  >=ならslide minになる
        while(!dq.empty()&&v[dq.back()]<=v[i]){
            dq.pop_back();
        }
        dq.push_back(i);
        if(i-k+1>=0){
            ret.push_back(v[dq.front()]);
            if(dq.front()==i-k+1) dq.pop_front();
        }
    }
    return ret;
}
/////


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

    vector<ll> dp(n,0);
    //一つ目
    rep(i,n) dp[i]=a[i];
    for(int times=2;times<=k;times++){
        vector<ll> dpp(n,0);

        //slide max
        //前半の範囲がm個ないところは0補充しておけばok
        reverse(ALL(dp));
        for(int mugen=0;mugen<m-1;mugen++) dp.push_back(0ll);
        reverse(ALL(dp));
        auto sm=slide_min(dp,m);
        for(int j=times-1;j<n;j++){
            dpp[j]=sm[j-1]+times*a[j];
        }


        swap(dp,dpp);
    }
    ll ans=0;
    rep(i,dp.size()) ans=max(ans,dp[i]);
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 5508
#include <iostream>
#include <map>
#include <queue>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
using namespace std;
#pragma warning (disable: 4996)

int N, cnt[26];

int main() {
	cin >> N;
	for (int i = 0; i < 26; i++) cnt[i] = (1 << 30);
	for (int i = 1; i <= N; i++) {
		string S;
		cin >> S;
		for (int j = 0; j < 26; j++) {
			int cnts = 0;
			for (int k = 0; k < S.size(); k++) { if ((S[k] - 'a') == j) cnts++; }
			cnt[j] = min(cnt[j], cnts);
		}
	}

	for (int i = 0; i < 26; i++) {
		for (int j = 0; j < cnt[i]; j++) cout << (char)('a' + i);
	}
	cout << endl;
	return 0;
}

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

using namespace std; 
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>; 

#define INF (INT_MAX)/2-1
#define MOD 1000000007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()

int main(){
  int H,W;
  cin>>H>>W;
  vector<string>a(H);
  for(int i=0;i<H;i++)cin>>a[i];
  vector<vector<int>>dp(H,vector<int>(W,0));
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      if(a[i][j]=='#')dp[i][j]=0;
      else if(i==0&&j==0)dp[i][j]=1;
      else{
        if(j-1>=0)dp[i][j]+=dp[i][j-1]%MOD;
        if(i-1>=0)dp[i][j]+=dp[i-1][j]%MOD;
      }
    }
  }
  cout<<dp[H-1][W-1]%MOD<<endl;
  return 0;
}


Measured memory_bytes: 5248
import numpy as np

n,m,x = map(int,input().split())
arr = np.array([list(map(int,input().split())) for i in range(n)])
c = arr.T[0] # c[n-1]まで
a = arr.T[1:].T # a[n-1][m-1]まで

ans = np.inf
for i in range(2**n):
    ability = np.zeros(m, np.int64)
    cost = 0
    # 二進数の右から0番目〜n-1番目をみていき、使用or不使用を判断
    for j in range(n):
    # 使用する場合にability/costを更新
        if (i>>j)&1: ability += a[j] ; cost += c[j]
    # 条件クリアしている場合にansを更新
    if np.all(ability>=x): ans = min(ans,cost)

# ansが無限なら、未更新＝条件クリアしてないので-1を出力
ans = -1 if ans==np.inf else ans
print(ans)


Measured memory_bytes: 27328
import sys
from collections import deque


N, M = map(int, input().split())
edge = [set() for _ in range(N)]
for _ in range(M):
    a, b = map(int, sys.stdin.readline().split())
    a -= 1; b -= 1
    edge[a].add(b)
    edge[b].add(a)

INF = 10 ** 8
path = [INF] * N
prev = [0] * N

q = deque()
path[0] = 0
q.append((0, 0))

while q:
    v, s = q.popleft()
    ns = s + 1
    for nv in edge[v]:
        if path[nv] > ns:
            path[nv] = ns
            prev[nv] = v
            q.append((nv, ns))

print('Yes')
for i in range(N - 1):
    print(prev[i + 1] + 1)


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


int main(){
int rab[200000];
int N;
cin>>N;
rab[0]= 0;
for(int i = 1;i<=N;i++)cin>>rab[i];
int cnt=0;
for(int i = 1;i<=N;i++){
if(i == rab[i] || rab[rab[i]]==i)cnt++;
}
cnt/=2;
cout<<cnt<<endl;
}

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

using namespace std;

typedef unsigned int ui;
typedef long long ll;
typedef unsigned long long ull;

constexpr int MAXM = 100000;

pair<int, int> intervals[MAXM + 2];

int main() {
	int N, M;
	cin >> N >> M;
	for(int i = 0; i < M; i++)
		cin >> intervals[i].second >> intervals[i].first;
	sort(intervals, intervals + M);
	int ans = 0;
	for(int i = 0, j = -1; i < M; i++) {
		if(!(intervals[i].second <= j && j < intervals[i].first)) {
			j = intervals[i].first - 1;
			ans++;
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 1024
#include<iostream>
using namespace std;
char a[102][102];
int main()
{
    int i=1,j,n,m,x,y,t1,t2,ans=0;
    cin>>n>>m;
    while(i<=n)
    {
        j=1;
        while(j<=m)
        {
            cin>>a[i][j];
            j=j+1;
        }
        i=i+1;
    }
    i=1;
    while(i<=n)
    {
        j=1;
        while(j<=m)
        {
            x=i-1;
            y=j-1;
            t1=x;
            t2=y;
            ans=0;
            if (a[i][j]=='.')
            {
                while(x<=t1+2)
                {
                    y=t2;
                    while(y<=t2+2)
                    {
                        if (a[x][y]=='#')  ans=ans+1;
                        y=y+1;
                    }
                    x=x+1;
                }
                cout<<ans;
            }
            if (a[i][j]=='#') cout<<"#";
            j=j+1;
        }
        cout<<endl;
        i=i+1;
    }
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] d1 = new int[n];
		int[] d2 = new int[n];
		for(int i = 0; i < n; i++){
			d1[i] = sc.nextInt();
			d2[i] = sc.nextInt();
		}
		
		int count = 0,max = 0;
		for(int i = 0; i < n; i++){
			if(d1[i] == d2[i]){
				count++;
				max = Math.max(max, count);
			}else{
				count = 0;
			}
		}
		
		if(max >= 3) System.out.println("Yes");
		else System.out.println("No");
	}
}

Measured memory_bytes: 35956
import java.util.Scanner;

public class Main {
  
    public static void main(String[] args) {
      
      Scanner sc = new Scanner(System.in);
      int N = sc.nextInt();
      int M = sc.nextInt();
      int[][] list = new int[N][2];//list[問題番号][0] == AC用//list[問題番号][1] == WA用
      int AC =0;//最終的なAC数を収める変数
      int WA =0;//最終的なWA数を収める変数
      for(int i = 0; i < M; i++){
        int num = sc.nextInt();
        String s = sc.next();
        if(s.equals("AC") && list[num-1][0]!=1){
          list[num-1][0] = 1;
          AC++;
          WA += list[num-1][1];//対象の問題の最終的なWAの数をWAに格納
        }else if(s.equals("WA") && list[num-1][0]!=1){
          list[num-1][1]++;
        }
      }      
      System.out.println(AC+" "+WA);
    }
}

Measured memory_bytes: 63120
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int beki[100000];
ll ky,ans;
int main(void){
	for(int i=0;i<300;i++){
		beki[i*i]=1;
	}
	int n,d; cin>>n>>d;
	int x[15][15];
	for(int i=0;i<n;i++){
		for(int j=0;j<d;j++){
			cin>>x[i][j];
		}
	}
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			for(int k=0;k<d;k++){
				ky=ky+(x[i][k]-x[j][k])*(x[i][k]-x[j][k]);
			}
			//cout<<ky<<endl;
			if(ky!=0&&beki[ky]==1){
				ans++;
			}
			ky=0;
		}
	}
	cout<<ans/2<<endl;
	
}


Measured memory_bytes: 640
#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;
int main(){
	int n;
	string s;
	int r = 0, b = 0;
	cin >> n >> s;
	for (int i = 0; i < n; i++) {
		if (s[i] == 'R') {
			r++;
		}
		else {
			b++;
		}
	}
	if (r > b) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>

int m,n;
int b[500],r[500],p[500];
bool v[500],c[500][500];

int gcd(int m,int n){
  if(m==n)
    return m;
  else if(m>n)
    return gcd(n,m);
  else
    return gcd (m,n-m);
}

bool match(int blue){
  if(blue<0) return true;
  for(int red=0; red<n; red++){
    if(!c[blue][red] || v[red]) continue;
    v[red] = true;
    if(match(p[red])){
      p[red] = blue;
      return true;
    }
  }
  return false;
}

int main(){
  while(scanf("%d %d",&m,&n),n){
    for(int i=0; i<m; i++)
      scanf("%d",&b[i]);
    for(int i=0; i<n; i++)
      scanf("%d",&r[i]);

    for(int i=0; i<n; i++) p[i]=-1;
    for(int i=0; i<m; i++) 
      for(int j=0; j<n; j++) 
	c[i][j] = (gcd(b[i],r[j])>=2);

    int cnt=0;
    for(int i=0; i<m; i++){
      for(int j=0; j<n; j++) v[j]=false;
      if(match(i)) ++cnt;
    }

    printf("%d\n",cnt);    
  }
}

Measured memory_bytes: 1012
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);

		int a = sc.nextInt();
		int b = sc.nextInt();
		int ans = 6 - a - b;
		System.out.println(ans);





	}
}


class Pair implements Comparable{
	int from;
	int end;
	@Override
	public int compareTo(Object other) {
		Pair otherpair = (Pair)other;

		return end - otherpair.end;
	}
}


Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
int T;
long long sum,a,b,Min=1e9,flag;
int main(){
	scanf("%d",&T);
	while(T--){
		scanf("%lld%lld",&a,&b);
		sum+=b;
		if(b<a&&Min>b)Min=b;
		if(b!=a)flag=1;
	}
	if(flag==1)printf("%lld",sum-Min);
	else puts("0");
}


Measured memory_bytes: 3820
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <utility>

using namespace std;

int suf[3][3] = { 2, 1, 1, 1, 2, 1, 1, 1, 2 };

int main() {
	int a, b, c, n, res[1000][4], type[301];

	while (cin >> a >> b >> c && a != 0) {
		cin >> n;
		fill(type, type + a + b + c + 1, 2);
		for (int i = 0; i < n; ++i) {
			for (int j = 0; j < 4; ++j) {
				cin >> res[i][j];
			}
		}

		while (1) {
			bool update = false;
			for (int i = 0; i < n; ++i) {
				if (res[i][3] == 1) {
					for (int j = 0; j < 3; ++j) {
						if (type[res[i][j]] == 2) {
							type[res[i][j]] = 1;
							update = true;
						}
					}
				}
				else {
					for (int j = 0; j < 3; ++j) {
						for (int k = 0; k < 3; ++k) {
							if (type[res[i][k]] != suf[j][k])
								break;
							if (k == 2) {
								type[res[i][j]] = 0;
								update = true;
							}
						}
					}
				}
			}
			if (update == false)
				break;
		}
		for (int i = 1; i <= a + b + c; ++i) {
			cout << type[i] << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 3068
#include <bits/stdc++.h>
#define REP(i, n) for (int (i) = 0; (i) < (int)(n); i++) 
#define FOR(i, a, b) for(int (i) = a; (i) < (int)b; i++)
#define RREP(i, n) for(int (i)=((int)(n)-1); (i)>=0; i--)
#define RFOR(i, a, b) for(int (i) =((int)(b)-1); (i)>=(int)a; i--)
#define ALL(v) (v).begin(),(v).end()
#define MOD 1000000007
#define F first
#define S second

using namespace std ;
typedef long long ll;
typedef vector<int> vint;
typedef vector<vint> vvint;
typedef pair<int, int> pint;

int main()
{
  string s, t, u ;
  cin >> s >> t ;
  u = s + t ;
  int n ;
  n = stoi(u) ;
  
  int i = 0 ;
  while(true){
    if(n == i*i){
      cout << "Yes"<<endl ;
      break ;
    }
    else{
      i++ ;
    }
    
    if(i==n+1){
      cout << "No"<<endl ;
      break ;
    }
  }
  

  return 0 ;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
using namespace std;
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const int MOD2 = 998244353;


int main(){
    string s, t;
    cin >> s >> t;
    int n = s.size();
    int m = t.size();
    int ans = 1010;
    rep(i, n-m+1){
        int tmp = 0;
        rep(j, m){
            if (t[j] != s[i+j]) tmp++;
        }
        ans = min(ans, tmp);
    }
    cout << ans << endl;
    return 0;
}


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

using namespace std;

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    for(int i=0; i<5; i++){
        int k;
        cin >> k;
        if(k==0){
            cout << i+1;
        }
    }
    return 0;
}

Measured memory_bytes: 3576
import itertools
N, M = map(int, input().split())
k = [list(map(int, input().split()))[1:] for _ in range(M)]
p = list(map(int, input().split()))
print(sum([all([sum([s[j-1] for j in v])%2==t  for v,t in zip(k, p)]) for s in itertools.product([0,1],repeat=N)]))

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#define rep(i, n)   for(int i = 0; i < (n); i++)
using namespace std;

int main(){
    int n;  cin >> n;
    string s;   cin >> s;
    if(n%2){
        cout << "No" << endl;
    }else{
        int l = 0, r = n/2;;
        bool flag = true;
        rep(i, n/2){
            if(s[l] != s[r])    flag = false;
            l++;    r++;
        }
        if(flag){
            cout << "Yes" << endl;
        }else{
            cout << "No" << endl;
        }
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <iostream>
#include <queue>
#include <unordered_map>
#include <cmath>
#include <queue>
#include <string>
#include <random>
#include <stack>
using namespace std;
typedef long long ll;
const int maxn = 105;

int main() {
#ifdef suiyuan2009
  freopen("/Users/suiyuan2009/CLionProjects/icpc/input.txt", "r", stdin);
  //freopen("/Users/suiyuan2009/CLionProjects/icpc/output.txt", "w", stdout);
#endif
  int n;
  cin>>n;
  vector<pair<int,int>> a;
  if(n&1)a.push_back(make_pair(n,n));
  int l = 1, r = n/2*2;
  while(l<r){
    a.push_back(make_pair(l,r));
    l++;
    r--;
  }
  reverse(a.begin(),a.end());
  vector<pair<int,int>> ret;
  for(int i=0;i+1<a.size();i++){
    ret.push_back(make_pair(a[i].first, a[i+1].first));
    ret.push_back(make_pair(a[i].second, a[i+1].first));
    if(a[i+1].first!=a[i+1].second){
      ret.push_back(make_pair(a[i].first, a[i+1].second));
      ret.push_back(make_pair(a[i].second, a[i+1].second));
    }
  }
  if(a.size()>2){
    int m = a.size();
    ret.push_back(make_pair(a[m-1].first, a[0].first));
    ret.push_back(make_pair(a[m-1].first, a[0].second));
    if(a[m-1].first!=a[m-1].second){
      ret.push_back(make_pair(a[m-1].second, a[0].first));
      ret.push_back(make_pair(a[m-1].second, a[0].second));
    }
  }
  cout<<ret.size()<<endl;
  for(int i=0;i<ret.size();i++){
    cout<<ret[i].first<<" "<<ret[i].second<<endl;
  }
  return 0;
}

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

using int32 = int_fast32_t;
using int64 = int_fast64_t;

const int32 INF = 1e9;
const int32 MOD = 1e9+7;
const int64 LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define ANS(n) cout << (n) << "\n"
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define ALL(obj) (obj).begin(),(obj).end()
#define pii pair<int32,int32>
#define pll pair<int64,int64>
#define pb(a) push_back(a)
#define mp make_pair

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int32 n,k,r,s,p;
    cin >> n >> k >> r >> s >> p;
    map<char,int32> score;
    score['r'] = p;
    score['s'] = r;
    score['p'] = s;
    string t;
    cin >> t;
    int64 ans = 0;
    REP(i,n){
        if(i - k < 0){
            ans += score[t[i]];
        }else{
            if(t[i] != t[i-k]){
                ans += score[t[i]];
            }else{
                t[i] = 'x';
            }
        }
    }
    ANS(ans);
    return 0;
}

Measured memory_bytes: 512
N,K=map(int,input().split())
p=list(map(int,input().split()))
ans=sum(p[0:K])
all_sum=[sum(p[0:K])]
for i in range(len(p)-K):
    ans=ans+p[i+K]-p[i]
    all_sum.append(ans)
ans=max(all_sum)
print((ans+K)/2)

Measured memory_bytes: 24816