akhauriyash/Code-Regression huggingface dataset:
#include <math.h>
#include <time.h>
#include <ctype.h>
#include <stdio.h>
#include <assert.h>
#include <stdlib.h>
#include <string.h>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
#include<iomanip>

#define mod 998244353
#define ll long long int
#define pb(x) push_back(x)
#define MP(x,y) make_pair(x,y)

using namespace std;

ll power(ll a, ll b, ll m)
{
	if (b == 0)
		return(1);
	ll sol = power(a, b / 2, m);
	sol = (sol * sol) % m;
	if (b % 2 == 1)
		sol = (sol * a) % m;
	return(sol);
}
ll gcd(ll a, ll b)
{
	if (b == 0)
		return a;
	else
	{
		return gcd(b, a % b);
	}
}
string s;
int fl[200007], fr[200007],sol[200007];
void solve()
{
	cin >> s;
	int n = s.length();
	fl[n - 1] = n - 1;
	for (int i = n - 2; i >= 0; i--)
	{
		if (s[i] == 'L')
			fl[i] = i;
		else
			fl[i] = fl[i + 1];
	}
	fr[0] = 0;
	for (int i = 1; i < n; i++)
	{
		if (s[i] == 'R')
		{
			fr[i] = i;
		}
		else
			fr[i] = fr[i - 1];
	}
	for (int i = 0; i < n; i++)
	{
		if (s[i] == 'R')
		{
			if ((fl[i] - i) % 2 == 0)
				sol[fl[i]]++;
			else
				sol[fl[i]-1]++;
		}
		else
		{
			if ((i-fr[i]) % 2 == 0)
				sol[fr[i]]++;
			else
				sol[fr[i]+1]++;
		}
	}
	for (int i = 0; i < n; i++)
		cout << sol[i] << " ";
}
int main()
{
	int t = 1;
	//cin >> t;
	while (t--)
		solve();
	return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#define rep(i,n) for(int i=0;i<n;i++)
#define ll long long int
#define MAX 1000000007
using namespace std;


int main(void){
	string s;
	cin>>s;
	ll work[s.length()+1][13],ans=0;
	rep(i,s.length()+1){
		rep(j,13){
			work[i][j]=0;
		}
	}
	work[0][0]=1;
	/*
	rep(j,13)cout<<work[0][j]<<" ";
	cout<<endl;*/

	ll dcur=1;
	for(int i=0;i<s.length();i++){
		int tmp;
		if(s[i]=='?')tmp=-1;
		else tmp = s[i]-'0';
		//cout<<"check:"<<tmp<<endl;
		rep(j,10){
			if(tmp !=  -1 && tmp != j)continue;
			rep(k,13){
				work[i+1][(k*10+j)%13]+=work[i][k];
				work[i+1][(k*10+j)%13]%=MAX;
			}
		}
		/*rep(j,13)cout<<work[i+1][j]<<" ";
		cout<<endl;*/
	}

	cout<<work[s.length()][5]<<endl;
	return 0;
}


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

int main()
{
ll n , x ;
cin >> n >> x ;
if(x==1||x==2*n-1){
  cout << "No" << endl;
}
else if(n==2){
  cout << "Yes" << endl;
  cout << 1 << endl;
  cout << 2 << endl;
  cout << 3 << endl;
}
else{
  cout << "Yes" << endl;
  vector<ll> ans(2*n-1);
  set<ll> s;
  if(x==2){
    ans[n-2]=x+2;s.insert(x+2);
    ans[n-1]=x;s.insert(x);
    ans[n]=x-1;s.insert(x-1);
    ans[n+1]=x+1;s.insert(x+1);
  }
  else{
    ans[n-2]=x-2;s.insert(x-2);
    ans[n-1]=x;s.insert(x);
    ans[n]=x+1;s.insert(x+1);
    ans[n+1]=x-1;s.insert(x-1);
  }
  ll st=1;
  rep(i,2*n-1){
    if(ans[i]!=0)continue;
    while(s.find(st)!=s.end())st++;
    ans[i]=st;
    st++;
  }
  for(auto an:ans){
    cout << an << endl;
  }
}
return 0;
}

Measured memory_bytes: 3072
#include<iostream>
using namespace std;
int main()
{
	int H, R;
	cin >> H >> R;
	if (H < -1 * R)
		cout << -1 << endl;
	else if (H == -1 * R)
		cout << 0 << endl;
	else
		cout << 1 << endl;
	return 0;
}

Measured memory_bytes: 3104
#include <iostream>
#include <utility>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <math.h>
#include <stack>
#include <set>
#include <deque>
#include <cmath>

using namespace std;
typedef long long ll;
ll mod = 1e9+7;
//ll mod = 998244353;
#define rep(i,n) for(int i = 0; i < (n); ++i)

int main() {
    int n;
    string s;
    cin >> n >> s;
    int l = 0, r = 0;
    rep(i, n) {
        if (s[i] == '(') ++l;
        else if (l == 0) ++r;
        else             --l;
    }
    rep(i, r) s = '(' + s;
    rep(i, l) s += ')';
    cout << s << endl;
    return 0;
}


Measured memory_bytes: 3612
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
inf = 10**17
mod = 10**9+7

n = int(input())
s = input()

ans = 0
for i in range(n):
    if s[i] == 'A' and s[i+1] == 'B' and s[i+2] == 'C': ans += 1

print(ans)


Measured memory_bytes: 9056
#include <bits/stdc++.h>
using namespace std;
//typedef
typedef long long ll;
typedef vector<int> vi;
typedef vector<string> vs;
//define
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
////////////////////////////////////////////////////////////////////
using namespace std ;

int main(){
  string s;
  cin >> s;

  if(s[2] == s[3] && s[4] == s[5]){
  cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
n=int(input())
a=[i for i in list(map(int,input().split()))if i<3200]
k=n-len(a)
c=0
for j in range(8):
    b=[i for i in a if (j)*400<=i and i<(j+1)*400]
    if len(b)>0:
        c+=1
print(str(c if c>0 else 1)+" "+str(k+c))

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

int main(void)
{
	int i, j, x, num, same;
	int count[1000] = {0}, big, place;
	int l_count[1000] = {0}, l_place;
	char c;
	char words[1000][40], l_word[1000][40];
	
	j = 0;
	i = 0;
	num = 0;
	
	while (1){
		scanf("%c", &c);
		
		if (c == '\n'){
			break;
		}
		else if (c == ' '){
			if (num != 0){
				same = 0;
				for (x = 0; x < num; x++){
					if (strcmp(l_word[x], words[j]) == 0){
						l_count[x]++;
						same = 1;
						break;
					}
				}
				
				if (same != 1) {
					strcpy(l_word[num], words[j]);
					l_count[num]++;
					num++;
				}
				
			}
			else {
				strcpy(l_word[0], words[0]);
				l_count[num]++;
				num++;
			}
			
			i = 0;
			j++;
			
		}
		else {
			words[j][i] = c;
			i++;
			count[j]++;
		}
		
	}
	
	big = 0;
	place = 0;
	
	for (i = 0; count[i] != 0; i++){
		if (count[i] > big){
			big = count[i];
			place = i;
		}
	}
	
	big = 0;
	l_place = 0;
	
	for (i = 0; l_count[i] != 0; i++){
		if (l_count[i] > big){
			big = l_count[i];
			l_place = i;
		}
	}
	
	printf("%s %s\n", words[l_place], words[place]);
	
	return (0);
}

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

int		main(void)
{
	int		a;
	cin >> a;
	int		b;
	cin >> b;
	if (a % b == 0)
		cout << 0 << endl;
	else
		cout << 1 << endl;
}

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

using namespace std;

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

	vector<int> L(N);

	int max_value = 0;
	int sum = 0;
	for (int i = 0; i < N; i++)
	{
		cin >> L[i];

		if (max_value < L[i])
		{
			max_value = L[i];
		}

		sum += L[i];
	}

	if (max_value < sum - max_value)
	{
		cout << "Yes" << endl;
	}
	else
	{
		cout << "No" << endl;
	}

	return 0;
}


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

int N;
int A[210];      

int main() {
    cin >> N;
    for (int i = 0; i < N; ++i) cin >> A[i];
    int res = 0;
    while (true) {
    	for(int i = 0; i < N; ++i){
    		if(A[i] % 2 != 0) goto END;
    		else A[i] /= 2;
    	}
    	res += 1;
    }

    END : cout << res << endl;


}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const double eps = 1e-8;

#ifdef DEBUG
#include "inc/debug.hpp"
#else
#define debug(...) 42
#endif

int main() {
    int N, R;
    cin >> N >> R;
    if (10 <= N) {
        cout << R << endl;
    } else {
        cout << R + 100 * (10 - N) << endl;
    }
    return 0;
}

Measured memory_bytes: 256
// </> : towhid1zaman

#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair< int, int > pii;
typedef vector<pii>vip;
typedef pair< pii, int > ppi;
#define fill(a,b) memset(a,b,sizeof(a))
#define all(v) (v).begin(),(v).end()
#define sp(k) cout<<setprecision(k)<<fixed;
#define rep(i,a) for(int i=0;i<a;i++)
#define rep1(i,a,b) for(int i=(a);i<=(b);++i)
#define irep(i,b,a) for(int i=(b);i>=(a);--i)
#define minv(v) *min_element(all(v))
#define maxv(v) *max_element(all(v))
#define unq(v) sort(all(v)),(v).erase(unique(all(v)),(v).end())
#define _ ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl "\n"
#define sqr(a) ((a)*(a))
#define sz(a) int(a.size())
#define ff first
#define ss second
#define pb push_back

const double pi = acos(-1.0);
const int mod = 1000000007; // (int)1e9+7
const int inf = 0x3f3f3f3f;// (int)3e18;
const int maxn = 2000100;



int main(){
        _
        ll n;cin >> n;
        vll a(n);
        unordered_map<ll,ll> map;
        ll sum = 0;
        rep(i,n){
            cin >> a[i];
            sum += a[i];
            map[a[i]]++;
        }

        ll q;cin >> q;
        while(q--){
            ll b,c;
            cin >> b >> c;
            ll tm = map[b];
            map[b] = 0;
            map[c] += tm;
            sum -= b * tm;
            sum += c * tm;
            cout << sum << endl;
        }

return 0;
}




Measured memory_bytes: 7904
#include <algorithm>
#include <iostream>

template<class T> inline void chmax(T & a, T b) {
	if (a < b) a = b;
}

template<class T> inline void chmin(T & a, T b) {
	if (a > b) a = b;
}

using namespace std;

const long long INF = 1LL << 60;

int main() {
	long long h[100010];
	long long dp[100010];

	int n; cin >> n;
	for (int i = 0; i < n; i++) scanf("%d", &h[i]);
	for (int i = 0; i < 100010; i++) dp[i] = INF;

	dp[0] = 0;
	for (int i = 0; i < n; i++) {
		chmin(dp[i + 1], dp[i] + abs(h[i] - h[i + 1]));
		chmin(dp[i + 2], dp[i] + abs(h[i] - h[i + 2]));
	}

	cout << dp[n - 1] << endl;

	return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <string>

using namespace std;

typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;

int main(int argc, char ** argv) {
	ll n, m, q;
	cin >> n >> m >> q;
	vvi s(n, vi(m,0));
	for(ll i=0; i<n; i++) {
		string tmp;
		cin >> tmp;
		for(ll k=0; k<tmp.length(); k++) {
			if(tmp[k] == '0') s[i][k] = 0;
			if(tmp[k] == '1') s[i][k] = 1;
		}
	}
	vvi v(n, vi(m,0));
	for(ll i=0; i<n; i++) {
		for(ll j=0; j<m; j++) {
			ll A=0, B=0, C=0;
			if(i > 0) A = v[i-1][j];
			if(j > 0) B = v[i][j-1];
			if(i > 0 && j > 0) C = v[i-1][j-1];
			v[i][j] = s[i][j] + A + B - C;
		}
	}
	vvi ev(n, vi(m,0)), eh(n, vi(m,0));
	for(ll i=0; i<n; i++) {
		for(ll j=0; j<m; j++) {
			ll A=0, B=0, C=0, D=0;
			if(i > 0) D = s[i][j]&s[i-1][j];
			if(i > 0) A = ev[i-1][j];
			if(j > 0) B = ev[i][j-1];
			if(i > 0 && j > 0) C = ev[i-1][j-1];
			ev[i][j] = D + A + B - C;
		}
	}
	for(ll i=0; i<n; i++) {
		for(ll j=0; j<m; j++) {
			ll A=0, B=0, C=0, D=0;
			if(j > 0) D = s[i][j]&s[i][j-1];
			if(i > 0) A = eh[i-1][j];
			if(j > 0) B = eh[i][j-1];
			if(i > 0 && j > 0) C = eh[i-1][j-1];
			eh[i][j] = D + A + B - C;
		}
	}
	/*
	cout << "v" << endl;
	for(ll i=0; i<n; i++) {
		for(ll j=0; j<m; j++) {
			cout << v[i][j] << " ";
		}
		cout << endl;
	}
	cout << "ev" << endl;
	for(ll i=0; i<n; i++) {
		for(ll j=0; j<m; j++) {
			cout << ev[i][j] << " ";
		}
		cout << endl;
	}
	cout << "eh" << endl;
	for(ll i=0; i<n; i++) {
		for(ll j=0; j<m; j++) {
			cout << eh[i][j] << " ";
		}
		cout << endl;
	}
	*/
	for(ll i=0; i<q; i++) {
		ll x1, x2, y1, y2;
		cin >> x1 >> y1 >> x2 >> y2;
		x1 --; x2 --;
		y1 --; y2 --;
		ll A_v = v[x2][y2];
		ll A_ev = ev[x2][y2];
		ll A_eh = eh[x2][y2];
		ll B_v = 0, C_v = 0, D_v = 0;
		ll B_ev = 0, C_ev = 0, D_ev = 0;
		ll B_eh = 0, C_eh = 0, D_eh = 0;
		if(x1 > 0 && y1 > 0) {
			B_v = v[x1-1][y1-1];
		}
		if(x1 > 0) {
			B_eh = eh[x1-1][y1];
			C_v = v[x1-1][y2];
			C_eh = eh[x1-1][y2];
		}
		if(y1 > 0) {
			B_ev = ev[x1][y1-1];
			D_v = v[x2][y1-1];
			D_ev = ev[x2][y1-1];
		}
		C_ev = ev[x1][y2];
		D_eh = eh[x2][y1];
		ll num_v = A_v + B_v - C_v - D_v;
		ll num_ev = A_ev + B_ev - C_ev - D_ev;
		ll num_eh = A_eh + B_eh - C_eh - D_eh;
		// cout << "num_v : " << num_v << endl;
		// cout << "num_ev : " << num_ev << endl;
		// cout << "num_eh : " << num_eh << endl;
		ll ans = num_v - num_ev - num_eh;
		cout << ans << endl;
	}

	return 0;
}


Measured memory_bytes: 127104
macro_rules! get {
      ($t:ty) => {
          {
              let mut line: String = String::new();
              std::io::stdin().read_line(&mut line).unwrap();
              line.trim().parse::<$t>().unwrap()
          }
      };
      ($($t:ty),*) => {
          {
              let mut line: String = String::new();
              std::io::stdin().read_line(&mut line).unwrap();
              let mut iter = line.split_whitespace();
              (
                  $(iter.next().unwrap().parse::<$t>().unwrap(),)*
              )
          }
      };
      ($t:ty; $n:expr) => {
          (0..$n).map(|_|
              get!($t)
          ).collect::<Vec<_>>()
      };
      ($($t:ty),*; $n:expr) => {
          (0..$n).map(|_|
              get!($($t),*)
          ).collect::<Vec<_>>()
      };
      ($t:ty ;;) => {
          {
              let mut line: String = String::new();
              std::io::stdin().read_line(&mut line).unwrap();
              line.split_whitespace()
                  .map(|t| t.parse::<$t>().unwrap())
                  .collect::<Vec<_>>()
          }
      };
      ($t:ty ;; $n:expr) => {
          (0..$n).map(|_| get!($t ;;)).collect::<Vec<_>>()
      };
}

fn main() {
    // 入力
    let S = get!(String);

    let ans = (S.match_indices("+").count() as i64) - (S.match_indices("-").count() as i64);

    // 出力
    println!("{}", ans);
}

Measured memory_bytes: 4352
use std::io::Read;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();
    let split_one_line = buf.split("\n");
    let mut line_itme;

    for s in split_one_line {
        if s == "0 0"{
            break
        }
        // line_itme = s.split(" ").collect();
        line_itme = s.split_whitespace();
        let mut vec = [
            line_itme.next().unwrap().parse::<i32>().unwrap(),
            line_itme.next().unwrap().parse::<i32>().unwrap()
        ];
        vec.sort();
        println!("{} {}", vec[0], vec[1]);
    }
}



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

int main(){
  int n,m,p;
  int ans = 0,pen = 0;
  int temp;
  bool ck;
  cin >> n >> m;
  vector<queue<string>> sub(n+1);
  string s;
  for(int i=0;i<m;i++){
    cin >> p >> s;
    sub.at(p).push(s);
  }
  
  for(int i=1;i<=n;i++){
    temp = 0;
    ck = false;
    while(sub.at(i).size()){
      s = sub.at(i).front();
      sub.at(i).pop();
      if(s == "AC"){
        ck = true;
        ans++;
        break;
      }
      else temp++;
    }
    if(ck) pen += temp;
  }
  
  cout << ans << ' ' << pen << endl;
}


Measured memory_bytes: 72064
function Main(input) {
  input = input.split("\n");
  var n = input[0];
  n=n.replace(/9/g,2);
  n=n.replace(/1/g,9);
  n=n.replace(/2/g,1);
  console.log('%s', n);
}
  
// "実行する"ボタンを押した時に実行される関数 (デバッグ用)
function debug(){
  var input = document.getElementById("input").value;
  Main(input);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 22076
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll x;cin >> x;
	ll a=x%11;
	ll b=x/11*2;
	if(a>6) cout << b+2 << endl;
	else{
		if(a==0) cout << b << endl;
		else cout << b+1 << endl;
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll        long long
#define  sci(x)   scanf("%d", &x)
#define  scl(x)   scanf("%lld", &x)
#define  scd(x)   scanf("%lf", &x)
#define l0(i,n)   for(ll i=0; i<n; i++)

int main ()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	//CODE TONOY
	int N,K,X,Y;
	int sum=0;
	cin>>N>>K>>X>>Y;
	for (int i=1;i<=N;i++){
		if(i<=K)
		sum+=X;
		else
		sum+=Y;
	}
	
	cout<<sum<<endl;	
	return 0;
}

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

int main(){
	int N, i;
	scanf("%d", &N);
	char *S = (char *)malloc(sizeof(char) * N);
	for(i = 0; i < N; i++){
		scanf("%c ", &S[i]);
	}
	for(i = 0; i < N; i++){
		if(S[i] == 'Y'){
			printf("Four\n");
			return 0;
		}
	}
	printf("Three\n");
	return 0;
}

Measured memory_bytes: 128
#include "bits/stdc++.h"
using namespace std;

int main() {
	int H, W;
	cin >> H >> W;
	vector<string> S(H);
	for (int n = 0; n < H; ++n) {
		cin >> S[n];
	}
	int count = 0;
	for (int i = 0;i<H;++i) {
		for (int j = 0;j<W;++j) {
			if ('.' == S[i][j]) {
				count++;
			}
		}
	}

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

	int nAns = 0;
	vector<vector<int>> data(H, vector<int>(W, -1));
	data[0][0] = 1;
	queue<pair<int, int>> q;
	q.emplace(0, 0);
	while (!q.empty()) {
		int x = q.front().first;
		int y = q.front().second;
		q.pop();
		//範囲内かつ0を4セット
		for (int l = 0; l < 4; ++l) {
			int x1 = x + dx[l];
			int y1 = y + dy[l];
			if ((0 <= x1) && (H > x1) && (0 <= y1) && (W > y1) && (-1 == data[x1][y1]) && ('#' != S[x1][y1])) {
				data[x1][y1] = data[x][y] + 1;
				q.emplace(x1, y1);
			}
		}
	}
	if (-1 == data[H-1][W-1]) {
		cout << -1<<endl;
		return 0;
	}
	cout << count -data[H-1][W-1] << endl;

	return 0;
}

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

using namespace std;

long long pow_5(long long z) {
	return z * z * z * z * z;
}

int main() {
	long long x;
	cin >> x;
	for (long long i = 0; i < 121; i++) {
		for (long long j = i; j < 121; j++) {
			if (x == pow_5(i) + pow_5(j)) {
				cout << i <<  " " << -j << "\n";
				return 0;
			}
			if (x == pow_5(j) - pow_5(i)) {
				cout << j << " " << i << "\n";
				return 0;
			}
		}
	}
	return 0;
}


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

using namespace std;
#define loop(i,n) for(int i=0;i<n;i++)
typedef long long ll;
int n,h[100002],o,t,dp[100002];
int rec(int i)
{
    if(i==n-1) return 0;
    if(dp[i]!=-1)return dp[i];
o=t=1e9;
    if(i+1<=n-1)
    {
        o=rec(i+1)+abs(h[i]-h[i+1]);
    }
    if(i+2<=n-1)
    {
        t=rec(i+2)+abs(h[i]-h[i+2]);
    }
    return dp[i]=min(t,o);
}
int main()
{
    cin>>n;

    loop(i,n)
    {
        cin>>h[i];
        dp[i]=-1;
    }
    int ans=rec(0);
    cout<<ans;
}



Measured memory_bytes: 4096
import java.util.Scanner;

public class Main {

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

        while(true) {
            int n = scanner.nextInt();
            int r = scanner.nextInt();
            if (n == 0 && r == 0) break;
            int cards[] = new int[n];
            for (int i = 0; i < n; i++) {
                cards[i] = n - i;
            }
            for (int i = 0; i < r; i++) {
                int p = scanner.nextInt();
                int c = scanner.nextInt();
                int tmpcards[] = new int[n];
                for (int j = 0; j < n; j++) {
                    tmpcards[j] = cards[j];
                }
                for (int j = 0; j < p - 1; j++) {
                    tmpcards[c + j] = cards[j];
                }
                for (int j = 0; j < c; j++) {
                    tmpcards[j] = cards[p - 1 + j];
                }
                cards = tmpcards;
            }
            System.out.println(cards[0]);
        }
        scanner.close();
    }
}



Measured memory_bytes: 37248
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll,ll>;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
const ll INF = 1LL<<60;
const ll MOD = 1e9+7;

int popcount(int x){
    if(x==0)return 0;
    else return popcount(x/2)+x%2;
}
int f(int x){
    return x % popcount(x);
}
int g(int x){
    if(x==0)return 0;
    else return g(f(x))+1;
}



int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n; cin>>n;
    string x; cin>>x;
    vector<ll> ans(200001,0);
    rep2(i,1,200001)ans[i]=g(i);
    int cnt = 0;
    for(char c:x)if(c=='1')cnt++;
    //cnt-1, cnt, cnt+1についてあまりをだせばOK
    //cnt==0,1はコーナー？
    //cnt+-1だけでよかったかも
    vector<int> r(3,0);
    for(char c:x){
        rep(i,3){
            if(i!=2&&cnt==0)continue;
            if(i==0&&cnt==1)continue;
            r[i]*=2;
            if(c=='1')r[i]+=1;
            r[i]%=cnt+i-1;
        }
    }
    vector<vector<int>> rem(3,vector<int>(n));
    //1000...000をcnt-1, cnt, cnt+1で割ったあまり
    for(int i=n-1; i>=0; i--){
        rep(j,3){
            if(j!=2&&cnt==0)continue;
            if(j==0&&cnt==1)continue;
            if(i==n-1)rem[j][i]=1;
            else{
                rem[j][i]=(2*rem[j][i+1])%(cnt+j-1);
            }
        }
    }

    /*rep(i,3){
        for(int A:rem[i])cout<<A<<" ";
        cout<<endl;
    }*/
    rep(i,x.size()){
        int popc = cnt;
        if(x[i]=='1')popc--;
        else popc++;
        int Ans;
        //cout<<popc<<endl;
        if(popc==0)Ans=0;
        else{
            int idx = (x[i]=='0')*2-1;
            int rema = (r[idx+1]+idx*rem[idx+1][i]+popc)%popc;
            //cout<<r[idx+1]<<","<<rem[idx+1][i]<<","<<r[idx+1]+idx*rem[idx+1][i]+popc<<","<<popc<<endl;
            Ans=1+ans[rema];
            //cout<<"a"<<(r[idx+1]+idx*rem[idx+1][i]+popc)%popc<<endl;
        }
        cout<<Ans<<endl;

    }
    return 0;
}

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

#define PI 3.14159265359
#define INF 1e9
#define LINF 1e18
#define IMOD 1000000007 
#define irep(i,n) for(int i = 0; i < (int)(n); i++)
#define irep2(i,a,n) for(int i = (int)(a); i <= (int)(n); i++)
#define lrep(i,n) for(long long  i = 0; i < (long long)(n); i++)
#define lrep2(i,a,n) for(long long i = (long long)(a); i <= (long long)(n); i++)

#define irrep(i,n) for(int i = (int)(n); i > -1; i--)
#define irrep2(i,a,n) for(int i = (int)(n); i >= (int)(a); i--)


typedef long long ll;
typedef std::vector<char> v_char;
typedef std::vector<v_char > v2_char;
typedef std::vector<double> v_double;
typedef std::vector<v_double > v2_double;
typedef std::vector<int> v_int;
typedef std::vector<v_int > v2_int;
typedef std::vector<ll> v_ll;
typedef std::vector<v_ll > v2_ll;
typedef std::vector<std::string> v_string;
typedef std::vector<v_string > v2_string;
typedef std::vector<bool> v_bool;
typedef std::vector<v_bool > v2_bool;
typedef std::pair<ll, ll> pll;
typedef std::pair<int, int> pii;

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

using namespace std; 

int main(void)
{
    int a, b, c;
    cin >> a >> b >> c;
    
    if(a+b+c >= 22) {
        puts("bust");
    } else {
        puts("win");
    }
    return 0;
}   
/** atcoder **/


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

using namespace std;

#define int long long
#define FOR(i, a, b) for(ll i = (a); i < (b); ++i)
#define FORR(i, a, b) for(ll i = (a); i > (b); --i)
#define REP(i, n) for(ll i = 0; i < (n); ++i)
#define REPR(i, n) for(ll i = n; i >= 0; i--)
#define FOREACH(x, a) for(auto &(x) : (a))
#define VECCIN(x)                                                              \
    for(auto &youso_ : (x)) cin >> youso_
#define mp make_pair
#define bitcnt __builtin_popcount
#define SZ(x) ((ll)(x).size())
#define All(a) (a).begin(), (a).end()
template <typename T = long long> inline T IN() {
    T x;
    cin >> x;
    return (x);
}
inline void CIN() {}
template <class Head, class... Tail>
inline void CIN(Head &&head, Tail &&... tail) {
    cin >> head;
    CIN(move(tail)...);
}
#define CINT(...)                                                              \
    int __VA_ARGS__;                                                           \
    CIN(__VA_ARGS__)
#define LCIN(...)                                                              \
    ll __VA_ARGS__;                                                            \
    CIN(__VA_ARGS__)
#define SCIN(...)                                                              \
    string __VA_ARGS__;                                                        \
    CIN(__VA_ARGS__)
#define Yes(a) cout << (a ? "Yes" : "No") << "\n"
#define YES(a) cout << (a ? "YES" : "NO") << "\n"
#define Printv(v)                                                              \
    {                                                                          \
        FOREACH(x, v) { cout << x << " "; }                                    \
        cout << "\n";                                                          \
    }
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
    std::fill((T *)array, (T *)(array + N), val);
}

typedef long long ll;
typedef unsigned long long ul;
typedef vector<ll> VL;
typedef pair<ll, ll> PL;
typedef priority_queue<ll> PQ;
typedef priority_queue<ll, VL, greater<ll>> PQG;

const int INF = 1e9;
const int MOD = 1e9 + 7;
// const int MOD = 998244353;
const ll LINF = 1e18 + 1;
const ll dx[] = {1, -1, 0, 0};
const ll dy[] = {0, 0, 1, -1};

ll N;
VL l, r;

signed main() {
    cin >> N;
    REP(i, N) {
        l.emplace_back(IN());
        r.emplace_back(IN());
    }
    sort(All(l), greater<ll>());
    sort(All(r));
    ll ans = 0, tmp = 0;
    REP(i, N) {
        tmp += l[i];
        ans = max(tmp, ans);
        tmp -= r[i];
        ans = max(tmp, ans);
    }
    tmp = 0;
    REP(i, N) {
        tmp -= r[i];
        ans = max(tmp, ans);
        tmp += l[i];
        ans = max(tmp, ans);
    }
    cout << ans * 2 << "\n";
}


Measured memory_bytes: 2036
using System;

namespace ITP1_1_C
{
	class Program
	{
		static void Main(string[] args)
		{
			string[] inputString = System.Console.ReadLine().Split(' ');

			int tate = int.Parse(inputString[0]);
			int yoko = int.Parse(inputString[1]);

			int menseki = tate * yoko;

			int nagasa = (tate + yoko) * 2;

			System.Console.WriteLine(menseki + " " + nagasa);
		}
	}
}

Measured memory_bytes: 5608
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <valarray>
#include <vector>
using namespace std;

using ll = long long;
using ld = long double;
const int INF = 1e9;
const double EPS = 1e-9;
const ll MOD = 1e9 + 7;

vector<ll> graph[100010];
vector<ll> dist;
vector<bool> seen;
ll dfs(int x)
{
  if (seen[x])
    return dist[x];
  seen[x] = true;
  for (auto &v : graph[x])
  {
    ll res = dfs(v);
    dist[x] = max(dist[x], res + 1);
  }
  return dist[x];
}

int main()
{
  long long N;
  scanf("%lld", &N);
  long long M;
  scanf("%lld", &M);
  vector<ll> indegree(N, 0);
  for (int i = 0; i < M; i++)
  {
    ll x, y;
    cin >> x >> y;
    x--;
    y--;
    graph[x].push_back(y);
    indegree[y]++;
  }
  dist.assign(N, 0);
  seen.assign(N, false);

  ll ans = 0;
  for (int i = 0; i < N; ++i)
  {
    ll res = dfs(i);
    ans = max(ans, res);
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 8704
#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <bitset>

#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <numeric>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define INF 2000000000
#define rep(i,n) for(int i=0;i<(n);i++)
typedef pair<int, int> P;
const ll MOD=1000000007;
using Graph = vector<vector<int>>;

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



int n;
ll k;
ll d[100005];
int main() {
    cin >> n >> k;
    for (int i = 0; i < n; i++) {
        ll a, b;
        cin >> a >> b;
        d[a] += b;
    }
    
    for (int ans = 1; ans <= 100000; ans++) {
        if (k <= d[ans]) {
            cout << ans << endl;
            return 0;
        }
        k -= d[ans];
    }
    return 0;
}

Measured memory_bytes: 1024
#include<algorithm>
#include<iostream>
#include<stdio.h>
#include<iostream>
#include<stdio.h>
#include<vector>
#include<set>
#include<string>
#include<iomanip>
#include<queue>
#include<functional>
#include<cmath>
#include<map>
#include<tuple>
#define rep(i,n) for(int i=0; i<(int)n; i++)//n回繰り返す
#define rrep(i,n)for(int i=n-1;i>=0;i--)
#define REP(i,n) for (int i = 1; i <= (int)n; i++)//i=1からi=nまで
#define RREP(i,n)for(int i=n;i>=1;i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using graph = vector<vector<int>>;
const ll mod = pow(10, 9) + 7;
const int INF = 1e9;
const ll LINF = 1e18;
const double pi = 3.14159265358979323846;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main() {
    int N, Q; cin >> N;
    vector<int>A(N + 1); ll ans = 0; map<int, int>cnt;
    REP(i, N) {
        cin >> A[i];
        ans += A[i];
        cnt[A[i]]++;
    }
    cin >> Q;
    vector<int>B(Q + 1);
    vector<int>C(Q + 1);
    REP(i, Q) {
        cin >> B[i] >> C[i];
    }
    REP(i, Q) {
        if (cnt[B[i]] != 0) {
            ans += (C[i] - B[i]) * cnt[B[i]];
            cnt[C[i]] += cnt[B[i]];
            cnt[B[i]] = 0;
            cout << ans << endl;

        }
        else {
            cout << ans << endl;
        }

    }
    
    
}



















Measured memory_bytes: 8744
import fileinput

x1, y1, x2, y2 = map(int, input().split())

xx = x2 - x1
yy = y2 - y1

x3 = x2 - yy
y3 = y2 + xx

x4 = x1 - yy
y4 = y1 + xx

print(x3, y3, x4, y4)

Measured memory_bytes: 3060
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<deque>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#include<functional>
#include<unordered_set>
#include<iomanip>
#include<cassert>
#include<regex>
#include<bitset>
#include<complex>
#include<chrono>
#include<random>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(),x.end()
using ll=long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;

ll gcd(ll n, ll m) {
	ll tmp;
	while (m!=0) {
		tmp = n % m;
		n = m;
		m = tmp;
	}
	return n;
}

ll lcm(ll n, ll m) {
	return abs(n * m) / gcd(n, m);//gl=xy
}
 
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
 
using namespace std;

//ここから

void solve(){
  string s;
  cin>>s;
  int sum=0;
  rep(i,3)if(s[i]=='1')++sum;
  cout<<sum;
}

int main(){
	ios::sync_with_stdio(false);
  cin.tie(0);
	cout<<fixed<<setprecision(15);
  solve();
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#define LL long long
LL ans = 1;
const LL mod = 1e9 + 7;
int N;
int A[100010];
int main() {
	std::cin >> N;
	for (int i = 0; i < N; i++) {
		int tmp;
		std::cin >> tmp;
		A[tmp]++;
	}
	if (N % 2) {
		if (A[0] != 1) {
			std::cout << 0 << std::endl;
			return 0;
		}
	}
	else {
		if (A[0] != 0) {
			std::cout << 0 << std::endl;
			return 0;
		}
	}
	for (int i = (N % 2 ? 2 : 1); i <= N; i += 2) {
		if (A[i] != 2) {
			std::cout << 0 << std::endl;
			return 0;
		}
	}
	for (int i = 0; i < N / 2; i++) {
		ans *= 2;
		ans %= mod;
	}
	std::cout << ans << std::endl;
	return 0;
}

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

#define int long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define uniqueV(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define dbg(x) cerr << #x << ": " << x << endl;
#define dbg2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define dbg3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define dbgB(value, size) cerr<<#value<<": "<<bitset<size>(value) << endl;
#define line() cerr << "---------------" << endl;

const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, -1, 1};
const double PI = 3.14159265358979323846;

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

template<typename T, typename U>
void print1(T Array, U size) {
  for (int i = 0; i < size; i++) {
    cout << Array[i] << " ";
  }
  cout << endl;
}

template<typename T>
void print(T Array, int height, int width) {
  for (int i = 0; i < height; i++) {
    for (int j = 0; j < width; j++) {
      cout << " " << Array[i][j];
    }
    cout << endl;
  }
}

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

int n;
int dp[55];

int rec(int stage) {
  if (stage == 0) {
    return dp[stage] = 1;
  }
  
  if (dp[stage] != -1) {
    return dp[stage];
  }

  int ans = 0;

  for (int i = 1; i <= 3; i++) {
    if (stage - i < 0) continue;
    ans += rec(stage - i);
  }

  return dp[stage] = ans;
}

signed main() {
  fill(dp, dp+33, -1);
  rec(30);
  while (1) {
    cin >> n;
    if (n == 0) break;
    int t = (dp[n] + 3650 - 1) / 3650;
    cout << t << endl;
  }

  return 0;
}


Measured memory_bytes: 3008
#include<bits/stdc++.h>
#include<map>
using namespace std;
typedef long long int ll;
typedef pair<int,int> p;
map<ll,int> mp;
int main(){
	int n;
	cin>>n;
	ll ret=0,sum=0;
	mp[0]++;
	for(int i=0;i<n;i++){
		ll a;
		cin>>a;
		sum+=a;
		ret+=mp[sum];
		mp[sum]++;
	}
	cout<<ret;
	return 0;
}

Measured memory_bytes: 12800
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <iomanip>
#include <vector>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <map>
#include <queue>
#define rep(i,n) for (int i=0;i<(n);i++)

using namespace std;

//ユークリッドの互除法
//p,qの最大公約数を返す
int gcd(int p, int q) {
	if (p % q == 0) return q;
	return gcd(q, p % q);
}

//最小公倍数を返す
long long lcm(long long a, long long b) {
	return a * b / gcd(a, b);
}

int main() {
	long long a, b;
	cin >> a >> b;

	cout << lcm(a, b) << endl;

	return 0;
}

Measured memory_bytes: 3628
package main

import (
	"fmt"
	"strings"
)

func main() {
	var str string
	var q int
	fmt.Scan(&str, &q)
	s := strings.Split(str, "")
	for i := 0; i < q; i++ {
		var com string
		var a, b int
		fmt.Scan(&com, &a, &b)
		switch com {
		case "print":
			fmt.Println(strings.Join(s[a:b+1], ""))
		case "reverse":
			for j, k := a, b; j < k; j, k = j+1, k-1 {
				s[j], s[k] = s[k], s[j]
			}
		case "replace":
			var rep string
			fmt.Scan(&rep)
			reps := strings.Split(rep, "")
			for j := a; j <= b; j++ {
				s[j] = reps[j-a]
			}
		}
	}
}



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

#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(x) (x).begin(),(x).end()
#define pb emplace_back

using namespace std;
using ll = long long;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> P;
 
const int INF = 1e9;
const double EPS = 1e-10;
const int MOD = 1e9+7;
const double PI = acos(-1.0);

ll dp[110][10];

int main(){
    int h,w,k;
    cin >> h >> w >> k;
    dp[0][0] = 1;
    for(int i = 0; i < h; i++){
        for(int j = 0; j < (1<<(w-1)); j++){
            int flag = 0,tmp = j;
            while(tmp/2){
                if(tmp%2&&tmp/2%2) flag = 1;
                tmp /= 2;
            }
            if(flag) continue;
            //cout << bitset<8>(j) << endl;
            int p[w+10];
            for(int l = 0; l < w; l++) p[l] = l;
            for(int l = 0; l < w-1; l++) if((j>>l)&1) swap(p[l],p[l+1]);
            for(int l = 0; l < w; l++){
                dp[i+1][p[l]] += dp[i][l];
                dp[i+1][p[l]] %= MOD;
            }
            
        }
    }
    cout << dp[h][k-1] << endl;
}

Measured memory_bytes: 256
import java.util.*;
import java.math.*;
         
class Main{
    public static void main(String[] args) {
        
        try(Scanner sc = new Scanner(System.in)){
 
            int money = Integer.parseInt(sc.next());
            
            int grad = 0;

            int moneyPer500Success = money - money % 500;

            grad += ((moneyPer500Success)/500)*1000;
            grad += (((money % 500)-((money % 500) % 5))/5)*5;

            System.out.println(grad);

        }catch(Exception e){
            e.printStackTrace();
        }        
    }
}

Measured memory_bytes: 21844
n=int(input())
num=2*(n//2) + 1
ans=[]
for i in range(1,n+1):
    for j in range(i+1,n+1):
        if i+j!=num:
            ans.append([i,j])
print(len(ans))
for a in ans:
    print(a[0],a[1])

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

struct cell{
  int l,r,u,d,dis;
  cell(int li, int ri, int ui, int di,int disi){
    l = li; r = ri; u = ui; d = di; dis = disi;
  }
};

typedef vector<vector<cell> > maze;
typedef pair<int,int> pii;

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

void bfs(maze& m, int h, int w){
  
  queue<pii> q;
  q.push(pii(0,0));
  m[0][0].dis = 0;

  while(!q.empty()){
    int prex = q.front().first;
    int prey = q.front().second;

    q.pop();
    if(prex == w-1 && prey == h-1) break;

    for(int i=0; i<4; i++){
      int nx = prex + dx[i];
      int ny = prey + dy[i];
      if(nx >= w || nx < 0 || ny >= h || ny < 0) continue; // ????£?????¶???????
      if(i==0 and m[prey][prex].l == 1) continue; // ?£???????
      if(i==1 and m[prey][prex].r == 1) continue;
      if(i==2 and m[prey][prex].d == 1) continue;
      if(i==3 and m[prey][prex].u == 1) continue;
      if(m[ny][nx].dis != -1) continue; // ??¢?´¢??????
      
      // ?§??????????
      m[ny][nx].dis = m[prey][prex].dis + 1;
      q.push(pii(nx,ny));
     }
  }
}



int main(){
  
  while(1){
    int w,h;
    cin >> w >> h;
    if(!w and !h) break;

    maze m(h+1,vector<cell>(w+1,cell(0,0,0,0,-1)));

    // ?????????????????¨?????????
    for(int i=0; i<h; i++){
      for(int j=0; j<w; j++){
	if(i==0)
	  m[i][j].u = 1;
	if(i==h-1)
	  m[i][j].d = 1;
	if(j==0)
	  m[i][j].l = 1;
	if(j==w-1)
	  m[i][j].r = 1;
      }
    }

    // ??\?????????????§????
    for(int i=0; i<2*h-1; i++){
      if(i%2 == 0)
	for(int j=0; j<w-1; j++){ // ????????????
	  int x; cin >> x;
	  m[i/2][j].r = x;
	  m[i/2][j+1].l = x;
	}
      else
	for(int j=0; j<w; j++){ // ?¨??????????
	  int x; cin >> x;
	  m[i/2][j].d = x;
	  m[i/2+1][j].u = x;
	}
    }

    bfs(m,h,w);
    cout << m[h-1][w-1].dis+1 << endl;
  }

}

Measured memory_bytes: 1236
#include <bits/stdc++.h>
//#include <atcoder/all>
#define ll long long int
#define MOD 1000000007
#define P pair<ll,ll>
#define INF 1000000000000000000

//using namespace atcoder;
using namespace std;

int main(void){
  ll n, m;
  cin >> n >> m;
  
  vector<ll> a(n);
  for (int i = 0; i < n; i++){
    cin >> a[i];
  }
  

  set<ll> b;
  ll tt = 0;
  for (ll i = 0; i < n; i++){
    ll t = 0;
    while (a[i] % 2 == 0){
      a[i] /= 2;
      t++;
    }
    b.insert(t);
    tt = t;
  }

  if (b.size() > 1){
    cout << 0 << endl;
  }
  else {
    ll l = (1LL << (tt-1));
    for (ll i = 0; i < n; i++){
      l = lcm(l, a[i]);
    }
    cout << (m / l + 1) / 2 << endl;
  }

  return 0;
}


Measured memory_bytes: 4028
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(i,m,n) for(int i=m;i<n;i++)
ll mod=1e9+7;

int main(){
  string s;
  cin>>s;
  if(s[2]==s[3] && s[4]==s[5]){
    cout<<"Yes"<<endl;
  }
  else{
    cout<<"No"<<endl;
  }
}

Measured memory_bytes: 256
#include"bits/stdc++.h"
using namespace std;
#define ll long long
#define LL long long
#define MOD 1000000007
ll N, M, K,H,W, ans, mi1,mi2,sum;
string s;
int main() {
	cin >> N>>M>>K;
	ans = 0;

	cout <<max(K-(N-M),ans)<< endl;
	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <math.h>
#include <algorithm>
#include <chrono>
#include <queue>
#include <functional>

#define out(t) cout << (t) << "\n"

using namespace std;

typedef long long ll;
typedef unsigned int uint;

void swap(int &a, int &b) {
    a ^= b;
    b ^= a;
    a ^= b;
}

uint tzcnt(uint x) {
    x = ~x & (x - 1);
    x -= x >> 1 & 0x55555555;
    x = (x & 0x33333333) + (x >> 2 & 0x33333333);
    x = x + (x >> 4) & 0x0F0F0F0F;
    return x * 0x01010101 >> 24;
}

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

    int n, a;
    cin >> n >> a;

    cout << ((n % 500) <= a ? "Yes" : "No") << std::endl;
}

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

template <typename T>
std::map<T, T> prime_factorization(T N) {
  std::map<T, T> list;

  uint64_t remain = N;
  while (remain % 2 == 0) {
    remain /= 2;
    list[2]++;
  }
  for (size_t i = 3; i * i <= remain; i += 2) {
    while (remain % i == 0) {
      remain /= i;
      list[i]++;
    }
  }
  if (remain != 1) list[remain] = 1;

  return list;
}

int main() {
  uint64_t N = 0;
  std::cin >> N;

  auto facts = prime_factorization(N);

  uint32_t count = 0;
  for (auto &&f : facts) {
    for (size_t i = 1; f.second >= i; i++) {
      f.second -= i;
      count++;
    }
  }

  std::cout << count << std::endl;

  return 0;
}

Measured memory_bytes: 3588
#include"bits/stdc++.h"
using namespace std;
using ll=long long;
template<class T=ll>inline T in(istream&is=cin){T ret;is>>ret;return ret;}
template<class T>inline auto vec2(class vector<T>::size_type h,class vector<T>::size_type w,T v=T()){return vector<vector<T>>(h,vector<T>(w,v));}
template<class RandomAccessIterator>inline void psortb(RandomAccessIterator first,RandomAccessIterator last){using P=pair<decltype(first->first),decltype(first->second)>;sort(first,last,[](const P&p1,const P&p2){return p1.second<p2.second||(p1.second==p2.second&&p1.first<p2.first);});}

int main()
{
    string s;cin>>s;
    string foo="hi";
    for(ll i=0;i<5;++i){
        if(s==foo){
            cout<<"Yes"<<endl;
            return 0;
        }
        foo+="hi";
    }
    cout<<"No"<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <tuple>
#include <cmath>
using namespace std;

int main(int argc, const char * argv[]) {
  int n;
  cin >> n;
  string s;
  char a;
  vector<string> vs;
  cin >> s;
  vs.push_back(s);
  a = s.at(s.size()-1);
  for(int i = 0; i < n -1; i++){
    cin >> s;
    vector<string>::iterator iter = find(vs.begin(), vs.end(), s);
    if(a != s.at(0) || iter != vs.end()){
      cout << "No" << endl;
      return 0;
    }
    vs.push_back(s);
    a = s.at(s.size()-1);
  }
  cout << "Yes" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
int s[505][505]={};
signed main(){
  cin.tie(NULL);
  ios::sync_with_stdio(false);
  int N,M,Q;
  int L,R;
  int p,q;
  cin>>N>>M>>Q;
  for(int i=0;i<M;i++){
    cin>>L>>R;
    s[L][R]++;
  }
  for(int i=1;i<=N;i++){
    for(int j=1;j<=N;j++){
      s[i][j]+=s[i-1][j]+s[i][j-1]-s[i-1][j-1];
    }
  }
  
  for(int i=0;i<Q;i++){
    cin>>p>>q; 
    cout<<s[q][q]-s[q][p-1]-s[p-1][q]+s[p-1][p-1]<<"\n";

  }
return 0;
}

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

using namespace std;
using namespace std;
#define rep(i,n) for(long long i=0; i<(long long)(n);i++)
//rep…「0からn-1まで」の繰り返し
#define rep2(i,s,n) for(long long i=s; i<=(long long)(n);i++)
//rep2…「sからnまで」の繰り返し
#define repr(i,s,n) for(long long i=s;i>=(long long)(n);i--)
//repr…「ｓからnまで」の降順の繰り返し

typedef long long ll;

const ll inf = 1e9+7;
const ll mod = 1e9+7;

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

    if(s<=n)cout<<"unsafe"<<endl;
    else cout<<"safe"<<endl;


}


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

int N, M;
int par[200010];

void init()
{
    for(int i = 0; i < 200010; i++)par[i] = i;
}

int root(int x)
{
    if(par[x] == x)return x;
    return par[x] = root(par[x]);
}

bool same(int x, int y)
{
    return root(x) == root(y);
}

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

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

    init();
    for(int i = 0; i < M; i++)
    {
        int x, y, z;
        cin >> x >> y >> z;
        if(!same(x, y))
        {
            N--;
            unite(x, y);
        }
    }

    cout << N << endl;
    return 0;
}



Measured memory_bytes: 1024
#include <iostream>

using namespace std;

int main() {
	int a,b,c,d ;
	cin >> a >> b >> c >> d;
	if (a+b > c+d) {
		cout << "Left" << endl;
	}
	else if (a+b < c+d) {
		cout << "Right" << endl;
	}
	else {
		cout << "Balanced" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
const int INF = 1111111111;
using namespace std;

typedef long long ll;

ll merge(vector<int>& A, int left, int mid, int right) {
    ll cnt = 0;
    int n1 = mid - left;
    int n2 = right - mid;
    vector<int> L(n1+1);
    for (int i = 0; i < n1; i++) {
        L[i] = A[left+i];
    }
    L[n1] = INF;
    vector<int> R(n2+1);
    for (int i = 0; i < n2; i++) {
        R[i] = A[mid+i];
    }
    R[n2] = INF;

    int i = 0, j = 0;
    for (int k = left; k < right; k++) {
        if (L[i] <= R[j]) {
            A[k] = L[i];
            i++;
        }else {
            A[k] = R[j];
            j++;
            cnt += n1 - i;
        }
    }
    return cnt;
}

ll mergeSort(vector<int>& A, int left, int right) {
    if (left + 1 < right) {
        int mid = (left + right) / 2;
        ll v1 = mergeSort(A, left, mid);
        ll v2 = mergeSort(A, mid, right);
        ll v3 = merge(A, left, mid, right);
        return v1+v2+v3;
    }
    return 0;
}

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

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

    ll ans = mergeSort(ary, 0, n);
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 2564