akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;

int main() {
    int a, b;
    cin >> a >>b;
    while (a!=0 && b!=0) {
        for(int i=0; i<a; i++) {
            for(int j=0; j<b; j++) {
                if (i==0 || i+1==a || j==0 || j+1==b ) {
                    cout <<'#';
                } else {
                    cout <<'.';
                }
            }
            cout << endl;
        }
        cout << endl;
        cin >> a >> b;
    }
    return 0;
}


Measured memory_bytes: 3096
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#define repi(i, n) for (int i = 0; i <= (n); i++)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
using namespace std;

int main() {
	string S;
	cin >> S;
  deque<int> d;
	int ans = 0;
	rep(i,S.size()){
		if(d.empty()){
			d.push_front(S[i] - '0');
			continue;
		}
		int top = d.front();
		if((S[i] - '0') != top){
			d.pop_front();
						ans+=2;
		}else {
			d.push_front(S[i] - '0');
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 768
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric, std.container, std.range;

enum P = 998244353L;

void main()
{
    auto abcd = readln.split.to!(long[]);
    auto A = abcd[0];
    auto B = abcd[1];
    auto C = abcd[2];
    auto D = abcd[3];
    auto DP = new long[][][](C+1, D+1, 2);
    DP[A][B][0] = 1;
    foreach (i; A..C+1) {
        foreach (j; B..D+1) {
            if (i == A && j == B) continue;
            DP[i][j][0] = (DP[i][j-1][0] * i % P + DP[i][j-1][1]) % P;
            DP[i][j][1] = (DP[i-1][j][0] + DP[i-1][j][1]) * j % P;
        }
    }
    writeln((DP[C][D][0] + DP[C][D][1]) % P);
}

Measured memory_bytes: 437552
#include<stdio.h>
int main(void) {
	char s[101];
	int flag1 = 0;
	int flag2 = 0;
	
	for (int k = 0; k < 101; k++) s[k] = '0';
	scanf("%s", s);

	for (int i = 1; i < 102; i++) {
		if (i % 2 == 0) {
			switch (s[i-1]) {
				case 'L':
				case 'U':
				case 'D':
				case '0':
					break;
				case 'R':
					flag1 = 1;
					break;
			}
		}
		else if(i % 2 == 1){
			switch (s[i-1]) {
				case 'R':
				case 'U':
				case 'D':
				case '0':
					break;
				case 'L':
					flag2 = 1;
					break;
			}
		}
	}
	if (flag1 == 0 && flag2 == 0) puts("Yes");
	else puts("No");

	return 0;
}

Measured memory_bytes: 128
n, k = (int(i) for i in input().split())
used = [0 for i in range(n)]
for i in range(k):
    val = int(input())
    a = [int(j) for j in input().split()]
    for aa in a:
        used[aa - 1] = 1
cnt = 0
for i in used:
    cnt += i == 0
print(cnt)


Measured memory_bytes: 67724
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define all(x) (x).begin(),(x).end()
#define INF 10000000
using ll = long long ;
ll gcd(ll a, ll b) {
  if(b == 0) return a;
  return gcd(b, a % b);
}
template< int id > struct CompTupleBy
{
  template<class T> 
  bool operator()( const T& a, const T& b ) const {
    return std::get<id>(a) < std::get<id>(b);
  }
};

using namespace std;

int main(){
    int n;
    cin >> n;
    int a1[n];
    int a2[n];
    rep(i,n){
        cin >> a1[i];
    }
    rep(i,n){
        cin >> a2[i];
    }
    int ans = a1[0]+a2[n-1];
    for(int i=n-1;i>0;i--){
        ans += a1[i];
    }
    int first=0,second=0,tmp_diff;
    int diff =0;
    for(int i=n-1;i>0;i--){
        first +=a1[i];
        second += a2[i-1];
        tmp_diff = second - first;
        diff = max(diff,tmp_diff);
    }
    cout << ans + diff << endl;
    
}

Measured memory_bytes: 256
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.NoSuchElementException;
import java.util.Random;

class Main {
	public static void main(String[] args) {
		new Main().run();
	}
	
	void run() {
		FastScanner sc=new FastScanner();
		PrintWriter pw=new PrintWriter(System.out);
		char[][] cs=new char[3][3];
		for(int i=0;i<3;++i)cs[i]=sc.next().toCharArray();
		pw.println(String.valueOf(cs[0][0])+String.valueOf(cs[1][1])+String.valueOf(cs[2][2]));
		pw.close();
	}

	
	static void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}

}


class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    public int nextInt() {
    	return Integer.parseInt(next());
    }
    
    public long nextLong() {
    	return Long.parseLong(next());
    }
}

Measured memory_bytes: 21204
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<(b);i++)
#define erep(i,a,b) for(int i=a;i<=(int)(b);i++)
#define per(i,a,b) for(int i=(b)-1;i>(a);i--)
#define eper(i,a,b) for(int i=((int)(a));i>=b;i--)
#define pb push_back
#define mp make_pair
#define INF (1<<30)-1
#define MOD 1000000007
using namespace std;
typedef long long ll;
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
int gcd(int a,int b){return b?gcd(b,a%b):a;}

string s;
int main() {
 ios::sync_with_stdio ( false );
 cin.tie ( 0 );
    cin >> s;
    s[3] = '8';
    cout << s << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main(String[] args) throws Exception{
		Scanner scn = new Scanner(System.in);
		String s = scn.next();
		String[] list = s.split("");
      	 if(s.length()%2==1){
     	 System.out.println("No");
           return;
         }else{
      	Arrays.sort(list);
      	String x = list[0];
      	int count = 0;
      	for(int i=0;i<s.length();i++){
        if(x.equals(list[i])){
          count++;
        }else{
          if(count%2==1){
            System.out.println("No");
            return;
          }
          count = 1;
          x = list[i];
        }
        }
      	System.out.println("Yes");
    }
	}
}


Measured memory_bytes: 35564
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define tr(container, it) \
	for (auto it = container.begin(); it != container.end(); it++)
#define scontains(c,x) ((c).find(x) != (c).end())   //O(log n) 
#define contains(c,x) (find((c).begin(),(c).end(),x) != (c).end()) //O(n)
#define Ichar(_x) char _x;scanf("%c",&_x);
#define Iint(_x) int _x;scanf("%d",&_x); 
#define Ill(_x)  ll _x;scanf("%lld",&_x);
#define inc(a,b,x)(x)>a && (x)<b	
#define incE(a,b,x)(x)>=a && (x)<=b	
//freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);

vector<pair<int,int>> factorize(int n)
{
	vector<pair<int, int>> vp;
	int primes[] = { 2,3,5,7,11,13,17,19,23,29,31,37 };
	for (int i = 0; i < 12; ++i)
	{
		int m = 0;
		while (n%primes[i]==0)
		{
			n = n / primes[i];
			m++;
		}
		if (m > 0)vp.push_back(make_pair(primes[i], m));
	}
	for(auto a :vp)
	{
		std::cout << a.first <<":" << a.second <<"\n";
	}

	return vp;

}
int main()
{
	Iint(n);
	int s1=0, s2=0, s3=0;
	for (int i = 0; i < n; ++i)
	{
		Iint(t);
		if (t % 4 == 0)s3++;
		else { if (t % 2 == 0)s2++;
		else { s1++; }
		}
	}
	if(s3>=(s1 - (s2<1)))std::cout << "Yes";
	else { std::cout << "No"; }




}




Measured memory_bytes: 256
from math import factorial
N, M = map(int, input().split())

if abs(N - M) > 1:
    print(0)
elif abs(N - M) == 1:
    print((factorial(N) * factorial(M)) % (10**9 + 7))
else:
    print((2 * factorial(N) * factorial(M)) % (10**9 + 7))

Measured memory_bytes: 5172
while gets
  l = $_.chomp
  t = 8
  t = 7 if l != ""
  t.times do
    l << gets.chomp
  end
  puts "A" if l.include?("1100000011")
  puts "B" if l.include?("1000000010000000100000001")
  puts "C" if l.include?("1111")
  puts "D" if l.include?("1000000110000001")
  puts "E" if l.include?("11000000011")
  puts "F" if l.include?("100000001100000001")
  puts "G" if l.include?("110000011")
end

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

int main(){
  int A, B, K;
  cin >> A >> B >> K;
  for(int i = min(A,B); i >= 1; i--){
    if(A % i == 0 && B % i == 0){
      K--;
      if(K == 0){
        cout << i << endl;
      }
    }
  }
    
}
    

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
using namespace std;

const long long INF = LLONG_MAX / 2;

class Edge
{
public:
    int to, dist;
    Edge(int to, int dist){
        this->to = to;
        this->dist = dist;
    }
};

int main()
{
    int n, m, init;
    cin >> n >> m >> init;
    vector<int> tree(n);
    for(int i=0; i<n; ++i)
        cin >> tree[i];

    vector<vector<Edge> > edges(n);
    for(int i=0; i<m; ++i){
        int a, b, t;
        cin >> a >> b >> t;
        -- a;
        -- b;
        if(t <= tree[a])
            edges[a].push_back(Edge(b, t));
        if(t <= tree[b])
            edges[b].push_back(Edge(a, t));
    }

    vector<long long> dp(n, -INF);
    priority_queue<pair<long long, int> > pq;
    dp[0] = init;
    pq.push(make_pair(init, 0));
    while(!pq.empty()){
        long long h;
        int curr;
        tie(h, curr) = pq.top();
        pq.pop();
        if(h < dp[curr])
            continue;

        for(const Edge& e : edges[curr]){
            long long h2 = min((long long)tree[e.to], h - e.dist);
            if(dp[e.to] < h2){
                dp[e.to] = h2;
                pq.push(make_pair(h2, e.to));
            }
        }
    }

    long long ans = -1;
    if(dp[n-1] > -INF)
        ans = tree[n-1] - dp[n-1] * 2 + init;
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 14796
#include<iostream>

using namespace std;

int main(void){

 int A[3],sum=0,i;

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

 if(sum>=22) cout<<"bust"<<endl;
 else cout<<"win"<<endl;

  return 0;
}


Measured memory_bytes: 256
N, K = [int(x) for x in input().split()]
P = [int(x) for x in input().split()]

#初期
SUM = [0]*N
SUM[0] = sum(P[0:K])

for i in range(N - K):
    SUM[i+1] = SUM[i]-P[i] + P[i+K]

EXP_V = (K + max(SUM))/2
print(EXP_V)

Measured memory_bytes: 24688
#include <iostream>

using namespace std;
int field[50][50];
int w, h, ans;
int dx[8] = {-1, 0, 1, -1, 1, -1, 0, 1}, dy[8] = {-1, -1, -1, 0,  0, 1, 1, 1};

void check(int x, int y)
{
    if (field[x][y])
        field[x][y] = 0;
    else
        return;
        
    for (int i=0; i<8; i++) {
        int nx = x+dx[i], ny = y+dy[i];
        if (0<= nx && nx<w && 0<=ny&&ny<h) {
            check(nx, ny);
        }
    }
}

int main()
{
    while (cin>>w>>h, w||h) {
        for (int y=0; y<h; y++) {
            for (int x=0; x<w; x++) {
                int i; cin >> i;
                field[x][y] = i;
                }
           }
       
       ans = 0;
       for (int y=0; y<h; y++) {
          for (int x=0; x<w; x++) {
               if (field[x][y]) {
                       ans++;
                       check(x, y);
               }  
            }   
        }

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

Measured memory_bytes: 1236
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
using namespace std;
#define F first
#define S second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define SZ(x) (int)(x).size()
#define int ll

vector<pair<int, int>> merge(vector<pair<int, int>> &a, vector<pair<int, int>> &b) {
	int ptr1 = 0, ptr2 = 0;
	vector<pair<int, int>> res;
	while (ptr1 < SZ(a) && ptr2 < SZ(b)) {
		if (a[ptr1] < b[ptr2]) {
			if (res.empty() || a[ptr1].S < res.back().S) {
				res.pb(a[ptr1]);
			}
			ptr1++;
		}
		else {
			if (res.empty() || b[ptr2].S < res.back().S) {
				res.pb(b[ptr2]);
			}
			ptr2++;
		}
	}
	while (ptr1 < SZ(a)) {
		if (res.empty() || a[ptr1].S < res.back().S) {
			res.pb(a[ptr1]);
		}
		ptr1++;
	}
  while (ptr2 < SZ(b)) {
    if (res.empty() || b[ptr2].S < res.back().S) {
      res.pb(b[ptr2]);
    }
    ptr2++;
  }
	return res;
}

const int N = 2e5 + 10;
vector<pair<int, int>> g[N], have[N];

void dfs(int V, int p, int mx) {
	if (SZ(g[V]) == 1) {
		have[V].pb({0, 0});
		return;
	}
	int u = -1, cu, v, cv;
	for (auto it : g[V]) {
		if (it.F != p) {
			dfs(it.F, V, mx);
			if (u == -1) {
				u = it.F;
				cu = it.S;
			}
			else {
				v = it.F;
				cv = it.S;
			}
		}
	}
	vector<pair<int, int>> kek1, kek2;
	int ptr = 0;
	for (auto it : have[u]) {
		while (ptr + 1 < SZ(have[v]) && it.S + cu + cv + have[v][ptr + 1].F <= mx) {
			ptr++;
		}
		if (ptr >= SZ(have[v])) {
			break;
		}
		if (it.S + cu + cv + have[v][ptr].F <= mx) {
			if (kek1.empty() || kek1.back().S > have[v][ptr].S + cv) {
				kek1.pb({it.F + cu, have[v][ptr].S + cv});
			}
		}
	}
	ptr = 0;
	for (auto it : have[v]) {
		while (ptr + 1 < SZ(have[u]) && it.S + cu + cv + have[u][ptr + 1].F <= mx) {
			ptr++;
		}
		if (ptr >= SZ(have[u])) {
			break;
		}
		if (it.S + cu + cv + have[u][ptr].F <= mx) {
			if (kek2.empty() || kek2.back().S > have[u][ptr].S + cu) {
				kek2.pb({it.F + cv, have[u][ptr].S + cu});
			}
		}	
	}
	have[V] = merge(kek1, kek2);
}

signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
	int n;
	cin >> n;
	for (int i = 1; i < n; i++) {
		int a, vl;
		cin >> a >> vl;
		g[a].pb({i + 1, vl});
		g[i + 1].pb({a, vl});
	}
	int l = -1, r = 1e12;
	while (r - l > 1) {
		int mid = (l + r) / 2;
		for (int i = 1; i <= n; i++) {
			have[i] = {};
		}
		dfs(1, 0, mid);
		if (have[1].empty()) {
			l = mid;
		}
		else {
			r = mid;
		}
	}
	cout << r << '\n';
} 


Measured memory_bytes: 41556
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 1; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))

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

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

using namespace std;

using Value = int32_t;

constexpr Value maxN = 100000;

Value calc(Value const n) {
  if (n < 6) {
    return n;
  }

  if (n < 9) {
    return n - 5;
  }

  std::vector<Value> base9s;
  Value d = 1;
  base9s.insert(base9s.begin(), d);
  for (int i = 0;; ++i) {
    d *= 9;
    if (d > maxN) {
      break;
    }
    base9s.insert(base9s.begin(), d);
  }
  std::vector<Value> base6s;
  d = 1;
  base6s.insert(base6s.begin(), d);
  for (int i = 0;; ++i) {
    d *= 6;
    if (d > maxN) {
      break;
    }
    base6s.insert(base6s.begin(), d);
  }

  Value ret = 0;
  std::vector<int> digit9_maxs(base9s.size(), 0);
  Value nn = n;
  for (int i = 0; i < digit9_maxs.size(); ++i) {
    digit9_maxs[i] = nn / base9s[i];
    ret += digit9_maxs[i];
    nn %= base9s[i];
  }

  for (int d0 = 0; d0 < 9; ++d0) {
    Value const nn0 = n - d0 * base9s[0];
    if (nn0 < 0) {
      break;
    }
    if (d0 >= ret) {
      break;
    }
    for (int d1 = 0; d1 < 9; ++d1) {
      Value const nn1 = nn0 - d1 * base9s[1];
      if (nn1 < 0) {
        break;
      }
      Value const dd1 = d0 + d1;
      if (dd1 >= ret) {
        break;
      }
      for (int d2 = 0; d2 < 9; ++d2) {
        Value const nn2 = nn1 - d2 * base9s[2];
        if (nn2 < 0) {
          break;
        }
        Value const dd2 = dd1 + d2;
        if (dd2 >= ret) {
          break;
        }
        for (int d3 = 0; d3 < 9; ++d3) {
          Value const nn3 = nn2 - d3 * base9s[3];
          if (nn3 < 0) {
            break;
          }
          Value const dd3 = dd2 + d3;
          if (dd3 >= ret) {
            break;
          }
          for (int d4 = 0; d4 < 9; ++d4) {
            Value const nn4 = nn3 - d4 * base9s[4];
            if (nn4 < 0) {
              break;
            }
            Value const dd4 = dd3 + d4;
            if (dd4 >= ret) {
              break;
            }
            Value ddd = dd4;
            Value nnn = nn4;
            for (auto b6 : base6s) {
              ddd += nnn / b6;
              nnn %= b6;
            }
            ret = std::min(ddd, ret);
          }
        }
      }
    }
  }
  return ret;
}

int main() {
  Value n;
  std::cin >> n;
  auto ret = calc(n);
  std::cout << ret << std::endl;
  return 0;
}


Measured memory_bytes: 256
n = input()
k = int(input())

def solve1(n):
    l = len(n)
    if l > 0:
        return int(n[0]) + 9 * (l-1)
    else:
        return 0

def solve2(n):
    l = len(n)
    if l > 1:
        ret = (int(n[0]) - 1) * 9 * (l-1) + 9 * 9 * (l - 1) * (l - 2)  // 2
        n = n[1:]
        while (n[0] == "0"):
            if (n == "0"):
                n = ""
                break
            
            n = n[1:]
        return ret + solve1(n)
    else:
        return 0

def solve3(n):
    l = len(n)
    if l > 2:
        ret = (int(n[0])-1) * 9 * 9 * (l - 1) * (l - 2) // 2 + 9 * 9 * 9 * (l - 1) * (l - 2) * (l - 3) // 6
        n = n[1:]
        while (n[0] == "0"):
            
            if (n == "0"):
                n = ""
                break
            n = n[1:]
        return ret + solve2(n)
    else:
        return 0

if k == 1:
    print(solve1(n))
elif k == 2:
    print(solve2(n))
else:
    print(solve3(n))
    

Measured memory_bytes: 3064
/*
 *  Created on: 24-October-2019
 *      Author: ankur314
 */
#include <bits/stdc++.h>
#define lli long long int
#define li long int
#define db double
#define ldb long double
#define vr vector
#define it iterator
#define fi(i,a,n) for(int i=a;i<n;i++)
#define fli(i,a,n) for(long int i=a;i<n;i++)
#define flli(i,a,n) for(long long int i=a;i<n;i++)
#define pb(n) push_back(n)
#define ppf() pop_front()
#define pii pair<int,int>
#define MOD 1000000007
#define INF 1000000005
 
#define debug1(x) cout<<x<<"\n"
#define debug2(x,y) cout<<x<<" "<<y<<"\n"
#define debug3(x,y,z) cout<<x<<" "<<y<<" "<<z<<"\n"
#define debug4(x,y,z,w) cout<<x<<" "<<y<<" "<<z<<" "<<w<<"\n"
 
using namespace std;

int main(){
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    /*freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);*/
    int n; cin>>n;
    db dp[n+1];
    memset(dp, 0, sizeof(dp));
    dp[0] = 1;
    fi(coin,1,n+1)
    {
    	db p_head; cin>>p_head;
    	for(int i=coin; i>=0; i--)
    	{
    		if(i!=0) dp[i] = dp[i-1] * p_head + dp[i] * (1-p_head);
    		else dp[i] = (dp[i] * (1-p_head));
    	}
    }
    db ans=0;
    fi(i,0,n+1)
    {
    	int t = n-i;
    	if(i > t)
    	{
    		ans += dp[i];
    	}
    }
    cout<<fixed<<setprecision(15)<<ans;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
typedef long long int ll;
typedef vector<int> vi;
typedef vector<ll> vll;
 
#define  ff         first
#define  ss         second
#define  pb         push_back
#define  all(x)     (x).begin(), (x).end()
#define  rep(i,a,b) for(int i=a ; i<b ; ++i)
#define  deb(x)     cout << #x << " - " << x << "\n";
#define  IOS        ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define  D2(x)      cout << "[" << #x << ": "; for(auto it:x) cout << it << " "; cout << "]\n"; 
#define  D2p(x)	    cout << #x << " ~ [ "; for(auto n: x) cout << n.first << "-" << n.second << " / "; cout << "]" << "\n";
#define  ps(x,y)    fixed<<setprecision(y)<<x
 
#define PI 3.141592653589793238462643383279502884L
const ll MOD = 1e9 + 7;
const ll INF = 1000000000;
const ll MAX_N = 4e4 + 10;

 
int main() {
    IOS;
    string s; cin >> s;
    int q,parity = 0,posn; cin >> q;
    char c;
    while(q--){
        int type; cin >> type;
        // deb(type);
        if(type==1) parity++;
        else{
            cin >> posn >> c;
            int sz = s.size();
            if(parity%2){
                if(posn==1) s.insert(sz,1,c);
                else s.insert(0,1,c);
            } else{
                if(posn==1) s.insert(0,1,c);
                else s.insert(sz,1,c);
            }
        }
        // deb(s);
    }
    if(parity%2) reverse(all(s));
    cout << s;
}

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

using namespace std;

typedef long long ll;
#define int ll
typedef long double ld;

typedef pair<int,int> pii;
#define x first
#define y second

const int a[33]={0,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};

signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int k;
    cin>>k;
    cout<<a[k];
}


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

#define ll long long
#define rep(i,x,y) for(int i=x;i<y;i++)
#define rel(i,x,y) for(int i=x-1;i>=y;i--)
#define all(x) x.begin(),x.end()
long long mod  = 1e9+7;

ll modpow(ll a,ll n,ll p = 1e9+7){
    ll result = 1;
    while(n > 0){
        if(n & 1) (result *= a) %= p;
        (a*=a) %= p;
        n >>= 1;
    }
    return result;
}

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    vector<ll> c;
    rep(i,0,n){
        int tmp;
        cin >> tmp;
        c.push_back(tmp);
    }
    sort(all(c));
    ll ans = (c[n-1] * modpow(2,n-1))%mod; //1桁目
    rep(r,1,n){
        ll tmp = (c[n-r-1] * modpow(2,n-r-1)) % mod; //掛ける桁と左側
        tmp *= (modpow(2,r) + modpow(2,r-1) * r) % mod; //見てる場所の個数と右側
        (ans += tmp) %= mod;
    }
    (ans *= modpow(2,n))%=mod;
    cout << ans << endl;
}

Measured memory_bytes: 2420
#include <cstdio>

#define LL long long

LL n ,m;
int main(){
	scanf("%lld%lld" ,&n ,&m);
	LL sum = 0;
	for(int i = 1 ; i <= m ; ++i){
		int t; scanf("%d" ,&t);
		sum += t;
	}
	if(sum > n) puts("-1");
	else printf("%lld\n" ,n - sum);
	return 0;
}

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

typedef long long ll;
/*
ll gcd(ll a, ll b){
	  return (a%b==0)? b: gcd(b,a%b);
}
ll lcm(ll a, ll b){
	  return a/gcd(a,b)*b;
	  }*/
ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b){return a/gcd(a,b)*b;}

int main(){

	  int n; cin >> n;
	  int a[n];
	  for(int i=0; i<n; i++) cin >> a[i];

	  int ans = a[0];
	  for(int i=0; i<n; i++) ans = lcm(ans,a[i]);
	  cout << ans << endl;
	  

}

Measured memory_bytes: 1160
n, m, k = map(int, input().split())
z = 998244353
if n <= k+1:
    a = 1
    for i in range(n):
        a = a*m%z
    print(a)
else:
    a = []
    b = []
    d = [1, 1]
    e = [1, 1]
    f = [0, 1]
    for i in range(2, n):
        d.append(d[-1]*i%z)
        f.append((-f[z%i]*(z//i))%z)
        e.append(e[-1]*f[-1]%z)
    for i in range(k+1):
        b.append(d[n-1]*e[i]*e[n-i-1]%z)
    x = 0
    g = [1]
    for i in range(n-1):
        g.append(g[i]*(m-1)%z)
    for i in range(k+1):
        a.append(b[i]*m*g[n-i-1]%z)
    for i in range(k+1):
        x = (x+a[i])%z
    print(x)

Measured memory_bytes: 49644
var GET=(function(){function f(s){return new g(s);}function g(s){this._s=s.trim().split("\n");this._y=0;}g.prototype.a=function(f){var s=this._s, y=this._y, r;if(typeof s[y]==="string")s[y]=s[y].split(" ").reverse();r=s[y].pop();if(!s[y].length)this._y++;return f?r:+r;};g.prototype.l=function(f){var s=this._s[this._y++].split(" ");return f?s:s.map(a=>+a);};g.prototype.m=function(n,f){var r=this._s.slice(this._y,this._y+=n).map(a=>a.split(" "));return f?r:r.map(a=>a.map(a=>+a));};g.prototype.r=function(n,f){var r=this._s.slice(this._y,this._y+=n);return f?r:r.map(a=>+a);};return f;})();
var o=GET(require("fs").readFileSync("/dev/stdin","utf8"));
function xArray(v){var a=arguments,l=a.length,r="Array(a["+--l+"]).fill(0).map(x=>{return "+v+";})";while(--l)r="Array(a["+l+"]).fill(0).map(x=>"+r+")";return eval(r);}

console.log(main());
function main(){
  var s = o.a(1);
  var n = s.length;
  var k = o.a();
  var ans = 0, t = s[0], u = 1;
  var a = [];
  for(var i = 1; i < n; i++){
    if(t === s[i])u++;
    else{
      a.push(u);
      ans += Math.floor(u/2);
      u = 1;
      t = s[i];
    }
  }
  a.push(u);
  ans += Math.floor(u/2);
  if(k === 1)return ans;
  if(s[0] !== s[n-1])return ans*k;
  if(a.length === 1)return Math.floor(a[0]*k/2);
  ans = 0;
  var m = a.length;
  for(var i = 1; i < m-1; i++){
    ans += Math.floor(a[i]/2);
  }
  ans *= k;
  ans += Math.floor(a[0]/2);
  ans += Math.floor(a[m-1]/2);
  ans += Math.floor((a[0]+a[m-1])/2)*(k-1);
  return ans;
}

Measured memory_bytes: 22080
#include <bits/stdc++.h>
using namespace std;
 
int main () {
  int N, A; // N=payment, A=number of 1-yen coins
  int Residue;
  
  cin >> N;
  cin >> A;
  Residue = N % 500;
  
  if (A >= Residue) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}


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

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef double dd;
#define all(v) v.begin(),v.end()
#define endl "\n"
#define clr(n, r) memset(n,r,sizeof(n));

void fast() {

    cin.tie(0);
    cin.sync_with_stdio(0);
}


int main() {
        fast();
    int a,b,h;
    cin>>a>>b>>h;
    cout<<(a+b)*h/2;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while (sc.hasNext()) {
			String line = sc.nextLine();
			Scanner s = new Scanner(line);
			int n = s.nextInt();
			int m = 0;
			for(int a=0; a<=9; a++) {
				for(int b=0; b<=9; b++) {
					for(int c=0; c<=9; c++) {
						for(int d=0; d<=9; d++) {
							if (a + b + c + d == n) m++;
						}
					}
				}
			}
			System.out.println(m);
		}
	}
}

Measured memory_bytes: 24752
using System;
using System.Linq;

namespace Aizu
{
    public class OnlineJudge
    {
        static void Main()
        {
            for (string input; (input = Console.ReadLine()) != "0 0";)
            {
                var s = input.Split().Select(q => int.Parse(q)).ToArray();
                var b = Enumerable.Range(0, s[0]).Select(q => Console.ReadLine().ToCharArray()).ToArray();
                var a = new bool[s[0], s[1]];
                var c = new[] { 0, 0 };
                var r = "LOOP";
                while (!a[c[0], c[1]])
                {
                    a[c[0], c[1]] = true;
                    switch (b[c[0]][c[1]])
                    {
                        case '>':
                            ++c[1];
                            break;
                        case '<':
                            --c[1];
                            break;
                        case '^':
                            --c[0];
                            break;
                        case 'v':
                            ++c[0];
                            break;
                        default:
                            r = c[1] + " " + c[0];
                            break;
                    }
                }
                Console.WriteLine(r);
            }
        }
    }
}

Measured memory_bytes: 9780
#include<bits/stdc++.h>
using namespace std;
const int maxn=2e5;
struct wjmzbmr
{
    int c0,c1,id;
    wjmzbmr(){}
    wjmzbmr(int a,int b,int c):c0(a),c1(b),id(c) {}
    bool operator < (const wjmzbmr& x) const
    {
        if(1LL*c0*x.c1!=1LL*c1*x.c0) return 1LL*c0*x.c1>1LL*c1*x.c0;
        return id<x.id;
    }
}a[maxn+5];
int p[maxn+5],f[maxn+5],tmp[maxn+5],tail[maxn+5],nx[maxn+5],c0[maxn+5],c1[maxn+5],d[maxn+5];
int n,root;
int b[maxn+5];
int c[maxn+5];
long long ans=0;
multiset<wjmzbmr> s;
int find(int x)
{
    if(f[x]==x) return f[x];else return f[x]=find(f[x]);
}
int main()
{

    scanf("%d",&n);
    for(int i=2;i<=n;++i) scanf("%d",&p[i]);
    for(int i=1;i<=n;++i)
    {
        scanf("%d",&tmp[i]);
        f[i]=i,tail[i]=i;
        if(tmp[i]==0) a[i]={1,0,i},c0[i]=1;else a[i]={0,1,i},c1[i]=1;
        if(i>=2)
        s.insert(a[i]);
    }
    while(s.size()>0)
    {
        wjmzbmr x=*s.begin();
        s.erase(s.begin());
        int u=x.id;

        int v=find(p[x.id]);
        nx[tail[v]]=u;
        ++d[u];
        f[u]=v,tail[v]=tail[u];
        if(v!=1) s.erase(s.find(wjmzbmr(c0[v],c1[v],v)));
        c0[v]+=c0[u],c1[v]+=c1[u];
        if(v!=1) s.insert(wjmzbmr(c0[v],c1[v],v));
    }
    for(int i=1;i<=n;++i)
        if(d[i]==0)
        {
            root=i;
            break;
        }
    for(int i=1;i<=n;++i,root=nx[root])
    {
        b[i]=tmp[root];
    }

    int now=0;
    for(int i=n;i>=1;--i)
        if(b[i]==1) ans+=now;else now+=1;
    printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 25740
#include<bits/stdc++.h>
#define fo(i,a,b) for((i)=(a);i<=(b);i++)
#define rfo(i,a,b) for((i)=(a);i>=(b);i--)
#define inrange(x,y,z) (((x)>=(y))&&((x)<=(z)))
#define ALL(vec) ((vec).begin(),(vec).end())
#define SOR(vec) sort(ALL(vec))
#define UNI(vec) (vec).erase(unique(ALL(vec)),(vec).end())
using namespace std;
int x;
int main(){
	#ifdef FILIN
		#ifndef DavidDesktop
			freopen(FILIN,"r",stdin);
			freopen(FILOUT,"w",stdout);
		#endif
	#endif
	ios::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>x;
	cout<<360/__gcd(360,x)<<endl;
	return 0;
}


Measured memory_bytes: 3644
package main

import "fmt"

func main(){
	var N int
	var count int
	fmt.Scan(&N)

	A := make([]int, N)
	for i := 0 ; i < N ; i++{
		fmt.Scan(&A[i])
	}
	//fmt.Println(A)
	flag := 0
	for {
		for i := 0 ; i < N ; i++{
			if i == 0 {	
				if A[0] % 2 == 0 {
					A[0] /= 2
				}else if A[0] % 2 == 1{
					flag = 1
					break
				}
			}else{
				if A[i] % 2 == 0{
					A[i] /= 2
				}else if A[i] % 2 == 1{
					flag = 1
					break
				}
			}
		}
		if flag == 1 {
			break
		}
		count++

	//	fmt.Println(A)
	}
	fmt.Println(count)

}

Measured memory_bytes: 512
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,ceil,sqrt,factorial,hypot,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    A=LI()
    A.sort()
    if A==[1,4,7,9]:
        print("YES")
    else:
        print("NO")
if __name__ == '__main__':
    main()

Measured memory_bytes: 3444
#include<bits/stdc++.h>
#include<algorithm>
#include<math.h>
#include<string>
#include<iostream>
#include<vector>
#include<cstdlib>
using namespace std;
 
template <class T> using V = vector<T>;
 
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
 
const long long INF = 1LL << 60;
 
using ll = long long;
using db = double;
using st = string;
using ch = char;
using bl = bool;
using vll = V<ll>;
using vpll =V<pair<ll,ll>>;
using vst = V<st>;
using vdb = V<db>;
using vch = V<ch>;
using vbl = V<bl>;
 
 
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define rFOR(i,a,b) for(ll i=(a);i>(b);i--)
#define oFOR(i,a,b) for(ll i=(a);i<(b);i+=2)
#define bgn begin()
#define en end()
#define SORT(a) sort((a).bgn,(a).en)
#define REV(a) reverse((a).bgn,(a).en)
#define M(a,b) max(a,b)
#define rM(a,b) min(a,b)
#define fi first
#define se second
#define sz size()
#define gcd(a,b) __gcd(a,b)
#define co(a) cout<<a<<endl;
#define ci(a) cin>>a;
 
 
ll sum(ll n) {
  ll m=0;
  FOR(i,0,20){
    m+=n%10;
    n/=10;
    if(n==0){
      break;
    }
  }
  return m;
}
 
 
const int MAX = 510000;
const int MOD = 1000000007;
 
long long fac[MAX], finv[MAX], inv[MAX];
 
void Comuse() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
 
 
#define comuse Comuse()
 
ll combi(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
 
 
 
 
ll lcm(ll a,ll b){
  ll n;
  n=a/gcd(a,b)*b;
  return n;
}
 
 
/****************************************\
| Thank you for viewing my code:)        |
| Written by RedSpica a.k.a. RanseMirage |
| Twitter:@asakaakasaka                  | 
\****************************************/
 
 
signed main() {
  ll n;
  	ci(n);
  co(3*n*n)
}

Measured memory_bytes: 256
n,Y = map(int,input().split())
x,y,z = 0,0,0
flag = 0
for x in range(n+1):
    for y in range(n+1):
        z = n-x-y
        if z>=0 and 10000*x + 5000*y + 1000*z == Y:
            flag = 1
            break
    if flag == 1:
        break
if(flag == 1):
    print(x,y,z)
else:
    print(-1,-1,-1)

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

using str = string;
using ss = stringstream;

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

    str s;cin>>s;
    int q;cin>>q;

    bool dir=true;
    str sf,sb;

    for(int i=0;i<q;i++)
    {
        int t;cin>>t;
        if(t==1)dir=!dir;
        else 
        {
            int f;
            char c;
            cin>>f>>c;
            if(dir^(f==2))sf.push_back(c);
            else sb.push_back(c);
        }
    }

    if(dir)
    {
        for(int i=sf.size()-1;i>=0;i--)cout<<sf[i];
        for(int i=0;i<s.size();i++)cout<<s[i];
        for(int i=0;i<sb.size();i++)cout<<sb[i];
    }
    else
    {
        for(int i=sb.size()-1;i>=0;i--)cout<<sb[i];
        for(int i=s.size()-1;i>=0;i--)cout<<s[i];
        for(int i=0;i<sf.size();i++)cout<<sf[i];
    }
    cout<<"\n";

    return 0;
}


Measured memory_bytes: 3932
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n; cin >> n;
  vector<ll> A(3*n); rep(i, 3*n) cin >> A[i];
  vector<ll> mx(n+1), mn(n+1);
  mx[0] = accumulate(begin(A), begin(A)+n, 0LL);
  mn[n] = accumulate(begin(A)+2*n, end(A), 0LL);
  {
    priority_queue<ll, vector<ll>, greater<ll>> q;
    rep(i, n) q.push(A[i]);
    REP(i, n, 2*n) {
      ll in = A[i]; q.push(in);
      ll out = q.top(); q.pop();
      mx[i-n+1] = mx[i-n]+in-out;
    }
  }
  {
    priority_queue<ll> q;
    REP(i, 2*n, 3*n) q.push(A[i]);
    for(int i=2*n-1; i>=n; i--) {
      ll in = A[i]; q.push(in);
      ll out = q.top(); q.pop();
      mn[i-n] = mn[i-n+1]+in-out;
    }
  }
  ll ans = -longinf;
  rep(i, n+1) ans = max(mx[i]-mn[i], ans);
  cout << ans << "\n";
  return 0;
}


Measured memory_bytes: 8976
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<stack>
#include<set>
#include<climits>
#include<cstdlib>
#include<cmath>
#include<string>

using namespace std;

#define INF 1 << 29
#define LL long long int

LL const MOD = 1000000007;

struct mypair{
    LL index;
    LL num;

    mypair(){

    }

    mypair(LL i,LL a):index(i),num(a){

    }

    bool operator < (const mypair & right) const{
        return num < right.num;
    }
};

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

    LL n;
    cin >> n;

    vector<mypair> a(n+1);

    for(int i = 1; i < n+1; i++){
        LL x;
        cin >> x;
        a[i] = mypair(i,x);
    }

    sort(a.begin()+1,a.end());

    set<LL> close;
    set<LL> minclose;

    close.insert(0);
    close.insert(n+1);
    minclose.insert(0);
    minclose.insert((-1)*(n+1));

    LL result = 0;

    for(int i = 1; i < n+1; i++){
        LL l,r;
        auto itl = minclose.upper_bound((-1)*a[i].index);
        l = *itl;
        auto itr = close.upper_bound(a[i].index);
        r = *itr;
        l = (-1) * l;
        minclose.insert((-1)*a[i].index);
        close.insert(a[i].index);
        result += (r-a[i].index) * (a[i].index-l) * i;
    }

    cout << result << endl;

    return 0;
}

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

#define REP(i, n) for(int (i)=0;(i)<(n);++(i))
#define MOD 1000000007

typedef long long ll;

using namespace std;
int main()
{
    int N;
    cin >> N;
    int ans = N * N * N;

    cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
# define M_PIl  3.141592653589793238462643383279502884L
using namespace std;
int main(){
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  long double n;
  cin>>n;
  cout<<2*M_PIl*n;
  return 0;
}

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

int a, b;
int area, length;

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

    cin >> a >> b;
    area = a * b;
    length = a + a + b + b;

    cout << area << ' ' << length << '\n';
    return 0;
}


Measured memory_bytes: 3140
#include<bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define int long long
#define vec(a,n) vector<int> (a)((n));
#define Vec(a,n) vector<string> (a)((n));
#define twovec(a,n,m) vector<vector<int>> a(n,vector<int>(m,0));
#define Twovec(a,n,m) vector<vector<double>> a(n,vector<double>(m,0));
#define P pair<int,int>
#define All(a) (a).begin(),(a).end()
#define Sort(a) sort(All(a));
#define Reverse(a) reverse(All(a));
#define PQ(n) priority_queue<P,vector<P>,greater<P>> (n)
#define pq(n) priority_queue<int> (n)
#define print(a) cout << (a) << endl;
#define printD(a) cout << setprecision(15) << (a) << endl;
using namespace std;
int max_int = 1000000007;
void Debug(auto a);
int nibul(auto a,auto b);
int nibuu(auto a,auto b);
void input(vector<int>& a,int n);

int n;

signed main(){
    cin >> n;
    int t = sqrt(n);
    int ans;
    for(int i =t;i>0;i--){
        if(n%i==0){
            ans = i + (n/i)-2;
            break;
        }
    }
    print(ans)
}

void Debug(auto a){
    cout << "{ ";
    for(auto b: a){
        cout << b << " ";
    }
    cout << "}" << endl;
}
int nibul(auto a,auto b){
    int x = lower_bound(All(a),b) - a.begin();
    //key以上の初めてのitr
    return x;
}
int nibuu(auto a,auto b){
    int x = upper_bound(All(a),b) - a.begin();
    //key以下の最後のitr
    return x-1;
}

void input(vector<int>& a,int n){
    REP(i,n){
        cin >> a[i];
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;

struct SegmentTree {
  using D = lint;

  using T = struct { D sum, sz; };
  static T op(const T& a, const T& b) { return {a.sum + b.sum, a.sz + b.sz}; }
  static constexpr T e() { return {0, 0}; }
  using U = struct {
    D p, q;
    bool operator==(const auto& r) const { return p == r.p and q == r.q; }
  };
  static void ap(const U& f, T& a) { a.sum = f.p * a.sum + f.q * a.sz; }
  static void cp(const U& g, U& f) { f.p *= g.p, f.q = g.p * f.q + g.q; }
  static constexpr U id() { return {1, 0}; }
  // ヘルパ関数
  D sum(int l, int r) { return acc(l, r).sum; }
  void add(int l, int r, D x) { act(l, r, {1, x}); }
  void mul(int l, int r, D x) { act(l, r, {x, 0}); }
  void update(int l, int r, D x) { act(l, r, {0, x}); }

  const int n;
  V<T> t;
  V<U> u;
  SegmentTree(int n) : n(n), t(2 * n, e()), u(n, id()) {}
  T& operator[](int i) { return t[i + n]; }
  void build() { for (int i = n - 1; i; --i) t[i] = op(t[2 * i], t[2 * i + 1]); }
  void push() { for (int i = 1; i < n; ++i) push(i); }
  void apply(const U& f, int i) {
    ap(f, t[i]);
    if (i < n) cp(f, u[i]);
  }
  void push(int i) {
    if (u[i] == id()) return;
    apply(u[i], 2 * i);
    apply(u[i], 2 * i + 1);
    u[i] = id();
  }
  void push(int l, int r) {
    for (int hl = __lg(l + n), hr = __lg(r - 1 + n); hr > 0; --hl, --hr) {
      int al = l + n >> hl, ar = r - 1 + n >> hr;
      if (al < n) push(al);
      if (ar != al) push(ar);
    }
  }
  T acc(int l, int r) {
    push(l, r);
    T resl = e(), resr = e();
    for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
      if (l & 1) resl = op(resl, t[l++]);
      if (r & 1) resr = op(t[--r], resr);
    }
    return op(resl, resr);
  }
  T get(int i) { return acc(i, i + 1); }
  void act(int l, int r, const U& f) {
    push(l, r);
    for (int i = l + n, j = r + n; i < j; i >>= 1, j >>= 1) {
      if (i & 1) apply(f, i++);
      if (j & 1) apply(f, --j);
    }
    l = l + n >> __builtin_ctz(l + n);
    while (l >>= 1) t[l] = op(t[2 * l], t[2 * l + 1]);
    r = r + n >> __builtin_ctz(r + n);
    while (r >>= 1) t[r] = op(t[2 * r], t[2 * r + 1]);
  }
  void set(int i, const T& a) {
    push(i, i + 1);
    t[i += n] = a;
    while (i >>= 1) t[i] = op(t[2 * i], t[2 * i + 1]);
  }
};

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  int n, q; cin >> n >> q;
  SegmentTree st(n);
  for (int i = 0; i < n; ++i) st.set(i, {0, 1});
  while (q--) {
    int tp; cin >> tp;
    if (!tp) {
      int l, r, x; cin >> l >> r >> x, ++r;
      st.update(l, r, x);
    } else {
      int l, r; cin >> l >> r, ++r;
      cout << st.sum(l, r) << '\n';
    }
  }
}


Measured memory_bytes: 7576
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main() {
	// your code goes here
	
	ll n;
	cin>>n;
	ll ans = 1e18;
	for(ll i=1;i<=sqrt(n);i++)
	{
	    if(n%i == 0)
	    {
	        ans = min(ans,(n/i)+i-2);
	    }
	}
	cout << ans;
	return 0;
}


Measured memory_bytes: 384
import sys
readline = sys.stdin.readline

from collections import Counter


def main():
    N = int(readline())
    A = list(map(lambda x: int(x) // 400, readline().split()))
    B = [b for b in A if b > 7]
    A = set([a for a in A if a <= 7])
    n_min = len(A)
    n_max = n_min + len(B)
    print(max(1, n_min), n_max)


if __name__ == '__main__':
    main()

Measured memory_bytes: 3316
#include<iostream>
#include<vector>
#include<map>
#include<queue>
#include<algorithm>
using namespace std;

const int N = 13;
const vector<vector<int>> NEXT = {
    {2},
    {2, 5},
    {0, 1, 3, 6},
    {2, 7},
    {5},
    {1, 4, 6, 9},
    {2, 5, 7, 10},
    {3, 6, 8, 11},
    {7},
    {5, 10},
    {6, 9, 11, 12},
    {7, 10},
    {10},
};

class Node {
public:
    vector<int> puzzle;
    int depth;
    Node(const vector<int>& p, int d) :puzzle(p), depth(d) {}
};

map<vector<int>, int> memo1;
map<vector<int>, int> memo2;

void bfs(const vector<int>& puzzle, map<vector<int>, int>& memo) {
    queue<Node> q;
    q.push(Node(puzzle, 0));
    while(!q.empty()) {
        Node current(q.front()); q.pop();
        if(current.depth > 10) continue;
        if(memo.count(current.puzzle)) continue;
        memo[current.puzzle] = current.depth;
        for(int i = 0; i < N; ++i) {
            if(current.puzzle[i] != 0) continue;
            for(const auto& j: NEXT[i]) {
                vector<int> next(current.puzzle);
                swap(next[i], next[j]);
                q.push(Node(next, current.depth + 1));
            }
        }
    }
}

int main() {
    vector<int> complete = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 0};
    vector<int> puzzle(N);
    bfs(complete, memo1);
    while(cin >> puzzle[0], puzzle[0] != -1) {
        for(int i = 1; i < N; ++i) cin >> puzzle[i];
        memo2.clear();
        bfs(puzzle, memo2);
        int answer = 21;
        for(auto& i: memo1) if(memo2.count(get<0>(i))) answer = min(answer, get<1>(i) + memo2[get<0>(i)]);
        if(answer > 20) cout << "NA" << endl;
        else cout << answer << endl;
    }
}

Measured memory_bytes: 12320
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    String o = sc.next();
    int b = sc.nextInt();

    if (o.equals("+")) {
      System.out.println(a + b);
    } else {
      System.out.println(a - b);
    }
  }
}


Measured memory_bytes: 21844
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <string>
#include <cstring>
#include <cctype>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <set>
#include <map>
using namespace std;

#define REP(i, s, e) for (int i = (s); i < (e); i++)
#define REPI(i, s, e) for (int i = (s); i <= (e); i++)
#define rep(i, n) REP(i, 0, n)
#define repi(i, n) REPI(i, 0, n)
#define ALL(v) (v).begin(), (v).end()

#define dump(x) (cout << #x << " = " << x << endl)
#define dump2(x, y) (cout << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")" << endl)

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

int main(void)
{
	int N, A, B, C, X;
	while (cin >> N >> A >> B >> C >> X, N|A|B|C|X) {
		vector<int> yn = vector<int>(N);
		rep(i, N) cin >> yn[i];

		int turn = 0;
		int idx = 0;
		rep(i, 10001) {
			if (X == yn[idx]) {
				idx++;
				if (idx == N)
					break;
			}
			X = (A*X+B)%C;
			turn++;
		}
		cout << (turn==10001?-1:turn) << endl;
	}
	return 0;
}

Measured memory_bytes: 1196
//shipc_b.cpp
//Sat Jul  7 20:35:31 2018

#include <iostream>
#include <string>
#include <queue>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <math.h>
using namespace std;
using ll=long long;

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

	int num = 0;

	while (num <= s.length()-1){
		cout << s[num];
		num += w;
	}

	printf("\n");
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please


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


	int N;
	cin >> N;

	int A[200001], B[200001];
	rep(i, N) cin >> A[i];
	rep(i, N) cin >> B[i];

	int OK = 1;
	priority_queue<pair<int, int>> que;
	rep(i, N) {
		if (A[i] < B[i]) que.push(mp(B[i], i));
		if (A[i] > B[i]) OK = 0;
	}

	ll kotae = 0;
	while (que.size()) {
		auto p = que.top();
		que.pop();

		int k = 0;
		if (p.second == 0) k += B[N - 1];
		else k += B[p.second - 1];
		if (p.second == N - 1) k += B[0];
		else k += B[p.second + 1];

		if (p.first <= k) OK = 0;
		else {
			int k2 = p.first % k;
			if (k2 < A[p.second]) {
				if ((A[p.second] - k2) % k) OK = 0;
				else {
					k2 = A[p.second];
				}
			}
			kotae += (p.first - k2) / k;
			B[p.second] = k2;
			if (B[p.second] > A[p.second]) que.push(mp(B[p.second], p.second));
			if (B[p.second] < A[p.second]) OK = 0;
		}
	}

	if (OK) co(kotae);
	else co(-1);

	Would you please return 0;
}

Measured memory_bytes: 3956