akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <cmath>
#include <queue>
#include <numeric>
#include <climits>
#include <iterator>
#include <iomanip>
#include <stack>
#include <set>
#include <cstdio>
#include <bitset>
#include <functional>
#include <tuple>
using namespace std;
const constexpr int INF = 1e9;
typedef pair<int, int> P;

#define FOR(i, a, n) for (ll i = (ll)a; i<(ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)

typedef long long ll;
typedef vector<int> VI;
const constexpr ll MOD = 1e9 + 7;
const int BITSIZE = 100010;

struct Less {
	bool operator()(const pair<int, int>& x, const pair<int, int>& y) const {
		return x.second < y.second;
	}
};
struct More {
	bool operator()(const pair<int, int>& x, const pair<int, int>& y) const {
		return x.first > y.first;
	}
};
//1-indexed
int bit[100010];

int bit_query(int i) {
	int res = 0;
	for (; i >= 1; i -= i & -i) res = max(res, bit[i]);
	return res;
}

void bit_set(int x, int v) {
	for (; x <= BITSIZE; x += x & -x) {
		bit[x] = max(bit[x], v);
	}
}
int N;
int main() {
	cin >> N;
	vector<pair<int, int> > r, b;

	REP(i, N) {
		int s, t; cin >> s >> t;
		r.push_back({ s, t });
	}
	sort(r.begin(), r.end(), More());

	REP(i, N) {
		int s, t; cin >> s >> t;
		b.push_back({ s, t });
	}
	sort(b.begin(), b.end(), Less());

	int ans = 0;
	bool got[101];
	for (int i = 0; i < N; ++i) got[i] = false;
	for (int i = 0; i < N; ++i) {
		for (int j = 0; j < N; ++j) {
			if (b[i].second > r[j].second&&b[i].first > r[j].first&&!got[j]) {
				got[j] = true;
				ans++;
				break;
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;
import java.math.*;
public class Main {
	static Scanner stdIn = new Scanner(System.in);
	static FastScanner sc = new FastScanner();
	static PrintWriter out = new PrintWriter(System.out);
	static String[] s = new String[] {"","Man","Oku","Cho","Kei","Gai","Jo","Jou","Ko","Kan","Sei","Sai","Gok","Ggs","Asg","Nyt","Fks","Mts"};
	static int INF = 2 << 25;
	public static void main(String[] args) {
		while(true) {
			int d = sc.nextInt();
			int n = sc.nextInt();
			if(d == 0 && n == 0) break;
			int[] a = new int[n];
			int[] e = new int[n];
			int[] r = new int[n];
			
			for(int i = 0; i < n; i++) {
				a[i] = sc.nextInt();
				e[i] = sc.nextInt();
				r[i] = sc.nextInt();
			}
			
			int[][] dp = new int[d+1][101];
			for(int i = d; i >= 0; i--) {
				Arrays.fill(dp[i], INF);
			}
			dp[d][0] = 0;
			for(int i = d; i >= 0; i--) {
				for(int j = 0; j <= 100; j++) {
					for(int k = 0; k < n; k++) {
						if(j >= r[k]) {
							dp[Math.max(0, i - a[k])][Math.min(j + e[k], 100)] = Math.min(dp[Math.max(0, i - a[k])][Math.min(j + e[k], 100)], dp[i][j] + 1);
						}
					}
				}
			}
			int min = INF;
			for(int i = 0; i < 101; i++) {
				min = Math.min(min, dp[0][i]);
			}
			if(min == INF) {
				out.println("NA");
			}
			else {
				out.println(min);
			}
			
		}
		out.flush();
		
	}
}

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;}
	private void skipUnprintable() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;}
	public boolean hasNext() { skipUnprintable(); 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 long nextLong() {
		if (!hasNext()) throw new NoSuchElementException();
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while(true){
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			}else if(b == -1 || !isPrintableChar(b)){
				return minus ? -n : n;
			}else{
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}
	
	public int nextInt() {
		return (int)nextLong();
	}
 
	public double nextDouble() {
		return Double.parseDouble(next());
	}
 
}

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

using namespace std;
int qu(int k);
int a[101];
int n;
int main()
{
    int count=0;
    scanf("%d",&n);
    for(int i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
        count+=a[i];
    }
    int k=count/n;
    int t1,t2;
    t1=qu(k);t2=qu(k+1);
    if(t1<t2)
        printf("%d\n",t1);
    else
        printf("%d\n",t2);
    return 0;
}
int qu(int k)
{
    int count=0;
    for(int i=0;i<n;i++)
    {
        count+=(k-a[i])*(k-a[i]);
    }
    return count;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<=n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
typedef double db;
const ll mod=998244353;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}

const int maxn=2e5+50;
ll ans,n,m,q,a[maxn],b[maxn],c[maxn],Q[maxn],x[maxn];

void check()
{
	ll tmp=0;
	for(int i=1;i<=q;i++) if(x[b[i]]-x[a[i]]==c[i]) tmp+=Q[i];
	ans=max(ans,tmp);
}

void dfs(int u)
{
	if(u==n+1) {check(); return;}
	for(int i=x[u-1];i<=m;i++)
	{
		x[u]=i;
		dfs(u+1);
	}
}

int main()
{
	cin>>n>>m>>q;
	for(int i=1;i<=q;i++) cin>>a[i]>>b[i]>>c[i]>>Q[i]; x[0]=1;
	dfs(1); cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 3640
n = int(input())
s = [list(input()) for _ in range(n)]

res = 0
for b in range(n):
    judge = True
    d = [['']*n for _ in range(n)]
    for i in range(n):
        for j in range(n):
            d[i][(j+b)%n] = s[i][j]
    
    for i in range(n):
        for j in range(n):
            if d[i][j] != d[j][i]:
                judge = False
    
    if judge:
        res += n

print(res)

Measured memory_bytes: 122620
import java.util.*

fun main(args: Array<String>) {
    val (n, l) = readLine()!!.split(' ').map { it.toInt() }
    val s = mutableListOf<String>()
    for (i in 0 until n) {
        s.add(readLine()!!)
    }
    s.sort()
    println(s.joinToString(""))
}

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

int isq(long long x){
  int s = 1, e = 1000000000;

  while(s < e){
    int m = (s + e + 1) >> 1;
    if(1LL * m * m > x) e = m - 1; else s = m;
  }

  return s;
}

int main(){
  int T; scanf("%d", &T);

  for(; T--; ){
    int a, b; scanf("%d%d", &a, &b);

    if(a == b){ printf("%d\n", 2 * a - 2); continue; }

    long long v = 1LL * a * b - 1;
    int sq = isq(v);

    printf("%d\n", 1LL * sq * (sq + 1) > v ? sq * 2 - 2 : sq * 2 - 1);
  }

  return 0;
}

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

int main () {
  int K, S;
  cin >> K >> S;
  
  int count = 0;
  for (int x = 0; x <= K; x++) {
    for (int y = 0; y <= K; y++) {
      int z = S - x - y;
      if (0 <= z && z <= K) {
        count++;
      }
    }
  }
  cout << count;

}

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

using namespace std;
#define rep(i,N) for(int i=0; i<N;i++)
using ll=long long;






int main(){
    int N;cin>>N;
    vector<ll> h(N);
    
    
    
    
    rep(i,N) cin>>h[i];
    bool ans=true;
    for(int i=N-2;i>=0;i--){
        if(h[i]>h[i+1]) h[i]--;
        if(h[i]>h[i+1]) {
         ans=false;
            break;
        }
    }
    if(ans) {
        cout<<"Yes"<<endl;
        
    }
    else
    {
        cout<<"No"<<endl;
    }
}


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

lint dx[4] = {1,0,-1,0};
lint dy[4] = {0,-1,0,1};
const int limit = 410;
 
lint h,w;
vector<string>s;
 
lint B = 0, W = 0;
bool visit[limit][limit];
void dfs(int x, int y){
  visit[x][y] = true;
  if(s[x][y] == '#') B++;
  else W++;
  
  for(lint i = 0; i < 4; i++){
    lint nx = x + dx[i];
    lint ny = y + dy[i];
    
    if(nx < 0 || nx >= h || ny < 0 || ny >= w) continue;
    if(s[x][y] == s[nx][ny])continue;
    if(visit[nx][ny]) continue;
    
    dfs(nx, ny);
  }  
}
 
signed main(){
  cin >> h >> w;
  s.resize(h);
  for(int i = 0; i<h; i++) cin >> s[i];
  
  lint ans=0;
  for(int x=0; x<h; x++){
   for(int y=0; y<w; y++){
     if(visit[x][y]) continue;
     B = W = 0;
     dfs(x,y);
     ans+= B * W;
   }
  }
  cout << ans << endl; 
}

Measured memory_bytes: 13184
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class Program
{
    static void Main(string[] args)
    {
            // 入力
            string[] sS = Console.ReadLine().Trim().Split(' ');
            int iN = int.Parse(sS[0]);

            System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
            sw.Start();

            // 解析
            int iOut = iN / 3;

            // 出力
            Console.WriteLine("{0}", iOut.ToString().Trim());

            sw.Stop();
#if DEBUG
            Console.WriteLine();
            Console.WriteLine("{0}", sw.Elapsed.ToString());
            Console.WriteLine("続行するには何かキーを押してください．．．");
            Console.ReadKey();
#endif
    }
}


Measured memory_bytes: 13268
a, b = map(int, input().split())
A = [list(input().split()) for i in range(a)]

lines = []
for j in A:
    for k in j:
        if "#" in k:
            lines.append(k)
lines_t = ["".join(list(i)) for i in zip(*lines)]
B = []
for g in lines_t:
    if "#" in g:
        B.append(g)
C = []
C = ["".join(list(i)) for i in zip(*B)]
for v in C:
    print(v)


Measured memory_bytes: 3064
A, B, C = sorted(list(map(int, input().split())))
ans = 0
if A % 2 == B % 2 and A % 2 != C % 2:
    A += 1
    B += 1
    ans += 1
if A % 2 == C % 2 and A % 2 != B % 2:
    A += 1
    C += 1
    ans += 1
if B % 2 == C % 2 and B % 2 != A % 2:
    B += 1
    C += 1
    ans += 1
ans += (C - A) // 2 + (C - B) // 2
print(ans)


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

vector<int> ai;
vector<int> bi;
vector<int> ci;

int main(){
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		int a;
		cin>>a;
		ai.push_back(a);
	}
	for(int j=0;j<n;j++){
		int b;
		cin>>b;
		bi.push_back(b);
	}
	for(int k=0;k<n;k++){
		int c;
		cin>>c;
		ci.push_back(c);
	}
	int ans=0;
	for(int z=0;z<n;z++){
		ans+=bi[ai[z]-1];
		if(z!=0 && ai[z-1]==ai[z]-1){
			ans+=ci[ai[z-1]-1];
		}
	}
	cout<<ans;
}

Measured memory_bytes: 3620
import java.util.*;

class Main {
  static Scanner sc = new Scanner(System.in);

  public static void main(String[] args) {
    int n = sc.nextInt();
    int x = n % 1000;
    if (x > 0) {
      int y = 1000 - x;
      System.out.println(y);
    } else {
      System.out.println(x);
    }
  }
}

Measured memory_bytes: 35772
#include <bits/stdc++.h>
using namespace std;
const int mx = 1E5 + 10;
struct node
{
    int id;
    int dat;
};
node s[mx];

bool cmp(node s1, node s2)
{
    return s1.dat < s2.dat;
}

int main()
{
    int n;
    cin >> n;
    for (int i = 1; i <= n; ++i)
    {
        s[i].id = i;
        cin >> s[i].dat;
    }
    sort(s + 1, s + n + 1, cmp);
    cout << s[1].id;
    for (int i = 2; i <= n; ++i)
    {
        cout << ' ' << s[i].id;
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 1536
#include <bits/stdc++.h>
#ifdef LOCAL_DEBUG
#define DEBUG 1
#define CERR if(DEBUG) cerr
#define MACRO(_1,_2,_3,_4,_5,_6,_7,_8,_9,_10,NAME,...) NAME
#define pr(...) CERR<<MACRO(__VA_ARGS__,pr10,pr9,pr8,pr7,pr6,pr5,pr4,pr3,pr2,pr1)(__VA_ARGS__)<<endl
#define pr1(a) (#a)<<"="<<(a)<<" "
#define pr2(a,b) pr1(a)<<pr1(b)
#define pr3(a,b,c) pr1(a)<<pr2(b,c)
#define pr4(a,b,c,d) pr1(a)<<pr3(b,c,d)
#define pr5(a,b,c,d,e) pr1(a)<<pr4(b,c,d,e)
#define pr6(a,b,c,d,e,f) pr1(a)<<pr5(b,c,d,e,f)
#define pr7(a,b,c,d,e,f,g) pr1(a)<<pr6(b,c,d,e,f,g)
#define pr8(a,b,c,d,e,f,g,h) pr1(a)<<pr7(b,c,d,e,f,g,h)
#define pr9(a,b,c,d,e,f,g,h,i) pr1(a)<<pr8(b,c,d,e,f,g,h,i)
#define pr10(a,b,c,d,e,f,g,h,i,j) pr1(a)<<pr9(b,c,d,e,f,g,h,i,j)
#define prArr(a){CERR<<(#a)<<"={";int i=0;for(auto t:(a))CERR<<(i++?", ":"")<<t;CERR<<"}"<<endl;}
#else
#define DEBUG 0
#define pr(...)
#define prArr(a)
#endif
using namespace std;
using Int = long long;
using _int = int;
using ll = long long;
using Double = long double;
const Int INF = (1LL<<60)+1e9; // ~ 1.15 * 1e18
const Int mod = (1e9)+7;
const Double EPS = 1e-8;
const Double PI = 6.0 * asin((Double)0.5);
using P = pair<Int,Int>;
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
template<class T1, class T2> ostream& operator<<(ostream& o,pair<T1,T2> p){return o<<"("<<p.first<<","<<p.second<<")";}
template<class T1, class T2, class T3> ostream& operator<<(ostream& o,tuple<T1,T2,T3> t){return o<<"("<<get<0>(t)<<","<<get<1>(t)<<","<<get<2>(t)<<")";}
template<class T1, class T2> istream& operator>>(istream& i,pair<T1,T2> &p){return i>>p.first>>p.second;}
template<class T> ostream& operator<<(ostream& o,vector<T> a){Int i=0;for(T t:a)o<<(i++?" ":"")<<t;return o;}
template<class T> istream& operator>>(istream& i,vector<T> &a){for(T &t:a)i>>t;return i;}
//INSERT ABOVE HERE


signed main(){
  srand((unsigned)time(NULL));
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  Int N, M;
  cin>>N>>M;

  vector<Int> A(N);
  cin>>A;
  Int s = 0;
  for(Int a:A) s += a;

  Int cnt = 0;
  for(Int a:A){
    if(a * 4 * M >= s) cnt++;
  }

  Int ans = cnt>=M;

  cout<<(ans? "Yes":"No")<<endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
long long int a,b,c;
  cin >>a >>b >>c;
  if (a%2==0 || b%2==0 ||c%2==0)cout << 0 <<endl;
  else cout << min(min(a*b,b*c),a*c) <<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <numeric>

using namespace std;


long long int gcd(long long int a, long long int b)
{
    for (;;)
    {
        if (a == 0) return b;
        b %= a;
        if (b == 0) return a;
        a %= b;
    }
}

long long int lcm(long long int a, long long int b)
{
    long long int temp = gcd(a, b);

    return temp ? (a / temp * b) : 0;
}

int main(){
    long long int a, b, c, d;
    cin >> a >> b >> c >> d;

    long long int dc_b = b / c;
    long long int dc_a = (a-1) / c;
    long long int dd_b = b / d;
    long long int dd_a = (a-1) / d;
    long long int dcd_b = b / lcm(c,d);
    long long int dcd_a = (a-1) / lcm(c,d);

    cout << (b - a + 1) - ((dc_b - dc_a) + (dd_b - dd_a) - (dcd_b - dcd_a)) << endl;

    return 0;

}

Measured memory_bytes: 256
from collections import defaultdict
def build_tree(N, edges):
    root_list = [i for i in range(N)]
    for p, q in edges:
        p -= 1
        q -= 1
        root_p = get_root(root_list, p)
        root_q = get_root(root_list, q)
        root_now = min(root_p, root_q, p)
        root_list[p] = root_now
        root_list[q] = root_now
        root_list[root_p] = root_now
        root_list[root_q] = root_now
    return root_list

def get_root(root_list, city):
    if root_list[city] == city:
        return city
    else: 
        root_list[city] = get_root(root_list, root_list[city])
        return root_list[city]

if __name__ == '__main__':
    N, K, L = map(int, input().split())
    roads = [None]*K
    rails = [None]*L
    for k in range(K):
        roads[k] = list(map(int, input().split()))
    for l in range(L):
        rails[l] = list(map(int, input().split()))
    
    
    '''N = 2*10**5
    L = int(N/2)
    K = int(N/2)
    roads = [None]*K
    rails = [None]*L
    for i in range(L):
        roads[i] = [2*i, 2*i+1]
    for i in range(K):
        rails[i] = [2*i, 2*i+1]'''
    
    road_roots = build_tree(N, roads)
    rail_roots = build_tree(N, rails)
    
    railroads = defaultdict(int)
    RR = []
    for n in range(N):
        rr = (get_root(road_roots, n), get_root(rail_roots, n))
        RR.append(rr)
        railroads[rr] += 1
    answer = [railroads[key] for key in RR]
    print(' '.join(map(str, answer)))

Measured memory_bytes: 108652
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <array>
#include <queue>
#include <map>
#include <set>
#include <sstream>
#include <stdio.h>
#include <cstring>

using namespace std;

#define Rep(i,a,b) for(int i = a; i < b; i++)
#define rep(i,b) Rep(i,0,b)
#define rrep(i,a) for(int i = a; i >= 0; i--)
#define allof(a) (a).begin(), (a).end()
#define pb push_back

typedef long long ll;
const int inf = 1e9 + 7;
const ll infll = 1ll << 60ll;
const ll mod = 1e9 + 7;
// 0~3までは右左下上 4~7までは斜め
constexpr int dx[] = { 1, 0, -1, 0, 1, 1, -1, -1 };
constexpr int dy[] = { 0, -1, 0, 1, 1, -1, -1, 1 };

// 最大公約数
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a%b);
}

// 最小公約数
long lcm(long a, long b) {
	return a / gcd(a, b) * b;
}

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

	string s, t;
	cin >> s >> t;

	// 同じ文字があって、目的の文字が異なればアウト
	vector<pair<int, int>> cc;

	rep(i, s.size()) {
		cc.push_back({ s[i], t[i] });
	}

	sort(allof(cc));

	char nowC = 'a';

	typedef map<char, char> M; // map<key の型, valueの型>
	M mp;
	M rmp;

	bool can = true;
	
	rep(i, cc.size()) {
		/*while (nowC != cc[i].first) {
			if (nowC == 'z') break;
			nowC++;
		}*/
		if (mp[cc[i].first] == 0) {
			mp[cc[i].first] = cc[i].second;
		}
		else {
			if (mp[cc[i].first] != cc[i].second) {
				can = false;
				break;
			}
		}
		if (rmp[cc[i].second] == 0) {
			rmp[cc[i].second] = cc[i].first;
		}
		else {
			if (rmp[cc[i].second] != cc[i].first) {
				can = false;
				break;
			}
		}
	}
	
	if (can) cout << "Yes" << endl;
	else cout << "No" << endl;

	return 0;
}

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

using namespace std;

int test( const vector<int>& v) {
    int buf[3], rv = 0;
    if (v.size()<3) return 0;
    for (size_t off=1; off<v.size()-1; ++off) {
        copy( &v.at(off)-1, &v.at(off)+2, &buf[0]);
	sort(&buf[0], &buf[3]);
        if (buf[1] == v.at(off)) ++rv;
    }
    return rv;
}

int main(void) {
    int N;
    cin >> N;
    vector<int> v;
    v.resize(N);
    for (int i=0; i<N; ++i) {
        cin >> v[i];
    }
    cout << test(v);
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main (String[] args) {
//------------------------------------------------------------

		Scanner sc =new Scanner(System.in);
		String s = sc.nextLine();
      	sc.close();
		String[] strArray = new String[s.length()];

		for (int i = 0; i<=s.length()-1; i++) {
			strArray[i] = String.valueOf(s.charAt(i));
		}
		for (int i =0; 2*i <s.length() ; i++) {
			System.out.print(strArray[2*i]);
		}

//------------------------------------------------------------
	}
}


Measured memory_bytes: 34180
//#include <bits/stdc++.h>
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <climits>
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define ROF(i, j, k) for(int i = (int)(j); i >= (int)(k); --i)
#define FORLL(i, n, m) for(long long i = n; i < (long long)(m); i++)
#define SORT(v, n) sort(v, v+n)
#define REVERSE(v) reverse((v).begin(), (v).end())

using namespace std;
using ll = long long;
const ll MOD=1000000007LL;
typedef pair<int, int> P;

ll ADD(ll x, ll y) { return (x+y) % MOD; }
ll SUB(ll x, ll y) { return (x-y+MOD) % MOD; }
ll MUL(ll x, ll y) { return x*y % MOD; }
ll POW(ll x, ll e) { ll v=1; for(; e; x=MUL(x,x), e>>=1) if (e&1) v = MUL(v,x); return v; }
ll DIV(ll x, ll y) { /*assert(y%MOD!=0);*/ return MUL(x, POW(y, MOD-2)); }

ll nl, nm;

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

  string s;
  cin >> s;

  string s1 = "dream";
  string s2 = "dreamer";
  string s3 = "erase";
  string s4 = "eraser";
  
  bool s1_f=false, s2_f=false, s3_f=false, s4_f=false;
  int i = s.size()-1;      
  while(s.size() > 0){
    s1_f=false, s2_f=false, s3_f=false, s4_f=false;
    REP(j, s1.size()){
      if(s1[s1.size()-1-j] != s[i-j]) s1_f = true;
      if(s3[s3.size()-1-j] != s[i-j]) s3_f = true;      
    }
    REP(j, s2.size()) if(s2[s2.size()-1-j] != s[i-j]) s2_f = true;
    REP(j, s4.size()) if(s4[s4.size()-1-j] != s[i-j]) s4_f = true;      
    
    if(s1_f && s2_f && s3_f && s4_f){cout << "NO" << endl; return 0;}
    if(!s1_f) s.erase(s.size()-s1.size(),s.size());
    if(!s2_f) s.erase(s.size()-s2.size(),s.size());
    if(!s3_f) s.erase(s.size()-s3.size(),s.size());
    if(!s4_f) s.erase(s.size()-s4.size(),s.size());
    i = s.size()-1;
  }
  cout << "YES" << endl;
  
  //vector<string> vs{"dream", "dreamer", "erase", "eraser"};
  //reverse()
  
  return 0;
}

 /*

  */


Measured memory_bytes: 512
N = int(input())
info = [list(map(int, input().split())) for i in range(N)]
#  print(info)

t = 0
for i in range(N):
    if info[i][2] != 0:
        t = i
        break
#  print(t)

def check(Cx, Cy, H):
    for i in range(N):
        if info[i][2] != max(H - abs(info[i][0] - Cx) - abs(info[i][1] - Cy), 0):
            return False
    return True



for Cx in range(101):
    for Cy in range(101):
        H = abs(info[t][0] - Cx) + abs(info[t][1] - Cy) + info[t][2]
        if check(Cx, Cy, H):
            print('{} {} {}'.format(Cx, Cy, H))










Measured memory_bytes: 3064
S = input()
T = input()
lens = len(S)
lent = len(T)
ans = []
for i in range(lens - lent + 1):
	ss = S[i:i+lent]
	count = 0
	for j in range(len(ss)):
		if(ss[j] != T[j]):
			count += 1
	ans.append(count)
print(min(ans))

Measured memory_bytes: 9120
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)  for(long long i=0;i<(long long)(n);i++)
#define Rep(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> PP;
typedef priority_queue<ll> PQ;
typedef priority_queue<ll,vector<ll>,greater<ll>> SMALLPQ;
using vi=vector<ll>;
using vvi=vector<vector<ll>>;
using vc=vector<char>;
using vvc=vector<vector<char>>;
const int inf=1000000007;
const int mod=1000000007;
void chmin(auto &a,auto b){if(b<a)a=b;}
void chmax(auto &a,auto b){if(a<b)a=b;}
int main(){
  ll n,k;cin>>n>>k;
  ll sum=0,ans=0;
  vi v(n);
  rep(i,n){
    cin>>v[i];
    sum+=v[i];
  }
  if(sum<k)cout<<n-1<<endl;
  else if(sum==k)cout<<n<<endl;
  else{
    sort(all(v));
    ll c=0;
    rep(i,n){
      c+=v[i];
      if(c>k){
        cout<<i<<endl;
        return 0;
      }
    }
  }
}


Measured memory_bytes: 256
package main

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

func max(a int, b int) int {
	if a >= b {
		return a
	}
	return b
}

type Node struct {
	Index     int
	Value     int
	Neighbors []*Node
	Len       int
	IsSearched  bool
}

var nodes []*Node
var already map[int]bool

// dp[i]: 長さiの増加部分列において最後の値の最小値
func search(n *Node, dp []int) {
	if n.IsSearched {
		return
	}
	n.IsSearched = true

	idx := sort.SearchInts(dp, n.Value)
	befVal := dp[idx]
	dp[idx] = n.Value
	n.Len = sort.SearchInts(dp, MAX_INT)
	for _, to := range n.Neighbors {
		search(to, dp)
	}
	dp[idx] = befVal
}

func solve(N int, a []int, u []int, v []int) []int {
	//fmt.Printf("%v, %v, %v\n", a, u, v)
	res := make([]int, N)
	nodes = make([]*Node, N)
	for i := 0; i < N; i++ {
		nodes[i] = &Node{i, a[i], nil, 0, false}
	}
	for i := 0; i < N-1; i++ {
		nodes[u[i]-1].Neighbors = append(nodes[u[i]-1].Neighbors, nodes[v[i]-1])
		nodes[v[i]-1].Neighbors = append(nodes[v[i]-1].Neighbors, nodes[u[i]-1])
	}

	dp := make([]int, N)
	for i:=0; i<N; i++ {
		dp[i] = MAX_INT
	}
	//fmt.Printf("準備完了！！\n")
	search(nodes[0], dp)

	for i := 0; i < N; i++ {
		res[i] = nodes[i].Len
	}
	//fmt.Printf("%#v\n", nodes)
	return res
}


func main() {
	sc.Split(bufio.ScanWords)
	var N, K int
	nextInt(&N, &K)
	var d = make([]int, K)
	var A = make([][]int, K)

	var have = make([]int, N)
	for i := 0; i < K; i++ {
		nextInt(&d[i])
		nextInts(&A[i])
		for _, j := range A[i] {
			have[j-1]++
		}
	}
	var ans int
	for i := 0; i < N; i++ {
		if have[i] == 0 {
			ans++
		}
	}
	//fmt.Printf("N: %d, K: %d, d: %v, A: %v\n", N, K, d, A)
	fmt.Printf("%d", ans)
	//res := solve(N, a, u, v)
	//for _, v := range res {
	//	fmt.Printf("%d\n", v)
	//}
}


const MAX_INT int = 1_000_000_000
var sc = bufio.NewScanner(os.Stdin)

var reader = bufio.NewReaderSize(os.Stdin, 1000000)
var writer = bufio.NewWriter(os.Stdout)

func nextLine() string {
	buffer := make([]byte, 0)
	for true {
		line, isPrefix, err := reader.ReadLine()
		if err != nil {
			panic(err)
		}
		buffer = append(buffer, line...)
		if !isPrefix {
			break
		}
	}
	return string(buffer)
}

func nextInt(A ...*int) {
	L := strings.Split(nextLine(), " ")
	for i, a := range A {
		*a, _ = strconv.Atoi(L[i])
	}
}
func nextInts(A *[]int) {
	L := strings.Split(nextLine(), " ")
	(*A) = make([]int, len(L))
	for i, l := range L {
		(*A)[i], _ = strconv.Atoi(l)
	}
}

func nextInt64() int64 {
	sc.Scan()
	hoge := sc.Text()
	i, e := strconv.ParseInt(hoge, 0, 64)
	if e != nil {
		panic(e)
	}
	return i
}


Measured memory_bytes: 2140
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, e) for (int i = (int)(s); i <= (int)(e); i++)
#define printYesNo(is_ok) puts(is_ok ? "Yes" : "No");
#define SORT(v) sort(v.begin(), v.end());
#define RSORT(v) sort(v.rbegin(), v.rend());
#define REVERSE(v) reverse(v.begin(), v.end());

int main()
{
    int N, M;
    cin >> N >> M;
    vector<int> A(N);
    vector<pair<int, int>> card(M);
    priority_queue<int, vector<int>, greater<int>> own_card;
    rep(i, N)
    {
        cin >> A[i];
        own_card.push(A[i]);
    }
    rep(i, M)
    {
        cin >> card[i].second >> card[i].first;
    }
    RSORT(card);

    rep(i, M)
    {
        if (card[i].first <= own_card.top())
            break;

        rep(j, card[i].second)
        {
            own_card.pop();
            own_card.push(card[i].first);
        }
    }

    long long ans = 0;
    while (own_card.size())
    {
        ans += own_card.top();
        own_card.pop();
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 2044
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
#define mod 1000000007
const long double PI = acos(-1);
 
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { return a * b / gcd(a, b); }
 
int main(){
    ll n;
    cin >> n;
    string s[n];
    for(ll i = 0; i < n; i++) cin >> s[i];
 
    int x[10] = {0, 0, 0, 0, 0, 0, 1, 1, 1, 2};
    int y[10] = {1, 1, 1, 2, 2, 3, 2, 2, 3, 3};
    int z[10] = {2, 3, 4, 3, 4, 4, 3, 4, 4, 4};
 
    vector<ll> march(5, 0);
    for(ll i = 0; i < n; i++){
        if(s[i][0] == 'M'){
            march[0]++;
        }
        if(s[i][0] == 'A'){
            march[1]++;
        }
        if(s[i][0] == 'R'){
            march[2]++;
        }
        if(s[i][0] == 'C'){
            march[3]++;
        }
        if(s[i][0] == 'H'){
            march[4]++;
        }
    }
 
    ll ans = 0;
    for(ll i = 0; i < 10; i++){
        ans += march[x[i]] * march[y[i]] * march[z[i]];
    }
    cout << ans << endl;
    return 0;
}

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

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

  double ans = 0;
  double x;
  string u;
  for (int i = 0; i < N; i++) {
    cin >> x >> u;
    if (u == "JPY") {
      ans += x;
    } else {
      ans += 380000.0 * x;
    }
  }
  cout << ans << endl;
 
}


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

divide = 0

i = 0
while i < n:
    while i+1 < n and a[i] == a[i+1]:
        i += 1

    if i+1 < n and a[i] < a[i+1]:
        while i+1 < n and a[i] <= a[i+1]:
            i += 1

    elif i+1 < n and a[i] > a[i+1]:
        while i+1 < n and a[i] >= a[i+1]:
            i += 1

    divide += 1
    i += 1

print(divide)

Measured memory_bytes: 14428
import           Control.Monad
import qualified Data.ByteString.Char8 as BS
import           Data.Foldable
import           Data.Maybe
import qualified Data.Sequence         as Seq

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine

main = do
  [x, y, a, b, c] <- getIntList
  ps <- getIntList
  qs <- getIntList
  rs <- getIntList

  let ps' = Seq.take x $ Seq.unstableSortBy (flip compare) $ Seq.fromList ps
      qs' = Seq.take y $ Seq.unstableSortBy (flip compare) $ Seq.fromList qs
      ss = ps' Seq.>< qs' Seq.>< Seq.fromList rs
      ans = sum $ Seq.take (x+y) $ Seq.unstableSortBy (flip compare) ss

  print ans

Measured memory_bytes: 72060
#include <iostream>
//#include <iomanip>
//#include <string>
#include <vector>
//#include <algorithm>
//#include <utility>
//#include <set>
//#include <map>
//#include <queue>
//#include <deque>
//#include <bitset>
//#include <math.h>
using namespace std ;
using ll = long long ;
//using ld = long double ;
using vll = vector<ll> ;
//using vvll = vector<vll> ;
//using vc = vector<char> ;
//using vvc = vector<vc> ;
//using vb = vector<bool> ;
//using vvb = vector<vb> ;
//using pll = pair<ll,ll> ;
//#define all(v) v.begin(),v.end()
//ll mod = 1000000007 ;
//long double pie = acos(-1) ;
//ll INF = 1000000000000 ;

//void yorn(bool a){if(a) cout << "Yes" << endl ; else cout << "No" << endl ;}
//void YorN(bool a){if(a) cout << "YES" << endl ; else cout << "NO" << endl ;}
//ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
//ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
//ll sa(long long a,long long b){if(a>b) return a-b ; return b-a ;}
//void fix_cout(){cout << fixed << setprecision(20) ;}

int main(){
	ll n ; cin >> n ;
	vll a(n+1),b(n) ;
	for(auto &i:a) cin >> i ;
	for(auto &i:b) cin >> i ;
	ll ans = 0 ;
	for(int i=0;i<n;i++){
		if(a.at(i)>b.at(i)){
			ans += b.at(i) ;
			continue ;
		}
		ans += a.at(i) ;
		b.at(i) -= a.at(i) ;
		if(a.at(i+1)>=b.at(i)){
			ans += b.at(i) ;
			a.at(i+1) -= b.at(i) ;
		}else{
			ans += a.at(i+1) ;
			a.at(i+1) = 0 ;
		}
	}
	cout << ans << endl ;
}


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

int main(int argc, char **argv) {
  double w, h, x, y;
  scanf("%lf %lf %lf %lf", &w, &h, &x, &y);
  printf("%.10lf %d\n", w*h/2, (w/2==x && h/2==y) ? 1 : 0);
  return 0;
}


Measured memory_bytes: 384
from collections import deque
n=int(input())
l=deque()

def push(L,d,x):
    if d=="0":
        L.appendleft(x)
    else:
        L.append(x)

def pop(L,d):
    if d=="0":
        L.popleft()
    else:
        L.pop()

for i in range(n):
    q=input().split()
    if q[0]=="0":
        push(l,q[1],q[2])
    elif q[0]=="1":
        print(l[int(q[1])])
    else:
        pop(l,q[1])


Measured memory_bytes: 34652
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
 
int main() {
  int  N, sum = 0;
  cin >> N;
  vector<int> vec(N);
  for (int i = 0; i < N; i++) {
    cin >> vec.at(i);
  }

  sort(vec.begin(), vec.end());
  vec.at(N-1) = vec.at(N-1)/2;
  
  for (int i = 0; i < N; i++) {
    sum = sum + vec.at(i);
  }
 
  cout << sum << endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
      int N = sc.nextInt();
      int M = sc.nextInt();
      int ans=0;
      if(N>=2){
        ans+= N*(N-1)/2;
      }
      if(M >=2){
        ans+=M*(M-1)/2;
      }
      System.out.println(ans);
	}
}

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

#define GO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long int

const int maxr = 2e3 + 5;
const int M = 1e9 + 7;
int dp[maxr];

int solve(int s) {
	if (s == 0)
		return 1;
	if (s == 1 || s == 2)
		return 0;
	int &ans = dp[s];
	if (ans != -1)
		return ans;
	ans = 0;
	for (int i = 3; i <= s; i++) {
		ans += solve(s - i);
		ans %= M;
	}
	return ans;
}

int32_t main()
{
	GO;
	int s;
	cin >> s;
	memset(dp, -1, sizeof(dp));
	int ans = solve(s);
	cout << ans << endl;
	return 0;
}

//!

Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N=300005,M=998244353;
char s[N];
int r,b,g,rb,rg,bg,n,ans=1;
signed main(){
	scanf("%lld",&n);
	scanf("%s",s+1);
	for (int i=1;i<=3*n;i++){
		if (s[i]=='R'){
			if (bg){
				(ans*=bg)%=M;
				bg--;
			}
			else if (b){
				(ans*=b)%=M;
				b--;rb++;
			}
			else if (g){
				(ans*=g)%=M;
				g--;rg++;
			}
			else r++;
		}
		if (s[i]=='G'){
			if (rb){
				(ans*=rb)%=M;
				rb--;
			}
			else if (r){
				(ans*=r)%=M;
				r--;rg++;
			}
			else if (b){
				(ans*=b)%=M;
				b--;bg++;
			}
			else g++;
		}
		if (s[i]=='B'){
			if (rg){
				(ans*=rg)%=M;
				rg--;
			}
			else if (r){
				(ans*=r)%=M;
				r--;rb++;
			}
			else if (g){
				(ans*=g)%=M;
				g--;bg++;
			}
			else b++;
		}		
	}
	for (int i=1;i<=n;i++)(ans*=i)%=M;
	printf("%lld\n",ans);
}

Measured memory_bytes: 512
import java.util.*;
import javax.lang.model.util.ElementScanner6;

class Music {
    String title;
    long time;

    Music(String s, long t) {
        title = s;
        time = t;
    }
}

public class Main {

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

        // 入力
        String c = sc.next();

        // 処理
        char out = c.toCharArray()[0];
        out++;

        // 出力
        System.out.println(out);
    }
}

Measured memory_bytes: 21716
use std::collections::HashMap;

#[allow(dead_code)]
fn rd() -> String {
    let mut input = String::new();
    std::io::stdin().read_line(&mut input).unwrap();
    input.trim().to_owned()
}

/// 1行の文字を空白で分割してVec<T>にする。
#[allow(dead_code)]
fn rd_vec<T : std::str::FromStr>() -> Vec<T> {
    rd().split_whitespace().map(|x| x.parse().ok().unwrap()).collect()
}

/// 1つの要素を入力で受け取る
#[allow(dead_code)]
fn rd_one<T : std::str::FromStr>() -> T {
    rd().parse().ok().unwrap()
}

/// 複数回read_splitを行う
#[allow(dead_code)]
fn rd_vec_mul<T : std::str::FromStr>(count : i32) -> Vec<Vec<T>> {
    (0..count).map(|_| rd_vec()).collect()
}

/// Vecを1列で出力する
#[allow(dead_code)]
fn op_vec<T : std::fmt::Display>(item : Vec<T>, splitter : char) {
    let cnt = item.len();
    let mut c = 0;
    for i in item.iter() {
        c+=1;
        if cnt > c {print!("{}{}", i, splitter);} else {println!("{}", i);}
    }
}

fn main() {
    let ia : i32 = rd_one();
    let input : Vec<i32> = rd_vec();
    let mut map = HashMap::<i32,i32>::new();
    for i in 0..ia {
        map.insert(input[i as usize], i + 1);
    }
    let mut vec : Vec<i32> = Vec::new();
    for i in 0..ia {
        let ga = map[&(&i + 1)];
        vec.push(ga);
    }
    op_vec(vec, ' ');
}



Measured memory_bytes: 8444
/*
 
@author
_      _          _                 _      _
\\    // /\    | | \  |     |    /\ \\    //     
 \\  // /__\   | |_/  |_____|   /__\ \\  //
  \\// /    \  | | \  |     |  /    \ \\//
   \/ /      \ | |_/  |     | /      \ \/
@ Indian Institute of Technology Bhilai

With practice comes perfection,
with knowledge comes wisdom.
Incorporate wisdom in you, practice will harvest better results.
Always learn from others, your method is good but someone's even better.
Results take time, run for wisdom, for innovation, for getting better.
Points are mere objects, either you solve first or you solve better.
Seek for betterment, for quality, pace is important but cannot outstand
the quality you persist.
Times are bad just as now but it'll improve, this is my passion and I promise 
I won't let it go. I'll build myself again like a fighter gets back up after 
being thrown to the ground.
I'll learn. I bet that. I promise that.
*/
 
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ul;
#define rep(i,n) for(ll i=0; i<n; i++)
#define rep1(i,n) for(ll i=1; i<=n; i++)
#define pb push_back
#define fi first
#define se second
#define all(v) v.begin(), v.end()
#define alla(arr,n) arr, arr+n
#define yes cout<<"YES\n"
#define no cout<<"NO\n"
#define fsync ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
const ll maxx =  1e9+7;

bool compare(const pair<ll,ll> &a, const pair<ll,ll> &b){
    return a.fi>b.fi;
}

ll inline power(ll a, ll b, ll p){
    a %= p;
    ll ans = 1;
    while(b>0){
        if(b & 1)
            ans = (ans*a)%p;
        a = (a*a)%p;
        b >>= 1;
    }
    return ans;
}

ll inv(ll n, ll p){
    return power(n,p-2, p);
}

bool inline isPrime(ll n) { 
    if (n <= 1)  return false; 
    if (n <= 3)  return true; 
    if (n%2 == 0 || n%3 == 0) return false; 
    for (ll i=5; i*i<=n; i=i+6) 
        if (n%i == 0 || n%(i+2) == 0) 
           return false; 
    return true; 
}

template<class T>
void printv(T &v, ll n){
    if(n==-1)
        n = v.size();
    rep(i,n)
        cout << v[i] << " ";
    cout << "\n";
}

void solve(){
    ll x,y=100;
    cin>>x;
    ll ans=0;
    while(y<x){
        y+=(y/100);
        ans++;
    }
    cout << ans << "\n";
}

int main(){
    fsync
    ll test=1;
    // cin >> test;
    while(test--){
        solve();
    }
}

Measured memory_bytes: 3648
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>

using namespace std;

int main()
{
  int N;
  cin >> N;
  vector<double> v(N, 0);
  for (int i = 0; i < N;i++){
    cin >> v[i];
  }

  sort(v.begin(), v.end());
  double data = (v[0] + v[1]) / 2;

  for (int i = 2; i < N; i++)
  {
    data = (v[i] + data) / 2;
  }
  cout << data;
}


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

int main() {
  int n;
  cin >> n;
  vector<int> w(n);
  for(int i = 0; i < n; i++) cin >> w.at(i);
  
  vector<int> sum(n, w.at(0));
  int total = w.at(0);
  for(int i = 1; i < n; i++){
    sum.at(i) = w.at(i) + sum.at(i - 1);
    total += w.at(i);
  }
  
  int ans = 10000000;
  for(int i = 0; i < n; i++){
    int k = abs(sum.at(i) - total + sum.at(i));
    ans = min(ans, k);
  }
  
  cout << ans << endl;
}

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

#define M 200
#define N 1000
#define INT(X) \
  ( (const int *)(X) )

static int
compare (
  const void * a,
  const void * b
  )
{
  if ( INT( a )[ 0 ] == INT( b )[ 0 ] )
  {
    return ( INT( a )[ 1 ] - INT( b )[ 1 ] );
  }

  return ( INT( a )[ 0 ] - INT( b )[ 0 ] );
}

/** Application main entry point. */
int
main (
  int     argc,
  char  * argv[ ]
  )
{
  int i, j, k;

  for ( ; ; )
  {
    int dm[ M ][ 2 ]
      , dn[ N ][ 2 ];
    int m, n;

    scanf ( "%d", &m );
    if ( !( m ) ) break ;
    for ( i = 0; i < m; ++i )
    {
      scanf ( "%d%d", &dm[ i ][ 0 ], &dm[ i ][ 1 ] );
    }
    scanf ( "%d", &n );
    for ( i = 0; i < n; ++i )
    {
      scanf ( "%d%d", &dn[ i ][ 0 ], &dn[ i ][ 1 ] );
    }

    qsort ( dm, m, sizeof ( int ) * 2, compare );
    qsort ( dn, n, sizeof ( int ) * 2, compare );

    for ( i = 0; i < n - m; ++i )
    {
      const int dx = dn[ i ][ 0 ] - dm[ 0 ][ 0 ]
              , dy = dn[ i ][ 1 ] - dm[ 0 ][ 1 ];

      for ( j = 1, k = i + j; j < m && k < n; ++k )
      {
        if ( dn[ k ][ 0 ] != dm[ j ][ 0 ] + dx ) continue ;
        j += !!( dn[ k ][ 1 ] == dm[ j ][ 1 ] + dy );
      }
      if ( j == m )
      {
        printf ( "%d %d\n", dx, dy );
        break ;
      }
    }
  }

  return ( 0 );
}

Measured memory_bytes: 0
#include<iostream>
#include<string>
#include<math.h>
#include<algorithm>
#include<vector>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
int main(){
    string s;
    cin>>s;
    if(s[5]-'0'==0&&s[6]-'0'<=4) cout<<"Heisei";
    else cout<<"TBD";
}

Measured memory_bytes: 256
#16D8101012J 伊藤惇 dj Python3 

def Greatest_Common_Divisor(x,y):
    if y>x:
        x,y=y,x
    if x>=y and y>0:
        return Greatest_Common_Divisor(y,x%y)
    return x

if __name__ == "__main__":
    x=list(map(int,input().split()))
    print(Greatest_Common_Divisor(x[0],x[1]))




Measured memory_bytes: 5600
#include<stdio.h>
#define N 100

int a[N+1][N+1];
int d[N+1];
int flg[N+1];

typedef struct Que{
	int num[N+1];
	int top;
}Que;

Que Q;

void enqueue(int x){
	Q.num[Q.top++]=x;
	return;
}

int dequeue(){
	int x=Q.num[0];
	for(int i=0;i<Q.top-1;i++)
		Q.num[i]=Q.num[i+1];
	Q.top--;
	return x;
}

void bfs(int u,int n){
	Q.top=0;
	
	enqueue(u);
	d[u]++;
	flg[u]=1;
	
	while(Q.top>0){
		int v=dequeue();
		for(int i=1;i<=n;i++){
			if(a[v][i]==1 && !flg[i]){
				enqueue(i);
				d[i]=d[v]+1;
				flg[i]=1;
			}
		}
	}
	
	return;
	
}

int main(){
	int n,i,j;
	int x,y,z;
	
	scanf("%d",&n);
	
	for(i=0;i<=n;i++){
		d[i]=-1;
		flg[i]=0;
		for(j=0;j<=n;j++){
			a[i][j]=0;
		}
	}
	
	for(i=0;i<n;i++){
		scanf("%d %d",&x,&y);
		for(j=0;j<y;j++){
			scanf("%d",&z);
			a[x][z]=1;
		}
	}
	
	bfs(1,n);
	
	for(i=1;i<=n;i++)
		printf("%d %d\n",i,d[i]);
	
	return 0;
	
}


Measured memory_bytes: 2104
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) FOR(i,0,n)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll INF = 1e10;
int N,W;
int w[105],v[105];
vector<vector<ll>> dp(105,vector<ll>(100005,INF));
void knapsack(){
    rep(i,N) rep(j,100001){
        if (j >= v[i]) dp[i+1][j] = min(dp[i][j],dp[i][j-v[i]]+w[i]);
        else dp[i+1][j] = dp[i][j];
    }
}
int main(){
    cin >> N >> W;
    rep(i,N) cin >> w[i] >> v[i];
    rep(i,N+1) dp[i][0] = 0;
    knapsack();
    ll ans = 0;
    rep(i,100001){
        if (dp[N][i] <= W){
            ans = i;
        }
    }
    PRINT(ans);
}


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

int gcd(int a, int b){
    if(b==0)
    return a;

    return gcd(b, a%b);
}

int main(){
    while(true){
        int a,b;
        cin>>a>>b;
        if(cin.eof())
        break;
        int g = gcd(a,b);
        cout << g << ' ' << a/g*b << endl;
    }
    return 0;
}


Measured memory_bytes: 3084
s = input()
K = int(input())

s_sub = list()
s_len = len(s)
for i in range(s_len):
    s_sub.append(s[i:])
    
s_sub.sort()
s_sub.append('')

pre_sum = 0
sum = len(s_sub[0])
z=0
for j in range(1,s_len+1):
    
    current = s_sub[j]
    before = s_sub[j-1]

    
    if sum >= K:
        print(before[:K-pre_sum+z])
        break

    z = 0
    for k in range(min(len(current),len(before))):
        if current[k] == before[k]:
            z+=1
        else:
            break  
    pre_sum =  sum 
    sum += len(current) - z

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

typedef long long ll;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define each(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); ++itr)
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define fi first
#define se second

const ll INF=123456789012345LL;

int main()
{
    int n,m;
    ll k;
    cin >>n >>m >>k;
    vector<ll> a(n);
    rep(i,n) cin >>a[i];

    ll dp[20001];
    fill(dp,dp+n+1,INF);
    dp[0]=0;

    //?§????i
    rep(i,n)
    {
        ll x=0, y=1234567890LL;
        //??????j
        for(int j=i; j<min(n,i+m); ++j)
        {
            x=max(x,a[j]);
            y=min(y,a[j]);
            int s=j-i+1;

            dp[j+1]=min(dp[j+1],dp[i]+k+s*(x-y));
        }
    }

    cout << dp[n] << endl;
    return 0;
}

Measured memory_bytes: 3248
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < n; i++)
#define repr(i, n) for(ll i = n; i >= 0; i--)
#define inf LLONG_MAX
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;


int main()
{
    ll n; cin >> n;
    vll l(n);
    rep(i, n) cin >> l[i];
    sort(all(l));
    ll cnt = 0;
    for (int a = 0; a < n - 2; a++) {
        for (int b = a + 1; b < n - 1; b++) {
            for (int c = b + 1; c < n; c++) {
                if (l[a] < l[b] + l[c] &&
                    l[b] < l[c] + l[a] &&
                    l[c] < l[a] + l[b]) cnt++;
            }
        }
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
while True:
    ten=input()
    if ten=='0':
        break
    a=ten.count('A')
    b=ten.count('B')
    if ten[0]=='A':
        a-=1
    elif ten[0]=='B':
        b-=1
    if a>b:
        a+=1
    else:
        b+=1
    print(a,b)


Measured memory_bytes: 5556
#include<iostream>
#include<map>
#include<queue>
#include<vector>
#include<algorithm>

using namespace std;

const string goal = "01234567";
typedef pair<string,int> P;
map<string,int> M;

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


int getpos(string s){

  for(int i = 0; i < s.length(); i++)
    if(s[i] == '0') return i;

  return 0;
}

vector<int> getable(int n){
  vector<int> V;

  for(int i = 0; i < 4; i++){
    int nex = n+dx[i];
    if(0 <= nex && nex <= 7){
      if(!(n == 3 && nex == 4 || n == 4 && nex == 3)) V.push_back(nex);
    }
  }
  return V;
}

void make(){
  queue<string> Q;

  Q.push(goal);
  M[goal] = 1;

  while(!Q.empty()){
    string s = Q.front();
    Q.pop();
    int pos = getpos(s);
    vector<int> able = getable(pos);

    for(int i = 0; i < able.size(); i++){
      string next = s;
      swap(next[pos],next[able[i]]);
      if(M[next] == 0){
	M[next] = M[s]+1;
	Q.push(next);
      }
    }
  }
}
int main(){
  make();

  int data[8];

  while(1){
    for(int i = 0; i < 8; i++)
      if(!(cin >> data[i])) return 0;
    
    string s = "";
    
    for(int i = 0; i < 8; i++)
      s += data[i]+'0';
    
    cout << M[s]-1<< endl;
  }
  return 0;
}

Measured memory_bytes: 3460