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

int main()
{
	int N;
	cin >> N;
	vector<int> a(N);
	int id = 0;
	for (int i = 0; i < N; i++) {
		cin >> a[i];
		if (abs(a[i]) > abs(a[id])) {
			id = i;
		}
	}
	if (a[id] == 0) {
		cout << 0 << endl;
		return 0;
	}
	vector<int> x, y;
	if (a[id] > 0) {
		for (int i = 0; i < N; i++) {
			if (a[i] < 0) {
				x.push_back(id);
				y.push_back(i);
			}
		}
		for (int i = 1; i < N; i++) {
			x.push_back(i - 1);
			y.push_back(i);
		}
	}
	else {
		for (int i = 0; i < N; i++) {
			if (a[i] > 0) {
				x.push_back(id);
				y.push_back(i);
			}
		}
		for (int i = N - 1; i >= 1; i--) {
			x.push_back(i);
			y.push_back(i - 1);
		}
	}
	cout << x.size() << endl;
	for (int i = 0; i < (int)x.size(); i++) {
		cout << x[i] + 1 << ' ' << y[i] + 1 << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <cstring>
#include <bitset>
#include <cmath>
#include <iomanip>
#include <stack>
#include <set>
#include <queue>
#include <algorithm>
#include <deque>
#include <map>
#include <cmath>
#include <iomanip>
#include <numeric>
#include <chrono>
using namespace std;

#define INF 1e18
#define int long long

signed main() {
    int x;
    cin >> x;

    if(x == 2) {
        cout << 2 << endl;
        return 0;
    }
    
    int i = x;
    while(true) {
        for(int j = 2; j < i; j++) {
            if(i % j == 0) break;
            else if(j == i - 1) {
                cout << i << endl;
                return 0;
            }
        }
        i++;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
    int R0,W0,C,R;
    while(scanf("%d %d %d %d",&R0,&W0,&C,&R),R0) {
        int n=0;
        if(W0*C>R0) {
            n=(int)ceil((W0*C-R0)/(double)R);
        }
        printf("%d\n",n);
    }
}

Measured memory_bytes: 3084
#include <bits/stdc++.h>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define rrep(i,n) for (int i=(n-1);i >= 0;i--)
#define all(v) v.begin(),v.end()
#define sz(v) (int)((v).size())
#define MAX(v) *max_element(all(v))
#define MIN(v) *min_element(all(v))
using namespace std; using ll = long long; using P = pair<int,int>;
using vl = vector<ll>; using vvl = vector<vl>;
void debug_out() { cout << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cout << H << " ";
    debug_out(T...);
}
#ifdef _DEBUG
#define debug(...) debug_out(__VA_ARGS__)
#else
#define debug(...) 
#endif
template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
    for (std::size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
    return os;
}
inline void IN(void){return;}
template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){cin >> first;IN(rest...);return;}
template<class T>bool chmax(T &a, const T &b) {if(a<b){a=b; return 1;} return 0;}
template<class T>bool chmin(T &a, const T &b) {if(b<a){a=b; return 1;} return 0;}
const ll INF = 1LL << 60;
const ll mod = 1000000007;
const int dx[8] = {1,0,-1,0,1,1,-1,-1}; const int dy[8] = {0,1,0,-1,1,1,-1,-1};

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    ll n,m;
    cin >> n >> m;
    vl a(m);
    rep(i,m) cin >> a[i];
    ll sum = 0;
    rep(i,m){
        sum += a[i];
    }
    if(sum > n) cout << -1 << endl;
    else cout << n-sum << endl;
}

Measured memory_bytes: 3680
road = []
count_num = [1, 2, 3, 4]
for i in range(3):
    a, b = map(int, input().split())
    road.append(a)
    road.append(b)
flag = True
for i in count_num:
    if road.count(i) >= 3:
        flag = False
if flag is True:
    print("YES")
else:
    print("NO")


Measured memory_bytes: 3060
# -*- coding: utf-8 -*-
import math
def main():
    N,A,B = map(int,input().split())
    ans0 = N//(A+B)
    ans1 = A*ans0
    ans2 = (N-(A+B)*ans0)
    if ans2 <= 0:
        ans2 = 0
    if ans2 < A:
        ans1 += ans2
    elif ans2 >= A:
        ans1 += A

    print(ans1)

if __name__ == '__main__':
    main()

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

int main() {

	string s; cin >> s;	
	string a = "dream";
	string b = "dreamer";
	string c = "erase";
	string d = "eraser";
	reverse(s.begin(), s.end());
	reverse(a.begin(), a.end());
	reverse(b.begin(), b.end());
	reverse(c.begin(), c.end());
	reverse(d.begin(), d.end());
	int na = a.size(); // 5
	int nb = b.size(); // 7
	int nc = na;       // 5
	int nd = d.size(); // 6
	string tmp_s = s;
	bool can = true;
	//while (na <= tmp_s.size()) {
	while (tmp_s != "") {
		if (nb <= tmp_s.size()) {
			if (tmp_s.substr(0, na) == a || tmp_s.substr(0, nc) == c) {
				tmp_s = tmp_s.substr(na);
			}
			else if (tmp_s.substr(0, nb) == b) {
				tmp_s = tmp_s.substr(nb);
			}
			else if (tmp_s.substr(0, nd) == d) {
				tmp_s = tmp_s.substr(nd);
			}
			else {
				can = false;
				break;
			}
		}
		else if (tmp_s.size() == nd) {
			if (!(tmp_s == d)) {
				can = false;
			}
			break;
		}
		else if (tmp_s.size() == na) {
			if (!(tmp_s == a || tmp_s == c)) {
				can = false;
			}
			break;
		}
		else {
			can = false;
			break;
		}
	}
	if (can) cout << "YES" << endl;
	else cout << "NO" << endl;
	return 0;
}

Measured memory_bytes: 3824
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <iomanip>
#include <cstdio>
#include <set>
#include <map>
#include <list>
#include <cstdlib>
#include <queue>
#include <stack>

using namespace std;

#define mod (1e9 + 7)
#define pi 3.1415926535897932
#define rep(i, n) for (int i = 0; i < n; i++)
#define repe(i, j, n) for(int i = j; i < n; i++)
#define repi(i, n) for (int i = 0; i <= n; i++)
#define repie(i, j, n) for (int i = j; i <= n; i++)
#define all(x) x.begin(), x.end()
#define println() cout << endl
#define P pair<int, int>
#define fi first
#define se second

typedef long long ll;

void solve1()
{
  int n, m; cin >> n >> m;
  vector<int> k(n);
  vector<vector<int>> a(n);
  rep(i, n) {
      cin >> k[i];
      for(int j = 0; j < k[i]; j++) {
          int in; cin >> in;
          a[i].push_back(in);
      }
  }

  int ans = 0;

  rep(i, m) {
      int cnt = 0;
      rep(j, n) {
          rep(m, k[j]) {
              if(a[j][m] == i+1) {
                  cnt ++;
              }
          }
      }

      if(cnt >= n) {
          ans ++;
      }
  }

  cout << ans << endl;
}



int main()
{
    solve1();
}

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

using namespace std;


int main(){
    string S;
    cin>>S;
    string ans="";
    int count=0;

    for(int i=0;i<S.size();++i){
        if(i==0){
            cout<<S[i];
        }else if(i==S.size()-1){
            
            cout<<count;
            cout<<S[i]<<endl;
        }else{
            count++;
        }
    }


}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int N;
    cin >> N;
    if(N%10 == 3) {
        cout << "bon" << endl;
    }else if(N%10 == 0 || N%10 == 1 || N%10 == 6 || N%10 == 8){
        cout << "pon" << endl;
    }else {
        cout << "hon" << endl;
    }
    
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
  using namespace std;
#define ll long long
#define fw(p) for(int w=0;w<(p);w++)
#define fx(p) for(int x=0;x<(p);x++)
#define fy(p) for(int y=0;y<(p);y++)
#define fz(p) for(int z=0;z<(p);z++)
#define fyg(p,g) for(int y=(g);y<(p);y++)
#define fzg(p,g) for(int z=(g);z<(p);z++)
#define ce(d) cout<<d<<endl;
#define vecp(p) int aa;cin>>aa;(p).push_back(aa);
#define vecpl(p) long long aa;cin>>aa;(p).push_back(aa);
#define vecps(p) string aa;cin>>aa;(p).push_back(aa);
#define vecp2(p) int ab;cin>>ab;(p).push_back(ab);
#define vecpl2(p) long long ab;cin>>ab;(p).push_back(ab);
#define vecps2(p) string ab;cin>>ab;(p).push_back(ab);
#define set0(k,n) for(int nn=0;nn<(n);nn++){ (k).push_back(0); }
#define sorts(c) sort((c).begin(),(c).end());
#define reverses(c) reverse((c).begin(),(c).end());
#define vec(b) vector<int> (b);
#define vecl(b) vector<long long> (b);
#define vecs(b) vector<string> (b);
#define vecsize(b,size) vector<int> (b)((size));
#define pb(b,a) (b).push_back((a));
#define doublece(a,b) cout<<(a)<<' '<<(b)<<endl;
#define pairs(s) vector<pair<int,int>> (s);
#define pairsl(s) vector<pair<ll,ll>> (s);
#define pairss(s) vector<pair<string,string>> (s);
#define pairsp(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairspl(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsps(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsREV(s) (s).push_back(make_pair(bb,aa));
#define pairslREV(s) (s).push_back(make_pair(bb,aa));
#define pairssREV(s) (s).push_back(make_pair(bb,aa));
#define MOD 1000000007

int main() {
	
	int X,A,B;
	cin>>X>>A>>B;
	if(A-B>=0){
		ce("delicious")
	}else if(X+A-B>=0){
		ce("safe")
	}else{
		ce("dangerous")
	}
	
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<cmath>
#include<climits>
#include<queue>

struct edge{
	int dst;
	int cost;
};

struct vtx{
	int idx;
	int minCost;
};

int dijkstra(std::vector<std::vector<edge>> graph){
	auto cmp= [](vtx x, vtx y){return x.minCost< y.minCost;};
	std::priority_queue<vtx, std::vector<vtx>, decltype(cmp)> que(cmp);

	std::vector<vtx> vList(graph.size());
	for(int i=0; i<vList.size(); i++){
		vList[i].idx= i;
		vList[i].minCost= -1;
	}
	vList[0].minCost= 0;
	
	que.push(vList[0]);

	while(!que.empty()){
		vtx tmp= que.top();
		que.pop();

		for(int i=0; i< graph[tmp.idx].size(); i++){
			int dstIdx= graph[tmp.idx][i].dst;
			int dstCost= graph[tmp.idx][i].cost;

			if(vList[dstIdx].minCost<0 || vList[tmp.idx].minCost + dstCost < vList[dstIdx].minCost){
				vList[dstIdx].minCost= vList[tmp.idx].minCost + dstCost;
				que.push(vList[dstIdx]);
			}
		}		
	}

	return vList[vList.size()-1].minCost;
}

int main(){
	int n, m;
	std::cin>>n>>m;

	std::vector<int> aList(m);
	std::vector<int> bList(m);
	std::vector<std::vector<int>> cList(m);
	std::vector<int> pow2(n+1);

	pow2[0]= 1;
	for(int i=0; i<n; i++)
		pow2[i+1]= pow2[i]*2;

	int numVtx= pow2[n];

	std::vector<std::vector<int>> costMat(numVtx);
	for(int i=0; i<numVtx; i++)
		costMat[i].resize(numVtx, -1);

	for(int i=0; i<m; i++){
		std::cin>>aList[i]>>bList[i];
		cList[i].resize(bList[i]);

		for(int j=0; j< bList[i]; j++)
			std::cin>>cList[i][j];
	}

	for(int i=0; i<m; i++){
		int addNum=0;
		for(int j=0; j< bList[i]; j++)
			addNum+= pow2[cList[i][j]-1];

		for(int j=0; j< numVtx; j++){
			int dstIdx= j|addNum;
			if(dstIdx == j)
				continue;

			if(costMat[j][dstIdx]<0)
				costMat[j][dstIdx]= aList[i];
			else
				costMat[j][dstIdx]= std::min(aList[i], costMat[j][dstIdx]);
		}
	}

	std::vector<std::vector<edge>> graph(numVtx);

	for(int i=0; i< numVtx; i++)
		for(int j=i; j< numVtx; j++)
			if(costMat[i][j]>=0)
				graph[i].push_back({j, costMat[i][j]});

	int ans= dijkstra(graph);

	std::cout<<ans<<std::endl;

	return 0;
}

Measured memory_bytes: 73344
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define reps(i, n) for (int i = 1; i <= (n); ++i)
#define repd(i, n) for (int i = (n)-1; i >= 0; --i)
#define repds(i, n) for (int i = (n); i > 0; --i)
#define loop(i, x, n) for (int i = (x); i < (n); ++i)
#define loops(i, x, n) for (int i = (x); i <= (n); ++i)
#define loopd(i, x, n) for (int i = (x); i > (n); --i)
#define loopds(i, x, n) for (int i = (x); i >= (n); --i)
#define itrep(i, a) for (auto i = begin(a); i != end(a); ++i)
#define itrepd(i, a) for (auto i = rbegin(a); i != rend(a); ++i)
#define each(i, x) for (auto &&i : x)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(a) ((int)a.size())
#define pow2(n) (n * n)
#define int ll
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
template <class T>
using p_queue = priority_queue<T, vector<T>, greater<T>>;
constexpr ll inf = static_cast<ll>(1e18);
constexpr int iinf = static_cast<int>(1e9);
constexpr double dinf = 1e10;
constexpr ld ldinf = 1e18;
constexpr double eps = 1e-8;
ll mod = static_cast<ll>(1e9 + 7);
template <class T, class... Args>
constexpr void mins(T &a, Args... args) { a = min<T>({a, args...}); }
template <class T, class... Args>
constexpr void maxs(T &a, Args... args) { a = max<T>({a, args...}); }
template <class F>
class FixPoint : private F {
public:
    explicit constexpr FixPoint(F &&f) : F(std::forward<F>(f)) {}
    template <class... Args>
    constexpr decltype(auto) operator()(Args &&... args) const { return F::operator()(*this, std::forward<Args>(args)...); }
};
template <class F>
constexpr decltype(auto) funcs(F &&f) { return FixPoint<F>{std::forward<F>(f)}; }
template <class T>
std::vector<T> vecs(int n, T &&val) { return std::vector<T>(std::forward<int>(n), std::forward<T>(val)); }
template <class... Args>
decltype(auto) vecs(int n, Args &&... args) { return std::vector<decltype(vecs(std::forward<Args>(args)...))>(std::forward<int>(n), vecs(std::forward<Args>(args)...)); }
template <class V, class T>
void fill(V &x, const T &val) { x = val; }
template <class V, class T>
void fill(vector<V> &vec, const T &val) {
    for (auto &&v : vec)
        fill(v, val);
}

void solve() {
    int n, x, t;
    cin >> n >> x >> t;
    cout << (n + x - 1) / x * t << endl;
}

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

Measured memory_bytes: 3636
N,M = map(int,input().split())
A = list(map(int,input().split()))
BC = [list(map(int,input().split())) for _ in range(M)]

A.sort()

#同じカードを書き換える操作は無駄なため、cが降順となるようにソート
BC.sort(key=lambda x:-x[1])

i = 0

for B,C in BC:
  for j in range(i,min(N,i + B)):
    if A[j] < C:
      A[j] = C
  #B枚分先を飛ばす BCはCに関して降順のため問題ない
  i = i + B

print(sum(A))

Measured memory_bytes: 36076
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        
        Scanner sc = new Scanner(System.in);
        
        long x = Long.parseLong(sc.next());
        
        long ans = (x / 500 * 1000) + ((x % 500) / 5 * 5);
        System.out.println(ans);
    }
}

Measured memory_bytes: 23636
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<string.h>
#include<iostream>
#include<queue>
#include<stack>
#include<math.h>
#define Max 1000
#define INF 1000000000000000000
using namespace std;


int main(){

	long long int a,b,k;
	scanf("%lld%lld%lld",&a,&b,&k);
	
	if(k > a){
		k = k-a;
		a = 0;
		if(k > b){
			k = k-b;
			b = 0;
		}else{
			b = b-k;
		}
	}else{
		a = a-k;
	}


	printf("%lld %lld\n",a,b);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <iomanip>
#include <limits>

using namespace std;
int main(){
    double W ,H ,x ,y ;
    cin >> W >> H >> x >> y ;
    double S = W*H/2.0 ;
    cout << fixed << setprecision(10);
    cout << S << " " ;
    if((x == W/2.0)&&(y == H/2.0)){
        cout << "1" << endl;
    }
    else{
        cout << "0" << endl;
    }
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
int main(void)
{
    int i, a, k, b;
    char s[4];

    scanf("%s", s);
    if (strcmp(s, "ARC"))
    {
        printf("ARC\n");
    }
    else
    {
        printf("ABC\n");
    }
    return 0;
}

Measured memory_bytes: 1608
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#define maxn 1001
#define re register
#define FOR(i, l, r) for(re int i = l; i <= r; ++i)
#define DFR(i, l, r) for(re int i = l; i >= r; --i)
using namespace std;

int n, m, c, r, t, x, y, z;
char b[2][2];

int main() {
	b[0][0] = 'R';
	b[1][0] = 'Y';
	b[0][1] = 'G';
	b[1][1] = 'B';
	scanf("%d%d%d", &n, &m, &t);
	FOR(i, 1, n) {
		FOR(j, 1, m) {
	  	    x = i+j; y = i-j+m;
			putchar(b[x/t%2][y/t%2]);
	  	}
	  	putchar(10);
	}
}

Measured memory_bytes: 512
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <x86intrin.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define V vector
template <typename T> bool chmin(T &a, const T &b) {if(a > b){a = b; return true;} return false;}
template <typename T> bool chmax(T &a, const T &b) {if(a < b){a = b; return true;} return false;}
template<typename A, size_t N, typename T> void Fill (A (&array)[N], const T & val) {fill ((T*)array, (T*)(array+N), val);}
V<int> dx = {-1, 1,  0, 0, -1, -1,  1, 1};
V<int> dy = { 0, 0, -1, 1, -1,  1, -1, 1};

int main () {
    ll n, x, m; cin >> n >> x >> m;
    V<ll> a(1, x);//初項から1個目のループ終了までを記憶
    map<ll, int> mp;//mp[i]:初めてiが出たindex
    ll y = x;
    int now = 0; mp[x] = now;
    ll loop_size, loop_start;//loopのサイズと開始のindex
    while (1) {
        now++;//今now項目を見ている
        ll ny = y * y % m;
        if (mp.count(ny)) {//もうnyが出てきてたら
            loop_size = now - mp[ny];
            loop_start = mp[ny];
            break;
        }
        mp[ny] = now;
        a.emplace_back(ny);
        y = ny;
    }
    ll ans = 0;
    
    if (n <= a.size()) {
        rep(i, n) ans += a[i];
        cout << ans << endl;
        return 0;
    }

    rep(i, loop_start) ans += a[i];
    n -= loop_start;
    ll loop_cnt = n / loop_size;
    V<ll> loop(loop_size);
    ll loop_sum = 0;
    for (int i = loop_start; i < a.size(); i++) {
        loop[i - loop_start] = a[i];
        loop_sum += a[i];
    }
    ans += loop_sum * loop_cnt;
    n %= loop_size;
    rep(i, n) ans += loop[i];
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 7164
#include <stdio.h>
 int main(void)
{
 int a,b,c;
 scanf("%d",&a);
 scanf("%d",&b);
 scanf("%d",&c);
 if(a<b&&b<c)
{
 printf("Yes\n");
 }
else{ printf("No\n");
 }
 return 0;
 } 


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

#define rep(i,s,n) for (int i = (int)s; i < (int)n; i++)
#define ll long long
#define pb push_back
#define eb emplace_back
#define All(x) x.begin(), x.end()
#define Range(x, i, j) x.begin() + i, x.begin() + j
#define lbidx(x, y) lower_bound(x.begin(), x.end(), y) - x.begin()
#define ubidx(x, y) upper_bound(x.begin(), x.end(), y) - x.begin()
#define llbidx(x, y, z) lower_bound(x.begin(), x.end(), z) - lower_bound(x.begin(), x.end(), y) // 二要素間の距離
#define deg2rad(deg) ((((double)deg)/((double)360)*2*M_PI))
#define rad2deg(rad) ((((double)rad)/(double)2/M_PI)*(double)360)
#define Find(set, element) set.find(element) != set.end()

typedef pair<int, int> PI;
typedef pair<ll, ll> PLL;

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

struct Query {
  int T, F;
  char C;
  int cnt;
};

int main() {
  string s;
  cin >> s;
  int Q;
  cin >> Q;
  vector<char> front;
  vector<char> back;

  vector<Query> query(Q);
  int T;
  int F;
  char C;
  rep(i, 0, Q) {
    cin >> T;
    if (T == 1) {
      query[i].T = 1;
    } else {
      query[i].T = 2;
      cin >> F >> C;
      query[i].F = F;
      query[i].C = C;
    }
  }

  reverse(All(query));

  int reverse_cnt = 0;
  rep(i, 0, Q) {
    if (query[i].T == 1) {
      reverse_cnt++;
    }
    if (query[i].T == 2) {
      query[i].cnt = reverse_cnt;
    }
  }

  if (reverse_cnt % 2 == 1) {
    reverse(All(s));
  }

  reverse(All(query));

  // rep(i, 0, Q) {
  //   cout << query[i].T << " " << query[i].F << " " << query[i].C << " " << query[i].cnt << endl;
  // }

  rep(i, 0, Q) {
    auto q = query[i];
    if (q.T == 2) {
      if (q.F == 1) {
        if (q.cnt % 2 == 0) {
          front.pb(q.C);
        }
        if (q.cnt % 2 == 1) {
          back.pb(q.C);
        }
      }
      if (q.F == 2) {
        if (q.cnt % 2 == 0) {
          back.pb(q.C);
        }
        if (q.cnt % 2 == 1) {
          front.pb(q.C);
        }
      }
    }
  }

  reverse(All(front));
  vector<char> ans;

  rep(i, 0, front.size()) {
    ans.pb(front[i]);
  }
  rep(i, 0, s.size()) {
    ans.pb(s[i]);
  }
  rep(i, 0, back.size()) {
    ans.pb(back[i]);
  }

  rep(i, 0, ans.size()) {
    cout << ans[i];
  }
  cout << endl;
  return 0;
};


Measured memory_bytes: 4536
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <algorithm>
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
const int mod= 1e+9+7;

int main(){
    ll n; cin>>n;
    vector<ll>a(n);
    rep(i,n)cin>>a[i];
    ll cnt=0,up,down;
    ll s;
    ll mx;
    for(int i=0;i<n;i++){
        up=1;down=1;
        if(a[i]<=a[i+1]){
            s=i;
            while(a[s]<=a[s+1]){
                up++;
                s++;
            }
        }
        if(a[i]>=a[i+1]){
            s=i;
            while(a[s]>=a[s+1]){
                down++;
                s++;
            }
        }
        mx=max(up,down);
        cnt++;
        i+=mx-1;
    }
    cout<<cnt<<endl;
}








Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define ALL(c) (c).begin(),(c).end()
#define EACH(i,c) for(auto i=(c).begin();i!=(c).end();++i)
using namespace std;
#define int long long


void solve(long long A, long long B, long long K){
	vector<int> v;
	for(int a = 1; a <= min(A,B); ++a) {
		if (A % a == 0 && B % a == 0) {
			v.push_back(a);
		}
	}
	reverse(ALL(v));
	cout << v[K - 1] << endl;
}

signed main(){
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    long long K;
    scanf("%lld",&K);
    solve(A, B, K);
    return 0;
}


Measured memory_bytes: 256
inte, sub = map(int, input().split(" "))
inte = inte % sub
t = [inte]
count = 0
while True:
    ab = abs(inte - sub)
    t.append(ab)
    if t[count] <= t[count + 1]:
        print(t[count])
        break
    else:
        count += 1
        
    

Measured memory_bytes: 2940
A, B, C, X, Y = map(int, input().split())
cost1 =  A+B; cost2 = C*2

if X == Y :
  print( X* min( cost1, cost2))
elif X > Y:
  a = Y * min( cost1, cost2) + ( X - Y) * A
  b = X * min( cost1, cost2)
  print( min( a, b))
else :
  a = X * min( cost1, cost2) + ( Y - X) * B
  b = Y * min( cost1, cost2)
  print( min(a,b))


Measured memory_bytes: 3064
#include<iostream>
using namespace std; //or std::cin et al.

int main() {
	int a,b,c;
	int sum,i;
	cin >> a >> b >> c;
	for ( i = a; i <= b; i++ ) {
		if ( c % i == 0 ) {
			sum++;
		}
	}
	cout << sum << endl;
	
	return 0;
}


Measured memory_bytes: 3136
#include <iostream>
#include <cstdio>
#include <vector>
#include <cstring>
#include <bitset>
#include <cmath>
#include <iomanip>
#include <stack>
#include <set>
#include <queue>
#include <algorithm>
#include <deque>
#include <map>
#include <cmath>
#include <iomanip>
using namespace std;

#define INF 1e18
#define int long long

template<typename T>
void printVec(vector<T> &v) {
    for(int i = 0; i < v.size(); i++) {
        cout << v[i] << " ";
    }
    cout << endl;
}

signed main() {
    int n, k; cin >> n >> k;
    int ans = 0;
    for(int i = 0; i < n; i++) {
        int h; cin >> h;
        if(h >= k) ans++;
    }

    cout << ans << endl;
    return 0;
}


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

int main() {
    int D, N; cin >> D >> N;
    int d = 1;
    for (int i = 0; i < D; i++)
    {
        d *= 100;
    }
    
    int cnt = 0;
    for (int i = d; i < 100000000; i+=d)
    {
        if(i%d==0 && i%(d*100)!=0) cnt++;
        if(cnt == N){
            cout << i << endl;
            return 0;
        }
    }       
}

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

int main() {
	using namespace std;
	ios_base::sync_with_stdio(false), cin.tie(nullptr);
	const __int128_t TEST_A = 1e9;
	const __int128_t TEST_B = 1e9;
	vector<__int128_t> regs(200000, 0);
	regs[0] = TEST_A;
	regs[1] = TEST_B;

	vector<tuple<char, int, int, int>> ops;
	auto plus = [&](int i, int j, int k) {
		regs[k] = regs[i] + regs[j];
		ops.emplace_back('+', i, j, k);
	};
	auto less = [&](int i, int j, int k) {
		regs[k] = regs[i] < regs[j];
		ops.emplace_back('<', i, j, k);
	};

	const int A[2] = {0, 1};
	const int R = 2;
	const int ZERO = 3;
	const int ONE = 4;
	plus(A[0], A[1], ONE);
	less(ZERO, ONE, ONE);

	auto neg = [&](int i, int j) {
		less(i, ONE, j);
	};

	auto either = [&](int i, int j, int k) {
		plus(i, j, k);
		less(ZERO, k, k);
	};
	const int SCRATCH1 = 5;
	const int SCRATCH2 = 6;
	auto both = [&](int i, int j, int k) {
		neg(i, SCRATCH1);
		neg(j, SCRATCH2);
		either(SCRATCH1, SCRATCH2, k);
		neg(k, k);
	};

	const int LG = 30;

	const int A_BITS[2] = {1000, 2000};
	const int SCRATCH = 10000;
	for (int z = 0; z < 2; z++) {
		plus(ZERO, ZERO, SCRATCH);
		for (int i = LG-1; i >= 0; i--) {
			plus(SCRATCH, SCRATCH, SCRATCH);
			plus(SCRATCH, ZERO, A_BITS[z]+i);
			for (int j = 0; j < i; j++) {
				plus(A_BITS[z]+i, A_BITS[z]+i, A_BITS[z]+i);
				plus(A_BITS[z]+i, ONE, A_BITS[z]+i);
			}
			less(A_BITS[z]+i, A[z], A_BITS[z]+i);
			plus(SCRATCH, A_BITS[z]+i, SCRATCH);
		}
	}

	const int R_BITS = 6000;
	for (int i = 0; i < LG; i++) {
		for (int j = 0; j < LG; j++) {
			both(A_BITS[0]+i, A_BITS[1]+j, SCRATCH);
			plus(R_BITS+i+j, SCRATCH, R_BITS+i+j);
		}
	}
	for (int i = 2*(LG-1); i >= 0; i--) {
		plus(R, R, R);
		plus(R, R_BITS+i, R);
	}

	assert(regs[2] == TEST_A * TEST_B);

	cout << ops.size() << '\n';
	for (auto [op, i, j, k] : ops) {
		cout << op << ' ' << i << ' ' << j << ' ' << k << '\n';
	}

	return 0;
}


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

typedef long long ll;
typedef pair<int, int> ii;

const int N = 1e5 + 5;
int n, m, a, b;
vector<int> e[N];
int d[N];

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

  cin >> n >> m;
  for (int i = 0; i < m; ++i) {
    cin >> a >> b;
    e[a].push_back(b);
    e[b].push_back(a);
  }

  queue<int> que;
  que.push(1);
  while (!que.empty()) {
    int u = que.front();
    que.pop();
    for (int v : e[u]) {
      if (d[v] == 0) {
        d[v] = u;
        que.push(v);
      }
    }
  }
  bool ok = true;
  for (int i = 2; i <= n; ++i) {
    if (d[i] == 0) ok = false;
  }

  if (ok) {
    cout << "Yes" << endl;
    for (int i = 2; i <= n; ++i) {
      cout << d[i] << endl;
    }
  } else {
    cout << "No" << endl;
  }
  
  return 0;
}


Measured memory_bytes: 10548
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <math.h>
#include <numeric>
#include <deque>
using namespace std;

int main() {
    int A, B;
    cin >> A >> B;
    int result = 0;
    int plus = A + B;
    int minus = A - B;
    int prod = A * B;
    cout << max(plus, max(minus, prod));
}


Measured memory_bytes: 888
#include<string>
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
    int n,i,j,x,c,w=0,e=0,left=0;
    string s;
    cin>>n>>s;
    for(i=1;i<n;i++){
        if(s[i]=='E')
            e++;
    }
    x=e+left;
    for(i=1;i<n;i++){
        if(s[i]=='E')
            e--;
        if(s[i-1]=='W')
            left++;
        if(e+left<x)
            x=e+left;
    }
    cout<<x<<endl;
}

Measured memory_bytes: 900
import java.util.*;
public class Main
{
  public static void main(String[]args)
  {
    Scanner take = new Scanner(System.in);
    while(take.hasNext())
    {
      int p = take.nextInt();
      int []a = new int[p];
      int np = 0;
      int i = 2;
      while(i<p)
      {
        if(prime(i))
        {
          a[i-1] = i;
        }
        i++;
      }
      for(int k = 0;k<a.length;k++)
      {
        if(a[k]!=0 & a[a.length-1-k]!=0)
        {
          np++;
        }
      }
      System.out.println(np);
    }
  }
  public static boolean prime(int i)
  {
    for(int j = 2;j<=i/2;j++)
    {
      if(i%j==0)
      {
        return false;
      }
    }
    return true;
  }
}

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

int main(){
    int x1, y1, x2, y2;
    cin>>x1>>y1>>x2>>y2;
    int x3, x4, y3, y4;
    int a = x2 - x1;
    int b = y2 - y1;
    x3 = x2 - b;
    y3 = y2 + a;
    x4 = x1 - b;
    y4 = y1 + a;
    cout<<x3<<" "<<y3<<" "<<x4<<" "<<y4<<endl;
    return 0;
}

Measured memory_bytes: 256
from collections import Counter

def primeFactorize(n):
  fac = []
  if n == 1: return fac
  while n%2 == 0:
    n //= 2
    fac.append(2)
  for i in range(3, int(n**0.5)+1, 2):
    while n%i == 0:
      n //= i
      fac.append(i)
  if n != 1: fac.append(n)
  return fac

n,p = map(int, input().split())
ans = 1
cnt = Counter(primeFactorize(p))

for k,v in cnt.items():
  if v < n: continue
  ans *= k**(v//n)
print(ans)

Measured memory_bytes: 9668
let s(a,b)=(b,a)open List;;let($)d c=match d with|[x;y;z]->(match c with|'N'->[y;s x;z]|'S'->[s y;x;z]|'E'->[s z;y;x]|'W'->[z;y;s x]|'Z'->[x;z;s y]|_->[])|_->[]and f()=Scanf.scanf"%d %d %d %d %d %d
"(fun a b c d e f->[(a,f);(b,e);(c,d)]);;let z=f();;print_endline(if mem(f())(concat(map(fun d->[d;d$'Z';d$'Z'$'Z';d$'Z'$'Z'$'Z'])[z;z$'N';z$'W';z$'E';z$'S';z$'S'$'S']))then"Yes"else"No")

Measured memory_bytes: 2272
K = int(input())


S = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]

print(S[K-1])

Measured memory_bytes: 3060
/*
[abc118] D - Match Matching
*/

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;

const int r[10] = {6, 2, 5, 5, 4, 5, 6, 3, 7, 6};

const int MAX_N = 1e4;

int N, M;
int A[10];
int dp[10][MAX_N + 10];

inline void chmax(int &a, int v) { a = max(a, v); }

string solve() {
    sort(A, A + M);

    memset(dp, -1, sizeof(dp));
    for (int i = 0; i < M; i++) {
        dp[i][0] = 0;
        for (int j = 1; j <= N; j++) {
            if (i - 1 >= 0) {
                chmax(dp[i][j], dp[i - 1][j]);
            }
            if (j - r[A[i]] >= 0 && dp[i][j - r[A[i]]] >= 0) {
                chmax(dp[i][j], dp[i][j - r[A[i]]] + 1);
            }
        }
    }

    string ans;
    for (int i = M - 1, j = N; i >= 0 && j > 0;) {
        if (j - r[A[i]] >= 0 && dp[i][j - r[A[i]]] == dp[i][j] - 1) {
            j -= r[A[i]];
            ans.push_back('0' + A[i]);
        } else {
            i--;
        }
    }

    return ans;
}

int main() {
    cin >> N >> M;
    for (int i = 0; i < M; i++) {
        cin >> A[i];
    }

    cout << solve() << endl;

    return 0;
}


Measured memory_bytes: 640
/**
 * File              : A.cpp
 * Author            : JCHRYS <jchrys@me.com>
 * Date              : 12.01.2020
 * Last Modified Date: 12.01.2020
 * Last Modified By  : JCHRYS <jchrys@me.com>
 */
#include <bits/stdc++.h>
using namespace std;

int main() {
    char c;
    cin >> c;
    cout << char(c+1);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rg register
string s;
int ans,flag,l;
int main() 
{
    cin>>s;
	ans=(s.length()-1)*9;
    for(int i=1;i<s.length();i++) 
        if(s[i]!='9') 
            flag=1;
    if(flag==0) 
         cout<<ans+s[0]-'0'<<endl;
    else 
         cout<<ans+s[0]-'1'<<endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
 
public class Main {
	
    public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
    	int A = sc.nextInt();
    	int B = sc.nextInt();
    	int C = sc.nextInt();
    	int max = Math.max(A, Math.max(B, C));
    	int min = Math.min(A, Math.min(B, C));
    	int mid = A+B+C-max-min;
    	int dir = max-mid;
    	int tmp = min+dir;
    	int res = (max-tmp)%2 == 0 ? (max-tmp)/2 : (max-tmp+1)/2+1;
    	System.out.println(dir+res);
    }
}

Measured memory_bytes: 21972
type ABC(stream:System.IO.TextReader) =
  member this.Scan1 f = stream.ReadLine() |> f
  member this.Scan2 f = stream.ReadLine().Split() |> Array.map f |> (fun a -> (a.[0], a.[1]))
  member this.Scan3 f = stream.ReadLine().Split() |> Array.map f |> (fun a -> (a.[0], a.[1], a.[2]))
  member this.Scan4 f = stream.ReadLine().Split() |> Array.map f |> (fun a -> (a.[0], a.[1], a.[2], a.[3]))
  member this.ScanVecH f = stream.ReadLine().Split() |> Array.map f
  member this.ScanVecV n f = [| for i in 1..n -> stream.ReadLine() |> f |]
  member this.ScanMatrix n f  = [ for i in 1..n do yield stream.ReadLine().Split() |> Array.map f ]
  member this.ScanCharMatrix n = [| for i in 1..n -> stream.ReadLine().ToCharArray() |]
  member this.Close () = stream.Close()

let util = ABC(stdin)
  
let N, M = util.Scan2 int
let As = util.ScanVecH int |> Array.sort

if N >= M
  then 0
  else
    let L = (Array.last As) - (Array.head As)
    let lmin =
      As
      |> Array.pairwise
      |> Array.map (fun (a,b)-> b-a)
      |> Array.sortDescending
      |> Array.take (N - 1)
      |> Array.sum
    L - lmin
|> printfn "%d"

util.Close()

Measured memory_bytes: 28248
n, k=map(int, input().split())
a=list(int(input()) for i in range(n))
a.sort()
b=a[n-1]
for i in range(n-k+1):
  if(b>a[i+k-1]-a[i]):
      b=a[i+k-1]-a[i]
print(int(b))


Measured memory_bytes: 7396
#include<bits/stdc++.h>
#include <iostream>
#include <numeric>
#include <math.h>
#define ll  long long
#define ull unsigned long
#define mpa make_pair
#define pb push_back
#define ff first
#define pii pair<ll,ll>
#define dd double
#define trace(x) cerr << #x << " : " << x << endl
#define ss second
#define boost ios_base::sync_with_stdio(0)
#define forp(i,a,b) for(ll i=a;i<=b;i++)
#define rep(i,n)    for(ll i=0;i<n;++i)
#define ren(i,n)    for(ll i=n-1;i>=0;i--)
#define forn(i,a,b) for(ll i=a;i>=b;i--)
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(typeof((c).begin()) i = (c).begin(); i != (c).end();
#define sc(x) scanf("%lld",&x)
#define clr(x,val) memset(x,val,sizeof(x))
#define pr(x) printf("%lld\n",x) 
#define gc getchar
#define pdd pair<dd,dd>
#define prec(x) cout<<fixed<<setprecision(x)
using namespace std;
pii cord[1000005],quer[1000005];
int main(){
	ll s=1,h1,s1,h2,s2;
	cin>>h1>>s1>>h2>>s2;
	string ans="Yes";
	
    while(1){
		if(s%2)h2-=min(h2,s1);
		else h1-=min(h1,s2);
		//cout<<s<<" "<<h2<<" "<<h1<<endl;
		if(h1==0){
			ans="No";
			break;
		}
		if(h2==0){
			ans="Yes";
			break;
		}
		s++;
	}
	cout<<ans;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <iostream>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;

const int INF = 0x3f3f3f3f;
const int MAXN = 1e5 + 5;

int n,len,ans = INF;
int head[MAXN],in[MAXN],dis[MAXN];

struct Edge{
	int to,next,w;
} e[MAXN * 20];

void add(int u,int v,int w){
	e[++len].to = v;
	e[len].next = head[u];
	e[len].w = w;
	head[u] = len;
}

void spfa(int s){
	queue<int> q;
	memset(dis,0x3f,sizeof(dis));
	memset(in,0,sizeof(in));
	q.push(s);
	dis[s] = s;
	while(!q.empty()){
		int u = q.front();
		q.pop();
		in[u] = 0;
		for(int i = head[u];i != -1;i = e[i].next){
			int v = e[i].to;
			if(dis[v] > dis[u] + e[i].w){
				dis[v] = dis[u] + e[i].w;
				if(!in[v]){
					in[v] = 1;
					q.push(v);
				}
			}
		}
	}
}

int main(){
    //freopen(".in","r",stdin);
    //freopen(".out","w",stdout);
    memset(head,-1,sizeof(head));
	scanf("%d",&n);
	for(int i = 1;i < n;i++){
		for(int j = 0;j <= 9;j++)
		    add(i,(i * 10 + j) % n,j);
	}
	for(int i = 1;i <= 9;i++){
		spfa(i);
		ans = min(ans,dis[0]);
	}
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 15036
def sec_to_time(sec):
  h = sec // 3600
  m = sec // 60 - h * 60
  s = sec % 60
  print(str(h).zfill(2) + ":" + str(m).zfill(2) + ":" + str(s).zfill(2))

def solve(h, m, s):
  sec = 7200 - (3600 * h + 60 * m + s)
  sec_to_time(sec)
  sec_to_time(sec * 3)

while True:
  h, m, s = map(int, input().split())
  if h == -1:
    break
  solve(h, m, s)


Measured memory_bytes: 5592
#include <bits/stdc++.h>
using namespace std;
char a[110];
int main()
{
	int n, m;
	
	scanf("%d%d", &n, &m);
	for (int i = 0; i < m + 2; i++) {
		putchar('#');
	}
	puts("");
	for (int i = 0; i < n; i++) {
		putchar('#');
		scanf("%s", a);
		printf("%s#\n", a);
	}
	for (int i = 0; i < m + 2; i++) {
		putchar('#');
	}
	puts("");
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Scanner;

public class Main {
	public static void main(String args[]) {
		Scanner scan = new Scanner(System.in);
		String str1 = scan.nextLine();
		String str2 = scan.nextLine();
		scan.close();

		int n = Integer.parseInt(str1);
		String[] num = str2.split(" ", 0);
		ArrayList<String> numList = new ArrayList<String>();

		for (int i = 0; i < n; i++) {
			numList.add(num[i]);
		}

		for (int i = n - 1; 0 <= i; i--) {
			System.out.print(numList.get(i));
			if (i != 0) {
				System.out.print(" ");
			}else{
				System.out.println("");
			}
		}
	}
}

Measured memory_bytes: 26332
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;
import java.util.TreeSet;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		int k = sc.nextInt();
		sc.close();

		TreeSet<Integer> chSet = new TreeSet<Integer>();
		for (int i = 0; i < s.length(); i++) {
			int ch = s.charAt(i) - 'a';
			chSet.add(ch);
		}

		Set<Integer> idxSet = new HashSet<Integer>();
		TreeSet<String> strSet = new TreeSet<String>();
		for (int nextCh : chSet.toArray(new Integer[0])) {
			for (int i = 0; i < s.length(); i++) {
				char ch = s.charAt(i);
				if (ch - 'a' == nextCh) {
					idxSet.add(i);
				}
			}

			for (int i = 1; i <= 5 && idxSet.size() > 0; i++) {
				for (int idx : idxSet.toArray(new Integer[0])) {
					if (idx + i <= s.length()) {
						String str = s.substring(idx, idx + i);
						strSet.add(str);
					} else {
						idxSet.remove(idx);
					}
				}
			}

			if (strSet.size() >= k) {
				break;
			}
		}

		System.out.println(strSet.toArray(new String[0])[k - 1]);
	}
}


Measured memory_bytes: 23764
import sys
from pprint import pprint

nCr_memo = {}

def solve(n, s):
  count_list = []
  #pprint(count_list)

  alpha2num = lambda c: ord(c) - ord('a')
  count = {}
  count_str_set = set()

  for i in xrange(n):
    #print s[i]
    count_list.append([0] * 26)
    for s_i in xrange(10):
      #print s[i][s_i]
      pos = alpha2num(s[i][s_i])
      count_list[i][pos] += 1
      #print s[i][s_i], pos, count_list[i][pos]
    
    #pprint(count_list[i])
    count_str = "".join(map(str, count_list[i]))
    #print count_str
    if count_str in count_str_set:
      count[count_str] += 1
    else:
      count_str_set.add(count_str)
      count[count_str] = 1

  ans = 0
  for count_str, c in count.items():
    if c == 1:
      continue
    ans += nCr(c, 2)

  return ans


def nCr(n, r): 
    key = str(n) + '_' + str(r)
    if key in nCr_memo:
        return nCr_memo[key]

    a = 1 
    b = 1 
    for i in range(r):
        a *= (n - i)
        b *= (i + 1)

    nCr_memo[key] = a / b
    return nCr_memo[key]
  

if __name__ == '__main__':

  n = int(sys.stdin.readline().strip())
  s = []
  for _ in xrange(n):
    s.append(sys.stdin.readline().strip())
  print solve(n, s)

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

int main() {

    string s;
    cin >> s;

    long long  ans = 0, sum = 0, ret = 0;
    int i, j;

    for(i=0; i< (1<<(s.length()-1)); i++) {
        ret = s[0] - '0';
        sum = 0;

        for(j=0; j<(s.length()-1); j++) {
            if(i & (1<<j )) {
                sum += ret;
                ret = 0;
            }
            ret = ret*10 + s[j+1] - '0';
        }
        
        sum += ret;
        ans += sum;
    }
    printf("%lld\n", ans);

}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)

typedef long long ll;


vector<int> vs[500];

int main(void) {
  int n;
  scanf("%d", &n);
  ll k = 1;
  while(k*(k-1) < 2*n) {
    ++k;
  }
  if(k*(k-1) != 2*n) {
    puts("No");
    return 0;
  }
  // cerr << "> " << k << endl;
  int cur = 1;
  REP(i, k-1) {
    int start = cur;
    while((int)vs[i].size() < k-1) {
      vs[i].push_back(cur);
      ++cur;
    }
    REP(j, cur-start) {
      vs[i+j+1].push_back(start+j);
    }
  }
  puts("Yes");
  printf("%lld\n", k);
  REP(i, k) {
    printf("%lld", k-1);
    REP(j, k-1) {
      printf(" %d", vs[i][j]);
    }
    puts("");
  }
  
  return 0;
}


Measured memory_bytes: 2304
A, B = map(int,input().split())
def gcd(a,b):
    if a < b:
        a,b = b,a
    if b == 0: return a
    r = a % b
    return gcd(b,r)

L = [1]

g = gcd(A, B)
g_copy = gcd(A, B)
i = 2
while g > 1:
    if i > g_copy ** (1/2) :
        if g != 1:
            L.append(i)
        break
    if g % i == 0:
        if L[-1] != i:
            L.append(i)
        g /= i
    else:
        i += 1
print(len(L))


Measured memory_bytes: 3064
#-------------------------------------------------------------------
import sys
def p(*_a):
  _s=" ".join(map(str,_a))
  #print(_s)
  sys.stderr.write(_s+"\n")
#-------------------------------------------------------------------

S = input()
S = S[::-1]

m = 2019

A=[0]*m
A[0]=1

a = 0
ans=0
for i,s in enumerate(S):
	a = a + (int(s) * pow(10,i,m))
	a %= m
	
	ans += A[a]
	A[a] += 1

print(ans)
	

Measured memory_bytes: 9296
#include<iostream>
#include<vector>
#include<algorithm>
 
#define ll long long
ll MAX = 1000000000+7;
 
using namespace std;
 
ll modF(ll a) {
    if (a<0) return modF((a%MAX)+MAX);
    else return (a%MAX);
}
 
int main() {
    ll t;
    t = 1;
    while (t--) {
        ll n, k, i, a, po=0, ni=0, ans=1;
        vector<ll> vcp, vcn;
        cin >> n >> k;
        for (i=0;i<n;i++) {
            cin >> a;
            if (a<0) {
                a=-a;
                ni++; vcn.push_back(a);
            }
            else {
                po++; vcp.push_back(a);
            }
        }
        if (po>0) sort(vcp.begin(),vcp.end());
        if (ni>0) sort(vcn.begin(),vcn.end());
 
        if (po==0) {
            if (k%2==0) {
                for (i=0;i<k;i++) {
                    ans = ans * (-vcn[ni-1]);
                    ans = modF(ans);
                    ni--;
                }
            }
            else {
                for (i=0;i<k;i++) {
                    ans = ans * (-vcn[i]);
                    ans = modF(ans);
                }
            }
        }
        else if (ni==0) {
            for (i=0;i<k;i++) {
                ans = ans * vcp[po-1];
                ans = modF(ans);
                po--;
            }
        }
        else {
            if (k%2==1) {
                ans = vcp[po-1];
                po--; k--;
            }
            while (k>1 && (po>=2 || ni>=2)) {
                ll propo = 0;
                if (po>=2) propo = vcp[po-1]*vcp[po-2];
                ll proni = 0;
                if (ni>=2) proni = vcn[ni-1]*vcn[ni-2];
 
                if (propo>proni) {
                    propo = modF(propo);
                    ans = ans*propo;
                    ans = modF(ans);
                    po = po-2;
                }
                else {
                    proni = modF(proni);
                    ans = ans*proni;
                    ans = modF(ans);
                    ni = ni-2;
                }
                k=k-2;
            }
            while (k>0) {
                if (po>0) {
                    ans = ans*vcp[po-1];
                    ans = modF(ans);
                    po--; k--;
                }
                else if (ni>0) {
                    ans = ans*(-vcn[ni-1]);
                    ans = modF(ans);
                    ni--; k--;
                }
            }
        }
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 5528
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#define FOR(i, a, n) for(int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define SORT(a) sort(a.begin(),a.end())
using namespace std;
int main(){
    //Seiranchan!
    int a,b,c,X,cnt=0;
    cin >> a >> b>> c>>X;

    for(int i=0;i<=a;i++){
        for(int j=0;j<=b;j++){
            for(int k=0;k<=c;k++){
                if(500*i+100*j+50*k==X){
                    cnt++;
                }
            }
        }
    }
    cout << cnt << endl;
}


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

#define IO std::ios_base::sync_with_stdio(false); std::cin.tie(NULL); std::cout.tie(NULL);
#define FIN freopen("entrada.in", "r", stdin);
#define FOUT freopen("saida.sol", "w", stdout);

#define ull unsigned long long
#define ll long long
#define pii pair<int, int>
#define pb push_back
#define MAX int(1e6+4)

const int INF = 0x3f3f3f3f;
using namespace std;

int main() {

    IO
    int x, n, dif = INT_MAX;
    cin >> x >> n;
    int ind = x;
    if (n == 0) {
        cout << x << "\n";
        return 0;
    }
    vector<int> vet(n);
    for (int &i:vet) cin >> i;
    sort(vet.begin(), vet.end());
    for (int i = 0; i <= vet.back() + 1; i++)
        if (!binary_search(vet.begin(), vet.end(), i) && abs(i - x) < dif)
            dif = abs(x - i), ind = i;

    cout << ind << "\n";

    return 0;
}

Measured memory_bytes: 3660
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1000000009LL;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }


int main() {
    vector<ll> n(3); rep(i,3) cin >> n[i];
    if(n[0]%2==0 || n[1]%2==0 || n[2]%2==0) cout << 0 << ln;
    else{
        sort(all(n));
        cout << n[0]* n[1] << ln;
    }
}


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

int main () {
 char c;
 cin >> c;
 
 if ( c == 'a' ||  c == 'i' || c == 'u' || c == 'e' || c == 'o' ) {
   cout << "vowel" << endl;
 } else {
   cout << "consonant" << endl;
 }
}

Measured memory_bytes: 256
#include<stdio.h>
#define MAX 1000000

int main(void){
  int i,j,c;
  int a,d,n;
  char p[MAX];
	
  p[0]=0;
  p[1]=0;
  p[2]=1;
  for(i=3;i<MAX;i+=2)p[i]=1;
  for(i=4;i<MAX;i+=2)p[i]=0;

  c = 3;  
  while(1){
    if(p[c]){
      for(i=2*c;i<MAX;i+=c)p[i] = 0;
    }
    while(!p[++c]);
    if(c>1000)break;
  }
  
  while(1){
    scanf("%d %d %d ",&a,&d,&n);
    if(!a && !d && !n)break;
    c = 0;
    i = 0;
    while(1){
      if(p[a+i*d])c++;
      if(n==c){
	printf("%d\n",a+i*d);
	break;
      }
      i++;
    }
  }
  return 0;
}

Measured memory_bytes: 0