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

const int MAX = 14;
const int INF = 1e8;

int N;
int d[MAX][MAX];

int dp[1<<MAX][MAX];


int rec(int S, int v)
{
	if (dp[S][v]>=0) {
		return dp[S][v];
	}
	
	if (S==(1<<N)-1) {
		return dp[S][v] = 0;
	}
	
	int res=INF;
	for (int u=0; u<N; u++) {
		if (!(S>>u&1)) {
			res = min(res, rec(S|1<<u, u)+d[v][u]);
		}
	}
	return dp[S][v] = res;
}

int main()
{
	while (cin>>N, N) {
		vector<string> c(N);
		for (int i=0; i<N; i++) {
			cin>>c[i];
		}
		
		vector<string> erase;
		for (int i=0; i<N; i++) {
			for (int j=0; j<N; j++) {
				if (i!=j) {
					if (c[i].find(c[j]) != string::npos) {
						if (c[i].size() > c[j].size() && c[i].size()<=20) {
							erase.push_back(c[j]);
						} else {
							erase.push_back(c[i]);
						}
					}
				}
			}
		}
		
		for (int i=0; i<erase.size(); i++) {
			for (int j=0; j<c.size(); j++) {
				if (erase[i] == c[j]) {
					c.erase(c.begin()+j);
					break;
				}	
			}
		}
		
		/**
		for (int i=0; i<c.size(); i++) {
			cerr << c[i] << endl;
		} **/
		
		
		N = c.size();
		fill(d[0], d[0]+MAX*MAX, INF);
		memset(dp, -1, sizeof(dp));
	
		for (int i=0; i<N; i++) {
			for (int j=0; j<N; j++) {
				if (i!=j) {
					string f = c[i], t = c[j];
					int tmp=0;
					for (int a=0; a<f.size(); a++) {
						bool ok=true;
						for (int b=0; b<a; b++) {
							if (b>=t.size() || f[f.size()-a+b] != t[b]) {
								ok = false;
							}
						}
						if (ok) tmp = max(tmp, a);
					}
					d[i][j] = min((int)t.size()-tmp, d[i][j]);
				}
			}
		}
		
		/**
		for (int i=0; i<N; i++) {
			for (int j=0; j<N; j++) {
				cerr<<d[i][j]<< " ";
			}
			cerr << endl;
		} **/
		
		int res = INF;
		for (int u=0; u<N; u++) {
			res = min(res, rec(1<<u, u)+(int)c[u].size());
		}
		
		cout << res << endl;
	}	
}

Measured memory_bytes: 2124
// include
// ------------------------------------------------
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <math.h>

using namespace std;

// func
// ------------------------------------------------
int CalcSumOfDigit(int n);      // 各桁の和を計算する。
string upper(string str);       // 英字を大文字に変換する。
string lower(string str);       // 英字を小文字に変換する。

// define
// ------------------------------------------------
#define all(a)        (a).begin(),(a).end()
#define rall(a)       (a).rbegin(),(a).rend()
#define sz(a)         int((a).size())
#define rep(i,n)      for(int(i)=0;(i)<(n);(i)++)
#define repe(i,n)     for(int(i)=0;(i)<=(n);(i)++)
#define vsort(v)      sort((v).begin(),(v).end())
#define rvsort(v)     sort(rall((v)))
#define vi            vector<int>
#define GCD(a,b)      __gcd((a),(b))
#define LCM(a,b)      (a)/GCD((a),(b))*(b)
#define kiriage(a,b)  ((a)+(b)-1)/(b)

const int INF = 1e9;

// code
// ------------------------------------------------
int main() {

  int n,m,x;
  cin >> n >> m >> x;

  vi a(m);
  rep(i,m) cin >> a[i];

  int l = 0;
  int r = 0;
  for(int i = 0;i < m;i++)
  {
    if(a[i] < x)
      r++;
    else
      l++;
  }


  cout << min(r,l) << endl;




  return 0;
}
// funcの実体
// ------------------------------------------------
int CalcSumOfDigit(int n)
{
  int s = 0;
  while(n)
  {
    s += n % 10;
    n = n / 10;
  }
  return s;
}

string upper(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(97 <= *itr && *itr <= 122)
    {
      *itr = *itr - 32;
    }
  }
  return str;
}

string lower(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(65 <= *itr && *itr <= 90)
    {
      *itr = *itr + 32;
    }
  }
  return str;
}


Measured memory_bytes: 256
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Queue;
import java.util.Scanner;
 


public class Main {
	private static Scanner sc = new Scanner(System.in);
	//result = Math.pow(num1, num3)
	//StringBuffer str = new StringBuffer(hoge1);
	//String hoge2 = str.reverse().toString();
	//map.containsKey(A)

	//Map<String, Integer> map = new HashMap<String, Integer>(n);
	/*for ( キーのデータ型 key : マップの名前.keySet() ) {
		データのデータ型 data = マップの名前.get( key );
		
		// keyやdataを使った処理;
	}*/
	//int i = Integer.parseInt(s);
	//Queue<String> qq=new ArrayDeque<>(); //add,poll,peek
	//Deque<String> qq=new ArrayDeque<>();//push,pop,peek
	//ArrayList<String> cc = new ArrayList<>(n);
	//Collections.sort(list);
	//Array.sort(list);   cc.contains(tmp)
	//Arrays.asList(c).contains("a")
	//list.set(1,"walk");//1 1 2 3 5
	//static long mod =1000000007;
	//static 	ArrayList<Integer> cc = new ArrayList<>(100);
	
	
	
	
	//for(int i=0;i<N;i++) {}
	public static void main(String[] args) {
		//int N=sc.nextInt();for(int i=0;i<N;i++) {}
		int A=sc.nextInt();
		int B=sc.nextInt();
		
		int v=(A+B)/2;
		
		if(Math.abs(A-v)==Math.abs(B-v)) {
			p(v);
		}else p("IMPOSSIBLE");
		
		
	}
	

	
	
	
	

	


	
	static void p(String ans) {System.out.println(ans);};
	static void p(int ans) {System.out.println(ans);};
	static void p() {System.out.println();};
	static void p(long ans) {System.out.println(ans);};
	static void p(double ans) {System.out.println(ans);};
	static String nextPermutation(String s) {
		ArrayList<Character> list=new ArrayList<>();
		for(int i=0;i<s.length();i++) {
			list.add(s.charAt(i));
		}
		int pivotPos=-1;
		char pivot=0;
		for(int i=list.size()-2;i>=0;i--) {
			if(list.get(i)<list.get(i+1)) {
				pivotPos=i;
				pivot=list.get(i);
				break;
			}
		}
		if(pivotPos==-1&&pivot==0) {
			return "Final";
		}
		int L=pivotPos+1,R=list.size()-1;
		
		
		
		int minPos=-1;
		char min =Character.MAX_VALUE;
		
		for(int i=R;i>=L;i--) {
			if(pivot<list.get(i)) {
				if(list.get(i)<min) {
					min=list.get(i);
					minPos=i;
				}
			}
		}
		
		Collections.swap(list, pivotPos, minPos);
		Collections.sort(list.subList(L, R+1));
		
		
		StringBuilder sb=new StringBuilder();
		for(int i=0;i<list.size();i++) {
			sb.append(list.get(i));
		}
		return sb.toString();
	}
}
	


Measured memory_bytes: 21972
use std::io::*;
use std::str::FromStr;
use std::cmp::{max, min};

fn read<T: FromStr> () -> T {
    let stdin = std::io::stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn count_factors(n: usize) -> usize {
    let mut count: usize = 0;
    for i in 1..(n+1) {
        if n % i == 0 {
            count += 1;
        }
    }
    count
}

fn main() {
    let N: usize = read();

    let mut ans:usize = 0;
    for x in (1..(N+1)).filter(|x| x % 2 != 0) {
        if count_factors(x) == 8 {
            ans += 1;
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
def main():
    N, X, Y = map(int, input().split())
    X -= 1
    Y -= 1

    ans = [0] * N
    for j in range(N):
        for i in range(j):
            d = min(
                j - i,
                abs(j - X) + 1 + abs(Y - i),
                abs(j - Y) + 1 + abs(X - i)
            )
            ans[d] += 1

    print(*ans[1:], sep='\n')


if __name__ == '__main__':
    main()


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

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

	//string s;
	int a;//,b,c;

	cin >> a;// >> b >> c;
	
	int ans=3*a*a;
	
	//if(ans<0) ans=0;
	
	cout << ans << "\n";
	
	
	return 0;

    }

Measured memory_bytes: 256
import numpy as np
import itertools
import queue

def accept_input():
    N,M = map(int,input().split())
    G = {}
    for _ in range(M):
        a,b = map(int,input().split())
        if a not in G:
            G[a] = [b]
        else:
            G[a].append(b)
        if b not in G:
            G[b] = [a]
        else:
            G[b].append(a)
    return N,M,G


def widthsearch(q):
    global curvisited
    movelist = [(0,1),(0,-1),(1,0),(-1,0)] 
    lastplace = ((0,0),0)
    cur = 0
    while curvisited < H*W:
        q1 = queue.Queue()
        cur += 1
        while not q.empty():
            pack = q.get()
            y = pack[0][0]
            x = pack[0][1]
            num = pack[1]
            for move in movelist:
                if y+move[0] == -1 or y + move[0] == H or x+move[1] == -1 or x + move[1] == W:
                    continue
                elif visitedlist[y+move[0]][x+move[1]] == 1:
                    continue
                elif S[y+move[0]][x+move[1]] == "#":
                    continue
                else:
                    visitedlist[y+move[0]][x+move[1]] = 1
                    curvisited += 1
                    q1.put(((y+move[0],x+move[1]),num+1))
            if curvisited == H*W:
                break
        q = q1
    return cur

N,M,G = accept_input()
l = []
for i in range(2,N+1):
    l.append(i)
al = 0
for comb in itertools.permutations(l, N-1):
    if comb[0] not in G[1]:
        continue
    for i in range(0,N-2):
        if comb[i+1] not in G[comb[i]]:
            break
    else:
        al += 1
print(al)


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

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

using namespace std;

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

	string res;
	for(char c:s){
		if(c!='B') res+=c;
		else if(!res.empty()) res.pop_back(); 
	}
	cout<<res<<'\n';

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <sstream>
#include <string>
#define _repargs(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _repargs(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define inf 2000000007
#define mp make_pair
#define pb push_back
typedef long long ll;
using namespace std;
template <typename T>
inline void output(T a, int p = 0) {
    if(p) cout << fixed << setprecision(p)  << a << "\n";
    else cout << a << "\n";
}
// end of template

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    // source code
    int N;
    cin >> N;
    vector<ll> A(N + 1);
    rep(i, N + 1) cin >> A[i];
    reverse(all(A));
    if(N == 0 && A[0] != 1) {
        output(-1);
        return 0;
    }
    if(N >= 1 && A[N] != 0) {
        output(-1);
        return 0;
    }
    
    vector<pair<ll, ll>> mm(N + 1);
    rep(i, N + 1) {
        if(i == 0) mm[i] = mp(A[i], A[i]);
        else {
            mm[i] = mp(A[i] + (mm[i - 1].first + 1) / 2, A[i] + mm[i - 1].second);
        }
    }
    
    ll cur = 1;
    bool ok = true;
    vector<ll> B(N + 1);
    for(int i = N; i >= 0; i--) {
        if(i == N) {
            B[i] = cur;
            cur -= A[i];
        }
        else {
            if(mm[i].first > cur * 2 || cur > mm[i].second) {
                ok = false;
                break;
            }
            cur *= 2;
            cur = min(cur, mm[i].second);
            B[i] = cur;
            cur -= A[i];
        }
    }
    
    if(!ok) {
        output(-1);
        return 0;
    }
    ll ans = 0;
    rep(i, N + 1) ans += B[i];
    output(ans);
    
    
    
    return 0;
}


Measured memory_bytes: 6372
#include<cstdio>
#include<iostream>
#include<vector>
#include<tuple>
#include<queue>
#include<algorithm>
#include<string.h>
#include<math.h>

using namespace std;

int main(int argc, char* argv[]){
  int n;
  int num;
  int ans=0;
  scanf("%d%d",&n);
  for(int i=0;i<=2;i++){
    num = n%10;
    if(num == 1){
      num = 9;
    }
    else num = 1;
    ans += num*(int)pow(10,i);
    n = n/10;
  }
  printf("%d\n",ans);
  return 0;
}

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

int main()
{
	string s, t;
	cin >> s >> t;

	sort(s.begin(), s.end());
	sort(t.rbegin(), t.rend());

	cout << ((s < t) ? "Yes" : "No") << endl;

	return 0;
}

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

int main(){
  int n,tmp;
  cin >> n;
  int ans[n],a[n-1];
  for(int i=0;i<n;i++) ans[i]=0;
  for(int i=0;i<n-1;i++){
    cin >> tmp;
    ans[tmp-1]++;
  }
  
  
  for(int i=0;i<n;i++)
    cout << ans[i] << endl;
  
  return 0;
}

Measured memory_bytes: 4380
n=input()
k=int(input())
L=len(n)
conf=[[0 for i in range(k+1)] for j in range(L)]
conf[0][1]=int(n[0])-1
conf[0][0]=1
notconf=[[0 for i in range(k+1)] for j in range(L)]
notconf[0][1]=1
for i in range(1,L):
    if n[i]=="0":
        for j in range(k+1):
            notconf[i][j]=notconf[i-1][j]
        conf[i][0]=conf[i-1][0]
        for j in range(1,k+1):
            conf[i][j]=9*conf[i-1][j-1]+conf[i-1][j]
    else:
        looking=int(n[i])
        for j in range(1,k+1):
            notconf[i][j]=notconf[i-1][j-1]
        conf[i][0]=conf[i-1][0]
        for j in range(1,k+1):
            conf[i][j]=notconf[i-1][j]+notconf[i-1][j-1]*(looking-1)+conf[i-1][j-1]*9+conf[i-1][j]
print(notconf[-1][k]+conf[-1][k])

Measured memory_bytes: 3064
#include<vector>
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include <iostream>
#include <algorithm>
#include <map>
#include <cmath>
#include<queue>
#include <sstream>
#include <set>

const long long INF = 1000000007;
using namespace std;
typedef long long llong;

//int isalpha(char ch): ch がアルファベットなら true を返す
//int isdigit(char ch): ch が数字なら true を返す
//int islower(char ch): ch が小文字なら true を返す
//int isupper(char ch): ch が大文字なら true を返す
//int tolower(char ch): ch の小文字を返す
//int toupper(char ch): ch の大文字を返す

//string型
//size()	文字数を返す
//Insert()	（指定した場所に）文字・文字列を挿入する
//erase()	（指定した場所の）文字・文字列を削除する
//clear()	すべての文字を削除する
//substr()	文字列の（指定した）部分文字列を返す
//replace()	（指定した）部分文字列を新しい文字列に置換する
//c_str()変換
//文字列の比較は、<=や==などを使え
//replace関数を使い、簡単に文字列を置換
//リバース関数：reverse(str.begin(), str.end());
//map<type, type> dict;で宣言
//グラフ理論用変数
//vector<vector<llong> > graph(N);

//ソート
//降順sort(v.begin(), v.end(), std::greater<Type>());

//大文字から小文字へんかん
//w[i] = w[i]-'A'+'a';

//vector
//assignメソッド　引数：サイズ、値
//与えられたサイズと値でvectorを初期化する

//queueクラス
//find()次に取り出す値の表示をする。
//pop()値を取り出す。戻り値はなし
//push()キューに値をプッシュする

//priority_queueクラス

//切り上げ
//ceil
//floor

int main(){
    llong N;
    cin >> N;
    llong temp;
    llong cnt;
    llong ans=-1;
    llong num;

    for(int i=1; i<=N; i++){
        temp = i;
        cnt = 0;
        while(temp%2==0){
            temp = temp / 2;
            cnt++;
        }
        if(cnt>ans){
            ans = cnt;
            num = i;
        }
    }
    cout << num << endl;
    return 0;
}


Measured memory_bytes: 3184
#include <iostream>
#include <sstream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <utility>
#include <map>
#include <list>
#include <climits>
#include <set>
#include <deque>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <bitset>

// #define cerr if(false)cerr
#define watch(x) cerr << "> " << #x << ": " << x << "\n";

using namespace std;

template <typename T>
std::ostream &operator <<(std::ostream &out, vector<T> &v) {
	for (typename vector<T>::size_type i = 0; i < v.size(); ++i)
		out << v[i] << " ";
	out << "\n";
    return out;
}
template <typename T, typename N>
std::ostream &operator <<(std::ostream &out, vector<pair<T, N> > &v) {
	for (size_t i = 0; i < v.size(); ++i)
		out << "(" << v[i].first << ", " << v[i].second << ") ";
	out << "\n";
    return out;
}
template <typename T>
std::ostream &operator <<(std::ostream &out, vector<vector<T> > &v) {
	for (size_t i = 0; i < v.size(); ++i) {
		for (size_t j = 0; j < v[i].size(); ++j) {
			out << v[i][j] << " ";
		}
		out << "\n";
	}
   	return out;
}

int main() {

	std::ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	int n;
	cin >> n;

	string directions;
	cin >> directions;

	int e_right = 0;
	for (int i = 0; i < n; ++i) {
		if (directions[i] == 'E') {
			++e_right;
		}
	}

	int w_left = 0;
	int min_changes = 1e9;
	for (int i = 0; i < n; ++i) {
		if (directions[i] == 'E') {
			--e_right;
		}

		min_changes = min(min_changes, max(0, e_right + w_left));
		
		if (directions[i] == 'W') {
			++w_left;
		}
	}

	cout << min_changes << "\n";

	return 0;

}

Measured memory_bytes: 720
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
int main() {
  string s;
  cin >>s;
  int n=s.size();
  int zero=0;
  int ichi=0;
  for(int i=0;i<n;i++){
    if(i%2==0&&s[i]!='1')zero++;
    if(i%2==1&&s[i]!='0')zero++;
    if(i%2==0&&s[i]!='0')ichi++;
    if(i%2==1&&s[i]!='1')ichi++;
  }
  int kotae=min(zero,ichi);
  cout<<kotae<<endl;
  return 0;
}

Measured memory_bytes: 3748
#include<iostream>
#include<array>
 
int main()
{
  bool result = true;
  std::size_t len;
  std::array<char,101> str;
  std::cin >> len;
  std::cin >> str.data();
  if(len & 1)
  {
    std::cout << "No";return 0;
  }
  for(auto i = 0;i < len/2;++i)
  {
    if(str[i] != str[i + len/2]){result = false;}
  }
  std::cout << (result?"Yes":"No");
}

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

using namespace std;

int gcd(int a, int b)
{
	while(b) {
		int t = a % b;
		a = b;
		b = t;
	}
	
	return a;
}

int max(int *m, int n)
{

	int max = 0;
	
	for (int i = 0; i < n; i++) {
		if (m[i] > max) {
			max = m[i];
		}
	}	
	
	return max;
}


int main()
{
	int n, a;
	vector<int> A;
	
	int *L, *R, *M;
	
  	cin >> n;
  	for (int i = 0; i < n; i++) {
  		cin >> a;
  		A.push_back(a);
  	}
  	
  	 L = new int[(n+1)];
  	 R = new int[(n+1) + 1];
  	 M = new int[(n+1)]; 
  	 L[0] = R[n+1] = 0;
  	
  	for (int i = 0; i < n; i++) {
  		L[i+1] = gcd(L[i], A[i]);
  	}
  	
  	 for (int i = n; i > 0; i--) {
  		R[i] = (gcd(R[i+1], A[i]));
  	}
  	
  	 for (int i = 0; i < n; i++) {
  		M[i] = (gcd(L[i], R[i+1]));
  	}

	cout << max(M, n);

    return 0;
}

Measured memory_bytes: 1912
/// Thank you tanakh!!!
/// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

use std::collections::BTreeSet;

fn main() {
    input!(s: chars, x: i64, y: i64);
    let mut v = vec![];
    let mut count = 0;
    for &c in s.iter() {
        if c == 'T' {
            v.push(count);
            count = 0;
        } else {
            count += 1;
        }
    }
    if count > 0 {
        v.push(count);
    }
    let x = x - v[0];

    let mut fx = vec![];
    let mut fy = vec![];
    for i in 1..v.len() {
        if i % 2 == 0 {
            fx.push(v[i]);
        } else {
            fy.push(v[i]);
        }
    }

    let x_sum = fx.iter().sum::<i64>();
    let y_sum = fy.iter().sum::<i64>();

    let mut xdp = BTreeSet::new();
    xdp.insert(0);
    for &fx in fx.iter() {
        let mut next = BTreeSet::new();
        for &cur in xdp.iter() {
            next.insert(cur + fx);
            next.insert(cur - fx);
        }
        xdp = next;
    }

    let mut ydp = BTreeSet::new();
    ydp.insert(0);
    for &fy in fy.iter() {
        let mut next = BTreeSet::new();
        for &cur in ydp.iter() {
            next.insert(cur + fy);
            next.insert(cur - fy);
        }
        ydp = next;
    }

    if xdp.contains(&x) && ydp.contains(&y) {
        println!("Yes");
    } else {
        println!("No");
    }
}


Measured memory_bytes: 4352
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>

using namespace std;

int main()
{
    int n,mod=1e9+7,ans=1;
    bool poss=true;
    
    scanf("%d",&n);
    
    int diffs[n]={0};
    
    for(int i=0;i<n;i++)
    {
        int x;
        
        scanf("%d",&x);
        
        diffs[x]++;
    }
    
    if(n&1^1)
    {
        for(int i=1;i<n;i+=2)
        {
            if(diffs[i]==2)
                ans=(ans*2)%mod;
            else
            {
                poss=false;
                break;
            }
        }
    }
    else
    {
        if(diffs[0]!=1)
            poss=false;
        else
        {
            for(int i=2;i<n;i+=2)
            {
                if(diffs[i]==2)
                    ans=(ans*2)%mod;
                else
                {
                    poss=false;
                    break;
                }
            }
        }
    }
    
    poss?printf("%d",ans):printf("0");

    return 0;
}

Measured memory_bytes: 4112
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
const int MAXN =3e5+5;
set<int> v1[MAXN];
int val[MAXN];
int ans;
int mx;
int root;

int dfs(int curr,int par){
    int mx1 = 0;
    int mx2= 0;
    for(int x:v1[curr]){
        if(x!=par){
            int currval = dfs(x,curr);
            if(currval>=mx1){
                mx2 = mx1;
                mx1 = currval;

            }else if(currval>mx2){
                mx2 = currval;
            }
        }
    }

    mx = max(mx,val[curr]+mx1+mx2);
    return val[curr]+mx1;
}
int main(){
    string s;
    int n;
    cin>>n;
    for(int i=1;i<n;i++){
        int x,y;
        cin>>x>>y;
        v1[x].insert(y);
        v1[y].insert(x);
    }
    cin>>s;

    s = " "+s;

    for(int i=1;i<=n;i++){
        val[i] = s[i] == 'W';
        ans+=val[i];
    }
    if(ans == 0){
        cout<<0<<endl;
        return 0;
    }
    if(ans == 1){
        cout<<1<<endl;
        return 0;
    }
    queue<int> q1;
    for(int i=1;i<=n;i++){
        if(v1[i].size() == 1){
            q1.push(i);
        }
    }
    while(q1.size()){
        int x= q1.front();
        q1.pop();
        if(val[x]==0){
            val[x] = 1000;
            int next = *v1[x].begin();
            v1[next].erase(x);
            if(v1[next].size() == 1){
                q1.push(next);
            }
        }
    }

    ans = 0;
    for(int i=1;i<=n;i++){
        if(val[i]!=1000){

            if(val[i] == 0 && v1[i].size()%2 ==0){
                val[i] = 0;
            }else if(val[i] == 1 && v1[i].size()%2 ==1 ){
                val[i] = 0;
            }else{
                val[i] = 1;
            }

            ans+=2+val[i];
            root = i;

        }
    }
    ans-=2;

    dfs(root,-1);
    cout<<ans - (2*mx)<<endl;

}


Measured memory_bytes: 31740
#include <bits/stdc++.h>
#include <list>
#define int long long
using namespace std;
const int INF = 1LL<<60;
const int MOD = (int)1e9 + 7;
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n, m;
    cin >> n >> m;
    priority_queue<double> q;
    for (int i = 0; i < n; i++) {
        double a;
        cin >> a;
        q.push(a);
    }
    for (int i = 0; i < m; i++) {
        double x = q.top() / 2;
        q.pop();
        q.push(x);
    }
    int sum = 0;
    for (int i = 0; i < n; i++) {
        double x = q.top();
        q.pop();
        sum += x;
    }
    cout << sum << "\n";
}

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

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

Node treeMinimum(Node x){


}

Node treeMaximum(Node x){


}

Node treeSearch(Node u, int k){


}

Node treeSuccessor(Node x){


}

void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y



}

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x!=NIL){
    y = x;
    if(z->key < x->key)
      x = x->left;
    else
      x = x->right;
  }

  z->parent = y;

  if(y == NIL)
    root = z;
  else if(z->key < y->key)
    y->left = z;
  else
    y->right = z;

}

void inorder(Node u){
  if(u->left != NIL)
    inorder(u->left);
  printf(" %d",u->key);
  if(u->right != NIL)
    inorder(u->right);  

}
void preorder(Node u){
  printf(" %d",u->key);
  if(u->left != NIL)
    preorder(u->left);
  if(u->right != NIL)
    preorder(u->right);

}


int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
  }

  return 0;
}



Measured memory_bytes: 25208
;; B - Bingo

(defun bingo (a b)
  (labels ((subset-of-b (lst)
             (subsetp lst b))
           (columns (rows)
             (loop for i below 3 collect
               (mapcar #'(lambda (row) (nth i row)) rows)))
           (diagonals (rows)
             (list (mapcar #'nth '(0 1 2) rows)
                   (mapcar #'nth '(2 1 0) rows))))
    (some #'subset-of-b
      (append a (columns a) (diagonals a)))))

(let* ((a (loop repeat 3 collect (loop repeat 3 collect (read))))
       (n (read))
       (b (loop repeat n collect (read))))
  (princ (if (bingo a b) "Yes" "No")))


Measured memory_bytes: 15976
#include <iostream>
#define ll long long
#define f(i, n) for (int i=1; i <= n; i++)
// sort(bb, bb+n);

using namespace std;
int main()
{
    std::ios::sync_with_stdio(false);
    double n,m,aa[1002],t=0,b=0,c=0;
    cin>>n>>m;
    f(i,n){
        cin >> aa[i];
        t += aa[i];
    }
    b=t/(m*4.0);

    f(i,n){
        if(aa[i]>=b){
            c++;
        }
    }

    if(c>=m){
        cout<<"Yes";
    }
    else{
        cout<<"No";
    }
    
    return 0;
}

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

#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pb push_back
#define fi first
#define se second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mii map<int,int>
#define mll map<ll,ll>
#define all(x) (x).begin(),(x).end()
#define S(x) (int)(x).size()
#define L(x) (int)(x).length()

#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<int , null_type , less<int> , rb_tree_tag , tree_order_statistics_node_update> ordered_set;

const int mod = 1e9+7;
const ll infl = 0x3f3f3f3f3f3f3f3fLL;
const int infi = 0x3f3f3f3f;

void solve()
{
	char a;
	cin>>a;
	if(a>='a' && a<='z') cout<<'a';
	else cout<<'A';
}

int main()
{
	IOS
	int t=1;
	//cin>>t;
	while(t--)
	{
		solve();
	}
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)
#define N 105
#define INF 100000000
typedef long long ll;
#define ALL(v) (v).begin(),(v).end()
#define SZ(x) int(x.size())
#define IN(a) cin>>(a)
#define OUT(a) cout<<(a)<<endl
typedef pair<int,int> P;
const int MAX = 100005;
const int MOD = 1000000007;
int main(){
    int n,m;
    cin>>n>>m;
    vector<P>a(n);
    REP(i,n){
        int p,q;
        cin>>p>>q;
        a[i]={p,q};
    }
    sort(ALL(a));
    ll ans=0;
    REP(i,n){
        if(m>a[i].second){
            m-=a[i].second;
            ans+=(ll)a[i].first*a[i].second;
        }else{
            ans+=(ll)a[i].first*m;
            break;
        }
    }
    OUT(ans);
    return 0;
}

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

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

	int N, M;
	cin >> N >> M;

	if (N*M % 2) co("Odd");
	else co("Even");

	Would you please return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<math.h>
#include<stdio.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  while(n!=0){
    int i;
    double s[1000]={},sum=0,a=0;
    for(i=0;i<n;i++){
      cin >> s[i];
      sum+=s[i];
    }
    for(i=0;i<n;i++){
      a+=((sum/n)-s[i])*((sum/n)-s[i])/n;
    }
    printf("%.5f\n",sqrt(a));
    cin >> n;
  }
  
  return 0;
}

Measured memory_bytes: 1252
#include<iostream>
#include<vector>
#include<map>
#include<string>
using namespace std;

void a(){
    string arc = "ARC";
    string abc = "ABC";
    string s;
    cin >> s;
    if(s.compare(arc)){
        cout<<arc;
    }else{
        cout<<abc;
    }
    return;
}

void b(){
    
}

void c(){
   
}

void d(){
    
}
int main(void){
    a();
    //b();
    //c();

}

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

int n,k;
const int MAXN=100+10;
const int MAXK=100000+100;
int a[MAXN];
int dp[MAXK];

int main()
{
	cin>>n;
	cin>>k;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
	}
	for(int i=1;i<=k;i++)
	{
		for(int j=1;j<=n;j++)
		{
			if(a[j]<=i)
			{
				if(!dp[i-a[j]]) dp[i]=1;
			}
		}
	}
	if(dp[k]) cout<<"First"<<endl;
	else cout<<"Second"<<endl;
	return 0;
}

Measured memory_bytes: 640
n = int(input())

a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))

ans = 0
before = -1
for i in range(n):
	ans += b[a[i]-1]
	if a[i] == before+1:
		ans += c[before-1]
	before = a[i]

print(ans)


Measured memory_bytes: 38256
#include <iostream>
#include <vector>
#include <cstring>

#define rep(i,n) for(int i=0;i<(n);i++)
#define YOKO 1
#define TATE 2

using namespace std;

struct B{
	int d;	// ubNÌü«@(1: ¡ü« 2: cü« )
	int p;	// ubNÌ·³  (1  d  5 )
	int q;	// ubNÌÊu@(1  p  5 ¡ü«ÌêÍ¶[ÌR}ª¿éÊu )
};

const int Hight = 5001;
const int Width = 5;

bool f[Hight][Width];

// cÁ½ubNðJEg
int count_block (void )
{
	int res = 0;

	for (int i = 0; i < Hight; i++ ){
		for (int j = 0; j < Width; j++ ){
			if (f[i][j] )
				res++;
		} // end for
	} // end for

	return res;
}

// ubNªlÜÁÄ¢éCðÁ·
void del_block (int n )
{
	for (int i = n + 1; i < Hight; i++ ){
		for (int j = 0; j < Width; j++ ){
			f[i-1][j] = f[i][j];
		} // end for
	} // end for
}

void is_all_row (void ) // ·×ÄubNªÜÁÄ¢éCðÁ·
{
	bool found = false;
	do{
		found = false;
		for (int i = 0; i < Hight; i++ ){
			int sum = 0;
			for (int j = 0; j < Width; j++ ){
				if (f[i][j] ){
					++sum;
				} // end if
			} // end for
			if (sum == Width ){
				del_block (i );
				found = true;
				break;			
			} // end if
		} // end for
	}while (found );
}

// row,colÌêÌãÌÊuªJ¢Ä¢é©Ç¤©Ì`FbN
bool check_tate (int row, int col )
{
	for (int i = row; i < Hight; i++ ){
		if (f[i][col] )
			return false;
	} // end for

	return true;
}

int main()
{
	int n;

	while (cin >> n && n ){
		memset (f, false, sizeof(f ) );
		vector <B> b (n );
		for (int i = 0; i < n; i++ ){
			cin >> b[i].d >> b[i].p >> b[i].q;
			b[i].q--;
		}// end for
	
		for (int i = 0; i < n; i++ ){
			int curr = 0;
			bool found = false; // »ÌÊuÉæqª é©Ç¤©
			do{
				found = false;	
				for (int j = b[i].q; j < b[i].q + b[i].p; j++ ){
					if (!check_tate (curr, j ) ){
						found = true;
						break;
					} // end if
					if (!f[curr][j] ){
						if (b[i].d == TATE ){	// cü«ÌêAê¾¯ÅOK
							break;
						}else{ 
							continue;
						} // end if
					}else{
						found = true;
						break;
					} // end if
				} // end for
				if (!found ){
					if (b[i].d == YOKO ){	// ¡ü«Ìê
						for (int j = b[i].q; j < b[i].q + b[i].p; j++ ){
							f[curr][j] = true;
						} // end for
					}else{					// cü«Ìê
						for (int j = 0; j < b[i].p; j++ ){
							f[curr+j][b[i].q] = true;
						} // end for 						
					} // end if
				}else{
					curr++;	// ²¸·ésðâ·
				} // end if
			}while (found );
			is_all_row ();	// ·×ÄÌCªlÜÁÄ¢é©`FbN
		} // end for

		int res = count_block();
		cout << res << endl;
	} // end loop
		
	return 0;
}

Measured memory_bytes: 940
//#define LOCAL
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<string>
#include<math.h>
#include<map>
#include<random>
#include<stack>
using namespace std;
using lld = long long int;
using llu = unsigned long long int;
using pii = pair<int, int>;
using pli = pair<lld, int>;
using pil = pair<int, lld>;
using pll = pair<lld, lld>;
using piii = pair<pii, pii>;
using pdii = pair<int, pii>;
int n;
#define I 262144
int a[200009];
int x[200009];
int xl;

vector<int> v[200009];
int res[200009];

stack<int> ss[200009];
int ma[2 * I];
int getma(int dep, int ql, int qr, int ll, int rr) {
	if (ql <= ll && rr <= qr)return ma[dep];
	if (qr < ll || rr < ql)return 0;
	return max(getma(dep * 2, ql, qr, ll, (ll + rr) / 2), getma(dep * 2 + 1, ql, qr, (ll + rr) / 2 + 1, rr));
}
void downdatema(int i) {
	ss[i].pop();
	int k = 0;
	if(ss[i].size() > 0){
		k = ss[i].top();
	}
	if (ma[i + I] != k) {
		ma[i + I] = k;
		i = (i + I) / 2;
		while (i > 0) {
			ma[i] = max(ma[i * 2], ma[i * 2 + 1]);
			i >>= 1;
		}
	}
}
void updatema(int i, int k) {
	if (ss[i].size() == 0) {
		ss[i].push(k);
		ma[i + I] = k;
		i = (i + I) / 2;
		while (i > 0) {
			ma[i] = max(ma[i * 2], ma[i * 2 + 1]);
			i >>= 1;
		}
	}
	else {
		if (k > ss[i].top()) {
			ss[i].push(k);
			ma[i + I] = k;
			i = (i + I) / 2;
			while (i > 0) {
				ma[i] = max(ma[i * 2], ma[i * 2 + 1]);
				i >>= 1;
			}
		}
		else {
			k = ss[i].top();
			ss[i].push(k);
		}
	}
}

void dfs(int si, int pi) {
	int i, j, k;
	int cur = getma(1, 0, a[si] - 1, 0, I - 1);
	updatema(a[si], cur + 1);
	res[si] = max(cur + 1, getma(1, 0, I - 1, 0, I - 1));
	for (i = 0; i < v[si].size(); i++) {
		j = v[si][i];
		if (j == pi)continue; 
		dfs(j, si);
	}
	downdatema(a[si]);
}
int main() {
	int i, j, k, l;
	int t = 1, tv = 0;
	while (t--) {
		scanf("%d",&n);
		for (i = 0; i < n; i++) {
			scanf("%d", &a[i]);
			x[xl++] = a[i];
		}
		sort(x, x + xl);
		xl = unique(x, x + xl) - x;
		for (i = 0; i < n; i++) {
			a[i] = lower_bound(x, x + xl, a[i]) - x;
		}
		for (i = 1; i < n; i++) {
			scanf("%d %d", &j, &k);
			j--; k--;
			v[j].push_back(k);
			v[k].push_back(j);
		}
		dfs(0, -1);
		for (i = 0; i < n; i++) {
			printf("%d\n", res[i]);
		}
	}
}

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

int main(void) {
	int n, i, j, k, len;
	cin >> n;
	int p[n + 1], m[n + 1][n + 1];
	for (i = 0; i <= n; i++)
	{
		if (i == 0) {
			cin >> p[i];
		} else if (i == 1) {
			cin >> p[i];
		} else {
			cin >> p[i] >> p[i];
		}
	}

	for (i = 1; i <= n; i++) 
		m[i][i] = 0;

	for (len = 2; len <= n; len++) {
		for (i = 1; i <= n - len + 1; i++) {
			j = i + len - 1;
			m[i][j] = INT_MAX;
			for (k = i; k < j; k++) {
				m[i][j] = min(m[i][j], m[i][k] + m[k + 1][j] + p[i - 1] * p[k] * p[j]);
			}
		}
	}
	cout << m[1][n] << endl;
}


Measured memory_bytes: 3112
#include <bits/stdc++.h>
#define rep(i,k,n) for(int i=k;i<n;i++)
#define rep2(i,k,n) for(int i=k;i<=n;i++)
typedef long long ll;
using namespace std;
int main()
{
   string s;
   cin >> s;
   int W=0;
   ll ans=0;
   rep(i,0,s.length()){
       if(s[i]=='W'){
           ans+=i-W;
           W++;
       }
   }

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

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define INF 1000000000
#define mod 1000000007
using ll=long long;
const ll LINF=1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return true;}return false;}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    
    while(true){
        ll n;cin>>n;
        if(n==0) return 0;
        vector<ll> a(n);
        ll sum=0;
        rep(i,n){
            cin>>a[i];
            sum+=a[i];
        }
        ll ave=sum/n;
        ll cnt=0;
        rep(i,n){
            if(a[i]<=ave) cnt++;
        }
        cout<<cnt<<endl;
    }
    return 0;
}



Measured memory_bytes: 3268
// ##MohK
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,x;
    cin>>n>>x;
    int a;
    int sum=0;
    int res=0;
    for(int i=0;i<n;i++)
    {
        cin>>a;
        sum=sum+a;
        if(sum<=x)
        {res++;}
    }
    cout<<res+1;
 
        return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#pragma region
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << (#x) << "] = [", _print(x)
#else
#define debug(x...)
#endif
#pragma endregion
typedef long long ll;
#define forn(i, n) for (int i = 1; i <= int(n); ++i)
#define sz(v) int((v).size())
#define int ll
#pragma region
#define x first
#define y second
#define mp make_pair
#define mt make_tuple
#define pb push_back
#pragma endregion


void solve()
{
    string s; cin>>s;
    cout << s;
    if (s.back() == 's') cout << "es";
    else cout << "s";
}

signed main()
{
    int T = 1;
    ios_base::sync_with_stdio(0); cin.tie(0);
    cout << fixed << setprecision(22);
    // cin >> T;
    for(int i=1;i<=T;++i)
    {
        //cout << "Case #" << i << '\n';
        solve();
    }
    return 0;
}


Measured memory_bytes: 3664
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9+7;

#define debug(...)                                                    \
  std::cerr << "LINE: " << __LINE__ << "  [" << #__VA_ARGS__ << "]:", \
      debug_out(__VA_ARGS__)

void debug_out() { std::cerr << std::endl; }

template <typename Head, typename... Tail>
void debug_out(Head h, Tail... t) {
  std::cerr << " " << h;
  if (sizeof...(t) > 0) std::cout << " :";
  debug_out(t...);
}

int main() {
    string s,t;
    cin >> s >> t;
    ll n=t.size();
    ll x=s.size();
    if(x<n){
        cout << "UNRESTORABLE" << endl;
        return 0;
    }
    vector<ll>check(51,MOD);
    for(ll i=x-n;i>=0;i--){
        bool judge=true;
        for(ll j=0;j<n;j++){
            if(s[i+j]!='?'&&s[i+j]!=t[j]){
                judge=false;
            }
        }
        if(judge){
            check[i]=i;
        }
    }
    sort(check.begin(),check.end());
    ll cnt=0;
    for(ll i=0;i<51;i++){
        if(check[i]==MOD) break;
        cnt++;
    }
    if(cnt==0){
        cout << "UNRESTORABLE" << endl;
        return 0;
    }
    vector<string>S(cnt,"");
    for(ll k=0;k<cnt;k++){
        string sumple="";
        for(ll i=0;i<x;i++){
            if(check[k]==i){
                for(ll j=0;j<n;j++){
                debug(t[j]);
                    sumple.push_back(t[j]);
                }
                i+=n;
            }
            
            if(i>=x)break;

            if(s[i]=='?'){
                sumple.push_back('a');
            }
            else {
            debug(s);
            	debug(s[i]);
                sumple.push_back(s[i]);
            }
          std::cerr<<sumple<<"\n";
        }
        S[k]=sumple;
    }
    sort(S.begin(),S.end());
    cout << S[0] << endl;
}


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

int main(void){
  int n;
  while(1){
    cin>>n;
    vector<int> score;
    if(n==0){break;}
    for(int i=0;i<n;i++){
      int tmp;
      cin>>tmp;
      score.push_back(tmp);
    }
    sort(score.begin(),score.end());
    int mean=0;
    for(int i=1;i<n-1;i++){
      mean+=score[i];
    }
    mean=mean/(n-2);
    cout<<mean<<endl;
  }
  return 0;
}



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

using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<int> Vi;
#define FOR(i,s,x) for(int i=s;i<(int)(x);i++)
#define REP(i,x) FOR(i,0,x)
#define ALL(c) c.begin(), c.end()
#define MP make_pair
#define DUMP( x ) cerr << #x << " = " << ( x ) << endl
#define fst first
#define snd second

int N, Q;
int S[10010];

int main() {
  int ans = 0;

  scanf("%d", &N);
  REP(i, N) scanf("%d", S+i);
  sort(S, S+N);

  scanf("%d", &Q);
  REP(i, Q) {
    int t;
    scanf("%d", &t);
    auto it = lower_bound(S, S+N, t);
    ans += (it != S+N && t == *it);
  }

  printf("%d\n", ans);
  return 0;
}

Measured memory_bytes: 1224
#include<bits/stdc++.h>
using namespace std;
#define int long long
vector<int> z,s;
vector<string> vs;
int rec(int p,int u,int sum){
  if(p==z.size()) return !sum;
  int res=0;
  for(int i=z[p];i<10;i++) if(!((u>>i)&1)) res+=rec(p+1,u|(1<<i),sum+s[p]*i);
  return res;
}
signed main(){
  int n,i,j,k;
  while(cin>>n,n){
    vs.clear();vs.resize(n);
    for(i=0;i<n;i++) cin>>vs[i];
    vector<char> vc;
    map<char,int> m;
    for(i=0;i<vs.size();i++)
      for(j=0;j<vs[i].size();j++)
	if(m.find(vs[i][j])==m.end())
	  m[vs[i][j]]=vc.size(),vc.push_back(vs[i][j]);
    z.clear();z.resize(vc.size(),0);
    s.clear();s.resize(vc.size(),0);
    reverse(vs.begin(),vs.end());
    for(i=0;i<vs.size();i++){
      if(vs[i].size()-1) z[m[vs[i][0]]]=1;
      reverse(vs[i].begin(),vs[i].end());
      for(j=0,k=1;j<vs[i].size();j++) s[m[vs[i][j]]]+=(i?1:-1)*k,k*=10;
    }
    cout << rec(0,0,0) << endl;
  }
  return 0;
}

Measured memory_bytes: 3024
#include "bits/stdc++.h"
using namespace std;

//#define int long long
#define DBG 1
#define dump(o) if(DBG){cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) if(DBG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define each(it,c) for(auto it=(c).begin();it!=(c).end();it++)
#define all(c) c.begin(),c.end()
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9 + 7);

signed main() {
	for (int N, Q; cin >> N >> Q&&N;) {
		vector<int> cnt(110, 0);
		rep(i, 0, N) {
			int M; cin >> M;
			rep(i, 0, M) {
				int Date; cin >> Date;
				cnt[Date]++;
			}
		}
		int ma = *max_element(all(cnt));
		if (ma < Q)cout << 0 << endl;
		else cout << max_element(all(cnt)) - cnt.begin() << endl;
	}
	return 0;
}

Measured memory_bytes: 3064
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<utility>
#include<algorithm> // sort
#include<map> // pair
#include<cmath>
using namespace std;
using ll = long long;
const ll mod = 1e9+7;
int main(){
  ll a,b,sum;
  cin >> a >> b;
  if(a > b){
    sum = 2 * a -1;
  }else if(a == b){
    sum = 2 * a;
  }else{
    sum = 2 * b - 1;
  }
  cout << sum;
}


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

int main(){
  long long A, B, C;
  cin >> A >> B >> C;
  long long ans=0;
  if(A*B*C%2==0) ans=0;
  else{
    ans=min({A*B, B*C, C*A});
  }
  cout << ans << endl;
}

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


int main(){
  ll N;
  cin >> N;
  ll mi=pow(10,15);
  ll x;
  for(int i=0;i<5;i++){
    cin >> x;
    mi = min(mi,x);
  }
  if(N < mi){
    cout << 5 << endl;
    return 0;
  }
  cout << (N + mi - 1) /mi + 4 << endl;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys


# UnionFind

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n
        
    def find(self, x): # O(α(n))
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]
    
    def union(self, x, y): # O(α(n))
        x = self.find(x)
        y = self.find(y)
        
        if x == y:
            return
        
        if self.parents[x] > self.parents[y]:
            x, y = y, x
        
        self.parents[x] += self.parents[y]
        self.parents[y] = x
    
    def size(self, x): #O(1)
        return -self.parents[self.find(x)]
        
    def same(self, x, y):
        return self.find(x) == self.find(y)
    
    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]
    
    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())
    
    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}
    
    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

def solve(N: int, M: int, K: int, A: "List[int]", B: "List[int]", C: "List[int]", D: "List[int]"):

    adjacency_list = [[] for _ in range(N+1)]
    uf = UnionFind(N+1)
    for i in range(M):
        adjacency_list[A[i]].append(B[i])
        adjacency_list[B[i]].append(A[i])
        uf.union(A[i],B[i])
    
    answer = []
    block_count = [0]*(N+1) # i と同じグループにいてかつブロックしてる人数
    for k in range(K):
        if uf.same(C[k],D[k]):
            block_count[C[k]] += 1
            block_count[D[k]] += 1
        

    for i in range(1,N+1):
        size = uf.size(i) # iがいるグループのサイズ
        answer.append(size-len(adjacency_list[i])-block_count[i]-1)
    print(*answer)

    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    A = [int()] * (M)  # type: "List[int]"
    B = [int()] * (M)  # type: "List[int]"
    for i in range(M):
        A[i] = int(next(tokens))
        B[i] = int(next(tokens))
    C = [int()] * (K)  # type: "List[int]"
    D = [int()] * (K)  # type: "List[int]"
    for i in range(K):
        C[i] = int(next(tokens))
        D[i] = int(next(tokens))
    solve(N, M, K, A, B, C, D)

if __name__ == '__main__':
    main()


Measured memory_bytes: 39392
import java.io.InputStream;
import java.io.PrintStream;
import java.util.*;

public class Main {

  public static void main(String[] args) {
    solve(System.in, System.out);
  }

  static void solve(InputStream is, PrintStream os) {
    Scanner sc = new Scanner(is);

    /* read */
    int r = sc.nextInt();
    int D = sc.nextInt();
    int x = sc.nextInt();

    for (int i = 1; i <= 10; i++) {
      x = r * x - D;
      os.println(x);
    }
  }
}

Measured memory_bytes: 22868
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, K;
  cin >> N >> K;
  
  int S = 1;
  
  for (int i = 0; i < N; i++) {
    if (S < K) {
      S *= 2;
    }
    else {
      S += K;
    }     
  }   
  
  cout << S << endl;   

}

Measured memory_bytes: 3632