akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
using Pld = pair<ld, ld>;
using Vec = vector<ll>;
using VecP = vector<P>;
using VecB = vector<bool>;
using VecC = vector<char>;
using VecD = vector<ld>;
using VecS = vector<string>;
template <class T>
using Vec2 = vector<vector<T>>;
#define REP(i, m, n) for(ll i = (m); i < (n); ++i)
#define REPN(i, m, n) for(ll i = (m); i <= (n); ++i)
#define REPR(i, m, n) for(ll i = (m)-1; i >= (n); --i)
#define REPNR(i, m, n) for(ll i = (m); i >= (n); --i)
#define rep(i, n) REP(i, 0, n)
#define repn(i, n) REPN(i, 1, n)
#define repr(i, n) REPR(i, n, 0)
#define repnr(i, n) REPNR(i, n, 1)
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define fs first
#define sc second
template <class T1, class T2>
bool chmax(T1 &a, const T2 b){if(a < b){a = b; return true;} return false;}
template <class T1, class T2>
bool chmin(T1 &a, const T2 b){if(a > b){a = b; return true;} return false;}
ll pow2(const int n){return (1LL << n);}
void co() { cout << endl; }
template <class Head, class... Tail>
void co(Head&& head, Tail&&... tail) {
    cout << head << ' ';
    co(forward<Tail>(tail)...);
}
void ce() { cerr << endl; }
template <class Head, class... Tail>
void ce(Head&& head, Tail&&... tail) {
    cerr << head << ' ';
    ce(forward<Tail>(tail)...);
}
void sonic(){ios::sync_with_stdio(false); cin.tie(0);}
void setp(const int n){cout << fixed << setprecision(n);}
constexpr int INF = 1e9+1;
constexpr ll LINF = 1e18L+1;
constexpr ll MOD = 1e9L+7;
constexpr ll MOD_N = 998244353;
constexpr ld EPS = 1e-11;
const double PI = acos(-1);

template <typename T>
struct BIT{
    ll N;
    vector<T> data;

    BIT(ll n){
        init(n);
    }

    void init(ll n){
        N = 1;
        while(N < n) N <<= 1;
        data.assign(N, 0);
    }

    void build(vector<T> v){
        init(N);
        for(int i = 0; i < v.size(); ++i){
            add(i, v[i]);
        }
    }

    void add(ll k, T x){
        ++k;
        while(k <= N){
            data[k] += x;
            k += k & -k;
        }
    }

    // [0, k)
    T sum(ll k){
        T res = 0;
        while(k){
            res += data[k];
            k -= k & -k;
        }
        return res;
    }

    // [a, b)
    T sum(ll a, ll b){return sum(b) - sum(a);}

    T at(ll k){return sum(k) - sum(k - 1);}

    
    T lower_bound(T k){
        ll l = 0, r = N;
        while(r - l > 1){
            ll m = (l + r) / 2;
            if(sum(m) >= k) r = m;
            else l = m;
        }
        return r;
    }
};

int main(void){
    ll n, q;
    cin >> n >> q;
    Vec a(n);
    rep(i, n) cin >> a[i];
    BIT<ll> bit(n);
    bit.build(a);
    while(q--){
        ll t, a, b;
        cin >> t >> a >> b;
        if (t == 0) bit.add(a, b);
        else
            co(bit.sum(a, b));
    }

    return 0;
}


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

using namespace std;

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


int main(){

	int a,b;

	while(cin >> a >> b){

		int x = 1;
		int sum = a + b;

		while(sum / 10 > 0){
		x++;
		sum = sum / 10;
		}
		cout << x << endl;
	}

	return 0;
}

Measured memory_bytes: 1156
k, q = map(int, input().split())
d = list(map(int, input().split()))
nxm = [list(map(int, input().split())) for i in range(q)]
for n, x, m in nxm:
    prev = x
    ans = 0
    cur = 0
    for i in range(k):
        prev += (d[i] % m) * ((n + k - i  - 2) // k)
        if d[i] % m == 0:
            cur += ((n + k - i  - 2) // k)
    print(n - prev // m + x // m - cur - 1)

Measured memory_bytes: 75400
import java.util.Scanner;
public class Main {
		public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		
		int k = scanner.nextInt();
		long sum = (long) 0;

		for(int i = k;i<=n+1;i++) {
			long cur = (long)(n-i+1)*i+ 1;
		
			sum = sum + cur ;
		}
		sum  = sum % 1000000007;
		System.out.println(sum);
	}


}

Measured memory_bytes: 35592
faces = input().split()

q = int(input())

for i in range(q):
    
    s = input().split()
    
    ss = s[0] + s[1]
    
    if ss in (faces[1] + faces[2] + faces[4] + faces[3] + faces[1]):
        # 1
        print(faces[0])
        
    elif ss in (faces[0] + faces[3] + faces[5] + faces[2] + faces[0]):
        # 2
        print(faces[1])
        
    elif ss in (faces[0] + faces[1] + faces[5] + faces[4] + faces[0]):
        # 3
        print(faces[2])
        
    elif ss in (faces[0] + faces[4] + faces[5] + faces[1] + faces[0]):
        # 4
        print(faces[3])
        
    elif ss in (faces[0] + faces[2] + faces[5] + faces[3] + faces[0]):
        # 5
        print(faces[4])
        
    elif ss in (faces[1] + faces[3] + faces[4] + faces[2] + faces[1]):
        # 6
        print(faces[5])
        
    else:
        print('error', ss)




Measured memory_bytes: 5600
#include<stdio.h>
int main(void)
{
        int n,h[100],count,i,j;
        scanf("%d",&n);

        for(i=0;i<n;i++){
                scanf("%d",&h[i]);
        }
        count = 1;
        int max =h[0];
        for(i=1;i<n;i++){
                if(h[i]>=max){
                        max=h[i];
                        count +=1;
                }
        }
        printf("%d\n",count);
        return 0;
}


Measured memory_bytes: 128
import java.util.*;
class Main{
    Scanner sc=new Scanner(System.in);
    void main(){
	double r=sc.nextDouble();


	double seki=r*r*Math.PI;
	double syu=r*2*Math.PI;
	System.out.printf("%.6f %.6f", seki,syu );
	System.out.println();
	
    }
    public static void main(String[]ag){
	new Main().main();
    }
}

Measured memory_bytes: 28352
import java.util.Scanner;
import java.util.List;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
	String a = sc.next();
   	String b = sc.next();
   	String c = sc.next();
    String af=a.substring(a.length()-1);
    String bb=b.substring(0,1);
    String bf=b.substring(b.length()-1);
    String cb=c.substring(0,1);
    if (af.equals(bb) && bf.equals(cb)){
      System.out.println("YES");
    } else {
      System.out.println("NO");
    }
  }
}

Measured memory_bytes: 21972
#include <iostream>
#include <algorithm>
#include <string>
#include <iomanip>
#include <vector>
using namespace std;

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

  vector<double> a(2*sum+1,1e9);
  int tmp=0;
  for(int i=0;i<n;i++){
    for(int j=tmp;j<=tmp+2*t[i];j++){
      a[j]=min(a[j],v[i]);
    }
    tmp+=2*t[i];
  }

  a[0]=0;
  for(int i=1;i<=2*sum;i++){
    a[i]=min(a[i],a[i-1]+0.5);
  }
  a[2*sum]=0;
  for(int i=2*sum-1;i>=0;i--){
    a[i]=min(a[i],a[i+1]+0.5);
  }
  double ans=0;
  for(int i=1;i<=2*sum;i++){
    ans+=(a[i]+a[i-1])/4;
  }
  cout<<setprecision(10)<<ans<<endl;
  return 0;
}


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

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
using vec_b = vector<bool>;
using vec_str = vector<string>;

#define INF (1LL << 60)
#define MOD 1000000007

#define REP(i,m,n) for(ll (i)=(m),i##_len=(n);(i)<(i##_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define _PR(x) cout << (x) << endl
#define _PS(x) cout << (x) << " "
#define SZ(x) ((ll)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define pb push_back


int main()
{
    ll A, P;
    cin >> A >> P;

    _PR((A*3+P)/2);

    return 0;
}

/*



*/

Measured memory_bytes: 256
#include <iostream>
using namespace std;
 
int main() {
	// your code goes here
	int  r;
    int  g;
    int res;
    cin>>r;
    cin>>g;
    if(g==0)
    {
    	cout<<-r;
    }
    
    else
    {
    	res=g-r;
    	r=r+res*2;
    	cout<<r;
    }
	return 0;
}

Measured memory_bytes: 256
"""
# 標準入力取得
## 文字列
 = sys.stdin.readline().rstrip()
 = list(sys.stdin.readline().rstrip())

## 数値
 = int(sys.stdin.readline())
 = map(int, sys.stdin.readline().split())
 = list(map(int, sys.stdin.readline().split()))
 = [list(map(int,list(sys.stdin.readline().split()))) for i in range(h)]  # 二次元配列入力　二次元マップみたいな入力のとき

# 0埋め, 小数点出力桁指定時のときの出力
a = 100
b = 0.987654321
print("{0:06d}-{1:6f}".format(a,b))
000100-0.987654

# 文字列をリストに格納
char_list = list("abcd") # ["a","b","c","d"]
"""

import math
import sys
import itertools
import queue
from fractions import gcd

def lcm(a, b):
    return a * b // gcd(a, b)

mod = 1000000007

if __name__ == "__main__":
    a= int(sys.stdin.readline())
    b= int(sys.stdin.readline())
    c= int(sys.stdin.readline())
    d= int(sys.stdin.readline())
    e= int(sys.stdin.readline())
    k= int(sys.stdin.readline())

    if e-a <= k:
        print("Yay!")
    else:
        print(":(")




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


int gcd(int m,int n){
  if(m==n) return m;

  if(m>n) return gcd(m-n,n);
  else
    return gcd(m,n-m);
}



int main(){
  int a,b;
  cin>>a>>b;

  cout <<gcd(a,b)<<endl;
}

Measured memory_bytes: 3088
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int n, m, x, y;
int Rank[100001];
int parent[100001];

int find(int x);
bool isSame(int x, int y);
void unite(int x, int y);


int main() {
    cin >> n >> m;

    vector<int> p(n+1, 0);
    for (int i = 1; i <= n; i++) {
        scanf("%d", &p[i]);
    }
    
    for (int i = 1; i <= n; i++ ) {
        Rank[i] = 0;
        parent[i] = i;
    }

    for (int i = 0; i < m; i++) {
        scanf("%d %d", &x, &y);
        
        if (!isSame(x, y)) 
            unite(x, y);
    }

    int ans = 0;
    for (int i = 1; i <= n; i++) {
        if (isSame(i, p[i]))
                ans++;
    }

    cout << ans << '\n';


}


int find(int x) {
    if (x == parent[x]) return x;
    else {
        return parent[x] = find(parent[x]);
    }
}

bool isSame(int x, int y) {
    return find(x) == find(y);
}

void unite(int x, int y) {
    x = find(x);
    y = find(y);

    if (x == y) return;

    if (Rank[x] < Rank[y]) {
        parent[x] = y;
    } 
    else {
        parent[y] = x;
        if (Rank[x] == Rank[y]) 
            Rank[x]++;
    }
}


Measured memory_bytes: 1408
a = input()

for i in range(1 << 3):
  ans = int(a[0])
  f = a[0]
  
  for j in range(3):
    if i & (1 << j):
      ans += int(a[j+1])
      f += '+'
    else:
      ans -= int(a[j+1])
      f += '-'
    f += a[j+1]
    
  if ans == 7:
    print(f + '=7')
    exit()

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

string s;

int main(){
  ios_base::sync_with_stdio(false);
  
  int ans = (1 << 30);
  
  cin >> s;
  
  for(int i=0;i<s.size()-2;i++){
    string a = s.substr(i, 3);
    int sn = stoi(a);
    if(abs(sn - 753) < ans){
      ans = abs(sn - 753);
    }
  }

  cout << ans << endl;

  return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#define int long long
using namespace std;

int x, y;

signed main() {
	cin >> x >> y;
	
	if (abs(x) > abs(y)) {
		cout << abs(x) - abs(y) + (x > 0) + (y > 0) << endl;
	}
	else if (abs(x) == abs(y)) {
		cout << 1 << endl;
	}
	else {
		cout << (x < 0) + abs(y) - abs(x) + (y < 0) << endl;
	}
	return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		String[] data = in.readLine().split(" ");
		int[] num = new int[6];
		for (int i = 0; i < 6; i++) {
			num[i] = Integer.parseInt(data[i]);
		}
		Dices2 dice = new Dices2(num[0], num[1], num[2], num[3], num[4], num[5]);
		int quesTime = Integer.parseInt(in.readLine());
		for (int j = 0; j < quesTime; j++) {
			String[] ques = in.readLine().split(" ");
			int top = Integer.parseInt(ques[0]);
			int front = Integer.parseInt(ques[1]);
			if ((top == dice.fo && front == dice.tw)
					|| (top == dice.tw && front == dice.th)
					|| (top == dice.th && front == dice.fi)
					|| (top == dice.fi && front == dice.fo)) {
				System.out.println(dice.on);
			} else if ((top == dice.on && front == dice.fo)
					|| (top == dice.fo && front == dice.si)
					|| (top == dice.si && front == dice.th)
					|| (top == dice.th && front == dice.on)) {
				System.out.println(dice.tw);
			} else if ((top == dice.on && front == dice.tw)
					|| (top == dice.tw && front == dice.si)
					|| (top == dice.si && front == dice.fi)
					|| (top == dice.fi && front == dice.on)) {
				System.out.println(dice.th);
			} else if ((top == dice.si && front == dice.tw)
					|| (top == dice.tw && front == dice.on)
					|| (top == dice.on && front == dice.fi)
					|| (top == dice.fi && front == dice.si)) {
				System.out.println(dice.fo);
			} else if ((top == dice.fo && front == dice.on)
					|| (top == dice.on && front == dice.th)
					|| (top == dice.th && front == dice.si)
					|| (top == dice.si && front == dice.fo)) {
				System.out.println(dice.fi);
			} else if ((top == dice.tw && front == dice.fo)
					|| (top == dice.fo && front == dice.fi)
					|| (top == dice.fi && front == dice.th)
					|| (top == dice.th && front == dice.tw)) {
				System.out.println(dice.si);
			}
		}
	}
}

class Dices2 {
	public int on, tw, th, fo, fi, si;

	public Dices2(int on, int tw, int th, int fo, int fi, int si) {
		this.on = on;
		this.tw = tw;
		this.th = th;
		this.fo = fo;
		this.fi = fi;
		this.si = si;
	}
}

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

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pll;
typedef vector<bool> vb;
const ll oo = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-9;
#define sz(c) ll((c).size())
#define all(c) begin(c), end(c)
#define FOR(i,a,b) for (ll i = (a); i < (b); i++)
#define FORD(i,a,b) for (ll i = (b)-1; i >= (a); i--)
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define TR(X) ({ if(1) cerr << "TR: " << (#X) << " = " << (X) << endl; })

template<typename T>
struct segtree {
	ll n;
	vector<T> value;

	segtree<T>(vector<T> leaves): n(sz(leaves)) {
		value.resize(2*n);
		copy(all(leaves),begin(value)+n);
		FORD(i,1,n) value[i] = value[2*i] + value[2*i+1];
	}
	
	void update(ll i, T v) {
		i += n;
		value[i] = v;
		for (i /= 2; i; i /= 2) value[i] = value[2*i] + value[2*i+1];
	}
	
	T query(ll i, ll j) {
		i += n, j += n;
		T resl, resr;
		for (; i < j; i /= 2, j /= 2) {
			if (i & 1) resl = resl + value[i++];
			if (j & 1) resr = value[--j] + resr;
		}
		return resl + resr;
	}
};

struct node {
	ll x = 0;
	node operator+(node n) { return {max(x,n.x)}; }
};

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	ll n, k;
	cin >> n >> k;
	
	ll m = 3e5 + 10;
	vector<node> leaves(m);
	segtree<node> S(leaves);

	FOR(i,0,n) {
		ll x; cin >> x;
		ll v = S.query(max(0LL,x-k), min(m,x+k+1)).x + 1;
		S.update(x, {v});
	}

	cout << S.query(0,m).x << endl;
}



Measured memory_bytes: 12704
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
const ll MAX = 1001001;
const ll MOD = 1000000007;
const ll INF = 1001001001;
int main()
{
    string s;
    cin >> s;
    vector<ll> a;
    rep(i, s.size())
    {
        a.push_back(s[s.size() - 1 - i] - '0');
    }
    a.push_back(0);
    ll n = a.size();
    vector<vector<ll>> dp(n + 1, vector<ll>(2));
    rep(i, n + 1)
    {
        rep(j, 2)
        {
            dp[i][j] = INF;
        }
    }
    dp[0][0] = 0;
    rep(i, n)
    {
        rep(j, 2)
        {
            ll now = a[i] + j;
            rep(k, 10)
            {
                ll co = k - now;
                if (co < 0)
                {
                    co += 10;
                    dp[i + 1][1] = min(dp[i + 1][1], dp[i][j] + k + co);
                }
                else
                {
                    dp[i + 1][0] = min(dp[i + 1][0], dp[i][j] + k + co);
                }
            }
        }
    }
    cout << dp[n][0] << endl;
}

Measured memory_bytes: 66800
#include<bits/stdc++.h>
#define ll long long
#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define dump(a) (cerr << #a << "=" << (a) << endl)
#define DUMP(list) cout << "{ "; for(auto nth : list){ cout << nth << " "; } cout << "}" << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }


using namespace std;

int main(){
    int N;
    cin >> N;
    string S[N];
    rep(i, N){
        cin >> S[i];
    }
    ll ans = 0;
    string t[N];

    rep(i, N){

        bool flag = true;
        rep(j, N){
                t[j] = S[(i+j)%N];
        }

        rep(j, N){
            rep(k, N){
                if (t[j][k] != t[k][j]) {
                    flag = false;
                }
            }
        }
        if (flag) {
            ans++;
        }
    }
    cout << ans * N << endl;

}


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

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

int main(){
	int n;
	cin >> n;
	vector<int> a;
	for(int i=0; i<n; i++) a.push_back(i+1);

	int p[2];
	fill(p, p+2, 0);
	for(int i=0; i<2; i++){
		int x[n];
		for(int j=0; j<n; j++) cin >> x[j];
		vector<int> b=a;
		while(1){
			bool flg=true;
			for(int j=0; j<n; j++){
				if(b[j]!=x[j]) flg=false;
			}
			if(flg) break;
			next_permutation(b.begin(), b.end());
			p[i]++;
		}
	}
	cout << abs(p[0]-p[1]) << endl;
	return 0;
}

Measured memory_bytes: 256
people_num, food_num = [int(n) for n in input().split()]
_, *fav_foods = [int(n) for n in input().split()]
fav_foods = set(fav_foods)

for p in range(1, people_num):
    _, *favs = [int(n) for n in input().split()]
    favs = set(favs)
    fav_foods = {f for f in fav_foods if f in favs}

print(len(fav_foods))


Measured memory_bytes: 3060
from scipy.misc import comb
N, A, B = map(int, input().split())
V = sorted(list(map(int, input().split())), reverse=True)

# 価値の平均の最大値を出力
print(sum(V[:A]) / A)

# A番目に大きいものがいくつあるか
C = V.count(V[A - 1])
if max(V) != V[A - 1]:
    # あと何個選ぶ必要があるか
    remain = A - len([v for v in V if v > V[A - 1]])
    print(comb(C, remain, 1))
else:
    ans = 0
    for i in range(A, B + 1):
        ans += comb(C, i, 1)
    print(ans)


Measured memory_bytes: 13284
import core.bitop;
import std.algorithm;
import std.ascii;
import std.bigint;
import std.conv;
import std.functional;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.random;
import std.typecons;

alias sread = () => readln.chomp();
alias Point2 = Tuple!(long, "y", long, "x");

T lread(T = long)()
{
    return readln.chomp.to!T();
}

T[] aryread(T = long)()
{
    return readln.split.to!(T[])();
}

void scan(TList...)(ref TList Args)
{
    auto line = readln.split();
    foreach (i, T; TList)
    {
        T val = line[i].to!(T);
        Args[i] = val;
    }
}

void minAssign(T, U = T)(ref T dst, U src)
{
    dst = cast(T) min(dst, src);
}

void maxAssign(T, U = T)(ref T dst, U src)
{
    dst = cast(T) max(dst, src);
}

void main()
{
    auto a = sread();
    auto b = sread();
    bool z = a[0] == b[2] && a[1] == b[1] && a[2] == b[0];
    writeln(z ? "YES" : "NO");
}


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

public class Main {

	static boolean[][] obstacleMap;
	static int[][] directions8 = { { -1, -1 }, { -1, 0 }, { -1, 1 }, { 0, -1 }, { 0, 1 }, { 1, -1 }, { 1, 0 },
			{ 1, 1 } };
	static int[][] directions6 = { { -1, -1 }, { -1, 0 }, { 0, -1 }, { 0, 1 }, { 1, 0 }, { 1, 1 } };
	static int[][] directions4 = { { -1, 0 }, { 1, 0 }, { 0, -1 }, { 0, 1 } };
	static int ans;
	static int t;
	static ArrayDeque<int[]> q;

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		while (true) {

			t = sc.nextInt();
			int n = sc.nextInt();

			if ((t | n) == 0) {
				break;
			}

			// [30][30]が(0,0)。
			obstacleMap = new boolean[1000][1000];
			for (int i = 0; i < n; i++) {
				obstacleMap[sc.nextInt() + 300][sc.nextInt() + 300] = true;
			}
			ans = 0;
			int[] start = { sc.nextInt() + 300, sc.nextInt() + 300, 0 };
			q = new ArrayDeque<>();
			q.add(start);
			while (!q.isEmpty()) {
				int[] next = q.poll();
				walk(next[0], next[1], next[2]);
			}

			System.out.println(ans);
		}

	}

	static void walk(int nowX, int nowY, int idx) {
		if (idx > t || obstacleMap[nowX][nowY]) {
			return;
		}
		ans++;
		obstacleMap[nowX][nowY] = true;
		for (int i = 0; i < 6; i++) {
			int[] next = { nowX + directions6[i][0], nowY + directions6[i][1], idx + 1 };
			q.add(next);
		}
	}

	// BFS用に二つの配列を足し算する
	static int[] addArrayElms(int[] a, int[] b) {
		int[] c = new int[a.length];
		for (int i = 0; i < a.length; i++) {
			c[i] = a[i] + b[i];
		}
		return c;
	}

	// //二分探索
	// k <= num となる最小の配列要素kのインデックスを返す
	static private int binarySearch(long num, long[] orderedArray) {
		int lowerBorder = -1;
		int upperBorder = orderedArray.length;
		int mid;

		while (upperBorder - lowerBorder > 1) {
			mid = (upperBorder + lowerBorder) / 2;
			if (orderedArray[mid] <= num) {
				lowerBorder = mid;
			} else {
				upperBorder = mid;
			}
		}
		return lowerBorder;
	}

	// 二分探索
	// k <= num となる最小のList要素kのインデックスを返す
	static private int binarySearch(long num, ArrayList<Long> orderedList) {
		int lowerBorder = -1;
		int upperBorder = orderedList.size();
		int mid;

		while (upperBorder - lowerBorder > 1) {
			mid = (upperBorder + lowerBorder) / 2;
			if (orderedList.get(mid) <= num) {
				lowerBorder = mid;
			} else {
				upperBorder = mid;
			}
		}
		return lowerBorder;
	}

	// aとbの最小公倍数を求める
	public static int gcd(int a, int b) {
		return b == 0 ? a : gcd(b, a % b);
	}

	public static long gcd(long a, long b) {
		return b == 0 ? a : gcd(b, a % b);
	}
}



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

int main(){
  int n;
  cin >> n;
  ll ans = 1;
  map<int, int> mp;
  for(int i=2; i<=n; ++i){
    int x = i;
    for(int j=2; j<=i; ++j){
      while(x%j == 0){
        x /= j;
        ++mp[j];
      }
    }
  }
  for(auto p : mp){
    ans *= p.second + 1;
    ans %= MOD;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static MyUtil;

class MyUtil
{
    public static void Swap<T>(ref T a, ref T b)
    {
        var t = a;
        a = b;
        b = t;
    }

    public static int[] ReadIntArray()
    {
        return ReadLine().Split().Select(x => int.Parse(x)).ToArray();
    }

    public static long[] ReadLongArray()
    {
        return ReadLine().Split().Select(x => long.Parse(x)).ToArray();
    }
}

class Program
{
    public static void Main()
    {
        int n, a, b, c;
        var t = ReadIntArray();
        n = t[0]; a = t[1]; b = t[2]; c = t[3];

        var l = new int[n];
        for (int i = 0; i < n; i++)
        {
            l[i] = int.Parse(ReadLine());
        }

        int maxi = 1 << (n*2);
        int ans = 1000000000;

        for (int i = 0; i < maxi; i++)
        {
            int alen = 0, anum = 0;
            int blen = 0, bnum = 0;
            int clen = 0, cnum = 0;

            int pat = i;
            for (int j = 0; j < n; j++)
            {
                switch (pat&3)
                {
                    case 0: /* nothing to do */
                        break;
                    case 1: /* used for A */
                        alen += l[j];
                        anum++;
                        break;
                    case 2: /* used for B */
                        blen += l[j];
                        bnum++;
                        break;
                    case 3: /* used for C */
                        clen += l[j];
                        cnum++;
                        break;
                }
                pat >>= 2;
            }

            if (anum > 0 && bnum > 0 && cnum > 0)
            {
                int score = Math.Abs(a - alen) + 10 * (anum - 1)
                    +       Math.Abs(b - blen) + 10 * (bnum - 1)
                    +       Math.Abs(c - clen) + 10 * (cnum - 1);
                ans = Math.Min(ans, score);
            }
        }

        WriteLine(ans);
    }
}


Measured memory_bytes: 13396
using System;
using System.Linq;
class c
{
    static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        var x = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
        var ans = int.MaxValue;
        for (int i = x.Min(); i <= x.Max(); i++)
        {
            var temp = 0;
            for (int j = 0; j < n; j++)
            {
                temp += (int)Math.Pow(x[j] - i, 2);
            }
            ans = Math.Min(temp, ans);
        }
        Console.WriteLine(ans);
    }
}


Measured memory_bytes: 13268
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j): return [[ini]*i for i2 in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for i2 in range(j)] for i3 in range(k)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from collections import Counter # a = Counter(A).most_common()
#from itertools import accumulate #list(accumulate(A))

N, K = mi()
A = li()
flag = [0]*N
l = []
i = 1
ind = 0
while True:
    flag[ind] = i
    l.append(ind+1)
    if not flag[A[ind]-1]:
        ind = A[ind]-1
    else:
        ind = A[ind]-1
        break
    i += 1

if K <= flag[ind] - 1:
    print(l[K])
    exit()

if ind != 0:
    K -= flag[ind] -1
    i -= flag[ind] -1
    l = l[flag[ind] -1:]
print(l[K%i])

Measured memory_bytes: 32284
#include<stdio.h>
int main()
{
	int a,b,c,x,y,z;
	scanf("%d %d %d",&a,&b,&c);
	x=a+b;
	y=a+c;
	z=b+c;
	if(a==b || b==c || c==a)
	{
		printf("%d\n",a+b);
	}
	else if(x<y && x<z)
	{
		printf("%d\n",x);
	}
	else if(y<z && y<x)
	{
		printf("%d\n",y);
	}
	else if(z<x && z<y)
	{
		printf("%d\n",z);
	}

	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<ll>;
#define  rep(i,n) for(ll i = 0; i < (n); ++i)
#define  red(i,n) for(ll i = (n)-1; i >= 0; --i)
#define  all(a)   begin(a),end(a)
#define  pb(a)    push_back(a)
#define  yn(a)    cout << ( (a)?"Yes\n":"No\n" )
inline ll gcd(ll a,ll b) { return b?gcd(b,a%b):a; }

int main()
{
    int n,ans=0;
    cin>>n;
    int a[n],b[n],c[n-1];
    rep(i,n)cin>>a[i];
    rep(i,n)cin>>b[i];
    rep(i,n-1)cin>>c[i];
    rep(i,n){
        ans+=b[a[i]-1]; 
        if(i>0 && a[i-1]+1==a[i]) ans+=c[a[i-1]-1];
    }
    cout<<ans<<endl;    
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>


int main(void)
{
	int x,i;


	for(i = 1; i <= 10000; i++)
	{
		scanf("%d" , &x);
		if(x == 0){
			break;
		}else
		{
			printf("Case %d: %d\n", i, x);
		}
	}
	return 0;
}

Measured memory_bytes: 596
#include <iostream>
#include <algorithm>

using namespace std;
template<class T> inline bool chmax(T& a, T b) {
	if (a < b) { a = b; return true; }
	return false;
}
template<class T> inline bool chmin(T& a, T b) {
	if (a > b) { a = b; return true; }
	return false;
}
const long long INF = 1LL << 60;

int N;
long long W, weight[110], value[110];
long long dp[110][100100] = { 0 };

int main() {
	cin >> N >> W;
	for (int i = 0; i < N; i++) cin >> weight[i] >> value[i];

	for (int i = 0; i < N; i++) {
		for (int sum_w = 0; sum_w <= W; sum_w++) {
			if (sum_w >= weight[i]) {
				chmax(dp[i + 1][sum_w], dp[i][sum_w - weight[i]] + value[i]);
			}
			chmax(dp[i + 1][sum_w], dp[i][sum_w]);
		}
	}

	cout << dp[N][W] << endl;

	return 0;
}


Measured memory_bytes: 81564
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)


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

  int n;
  cin >> n;  
  int a[n];
  rep(i,n) cin >> a[i];
  int odd=0;
  //  int even=0;
  rep(i,n){
    if(a[i]%2==1) odd++;
    //    else even++;
  }
  if(odd%2==0) cout << "YES" << endl;
  else cout << "NO" <<endl;
  
  return 0;
    

}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define ii pair<int,int>
#define F first
#define S second
#define pb push_back
#define pf push_front
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define fore(i,a,b) for(int i = a;i < b; i+= 1)
#define forr(i,a) for(int i = a; i >= 0; i--)
#define fori(i,m) for(auto i = m.begin(); i != m.end(); i++) 
#define sz(s) int(s.size())
#define cls(a,car) memset(a,car,sizeof (a))
using namespace std;
typedef long long ll;
const int N = 1 * 1e5 + 5;
const ll mod = 1e9 + 7;
const int INF = INT_MAX;
const ll INFCAD  = ll(INT_MAX) * 2 + 1;
int n, k;
ii v[N][3];
int dp[N][5];
int f(int i,int last){
    if(i == n)
        return 0;
    if(dp[i][last] != -1)return dp[i][last];
    int &ans = dp[i][last];
    ans = -1e9;
    if(v[i][0].S != last)
        ans = max(ans,f(i + 1,v[i][0].S) + v[i][0].F);

    if(v[i][1].S != last)
        ans = max(ans,f(i + 1,v[i][1].S) + v[i][1].F);

    if(v[i][2].S != last)
        ans = max(ans,f(i + 1,v[i][2].S) + v[i][2].F);
    return ans;

}
int main(){/*
    freopen("in","r",stdin);
    freopen("out","w",stdout);*/
    cls(dp, -1);
    cin >> n;
    fore(i,0,n){
        cin >> v[i][0].F >> v[i][1].F >> v[i][2].F;
        v[i][0].S = 0;
        v[i][1].S = 1;
        v[i][2].S = 2;
    }
    cout << f(0,3) << '\n';
    return 0;   
}

Measured memory_bytes: 10752
#include <bits/stdc++.h>
#define int long long

using namespace std;

const int O = 1e3 + 5;

int n;

int Mu5(int x){
    return 1LL * x * x * x * x * x;
}

main(){
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cin >> n;
    for (int i = O; i >= -O; -- i){
        for (int j = O; j >= -O; -- j)
            if (Mu5(i) - Mu5(j) == n){
                cout << i << " " << j;
                return 0;
            }
    }
}

Measured memory_bytes: 3536
#include <iostream>
#include <algorithm>
#include <cmath>
#include <limits>
#include <vector>
#include <cstdio>
#include <bits/stdc++.h>
#include <set>
using namespace std;
using ll =long long;

int main (void) {
  ll a,b;
  cin >> a>> b;
  int sa=b-a+1;
  if(a*b<=0) {
    cout << "Zero";
    return 0;
  }
  if(sa%2==1 && b<0 ){
    cout << "Negative";
  }
  else{
    cout << "Positive";
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = (s); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) for(int i = (n); i >= 0; i--)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << '\n';
#define CFYN(n) cout << ( (n) ? "YES":"NO") << '\n';
#define OUT(n) cout << (n) << '\n';
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;

int main(void)
{
    IOS
    int N; cin >> N;
    vector<ll> v(N);
    set<ll> st;
    REP(i,N) {
        cin >> v[i];
        st.insert(v[i]);
    }
    sort(RALL(v));
    map<ll,ll> mp;
    ll cnt = v[0];
    mp[cnt]++;
    ll ans = 0;
    FOR(i,1,N) {
        if (v[i] != cnt) {
            mp[cnt]--;
            ans += cnt;
            mp[v[i]] += 2;
            if (mp[cnt] == 0) {
                auto it = st.lower_bound(cnt);
                it--;
                cnt = *it;
            }
        } else {
            ans += cnt;
            mp[cnt]++;
        }
    }

    cout << ans << '\n';


    return 0;
}

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

int main()
{
	int n;
	int num[21];
	int count = 0;

	scanf("%d", &n);

	for (int i = 0; i < n; i++)
	{
		scanf("%d", &num[i]);
	}

	for (int i = 1; i < n-1; i++)
	{
		
		if (((num[i] > num[i-1]) && (num[i] < num[i + 1]))|| ((num[i] < num[i - 1]) && (num[i] > num[i + 1])))
			count++;
		
	}

	printf("%d", count);

	return 0;
}

Measured memory_bytes: 128
#include <cstdio>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <iterator>
#include <cassert>
#include <numeric>
#pragma warning(disable:4996) 
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF  9223300000000000000
#define LINF2 1223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
//const long long MOD = 998244353;

using namespace std;


void solve()
{
    int max = -INF;
    int a, b, c;
    scanf("%d%d%d", &a, &b, &c);
    max = MAX(MAX(a, b), c);
    int tmp=max * 3 - a - b - c;
    if (tmp % 2 == 0) {
        printf("%d", tmp / 2);
    }
    else {
        printf("%d", (tmp + 3) / 2);
    }

    return;
}

int main(int argc, char* argv[])
{
#if 1
    solve();
#else
    int T;
    scanf("%d%d", &T, &B);
    int t;
    for(t=0; t<T; t++) {
        //printf("Case #%d: ", t+1);
        solve();
    }
#endif
    return 0;
}



Measured memory_bytes: 128
#include<iostream>
#include<set>
using namespace std;
int main()
{
  int x,n,i,p,q;
  cin>>x>>n;
  set<int> S;
  for(i=0;i<n;i++)
  {
    cin>>p;
  	S.insert(p);
  }
  p=x;
  while(S.count(p))
    --p;
  q=x;
  while(S.count(q))
    ++q;
  if(x-p<=q-x)
    cout<<p;
  else
    cout<<q;
}

Measured memory_bytes: 3608
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ld long double
#define al(a) (a).begin(),(a).end()
#define mk make_pair
#define check cout<<"?"<<endl;
                                                                                                     
ll MOD=1000000007;                                                                                     
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

int main(){
    ll n; cin>>n;
    vector<ll> c(n,0),cl;
    rep(i,n){
        cin>>c[i]; c[i]--;
    }
    rep(i,n-1){
        if(c[i]!=c[i+1]) cl.push_back(c[i]);
    }
    cl.push_back(c.back());
    ll N=cl.size();
    vector<ll> dp(N+1,0),h(200000,0);
    dp[1]=1; h[cl[0]]=1;
    for(int i=2;i<=N;i++){
        dp[i]=(dp[i-1]+dp[h[cl[i-1]]])%MOD;
        h[cl[i-1]]=i;
    }
    cout<<dp[N]<<endl;
}

Measured memory_bytes: 9536
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cassert>
#include <complex>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <sstream>
#include <ctime>
#include <cctype>
#include <set>
#include <map>
#include <queue>
#include <bitset>
#include <deque>
#include <stack>
#include <memory.h>
using namespace std;
#define ll long long 
vector<int> nei[2017];
int dfs(int x,int p,int d,int mx){
	int ans=1;
	if(d!=mx){
		for(int y:nei[x]){   
			if(y==p){
				continue;
			}
			ans+=dfs(y,x,d+1,mx);
		}
	}
	return ans;
}
int main()
{
	int n,k;
	cin>>n>>k;
	for(int i=0;i<n-1;i++){
		int a,b;
		cin>>a>>b;
		nei[a].push_back(b);
		nei[b].push_back(a);
	}
	int ans=0;
	if(k%2==0){
		for(int v=1;v<=n;v++){
			ans=max(ans,dfs(v,-1,0,k/2));
		}
	}
	else{
		for(int v=1;v<=n;v++){
			for(int u:nei[v]){
				ans=max(ans,dfs(v,u,0,k/2)+dfs(u,v,0,k/2));
			}
		}
	}
	ans=n-ans;
	cout<<max(0,ans);
    return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include <cmath>
#include<queue>
#include<cstdio>
//#include <bits/stdc++.h>
using namespace std;
int main(){
    int N,M;
    cin>>N>>M;
    int ans;
    ans=N*(N-1)/2+M*(M-1)/2;
    cout<<ans<<endl;
    return 0;
}

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

const int N = (int)5e4;
const long long INF = (long long)1e18;

long long dat[N+5];

int main() {
    for (int i=0; i<N+3; i++) dat[i] = INF;
    dat[0] = 0;

    int h,n; scanf("%d %d", &h, &n);
    for (int i=1; i<=n; i++) {
        int a,b; scanf("%d %d", &a, &b);

        for (int i=a; i<=N; i++) {
            dat[i] = min(dat[i], dat[i-a] + b);
        }
    }

    long long res = INF;
    for (int i=h; i<=N; i++) {
        res = min(res, dat[i]);
    }

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


Measured memory_bytes: 640
from itertools import combinations
from functools import reduce
from operator import mul

N = int(input())
S_row = [input() for _ in range(N)]

count = [0] * 5
for i, c in enumerate("MARCH"):
    count[i] = len(list(filter(lambda n: n[0] == c, S_row)))

print(sum(map(lambda x: reduce(mul, x), combinations(count, 3))))


Measured memory_bytes: 11064
#include<iostream>
#include<string>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;

int main(){
  string s;
  cin>>s;
  bool ans=true;
  rep(i,s.length()){
    if(i%2==0&&s[i]=='L')ans=false;
    if(i%2==1&&s[i]=='R')ans=false;
  }
    if(ans)cout<<"Yes"<<endl;
   else cout<<"No"<<endl;
}

Measured memory_bytes: 384
#a,b=map(int,input().split())
n=int(input())
#s,t=list(input().split())
a=list(map(int,input().split()))
nex=1
ans=0
for i in range(n):
    if a[i]==nex:
        nex+=1
    else:
        ans+=1
print(-1) if n==ans else print(ans)


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

using namespace std;
typedef long long ll;

#define  input freopen("in.txt","r",stdin)
#define  output freopen("out.txt","w",stdout)

const int mxn = 2e5;
ll dp[mxn];
ll arr[mxn];
ll n, k;

int main()
{
	//input;
	//output;

	cin >> n >> k;

	for(int i = 0; i < n; i++) 
	{
		cin >> arr[i];
		dp[i] = 1e18;
	}
	dp[0] = 0;

	for(int i = 0; i < n; i++) 
	{
		for(int r = i+1; r <= i+k; r++) 
			dp[r] = min(dp[r], dp[i]+abs(arr[i]-arr[r]));
	}
	cout << dp[n-1] << '\n';
	return 0;
}

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N;
vector<int> E[202020];
vector<int> C[3];
int R[202020];

vector<int> cand[2];

void dfs(int cur,int pre,int d) {
	cand[d].push_back(cur);
	FORR(e,E[cur]) if(e!=pre) dfs(e,cur,d^1);
}

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N;
	for(i=1;i<=N;i++) C[i%3].push_back(i);
	
	FOR(i,N-1) {
		cin>>x>>y;
		E[x-1].push_back(y-1);
		E[y-1].push_back(x-1);
	}
	dfs(0,0,0);
	
	if(cand[0].size()>cand[1].size()) swap(cand[0],cand[1]);
	
	if(cand[0].size()<=C[0].size()) {
		while(cand[0].size()&&C[0].size()) {
			x=cand[0].back();
			y=C[0].back();
			cand[0].pop_back();
			C[0].pop_back();
			R[x]=y;
		}
		FORR(c,cand[0]) {
			FOR(i,3) if(C[i].size()) {
				R[c]=C[i].back();
				C[i].pop_back();
				break;
			}
		}
		FORR(c,cand[1]) {
			FOR(i,3) if(C[i].size()) {
				R[c]=C[i].back();
				C[i].pop_back();
				break;
			}
		}
	}
	else {
		assert(C[2].size()<=cand[0].size());
		assert(C[1].size()<=cand[1].size());
		while(cand[0].size()&&C[2].size()) {
			x=cand[0].back();
			y=C[2].back();
			cand[0].pop_back();
			C[2].pop_back();
			R[x]=y;
		}
		while(cand[1].size()&&C[1].size()) {
			x=cand[1].back();
			y=C[1].back();
			cand[1].pop_back();
			C[1].pop_back();
			R[x]=y;
		}
		FORR(c,cand[0]) {
			FOR(i,3) if(C[i].size()) {
				R[c]=C[i].back();
				C[i].pop_back();
				break;
			}
		}
		FORR(c,cand[1]) {
			FOR(i,3) if(C[i].size()) {
				R[c]=C[i].back();
				C[i].pop_back();
				break;
			}
		}
		
		
		
	}
	
	
	
	
	FOR(i,N) cout<<R[i]<<" ";
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 22296
#include<stdio.h>

int main()
{

  int N,A[100],i,j,minj,tmp,c=0;

  scanf("%d",&N);

  for(i=0;i<N;i++){

    scanf("%d",&A[i]);

  }

  for(i=0;i<N-1;i++){

    minj=i;

    for(j=i;j<N;j++){

      if(A[j]<A[minj]){

	minj=j;

      }

      }

	tmp=A[i];

	A[i]=A[minj];

	A[minj]=tmp;

	if(i!=minj)c++;

    

  }

  for(i=0;i<N;i++){

    printf("%d",A[i]);

    if(i!=N-1)printf(" ");

  }

  printf("\n");

  printf("%d\n",c);

  return 0;
}




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


#define FOR(i,a,b) for(unsigned long long i=a;i<=(unsigned long long )(b);i++)

int main(){ 
    unsigned long long N, m=0;
    cin >> N;
    unsigned long long ans =0;
    
    FOR(i,1,N-1){
        m = (N-1)/i +1;
        while(i*m > N-1){
            m--;
        }
        ans += m;
    }
cout << (ans-m+1);
}

Measured memory_bytes: 3636
//
//  main.cpp
//  AC
//
//  Created by makinofuya on 2019/07/08.
//  Copyright © 2019 makinofuya. All rights reserved.
//
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <stack>
#include <math.h>

typedef long long ll;
using namespace std;
#define mod 1000000007
#define rep(i,n) for(ll i=0;i<n;i++)
#define out(s) cout << s << endl


int main(){
    int h,w;cin >> h >> w;
    vector<string> a(h);
    for (int i = 0; i < h; i++) {
        cin >> a[i];
    }
    
    vector<bool> row(h, false);
    vector<bool> col(w, false);
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            if (a[i][j] == '#') {
                row[i] = true;
                col[j] = true;
            }
        }
    }
    
    for (int i = 0; i < h; i++) {
        if (row[i]) {
            for (int j = 0; j < w; j++) {
                if (col[j]) {
                    cout << a[i][j];
                }
            }
            cout << endl;
        }
    }
}




Measured memory_bytes: 256
#! -*- coding:utf-8 -*-
s = str(input())
s = list(s)
x = 'abcdefghijklmnopqrstuvwxyz'
x = list(x)

flag = 0
for i in range(len(s)):
    try:
        if(len(x) == 1 and s[i] == x[0]):
            flag = 1
        x.remove(s[i])
    except:
        pass

if(flag == 1):
    print('None')
else:
    print(x[0])


Measured memory_bytes: 3956
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define inf 1e18
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define pb push_back
#define ff first
#define ss second
#define vll vector<ll>
#define pii pair<ll,ll>
#define sz(v) (v).size()
#define srt(v) sort(v.begin(),v.end())
#define ull unsigned long long
#define tell(a) cout<<a<<" "
#define el cout<<endl;
#define rev(v) reverse(v.begin(),v.end())
#define rep(i,a,n) for(int i=a;i<n;i++)
#define M 1000000007
ll power(ll x, ll y, ll p){ll res = 1;x = x % p;while (y > 0){   if (y & 1)res = (res*x) % p;y = y>>1;
x = (x*x) % p;}return res;}



int main()
{
    IOS;
    int n;
    cin>>n;
    ll ans=0;
    vector<pii>v[n+1];
    for(int i=0;i<n;i++)
    {
        int t;
        cin>>t;
        while(t--)
        {
            int x,y;
            cin>>x>>y;
            v[i+1].pb({x,y});
        }
    }
    ll pp[n+1];
    for(int i=0;i<(1<<n);i++)
    {
        int mm=0,flag=1;
        memset(pp,-1,sizeof(pp));
        for(int j=1;j<=n;j++)
        {
            if((1<<j-1)&i)
            {
                pp[j]=1;
                // cout<<j<<endl;
            }
        }
        // for(int j=1;j<=n;j++)
        // cout<<pp[j]<<endl;
        for(int j=1;j<=n;j++)
        {
            if(pp[j]==1)
            {
                for(int k=0;k<v[j].size();k++)
                pp[v[j][k].ff]=v[j][k].ss;
            }
        }
        // for(int j=1;j<=n;j++)
        // cout<<pp[j]<<endl;
        for(int j=1;j<=n&&flag;j++)
        {
            if(pp[j]==1)
            {
                mm++;
                for(int k=0;k<v[j].size();k++)
                if(pp[v[j][k].ff]!=v[j][k].ss)
                {
                    flag=0;
                    break;
                }
            }
        }
        if(flag)
        ans=max(ans,(ll)mm);
        
    }
    cout<<ans;
}



Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
int main() {
  int ans=0;
  string s;
  cin >> s;
  if(s[0]=='2') {
    ans++;
  }
  if(s[1]=='2') {
    ans++;
  }
  if(s[2]=='2') {
    ans++;
  }
  if(s[3]=='2') {
    ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
def insertionSort(insert_list, num, g): 
    cnt = 0 
    for i in range(g, num):
        temp = insert_list[i]
        j = i - g 
        while (j >= 0 and insert_list[j] > temp):
            insert_list[j+g] = insert_list[j]
            j -= g
            cnt += 1
        insert_list[j+g] = temp
    return insert_list, cnt 

def shellSort(shell_list, num):
    cnt = 0 
    G = [1] 
    G_num = 1 
    for i in range(num):
        G_num = G_num*3 + 1 
        if G_num > num:
            break
        else:
            G.append(G_num)
    G.reverse()
    m = len(G)

    for i in range(m):
        shell_list, cnt_num = insertionSort(shell_list, num, G[i])
        cnt += cnt_num
    return m, G, cnt, shell_list    

if __name__ == "__main__":
    num = int(raw_input())
    num_list = [int(raw_input()) for i in range(num)]

    m, G, cnt, shell_list = shellSort(num_list, num)

    print m
    G = map(str, G)
    print " ".join(G)
    print cnt 
    for i in shell_list:
        print i

Measured memory_bytes: 77668
import math
a, b, c = map(float, input().split())
c = float(math.pi * c / 180)
S = float(0.5 * a * b * math.sin(c))
d = float(math.sqrt(pow(a, 2) + pow(b, 2) - 2 * a * b * math.cos(c)))
L = float(a + b + d)
h = float(2 * S / a)
print(S)
print(L)
print(h)



Measured memory_bytes: 5688
def main():
    N = int(input())
    A = [int(a) for a in input().split()]

    if all(a >=3200 for a in A):
        return 1, len(A)

    cls = set()
    count = 0
    for a in A:
        isAbove = True
        for i in range(8):
            if 400*i <= a < 400*(i+1):
                cls.add(i)
                isAbove = False
                break
        if isAbove:
            count += 1
    return len(cls), len(cls)+count

if __name__ == '__main__':
    output = main()
    print(" ".join(map(str, output)))

Measured memory_bytes: 3064
//q1.cpp

#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#define debug(x) cerr << #x << " = " << x << endl;


#define mod 1000000007 //1e9+7
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 10000


int main(){
    
    int t[6];
    int ans = 0;
    
    for(int i=0;i<6;i++){
        scanf("%d",&t[i]);
        ans += t[i];
    }
    
    printf("%d\n",ans-min(min(t[0],t[1]),min(t[2],t[3]))-min(t[4],t[5]));
    
    return 0;
}

Measured memory_bytes: 3224