akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define allin(a , x) for(auto a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

template<class T1, class T2>
istream &operator>>(istream &in, pair<T1, T2> &P){
	in >> P.first >> P.second;
	return in;
}
template<class T1, class T2>
ostream &operator<<(ostream &out, const pair<T1, T2> &P){
	out << "(" << P.first << ", " << P.second << ")";
	return out;
}
template<class T>
istream &operator>>(istream &in, vector<T> &arr){
	for(auto &x: arr) in >> x;
	return in;
}
template<class T>
ostream &operator<<(ostream &out, const vector<T> &arr){
	for(auto &x: arr) out << x << ' '; cout << "\n";
	return out;
}
template<class T>
istream &operator>>(istream &in, deque<T> &arr){
	for(auto &x: arr) in >> x;
	return in;
}
template<class T>
ostream &operator<<(ostream &out, const deque<T> &arr){
	for(auto &x: arr) out << x << ' '; cout << "\n";
	return out;
}
const int N = 100005;
vector<int> adj[N];
int pai[N];
int cor[N];
struct edge{
	int u , v;
}; 
vector<edge> v;
int n;

void dfs(int x , int y){
	set<int> jf;
	int cj = 1;
	if(y != -1 && cor[y] == cj) cj++; 
	rep(i,0,adj[x].size()){
		if(adj[x][i] == y) continue;
		edge w = v[adj[x][i]];
		int v = w.u ^ w.v ^ x;
		cor[adj[x][i]] = cj++;
		if(y != -1 && cor[y] == cj) cj++;
		dfs(v , adj[x][i]);

	}
}


int32_t main(){
	scanf("%d" , &n);
	rep(i, 0 , n-1){
		int x , y;
		scanf("%d%d" , &x,  &y);
		adj[x].push_back(v.size());
		adj[y].push_back(v.size());
		v.push_back({x,y});
	}
	int ans = 0;
	rep(i, 1 , n+1){
		ans = max(ans , (int)adj[i].size()) ; 
	}
	dfs(1 , -1);
	printf("%d\n", ans);
	rep(i , 0 , n-1){
		printf("%d\n" , cor[i]);
	}
}

Measured memory_bytes: 11640
#include <bits/stdc++.h>
using namespace std;
string num[11];
int n,k,used[11];
set<string> S;
void dfs(int dep,string str){
  if(dep==k){S.insert(str);return; }

  for(int i=0;i<n;i++){
    if(used[i])continue;
    used[i]=1;
    dfs(dep+1,str+num[i]);
    used[i]=0;
  }
}

int main(){
  while(cin>>n,n){
    cin>>k;
    for(int i=0;i<n;i++)cin>>num[i];
  memset(used,0,sizeof(used));
  S.clear();
  dfs(0,"");
  cout <<S.size()<<endl;
  }
  return 0;
}

Measured memory_bytes: 3348
#include <bits/stdc++.h> //C++の機能を「全て」読み込むための命令
#define rep(i,n) for(int i=0; i<(n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;

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

    //Wの数とSの数の累積和を計算
    vector<int> W_cs(n,0);
    vector<int> E_cs(n,0);
    rep(i,n){
        if(i==0){
            if(s.at(i)=='W') W_cs.at(i) = 1;
            else E_cs.at(i) = 1;
        }
        else{
            W_cs.at(i) = W_cs.at(i-1);
            E_cs.at(i) = E_cs.at(i-1);
            if(s.at(i)=='W') W_cs.at(i) += 1;
            else E_cs.at(i) += 1;
        }
    }
    // rep(i,n){
    //     cout<<W_cs.at(i)<<" ";
    // }
    // cout<<endl;
    // rep(i,n){
    //     cout<<E_cs.at(i)<<" ";
    // }
    // cout<<endl;

    //処理
    int ans=0;//向きを直す人数
    int ans_max=0;
    rep(p,n){
        if(p==0){
            if(s.at(p)=='W') ans = E_cs.at(n-1);
            else ans = E_cs.at(n-1) - 1;
            ans_max = ans;
        }
        else{
            if(s.at(p)=='W'){
                ans = E_cs.at(n-1) - E_cs.at(p) + W_cs.at(p) -1;
            }
            else ans = E_cs.at(n-1) - E_cs.at(p) + W_cs.at(p);
        }
        // cout<<ans<<endl;
        if(ans_max>ans) ans_max = ans;
    }

    cout<<ans_max<<endl;
    return 0;
}

Measured memory_bytes: 3076
#pragma region header
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#define int long long
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define rev(i, n) for(int i = (int)(n - 1); i >= 0; i--)
#define rev1(i, n) for(int i = (int)(n); i > 0; i--)
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define resort(v) sort((v).rbegin(), (v).rend())
#define vi vector<int>
#define vvi vector<vector<int>>
#define vc vector<char>
#define vvc vector<vector<char>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
using ll = long long;
using P = pair<int, int>;
/* ----------------よく使う数字や配列----------------- */
int dx[] = {1,0,-1,0};
int dy[] = {0,1,0,-1};
constexpr ll mod = 1e9+7;
constexpr int inf = INT32_MAX/2;
constexpr ll INF = LLONG_MAX/2;
constexpr long double eps = DBL_EPSILON;
constexpr long double pi = 3.141592653589793238462643383279;
/* ----------------------end----------------------- */

/* --------------------テンプレート------------------ */
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;
}
/* ----------------------end----------------------- */

/* --------------------ライブラリ-------------------- */
ll fact(int i) {       //階乗
    if (i == 0) return 1;
    return (fact(i - 1)) * i % mod;
}
ll gcd(ll a, ll b) {        //最大公約数
    if(b == 0) return a;
    return gcd(b, a % b); 
}
ll lcm(ll a, ll b) {      //最小公倍数
    return a / gcd(a, b) * b ;
}
int keta(ll n) {        //桁数を求める
    if(n == 0) return 1;
    int count = 0;
    while(n != 0) {
        n /= 10;
        count++;
    }
    return count;
}
ll ketasum(ll n) {    //各桁の和
    ll sum = 0;
    while(n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
/* ----------------------end----------------------- */
#pragma endregion

vi prime_factorize(int n) {
    vi v;
    for(int i = 2;i<=sqrt(n);i++) {
        if(n%i==0) {
            int count = 0;
            while(n%i==0) {
                count++;
                n/=i;
            }
            v.pb(count);
        }
    }
    if(n!=1) v.pb(1);
    return v;
}
signed main() {
    vi v = {1,3,6,10,15,21,28,36};
    int n;cin >> n;
    vi vec = prime_factorize(n);
    int count = 0;
    for(auto p:vec) {
        // cout << p << ' ' << upper_bound(all(v),p)-v.begin() << char(10);
        count+=upper_bound(all(v),p)-v.begin();
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 3728
#include <iostream>
#include <algorithm>
#include <climits>
#include <string>
#include <map>
#include <array>
#include <vector>

typedef long long ll;

using namespace std;

int main()
{
    int a, b, c, k, max;

    cin >> a >> b >> c >> k;

    vector<int> v = {a, b, c};

    sort(v.begin(),v.end());
    for (int i = 0; i < k; ++i) {
        v[2] = v[2] * 2;
    }

    cout << (v[0] + v[1] + v[2]) << endl;
    return 0;
}

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

using namespace std;

typedef long long ll;
#define mems(p) memset(p,-1,sizeof(p))
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define nl "\n"

const int mxN = 1e5;
const ll MOD = 1e9 + 7;

void fast()
{ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);}

ll gcd(ll a, ll b) {
	return b ? gcd(b, a%b) : a;
}

int main() {
	fast();
	int n;
	cin >> n;
	int tmp = 1000 - n%1000;
	if (tmp == 1000) tmp = 0;
	cout << tmp << nl;
}

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

int main()
{
	int n;
	cin >> n;
	multiset<int> boss;
	for (int i = 2; i <= n; i++) {
		int input;
		cin >> input;
		boss.insert(input);
	}
	vector<int> sub(n+1);
	for (int i = 1; i <= n; i++) {
		sub[i] = boss.count(i);
		boss.erase(i);
	}
	for (int i = 1; i <= n; i++) cout << sub[i] << "\n";
}


Measured memory_bytes: 13528
#define _USE_MATH_DEFINES
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<string>
#include<iomanip>
#include<cassert>
#include<functional>
typedef long long ll;

int main(){
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	
	int length;
	int count = 0;
	bool flag = false;

	std::cin >> length;
	std::vector<int> input(length);
	for (int i = 0; i < length; i++){
		std::cin >> input[i];
	}

	while (flag == false){
		flag = true;
		for (int i = length - 1; i >= 1; i--){
			if (input[i] < input[i - 1]){
				std::swap(input[i], input[i - 1]);
				count++;
				flag = false;
			}
		}
	}

	for (int i = 0; i < length; i++){
		std::cout << input[i];
		if (i != length - 1){
			std::cout << ' ';
		}
		else{
			std::cout << '\n';
		}
	}

	std::cout << count << '\n';

	return 0;
}


Measured memory_bytes: 3204
#include<stdio.h>

int main()
{
    int a,b,i,s=0;
    scanf("%d",&a);
    i=a;
    while(a)
    {
        b=a%10;
        a=a/10;
        s+=b;
    }
    if(i%s==0) printf("Yes\n");
    else printf("No\n");
    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <numeric>
#include <cmath>

using namespace std;

typedef long long int ll;

#define all(x) x.begin(),x.end()

const ll mod = 1e9+7;
const ll INF = 1e9;
const ll MAXN = 1e9;

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

	sort(all(a));
	int front=0,back=n-1;
	deque<ll> res;
	bool is_front = false;
	int cnt = 0;
	res.push_front(a[0]);
	front++;
	// if(n % 2 != 0){
	// 	is_front = false;
	// }
	while(front<=back){
		if(is_front){
			if(cnt == 0){
				res.push_front(a[front]);
				cnt++;
				front++;
			}else if(cnt == 1){
				res.push_back(a[front]);
				cnt++;
				front++;
			}
			if(cnt == 2){
				is_front = false;
				cnt = 0;
			}
		}else{
			if(cnt == 0){
				res.push_front(a[back]);
				cnt++;
				back--;
			}else if(cnt == 1){
				res.push_back(a[back]);
				cnt++;
				back--;
			}
			if(cnt == 2){
				is_front = true;
				cnt = 0;
			}
		}
	}

	vector<ll> ress;
	ll ans = 0;
	for(auto itr = res.begin(); itr != res.end(); ++itr){
		ress.push_back(*itr);
	}
	// for(int i = 0; i < n; i++){
	// 	cout << ress[i] << " ";
	// }printf("\n");
	for(int i = 1; i < n; i++){
		ans += abs(ress[i]-ress[i-1]);
	}
	// cout << ans << endl;

	front=0,back=n-1;
	deque<ll> res2;
	is_front = true;
	cnt = 0;
	res2.push_front(a[n-1]);
	back--;
	// if(n % 2 != 0){
	// 	is_front = false;
	// }
	while(front<=back){
		if(is_front){
			if(cnt == 0){
				res2.push_front(a[front]);
				cnt++;
				front++;
			}else if(cnt == 1){
				res2.push_back(a[front]);
				cnt++;
				front++;
			}
			if(cnt == 2){
				is_front = false;
				cnt = 0;
			}
		}else{
			if(cnt == 0){
				res2.push_front(a[back]);
				cnt++;
				back--;
			}else if(cnt == 1){
				res2.push_back(a[back]);
				cnt++;
				back--;
			}
			if(cnt == 2){
				is_front = true;
				cnt = 0;
			}
		}
	}

	vector<ll> ress2;
	ll ans2 = 0;
	for(auto itr = res2.begin(); itr != res2.end(); ++itr){
		ress2.push_back(*itr);
	}
	// for(int i = 0; i < n; i++){
	// 	cout << ress2[i] << " ";
	// }printf("\n");
	for(int i = 1; i < n; i++){
		ans2 += abs(ress2[i]-ress2[i-1]);
	}

	cout << max(ans,ans2) << endl;
	return 0;
}

Measured memory_bytes: 4984
#include <iostream>
#include <algorithm>
#include <string>
#include <sstream>
#include <cmath>
using namespace std;
#define N_MAX 13
#define INF 99999999
int W;
int N;
int R[N_MAX];
double D[N_MAX][N_MAX];
double dp[(1<<N_MAX)][N_MAX];

/*
double rec(int s, int u) {
  if(s == (1<<N) - 1) return 0;
  double res = INF;
  for(int v = 0; v < N; ++v) {
    if((s>>v) & 1) continue;
    res = min(res, D[u][v] + rec(s | (1<<v), v));
  }
  return res;
}
*/

void make() {
  for(int i = 0; i <= N; ++i) {
    for(int j = 0; j < N; ++j) {
      if(i == j) {
	D[i][j] = 0;
      } else if(i == N || R[i] == R[j]) {
	D[i][j] = R[j] * 2;
      } else {
	double d = sqrt( pow((double)(R[i]+R[j]), 2.0)
			 - pow((double)(R[i]-R[j]), 2.0) );
	D[i][j] = d - R[i] + R[j];
      }
    }
  }
}

void solve() {
  make();
  for(int i = 0; i < 1<<N; ++i) {
    if(i == (1<<N)-1) fill(dp[i], dp[i]+N+1, 0);
    else              fill(dp[i], dp[i]+N+1, INF);
  }

  for(int s = (1<<N) - 2; s >= 0; s--) {
    for(int u = 0; u <= N; u++) {
      for(int v = 0; v < N; v++) {
	if((s>>v) & 1) continue;
	dp[s][u] = min(dp[s][u], D[u][v] + dp[s|(1<<v)][v]);
      }
    }
  }
  cout << (dp[0][N] <= W ? "OK" : "NA") << endl;
}

main() {
  string line;
  while(getline(cin, line)) {
    stringstream ss;
    ss << line;
    ss >> W;
    N = 0;
    int a;
    while(ss >> a) R[N++] = a;
    solve();
  }
}

Measured memory_bytes: 1344
#include<iostream>
#include <string>
#include <cstdlib> //絶対値利用のため
#include <algorithm>
#include <vector>
using namespace std;


int main() {
	int a, b;
	cin >> a >> b;
	if ((a + 1) / 2 >= b) cout << "YES" << endl;
	else cout << "NO" << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>
#include <sstream>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <numeric>
#include <cmath>
#include <climits>
#include <limits>
#include <cfloat>
#include <fstream>
using namespace std;

int main()
{
//	cut here before submit 
//	freopen("testcase.pym", "r", stdin);
	string str = "";
	int n;
	int count = 0;
	int x, h;

	while (getline (cin, str ) ){
		stringstream ss(str);
		ss >> n;

		if (count % 2 == 0 ){
			x = n;
			++count;
			continue;
		} // end if

		if (count % 2 != 0 ){
			h = n;
			++count;		
		} // end if
		
		if (x == 0 && h == 0){
			break;
		}else{
			//cout << "x: " << x << " h: " << h << endl;
			if (x == 0 || h == 0){
				cout << '0' << endl;
			}else{
				double m = (double)x/2.*(double)x/2.;
					m += (double)(h*h);
				double s  = sqrt (m);
				double res = x*(x+2*s);
				printf ("%.9f\n", res );
			} // end if
		} // end if
	} // end loop

		
	return 0;
}

Measured memory_bytes: 0
// Try DISCO presents ディスカバリーチャンネル コードコンテスト2020 予選
// author: Leonardone @ NEETSDKASU

fn main() {
    let mut stdin = String::new();
    std::io::Read::read_to_string(&mut std::io::stdin(), &mut stdin).unwrap();
    let mut stdin = stdin.split_whitespace();
    let mut get = || stdin.next().unwrap();
    macro_rules! get {
        ($t:ty) => (get().parse::<$t>().unwrap());
        () => (get!(i64));
    }
    
    let n = get!(usize);
    let mut vs = vec![];
    for _ in 0..n {
        vs.push(get!());
    }
    let sum: i64 = vs.iter().sum();
    let half = sum / 2;
    let mut tmp_sum = 0;
    for i in 0..n {
        tmp_sum += vs[i];
        if tmp_sum < half {
            continue;
        }
        tmp_sum -= vs[i];
        let tmp = sum - tmp_sum - vs[i];
        let diff = (tmp_sum - tmp).abs();
        let ans = (vs[i] - diff).abs();
        println!("{}", ans);
        break;
    }
    
}

Measured memory_bytes: 10488
//Robs Code

/***********HEADER***************/
#include <iostream>
#include <bitset>
#include <deque>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <string>
#include <algorithm>
#include <list>
#include <vector>
#include <unordered_set>
#include <unordered_map>
#include <stack>
#include <set>
#include <queue>
#include <map>
#include <iomanip>

/***********MACROS***************/
#define int long long int
#define all(x) x.begin(),x.end()
#define allr(x) x.rbegin(),x.rend()
#define endl "\n"
#define pb push_back
#define _1 first
#define _2 second
#define pii pair<int,int>

using namespace std;

const int N = 1e5 + 1;
int n,m,i,j,k,l,x,y,z,cnt[3],sum[3];

/***********MAIN**************/
signed main(){
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
	cin >> k;
	int a,b;
	cin >> a >> b;
	for(int i=a;i<=b;i++){
		if(i%k == 0){
			cout << "OK";
			return 0;
		}
	}
	cout << "NG";
}
//.........

Measured memory_bytes: 3616
import decimal
w, h, x, y = map(int, input().split())

decimal.getcontext().prec = 9
w = decimal.Decimal(w)
h = decimal.Decimal(h)
d = decimal.Decimal(2)

print("{:.6f}".format((w*h) / d))

if w / 2 == x and h / 2 == y:
    print(1)
else:
    print(0)

Measured memory_bytes: 5332
import java.util.*;

class Main{
    public static void main(String[] args){
        int tmp = -1;
        int max = 0;
        Scanner sc = new Scanner(System.in);

        int blue = sc.nextInt();
        String[] s = new String[blue];
        for(int i=0;i<blue;i++){
            s[i]=sc.next();
        }
        int red = sc.nextInt();
        String[] t  =new String[red];
        for(int i=0;i<red;i++){
            t[i]=sc.next();
        }
        sc.close();

        for(int i=0;i<blue;i++){
            for(int j=0;j<blue;j++){
                if(s[i].equals(s[j])){
                    tmp++;
                }
            }
            for(int k=0;k<red;k++){
                if(s[i].equals(t[k])){
                    tmp--;
                }
            }
            max = Math.max(max,tmp);
            tmp = 0;
        }
        System.out.print(max);
    }
}

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

int main(){
    int n;
    cin >> n;
    int a[n];
    for(int i=0;i<n;i++) cin >> a[i];
    int ans=a[0];
    for(int i=0;i<n;i++){
        ans=__gcd(ans,a[i]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 640
//参考：http://ehafib.hatenablog.com/entry/2015/12/23/164517
//インクルード(アルファベット順,bits/stdc++.hは使わない派閥)
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列

using namespace std;
typedef long long ll;

//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
//xにはvectorなどのコンテナ
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素

int n,m,q;
vector<int> a,b,c,d;
int ans;

void dfs(vector<int> A){
    if(A.size()==n+1){
        int now=0;
        REP(i,q){
            if(A[b[i]]-A[a[i]]==c[i]) now +=d[i];
        }
        ans = max(ans,now);
        return;
    }

    A.push_back(A.back());
    while(A.back() <= m){
        dfs(A);
        A.back()++;
    }
}

int main(){
    cin >> n >> m >> q;
    a = b = c = d = vector<int>(q);
    REP(i,q){
        cin >> a[i] >> b[i] >> c[i] >> d[i];
    }

    dfs(vector<int>(1,1));
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb emplace_back
typedef long long ll;
typedef pair<int,int> pint;

const int max_n=55555;
bool is_prime[max_n];
int prime[max_n];
int sieve(int n){
    int p=0;
    rep(i,n+1) is_prime[i]=true;
    is_prime[0]=is_prime[1]=false;
    FOR(i,2,n+1){
        if(is_prime[i]){
            prime[p++]=i;
            for(int j=2*i;j<=n;j+=i) is_prime[j]=false;
        }
    }
    return p;
}
int main(){
    int n;
    cin>>n;
    int p=sieve(55555);
    vector<int> v;
    rep(i,p){
        if(prime[i]%5==1) v.pb(prime[i]);
        if(v.size()==n) break;
    }
    for(auto it :v){
        cout<<it<<" ";
    }
    cout<<endl;
    return 0;
}

Measured memory_bytes: 384
//Jai Shree Krishna
#include <bits/stdc++.h>
using namespace std;
#define PI acos(-1)
#define MOD (ll)1000000007
#define pii pair<long long ,long long >
#define ll  long long int
#define loop(i,n) for(ll i=0;i<n;i++)
#define loop2(i,n) for(ll i = 1;i<=n;i+=1)
#define pb push_back
#define mp make_pair
#define EPS 1e-8
void display(vector<int> v1){loop(i,v1.size()){cout<<v1[i]<<" ";}cout<<endl;}
ll dx[8] = {0,1,0,-1,1,1,-1,-1};
ll dy[8] = {1,0,-1,0,1,-1,1,-1};

const int MAXN = (int)3e5+100;
int arr[MAXN];

int f[MAXN];
int cnt[MAXN];
int ans  =0 ;
void add(int i)
{
    cnt[i]+=1;
    if(i-cnt[i]+1>0)
    {
        if(f[i-cnt[i]+1]==0)
            ans+=1;
        f[i-cnt[i]+1]+=1;
    }
}

void del(int i)
{
    if(i-cnt[i]+1>0)
    {
        f[i-cnt[i]+1]-=1;
        if(f[i-cnt[i]+1]==0)
            ans-=1;
    }
    cnt[i]-=1;
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
   
    int n,m;
    cin>>n>>m;
    for(int i = 1;i<=n;i+=1)
    {
        cin>>arr[i];
        cnt[arr[i]]+=1;
    }
    for(int i = 1;i<=n;i+=1)
    {
        for (int j = i; j>0 and j>i-cnt[i]; j-=1) {
            f[j]+=1;
        }
    }
    for(int i = 1;i<=n;i+=1)
    {
        ans+=(f[i]>0);
    }
    for(int i = 1;i<=m;i+=1)
    {
        int x,y;
        cin>>x>>y;
        add(y);
        del(arr[x]);
        cout<<n-ans<<endl;
        arr[x] = y;
    }
    return 0;
}




Measured memory_bytes: 3840
#include<map>
#include<iostream>
#include<deque>
#include<algorithm>
#include<string>
#include<cctype>
#include<iomanip>
#include<vector>
#include<queue>
#include<math.h>
#include<bitset>
#include<random>
using namespace std;
using ll = long long;
using lll = __int128_t;
typedef pair<ll,ll> P;
#define REP(i,b,e) for(ll i=(ll)b;i<(ll)e;i++)
#define rep0(i,n) REP(i,0ll,n)
#define rep1(i,n) REP(i,1ll,n+1)
const ll longinf=1ll<<60;
const int inf=(1<<30)-1;
const ll mod=1e9+7;

map<map<char,ll>,ll> mp;

int main(){
      int n;
      cin>>n;
      string s[n];
      rep0(i,n) cin>>s[i];
      rep0(i,n){
            map<char,ll> mpp;
            rep0(j,10){
                  mpp[s[i][j]]++;
            }
            mp[mpp]++;
      }
      ll ans=0;
      for(auto iter=mp.begin();iter!=mp.end();iter++){
            ll k=(iter->second);
            ans+=((k*(k-1))/2);
      }
      cout<<ans<<endl;
      return 0;
}

Measured memory_bytes: 69376
#include "stdio.h"
#define mod 1000000007

int main(void)
{
  int n;
  int k;
  int i,j;
  scanf("%d",&n);
  scanf("%d",&k);
  long kei=0;
  long min=0;
  long max=0;

  for(i=0;i<k;i++)
  {
    min = min + i;
    max = max + (n-i);
  }
  kei = (max-min)+1;

  for(j=k;j<=n;j++)
  {
    min =min + j;
    max =max + (n-j);
    kei = kei+ (max - min) + 1;
  }

  printf("%ld",kei%mod);
}

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

using namespace std;

#define Rep(i,a,b)  for (int i=(a);i<(b);i++)
#define rep(i,n)    for (int i=0;i<(n);i++)
#define all(x)      (x).begin(), (x).end()

#define ll long long

int main()
{
	int n;
	cin >> n;
	if (n % 2)
		cout << n * 2 << endl;
	else
		cout << n << endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
 
using namespace __gnu_pbds;
using namespace std;
 
typedef long long int ll;
typedef unsigned long long int sll;
typedef long double ld;
#define A 1000000007
#define D 100000000000000ll
#define B 998244353ll
#define C 1000000000000000000ll
#define M 4000
#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define oset tree<pair<ll,ll>, null_type,less_equal<pair<ll,ll>>, rb_tree_tag,tree_order_statistics_node_update> 
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define mxe(v) *max_element(v.begin(),v.end())
#define mne(v) *min_element(v.begin(),v.end())
#define bs binary_search
#define lb lower_bound
#define ub upper_bound
#define ve vector
#define br break
#define PI acos(-1)
#define subt cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n" 

const ll MAXN=200005;
ve<ve<ll>> adj(MAXN);
ll n,ans;

int main() 
{
    FAST;
    cin>>n;
    ll a,b;
    for(int i=1;i<n;i++)
    {
        cin>>a>>b;
        adj[a].pb(b);
        adj[b].pb(a);
    }
    for(int i=1;i<=n;i++)
    {
        ans+=(n-i+1)*i;
        for(auto j:adj[i])
            if(j>i)
                ans-=(i*(n-j+1));
    }
    cout<<ans;
    subt;
    return 0;
}

Measured memory_bytes: 15752
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <array>
#include <vector>
#include <functional>
#include <unordered_map> 
#include <map> 
#include <numeric>
#include <limits>
#include <utility>
#include <queue>
#include <random>
#include <bitset>
using namespace std;
typedef long long LL;

int main() {
	int t, i, j, k;
	int a, b, c ,F=0;
	
	cin >> a;

	F = a/100%10+a/10%10+a%10;

	cout << F << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
const long long INF = 1LL << 60;
const long long MOD = 1000000007;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rep1(i, n) for (ll i = 1; i <= (n); ++i)
#define rrep(i, n) for (ll i = (n - 1); i >= 0; --i)
#define perm(c) sort(ALL(c));for(bool c##p=1;c##p;c##p=next_permutation(ALL(c)))
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define MAX max<ll>
#define MIN min<ll>
#define pb push_back
#define to_s to_string
#define len(v) (ll)v.size()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define print(x) cout << (x) << '\n'
#define drop(x) cout << (x) << '\n', exit(0)
#define debug(x) cout << #x << ": " << (x) << '\n'
using namespace std;
using ll = long long;
typedef pair<ll, ll> P;
typedef vector<ll> vec;
typedef vector<vector<ll>> vec2;
typedef vector<vector<vector<ll>>> vec3;
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; }
ll devc(ll x, ll y) { return (x + y - 1) / y; }

map<ll,ll> Prime_Factorization(ll N){
    map<ll,ll> PF;
    for(ll i = 2; i * i <= N; i++) while(!(N%i)) PF[i]++, N /= i;
    if(N != 1) PF[N] = 1;
    return PF;
}

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

    ll N;
    cin >> N;
    map<ll, ll> mp;

    rep1(i, N){
        map<ll, ll> tp = Prime_Factorization(i);
        for(auto m : tp) mp[m.first] += m.second;
    }

    ll ans = 1;
    for(auto m : mp) ans *= m.second + 1, ans %= MOD;
    print(ans);

    return 0;
}

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

int main() {
  ll n,p;
  string s;
  cin >> n;
  vector<pair<pair<string,ll>,ll>>a(n);
  rep(i,n){
  	cin >> s >> p;
  	a.at(i)=make_pair(make_pair(s,-1*p),i+1);
  }
  sort(a.begin(),a.end());
  rep(i,n) cout << a.at(i).second << endl;
}


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

using P = pair<int, int>;

int n, m, cnt, ans;
P p[100010];
prique2(int)que;
int main() {
	scanf("%d %d", &n, &m);
	rep(i, n) {
		scanf("%d %d", &p[i].first, &p[i].second);
	}
	sort(p, p + n);
	for (int i = 1; i <= m; ++i) {
		for(; cnt < n&& p[cnt].first <= i; cnt++) {
			que.push(p[cnt].second);
		}
		if (que.empty()) {
			if (n <= cnt) break;
			continue;
		}
		ans += que.top();
		que.pop();
	}
	printf("%d\n", ans);
}


Measured memory_bytes: 1660
#include <cmath>
#include <deque>
#include <iostream>
#include <string>
#include <utility>

using namespace std;

int main()
{
    int N;
    int M;
    int i;

    cin >> N;

    i = 1000;
    while (i <= N)
    {
        i += 1000;
    }

    if (N % 1000 == 0)
        i -= 1000;

    M = i - N;

    cout << M << endl;

    return 0;
}


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

const long long INF = 1e7 + 1;
const long long MOD = 1000000007;
const long double PI = 3.1415926;

#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); ++i)
#define RFOR(i,n,r) for(ll i = (ll)(n-1); i >= r; --i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,n,0)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()

#define cout cout << setprecision(12)

using ll = long long int;
using ull = unsigned long long int;
using ld = long double;
using vi = vector<ll>;
using vvi = vector<vi>;
using vp = vector<pair<ll, ll>>;
using vs = vector<string>;
using vc = vector<char>;
using lst = list<ll>;
using pq = priority_queue<ll>;

template < typename T >
inline void dbg(T a) { cout << a << ' ' << endl; }

ll n, m, k, ans = 0, sum = 0, cnt = 0;
string s, t;
char c;

/*--------------------template--------------------*/

int main() {
    cin >> n;
	cin >> s >> t;
	REP(i,n) {
    	cout << s[i] << t[i];
    }
    cout << endl;
}


Measured memory_bytes: 256
/*
digu_J - Digvijay Janartha
NIT Hamirpur - INDIA
*/

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

template < typename T > using ordered_set = tree < T, null_type, less < T >, rb_tree_tag, tree_order_statistics_node_update >;
template < typename T > using MinPriorityQueue = priority_queue < T, vector < T >, greater < T > >;

#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template < typename Arg1 >
void __f(const char* name, Arg1&& arg1) {
    cout << name << " : " << arg1 << std :: endl;
}
template < typename Arg1, typename... Args >
void __f(const char* names, Arg1&& arg1, Args&&... args) {
    const char* comma = strchr(names + 1, ',');
    int len = comma - names;
    for (int i = 0; i < len; ++i) {
        cout << names[i];
    }
    cout <<  " : " << arg1 << " | ";
    __f(comma + 1, args...);
}
#else
#define trace(...)
#endif

typedef double db;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair < ll, ll > pll;
typedef pair < int, int > pii;
typedef vector < ll > vll;
typedef vector < int > vi;

#define eb emplace_back
#define pb push_back
#define F first
#define S second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define unique_sort(x) (sort(x.begin(), x.end()), x.resize(distance(x.begin(), unique(x.begin(), x.end()))))
#define fast_io() ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0)

const ll LINF = LLONG_MAX, base = 1e9, MOD = 1e9 + 7, N = 15, M = 1e3 + 10;
const int INF = INT_MAX;
const db PI = acos(-1);

int n, m, ans, p[N];
vi q[N];

void test();
void solve(string s);

int main() {
    fast_io();
    test();
    return 0;
}

void test() {
    cin >> n >> m;
    for (int i = 1, x; i <= m; ++i) {
        cin >> x;
        for (int j = 1, y; j <= x; ++j) {
            cin >> y;
            q[i].eb(y);
        }
    }
    for (int i = 1; i <= m; ++i) {
        cin >> p[i];
    }
    solve("");
    cout << ans << "\n";
}

void solve(string s) {
    int sz = s.size();
    if (sz >= n) {
        bool ok = true;
        for (int i = 1; i <= m; ++i) {
            int temp = 0;
            for (int j = 0; j < q[i].size(); ++j) {
                if (s[q[i][j] - 1] == '1') {
                    temp = (temp + 1) % 2;
                }
            }
            ok &= (temp == p[i]);
        }
        ans += ok;
        return;
    }
    solve(s + '0');
    solve(s + '1');
}


Measured memory_bytes: 256
#include"bits/stdc++.h"
using namespace std;
int a[100001],f[100001];
int n;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	f[2]=abs(a[2]-a[1]);
	for(int i=3;i<=n;i++)
		f[i]=min(f[i-1]+abs(a[i]-a[i-1]),f[i-2]+abs(a[i]-a[i-2]));
	printf("%d",f[n]);
	return 0;
}


Measured memory_bytes: 1024
#include <stdio.h>

int fun(int n)
{
	int sum = 0, nn = n;
	while(nn)
	{
		sum += nn % 10;
		nn /= 10;
	}
	if(n%sum==0)
		return 1;
	else
		return 0;
}

int main()
{
    int n;
    scanf("%d", &n);
    
    if(fun(n))
    	printf("Yes\n");
    else
    	printf("No\n");

    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#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 repR(i,n) for(ll i=n;i>=0;i--)
#define all(v)(v).begin(),(v).end()
#define rall(v)(v).rbegin(),(v).rend()
#define F first
#define S second
#define pb push_back
#define pu push
#define COUT(x) cout<<(x)<<endl
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,vector<ll>,greater<ll>>
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define mp make_pair
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define sz(x) (int)(x).size()
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MOD = 1000000007LL;
const ll INF = 1LL << 60;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pll = pair<ll, ll>;
int main(){
  ll n,k;
  cin>>n>>k;
  vll a(n);
  vll b(2001);
  vll c(n);
  ll ans=0;
  rep(i,n) {
    cin>>a[i];
  }
  ll kk=(k-1)*k/2;
  kk%=MOD;
  rep(i,n){
    ll f=0;
    for(int j=i;j<n;j++){
      if(a[i]>a[j]) f++;
    }
    c[i]=f;
  }
  rep(i,n){
    b[a[i]]++;
  }
  for(int i=1;i<2001;i++){
    b[i]+=b[i-1];
  }
  rep(i,n){
    ans+=c[i]*k;
    ans%=MOD;
    ans+=kk*b[a[i]-1]%MOD;
    ans%=MOD;
  }
  COUT(ans);
}
  


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

ll x = 1e9 + 7; 

int main() {
  ll x;
  cin >> x;
  ll ans = 0;
  ans += 1000 * (x/500);
  x %= 500;
  ans += 5 * (x/5);
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 3524
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

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

	std::pair<std::string, std::pair<int, int>> data;
	std::vector<std::pair<std::string, std::pair<int, int>>> L(N);
	
	for (int i = 0; i < N; i++)
	{
		std::string S;
		int P;
		std::cin >> S >> P;
		data.first = S;
		data.second.first = -P;
		data.second.second = i + 1;
		L[i] = data;
	}

	std::sort(L.begin(), L.end());
	for (int i = 0; i < N; i++)
	{
		std::cout << L[i].second.second << std::endl;
	}

	return 0;
}

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

int main() {
    vector<int> abc(3);
    for (auto& e : abc) cin >> e;
    sort(begin(abc), end(abc));
    cout << (abc == vector<int> { 5, 5, 7 } ? "YES" : "NO") << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n;
  cin>>n;
  float sum=0;
  for(int i=0;i<n;i++)
  {
    float x;
    cin>>x;
    sum+=1/x;
  }
  cout<<1/sum;
  return 0;
}

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

int main() {
    int N;
    cin >> N;
    vector<int> A(N), B(N), C(N);
    for (int i = 0; i < N; i++) cin >> A[i];
    for (int i = 0; i < N; i++) cin >> B[i];
    for (int i = 0; i < N; i++) cin >> C[i];
    sort(A.begin(), A.end());
    sort(B.begin(), B.end());
    sort(C.begin(), C.end());

    long long res = 0;
    for (int i = 0; i < N; i++) {
        int b = B[i];
        int n_uppers = (int)(lower_bound(A.begin(), A.end(), b) - A.begin());
        int n_lowers = (int)(N - (upper_bound(C.begin(), C.end(), b) - C.begin()));

        res += (long long)n_uppers * n_lowers;
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 1408
using System;

namespace abc152_a
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] MN = Console.ReadLine().Split(" ");
            int N = int.Parse(MN[0]);
            int M = int.Parse(MN[1]);
            if(N == M)
            {
                Console.WriteLine("Yes");
                return;
            }
            Console.WriteLine("No");
        }
    }
}


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

int main() {
    int N, M, K;
    cin >> N >> M >> K;
    vector<long long> a(N + 1), b(M + 1);
    for (int i = 1; i <= N; i++) {
        int A;
        cin >> A;
        a[i] = A + a[i - 1];
    }
    for (int i = 1; i <= M; i++) {
        int B;
        cin >> B;
        b[i] = B + b[i - 1];
    }

    int j = M, ans = 0;
    for (int i = 0; i <= N; i++) {
        if (a[i] > K) break;
        while (b[j] > K - a[i]) j--;
        ans = max(ans, i + j);
    }

    cout << ans << endl;
}

Measured memory_bytes: 6424
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE BinaryLiterals #-}
{-# LANGUAGE MultiWayIf #-}
{-# LANGUAGE NumDecimals #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TupleSections #-}

import Control.Applicative
import Control.Arrow
import Control.Monad
import Control.Monad.ST

import Data.Char
import Data.List
import Data.Maybe

import qualified Data.ByteString.Char8 as B

import Data.Array.ST.Safe
import Data.STRef

import Debug.Trace
import Text.Printf

readInt = readLn :: IO Int
readInteger = readLn :: IO Integer
readInts = map ( fst . fromJust . B.readInt ) . B.words <$> B.getLine
readIntegers = map ( fst . fromJust . B.readInteger ) . B.words <$> B.getLine

which a b f = if f then a else b
mp [ a, b ] = ( a, b )

modifyArray a i f = writeArray a i =<< f <$> readArray a i

main = do
	[ n, r ] <- readInts
	print $ if n < 10
		then r + 100 * ( 10 - n )
		else r

Measured memory_bytes: 380
import math
import fractions
n = int(input())


l = list(map(int ,input().split()))

lc = 1

def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)


for i in range(n):
    lc = lcm(lc,l[i])
ans = 0
for i in range(n):
    ans+=lc//l[i]

print(ans%1000000007)


Measured memory_bytes: 6112
from collections import deque
def solve():  
    h, w = map(int,input().split())
    ch, cw = map(int,input().split())
    Dh, Dw = map(int,input().split())
    
    M = ['##' + input() + '##' for _ in range(h)]
    for i in range(2):
        M.insert(0,'#'*(w+4))
        M.append('#'*(w+4))
    
    INF = float('inf')
    cost = [[INF for _ in range(w+4)] for _ in range(h+4)]
    cost0 = deque()
    ans = -1
    
    cost0.append((ch+1, cw+1, 0))
    cost[ch+1][cw+1] = 0
    
    move = [(1,0),(0,1),(-1,0),(0,-1)]
    warp = [(i,j) for i in range(-2,3) for j in range(-2,3) if (i,j) not in [(0,0)] + move]
    
    cost1 = deque()
    
    while cost0:
        h, w, c = cost0.popleft()
        cost1.append((h, w, c))
        
        for i,j in move:
            dh = h + i
            dw = w + j
            if M[dh][dw] == '.' and c < cost[dh][dw]: #コストが高いところから低いところに戻らないようにするため
                cost[dh][dw] = c
                cost0.appendleft((dh, dw, cost[dh][dw]))
        
        if len(cost0) == 0:
            while cost1:
                h, w, c = cost1.popleft()
                for i,j in warp:
                    dh = h + i
                    dw = w + j
                    if M[dh][dw] == '.' and c+1 < cost[dh][dw]:  #無駄なワープをなくすため
                        cost[dh][dw] = c+1
                        cost0.append((dh, dw, cost[dh][dw]))
        if cost[Dh+1][Dw+1] != INF:
            ans = cost[Dh+1][Dw+1]
    
    print(ans)

if __name__ == "__main__":
    solve()
                    

Measured memory_bytes: 24620
from collections import deque
if __name__ == '__main__':

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

    rvflg = False

    d_st = deque()
    d_ed = deque()

    for _ in range(n):
        q = input()
        if len(q) == 1:
            if rvflg:
                rvflg = False
            else:
                rvflg = True
        else:
            i,f,c = map(str,q.split())
            if f == "1":#先頭に追加
                if rvflg:
                    #末尾に追加
                    d_ed.append(c)
                else:
                    #先頭に追加
                    d_st.appendleft(c)
            else:#末尾に追加
                if rvflg:
                    #先頭に追加
                    d_st.appendleft(c)
                else:
                    #末尾に追加
                    d_ed.append(c)

    ans = "".join(d_st) + s + "".join(d_ed)
    #最後に反転するかを決定
    if rvflg:
        ans = ans[::-1]
    print(ans)



Measured memory_bytes: 12348
#include <iostream>
#include <iomanip>
#include <cmath>
#include <vector>
#include <algorithm>

using namespace std;

struct dice {
	int face[6];
	int T;
	int S;
	int E;
};

int main(void) {
	dice d;
	for (int i = 0; i < 6; ++i) {
		cin >> d.face[i];
	}
	d.T = 0;
	d.S = 1;
	d.E = 2;

	string str;
	cin >> str;
	int temp;
	for (int i = 0; i < str.length(); ++i) {
		temp = d.T;
		switch (str[i]) {
			case 'E':
				d.T = 5-d.E;
				d.E = temp;
				break;
			
			case 'N':
				d.T = d.S;
				d.S = 5-temp;
				break;

			case 'S':
				d.T = 5-d.S;
				d.S = temp;
				break;

			case 'W':
				d.T = d.E;
				d.E = 5-temp;
				break;
		}
	}
	cout << d.face[d.T] << endl;
	return 0;
}



Measured memory_bytes: 3172
#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <utility>
#include <iomanip>  // std::setprecision()
using namespace std;
using ll = long long;
#define rep(i,a,b) for(ll i=(a); i<(b); i++)
#define YES cout << "YES" << endl;
#define NO cout << "NO" << endl;
#define yes cout << "Yes" << endl;
#define no cout << "No" << endl;
#define pai 3.14159265358979323846
ll gcd(ll a, ll b){if (a%b == 0)  return(b);else  return(gcd(b, a%b));}
ll lcm(ll a, ll b){return a * b / gcd(a, b);}
/* map<string,int> */
/* 大文字を小文字に変換 tolower*/
/* 小文字を大文字に変換 toupper*/
/* 辞書順 next_permutation(a.begin(),a.end()) */
 
int main() {
    ll k;
    cin >> k;
    if (k %2 ==0) {
        cout << -1 << endl;
        return 0;
    }
    ll s =0;
    for (int i =0; i< pow(10,6) +1;i++) {
        s *= 10;
        s += 7;
        s %= k;
        if (s == 0) {
            cout << i+1 << endl;
            return 0;
        }
    }
    cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 3156
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) (x).begin(),(x).end()
using ll = long long;
using P = pair<int,int>;
 
 
 
int main() {
	
	
	int n; cin >> n;
	int num = 7;
	
	rep(i,n+1){
		num %= n;
		if(num == 0){
			cout << i+1 << endl;
			return 0;
		}
		else{
			int num_copy = num * 10 + 7;
			if(num_copy % n == num){
				cout << "-1" << endl;
				return 0;
			}
			else num = num_copy;
		}
	}
    cout << "-1\n";
    return 0;
	return 0;
}

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

long int max(long int a,long int b){
  if(a > b){
    return a;
  }else{
    return b;
  }
}

int main(){
  int N,W;
  scanf("%d%d",&N,&W);
  long int w[N+1],v[N+1];
  for(int i = 1;i <= N;i++){
    scanf("%ld%ld",&w[i],&v[i]);
  }
  long int V[N+1][W+1];
  for(int i = 0;i <= W;i++){
    V[0][i] = 0;
  }
  for(int i = 0;i <= N;i++){
    V[i][0] = 0;
  }
  
  for(int i = 1;i <= N;i++){
    for(int j = 1;j <= W;j++){
      if(w[i] <= j){
        V[i][j] = max(V[i-1][j-w[i]] + v[i],V[i-1][j]);
      }else{
        V[i][j] = V[i-1][j];
      }
    }
  }
  printf("%ld\n",V[N][W]);
  return 0;
}


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

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

    llu ans = 1;
    for (llu i = 1; i < n; i++) {
        if ((llu)(i * i) <= (llu)n) {
            ans = (llu)(i * i);
        }
        else 
            break;
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MAX = 200'001;
ll a[MAX], dp[MAX], ans[MAX];
vector<ll> adj[MAX];
void go(ll now, ll prev, ll dep) {
	dp[dep] = 1e9;
	ll p = (ll)(lower_bound(dp+1, dp+1+dep,a[now])-dp);
	ll tmp = dp[p];
	dp[p] = a[now];
	ans[now] = (ll)(lower_bound(dp+1, dp+1+dep, 1e9)-dp-1);
	for (ll next : adj[now]) {
		if (next == prev) continue;
		go(next, now, dep+1);
	}
	dp[p] = tmp;
}

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

    ll N; cin >> N;
    for (ll i = 1; i <= N; i++) {
    	cin >> a[i];
    }
    for (ll i = 1; i < N; i++) {
    	ll u, v; cin >> u >> v;
    	adj[u].push_back(v);
    	adj[v].push_back(u);
    }
    go(1,0,1);
    for (ll i = 1; i <= N; i++) {
    	cout << ans[i] << '\n';
    }
}

Measured memory_bytes: 33444
#include <iostream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <cassert>
#include <string>
#include <memory.h>
#include <queue>
#include <cstdio>
#include <cstdlib>
#include <set>
#include <map>
#include <cctype>
#include <iomanip>
#include <sstream>
#include <cctype>
#include <fstream>
#include <cmath>
using namespace std;

#define REP2(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define REP(i, n) REP2(i, 0, n)
#define ALL(c) (c).begin(), (c).end()
#define ITER(c) __typeof((c).begin())
#define PB(e) push_back(e)
#define FOREACH(i, c) for(ITER(c) i = (c).begin(); i != (c).end(); ++i)
#define MP(a, b) make_pair(a, b)
#define PARITY(n) ((n) & 1)

typedef long long ll;
typedef pair<ll, ll> P;
const int INF = 1000 * 1000 * 1000 + 7;
const double EPS = 1e-10;

bool live(vector<vector<int> > S, int sr, int sc){
  if(S[sr][sc] == 0) return true;
  int n = S.size();
  int color = S[sr][sc];
  int dr[6] = {-1, -1, 0, 0, 1, 1};
  int dc[6] = {-1, 0, -1, 1, 0, 1};

  queue<int> rs, cs;
  rs.push(sr);
  cs.push(sc);
  while(!rs.empty()){
    int r = rs.front(); rs.pop();
    int c = cs.front(); cs.pop();
    if(S[r][c] == 0) return true;
    S[r][c] = -1;
    
    REP(i, 6){
      int r2 = r + dr[i];
      int c2 = c + dc[i];
      if(0 <= r2 && r2 < n && 0 <= c2 &&c2 < n){
        if(S[r2][c2] == color || S[r2][c2] == 0){
          rs.push(r2);
          cs.push(c2);
        }
      }
    }
  }
    
  return false;
  
}

vector<vector<int> > calc(const vector<vector<int> > &S){
  int n = S.size();
  vector<vector<int> > R(n, vector<int>(n, 0));
  REP(i, n)REP(j, i + 1)  R[i][j] = !live(S, i, j);
  return R;
}

int main(){
  int n, c;
  while(cin >> n >> c && n + c){
    vector<vector<int> > S(n, vector<int>(n, -1));

    int best = -INF;
    REP(i, n)REP(j, i + 1) cin >> S[i][j];
    REP(i, n)REP(j, i + 1){
      if(S[i][j] == 0){
        S[i][j] = c;

        int score = 0;
        vector<vector<int> > R = calc(S);
        REP(k, n)REP(l, k + 1){
          if(R[k][l]){
            score += (S[k][l] == c ? -1 : 1);
          }
        }
        best = max(best, score);
        
        S[i][j] = 0;
      }
    }

    cout << best << endl;
  }
  return 0;
}

Measured memory_bytes: 1224
from collections import defaultdict

S = input()
T = input()

dictS = defaultdict(int)
dictT = defaultdict(int)
dictS[S[0]] = dictT[T[0]] = 1
n = 2

for i in range(1, len(S)):
    if dictS[S[i]] == dictT[T[i]]:
        if dictS[S[i]] == 0:
            dictS[S[i]] = dictT[T[i]] = n
            n += 1
    else:
        print('No')
        break
else:
    print('Yes')

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

vector<ll>par(2e5+10);
void init(ll n) {
  for(ll i=0;i<n;i++) {
    par[i]=i;
  }
}

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

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

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

int main() {
  ll n,m;
  cin >> n >> m;
  vector<pll> v(m);
  for(ll i=0;i<m;i++) {
    ll a,b;
    cin >> a >> b;
    v[i]=pll(a,b);
  }
  ll ans=0;
  for(ll i=0;i<m;i++) {
    init(n+1);
    for(ll j=0;j<m;j++) {
      if(j==i) continue;
      unite(v[j].first,v[j].second);
    }
    set<ll> check;
    for(ll i=0;i<n;i++) {
      check.insert(root(i+1));
    }
    if(check.size()!=1) {
      ans++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define ll long long int
#define vll vector<ll>
using namespace std;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    ll n, k, a;
    cin >> k >> n;
    vll x;
    
    for(ll i=0; i<n; i++){
        cin >> a;
        x.push_back(a);
    }
    ll ans = 0;
    for(ll i=0; i<n; i++){
        ans += x[i];
    }
    
    if(k < ans){
        cout << -1 << endl;
    }
    else{
        cout << k - ans << endl;
    }
    return 0;
}

Measured memory_bytes: 3764