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

using namespace std;
using ll = long long;
#define int ll
using PII = pair<int, int>;
template <typename T> using V = vector<T>;
template <typename T> using VV = vector<V<T>>;
template <typename T> using VVV = vector<VV<T>>;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define PB push_back

const ll INF = (1LL<<60);
const int MOD = 1000000007;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template <typename T> bool IN(T a, T b, T x) { return a<=x&&x<b; }
template<typename T> T ceil(T a, T b) { return a/b + !!(a%b); }
template<class S,class T>
ostream &operator <<(ostream& out,const pair<S,T>& a){
  out<<'('<<a.first<<','<<a.second<<')';
  return out;
}
template<class T>
ostream &operator <<(ostream& out,const vector<T>& a){
  out<<'[';
  REP(i, a.size()) {out<<a[i];if(i!=a.size()-1)out<<',';}
  out<<']';
  return out;
}

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

bool used[10000];
signed main(void)
{
  cin.tie(0);
  ios::sync_with_stdio(false);

  int t;
  cin >> t;
  REP(test, t) {
    int a, b, c, d;
    cin >> a >> b >> c >> d;

    if(a < b) {
      cout << "No" << endl;
      continue;
    }
    if(b > d) {
      cout << "No" << endl;
      continue;
    }
    if(b == d) {
      if(c >= b) {
        cout << "Yes" << endl;
      } else {
        if(a%b <= c) cout << "Yes" << endl;
        else cout << "No" << endl;
      }
      continue;
    }
    if(c >= b) {
      cout << "Yes" << endl;
      continue;
    }
    int g = __gcd(b, d);
    int ma = b - g + a%g;
    if(ma > c) {
      cout << "No" << endl;
    } else {
      cout << "Yes" << endl;
    }
  }

  return 0;
}


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

using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
	REP(i, v.size()) { if (i)os << " "; os << v[i]; }return os;
}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
	REP(i, v.size()) { if (i)os << endl; os << v[i]; }return os;
}

const ll INF = 1LL << 60;
ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

#define int long long

inline void my_io() {

	std::ios::sync_with_stdio(false);

	std::cin.tie(0);

	cout << fixed << setprecision(16);

}

signed main() {
	ll n, t, x, y;

	cin >> n >> t;

	vector<pair<ll, ll>> v;

	REP(i, n) {
		cin >> x >> y;
		v.push_back(make_pair(x, y));
	}

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

	REP(i, n) {
		if (v[i].second <= t) {
			cout << v[i].first << endl;
			return 0;
		}
	}

	cout << "TLE" << endl;
}

Measured memory_bytes: 256
n,k = gets.split.map(&:to_i)
arr = Array.new(k+1){Array.new(k+1,0)}
arr2 = Array.new(k+1){Array.new(k+1,0)}
col = Array.new(k+1,0)
col2 = Array.new(k+1,0)
n.times do
  x,y,c = gets.split
  x,y,c = x.to_i,y.to_i,c.chomp
  t = (c == "W") ? 0 : 1
  xm = x % k
  ym = y % k
  arr[xm][ym] += 1
  arr2[xm][ym] += 1 if ((x/k + y/k) % 2) == t
  # p [x,y,c,t,((x/k + y/k) % 2),((x/k + y/k) % 2) == t]
end
k.times do |i|
  k.times do |j|
    col[i] += arr[j][i]
    col2[i] += arr2[j][i]
  end
end

k.times do |i|
  k.times do |j|
    arr[i][j] += arr[i][j-1]
    arr2[i][j] += arr2[i][j-1]
  end
end

max = min = ni = num = col2.inject(:+)

(k+1).times do |i|
  num = ni - col2[i-1] + (col[i-1] - col2[i-1])
  ni = num
  max = num if num > max
  min = num if num < min
  # p [i,num]
  k.times do |j|
    num -= arr2[j][k-1] - arr2[j][i-1]
    num += arr2[j][i-1]
    num += arr[j][k-1] - arr[j][i-1] - (arr2[j][k-1] - arr2[j][i-1])
    num -= arr[j][i-1] - arr2[j][i-1]
    max = num if num > max
    min = num if num < min
    # p [i,j,num]
  end
end

puts max > (n-min) ? max : n-min


Measured memory_bytes: 19708
import sys
input = sys.stdin.readline
from itertools import accumulate


def read():
    N = int(input().strip())
    S = input().strip()
    return N, S


def solve(N, S):
    W = [0] * (N+1)  # W[j]-W[i]: 区間[i, j)の白の数
    B = [0] * (N+1)  # B[j]-B[i]: 区間[i, j)の黒の数
    for i in range(N):
        s = S[i]
        W[i+1] = W[i] + 1 if s == "." else W[i]
        B[i+1] = B[i] + 1 if s == "#" else B[i]
    # i以上を黒に、i未満を白にする
    # .....##### になればOK
    ans = N
    for i in range(N+1):
        b2w = W[N] - W[i]
        w2b = B[i] - B[0]
        ans = min(ans, b2w + w2b)
    return ans


if __name__ == '__main__':
    inputs = read()
    print("%d" % solve(*inputs))


Measured memory_bytes: 18716
N, M, K = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))

ma = 0
mb = 0

i=0
j=0

flag = True

while ma + A[i] <= K:
  ma += A[i]
  i += 1
  if i == len(A):
    break

while mb + B[j] <= K - ma:
  mb += B[j]
  j += 1
  if j == len(B):
    flag = False
    break

ans = i + j
k = i-1
while flag and k >= 0:
  ma -= A[k]
  while mb + B[j] <= K - ma:
    mb += B[j]
    j += 1
    if j == len(B):
      flag = False
      break      
  ans = max(ans,k+j)
  k -= 1

print(ans)

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

typedef long long ll;

#define MOD 1000000007
#define INF LLONG_MAX
#define decimDigits(n) fixed << setprecision(n)
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define irep(it, arr) for(auto it = begin(arr); it != end(arr); it++)

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

int main(){

    ll a, b, x, ans = 0;

    cin >> a >> b >> x;

    cout << (b / x) - (a / x) + (a % x ? 0 : 1) << endl;

    return 0;
}

Measured memory_bytes: 256
#include<algorithm>
#include<climits>
#include<cmath>
#include<cstring>
#include<deque>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;

using lint = long long;
using P = pair<int, int>;
using LLP = pair<long long, long long>;

#define REP(i, x, n) for(int i = (x), i##_len = int(n) ; i < i##_len ; ++i)
#define rep(i, n) for(int i = 0, i##_len = int(n) ; i < i##_len ; ++i)
#define reps(i, n) for(int i = 1, i##_len = int(n) ; i <= i##_len ; ++i)
#define rrep(i, n) for(int i = int(n) - 1 ; i >= 0 ; --i)
#define rreps(i, n) for(int i = int(n) ; i > 0 ; --i)
#define SORT(x) sort((x).begin(), (x).end())
#define SORT_INV(x) sort((x).rbegin(), (x).rend())
#define TWINS(x) cout << ((x) ? "Yay!" : ":(") << endl

const int IINF = (1 << 30) - 1;
const long long LLINF = 1LL << 61;
const int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1};
const int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};
const double EPS = 1e-8;

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

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

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

    int l, r;
    cin >> l >> r;

    vector<int> cnt(2019, 0);
    for(int i = l ; i <= min(r, l + 2019 * 2) ; ++i){
        ++cnt[i % 2019];
    }

    int ans = 2019;
    for(int i = 0 ; i < 2019 ; ++i){
        if(cnt[i] > 1){
            chmin(ans, (i * i % 2019));
        }
        for(int j = 0 ; j < 2019 ; ++j){
            if(i == j){
                continue;
            }
            if(cnt[i] > 0 && cnt[j] > 0){
                chmin(ans, (i * j % 2019));
            }
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

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

    int n = sc.nextInt();

    long[] R = new long[n];
    for (int i = 0; i < n; i++) {
        R[i] = sc.nextLong();
    }

    long min = Long.MAX_VALUE;
    long max = Long.MIN_VALUE;
    for (int i = 0; i < n; i++) {
        max = Math.max(R[i] - min, max);
        min = Math.min(R[i], min);
    }

    System.out.println(max);
  }
}


Measured memory_bytes: 102416
#include <bits/stdc++.h>
#define ll long long
#define MAX 2999
ll mod = pow(10,9) + 7;

using namespace std;

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

    ll prev[k+1];
    ll curr[k+1];
    prev[0] = 1;

    if(n == 1){
        if(k <= a[0]) cout << 1;
        else cout << 0;
        return 0;
    }

    for(int i=1; i<=k; i++){
        if(i <= a[0]) prev[i] = (prev[i-1]%mod + 1)%mod;
        else prev[i] = prev[i-1]%mod;
    }


    for(int i=1; i<n; i++){

        for(int j=0; j<=k; j++){
            int startind = max((ll)0,j-a[i]);
            int endind = j;
            curr[j] = prev[endind]%mod;
            if(startind>0) curr[j] = (curr[j]%mod - prev[startind-1]%mod + mod)%mod;
        }

        prev[0] = curr[0]%mod;
        for(int j=1; j<=k; j++) prev[j] = (prev[j-1]%mod + curr[j]%mod)%mod;
    }

    cout << curr[k];
    return 0;
}


Measured memory_bytes: 1792
#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 cnt = 0;
    for (int i = 0; i < n - 1; ++i) {
        if (a[i] == a[i + 1]) {
            a[i + 1] = 10000;
            cnt++;
        }
    }
    cout << cnt << endl;
    return 0;
}



Measured memory_bytes: 256
n,k = map(int,input().split())

a = [input() for i in range(2 * k)]
b = a[1:2*k:2]
y=[]
for i in b:
  x = i.split()
  y.extend(x)

b=[]
d=1
while d <= 100:
  b.append(str(d))
  d+=1

c = 0

for i in b:
  if i in y:
    c += 1

c = n - c
print(c)

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

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<=(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define Eunique(v) v.erase(unique(all(v)),v.end())
#define Eback(s) s.erase(s.end()-1,s.end())
#define rev(v) reverse(all(v))
#define minvec(v) *min_element(all(v))
#define maxvec(v) *max_element(all(v))
#define sumvec(v) accumulate(all(v),0LL)
#define mapmin(v) v.rbegin()->first
#define mapmax(v) v.begin()->first
#define pb push_back
#define pf push_front
#define m_p make_pair
#define DOUBLE fixed << setprecision(15)
#define OK cerr<<"OK\n"
#define OK1 cerr<<"OK1\n"
#define OK2 cerr<<"OK2\n"
#define SIZE(s) (int)s.size()
#define INF ((1LL<<62)-(1LL<<31))
#define zero(x,n) setw(x) << setfill('0') << n

typedef long long ll;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<long long> vll;
typedef vector<vll> vvll;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<string> vs;

typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef vector<pair<int,int>> vpii;
typedef vector<pair<ll,ll>> vpll;

const double pi = acos(-1.0);
const int mod=1000000007;
const int mod2=998244353;

template<class A, class B>
ostream& operator<<(ostream& ost, const pair<A, B>&p) {
	ost << "{" << p.first << ", " << p.second << "} ";
	return ost;
}

template<class T>
ostream& operator<<(ostream& ost, const vector<T>&v) {
	ost << "{";
	for (int i = 0; i<(int)v.size(); i++) {
		if (i)ost << " ";
		ost << v[i];
	}
	ost << "} \n";
	return ost;
}

template<class A, class B>
ostream& operator<<(ostream& ost, const map<A, B>&v) {
	ost << "{";
	for (auto p:v) {
		ost << "{" << p.first << ", " << p.second << "} ";
	}
	ost << "} ";
	return ost;
}

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

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

void YES(bool b) {cout << ((b)?"YES\n":"NO\n");}
void Yes(bool b) {cout << ((b)?"Yes\n":"No\n");}
void yes(bool b) {cout << ((b)?"yes\n":"no\n");}
void Yay(bool b) {cout << ((b)?"Yay!\n":":(\n");}

ll powmod(ll a,ll b){ll c=1; while(b>0){ if(b&1){ c=a*c%mod; } a=a*a%mod; b>>=1; } return c;}
ll gcd(ll x, ll y) {return __gcd(x,y);}
ll lcm(ll x, ll y) {return x/__gcd(x,y)*y;}

int main()
{
	string s;
	ll n;
	cin >> s >> n;
	rep(i,SIZE(s)){
		if(s[i]!='a' && 'z'-s[i]+1<=n){
			n-='z'-s[i]+1;
			s[i]='a';
		}
		if(i==SIZE(s)-1){
			rep(j,n){
				if(s[i]=='z') s[i]='a';
				else s[i]++;
			}
		}
	}
	cout << s << endl;
	return 0;
}


Measured memory_bytes: 640
def e_sum_equals_xor(L, MOD=10**9 + 7):
    # 参考: http://drken1215.hatenablog.com/entry/2019/06/10/150000
    num_bit1, ans = 0, 0
    for i in range(len(L)):
        length = len(L) - i - 1
        if L[i] == '1':
            # Lのi桁目が1だった場合、そこでa+bのi桁目を0とするとa+b<=Lが確定する。
            # i+1桁目以降は (a, b)≠(1, 1) の3通りが選べる。
            # また、a+bのi桁目を1とすると、a+b<=Lとなるには、i桁目より前の桁で、
            # Lのk桁目とa+bのk桁目が一致しなければならない。
            # i桁目以前でLのビットが0の桁ではa+bのビットを0にする。1通り。
            # Lのビットが1の桁ではa+bのビットを1にする。2通り。
            ans += pow(3, length, MOD) * pow(2, num_bit1, MOD)
            num_bit1 += 1
    ans += pow(2, num_bit1, MOD)
    return ans % MOD

L = input()
print(e_sum_equals_xor(L))

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

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();

    let answer = solve(&buf);

    println!("{}", answer);
}

fn solve(input: &str) -> String {
    let mut iterator = input.split_whitespace();

    let a: usize = iterator.next().unwrap().parse().unwrap();
    let b: usize = iterator.next().unwrap().parse().unwrap();
    let mut x: usize = 1;
    let mut count: usize = 0;
    while x < b {
        x += a - 1;
        count += 1;
    }
    return count.to_string();
}


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

#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#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 fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

using namespace std;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll, ll> pll;
typedef long double ld;

template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }

int main() {
	int n; scanf("%d",&n);
	int time = 0;
	priority_queue<pii> store;
	forn(i, n) {
		int a, b;
		scanf("%d%d", &a, &b);
		store.push({-b, -a});
	}
	bool fine = true;
	while(!store.empty() && fine) {
		pii ok = store.top();
		store.pop();
		if(ok.first * -1 >= time + ok.second * -1)
			time += ok.second * -1;
		else
			fine = false;
	}
	fine?printf("%s", "Yes"):printf("%s", "No");
		
	return 0;
}

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

int main() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  
  string w;
  cin >> w;
  
  vector<int> cnt(26);
  rep(i, 26) cnt[i] = 0;
  rep(i, w.size()) ++cnt[w[i] - 'a'];
  bool ok = true;
  rep(i, 26) {
    if(cnt[i] % 2 != 0) {
      ok = false;
      break;
    }
  }
  
  if(ok) {
    cout << "Yes" << endl;
    return 0;
  }
  else {
    cout << "No" << endl;
    return 0;
  }
}


Measured memory_bytes: 3616
#include<bits/stdc++.h>
#define fi first
#define se second
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define rrep(i, n) for (int (i) = 1; (i) <= (n); (i++))
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define pb push_back
#define eb emplace_back
#define yn {puts("Yes");}else {puts("No");}
#define printd(x) printf("%.12f\n", ans);
template<class T> bool chmin(T& a, const T& b) {if (a > b) {a = b; return 1;} return 0;}
template<class T> bool chmax(T& a, const T& b) {if (a < b) {a = b; return 1;} return 0;}
using namespace std;
using ll = long long;
using P = pair<int, int>;



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

    bool ok = true;
    int n = s.size();
    for (int i = 0; i < n / 2; i++) {
        if (s[i] != s[n - 1 - i]) ok = false;
        //cout << i << " " << s[i] << " " << s[n - 1 - i] << endl;
    }
    //if (ok) yn
    for (int i = 0; i < n / 2 / 2; i++) {
        if (s[i] != s[n / 2 - 1 - i]) ok = false;
    }
    //if (ok) yn
    for (int i = (n + 3) / 2 - 1;  i < n / 2 / 2 + (n + 3) / 2 - 1; i++) {
        if (s[i] != s[n  - 1 - i]) ok = false;
    }

    if (ok) yn
    return 0;
}


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

int gcd(int x,int y){
    if(x%y==0){
        return y;
    }
    while(x%y!=0){
        int tmp=x%y;
        x=y;
        y=tmp;
    }
    return y;
}

int main(){
    int x,y;
    cin>>x>>y;
    cout<<gcd(x,y)<<endl;
    return 0;
}


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define maxn 55
struct Point{
	double x,y;
}p[maxn],r[maxn];
Point midpoint(Point a,Point b){return Point{(a.x+b.x)/2,(a.y+b.y)/2};}
double dist(Point a,Point b){return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));}
struct Cir{
	Point o;double r;
}D;
bool incir(Cir a,Point b){return dist(a.o,b)<=a.r;}
Cir cocir(Point x,Point y,Point z){
	double a=x.x-y.x,b=x.y-y.y,c=x.x-z.x,d=x.y-z.y,
	e=-((x.x*x.x-y.x*y.x)-(y.y*y.y-x.y*x.y))/2,f=-((x.x*x.x-z.x*z.x)-(z.y*z.y-x.y*x.y))/2;
	Point o=Point{(f*b-e*d)/(a*d-b*c),(f*a-e*c)/(b*c-d*a)};
	return Cir{o,dist(x,o)};
}
Cir welzl(int s1,int s2){
	if(!s1||s2>=3){
		if(!s2)return Cir{p[0],-1};
		if(s2==1)return Cir{r[0],0};
		if(s2==2)return Cir{midpoint(r[0],r[1]),dist(r[0],r[1])/2};
		return cocir(r[0],r[1],r[2]);
	}
	int x=rand()%s1;swap(p[x],p[s1-1]);
	D=welzl(s1-1,s2);
	if(incir(D,p[s1-1]))return D;
	r[s2++]=p[s1-1];return welzl(s1-1,s2);
}
int main(){
	int n;scanf("%d",&n);srand(0);
	for(int i=0;i<n;i++)scanf("%lf%lf",&p[i].x,&p[i].y);
	printf("%.10lf",welzl(n,0).r);
	return 0;
} 

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		String S = sc.next();
		char c[] = S.toCharArray();
		sc.close();
		for (int i = 0; i < S.length(); i++) {
			c[i] += N;
			if (c[i] > 'Z') {
				System.out.print((char) (c[i] - 26));
			} else {
				System.out.print(c[i]);
			}
		}
	}
}


Measured memory_bytes: 26324
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
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0;i<(n);++i)
#define fi first
#define se second
#define INF 1000000009
#define lINF 1000000000000000009
typedef long long ll;

// auto mod int
const int mod = 1000000007;
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;
  }
};

// combination mod prime
// https://www.youtube.com/watch?v=8uowVvQ_-Mo&feature=youtu.be&t=1619
struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
 }
}comb(200009);

int main(){
  int n,k;
  cin>>n>>k;
  k=min(k,n);
  mint ans=0;
  for(int i=0;i<=k;i++){
    ans+=comb(n,i)*comb(n-1,i);
  }
  cout<<ans.x<<endl;
  return(0);
}


Measured memory_bytes: 3328
a, b = map(int,raw_input().split())
while True:
    if min(a, b) == 1:
        print 1
        break
    elif 1 < b < a:
        a = a % b
    elif 1 < a < b:
        b = b % a
    else:
        print max(a, b)
        break

Measured memory_bytes: 4204
#include<algorithm>
#include<bitset>
#include<cmath>
#include<complex>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<iterator>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;
typedef long long ll;

#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--)
#define ALL(x) (x).begin(),(x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define D()
#define INF 1000000000000
#define MOD 10000007
#define MAXR 100000
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define INITA(a,i,j,v) for(ll k=i;k<=j;k++){a[k]=v;}

int main() {
    string s; cin >> s;
    if (s == "keyence") {
        cout << "YES" << endl;
        return 0;
    }
    FOR(i, 0, s.size()-1) {
        FOR(j, 0, s.size()-1) {
            string tmp = s.substr(0, i) + s.substr(j, s.size()-j);
            if (tmp == "keyence") {
                cout << "YES" << endl;
                return 0;
            }
        }
    }
    cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
using pii = pair<int,int>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const long long MOD=1e9+7;

int main() {
    int n;
    cin>>n;
    cout<<(n-1)/2<<endl;
    return 0;
}

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

int main(){
	int n;
	cin >> n;
	int k =n;
	map<long long ,long long> m;
	vector<long long> v;
	while(n--){
		int temp;
		cin >> temp;
		m[temp]++;
		v.push_back(temp);
	}
	long long sum = 0;
	for(auto x: m){
		//cout << x.first<< " " << x.second << endl;
		sum += x.second*(x.second-1)/2;
	}
	//cout << sum << endl;
	for(int i = 0; i< k;i++){
		cout << sum - (m[v[i]]-1) << endl;
	}
		
}


Measured memory_bytes: 12144
#include <iostream>
#include <assert.h>
#include <vector>
#include <unordered_map>
#include <queue>
#include <climits>
#include <cmath>
#include <algorithm>
using namespace std;
int main(){
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);
  string s;
  cin >> s;
  bool prevR = false;
  int cons = 0;
  int res = 0;
  for (int i = 0; i < 3; i++) {
    if (s[i] == 'R') {
      if (prevR == true) {
        cons++;
      } else {
        res = max(res, cons);
        cons = 1;
        prevR = true;
      }
    } else {
      res = max(res, cons);
      cons = 0;
      prevR = false;
    }
  }
      
  cout << max(res, cons) << endl;
  return 0;

}


Measured memory_bytes: 3644
#include<stdio.h>

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

  int temp , flag = 1 , flag2 = 1;
  int h = m;
  while(flag == 1){
    h /= 1.3;
    if(h < 1){
      h = 1;
      flag = 0;
    }
    for(int i = 0;i + h < m;i ++){
        if(b[i] > b[i+h]){
          flag = 1;
          temp = b[i];
          b[i] = b[i+h];
          b[i+h] = temp;
          temp = a[i];
          a[i] = a[i+h];
          a[i+h] = temp; 
      }
    }
  }

  int count = 0;
  int hasi[100000] = {0};

  for(int i = 0;i < m;i ++){
    flag = 1;
    int x = a[i];
    while(flag == 1 && x < b[i]){
      if(hasi[x] != 0){
        flag = 0;
      }
      x ++;
    }
    if(flag == 1){
      hasi[b[i]-1] = 1;
      count ++;
    }  
  }

  printf("%d\n",count);

  return 0;
}

Measured memory_bytes: 2856
#include <iostream>
#include <string>
#include <sstream>
#define MAX 100000
using namespace std;

struct Queue{
    int head;
    int tail;
    int q[MAX];

    void initialize(){
        head = 0;
        tail = 0;
    }
    bool isEmpty(){
        return (head == tail);
    }
    bool isFull(){
        return (head == (tail+1)%MAX);
    }
    void enqueue(int x){
        if(isFull()){
            cout << "queue overflow\n";
            //exit(0);
        }
        q[tail] = x;
        if(tail == MAX-1){
            tail = 0;
        }
        else{
            tail += 1;
        }
    }
    int dequeue(){
        if(isEmpty()){
            cout << "queue underflow\n";
            //exit(0);
        }
        int x = q[head];
        if(head == MAX-1){
            head = 0;
        }
        else{
            head += 1;
        }
        return x;
    }
};

void calc(Queue q_name, string name[], Queue q_time, int quantum){
    int t_sum = 0;
    while(q_name.head != q_name.tail){
        if(q_time.q[q_time.head] <= quantum){
            t_sum += q_time.dequeue();
            cout << name[q_name.dequeue()] << " " << t_sum << '\n';
        }
        else{
            t_sum += quantum;
            q_name.enqueue(q_name.q[q_name.head]);
            q_time.enqueue(q_time.q[q_time.head]-quantum);

            if(q_name.head == MAX-1){
                q_name.head = 0;
                q_time.head = 0;
            }
            else{
                q_name.head += 1;
                q_time.head += 1;
            }
        }
    }
}

int main(){
    Queue q_name, q_time;
    int num, quantum;
    string name[MAX];
    int t;

    q_name.initialize();
    q_time.initialize();

    cin >> num >> quantum;
    for(int i=0; i<num; i++){
        cin >> name[i] >> t;
        q_name.enqueue(i);
        q_time.enqueue(t);
    }

    calc(q_name, name, q_time, quantum);

    return 0;
}



Measured memory_bytes: 7428
#include<bits/stdc++.h>
using namespace std;
 
const int mod = 1e9 + 7;
int32_t main() {
	int n, m; cin>>n>>m;
	vector<int> dp(n + 1);
	map<int, int> broken;
	for(int i = 0; i < m; i++){
		int x; cin>>x;
		broken[x] = 1;
	}
	dp[0] = 1;
	dp[1] = (broken[1] ? 0 : 1);
	for(int i = 2; i <= n; ++i){
		if(broken[i]) dp[i] = 0;
		else dp[i] = (dp[i-1] + dp[i-2]) % mod;
	}
	cout<<dp[n]<<endl;
}


Measured memory_bytes: 5376
def A():
    N, R = map(int, input().split())
    if N >= 10:
        print(R)
    else:
        print(R + 100*(10-N))

def B():
    N, K = map(int, input().split())
    n = N
    ans = 1
    while n >= K:
        q, r = divmod(n, K)
        ans += 1
        n = q
    print(ans)

import math
def C():
    N = int(input())
    X = [int(i) for i in input().split()]
    X.sort()
    l = 1
    r = 100
    ans = float('-inf')
    while l<r:
        #print(l, r)
        temp_l = 0
        temp_r = 0
        for i in X:
            temp_l += (i-l)**2
            temp_r += (i-r)**2
        ans = min(temp_l, temp_r)
        if temp_l < temp_r:
            r = int(math.floor((l+r)/2.0))
        else:
            l = int(math.ceil((l+r)/2.0))
    
    print(ans)
C()

Measured memory_bytes: 3192
#include <iostream>
#define LL long long
using namespace std;

LL N,A;

bool check(LL x,LL p1, LL p2){
    LL i,aux=1;
    for (i=1; i<=p1; i++){
        aux*=x;
        if (aux>=N) return 1;
    }

    for (i=1; i<=p2; i++){
        aux*=(x+1);
        if (aux>=N) return 1;
    }

    return 0;
}

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

    LL res=N;

    LL k,t,x,l,r,mid;
    for (k=2; k<=40; k++){
        for (t=0; t<=k; t++){
            l=1,r=2000000;
            while (l<r){
                mid=(l+r)/2;
                if (check(mid,t,k-t)) r=mid;
                else l=mid+1;
            }

            x=r;
            res=min(res,k*(x+1)-t+(k-1)*A);
        }
    }

    cout << res << "\n";
    return 0;
}


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

using namespace std;
using   ll=long long;

#define fast            ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)

#define endl            "\n"
#define pb              push_back
#define mp              make_pair
#define F               first
#define S               second
#define int             long long int
#define pll                pair<int , int>

#define ALL(v)          v.begin(),v.end()
#define ALLR(v)         v.rbegin(),v.rend()
#define pii             3.14159265358979323
#define inf             LLONG_MAX
#define ones(x)         __builtin_popcount(x)
#define fill(a,b)       memset(a,b,sizeof(a))
#define mod             1000000007
#define hell            998244353 

ll mod_pow(ll a,ll b,ll m) 
{
    ll res = 1;
    while(b)    
    {
        if(b&1)     
        {
            res=(res*a) % m;
        }
        a=(a*a) % m;
        b>>=1;
    }
    return res;
}

ll mod_inverse(ll a) 
{
    return mod_pow(a , mod-2 , mod);
}

void solve() 
{
	int K;  
	
	cin >> K;
	
    int a = 7;
    
    for (int i = 1; i <= K; ++i) {
        if (a % K == 0) {
            cout << i << endl;
            return;
        }
        else {
        	a = (10 * a + 7) % K;
        }
    }
    
    cout << -1 << endl;
}

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


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

typedef long long ll;
typedef long double ld;
typedef vector<vector<int>> Graph;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
#define pi 3.14159265359
#define inf 2147483647
#define INF 9223372036854775807
#define mod 1000000007
#define mod2 998244353

int main() {
    int N; cin >> N;
    cout << "ABC" << N << endl;
    return 0;
}

Measured memory_bytes: 3556
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <fstream>
#include <sstream>
#include <math.h>
#include <map>
using namespace std;

int main()
{
	int A,B,C;
	cin >> A >> B >> C;
	cout << (A*B)/2 << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <vector>
#include <cmath>
#include <algorithm>
#include <numeric>
using namespace std;

unsigned long long combi(int n,int k){
  unsigned long long r = 1;
  for (unsigned long long d = 1; d <= k; ++d) {
    r *= n--;
    r /= d;
  }
  return r;
}

int main(void){
  int n,a,b,c,d;
  scanf("%d%d%d",&n,&a,&b);
  vector<unsigned long long> v(n);
  for(int i=0;i<n;i++) scanf("%llu",&v[i]);
  sort(v.begin(),v.end());
  unsigned long long su=0;
  for(int i=a;i>0;i--) su+=v[n-i];
  double ans1=(double)su/(double)a;
  for(c=n-1;c>=0;c--) if(v[c]==v[n-a])break;
  c=n-1-c;
  d=count(v.begin(),v.end(),v[n-a]);
  unsigned long long ans2=combi(d,a-c);
  for(int i=a+1;i<=b;i++){
    if(v[n-1]==v[n-i]){
      ans2+=combi(d,i-c);
    }else{break;}
  }
  printf("%f\n%llu\n",ans1,ans2);
}


Measured memory_bytes: 256
def divisors(num)
  ans = []
  1.upto(Math.sqrt(num).ceil) do |i|
    if num % i == 0
      ans << i
      ans << num / i if i != num / i
    end
  end
  ans.sort
end
 
def max_gcd(n, k, arr)
  sum = arr.inject(:+)
 
  divs = divisors(sum)
  divs.shift
 
  divs.reverse_each do |d|
    remainders = arr.map { |a| a % d }.sort
    remainders.shift while !remainders.empty? && remainders[0] == 0
    count = 0
    until remainders.empty?
      minus_count = remainders.shift
      count += minus_count
 
      while minus_count > 0
        need_plus_count = (d - remainders[-1])
        plus_count = [need_plus_count, minus_count].min
        minus_count -= plus_count
        remainders[-1] += plus_count
        remainders.pop if remainders[-1] % d == 0
      end
    end
 
    if count <= k
      puts d
      exit
    end
  end
 
  puts 1
end
 
n, k = gets.split.map(&:to_i)
arr = gets.split.map(&:to_i)
 
max_gcd(n, k, arr)

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

#define SIZE_OF_ARRAY(array) sizeof(array)/sizeof(array[0])

long long gcd(long long a, long long b){
    if (a >= b) {
        long long amari = a % b;
        if(amari == 0){
            return b;
        } else {
            return gcd(amari, b);
        }
    } else {
        long long amari = b % a;
        if(amari == 0){
            return a;
        } else {
            return gcd(amari, a);
        }
    }
}

int main() {
    long long K;
    cin >> K;
    long long sum = 0;
    for(long long i = 1; i <= K; i++){
        for(long long j = 1; j <= K; j++){
            for(long long k = 1; k <= K; k++){
                sum = sum + gcd(i,gcd(j,k));
            }
        }
    }
    cout << sum;
    return 0;
}

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

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  if (a == b && b == c) {
    puts("No");
  } else if (a == b || b == c || c == a) {
    puts("Yes");
  } else {
    puts("No");
  }
}


Measured memory_bytes: 256
//
// Created by 吉川純平 on 2019-12-01.
//

#include <bits/stdc++.h>
using namespace std;
//using ll = long long;
//using ull = unsigned long long;
#define ll long long
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 (a>b) { a=b; return 1; } return 0; }
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
#define all(x) (x).begin(),(x).end()
ll tmp1,tmp2,tmp3;
const ll mod = 1000000007;
const int INF = 1e9;
const ll INFLONG = 1e18;
void swap(ll *x,ll *y){
  ll tmp;
  tmp = *x;
  *x = *y;
  *y = tmp;
}
ll n;
vector<ll> a(20);
bool calc(ll x,ll num){
  if(num == n){
    if(x == 0){
      return 1;
    }else{
      return 0;
    }
  }else{
    return calc(x - a[num],num+1) || calc(x,num+1);
  }
}
int main(){
  ll q;
  cin >> n;
  rep(i,n){
    cin >> a[i];
  }
  cin >> q;
  vector<ll> m(q);
  rep(i,q){
    cin >> m[i];
  }
  rep(i,q){
    if(calc(m[i],0)){
      cout << "yes" << endl;
    }else{
      cout << "no" << endl;
    }
  }
}



Measured memory_bytes: 3108
#include<cstdio>
#include<algorithm>
#include<iostream>

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

using namespace std;


int main(void){
	int n;
	while(cin >> n){
		int ans = 100000000;
		int a[32]={0};
		if(!n)break;
		rep(i,n)cin >> a[i];
		
		rep(i,1<<n){
			int ga = 0,gb = 0;
			for(int j = 1,index = 0; j < 1<<n; j = j<<1,index++){
				if(i&j){
					ga+=a[index];
				}else{
					gb+=a[index];
				}
			}
			ans = min(abs(ga-gb), ans);
		}
		
		printf("%d\n", ans);
	}
}

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


int main(){
  int n;
  cin >> n;
  vector<int> vec(3*n);
  for(int i=0;i<3*n;i++){
    cin >> vec.at(i);
  }
  sort(vec.begin(),vec.end());
  reverse(vec.begin(),vec.end());
  long long int ans = 0;
  for(int k=1;k<2*n;k+=2){
    ans += vec.at(k);
  }
  cout << ans << endl;
}

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

using namespace std;
#define inputInt(a) int a; cin >> a; 
#define inputInt2(a,b) int a; int b; cin >> a >> b; 
#define inputInt3(a,b,c) int a; int b; int c; cin >> a >> b >> c;
#define inputLong(a) long a;cin >> a; 
#define inputIntArray(a,N) int a[N];for(int i=0;i<N;i++){cin >> a[i];}
#define inputLongArray(a,N) long a[N];for(int i=0;i<N;i++){cin >> a[i];}
#define inputIntArray2(a,b,N) int a[N]; int b[N]; for(int i=0;i<N;i++){cin >> a[i] >> b[i];}
#define output(answer) cout << answer << endl;
#define fN(i,N)    for(int i=0; i<N; i++)
#define fSE(i,s,e) for(int i=s; i<=e; i++)
#define ll long long
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define FOR(i,N) for(int i=0; i<N; i++)
#define cinv(v,N) vector<int> v(N); for(int i=0; i<N; i++){ cin >> v[i]; }
#define mt make_tuple
#define vll vector<long long int>
#define vvll vector<vector<long long int>>
#define all(v) (v).begin(),(v).end()
const ll MOD2 = 998244353;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main()
{
  //input
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  string S; cin >> S; 
  ll N = S.size();
  
  //main
  //string ans = "Yes";
  for(int i=0; i<=(N-1); i++){
    if(S[i]!=S[N-1-i]){
      cout << "No" << endl; return 0; 
    }
  }
  for(int i=0; i<=((N-1)/2)-1; i++){
    if(S[i]!=S[((N-1)/2-1)-i]){
      cout << "No" << endl; return 0; 
    }
  }
  for(int i=((N+1)/2); i<=N-1; i++){
    if(S[i]!=S[(N-1)+(N+1)/2-i]){
      cout << "No" << endl; return 0; 
    }
  }
  
  // output
  cout << "Yes" << endl;

  return 0;
}



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

using namespace std;

typedef long long ll;

const int MAX_N = 550;
const ll INF = 1e18;

int n, ai[MAX_N][MAX_N];
ll pre[MAX_N][MAX_N], dp[MAX_N][MAX_N], cost[MAX_N][MAX_N];

int main()
{
	scanf("%d", &n);
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= n; j++)
			if (i != j)
				scanf("%d", &ai[i][j]);
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= n; j++)
			pre[i][j] = ai[i][j] + pre[i][j - 1];
	for (int i = 0; i <= n; i++)
		for (int j = i + 1; j <= n; j++)
			dp[i][j] = INF;
	for (int i = 1; i <= n; i++)
		for (int j = i; j <= n; j++)
			for (int k = i; k <= j; k++)
				cost[i][j] += pre[k][j] - pre[k][k];
	for (int i = 1; i <= n; i++)
		dp[0][i] = cost[1][i];
	for (int i = 0; i <= n; i++)
		for (int j = i + 1; j <= n; j++)
		{
			ll acc = dp[i][j];
			for (int k = j + 1; k <= n; k++)
				acc += pre[k][i], dp[j][k] = min(dp[j][k], acc + cost[j + 1][k]);
		}
	ll ans = INF;
	for (int i = 0; i <= n - 1; i++)
		ans = min(ans, dp[i][n]);
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 11348
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int a;
  cin>>a;
  int arr[a];
  for(int i=0;i<a;i++)
    cin>>arr[i];
  int sum=0;
  for(int i=0;i<a;i++)
    for(int j=i+1;j<a;j++)
      sum+=(arr[i]*arr[j]);
  cout<<sum<<"\n";
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fast {ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);}
typedef long long int ll;
typedef string S;
#define M 1e18
#define AS 1000005
#define in(x)  cin>>x
#define o(x)  cout<<x
#define sp cout<<' '
#define nw cout<<endl
#define rt return
#define fr(i,a,n) for(ll i=a;i<=n;i++)
#define frm(i,a,n) for(ll i=n;i>=a;i--)
#define P pair<ll,ll>
#define vc vector<ll>
#define pb push_back
#define MP map<ll,ll>
bool sortin(const pair<ll,ll> &e,const pair<ll,ll> &f){return (e.first<f.first);}
bool POT(ll x){return x && (!(x&(x-1)));}
ll i,j,k,l,m,n,p,q,r,a,b,c,x,y,z,ts,mn=1e18,mod=1e9+7;
ll ar[AS],br[AS],xr[AS],tem[AS];
int main()
{
    fast;
    in(n>>m>>k);
    map<P,ll>mp;
    fr(i,1,k)
    {
        in(x>>y);
        ar[x]++;br[y]++;
        if(ar[x]>p)p=ar[x];
        if(br[y]>q)q=br[y];
        mp[{x,y}]=1;
    }
   // o(p);sp;o();nw;
    fr(i,1,300006)
    {
        if(ar[i]==p)xr[c++]=i;
        if(br[i]==q)tem[r++]=i;
    }
   if(c*r>k){o(p+q);rt 0;}
    fr(i,0,c)
    {
        fr(j,0,r)
        {
           m=ar[xr[i]]+br[tem[j]];
            if(mp[{xr[i],tem[j]}])m--;
            l=max(l,m);
        }
    }
    o(l);
}


Measured memory_bytes: 45840
#D
import itertools
N=int(input())
S=str(input())
count=0
for i,j,k in itertools.product(range(10),repeat=3):
  try:
    x = S.index(str(i))
    y = S.index(str(j),x+1)
    z = S.index(str(k),y+1)
    count +=1
  except:
    continue

print(count)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int N=500005,P=998244353;
int n,m,ans,fac[N],ifac[N];
inline int pw(int a,int b){int r=1;for(;b;b>>=1,a=1ll*a*a%P)if(b&1)r=1ll*r*a%P;return r;}
inline int C(int a,int b){return a<0||b<0||a<b?0:1ll*fac[a]*ifac[b]%P*ifac[a-b]%P;}
int main()
{
	scanf("%d%d",&n,&m);if(n<m)swap(n,m);
	for(int i=fac[0]=1;i<=n;i++)fac[i]=1ll*fac[i-1]*i%P;
	ifac[n]=pw(fac[n],P-2);
	for(int i=n;i;i--)ifac[i-1]=1ll*ifac[i]*i%P;
	for(int i=0;i<=m;i++)ans=(ans+1ll*(i&1?P-1:1)*C(n,i)%P*C(m,i)%P*fac[i]%P*pw(m+1,n-i)%P*pw(n+1,m-i))%P;
	printf("%d\n",ans);return 0;
}

Measured memory_bytes: 4096
#include<bits/stdc++.h>
using namespace std;
vector<long>a;
void f(long i,long n,long &ans)
{
	if(i!=n-1&&a[i]>0)
	{
		if(abs(a[i])>abs(a[i+1]))ans+=a[i]*(a[i]+1)/2;
		else ans+=a[i]*(a[i]-1)/2;
	}
	else if(a[i]>0)ans+=a[i]*(a[i]+1)/2;
	else if(i!=0&&a[i]<0)
	{
		if(abs(a[i-1])>abs(a[i]))ans+=abs(a[i])*(abs(a[i])-1)/2;
		else ans+=abs(a[i])*(abs(a[i])+1)/2;
	}
	else if(a[i]<0)ans+=abs(a[i])*(abs(a[i])+1)/2;
}
int main()
{
	char s[500005]={0};
	long i,n;
	for(cin>>s;s[n];n++);n++;
	long buf=s[0]=='<'?1:-1;
	for(i=1;i<n-1;i++)
	{
		if(buf>0&&s[i]=='<')buf++;
		else if(buf<0&&s[i]=='>')buf--;
		else if(buf>0&&s[i]=='>')a.emplace_back(buf),buf=-1;
		else if(buf<0&&s[i]=='<')a.emplace_back(buf),buf=1;
	}
	a.emplace_back(buf);
	n=a.size();
	long ans=0;
	for(i=0;i<n;i++)f(i,n,ans);
	cout<<ans<<endl;
}

Measured memory_bytes: 2932
import sys
sys.setrecursionlimit(100000)
N = int(input().strip())
shogen = [[-1 for _ in range(N)] for j in range(N)]
for i in range(N):
    size = int(input().strip())
    for j in range(size):
        k, tf = map(int, input().strip().split())
        k -= 1
        shogen[i][k] = tf

def dfs(bp, k):
    if k == N:
        # 矛盾なら0 そうでないならbp = Trueの数を返す
        for i in range(N):
            if not bp[i]:
                continue
            for j in range(N):
                if shogen[i][j] == 1 and not(bp[j]):
                    return 0
                if shogen[i][j] == 0 and bp[j]:
                    return 0
        cnt = 0
        for i in range(N):
            if bp[i]:
                cnt += 1
        return cnt
    """
    #　矛盾チェック
    mujun = False
    for j in range(N):
        if j == k:
            for l in range(N):s
                if shogen[k][l] == 0
        else:
            if shogen[j][k] == 0:
                mujun = True
                break

    """
    bp[k] = True
    tmp1 = dfs(bp, k + 1)
    bp[k] = False
    tmp2 = dfs(bp, k + 1)

    return max(tmp1, tmp2)

tmp_bp = [False] * N
ans = dfs(tmp_bp, 0)
print(ans)

Measured memory_bytes: 3064
#include<iostream>
#include<vector>
using namespace std;
int main(){
    int an,bn;
    cin>>an>>bn;
    vector<int>A(an),B(bn);
    for(int i=0;i<an;i++)cin>>A[i];
    for(int i=0;i<bn;i++)cin>>B[i];
    int ma=0;
    for(int i=0;i<bn;i++){
        int pos=0;
        int cnt=0;
        for(int j=i;j<bn;j++){
            while(A[pos]!=B[j]&&pos<an)pos++;
            if(pos==an)break;
            cnt++;
            pos++;
        }
        ma=max(ma,cnt);
    }
    cout<<ma<<endl;
    return 0;
}

Measured memory_bytes: 1236
import scala.io.{StdIn => in}
import scala.collection.{mutable => mu}

object Main extends App {
  val Array(n, m) = in.readLine.split(" ").map(_.toInt)
  val seq = in.readLine.split(" ").map(_.toInt)

  val map = mu.HashMap.empty[Int, Int]
  seq.foreach(i => map.put(i, map.getOrElse(i, 0) + 1))
  Iterator.continually(in.readLine)
    .take(m)
    .map(_.split(" ").map(_.toInt))
    .foreach(e => map.put(e(1), map.getOrElse(e(1), 0) + e(0)))

  val keys = map.keys.toArray.sorted(Ordering[Int].reverse).iterator

  def rec(acc:Long, cnt:Int):Long = {
    val key = keys.next()
    val value = map(key)
    if(cnt - value < 1) acc + key.toLong * cnt
    else rec(acc + key.toLong * value, cnt - value)
  }

  val ans = rec(0L, n)
  println(ans)
}

Measured memory_bytes: 97140
import bisect

N,Q = [int(i) for i in input().rstrip().split(" ")]
s = input().rstrip()

pos_lst = []
al_old = ""
for i,al in enumerate(s):
	if al == "C" and al_old == "A":
		pos_lst.append(i)

	al_old = al

for _ in range(Q):
	l,r = [int(i) for i in input().rstrip().split(" ")]
	lpos = bisect.bisect_left(pos_lst,l)
	rpos = bisect.bisect_left(pos_lst,r-0.5)
	print(rpos-lpos)
	

Measured memory_bytes: 5772
#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
//#define cerr if(false) cerr
#define show(...) cerr << #__VA_ARGS__ << " = ",debug(__VA_ARGS__);
using namespace std;
using ll = long long;
using pii = pair<int,int>;
template<typename T, typename S>
ostream &operator<<(ostream &os,pair<T,S>a){
    os << '(' << a.first << ',' << a.second << ')';
    return os;
}
template<typename T>
ostream &operator<<(ostream &os, vector<T> v){
    for(auto x:v)os << x << ' ';
    return os;
}
void debug(){cerr << '\n';}
template<typename H, typename... T>
void debug(H a, T... b){
    cerr << a;
    if(sizeof...(b))cerr << ", ";
    debug(b...);
}
int main(){
    stack<int>st;
    string s;
    cin >> s;
    rep(i,s.size()){
        if(st.size() and st.top() != s[i]-'0'){
            st.pop();
        }else{
            st.push(s[i]-'0');
        }
    }
    cout << s.size() - st.size() << endl;
}

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

const int MOD=1000000007;
const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;

char maze[50][50];
int  dist[50][50];

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

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

  cin>>s;
  
  if(s=="Sunny") cout<<"Cloudy"<<endl;
  if(s=="Cloudy") cout<<"Rainy"<<endl;
  if(s=="Rainy")cout<<"Sunny"<<endl;
  
  
}
  



Measured memory_bytes: 256
/*author:anshumanc007
   created on:05/01/2019
            */
#include <bits/stdc++.h>
#include <queue>
#include <stack>
using namespace std;


#define first fi
#define second se
typedef pair<long long int,long long int> pa;
#define MAX 100005
long long int MOD=1e9+7;
long long int INF=1e18;
long long int dp[MAX];

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    long long int i,j,k,l,m,n,o,p,q,r,x,y,a,b,mini=INF,maxi=0,cnt=0;
    cin>>n>>k;
    long long int A[n+1];
    for(i=1;i<=n;i++)
    {
        cin>>A[i];
    }
    A[0]=INF;
    for(i=0;i<=n;i++)
    {
        
            dp[i]=INF;
        
    }
    dp[1]=0;     
    for(i=2;i<=n;i++)
    {
        for(j=1;j<=min(i,k);j++)
        {
            dp[i]=min(dp[i],dp[i-j]+abs(A[i-j]-A[i]));
        }
         
    }
    cout<<(dp[n]);
}

Measured memory_bytes: 1792