akhauriyash/Code-Regression huggingface dataset:
#pragma region template
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vld = vector<ld>;
using vvld = vector<vld>;
using vvvld = vector<vvld>;
using vs = vector<string>;
using pll = pair<ll, ll>;
using vp = vector<pll>;
template <typename T>
using pqrev = priority_queue<T, vector<T>, greater<T>>;
#define rep(i, n) for (ll i = 0, i##_end = (n); i < i##_end; i++)
#define repb(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repr(i, a, b) for (ll i = (a), i##_end = (b); i < i##_end; i++)
#define reprb(i, a, b) for (ll i = (b)-1, i##_end = (a); i >= i##_end; i--)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((ll)(x).size())
//*
constexpr ll MOD = 1e9 + 7;
/*/
constexpr ll MOD = 998244353;
//*/
constexpr ll INF = 1e+18;
constexpr ld EPS = 1e-12L;
constexpr ld PI = 3.14159265358979323846L;
constexpr ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }
constexpr ll LCM(ll a, ll b) { return a / GCD(a, b) * b; }
template <typename S, typename T>
constexpr bool chmax(S &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename S, typename T>
constexpr bool chmin(S &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
#ifdef OJ_LOCAL
#include "dump.hpp"
#else
#define dump(...) ((void)0)
#endif
template <typename T>
bool print_(const T &a) {
  cout << a;
  return true;
}
template <typename T>
bool print_(const vector<T> &vec) {
  for (auto &a : vec) {
    cout << a;
    if (&a != &vec.back()) {
      cout << " ";
    }
  }
  return false;
}
template <typename T>
bool print_(const vector<vector<T>> &vv) {
  for (auto &v : vv) {
    for (auto &a : v) {
      cout << a;
      if (&a != &v.back()) {
        cout << " ";
      }
    }
    if (&v != &vv.back()) {
      cout << "\n";
    }
  }
  return false;
}
void print() { cout << "\n"; }
template <typename Head, typename... Tail>
void print(Head &&head, Tail &&... tail) {
  bool f = print_(head);
  if (sizeof...(tail) != 0) {
    cout << (f ? " " : "\n");
  }
  print(forward<Tail>(tail)...);
}
#pragma endregion

void Pr(bool f){
  cout << (f ? "Yes" : "No") << "\n";
  exit(0);
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(20);
  ll n, m;
  cin >> n >> m;
  vll a, b;
  if(n%2){
    ll i = 1, j = n-1;
    while(i<j){
      a.emplace_back(i);
      b.emplace_back(j);
      i++;
      j--;
    }
  }else{
    ll i = 1, j = n;
    rep(k, n/4){
      a.emplace_back(i);
      b.emplace_back(j);
      i++;
      j--;
    }
    j--;
    rep(k, (n-2)/4){
      a.emplace_back(i);
      b.emplace_back(j);
      i++;
      j--;
    }
  }
  rep(i, m){
    print(a[i], b[i]);
  }
}


Measured memory_bytes: 4804
A, B, K = map(int, input().split())
s = set()

if K <= B - A:
    for i in range(K):
        s.add(A + i)
    for i in range(K):
        s.add(B - K + i + 1)
else:
    for i in range(B - A + 1):
        s.add(A + i)

print(*sorted(s), sep="\n")

Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int(i)=0;i<(n);i++)

int main(){
  int n,k;cin>>n>>k;
  vector<int> h(n,0);
  REP(i,n) cin>>h.at(i);
  sort(h.begin(),h.end(),greater<int>());
  REP(i,k) if(i<n) h.at(i)=0;
  long long ans=0;
  REP(i,n) ans+=(long long)h.at(i);
  
  cout<<ans;
}

Measured memory_bytes: 1024
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Convert;
using static System.Math;
using Pair = System.Tuple<int, int>;
using Edge = System.Tuple<int, int, long>;
//using Debug;
//using static System.Globalization.CultureInfo;

class Program
{
    static void Main(string[] args)
    {
        var str = ReadLine();
        var min = str.Length;
        for (var i = 0; i < str.Length - 1; i++)
            if (str[i] != str[i + 1])
                min = Min(min, Max(i + 1, str.Length - 1 - i));
        WriteLine(min);
    }
}

Measured memory_bytes: 13140
# -*- coding: utf-8 -*-

import sys
import os
import math


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


def selection_sort(A):
    swap_num = 0
    for i in range(N):
        min_i = i
        for j in range(i + 1, N):
            if A[j] < A[min_i]:
                min_i = j
        if i != min_i:
            A[i], A[min_i] = A[min_i], A[i]
            swap_num += 1
    print(*A)
    print(swap_num)

selection_sort(A)

Measured memory_bytes: 7808
#include<stdio.h>
int main(){
	
	int a, b, hasil;
	scanf("%d %d",&a, &b);
	
	hasil=a/b;

		if(a%b!=0 || b>a)
			printf("%d\n", hasil+1);
		else
			printf("%d\n", hasil);
		
			
	
	return 0;
}

Measured memory_bytes: 1736
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <functional>
#include <math.h>
#include <stdlib.h>
#include <map>
#include <deque>
#include <list>
#include <sys/timeb.h>
#include <fstream>
#include <set>

using namespace std;

#define repr(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repr(i,0,n)
#define reprrev(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define reprev(i,n) reprrev(i,0,n)
#define repi(itr,ds) for(auto itr=ds.begin();itr!=ds.end();itr++)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define mp make_pair
#define mt make_tuple
#define INF 1050000000
#define INFL 1100000000000000000LL
#define EPS (1e-10)
#define MOD 1000000007
#define PI 3.1415926536
#define RMAX 4294967295

typedef long long ll;
typedef pair<int, int> Pi;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<Pi> vPi;
typedef vector<vector<int> > vvi;
typedef vector<vector<bool> > vvb;
typedef vector<vector<ll> > vvll;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<double> > vvd;
typedef vector<vector<Pi> > vvPi;
typedef priority_queue<int, vector<int>, greater<int> > pqli;
typedef priority_queue<ll, vector<ll>, greater<ll> > pqlll;
typedef priority_queue<Pi, vector<Pi>, greater<Pi> > pqlP;
struct Edge {
	int from, to, cost;
	bool operator<(Edge e) {
		return cost < e.cost;
	}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
template <class T>
using vec = vector<T>;
template<class T>
using pql = priority_queue<T, vector<T>, greater<T>>;
string debug_show(Pi a) {
	return "(" + to_string(a.first) + "," + to_string(a.second) + ")";
}

template<class T>
struct augEdge {
	T from, to;
	int cost;
	bool operator<(augEdge e) { return cost < e.cost; }
	bool operator>(augEdge e) { return cost > e.cost; }
};
template<class T>
using augGraph = vector<augEdge<T>>;


bool pairCompare(const Pi& firstElof, const Pi& secondElof)
{
	return firstElof.second > secondElof.second;
}

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

	int a, b, c, d;
	cin >> a >> b >> c >> d;
	cout << (c - a)*(d - b) << endl;

	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(n);i++)
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const ll INF = (1LL << 31) - 1;
const double pi=acos(-1);
const int MAX = 10001000;
bool IsPrime[MAX];
vector<int> Era(int n = MAX) {
    vector<int> res;
    IsPrime[0] = false; IsPrime[1] = false; 
    for (int i = 2; i < n; ++i) IsPrime[i] = true;
    for (int i = 2; i < n; ++i) {
        if (IsPrime[i]) {
            res.push_back(i);
            for (int j = i*2; j < n; j += i) IsPrime[j] = false;
        }
    }
    return res;
}
int main(){
  Era();
  int n;
  cin >> n;
  int cnt=0;
  int num=16;
  cout << 11;
  while(cnt<n-1){
    if(IsPrime[num]){
      cout<<" "<<num;
      num+=5;
      cnt+=1;
    }
    else num+=5;
  }  
  cout << endl;
  return 0;
}


Measured memory_bytes: 16112
#include<bits/stdc++.h>
using namespace std;
#define        fast        ios_base::sync_with_stdio(false);cin.tie(NULL)
#define        ll          long long int
#define        End         return 0
#define        st          string
#define        sz(x)       (int)x.size()
#define        nl          '\n'
int main()
{
    fast;
    ll a,b,c,d,x,y,z,z1;
    cin>>a>>b>>c>>d;
    x=a*c;
    y=a*d;
    z=b*c;
    z1=b*d;
    cout<<max(x,max(y,max(z,z1)));
    End;
}



Measured memory_bytes: 3648
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>

#define ll long long
#define Pr pair<ll, ll>
#define mp make_pair

using namespace std;

const int N = 1e5 + 10;

map<ll, int> cnt;
int p[N];
int vis[N];
ll p2[N], lis[N];
Pr rec[N];
int n, m, cntp, cntpair, ans;

void prework(int n) {
  cntp = 0;
  vis[1] = 1;
  for (int i = 2; i <= n; ++i) {
    if (!vis[i]) p[++cntp] = i, p2[cntp] = 1LL * i * i;
    for (int j = 1; j <= cntp && i * p[j] <= n; ++j) {
      vis[i * p[j]] = 1;
      if (i % p[j] == 0) break;
    }
  }
}

void print(Pr x) { printf("(%lld,%lld)\n", x.first, x.second); }
void work(ll val) {
  int tmp = 0;
  ll nwval = 1, need = 1;
  for (int i = 1; p2[i] * p[i] <= val; ++i) {
    if (val % p[i]) continue;
    tmp = 0;
    while (val % p[i] == 0) tmp = (tmp + 1) % 3, val /= p[i];
    if (tmp == 0)
      continue;
    else if (tmp == 1)
      need *= p2[i], nwval *= p[i];
    else
      need *= p[i], nwval *= p2[i];
  }
  nwval *= val;
  if (val > 1) {
    ll ttmp = sqrt(val);
    if (ttmp * ttmp == val)
      need *= ttmp;
    else
      need *= val * val;
  }
  ++cnt[nwval];
  if (nwval > need)
    rec[++cntpair] = mp(need, nwval);
  else
    rec[++cntpair] = mp(nwval, need);
}

int main() {
  ll val;
  scanf("%d", &n);
  prework(1e5), cnt.clear();
  lis[0] = cntpair = 0;
  for (int i = 1; i <= n; ++i) scanf("%lld", &val), work(val);
  sort(rec + 1, rec + 1 + cntpair);
  cntpair = unique(rec + 1, rec + 1 + cntpair) - rec - 1;
  ans = 0;
  for (int i = 1; i <= cntpair; ++i)
    if (rec[i].first == 1 && rec[i].second == 1)
      ans += 1;
    else
      ans += max(cnt[rec[i].first], cnt[rec[i].second]);
  printf("%d\n", ans);
}


Measured memory_bytes: 14848
#include<bits/stdc++.h>
using namespace std;
map<int,int> m;
vector<int> v;

int main() {
	int n,ans;
	cin>>n;
	for(register int i=1; i<=n; ++i) {
		int x;
		cin>>x;
		if(m[x]==0) v.push_back(x);
		++m[x];
	}
	for(register int i=0; i<v.size(); ++i) if(m[v[i]]>=v[i]) ans+=m[v[i]]-v[i];
		else ans+=m[v[i]];
	cout<<ans;
	return 0;
}

Measured memory_bytes: 5112
n, m = map(int, input().split())
a = [input() for _ in range(n)]
b = [input() for _ in range(m)]
c = any([c[j:j+m] for c in a[i:i+m]] == b
        for j in range(n-m+1) for i in range(n-m+1))
print('Yes' if c else 'No')


Measured memory_bytes: 3060
#include<cstdio>
#include<algorithm>
#include<cmath>
#define cmax(_i,_j) ((_i)<(_j)?(_i)=(_j):0)
#define cmin(_i,_j) ((_i)>(_j)?(_i)=(_j):0)
using namespace std;
namespace runzhe2000
{
	void main()
	{
		int n, ans = 0; scanf("%d",&n);
		for(int i = 1; i <= n; i++)
		{
			int x; scanf("%d",&x);
			for(;x%2==0;x/=2,ans++);
		}
		printf("%d\n",ans);
		
	}
}
int main()
{
	runzhe2000::main();
}

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

#define froop1(a,n) for(int i = a;i < n;i++)
#define froop2(a,n) for(int i = a;i > n;i--)
int main(){
	long long N ,count = 0;
  cin >> N;
  vector<string> st(N);
  map<string,long long> str;
  froop1(0,N){
    string s;
    cin >> s;
    sort(s.begin(),s.end());
    st.at(i)= s;
    if(str.count(st.at(i))) str[st.at(i)]++;
    else str[st.at(i)] = 1;
  }
  for(pair<string,long long> p : str){
   long long k = p.second;
    long long c = 0;
    for(long long j = 2;j <= k;j++){
      if(j == 2)c++;
      else c += (j - 1);
    }
    count += c;
  }
  cout << count << endl; 
  return 0;
}

Measured memory_bytes: 13912
/*---------------------------------
 *File name: A.cpp
 *Creation date: 2020-07-05 19:35
 *Link: 
 *-------------------------------*/
#include<set>
#include<map>
#include<cmath>
#include<queue>
#include<vector>
#include<cstdio>
#include<string>
#include<cstring>
#include<iostream>
#include<algorithm>
#define fi first
#define se second
#define pb push_back
#define LL long long
#define PII pair<int, int>
#define Pque priority_queue 
using namespace std;
const int maxn = 1e5 + 5;
const int inf = 0x3f3f3f3f;
const LL mod = 1e9 + 7;
const double EPS = 1e-8;

int main(){
	int n;
	scanf("%d", &n);
	printf("%d\n", (1000 - n % 1000) % 1000);
	return 0;
}

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

int main(){

    int N;
    cin >> N;
    vector<int> d(N);
    int sum=0;
    for (int i = 0; i < N; i++) {
        cin >> d.at(i);
    }

    for(int i=0;i<N-1; i++){
        for(int j= i+1; j<N; j++){
            sum += d.at(i)*d.at(j);
        }
    }
    cout << sum << endl;

}


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

int main() {
    string S;
    string subs;
    bool flag;
    size_t max_size=0;
    cin >> S;
    for (size_t i = 0; i < S.size(); i++)
    {
        for (size_t j = 1; j < S.size() - i + 1; j++)
        {
            subs = S.substr(i, j);
            flag = true;
            for (size_t k = 0; k < subs.size(); k++)
            {
                // ACGT以外の文字が一つでもあったら
                if ((subs[k] != 'A') && (subs[k] != 'C') && (subs[k] != 'G') && (subs[k] != 'T')) {
                    flag = false;
                    break;
                }
            }
            if (flag) {
                if (max_size < subs.size()) max_size = subs.size();
            }
            
        }    
    }
    
    cout << max_size << endl;
    return 0;
}

Measured memory_bytes: 3592
N = int(input())
D = {}
for _ in range(N):
    S = "".join(sorted(input()))
    if S in D:
        D[S] += 1
    else:
        D[S] = 1

ans = 0
for v in D.values():
    ans += v * (v - 1) // 2

print(ans)

Measured memory_bytes: 17848
#include<stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
int main(){
	
	char c;
	scanf("%c",&c);

	if(c=='a'||c=='i'||c=='u'||c=='e'||c=='o'){
		printf("vowel\n");
	}
	else{
		printf("consonant\n");
	}
	
		
	return 0;
}

Measured memory_bytes: 128
s=input()
t=input()
n=len(s)

dic={}
ans='Yes'
for i in range(n):
    if t[i] not in dic:
        dic[t[i]]=s[i]
    
    else:
        if dic[t[i]]==s[i]:
            continue
        else :
            ans='No'
            break
    
if len(dic)!=len(set(dic.values())):
    ans='No'
print(ans)

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

using ll = long long;
using ld = double;
using pii = pair<int, int>;

ll dp[81];
int a[81];

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

	int n;
	cin >> n;

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

	fill(dp, dp + n + 1, 1000);

	for (int i = 1; i <= n; i++) {
		for (int j = i + 1; j <= n; j++) {
			for (int k = j + 1; k <= n; k++) {
				if (a[i] > a[j] && a[j] < a[k]) {
					ll sum = dp[i] / a[j] * a[k] + dp[i] % a[j];
					dp[k] = max(dp[k], sum);
				}
			}
			if (a[i] < a[j]) {
				ll sum = dp[i] / a[i] * a[j] + dp[i] % a[i];
				dp[j] = max(dp[j], sum);
			}
		}
	}

	cout << *max_element(dp, dp + n + 1);

	return 0;
}

Measured memory_bytes: 3604
#include <iostream>
using namespace std ;
int main()
{
	int a=0 , b=0 , c=0 , d=0 ;
	cin >> a >> b ;
	1<=a,b<=100 ;
	c=a*b ;
	d=2*a+2*b ;
	cout << c << " " << d << endl ;
}



Measured memory_bytes: 3036
#include <iostream>

using namespace std;

int N, X;
int l[101];
int ans;

int main() {
	cin >> N >> X;
	ans++;
	for(int i = 1; i <= N; i++) {
		cin >> l[i];
		l[i] += l[i - 1];
		if (l[i] <= X) ans++;
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 256
a=input()
l=list(map(int,input().split()))


def calc(n):
        return n//2
        
        
min=min(l)
cnt=0
flg=True
list2=l

while flg:
    flg=all(elem % 2 == 0 for elem in list2)
    if flg==False:
        break
    list2=list(map(calc,list2))
    min=min//2
    cnt=cnt+1
   
    

print(cnt)

Measured memory_bytes: 3064
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {
	n := getInt()
	k := getInt()
	isDisliked := make([]bool, 10)
	for i := 0; i < k; i++ {
		isDisliked[getInt()] = true
	}

	for {
		s := strconv.Itoa(n)
		flag := true
		for _, c := range s {
			if isDisliked[atoi(string(c))] {
				flag = false
				break
			}
		}
		if flag {
			break
		}

		n++
	}

	fmt.Println(n)
}

func atoi(s string) int {
	ret, _ := strconv.Atoi(s)
	return ret
}

// -----------------------------------------

var scanner = wordScanner()

func wordScanner() *bufio.Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	return sc
}

func getInt() int {
	scanner.Scan()
	i, err := strconv.Atoi(scanner.Text())
	if err != nil {
		panic(err)
	}
	return i
}

func getIntSlice(n int) []int {
	is := make([]int, n)
	for i := range is {
		is[i] = getInt()
	}
	return is
}

func getString() string {
	scanner.Scan()
	s := scanner.Text()
	return s
}


Measured memory_bytes: 1920
while True:
    n = input()
    if n == '0': break
    q1, b, c1, c2, q2 = map(int, n.split())
    for i in range(q2, 0, -1):
        c = i * c1
        x = (b-c)//c2
        if i+x < q1:
            continue
        elif x >= 0:
            print(i, x)
            break
    else:
        print('NA')




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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef pair<int, int> pii;

#define erep(i, x, n) for (auto i = x; i<=(ll)(n); i++)
#define rep(i, x, n) for(auto i = x; i<(ll)(n); i++)
#define all(v) ((v).begin()), ((v).end())
#define sz(v) ((int)((v).size()))
#define mod(n, m) (((n%m) + m)%m)
#define reset(n, m) memset(n, m, sizeof n)
#define endl '\n'

const int N = 1e5 + 5;
int W[N], V[N];
ll memo[101][N];
int n, w;

ll solve(int idx, int v)
{
	if (v < 0)
		return 1e10;
	if (!v)
		return 0;
	if (idx == n)
		return 1e10;

	ll &ret = memo[idx][v];
	if (~ret)
		return ret;

	ret = 1e10;
	ret = min(ret, solve(idx + 1, v));
	ret = min(ret, W[idx] + solve(idx + 1, v - V[idx]));

	return ret;
}

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

	cin >> n >> w;

	rep(i, 0, n)
		cin >> W[i] >> V[i];

	reset(memo, -1);
	ll res = 0;
	rep(i, 0, N)
	{
		ll wcurr = solve(0, i);
		if (wcurr <= w)
			res = i;
	}

	cout << res << endl;

	return 0;
}


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

int charToInt(char c){
    char zero_num = '0';
    return (int)c - (int)zero_num;
}

signed main(){
    double D, T, S;cin>>D>>T>>S;
    if(D/S<=T){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }

    return 0;
}

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

using namespace std;

struct node {
  int key;
  node *lp,*rp;

  node(){}
  node(int z):key(z),lp(NULL),rp(NULL){}

} *root;

void insert(node* z){
  node *x=root,*y=NULL;

  while(x){
    y = x;
    x = (z->key < x->key) ? x->lp : x->rp;
  }

  if(!y)root = z;
  else (z->key < y->key ? y->lp : y->rp) = z;
}

vector<int> preorder, inorder;

int dfs(node *t = root){
  preorder.push_back(t->key);
  if(t->lp)dfs(t->lp);
  inorder.push_back(t->key);
  if(t->rp)dfs(t->rp);
}

int main(void) {

  root = NULL;

  int n,v;
  string s;
  cin >> n;

  for(int i=0,m=0;i<n;i++){
    cin >> s;
    if(s=="insert"){
      cin >> v;
      insert(new node(v));
      m++;
    } else {
      dfs();
      for(int j=0;j<m;j++)cout << " " << inorder[j];
      cout << endl;
      for(int j=0;j<m;j++)cout << " " << preorder[j];
      cout << endl;

      preorder.clear();
      inorder.clear();
    }
  }

  return 0;
}

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

std::string sta = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";

void calc(char &c,int key){

	int it = sta.find(c);

	if (it - key < 0)it += 52;
	it -= key;

	c = sta[it];
}

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

		std::vector<int>k(n);
		for (int i = 0; i < n; i++)std::cin >> k[i];

		std::string str;
		std::cin >> str;


		for (int i = 0, key = 0; i < str.size(); i++, key++){
			if (key == n)key -= n;

			calc(str[i], k[key]);

		}

		std::cout << str << std::endl;
	}
	return 0;
}

Measured memory_bytes: 1216
N, A, B = map(int,input().split())
sum = 0
for i in range(1, N+1):
    s_sum = 0
    j = i
    while True:
        if j >= 10:
            s_sum += j % 10
            j = j // 10
        else:
            s_sum += j
            break
    if A <= s_sum and s_sum <= B:
        sum += i
print(sum)

Measured memory_bytes: 3060
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<ctime>
#include<cctype>
#include<climits>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<memory>
#include<functional>
#include<set>
 
#include<stdio.h>
 
using namespace std;
 
#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define F(i,j,k) fill(i[0],i[0]+j*j,k)
#define P(p) cout<<(p)<<endl;
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define INF 1<<25
#define pb push_back
#define read(a) scanf("%d",&(a))
#define write(a) printf("%d",(a))
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<double> vd;
typedef pair<int,int> pii;
typedef pair<long,long> pll;
typedef long long ll;
int main() {
	int a[4],b[4];
	rep(i,4) read(a[i]);
	rep(i,4) read(b[i]);
	int suma=0, sumb=0;
	rep(i,4) suma+=a[i];
	rep(i,4) sumb+=b[i];
	write(max(suma,sumb));
	printf("\n");
}

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

struct edge{
    int from;
    int to;
    long long cost;
    edge(int a, int b, long long c){
        from=a;
        to=b;
        cost=c;
    }
};

struct BF{
    vector<edge> e;
    long long d[10000], INF=1e18;
    bool neg[10000];
    void AddEdge(int from, int to, long long cost){
        e.push_back(edge(from, to, cost));
    }

    // return true if negative cycle
    void bellman_ford(int n, int s){
        fill(d, d+n, INF);
        fill(neg, neg+n, false);
        d[s]=0;
        bool update=true;
        int m=e.size(),count=0;
        for(int j=0;j<n&&update;j++){
            update=false;
            for(int i=0;i<m;i++){
                if(d[e[i].from]!=INF&&d[e[i].from]+e[i].cost<d[e[i].to]){
                    d[e[i].to]=d[e[i].from]+e[i].cost;
                    update=true;
                }
            }
        }
        for(int j=0;j<n;j++){
            for(int i=0;i<m;i++){
                if(d[e[i].from]!=INF&&d[e[i].from]+e[i].cost<d[e[i].to]){
                    d[e[i].to]=d[e[i].from]+e[i].cost;
                    neg[e[i].to]=true;
                }
                if(neg[e[i].from])neg[e[i].to]=true;
            }
        }
    }
};

int main(void){
    int n,m;
    BF bf;
    cin>>n>>m;
    for(int i=0;i<m;i++){
        int a,b,c;
        cin>>a>>b>>c;
        a--;
        b--;
        bf.AddEdge(a, b, -c);
    }
    bf.bellman_ford(n,0);
    if(bf.neg[n-1]){
        cout<<"inf"<<endl;
    }else{
        cout<<-bf.d[n-1]<<endl;
    }
    return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define All(A) A.begin(),A.end()
#define RAll(A) A.rbegin(),A.rend()
typedef long long LL;
const LL mod=1e9+7;
const LL LINF=1LL<<62;
const LL INF=1<<30;

double p[101],P[101];


template< typename G >
struct StronglyConnectedComponents {
    const G &g;
    G gg, rg;
    vector< int > comp, order, used;

    StronglyConnectedComponents(G &g) : g(g), gg(g.size()), rg(g.size()), comp(g.size(), -1), used(g.size()) {
        for(int i = 0; i < g.size(); i++) {
            for(auto e : g[i]) {
                gg[i].emplace_back((int) e);
                rg[(int) e].emplace_back(i);
            }
        }
    }

    int operator[](int k) {
        return (comp[k]);
    }

    void dfs(int idx) {
        if(used[idx]) return;
        used[idx] = true;
        for(int to : gg[idx]) dfs(to);
        order.push_back(idx);
    }

    void rdfs(int idx, int cnt) {
        if(comp[idx] != -1) return;
        comp[idx] = cnt;
        for(int to : rg[idx]) rdfs(to, cnt);
    }

    void build(G &t) {
        for(int i = 0; i < gg.size(); i++) dfs(i);
        reverse(begin(order), end(order));
        int ptr = 0;
        for(int i : order) if(comp[i] == -1) rdfs(i, ptr), ptr++;
        t.resize(ptr);
        for(int i=0;i<g.size();i++) P[i]=1;
        for(int i=0;i<g.size();i++) P[comp[i]]*=p[i];
        for(int i = 0; i < g.size(); i++) {
            for(auto &to : g[i]) {
                int x = comp[i], y = comp[to];
                if(x == y) continue;
                t[x].push_back(y);
            }
        }
    }
};

int main(){
    int N;
    while(cin >> N){
        if(!N) break;
        vector<vector<int>> G(N);
        for(int i=0;i<N;i++){
            int m;
            cin >> p[i] >> m;
            for(int j=0;j<m;j++){
                int u;
                cin >> u;
                u--;
                G[i].eb(u);
            }
        }
        StronglyConnectedComponents<vector<vector<int>>> scc(G);
        vector<vector<int>> h;
        scc.build(h);
        vector<int> s(h.size(),0);
        for(int i=0;i<h.size();i++){
            for(int j=0;j<h[i].size();j++){
                s[h[i][j]]++;
            }
        }
        double ans=1.0;
        for(int i=0;i<h.size();i++){
            if(!s[i]){
                ans*=1-P[i];
            }
        }
        cout <<fixed<<setprecision(9)<<ans << endl;
    }
    return 0;
}


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

int main() {
	ios_base::sync_with_stdio( false );

	string a;
	string b;
	map<string, int> mp;
	int x = 0;

	string s;
	while( cin >> s ) {
		mp[s] += 1;
		if( mp[s] > x ) {
			x = mp[s];
			a = s;
		}

		if( s.size() > b.size() ) {
			b = s;
		}
	}

	cout << a << ' ' << b << endl;
}



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

int main(void){
	int count = 0;
	string W, T; 
	cin >> W;
	
	for (int i = 0; i < W.size(); i++)W[i] = tolower(W[i]);
	while (true){
		cin >> T;
		if (T == "END_OF_TEXT") break;
		for (int i = 0; i < T.size(); i++)T[i] = tolower(T[i]);
		if (W == T) count++;
	}
	cout << count << endl;
	
	return 0;
}

Measured memory_bytes: 3148
#include <stdio.h>
#include <stdlib.h>

int main(void){
    long long int X;

    scanf("%lld",&X);


    long long int money=100;
    int absmoney=100;
    int year;


 
    year=0;
    while(money<X){
        money+=money/100;
        year++;
        //absmoney=abs(money);
    }

    printf("%d",year);
    return 0;


}

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

int main() {
    int N; cin >> N;
    vector<int> a(N);
    int ans = 0;
    rep(i, N){
        cin >> a[i];
        while(a[i] % 2 == 0){
            ans++;
            a[i] /= 2;
        }
    }

    cout << ans << endl;


    return 0;
}

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

using ll = long long;
const int INF = 1001001001;

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

int main(void)
{
  int n;
  cin >> n;
  vector<int> p(n);

  rep(i,n) cin >> p[i];

  int m = INF;
  int count = 0;
  rep(i,n) {
    m = min(m, p[i]);
    if (m == p[i]) {
      count++;
    }
  }
  cout << count << endl;
}


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

#ifdef LOCAL
#include "../../dump.hpp"
#else
#define dump(...)
#endif

#define int ll
#define rep(i,n) for(int i=0,i##_cond=(n);i<i##_cond;++i)
#define FOR(i,a,b) for(int i=(a),i##_cond=(b);i<i##_cond;++i)
#define ROF(i,a,b) for(int i=(a)-1,i##_cond=(b);i>=i##_cond;--i) // ROF(i,n,0)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend() //sortで降順
#define SUM(a) accumulate(all(a),int(0))
using ll  = long long;
using vi  = vector<int>;
using vvi = vector<vi>;
using vs  = vector<string>;
using pii = pair<int,int>;
constexpr ll inf = 1ll<<61;
constexpr ll mod = 1e9+7;
template<class T>bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}
template<class T>T add(const T &a, const T &b){return (a+b)%mod;}

signed main(){
  int n, k; cin >> n >> k;
  vi a(n); rep(i,n) cin >> a[i];
  vi total(3000), now(3000);
  rep(i,n) total[a[i]]++;
  int ans = 0;
  rep(i,n){
    int tmp = 0;
    rep(j,a[i]) tmp += total[j];
    ans += (tmp*((k*(k-1)/2)%mod))%mod;
    ans %= mod;
    dump(ans, tmp);
    tmp = 0;
    rep(j,a[i]) tmp += total[j] - now[j];
    ans += (k*tmp)%mod;
    dump(ans, tmp);
    ans %= mod;
    now[a[i]]++;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
import java.awt.geom.Point2D;
import java.util.*;
public class Main {
	Scanner in = new Scanner(System.in);
	public static void main(String[] args) {
		new Main();
	}
	public Main() {
		new AOJCGL_1().doIt();
	}
	
	class AOJCGL_1{
		void doIt(){
			Point2D p0 = new Point2D.Double(in.nextDouble(),in.nextDouble());
			Point2D p1 = new Point2D.Double(in.nextDouble(),in.nextDouble());
			int q = in.nextInt();
			double kyori = p0.distance(p1);
			for(int i=0;i<q;i++){
				Point2D p2 = new Point2D.Double(in.nextDouble(),in.nextDouble());
				double angle =angle(p0, p1, p2);
//				System.out.println(angle);
				double t = p0.distance(p2) * Math.cos(angle);
				Point2D result = new Point2D.Double(p0.getX()+(p1.getX()-p0.getX())*t/kyori,
						p0.getY()+(p1.getY()-p0.getY())*t/kyori);
				System.out.printf("%.9f %.9f\n",result.getX(),result.getY());
			}
		}
		
		private double angle(Point2D p0, Point2D p1, Point2D p2){
			return Math.atan2(p2.getY()-p0.getY(),p2.getX()-p0.getX())-
			Math.atan2(p1.getY()-p0.getY(),p1.getX()-p0.getX());
		}
		
	}
}

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

int main() {

  int N;
  cin >> N;

  string S;
  cin >> S;

  int answer = 0;

  string s1 = "";
  string s2 = "";

  vector<int> count1(26);
  vector<int> count2(26);

  for (int i = 1; i < N; i++) {
    s1 = S.substr(0, i);
    s2 = S.substr(i, N - i);
    count1.clear();
    count1.resize(26);
    count2.clear();
    count2.resize(26);
    int same = 0;
    for (int j = 0; j < s1.size(); j++) {
      count1[(int) s1[j] - 'a']++;
    }
    for (int j = 0; j < s2.size(); j++) {
      count2[(int) s2[j] - 'a']++;
    }
    for (int j = 0; j < 26; j++) {
      if (0 < count1[j] && 0 < count2[j]) {
        same++;
      }
    }
    answer = max(answer, same);
  }

  cout << answer << endl;

}

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

using ll = int64_t;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define ddrep(i, n) for (int i = n; i > 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)

#define rng(a) a.begin(), a.end()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))

using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
	os << "(" << p.first << "," << p.second << ")";
	return os;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
	os << "{";
	rep(i, (int)v.size()) {
		if (i)
			os << ",";
		os << v[i];
	}
	os << "}";
	return os;
}

template <typename T, size_t S> void printArray(const T (&array)[S]) {
	for (auto val : array)
		std::cout << val << ", ";
	std::cout << "\n";
}

const int mod = 1e9 + 7;
const int inf = 1e9 + 5;

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

	ll n; std::cin >> n;
	if (n % 2 == 1)
		std::cout << 0 << "\n";
	else {
		ll ans = 0;
		ans += n / 10;
		ll five = 50;
		while (five <= n)
			ans += n / five, five *= 5;
		std::cout << ans << "\n";
	}
}


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

int main(void){
	int n;
	cin>>n;
	double *DP=new double[n+1];
	DP[0]=1;
	for(int i=1;i<=n;i++) DP[i]=0;

	for(int i=0;i<n;i++){
		double p;
		cin>>p;
		for(int j=i+1;j>0;j--){
			DP[j]=DP[j]*(1-p)+DP[j-1]*p;
		}
		DP[0]*=(1-p);
	}

	double ans=0;
	for(int i=n;i>n/2;i--){
		ans+=DP[i];
	}

	printf("%.10f\n",ans);
	
	return 0;
}


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

int main(void){

    int N = 0;
    int X = 0;
    int Y = 0;
    int min = 5000;

    scanf("%d %d %d", &N, &X, &Y);

    int check[3000] = {};

    for (int i = 1; i <= N; i++){
        for (int j = i + 1; j <= N; j++){
            if (j != i){
                min = abs(j - i);
                if ((abs(X - i) + abs(j - Y) + 1) < min){
                    min = abs(X - i) + abs(j - Y) + 1;
                }
                if ((abs(Y - i) + abs(j - X) + 1) < min){
                    min = abs(Y - i) + abs(j - X) + 1;
                }
            }
                    check[min - 1]++;
        }
        //printf("%d\n", min);

    }

    for (int k = 0; k < N - 1; k++){
        printf("%d\n", check[k]);
    }

    return 0;
}

Measured memory_bytes: 128
import bisect, collections, copy, heapq, itertools, math, string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int, sys.stdin.readline().rstrip().split())
def LI(): return list(map(int, sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())

from collections import deque
from collections import Counter
import bisect
from collections import defaultdict
import itertools

def main():
    N, Q = MI()
    #i行の一番右をline_right[i],　j列目の一番下をcolumn_under[j]とする。
    line_right = deque([(N, N)])
    line_right_keys = deque([N])
    column_under = deque([(N, N)])
    column_under_keys = deque([N])
    bla = pow(N - 2, 2)
    x_min = N
    y_min = N
    for i in range(Q):
        query = LI()
        if query[0] == 1:
            w = query[1]
            x = bisect.bisect_left(column_under_keys, w)
            bla -= column_under[x][1] - 2
            if w < x_min:
                line_right.appendleft((column_under[x][1], w))
                line_right_keys.appendleft(column_under[x][1])
                x_min = w
        else:
            y = query[1]
            z = bisect.bisect_left(line_right_keys, y)
            bla -= line_right[z][1] - 2
            if y < y_min:
                column_under.appendleft((line_right[z][1], y))
                column_under_keys.appendleft(line_right[z][1])
                y_min = y
    print(bla)
if __name__ == "__main__":
    main()


Measured memory_bytes: 86332
#include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<deque>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const int inf=1e9+7;
const ll INF=1LL<<60 ;
const ll mod=1e9+7 ;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<int, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
#define debug(x)  cout << #x << " = " << (x) << endl;
using Graph = vector<vector<int> >;
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; }
#define int long long

template <class Abel> struct BIT {
private:
	vector<Abel> node; int n;
    Abel UNITY_SUM = 0; //to be set
public:
	BIT(int n_) {
		n = n_; node.resize(n, UNITY_SUM);
	}
	//0-indexed
	void add(int a, Abel w) {
		for (int i = a; i < n; i |= i + 1)node[i] += w;
	}
	//[0,a)
	Abel sum(int a) {
		Abel ret = UNITY_SUM;
		for (int i = a - 1; i >= 0; i = (i&(i + 1)) - 1)ret += node[i];
		return ret;
	}
	//[a,b)
	Abel sum(int a, int b) {
		return sum(b) - sum(a);
	}
    //debug
    void print() {
        for(int i = 0; i < n; ++i) cout << sum(i, i + 1) << ",";
        cout << endl;
    }
};

//BITで和は分かるから、それをどう使うか
//平均がaなら、全部-aして、合計が0で考えるとok
//累積和からBITからの転倒数
//和が０となるものを考えれば良いように値を加工する
//区間長に依存しない

void solve() {
	int n; cin >> n;
    vector<int> a(n); rep(i, n) cin >> a[i];
    int ok = 0, ng = 1LL<<32;

    const int geta = n + 1;
    while(ng - ok > 1) {
		int mid = (ng + ok) / 2;
	    BIT<ll> bit(2 * n + 10);
        ll num = 0;
        int sum = 0;
        bit.add(sum + geta, 1);
        rep(i, n) {
            int val;
            if(a[i] >= mid) val = 1;
            else val = -1;
            sum += val; //sumはマイナスもありうる -> getaをたして、マイナスをプラスにして扱う
            //転倒数を求めるパート
            num += bit.sum(0, sum + geta + 1); //今まで出た自分以下の数の個数
            bit.add(sum + geta, 1);
        }
        if(num >= ((n + 1) * n / 2 + 1) / 2 ) ok = mid;
        else ng = mid;
    }
    cout << ok << endl;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//init();
	solve();
	//cout << "finish" << endl;
    return 0;
}

Measured memory_bytes: 2664
#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()

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int a,b; cin >> a >> b;
    int ans = -1;
    rep(i,0,100000){
        if(int(i*0.08) == a && int(i*0.1) == b){ ans = i; break; }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long pp[100005];
main()
{
	int t,p;
	long long w,v;
	scanf("%d%d",&t,&p);
	for(int i = 1;i <= p;i++)
	{
		pp[i]=-1e14;
	}
	for(int i = 0;i < t;i++)
	{
		scanf("%lld%lld",&w,&v);
		for(int j = p;j >= 0;j--)
		{
			if(w+j<=p)
			pp[j+w]=max(pp[j+w],pp[j]+v);
		}
	}
	long long mx=0;
	for(int i = 0;i <= p;i++)
	mx=max(mx,pp[i]);
	printf("%lld",mx);
}

Measured memory_bytes: 1024
//Do what you can't.

import java.io.*;
import java.util.*;
import java.math.BigInteger;
public class Main{
  public static void main(String[] args) {
    InputReader in = new InputReader(System.in);
    PrintWriter w = new PrintWriter(System.out);
    int a = in.nextInt(), b = in.nextInt(), c = in.nextInt();
    int temp = a * 100 + b * 10 + c;
    if (temp % 4 == 0)
      w.println("YES");
    else
      w.println("NO");
    w.close();
  }
  static class InputReader {

    private final InputStream stream;
    private final byte[] buf = new byte[8192];
    private int curChar, snumChars;
    private SpaceCharFilter filter;

    public InputReader(InputStream stream) {
      this.stream = stream;
    }

    public int snext() {
      if (snumChars == -1)
        throw new InputMismatchException();
      if (curChar >= snumChars) {
        curChar = 0;
        try {
          snumChars = stream.read(buf);
        } catch (IOException e) {
          throw new InputMismatchException();
        }
        if (snumChars <= 0)
          return -1;
      }
      return buf[curChar++];
    }

    public int nextInt() {
      int c = snext();
      while (isSpaceChar(c)) {
        c = snext();
      }
      int sgn = 1;
      if (c == '-') {
        sgn = -1;
        c = snext();
      }
      int res = 0;
      do {
        if (c < '0' || c > '9')
          throw new InputMismatchException();
        res *= 10;
        res += c - '0';
        c = snext();
      } while (!isSpaceChar(c));
      return res * sgn;
    }

    public long nextLong() {
      int c = snext();
      while (isSpaceChar(c)) {
        c = snext();
      }
      int sgn = 1;
      if (c == '-') {
        sgn = -1;
        c = snext();
      }
      long res = 0;
      do {
        if (c < '0' || c > '9')
          throw new InputMismatchException();
        res *= 10;
        res += c - '0';
        c = snext();
      } while (!isSpaceChar(c));
      return res * sgn;
    }

    public int[] nextIntArray(int n) {
      int a[] = new int[n];
      for (int i = 0; i < n; i++) {
        a[i] = nextInt();
      }
      return a;
    }

    public String readString() {
      int c = snext();
      while (isSpaceChar(c)) {
        c = snext();
      }
      StringBuilder res = new StringBuilder();
      do {
        res.appendCodePoint(c);
        c = snext();
      } while (!isSpaceChar(c));
      return res.toString();
    }

    public String nextLine() {
      int c = snext();
      while (isSpaceChar(c))
        c = snext();
      StringBuilder res = new StringBuilder();
      do {
        res.appendCodePoint(c);
        c = snext();
      } while (!isEndOfLine(c));
      return res.toString();
    }

    public boolean isSpaceChar(int c) {
      if (filter != null)
        return filter.isSpaceChar(c);
      return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
    }

    private boolean isEndOfLine(int c) {
      return c == '\n' || c == '\r' || c == -1;
    }

    public interface SpaceCharFilter {
      public boolean isSpaceChar(int ch);
    }
  }
}

Measured memory_bytes: 22612
using System;
using System.Linq;//リストの使用
using System.Collections.Generic;
class Program
{
	static void Main()
	{
		long n = long.Parse(Console.ReadLine());
    long[] answer = new long[n];
    long sumMemo = 0;
    string answerMemo = "";
    
    if(n == 3) Console.WriteLine("2 5 63");
    else if(n == 4) Console.WriteLine("2 5 20 63");
    else if(n == 5) Console.WriteLine("2 5 20 30 63");
    else
    {
      for(long i = 0; i < n; i++)
      {
      long memo = i/4;
        if(i%4 == 0) answer[i] = 6*memo+2;
        if(i%4 == 1) answer[i] = 6*memo+3;
        if(i%4 == 2) answer[i] = 6*memo+4;
        if(i%4 == 3) answer[i] = 6*memo+6;
      sumMemo += answer[i];
      }
      if(sumMemo%6 == 2) answer[4] = 30000;
      if(sumMemo%6 == 3) answer[5] = 30000;
      if(sumMemo%6 == 5) answer[5] = 29998;

      answerMemo = answer[0].ToString();
      for(long i = 1; i < n; i++)
      {
        answerMemo += " "+answer[i].ToString();
      }
      Console.WriteLine(answerMemo);
    }
	}
}


Measured memory_bytes: 31712
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cstdio>
#include <numeric>
#include <cmath>

#define rep(i, n) for(int i = 0;i < (int)(n); i++)
#define pb push_back
typedef long long ll;

using namespace std;

int main() {
    int n;
    cin >> n;
    int ans = 0;
    rep(i, n){
        int from, to;
        cin >> from >> to;
        ans += (to - from + 1);
    }
    cout << ans;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
int main() {
	int k, x;	cin >> k >> x;
  	if(k*500 >= x) cout << "Yes" << endl;
  	else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <cstring>
#define ll long long
using namespace std;
int n;
char s1[100+10],s2[100+10];
int main()
{
    scanf("%d",&n);
    int f,ans=n;
    scanf("%s\n%s",s1,s2);
    for(int i=0; i<n; i++)
    {
        if(s1[i]==s2[0])
        {
            f=1;
            for(int j=1,k=i+1; j<n&&k<n; j++,k++)
                if(s1[k]!=s2[j])
                {
                    f=0;
                    break;
                }
            if(f==1||i==n-1) ans=i;
        }
        if(f==1) break;
    }
    ans=n-ans;
    printf("%d\n",n*2-ans);
    return 0;
}


Measured memory_bytes: 256
def insertionSort(At, Nt):
	for i in range(Nt):
		v = At[i]
		j = i - 1
		while j >= 0 and At[j] > v:
			A[j + 1] = A[j]
			j = j - 1
		A[j + 1] = v
		print(" ".join(map(str,At)))
	return At

if __name__ == '__main__':
	N = int(input())
	A = list(map(int, input().split()))
	A = insertionSort(A, N)
	#print(" ".join(map(str,A)))

Measured memory_bytes: 7736
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <queue>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <stdio.h>
#include <complex>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<int, PII> TIII;
typedef long long LL;
typedef vector<LL> VLL;

//container util

//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define MT(a,b,c) MP(a, MP(b, c))

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

VI visit;

typedef struct{
	int to, rev, cap;
}edge;
void add_edge(vector<vector<edge> > &g, int s, int e){
	edge e1 = {e, g[e].size(), 1};
	edge e2 = {s, g[s].size(), 0};
	g[s].PB(e1);
	g[e].PB(e2);
}
int gcd(int a, int b)
{
    while( 1 )
    {
        a = a % b;
		if( a == 0 )
			return b;
		b = b % a;

        if( b == 0 )
			return a;
    }
}

int dfs(vector<vector<edge> > &g, int s, int t, int f){
	if(s==t)return f;
	visit[s] = 1;
	REP(i, g[s].size()){
		edge &e = g[s][i];
		if(!visit[e.to] && e.cap>0){
			int d = dfs(g, e.to, t, min(f, e.cap));
			if(d > 0){
				e.cap -= d;
				g[e.to][e.rev].cap += d;
				return d;
			}
		}
	}
	return 0;
}	

int main(){
	while(1){
		int n,m;
		cin >> n>>m;
		if(n==0)break;
		vector<vector<edge> > g(n+m+2);
		VI va(n), vb(m);
		REP(i,n)cin>>va[i];
		REP(i,m)cin>>vb[i];
		REP(i,n){
			REP(j,m){
				if(gcd(va[i], vb[j]) > 1){
					add_edge(g, i+1, n+j+1);
				}
			}
		}
		REP(i,n)add_edge(g, 0, i+1);
		REP(i,m)add_edge(g, n+i+1, n+m+1);
		int mf = 0;
		while(1){
			int ret = 0;
			visit = VI(n+m+2, 0);
			ret = dfs(g, 0, n+m+1, 1);
			if(ret == 0)break;
			mf += ret;
		}
		cout << mf << endl;
	}
}

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

int main(){
	stack<int> st;
	string n;
	int x,y;
	while(cin >> n){
		if(n == "+"){
			x = st.top();
			st.pop();
			y = st.top();
			st.pop();
			st.push(y+x);
		}else if(n == "-"){
			x = st.top();
			st.pop();
			y = st.top();
			st.pop();
			st.push(y-x);
		}else if(n == "*"){
			x = st.top();
			st.pop();
			y = st.top();
			st.pop();
			st.push(y*x);
		}else{
			st.push(stoi(n));
		}
	}
	cout << st.top() << endl;
	return 0;
}	

Measured memory_bytes: 3200
#include<iostream>
#define N 12

using namespace std;

int main () {

  int L;
  int m,n;
  int mon;
  bool skip;

  while ( true ) {
    cin >> L;
    if ( L == 0 )
      break;
    //sum = L;
    skip = false;
    for ( int i=0; i<N; i++ ) {
      cin >> m >> n;
      L -= m-n;
      if ( L <= 0 && !skip ) {
	skip = true;
	mon = i+1;
      }
      
    }

    if ( skip )
      cout << mon << endl;
    else
      cout << "NA\n";
   }

}


    

    

Measured memory_bytes: 0