akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#include<iostream>
#include<queue>
#include<string>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<cstring>
#include<iomanip>
#include<cstdlib>
#include<ctime>
#include<set>
#include<map>
#include<utility>
#include<vector>
#include<stack>
#include<sstream>
#include<algorithm>
using namespace std;
/****************************/
#define ll long long
#define vi vector<int>
#define pii pair<int,int>
#define vpii vector<pair<int,int> >
#define qi queue<int>
#define mii map<int,int>
#define msi map<string,int>
/****************************/
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rep2(i,n) for(ll i=(n)-1;i>=0;i--)
#define rep3(i,a,n) for(ll i=(a);i<(n);i++)
#define mp make_pair
#define pb push_back
#define st first
#define nd second
#define pi 3.1415926535897932384626433832795
#define zero(n) memset(n,0,sizeof(n));
#define SZ(n) n.size()
#define ss st.st
#define sn st.nd 
#define mod 1000000007
/****************************/
using namespace std;
int n;
ll ans;
int main()
{
	cin>>n;
	ans=1;
	rep(i,n)
	{
		ans*=10;
		ans%=mod;
	}
	ll ans1=1;
	rep(i,n)
	{
		ans1*=9;
		ans1%=mod;
	}
	ll ans2=1;
	rep(i,n)
	{
		ans2*=8;
		ans2%=mod;
	}
	ans-=2*ans1;
	if(ans<0)
	{
		while(ans<0) ans+=mod;
	}
	ans%=mod;
	ans+=ans2;
	ans%=mod;
	cout<<ans;
	return 0;
}

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

using namespace std;

#define endl '\n'
#define ll long long
#define int long long
const int32_t INFint = 1e9;
const ll INFll = 1e18;
const ll INF = 1LL << 60;
#define MOD 1000000007ll
#define fast                      \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);                   \
    cout.tie(0);

#define vi vector<int>
#define pii pair<int, int>
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define foreach(it, v) for (__typeof((v).begin()) it = (v).begin(); it != (v).end(); it++)

#define deb1(x) cout << #x << ": " << x << endl
#define deb2(x, y) cout << #x << ": " << x << " | " << #y << ": " << y << endl
#define deb3(x, y, z) cout << #x << ":" << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl
#define deb4(a, b, c, d) cout << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl
#define deb5(a, b, c, d, e) cout << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl
#define deb6(a, b, c, d, e, f) cout << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl
#define nl cout << endl
// void bfs(vector<int> & dist , vector< vector<int> > & edges , int index )
// {
//     queue< pair<int,int> > q ;
//     dist[index] = -1 ; 
//     q.push(mp(index,0)) ;
//     while(!q.empty())
//     {
//         pair<int,int> top = q.front() ;
//         // deb2(top.ff,top.ss); 
//         q.pop() ; 
//         if(dist[top.ff] != -1 )
//             continue ;
//         // deb3(top.ff,top.ss,dist[top.ff]) ;
//         dist[top.ff] = top.ss ;
//         for(int i = 0 ; i < edges[top.ff].size(); i++ )
//         {
//             if (dist[edges[top.ff][i]] == -1)
//             {
//                 q.push(mp(edges[top.ff][i],dist[top.ff]+1));
//             }
//         }
//     } 
// }
int32_t main()
{
    fast;
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
    int t;
    cin >> t;
    long double circ = 2.0 * t * M_PI ;
    cout<<circ<<endl;
}

Measured memory_bytes: 3788
#include <iostream>
#include <string>
#include <math.h>
#include <iomanip>
#include <cmath>

using namespace std;

int main()
{
    int x,a,b;
    cin>>x>>a>>b;
    if (abs(x-a)<abs(x-b))
    {
        cout<<"A"<<endl;
    }
    else
    {
        cout<<"B"<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
N = int(input())
s = input()
s += s[0]

def main():
  # S: 1, W: 0
  for a0, a1 in ((0, 0), (0, 1), (1, 0), (1, 1)):
    l = [a0, a1]

    for c in s[1:]:
      if c == 'o':
        a0, a1 = a1, not (a0 ^ a1)
      else:
        a0, a1 = a1, (a0 ^ a1)
      l.append(a1)

    if (l[0] == l[-2]) and (l[1] == l[-1]):
      print(''.join('S' if i == 1 else 'W' for i in l[:-2]))
      exit()

  print(-1)

if __name__ == '__main__':
  main()

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

string S,T;

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>S;
	T=S;
	reverse(ALL(T));
	FORR(c,T) {
		if(c=='p') c='q';
		else if(c=='q') c='p';
		else if(c=='b') c='d';
		else if(c=='d') c='b';
	}
	
	if(S==T) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n';
	FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	solve(); return 0;
}


Measured memory_bytes: 512
#include<iostream>
#include<string>
#include<algorithm>
#include<bits/stdc++.h>
 
using namespace std;


int MOD=1000000007;

int main(void){
    long long N,ans=0;
    cin >> N;
    for(long long i=1; i<N; i++){
        ans+=i;
    }
    cout << ans << endl;
}




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

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

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

    sort(A.begin(), A.end());

    int d1 = A[2] - A[0];
    int d2 = A[2] - A[1];

    int ans = 0;
    if(d1 % 2 == d2 % 2){
        ans = (d1 + d2) / 2;
    }else{
        ans++;
        ans += (d1 + d2 + 1) / 2;
    }

    cout << ans << endl;

    return 0;
}

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

int main(void){
    double a, b, c, d, e, f, x=0, y=0;
    double unit = 1000.0;
    while((scanf("%lf %lf %lf %lf %lf %lf",&a, &b, &c, &d, &e, &f)) !=EOF){
        if(a*e != b*d){
            x = ( e*c - b*f ) / ( a*e - b*d );
            y = ( a*f - d*c ) / ( a*e - b*d );
        }
        else{
            
        }
        x *= unit; y *= unit;
        x = round(x); y = round(y);
        x /= unit; y /= unit;
        
        if(x == -0.0)
            x = 0.0;
        if(y == -0.0)
            y = 0.0;
        
        printf("%.3f %.3f\n",x, y);
        
    }
    
    return 0;
}

Measured memory_bytes: 664
import java.util.Scanner;

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

        while (sc.hasNext()) {
            int weight = Integer.parseInt(sc.next());

            boolean flag = false;
            for (int i = 1; i <= 512; i <<= 1) {
                if ((weight & i) == i) {
                    if (!flag) {
                        flag = true;
                    } else {
                        System.out.printf(" ");
                    }
                    System.out.print(i);
                }
            }
            System.out.println();
        }
    }
}

Measured memory_bytes: 26276
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Main {

    public static void main(String[] args) throws Exception {

        try {

            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

            String intputString = br.readLine();

            System.out.println(intputString.replaceAll(",", " "));

        } catch (IOException | NumberFormatException e) {
            e.printStackTrace();
            System.exit(0);
        } catch (final Exception e) {
            e.printStackTrace();
            System.exit(0);
        }
    }
}

Measured memory_bytes: 21204
#include<iostream>

int main()
{
    int A,B,C;
    int res;
    std::cin>>A>>B>>C;

    if(A>=B && A>=C)
        res = 10*A+B+C;
    else if(B>=C)
        res = 10*B +A +C;
    else
        res = 10*C+A+B;
    std :: cout << res <<std:: endl;
    return 0;

}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main()
{
    // 文字列2つの入力
    char s[11], t[11], u[11];
    scanf("%s %s",s, t);
    int a,b;
    // スペース区切りの整数の入力
    scanf("%d %d",&a,&b);
    // 文字列の入力
    scanf("%s",u);
    if (strcmp(s, u) == 0) {
        a--;
    } else {
        b--;
    }
    // 出力
    printf("%d %d\n",a, b);
    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <random>
#include <iomanip>
#include <cassert>
#include <complex>
#include <functional>
 
using namespace std;
 
typedef long long ll;

int main() {
  ios_base::sync_with_stdio(false); cin.tie(0);
#ifdef LOCAL
  freopen("input.txt", "r", stdin);
#endif
  int n;
  cin >> n;
  vector <pair <string, int>> a;
  for (int i = 0; i < n; ++i) {
    string s; int t;
    cin >> s >> t;
    a.push_back({s, t});
  }
  string want;
  cin >> want;
  bool fnd = false;
  int ans = 0;
  for (int i = 0; i < n; ++i) {
    if (fnd) {
      ans += a[i].second;
    }
    if (a[i].first == want) {
      fnd = true;
    }
  }
  cout << ans << '\n';
}


Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
#define swap(a,b) a^=b^=a^=b

int main(){
	
	int N, a, b, c, i;
	
	scanf("%d", &N);
	
	for(i=0; i<N; i++){
		scanf("%d %d %d", &a, &b, &c);
		
		if(c == sqrt(a*a+b*b) || b == sqrt(c*c+a*a) || a == sqrt(b*b+c*c)){
			printf("YES\n");
		} else printf("NO\n");
		
	}
	
	return 0;
}

Measured memory_bytes: 580
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const int INF=1e9;

int cnt[2001][2001];

int main(){
    int n,k;
    cin>>n>>k;
    for(int i=0;i<n;i++){
        int x,y;
        char c;
        cin>>x>>y>>c;
        if(c=='W')cnt[(x+k)%(2*k)+1][y%(2*k)+1]++;
        else cnt[x%(2*k)+1][y%(2*k)+1]++;
    }
    for(int i=0;i<2*k;i++){
        for(int j=0;j<2*k;j++){
            cnt[i+1][j+1]+=cnt[i][j+1]+cnt[i+1][j]-cnt[i][j];
        }
    }
    int ans=0;
    for(int i=0;i<k;i++){
        for(int j=0;j<k;j++){
            int s=0;
            s+=cnt[i][j+k]-cnt[i][j];
            s+=cnt[i+k][j]-cnt[i][j];
            s+=cnt[2*k][j+k]-cnt[i+k][j+k]-cnt[2*k][j]+cnt[i+k][j];
            s+=cnt[i+k][2*k]-cnt[i+k][j+k]-cnt[i][2*k]+cnt[i][j+k];
            ans=max({ans,s,n-s});
        }
    }
    cout<<ans<<endl;
}


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

using namespace std;
using ll = long long;

//container util
#define SORT(c) sort((c).begin(),(c).end())

//repetition
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

const int INF = 1e9;

int main(void){

	string S; cin >> S;
	REP(i,S.length()) cout << 'x';
	cout << endl;
	


	return 0;

}


Measured memory_bytes: 256
N = int(input())

S = {}

for i in range(N):
    s = input()

    if s not in S:
        S[s] = 1
    else:
        S[s] += 1
maxNum = 0
Smx = []
for s in S:
    if maxNum == S[s]:
       Smx.append(s)
    elif maxNum < S[s]:
        maxNum = S[s]
        Smx = [s]

for s in sorted(Smx):
    print(s)

Measured memory_bytes: 32988
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef vector<LL> VI;
typedef vector<VI> VVI;
typedef pair<LL, LL> PII;
typedef vector<string> VS;
inline LL toInt(string s) {LL v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
#define PB push_back
#define MP make_pair
#define SZ(a) LL((a).size())
#define EACH(x,c) for(auto x: (c))
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define ALL(c) (c).begin(), (c).end()
#define REVERSE(c) reverse(ALL(c))
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort((c).rbegin(),(c).rend())
#define STABLE_SORT(c) stable_sort(ALL(c))
#define STABLE_RSORT(c) stable_sort((c).rbegin(),(c).rend())
#define UNIQUE(c) SORT(c); (c).erase(unique(ALL(c)), (c).end());
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
const double INF = 1e7;
const double EPS = 1e-10;
const double PI  = acos(-1.0);
#define dump(x)  cerr << #x << " = " << (x) << endl;


int main() {
	VI X(5);
	LL k;
	REP(i, 5) {
		cin >> X[i];
	}
	cin >> k;
	SORT(X);
	if (X[4] - X[0] <= k) {
		cout << "Yay!\n";
	} else {
		cout << ":(\n";
	}
	
    return 0;
}


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

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())

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

const double PI=3.14159265358979323846;

int mod = 1e9+7;

struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
 
  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};



int main(){
  int N;
  cin >> N;
  int zero = 0;
  map<LP, P> mp;
  rep(_, N){
    ll x, y;
    cin >> x >> y;
    if(x==0 && y==0){
      zero++;
      continue;
    }
    ll g = gcd(x, y);
    x /= g;
    y /= g;
    if(y<0){
      x = -x;
      y = -y;
    }
    if(y==0 && (x<=0)){
      x = -x;
      y = -y;
    }
    bool rot90 = (x<=0);
    if(rot90){
      ll tmp = x;
      x = y;
      y = -tmp;
    }

    if(rot90){
      mp[{x, y}].first++;
    }else{
      mp[{x, y}].second++;
    }
  }

  mint ans = 1;
  for(auto p: mp){
    int s = p.second.first;
    int t = p.second.second;

    mint now = 1;
    now += mint(2).pow(s)-1;
    now += mint(2).pow(t)-1;
    ans *= now;
  }
  ans -= 1;

  ans += zero;
  cout << ans.x << endl;
  return 0;
}


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

int GetDigits(int num) {
    int digit = 0;
    while(num != 0) {
        num /= 10;
        digit++;
    }
    return digit;
}

int main() {
    long long N;
    cin >> N;
    int ans = 10000000001;
    for (int A=1; A<=sqrt(N); A++) {
        if (N % A == 0) {
            int B = N / A;
            int F = max(GetDigits(A), GetDigits(B));
            ans = min(ans, F);
        } else {
            continue;
        }
    }
    cout << ans << endl;
}


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



int main(){

  int n,m,Q;
  cin >> n >> m >> Q;
  vector<pair<int, int> > range;
  int l,r;
  rep(i,m){
    cin >> l >> r;
    l--;r--;
    range.pb(mp(l,r));
  }
  int p[Q],q[Q];
  rep(i,Q){
    cin >> p[i]  >> q[i];
    p[i]--;q[i]--;
  }

  sort(range.begin(), range.end());
  int s[m],e[m];
  rep(i,m){
    s[i]=range[i].first;
    e[i]=range[i].second;
  }
  int dp[n][n];
  rep(i,n) rep(j,n) dp[i][j]=0;
  rep(i,n){
    //    dp[i][i]=0;
    int si = lower_bound(s, s+m, i) -s;
    int usi = upper_bound(s,s+m, i) -s;
    if(si==usi) continue;
    for(int j=i; j<=n-1; j++){
      dp[i][j] = upper_bound(e+si, e+usi,j) - lower_bound(e+si, e+usi,j);    
      //      cout << i << " " << j << " " << dp[i][j] << endl;
    }
  }
  int ans[n][n];
  rep(li,n){
    for(int ri=li; ri<=n-1; ri++){
      ans[li][ri]=0;
      for(int lli=li; lli<=ri; lli++){
	for(int rri=lli; rri<=ri; rri++){
	  ans[li][ri]+=dp[lli][rri];
	}
      }
    }
  }
  rep(i,Q){
    cout << ans[p[i]][q[i]] << endl;
  }
  
  
  return 0;

}


Measured memory_bytes: 6896
//coloring colorfully
#include <iostream>
using namespace std;
int main(int argc, char const *argv[])
{
	string s;
	cin >> s;
	int zo = 0,oz = 0;
	for (int i = 0; i < s.length(); ++i)
	{
		if (i%2 == 0)
		{
			if (s[i] == '1')
			{
				zo++;
			}
			else if (s[i] == '0')
			{
				oz++;
			}
		}
		else
		{
			if (s[i] == '1')
			{
				oz++;
			}
			else if (s[i] == '0')
			{
				zo++;
			}
		}
	}
	if (zo < oz)
	{
		cout << zo << endl;
	}
	else
	{
		cout << oz << endl;
	}
	return 0;
}

Measured memory_bytes: 512
s=list(input())
a=0
t='?'
ch=0
l=len(s)
for i in range(l):
    if ch==1:
        ch=0
        continue
    if s[i]!=t:
        a+=1
        t=s[i]
    else:
        if i<l-1:
            t=s[i]+s[i+1]
            a+=1
            ch=1
print(a)


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

int main(void){
    int a, b, theta=90;
    double x=0.0, y=0.0;
    double PI=3.14159265358;
    while(scanf("%d,%d",&a, &b)!=EOF){
        if(a+b==0) break;
        x+=(double)a*cos(theta*PI/180);
        y+=(double)a*sin(theta*PI/180);
        theta-=b;
    }
    cout << (int)x << "\n" << (int)y << "\n";
}



Measured memory_bytes: 3292
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	int ar[n+1]={0};
	for (int i=0;i<n-1;i++)
	{
		int tmp;
		cin>>tmp;
		ar[tmp]++;
	}
	for(int i=1;i<n+1;i++)
	cout<<ar[i]<<endl;
}

Measured memory_bytes: 4416
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from itertools import permutations, accumulate, combinations, combinations_with_replacement
from math import sqrt, ceil, floor, factorial
from bisect import bisect_left, bisect_right, insort_left, insort_right
from copy import deepcopy
from operator import itemgetter
from functools import reduce
from fractions import gcd
import sys
def input(): return sys.stdin.readline().rstrip()
def I(): return int(input())
def Is(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def TI(): return tuple(map(int, input().split()))
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def TIR(n): return [TI() for _ in range(n)]
def S(): return input()
def Ss(): return input().split()
def LS(): return list(input())
def SR(n): return [S() for _ in range(n)]
def SsR(n): return [Ss() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
sys.setrecursionlimit(10**6)
MOD = 10**9+7
INF = 10**18
# ----------------------------------------------------------- #

n, m = Is()
KA = LIR(n)
A = []
for i in range(n):
    A.append(set(KA[i][1:]))
ans = 0
for i in range(1, m+1):
    for j in range(n):
        if i not in A[j]:
            break
    else:
        ans += 1
print(ans)


Measured memory_bytes: 64108
N = int(input())
s_list = []
for _ in range(N):
  s_list.append(''.join(sorted(list(input()))))

from collections import Counter
c = Counter(s_list)

ans = 0
for k, v in Counter(c.values()).items():
    ans += (k*(k-1)) / 2 * v
print(int(ans))

Measured memory_bytes: 19760
# -*- coding: utf-8 -*-
import math
# 整数の入力
n, k = map(int, input().split())
# 計算
count = 0
max = 0
min = 0

for i in range(k):
    min += i
    max += n-i
# print(min, max)
for i in range(k, n+2):
    count += max - min + 1
    min += i
    max += n-i
    # print(count)
    # print(min, max)

print(count%(10**9+7))

Measured memory_bytes: 9044
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
using namespace std;

//N以下の素数列挙。O(N log log N)
int N = 101000;
set<int> primes;
vector<bool> is_prime(N + 1, true);
void init() {
        is_prime[0] = is_prime[1] = false;
        for (int i = 2; i <= N; i ++) {
                if (is_prime[i]) {
                        primes.insert(i);
                        for (int j = i + i; j <= N; j += i) is_prime[j] = false;
                }
        }
}

int main() {
        init();
        vector<int> ok(101000, 0);
        for (int i = 1; i <= 100000; i ++) {
                if (i & 1) {
                        if (primes.count(i) && primes.count((i + 1) / 2)) ok[i] = 1;
                }
        }
        for (int i = 1; i <= 100000; i ++) {
                ok[i] += ok[i - 1];
        }
        int q;
        scanf("%d", &q);
        while (q --) {
                int l, r;
                scanf("%d%d", &l, &r);
                printf("%d\n", ok[r] - ok[l - 1]);
        }
        return 0;
}



Measured memory_bytes: 1536
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <math.h>
using namespace std;

#define ll long long int
#define MOD 1000000007
#define INF 1e9 + 1
#define fast ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define vi vector<int>
#define vl vector<long>
#define vll vector<long long>
#define pb push_back


void lcs_dpBU(string a, string b, int n, int m) {

    int dp[n+1][m+1];
    for(int i = 0; i <= m; i++) dp[0][i] = 0;
    for(int i = 0; i <= n; i++) dp[i][0] = 0;
    
    for(int i = 1; i <= n; i++) {
        for(int j = 1; j <= m; j++) {
            if(a[i-1] == b[j-1]) dp[i][j] = 1 + dp[i-1][j-1];
            else dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
        }
    }

    //code to print the longest subseq itself
    int index = dp[n][m];

    char ans[index+1];

    ans[index] = '\0';

    int i = n, j = m;
    while(i > 0 && j > 0) {

        if(a[i-1] == b[j-1]) {
            ans[index - 1] = a[i-1];
            i--; j--;index--;
        }

        else if(dp[i-1][j] > dp[i][j-1]) {
            i--;
        }
        else {
            j--;
        }

    }

    cout<<ans<<"\n";

  
}


int main() {
	fast
	int t=1;
// 	cin>>t;
	while(t--) {
        string a,b;
        cin>>a>>b;
        int n = a.length();
        int m = b.length();
       lcs_dpBU(a,b,n,m);

	}
	return 0;
}

Measured memory_bytes: 35456
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <stdbool.h>
#define LL long long
#define INF 1<<31-1
#define MIN(x,y) ((x)<(y)?(x):(y))
#define MAX(x,y) ((x)<(y)?(y):(x))
#define FOR(i,a,n) for(i=a;i<n;i++)
#define MOD 1000000007
#define NUM 100001

void swap(int* a,int* b){int tmp=*a;*a=*b;*b=tmp;}
int GCD(int a,int b){int c=1,tmp=MAX(a,b);b=MIN(a,b);a=tmp;while(c!=0){c=a%b;a=b;b=c;}return a;}
int LCM(int a,int b){return a*b/GCD(a,b);}
int POW(LL a,LL n){LL ans=1;while(n>0){if(n&1)ans=ans*a%MOD;a=a*a%MOD;n>>=1;}return (int)ans;}
int icmp(const void* a,const void* b){return *(int*)a-*(int*)b;}
int ccmp(const void* a,const void* b){return *(char*)a-*(char*)b;}
int scmp(const void* a,const void* b){return strcmp(*(char**)a,*(char**)b);}
LL fac[NUM],finv[NUM],inv[NUM];
void comi(){int i;fac[0]=fac[1]=1;finv[0]=finv[1]=1;inv[1]=1;FOR(i,2,NUM){fac[i]=fac[i-1]*i%MOD;inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;finv[i]=finv[i-1]*inv[i]%MOD;}}
int com(int n,int k){if(n<k||n<0||k<0)return 0;return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;}

typedef struct{int s,e,c;}Edge;
int par[NUM];
int UF(){for(int i=0;i<NUM;i++)par[i]=-1;}
int Root(int x){if(par[x]<0)return x;else return par[x]=Root(par[x]);}
int Size(int x){return -par[Root(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){if(Size(x)<Size(y))swap(&x,&y);par[x]+=par[y];par[y]=x;}}


int main(){
	UF();
  int N,M,i,ans=0;
  scanf("%d%d",&N,&M);
	int X[M],Y[M],Z[M],flag[N];
	FOR(i,0,M)scanf("%d%d%d",&X[i],&Y[i],&Z[i]);
	FOR(i,0,M){
		X[i]--;Y[i]--;
		Unite(X[i],Y[i]);
	}
	FOR(i,0,N)flag[i]=0;
	FOR(i,0,N)if(flag[Root(i)]==0){
		flag[Root(i)]=1;
		ans++;
	}
	
  printf("%d\n",ans);
	return 0;
}


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

#define INF 1000000000
#define MAX_V 102

// ?????°: ??£??\??????, ????????°
int prim(int adjmatrix[MAX_V][MAX_V], int v){
  // ?????§???????????????????????¨?????§???????°??????????
  int mincost[v];
  // ??????i?????¨????????????????????????
  bool used[v];

  // ?????????
  for(int i = 0; i < v; i++){
    mincost[i] = INF;
    used[i] = false; 
  }
  mincost[0] = 0;
  int length = 0;

  while(true){
    // ??¨????±??????????????????????????????¨?????§?????????????????????????°?????????????????????¢???
    // newmember???????¬??????¨????????????????£??????????(-1??§?????????)
    int newmember = -1;
    for(int u = 0; u < v; u++){
      // if(???u???????????¨???????±?????????????????????? && ?????¶???????£??????????u?????¨?????????){ u???????£??????????; }
      if(!used[u] && (newmember == -1 || mincost[u] < mincost[newmember])){ newmember = u; }
    }

    // ????????????????????£??????newmember???-1??¨???????????¨???
    // ???????????????????????¨???????±???????????????¨???????????¨????????§?????¢?´¢??????
    if(newmember == -1){ break; }
    
    // ???newmember?????¨?????????
    used[newmember] = true;
    length += mincost[newmember];

    // ??¨?????§???????°??????????????¨?????????´???
    // ??°?????????newmember?????¨???????±????????????¨????????£????????§???????????§???????°???¨???newmember?????§??????????????¢???????????????????????°??????
    for(int u = 0; u < v; u++){
      mincost[u] = min(mincost[u], adjmatrix[newmember][u]);
    }
  }
  
  return length;
}


int main(void){
  
  while(true){
    // ???????????°??¨???????????°???????????????
    int n, m;
    cin >> n;
    if(n == 0){ break; }
    cin >> m;
    
    // ??£??\???????????£?¨???¨?????????
    int adjmatrix[MAX_V][MAX_V];
    for(int i = 0; i < MAX_V; i++){
      for(int j = 0; j < MAX_V; j++){
        adjmatrix[i][j] = INF;
      }
    }

    // ???????????±????????????????????£??\???????????????
    for(int i = 0; i < m; i++){
      int a, b, d;
      scanf("%d,%d,%d", &a, &b, &d);
      adjmatrix[a][b] = d;
      adjmatrix[b][a] = d;
    }
  
    // ????°???¨?????¨????????????????±???????
    int length = prim(adjmatrix, n);

    // ???????????????
    cout << length / 100 - n + 1 << endl;
  }

  return 0;
}

Measured memory_bytes: 1284
N, X = gets.split.map(&:to_i)
l = gets.split.map(&:to_i)

1.upto(N-1) do |i|
  l[i] = l[i - 1] + l[i]
end

count = 1

0.upto(X) do |i|
  if l.include?(i)
    count += 1
  end
end

puts count

Measured memory_bytes: 1788
#include <stdio.h>
int main()
{
int A,B,max=0,i=0,t=0 ;
scanf("%d %d",&A,&B);
for(i=0;i<2;i++)
{
if(A>B)
{
t=A;
A=A-1;
}
else
{
t=B;
B=B-1;
}
max=max+t;
}
printf("%d\n",max);

return 0;
}

Measured memory_bytes: 128
from itertools import accumulate

def divisor(n):
    ass = []
    for i in range(1,int(n**0.5)+1):
        if n%i == 0:
            ass.append(i)
            if i**2 == n:
                continue
            ass.append(n//i)
    return sorted(ass, reverse=True)

n,k = map(int, input().split())
a = list(map(int, input().split()))
div = divisor(sum(a))

for x in div:
    r = sorted([i%x for i in a])
    sr = sum(r)
    if sr == 0:
        print(x)
        exit()
    cr = list(accumulate(r))
    for i, j in enumerate(cr):
        if j == x*(n-i-1) - (sr-j) and j <= k:
            print(x)
            exit()

Measured memory_bytes: 42988
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <chrono>
#include <climits>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;

template <class T1, class T2>
ostream& operator << (ostream& out, const pair <T1, T2> p)
{
	out << '(' << p.first << ',' << p.second << ')';
	return out;
}

template <class T1, class T2>
istream& operator >> (istream& in, pair<T1, T2> &p)
{
	in >> p.first >> p.second;
	return in;
}

template <class T>
istream& operator >> (istream& in, vector<T> &v)
{
	for (T &x : v)
		in >> x;
	return in;
}

template <class T>
ostream& operator << (ostream& out, const vector<vector<T>> &v)
{
	for (const vector<T> &x : v)
		out << x << '\n';
	return out;
}

template <class T>
ostream& operator << (ostream& out, const vector<T> &v)
{
	for (const T &x : v)
		out << x << ' ';
	return out;
}

long long gcd (long long a, long long b)
{
	if (b > a)
		swap(a, b);
	return (b ? gcd(b, a % b) : a);
}

using ll   = long long;
using pii  = pair<int, int>;
using pll  = pair<long long, long long>;
using tiii = pair<pair<int, int>, int>;
using vi   = vector<int>;
using vl   = vector<long long>;
using vvi  = vector<vector<int>>;
using vvl  = vector<vector<long long>>;

#define F          first
#define S          second
#define First      first.first
#define Second     first.second
#define Third      second
#define mp         make_pair
#define rep(i,a,b) for (int i = (a); i < (b); i++)
#define per(i,b,a) for (int i = (b); i > (a); i--)
#define all(x)     x.begin(), x.end()
#define ret(x)     return cout << x, 0;
#define throwex    throw runtime_error ("Found the error.");

const int h = 1000000007;

signed main()
{
	ios::sync_with_stdio(false);
	#ifdef ONLINE_JUDGE
	cin.tie(nullptr);
	cout.tie(nullptr);
	cerr.setstate(ios::failbit);
	#endif

	int n, m, x;
	cin >> n >> m >> x;
	vvi a(n, vi(m));
	vi c(n);
	rep(i,0,n)
		cin >> c[i] >> a[i];
	int ans = INT_MAX;
	rep(i,0,(1 << n))
	{
		int z = 0;
		vi cur(m);
		int cost = 0;
		int mask = i;
		while(mask)
		{
			if(mask & 1)
			{
				rep(j,0,m)
					cur[j] += a[z][j];
				cost += c[z];
			}
			mask /= 2;
			z++;
		}
		bool y = true;
		for(auto f : cur)
			if(f < x)
				y = false;
		if(y)
			ans = min(ans, cost);
	}
	cout << (ans == INT_MAX ? -1 : ans);
}


Measured memory_bytes: 3660
n = int(input())

prime = []
table = [True] * (n + 1)

for i in range(2, n + 1):
    if not table[i]:
        continue
    k = i + i
    while k < n + 1:
        table[k] = False
        k += i

    prime.append(i)

ans = 1
for p in prime:
    k = 0
    for i in range(1, n + 1):
        v = i
        while v % p == 0:
            v //= p
            k += 1
    ans *= k + 1

print(ans % 1000000007)

Measured memory_bytes: 40304
import sys
def input(): return sys.stdin.readline().rstrip()
sys.setrecursionlimit(10 ** 7)
MOD = 998244353

N, S = map(int, input().split())
A = list(map(int, list(input().split())))

ans = 0
dp = [0]*(S+1)
for i in range(N):
    dp[0] += 1      # Lがiからを足す
    next_dp = [0]*(S+1)
    for j in range(S+1):
        next_dp[j] += dp[j]             # A[i]を選ばない
        next_dp[j] %= MOD
        if j+A[i]<=S:
            next_dp[j+A[i]] += dp[j]    # A[i]を選ぶ
            next_dp[j+A[i]] %= MOD
    dp = next_dp
    ans += dp[S]    # Rがiまでを足す
    ans %= MOD

print(ans)

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

void fnInput(int64_t& rnNum)
{
  cin >> rnNum;
}

int fnDigitsCheck(int64_t nDivisor)
{
  int nDigitCnt = 0;
  while (nDivisor)
  {
    nDigitCnt++;
    nDivisor /= 10;
  }

  return nDigitCnt;
}

int fnMultiplCheck(int64_t nNum)
{
  int nMinDigit = fnDigitsCheck(nNum);
                                           
  for (int64_t n = 2; n * n <= nNum; n++)  // int型 n では n * n が int型の範囲を
  {                                        // 超えて桁落ちが発生し 永久ループとなる
    if (nNum % n != 0)  continue;          // nNum の平方根を超えない整数 + 1 ～ nNum
    int64_t nOtr = nNum / n;               // で左記検査を行うと当然 TLE となる
    nMinDigit = min(nMinDigit, fnDigitsCheck(nOtr));
  }
  return nMinDigit;
}

int main()
{
  int64_t nNum;
  
  fnInput(nNum);
  cout << fnMultiplCheck(nNum) << endl;

  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 200000 + 100;

int main()
{
	string s;
	cin >> s;
	int len = s.size();
	LL sum = 0;
	for(int i = 0; i < len; i++)
		sum += s[i] - '0';
	if(sum % 9 == 0)
		cout << "Yes\n";
	else
		cout << "No\n";
	return 0;
}

Measured memory_bytes: 3720
#include <bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long

int32_t main()
{
	IOS;
	string s;
	cin >> s;
	int ans = 0;
	string prv = "";
	string cur = "";
	for(int i = 0; i < s.size(); i++)
	{
		cur += s[i];
		if(cur != prv)
		{
			prv = cur;
			cur = "";
			ans++;
		}
	}		
	cout << ans;
	return 0;
}

Measured memory_bytes: 720
using System;
using System.CodeDom.Compiler;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using System.Xml;

class Program
{
	static void Main(string[] args)
	{
		int[] intArray = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();
		int H = intArray[0];
		int A = intArray[1];

		int cnt = H / A;
		if(H % A != 0)
		{
			cnt++;
		}
		Console.WriteLine(cnt);
	}
}

//string s = Console.ReadLine();
//int[] intArray = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();
//int H = intArray[0];
//int W = intArray[1];
//int N = int.Parse(Console.ReadLine());

//Console.WriteLine(ans);
//Console.WriteLine("Yes");
//Console.WriteLine("No");
//Console.ReadKey();


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


int main(){
    ll N,cnt= 0;
    cin >> N;
    vector<ll> ans;
    queue<ll> que;

    que.push(3);
    que.push(5);
    que.push(7);
    char p[3] ={'3','5','7'};
    while(!que.empty()){
        ll v = que.front();
        que.pop();
        for(int i = 0; i < 3; i++){
            string tmp = to_string(v);
            tmp += p[i];
            if(stoll(tmp) <= N){
                que.push(stoll(tmp));
                ans.push_back(stoll(tmp));
            }
        }
    }

    for(int i = 0; i < ans.size(); i++){
        bool flag_3 = false;
        bool flag_5 = false;
        bool flag_7 = false;
        for(int j = 0; j < to_string(ans[i]).size(); j++){
            if(to_string(ans[i])[j] == '3') flag_3 = true;
            if(to_string(ans[i])[j] == '5') flag_5 = true;
            if(to_string(ans[i])[j] == '7') flag_7 = true;
        }
        if(flag_7 && flag_5 && flag_3){
            cnt++;
        }
    }
    
    cout << cnt << endl;
}





Measured memory_bytes: 768
// https://atcoder.jp/contests/abc122/tasks/abc122_b

#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>

using namespace std;

int main(){
  string s;
  cin >> s;
  int ans = 0;
  int cnt = 0;
  for(int i = 0; i < s.length(); i++){
    if(s[i] == 'A' || s[i] == 'C' || s[i] == 'G' || s[i] == 'T') cnt++;
    else cnt = 0;
    ans = max(ans, cnt);
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <stdio.h>
#include <set>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#include <memory.h>
#include <string>
#include <sstream>
#include <cstdlib>
#include <ctime>
#include <cassert>

using namespace std;

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

#define MP make_pair
#define PB push_back
#define FF first
#define SS second

#define FORN(i, n) for (int i = 0; i <  (int)(n); i++)
#define FOR1(i, n) for (int i = 1; i <= (int)(n); i++)
#define FORD(i, n) for (int i = (int)(n) - 1; i >= 0; i--)

#define DEBUG(X) { cout << #X << " = " << (X) << endl; }
#define PR0(A,n) { cout << #A << " = "; FORN(_,n) cout << A[_] << ' '; cout << endl; }

#define MOD 1000000007
#define INF 2000000000

int GLL(LL& x) {
    return scanf("%lld", &x);
}

int GI(int& x) {
    return scanf("%d", &x);
}

const int MAXL = 20;
const int MAXN = 100010;
LL pos[MAXN]; int pnext[MAXN][MAXL];

int n, q, a, b;

LL l;

bool check(int days) {
    int end = a;

    FORD(l, MAXL) {
        if (days & (1 << l)) end = pnext[end][l];
    }

    return end >= b;
}

int main() {
    GI(n); FOR1(i, n) GLL(pos[i]); GLL(l);

    int end = 1;

    FOR1(i, n) {
        while (end+1 <= n && pos[end+1] - pos[i] <= l) end++;
        pnext[i][0] = end;
    }

    for (int l = 1; l < MAXL; l++) {
        FOR1(i, n) {
            int pmid = pnext[i][l-1];
            pnext[i][l] = pnext[pmid][l-1];
        }
    }

    GI(q);

    while (q--) {
        GI(a); GI(b);
        if (a > b) swap(a, b);

        int lo = 1; int hi = MAXN; int res = -1;

        while (lo <= hi) {
            int mid = (lo + hi) / 2;

            if (check(mid)) {
                res = mid;
                hi = mid - 1;
            }
            else {
                lo = mid + 1;
            }
        }

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

    return 0;
}


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

using namespace std;

int N;
int result = 1;
int main()
{
  cin >> N;
  vector<int> height(N);
  for (int i = 0; i < N; i++)
  {
    cin >> height[i];
  }

  for (int i = 1; i < N; i++)
  {
    bool view = true;
    for (int j = i - 1; j >= 0; j--)
    {
      if (height[j] > height[i])
      {
        view = false;
        break;
      }
    }
    // cout << ": " << height[i] << " : " << view << endl;
    if (view)
    {
      result++;
      // cout << height[i] << endl;
    }
    // cout << height[i] << endl;
  }

  cout << result;
}

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

using namespace std;

int main()
{
    int n;
    string s;
    cin >> n;
    cin >> s;
    s = "."+s+"#";
    n += 2;
    vector<int> w = vector<int>(n);
    vector<int> b = vector<int>(n);

    int b_count = 0;
    int w_count = 0;
    for(int i = 0; i < n; i++) {
        if(s[i] == '#') {
            b_count++;
        }
        b[i] = b_count;
    }

    for(int i = n-1; i >= 0;i--) {
        if(s[i] == '.') {
            w_count++;
        }
        w[i] = w_count;
    }
    // for(int i = 0;i<n;i++) {
    //     cout << s[i] << ": w=" << w[i] << ", b=" << b[i] << endl;
    // }

    int result = 2000000;
    for(int i = 1; i < n-1; i++){
        result = min(result, w[i+1]+b[i-1]);
    }
    cout << result << endl;

    
    return 0;
}

Measured memory_bytes: 2112
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
typedef long long ll;

const ll INF = 1ll << 60ll;

ll n, m;
ll a, b, c;
ll d[105][105];
ll g[105][105];

ll ans;

void floyd();
void init();

int main()
{
    init();

    scanf("%lld %lld", &n, &m);
    for (int i = 0; i < m; i++) {
        scanf("%lld %lld %lld", &a, &b, &c);

        d[a][b] = c;
        d[b][a] = c;
        
        g[a][b] = c;
        g[b][a] = c;
    }

    floyd();

    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= n; j++) {
            if (g[i][j] == INF) continue;

            if (g[i][j] != d[i][j]) {
                ans++;
            }
        }
    }

    printf("%lld\n", ans / 2);

    return 0;
}

void floyd()
{
    for (int k = 1; k <= n; k++) {
        for (int i = 1; i <= n; i++) {
            if (d[i][k] == INF) continue;
            for (int j = 1; j <= n; j++) {
                if (d[k][j] == INF) continue;
                d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
            }
        }
    }
}

void init()
{
    for (int i = 0; i < 105; i++) {
        for (int j = 0; j < 105; j++) {
            d[i][j] = INF;
            g[i][j] = INF;
        }
    }
}


Measured memory_bytes: 384
// https://atcoder.jp/contests/sumitrust2019/tasks/sumitb2019_c

#include "algorithm"
#include "cmath"
#include "functional"
#include "iomanip"
#include "iostream"
#include "numeric"
#include "queue"
#include "set"
#include "string"
#include "vector"
#define rep(i, to) for (ll i = 0; i < (to); ++i)
#define repf(i, from, to) for (ll i = from; i < (to); ++i)
#define repr(i, from) for (ll i = from - 1; i >= 0; --i)
#define all(vec) vec.begin(), vec.end()
#define fi first
#define se second
using namespace std;
typedef long long ll;
template <typename T>
using V = vector<T>;
using VL = V<ll>;
using VVL = V<VL>;
template <typename T, typename U>
using P = pair<T, U>;
using PL = P<ll, ll>;
using VPL = V<PL>;
template <typename T>
inline bool chmax(T& a, T b);
template <typename T>
inline bool chmin(T& a, T b);
void print_ints(vector<ll> v);
template <typename T>
void drop(T a);

const ll INF = 1e18;

void solve() {
  ll X;
  cin >> X;

  ll t = X / 100;
  ll r = X % 100;

  if (r <= 5 * t) drop(1);
  drop(0);
}

struct exit_exception : public std::exception {
  const char* what() const throw() { return "Exited"; }
};

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

  try {
    solve();
  } catch (exit_exception& e) {
  }

  return 0;
}
#endif

template <typename T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}

template <typename T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

void print_ints(vector<ll> v) {
  rep(i, v.size()) {
    if (i > 0) {
      cout << " ";
    }

    cout << v[i];
  }

  cout << endl;
}

template <typename T>
void drop(T res) {
  cout << res << endl;
  throw exit_exception();
}


Measured memory_bytes: 256
from collections import deque

S = input()
Q = int(input())

ans = deque()
ans.append(S)
reverse = False

for i in range(Q):
    x = list(input().split())
    if int(x[0]) == 1:
        reverse = not reverse
        continue
    if int(x[1]) == 1 and not reverse:
        ans.appendleft(x[2])
    elif int(x[1]) == 2 and reverse:
        ans.appendleft(x[2])
    else:
        ans.append(x[2])

ans = ''.join(ans)

if reverse:
    print(ans[::-1])
else:
    print(ans)    





Measured memory_bytes: 67800
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

import static java.lang.Integer.parseInt;

/**
 * Swap Cipher
 */
public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line;
		String[] words;

		while ((line = br.readLine()) != null && !line.isEmpty()) {

			int N = parseInt(line);
			if (N == 0) break;

			char[] msg = br.readLine().toCharArray();

			int[][] swaps = new int[N][2];

			for (int i = 0; i < N; i++) {
				line = br.readLine();
				swaps[i][0] = parseInt(line.substring(0, line.indexOf(' '))) - 1; ;
				swaps[i][1] = parseInt(line.substring(line.indexOf(' ') + 1)) - 1; ;
			}

			for (int i = N - 1; i >= 0; i--) {
				int shift = swaps[i][1] - swaps[i][0];
				for (int j : swaps[i]) {
					msg[j] += shift;
					if (msg[j] > 'z') {
						msg[j] -= 'z' + 1;
						msg[j] %= 26;
						msg[j] += 'a';
					}
				}
				char tmp = msg[swaps[i][0]];
				msg[swaps[i][0]] = msg[swaps[i][1]];
				msg[swaps[i][1]] = tmp;
			}

			System.out.println(msg);
		}
	}
}

Measured memory_bytes: 24652
#include <iostream>
#include <vector>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
int main(){
	vector<int> d;
	int n,m; cin >> n >> m;
	rep(i,2*n)d.push_back(i+1);
	rep(I,m){
		int k; cin >> k;
		if(k == 0){
			vector<int> t[3];
			rep(i,n)t[0].push_back(d[i]);
			rep(i,n)t[1].push_back(d[n+i]);
			rep(i,n){
				t[2].push_back(t[0][i]);
				t[2].push_back(t[1][i]);
			}
			d = t[2];
		}else{
			vector<int> t;
			rep(i,2*n-k)t.push_back(d[k+i]);
			rep(i,k)t.push_back(d[i]);
			d = t;
		}
	}
	rep(i,2*n)cout << d[i] << endl;
}

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

int main() {
	string s;
	while(cin >> s){
		int cnt = 0;
		for(int i = 0; i < s.length() - 2; i++){
			if(s[i] == 'J' && s[i + 1] == 'O' && s[i + 2] == 'I') cnt++;
		}
		cout << cnt << endl;
		cnt = 0;
		for(int i = 0; i < s.length() - 2; i++){
			if(s[i] == 'I' && s[i + 1] == 'O' && s[i + 2] == 'I') cnt++;
		}
		cout << cnt << endl;
	}
	return 0;
}

Measured memory_bytes: 3204
#include<bits/stdc++.h>
#define ll long long int
#define ld long double
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
using namespace std;

int main(){
    fast;
    ll n, mn = 10000000001, k, x;
    cin >> n >> k;
    vector<ll> a(n), dp(n);
    for(int i = 0; i < n; ++i)
        cin >> a[i];
    dp[0] = 0;
    for(int i = 1; i < n; ++i){
        ll ans = i-k;
        if(ans < 0)
            ans = 0;
        for(int j = ans; j < i; ++j){
            ll diff = abs(a[i]-a[j]);
            dp[i] = diff+dp[j];
            if(dp[i] < mn){
                mn = dp[i];
            }
        }
        dp[i] = mn;
        mn = 10000000001;
    }
    cout << dp[n-1];
    return 0;
}

Measured memory_bytes: 1792
function Main(input){
    input = input.split(" ").map(Number);
    for(var i=0;true;i++){
        if(i%2==0){
            input[2]-=input[1];
            if(input[2]<=0){
                console.log("Yes");
                break;
            }
        }else{
            input[0]-=input[3];
            if(input[0]<=0){
                console.log("No");
                break;
            }
        }
    }
  }Main(require("fs").readFileSync("/dev/stdin", "utf8").trim());

Measured memory_bytes: 29616
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); ++i)
using namespace std;
using ll=long long;
int main(){
    ll n,k;
    cin>>n>>k;
    if(n%k!=0)cout<<min(n,k-n%k)<<endl;
    else cout<<0<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define ll long long
#define db long double
#define ii pair<int,int>
#define vi vector<int>
#define fi first
#define se second
#define sz(a) (int)(a).size()
#define all(a) (a).begin(),(a).end()
#define pb push_back
#define mp make_pair
#define FN(i, n) for (int i = 0; i < (int)(n); ++i)
#define FEN(i,n) for (int i = 1;i <= (int)(n); ++i)
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repv(i,a,b) for(int i=b-1;i>=a;i--)
#define SET(A, val) memset(A, val, sizeof(A))
typedef tree<int ,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set ;
// order_of_key (val): returns the no. of values less than val
// find_by_order (k): returns the kth largest element.(0-based)
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ','); cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif
const int N=100005;
vi v[N];
int root=-1,dp[N],n;
vi tmp;
void dfs(int u,int val,int par=-1)
{
  dp[u]=0;
  for(int v1:v[u])
    {
      if(v1==par) continue;
      dfs(v1,val,u);
    }
  for(int v1:v[u]) if(v1!=par) tmp.pb(dp[v1]);
  if(sz(tmp)%2==0) tmp.pb(0);
  sort(all(tmp));
  int low=0,high=sz(tmp)-1;
  while(low<high)
    {
      int mid=(low+high)>>1;
      int i=0,j=sz(tmp)-1;
      bool ok=true;
      while(i<j)
	{
	  if(i==mid) i++;
	  else if(j==mid) j--;
	  else if(tmp[i]+tmp[j]>val) { ok=false; break; }
	  else i++,j--;
	}
      if(ok) high=mid;
      else low=mid+1;
    }
  int i=0,j=sz(tmp)-1;
  bool ok=true;
  while(i<j)
    {
      if(i==low) i++;
      else if(j==low) j--;
      else if(tmp[i]+tmp[j]>val) { ok=false; break; }
      else i++,j--;
    }
  if(!ok) dp[u]=val+100;
  else dp[u]=tmp[low]+1;
  tmp.clear();
}
int main()
{
  std::ios::sync_with_stdio(false);
  cin.tie(NULL) ; cout.tie(NULL) ;
  int x,y;
  cin>>n;
  rep(i,1,n) cin>>x>>y,v[x].pb(y),v[y].pb(x);
  rep(i,1,n+1) if(sz(v[i])==1) root=i;
  assert(root!=-1);
  int cnt=0;
  rep(i,1,n+1) cnt+=(sz(v[i])&1);
  int low=0,high=n-1;
  while(low<high)
    {
      int mid=(low+high)>>1;
      dfs(root,mid);
      bool ok=true;
      rep(i,1,n+1) ok&=(dp[i]<=mid+1);
      if(ok) high=mid;
      else low=mid+1;
    }
  cout<<cnt/2<<" "<<low<<endl;
  return 0 ;
}


Measured memory_bytes: 15488