akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define INF 1e18+5

const int nax = 2e5+9;

const int mod = 1e9+7;

vector<int> fact(nax);
vector<int> inv_fact(nax);

int pow(int b, int e){
    int ans = 1;
    while(e){
        if(e%2){
            ans*=b;
            ans%=mod;
        }
        b*=b;
        b%=mod;
        e/=2;
    }
    return ans;
}

int inv(int a){
    return pow(a,mod-2);
}

int bino(int a, int b){
    if(a < 1 || b < 1) return 0;
   // cout << fact[a+b-2]  << ' ' << inv_fact[a-1] << ' ' << inv_fact[b-1] << endl;
    return (((fact[a+b-2]*inv_fact[a-1])%mod)*inv_fact[b-1]%mod);
}

bool comp(pair<int, int> &a, pair<int, int> &b){
    return a.first+a.second < b.first+b.second;
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int h, w;
    cin >> h >> w;
    int n;
    cin >> n;
    fact[0] = inv_fact[0] = 1;
    for(int i = 1; i < nax; i++){
        fact[i] = fact[i-1]*i%mod;
        inv_fact[i] = inv(fact[i]);
    }
    vector< pair<int, int> > points(n+1);
    for(int i = 0; i < n; i++){
        int a, b;
        cin >> a >> b;
        points[i].first = a;
        points[i].second = b;
    }
    points[n] = make_pair(h,w);
    sort(points.begin(), points.end(), comp);
    vector<int> dp(n+1);

    for(int i = 0; i <= n; i++){
        dp[i] = bino(points[i].first, points[i].second);
        //cout << "DP " << points[i].first << ' ' << points[i].second << ' '  << i << ' ' << dp[i] << endl;
        for(int j = 0; j < i; j++){
            if(points[j].first <= points[i].first && points[j].second <= points[i].second){
                dp[i] -= (dp[j]*bino(points[i].first-points[j].first+1, points[i].second-points[j].second+1)%mod);
                dp[i] = (dp[i]+mod)%mod;
            }
        }
    }
    cout << dp[n] << endl;
}


Measured memory_bytes: 3456
#include <bits/stdc++.h>
using namespace std;
#define ALL(x) (x).begin(),(x).end()
#define COUT(x) cout<<(x)<<"\n"
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define REP(i, n) for(int i=0;i<n;i++)
#define YES(x) cout<<(x?"YES":"NO")<<"\n"
#define Yes(x) cout<<(x?"Yes":"No")<<"\n"
#define dump(x) cout<<#x<<" = "<<(x)<<"\n"
#define endl "\n"
using G = vector<vector<int>>;
using M = map<int,int>;
using P = pair<int,int>;
using PQ = priority_queue<int>;
using PQG = priority_queue<int,vector<int>,greater<int>>;
using V = vector<int>;
using ll = long long;
using edge = struct { int to; int cost; };
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

int main() {
  IOS;
  M m;
  REP(i,3) {
    int x; cin >> x;
    m[x]++;
  }
  YES(m[5] == 2 && m[7] == 1);
  return 0;
}

Measured memory_bytes: 3524
#include <stdio.h>

int main(int argc, char **argv)
{
	int i , acnt = 0, bcnt = 0, ccnt = 0;
	char cards[3][300] = { 0 };
	char turn = 'a';

	for (i = 0; i < 3; i++) {
		scanf("%s", cards[i]);
	}
	for (;;) {
		if (turn == 'a') {
			turn = cards[0][acnt];
			if (!turn) {
				printf("A\r\n");
				break;
			}
			acnt++;
		} else if (turn == 'b') {
			turn = cards[1][bcnt];
			if (!turn) {
				printf("B\r\n");
				break;
			}
			bcnt++;
		} else {
			turn = cards[2][ccnt];
			if (!turn) {
				printf("C\r\n");
				break;
			}
			ccnt++;
		}
	}

	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <string>
#include <math.h>
#include <algorithm>
#include <set>
#include <iomanip>
#include <stdio.h>
#include <sstream>
#include <string>
using namespace std;
int main(void){
  int n;
  cin>>n;
  vector<int> s(n);
  for(int i=0; i<n; i++){
    cin>>s.at(i);
  }
  vector<int> ans(n);
  bool can=true;
  for(int i=1; i<=n; i++){
    if(s.at(i-1)>i){
      can=false;
    }
  }

  if(can){
    for(int i=0; i<n; i++){
      for(int j=0; j<n; j++){
        if(s.at(s.size()-1-j)==s.size()-j){
          ans.at(ans.size()-1-i)=s.size()-j;
          s.erase(s.begin()+s.size()-1-j);
          break;
        }
      }
    }
    for(int i=0; i<n; i++){
      cout<<ans.at(i)<<endl;
    }
  }else{
    cout<<-1<<endl;
  }
}

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

int main(void){
int N;
cin >> N;
int t1 = 0, t2, x1 = 0, x2, y1 = 0, y2;
for(int i = 0; i < N; ++i){
cin >> t2 >> x2 >> y2;
if(t2 - t1 < (x2-x1)+(y2-y1)){
cout << "No" << endl;
return 0;
}else if(((t2 - t1)-((x2-x1)+(y2-y1)))%2 == 1){
cout << "No" << endl;
return 0;
}
t1 = t2;
x1 = x2;
y1 = y2;
}
cout << "Yes" << endl;
return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<map>
#include<vector>
#include<iterator>
#include<algorithm>
using namespace std;

map<string, int> bag;
map<string, int> :: iterator itr_bag;

map<int, vector<string> > ans;
map<int, vector<string> > :: iterator itr_ans;
int main(){
	int n;
	cin >> n;
	for(int i=0; i < n; i++){
		string s;
		cin >> s;
		bag[s]++;
	}
	
	for(itr_bag=bag.begin(); itr_bag!=bag.end(); ++itr_bag){
		int score = itr_bag->second;
		string name = itr_bag->first;
		ans[-score].push_back(name);
	}

	for(itr_ans=ans.begin(); itr_ans!=ans.end();){
		int score = itr_ans->first;
		sort(ans[score].begin(), ans[score].end());
		for(int i=0; i < ans[score].size(); i++) cout << ans[score][i] << endl;
		break;
	}
}


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

int main(){
    int L;
    cin >> L;
    vector<ll> a(L+1, 0);
    for (int i = 1; i <= L; i++) cin >> a[i];
    
    vector<vector<ll>> dp(L+1, vector<ll>(5, 0));
    for (int i = 1; i <= L; i++) {
        ll t = dp[i-1][0];
        dp[i][0] = t+a[i];
        t = min(t, dp[i-1][1]);
        dp[i][1] = t + ((a[i] == 0) ? 2 : a[i]%2);
        t = min(t, dp[i-1][2]);
        dp[i][2] = t + (a[i]+1)%2;
        t = min(t, dp[i-1][3]);
        dp[i][3] = t + ((a[i] == 0) ? 2 : a[i]%2);
        t = min(t, dp[i-1][4]);
        dp[i][4] = t + a[i];
    }
    
    ll ans = dp[L][0];
    for (int i = 1; i <= 4; i++) ans = min(ans, dp[L][i]);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 15872
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <iomanip>
#include <algorithm>
#include <sstream>
#include <string>
#include <math.h>
#include <set>
#include <deque>
#include <queue>
using namespace std;
typedef long long ll;
const int mod = 1000000007;

int main() {
    ios::sync_with_stdio(false);
    int n;
  	cin >> n;
  	cout << n / 3;
}

Measured memory_bytes: 3592
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <climits>
#include <bitset>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<pair<int,int>> vpii;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvc;
typedef vector<vector<string>> vvs;
#define rep(i,n) for(int i=0;i<n;i++)
#define fin(ans) cout<<(ans)<<endl
#define P 1000000007
#define STI(s) atoi(s.c_str())//string to int
#define mp(p,q) make_pair(p,q)
#define Sort(a) sort(a.begin(),a.end())
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
const int INF = INT_MAX;
const long long LLINF = 1LL<<60;
//g++ -std=c++1z temp.cpp
//./a.exe
    
int main(void){ios::sync_with_stdio(false);cin.tie(0);
//////////////////////////////////////////////////////
    
  int a,b;
  cin >> a >> b;
  if ((a+b)<10)
  {
    cout << a+b << endl;
  }else
  {
    cout << "error" << endl;
  }
  
  
  
  
  
  
  
  
 
//////////////////////////////////////////////////////
return 0;}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

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

        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int d = sc.nextInt();

        sc.close();

        int ab = a * b;
        int cd = c * d;

        if (ab > cd) {
            System.out.println(ab);
        } else if (ab < cd) {
            System.out.println(cd);
        } else {
            System.out.println(ab);
        }

    }
}

Measured memory_bytes: 22740
#include <algorithm>
#include <cstdio>

static const size_t n_max = 1000;
static std::pair<int, size_t> A[n_max];
static size_t C[n_max];
static bool visited[n_max];

int main() {
  size_t n;
  scanf("%zu\n", &n);
  for (size_t i = 0; i < n; i++) {
    scanf("%d", &A[i].first);
    A[i].second = i;
  }
  std::sort(A, A + n);
  int M = A[0].first;
  int cost = 0;
  for (size_t i = 0; i < n; i++) {
    if (visited[i])
      continue;
    visited[i] = true;
    C[0] = i;
    size_t l = 1;
    auto m = A[i].first, s = A[i].first;
    while (!visited[A[C[l-1]].second]) {
      C[l] = A[C[l-1]].second;
      visited[C[l]] = true;
      m = std::min(m, A[C[l]].first);
      s += A[C[l]].first;
      l++;
    }
    if (l == 1)
      continue;
    cost += std::min((s - m) + m * (l - 1), (s - m) + M * (l - 1) + 2 * (m + M));
  }
  printf("%d\n", cost);
  return 0;
}

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


string n;


void input() {
    cin >> n;
}


int main() {
    input();
    for (char c : n) {
        if (c == '1') cout << "9";
        else cout << "1";
    }
    cout << endl;
}


Measured memory_bytes: 256
import java.util.*;
 
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int number = 0;
		number = N % 10;
		if(number == 2 || number == 4 || number == 5 || number == 7 || number == 9) {
			System.out.println("hon");
		}else if(number == 0 || number == 1 || number == 6 || number == 8) {
			System.out.println("pon");
		}else if(number == 3) {
			System.out.println("bon");
		}
  }
}

Measured memory_bytes: 35580
#include<cstdio>
char s[200005];
int sum[200005];

int min(int a,int b){ return a>b?b:a; }

int main(){
    int n;
    scanf("%d%s",&n,s+1);
    sum[0] = 0;
    for(int i = 1; i <= n; i++){
        sum[i] = sum[i-1];
        if(s[i]=='R') sum[i]++;
    }
    int ans = n;
    for(int i = 0; i <= n; i++){
        int need = i-sum[i], left = sum[n]-sum[i];
        int cur = 0;
        int minus = min(need,left);
        need -= minus, left -= minus;
        cur += minus;
        cur += need+left;
        if(cur<ans) ans = cur;
    }
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 2712
def main():
    #from sys import stdin, setrecursionlimit
    #setrecursionlimit(10**9)
    #r = input()
    #n = int(input())
    #a, b = map(int, input().split())
    #s, y = input().split()
    #a = input().split()
    #a = [int(input()) for i in range(n)]
    #a = list(map(int, input().split()))
    #a = [list(map(int, input().split())) for i in range(n)]
    #a = [int(s) - 1 for s in input().split()]
    #l=[int(input()) for _ in range(int(input()))]
    #res = 0
    n,k = map(int,input().split())
    a = sorted([int(input()) for i in range(n)])
    b = list(a[i]-a[i-k+1] for i in range(k-1,n))
    print(min(b))

if __name__ == '__main__':
    main()


Measured memory_bytes: 56408
#include <cstdio>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

class Bit
{
    int n;
    vector<long long> data;
public:
    Bit(int n){ // コンストラクタ
        this->n = n;
        data.assign(n+1, 0);
    }
    void add(int k, long long x){ // k番目の要素にxを加算する
        ++ k;
        while(k <= n){
            data[k] += x;
            k += k & -k;
        }
    }
    long long sum(int k){ // 区間[0,k]の総和を返す
        ++ k;
        long long ret = 0;
        while(k > 0){
            ret += data[k];
            k -= k & -k;
        }
        return ret;
    }
    long long sum(int a, int b){ // 区間[a,b]の総和を返す
        return sum(b) - sum(a-1);
    }
    int upper_bound(long long x){ // 総和が初めてxを超える位置を返す（ただし、各位置の数値が非負数であることを前提とする）
        int b = 1;
        while(b < n)
            b *= 2;
        int a = 0;
        while(b > 0){
            if(a+b <= n && x >= data[a+b]){
                x -= data[a+b];
                a += b;
            }
            b /= 2;
        }
        return (a < n)? a : -1;
    }
    int lower_bound(long long x){ // 総和が初めてx以上になる位置を返す（ただし、各位置の数値が非負数であることを前提とする）
        return upper_bound(x-1);
    }
};

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

    vector<pair<int, int> > a(n); // 放出量、許容量
    for(int i=0; i<n; ++i)
        cin >> a[i].first >> a[i].second;
    sort(a.begin(), a.end());

    vector<vector<int> > index(100001); 
    for(int i=0; i<n; ++i)
        index[a[i].second].push_back(i);


    int left = 0;
    int right = n;
    while(left < right){
        int mid = (left + right + 1) / 2;

        bool ok = false;
        Bit foo(n);
        Bit num(n);
        for(int i=100000; i>=1; --i){
            for(unsigned j=0; j<index[i].size(); ++j){
                int k = index[i][j];
                foo.add(k, a[k].first);
                num.add(k, 1);
            }

            int k = num.lower_bound(mid);
            if(k == -1)
                continue;
            long long sum = foo.sum(k);
            if(sum <= (long long)i * mid){
                ok = true;
                break;
            }
        }

        if(ok)
            left = mid;
        else
            right = mid - 1;
    }

    cout << left << endl;

    return 0;
}

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

int main(){
  int W,H,x,y,r;
  cin >> W >> H >> x >> y >> r;
  if (r<=x && x<=W-r && r<=y && y<=H-r){
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}



Measured memory_bytes: 3104
//Author: Fuadul Hasan(fuadul202@gmail.com)
#include<bits/stdc++.h>
using namespace std;

#define ll long long
const int N   = 2e5 + 5;

int main(){
	
	int n;
	cin>>n;
	string a[4] = {"AC", "WA", "TLE", "RE"};
	string s;
	map<string ,int>m;
	while(n--){
		cin>>s;
		m[s]++;
	}	

	for(string  i: a){
		cout<<i<<" x "<<m[i]<<endl;
	}


	

	return 0;
}

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

string LCS(const string& s, const string& t) {
	int n = s.size(), m = t.size();
	vector<vector<int>> lcs(n + 1, vector<int>(m + 1));
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= m; j++) {
			if (s[i - 1] == t[j - 1]) {
				lcs[i][j] = max(lcs[i][j], lcs[i - 1][j - 1] + 1);
			} else {
				lcs[i][j] = max({lcs[i][j], lcs[i - 1][j], lcs[i][j - 1]});
			}
		}
	}
	string ret = "";
	for (int i = n, j = m; i > 0 && j > 0;) {
		if (lcs[i][j] == lcs[i - 1][j]) {
			i--;
			continue;
		}
		if (lcs[i][j] == lcs[i][j - 1]) {
			j--;
			continue;
		}
		assert(s[i - 1] == t[j - 1]);
		ret += s[i - 1];
		i--, j--;
	}
	reverse(ret.begin(), ret.end());
	return ret;
}

int main() {
	string s, t;
	cin >> s >> t;
	cout << LCS(s, t) << endl;
}

Measured memory_bytes: 35584
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <tuple>

using ll = long long;
using namespace std;
#define modmod 1000000007


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

    if(abs(N-M) >= 2){
        cout << 0 << endl;
        return 0;
    }

    ll N_num = 1, M_num = 1;

    for(int i = 1; i <= N; i++){
        N_num = ((N_num % modmod) * (i%modmod)) % modmod;
    }

    for(int i = 1; i <= M; i++){
        M_num = ((M_num%modmod) * (i%modmod)) % modmod;
    }

    ll result;

    if(N==M){
        result = N_num*M_num*2;
    }else{
        result = N_num*M_num;
    }

    ll res = result % 1000000007;

    cout << res << endl;

    return 0;
}


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

string s;
bool f[26];

int main() {
	cin >> s;
	if (s.size() < 26) {
		for (int i = 0; i < s.size(); ++i) {
			f[s[i] - 'a'] = 1;
		}
		for (int i = 0; i < 26; ++i) if (!f[i]) {
			return cout << s << char('a' + i) << '\n',0;
		}
	}
	else {
		int pos = -1;
		for (int i = 25; i >= 0; --i) {
			f[s[i] - 'a'] = 1;
			for (int j = (s[i] - 'a' + 1); j < 26; ++j) if (f[j]) {
				s[i] = char(j + 'a'), pos = i;
				break;
			}
			if (~pos) break;
		}
		if (~pos) {
			s.resize(pos + 1);
			cout << s << '\n';
		}
		else cout << -1 << '\n';
	}
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();
		int D = sc.nextInt();
		
		sc.close();
		
		while(true) {
			C -= B;
			
			if (C <= 0) {
				System.out.println("Yes");
				break;
			}
			
			A -= D;
			
			if (A <= 0) {
				System.out.println("No");
				break;
			}
		}
	}

}


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

const int MAXN = 205;
const int INF = 1000000000;

struct edge {
	int a, b, cap, flow;
};

int N, s, t, d[MAXN], ptr[MAXN], q[MAXN];
vector<edge> e;
vector<int> g[MAXN];

void add_edge (int a, int b, int cap) {
	edge e1 = { a, b, cap, 0 };
	edge e2 = { b, a, 0, 0 };
	g[a].push_back ((int) e.size());
	e.push_back (e1);
	g[b].push_back ((int) e.size());
	e.push_back (e2);
}

bool bfs() {
	int qh=0, qt=0;
	q[qt++] = s;
	memset (d, -1, N * sizeof d[0]);
	d[s] = 0;
	while (qh < qt && d[t] == -1) {
		int v = q[qh++];
		for (size_t i=0; i<g[v].size(); ++i) {
			int id = g[v][i],
				to = e[id].b;
			if (d[to] == -1 && e[id].flow < e[id].cap) {
				q[qt++] = to;
				d[to] = d[v] + 1;
			}
		}
	}
	return d[t] != -1;
}

int dfs (int v, int flow) {
	if (!flow)  return 0;
	if (v == t)  return flow;
	for (; ptr[v]<(int)g[v].size(); ++ptr[v]) {
		int id = g[v][ptr[v]],
			to = e[id].b;
		if (d[to] != d[v] + 1)  continue;
		int pushed = dfs (to, min (flow, e[id].cap - e[id].flow));
		if (pushed) {
			e[id].flow += pushed;
			e[id^1].flow -= pushed;
			return pushed;
		}
	}
	return 0;
}

int dinic() {
	int flow = 0;
	for (;;) {
		if (!bfs())  break;
		memset (ptr, 0, N * sizeof ptr[0]);
		while (int pushed = dfs (s, INF))
			flow += pushed;
	}
	return flow;
}

const int Maxn = 105;

int n, m;
int B[Maxn][Maxn];

void Solve(int col)
{
    N = n + n + 2; s = 0, t = N - 1;
    e.clear();
    for (int i = 0; i < N; i++)
        g[i].clear();
    for (int i = 0; i < n; i++)
        add_edge(0, i + 1, 1);
    for (int i = 0; i < n; i++)
        add_edge(1 + n + i, N - 1, 1);
    for (int i = 0; i < n; i++)
        for (int j = col; j < m; j++) {
            int id = (B[i][j] - 1) / m;
            add_edge(i + 1, 1 + n + id, 1);
        }
    assert(dinic() >= n);
    for (int i = 0; i < e.size(); i++)
        if (1 + n <= e[i].a && e[i].a < N - 1 &&
            1 <= e[i].b && e[i].b <= n && e[i].flow < e[i].cap) {
                int row = e[i].b - 1;
                int id = e[i].a - (1 + n);
                int pnt = col;
                while ((B[row][pnt] - 1) / m != id) pnt++;
                swap(B[row][col], B[row][pnt]);
            }
}

int main()
{
    scanf("%d %d", &n, &m);
    for (int i = 0; i < n; i++)
        for (int j = 0; j < m; j++)
            scanf("%d", &B[i][j]);
    for (int j = 0; j < m; j++)
        Solve(j);
    for (int i = 0; i < n; i++)
        for (int j = 0; j < m; j++)
            printf("%d%c", B[i][j], j + 1 < m? ' ': '\n');
    for (int j = 0; j < m; j++) {
        vector <int> tmp;
        for (int i = 0; i < n; i++)
            tmp.push_back(B[i][j]);
        sort(tmp.begin(), tmp.end());
        for (int i = 0; i < n; i++)
            B[i][j] = tmp[i];
    }
    for (int i = 0; i < n; i++)
        for (int j = 0; j < m; j++)
            printf("%d%c", B[i][j], j + 1 < m? ' ': '\n');
    return 0;
}


Measured memory_bytes: 952
#include <cstdio>
#include <iostream>
#include <cmath>
using namespace std;

int dx[] = {0,0,1,-1};
int dy[] = {1,-1,0,0};
char room[5][5] = {
	{1,1,1,1,1},
	{1,0,0,0,1},
	{1,0,0,0,1},
	{1,0,0,0,1},
	{1,1,1,1,1}
};

void solve(char n, double m[5][5] ){
	for( ; n>0 ; n-- ){
		double tmp[5][5] = {0};
		
		for(int y=1 ; y <= 3 ; y++ ){
			for(int x=1 ; x <= 3 ; x++ ){
				if( m[y][x] > 0.0 ){
					for(int i=0 ; i<4 ; i++ ){
						int mx = x + dx[i];
						int my = y + dy[i];
						if( room[my][mx] == 0 ){
							tmp[my][mx] += m[y][x]/4.0;
						}else{
							tmp[y][x] += m[y][x]/4.0;
						}
					}
					//m[y][x] = 0;
				}
			}
		}
		for(int y=1 ; y <= 3 ; y++ ){
			for(int x=1 ; x <= 3 ; x++ ){
				m[y][x] = tmp[y][x];
			}
		}
	}
}

int main(){
	char fx[256] = {0}, fy[256] = {0};
	int n;
	char s, t, b;
	
	for(int i=0;i<9;i++){
		fx[i+'A'] = i%3+1;
		fy[i+'A'] = i/3+1;
	}
	
	while( scanf("%d", &n) , n ){
		scanf(" %c %c %c ", &s, &t, &b);
		//cin >> s >> t >> b;
		double m[5][5] = {0};
		for(int i=1 ; i<=3 ; i++){
			for(int j=1 ; j<=3 ; j++){
				room[i][j] = 0;
				//m[i][j] = 0;
			}
		}
				
		room[ fy[b] ][ fx[b] ] = 1;
		m[ fy[s] ][ fx[s] ] = 1.0;
		
		solve( n , m );
		
		//debug( m );
		printf("%.9f\n" , m[ fy[t] ][ fx[t] ] );
	}
}

Measured memory_bytes: 0
N,K = map(int,input().split())
Data  = map(int,input().split())
Data2 = [0]*N
for idx,data in enumerate(Data):
    e = data * (data+1) / 2 / data
    Data2[idx] = e
#print(Data2)
sum1 = 0
for i in range(K):
    sum1 += Data2[i]
ans = sum1
for i in range(0,N-K):
    sum1 -= Data2[i]
    sum1 += Data2[i+K]
    if ans < sum1:
        ans = sum1
print(ans)

Measured memory_bytes: 23588
#include <iostream>
#include<cstdio>

using namespace std;

int main()
{
    char ltr[3][3];
    for(int i=0;i<3;i++)
    {
        for(int j=0;j<3;j++)
        {
            scanf("%c",&ltr[i][j]);
            if(ltr[i][j]=='\n')
            j--;
        }
    }
    printf("%c%c%c",ltr[0][0],ltr[1][1],ltr[2][2]);
    return 0;
}


Measured memory_bytes: 256
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, K, *A = map(int, read().split())

    print((N + K - 3) // (K - 1))

    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 20452
#include <iostream>
#include <vector>
#include <tuple>
#include <climits>
const int64_t UNVISITED = INT64_MIN;
const int64_t INF = INT64_MAX;
using namespace std;
using edges = vector<tuple<int,int,int64_t>>;
int64_t solve(const edges &g, int n){
  vector<int64_t> score(n,UNVISITED);
  score[0] = 0;
  for(int i = 0; i <= n; i++){
    bool update = false;
    //cout << i << endl;
    for(auto &e: g){
      auto &from   = get<0>(e);
      auto &to     = get<1>(e);
      auto &weight = get<2>(e);
      if(score[from] == UNVISITED) continue;
      if(score[from] + weight > score[to]){
        //cout << "update:" << to << ',' << score[to] << " to "<< score[from] + weight << endl;
        score[to] = score[from] + weight;
        if(to == n-1 && i == n){
          return INF;
        }
        update = true;
      }
    }
    if(not update)break;
  }
  return score[n-1];
}
int main(){
  int n,m;
  cin >> n >> m;
  edges g(m);
  for(int i = 0; i < m; ++i){
    int a,b;
    int64_t c;
    cin >> a >> b >> c;
    g.push_back(make_tuple(a-1,b-1,c));
  }
  auto ans = solve(g,n);
  if(ans == INF) cout << "inf" << endl;
  else cout << ans << endl;
}


Measured memory_bytes: 384
#!/usr/bin/python
# -*- coding: utf-8 -*-
import sys,collections,itertools,re,math,fractions,decimal,random,array,bisect,heapq

# decimal.getcontext().prec = 50
# sys.setrecursionlimit(10000)
# MOD = 10**9 + 7

def solve(f):
    a, b = f.read_int_list()

    n = 1
    ans = 0
    while n < b:
        n += a - 1
        ans += 1

    return ans


class Reader(object):
    def __init__(self, filename=None):
        self.file = open(filename) if filename is not None else None
        self.case = 1

    def __readline(self):
        return self.file.next().strip() if self.file else raw_input()

    def next_case(self):
        self.file.next()
        self.case += 1

    def read_int(self): return int(self.__readline())
    def read_float(self): return float(self.__readline())
    def read_long(self): return long(self.__readline())
    def read_decimal(self): return decimal.Decimal(self.__readline())
    def read_str(self): return self.__readline()

    def read_int_list(self): return map(int, self.__readline().split())
    def read_float_list(self): return map(float, self.__readline().split())
    def read_long_list(self): return map(long, self.__readline().split())
    def read_decimal_list(self): return map(decimal.Decimal, self.__readline().split())
    def read_str_list(self): return self.__readline().split()

if __name__ == '__main__':
    filename = sys.argv[1] if len(sys.argv) > 1 else None
    f = Reader(filename)
    if f.file:
        while True:
            print "Case #%d\n"%f.case, solve(f)
            try:
                f.next_case()
            except StopIteration:
                break
    else:
        print solve(f)


Measured memory_bytes: 4636
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <queue>
#include <vector>
#include <algorithm>
#include <map>

int H, W;
char map[20][20];
int dist_value;
int dist[20][20];

void initdist(){
  dist_value = 0;
  for (int i=0; i<H; i++){
    for (int j=0; j<W; j++){
      dist[i][j] = -1;
    }
  }
  return;
}

struct coord  {
  int x;
  int y;
};

int drow[4]={1,-1,0,0};
int dcolumn[4]={0,0,1,-1};
std::queue<coord > queue_next;
coord last;

void bfs(int start_i, int start_j){
  queue_next.push((coord){start_i,start_j});
  dist_value = 0;
  while(queue_next.size()){
    std::queue<coord > queue(queue_next);
    // clear queue_next
    std::queue<coord> empty;
    std::swap(queue_next, empty);
    while(queue.size()){
      int thisi = queue.front().x;
      int thisj = queue.front().y;
      last.x = thisi;
      last.y = thisj;
      queue.pop();
      dist[thisi][thisj]=dist_value;
      for(int k=0; k<4; k++){
        if (thisi+drow[k]>=0 && thisi+drow[k]<H && thisj+dcolumn[k]>=0 && thisj+dcolumn[k]<W){
          if (dist[thisi+drow[k]][thisj+dcolumn[k]]==-1 && map[thisi+drow[k]][thisj+dcolumn[k]]!='#'){
            queue_next.push((coord){thisi+drow[k], thisj+dcolumn[k]});
            dist[thisi+drow[k]][thisj+dcolumn[k]] = -2;
          }
        }
      }
    }
    dist_value++;
  }
  return;
}


int maxdist(){
  int ans = 0;
  for (int i=0; i<H; i++){
    for (int j=0; j<W; j++){
      if (map[i][j]=='#'){
        continue;
      }
      initdist();
      bfs(i,j);
      ans = std::max(ans,dist_value-1);
    }
  }
  return ans;
}

int main(){
  scanf("%d",&H);
  scanf("%d",&W);
  std::string S;
  
  for (int i=0; i<H; i++){
    std::cin >> S;
    for (int j=0; j<W; j++){
      map[i][j] = S[j];
    }
  }
  int ans = maxdist();
  printf("%d\n",ans);

  return 0;
}


Measured memory_bytes: 888
#include <stdio.h>
#include <vector>
using namespace std;

const long long mod = 1000000007;
long long inv[5050]={0,1},fact[5050]={1,1},ifact[5050]={1,1},cnt[5050]={1};

vector<int> G[5050];
int N,S[5050];

void go(int x, int l)
{
	S[x]++;
	for (auto y : G[x]) if (y != l){
		go(y,x);
		S[x] += S[y];
	}
}

int main()
{
	for (int i=2;i<5050;i++){
		inv[i] = (mod - mod / i) * inv[mod % i] % mod;
		fact[i] = fact[i-1] * i % mod;
		ifact[i] = ifact[i-1] * inv[i] % mod;
	}

	scanf ("%d",&N);

	for (int i=1;i<N;i++){
		int x,y; scanf ("%d %d",&x,&y);
		G[x].push_back(y);
		G[y].push_back(x);
	}
	go(1,0);

	for (int i=1;i<=N;i++){
		if (S[i] * 2 == N){
			printf ("%lld\n",fact[N/2]*fact[N/2]%mod);
			return 0;
		}
	}

	vector<int> sz;
	for (int i=1;i<=N;i++) if (N <= S[i] * 2){
		bool g = 1;
		for (int j : G[i]) if (S[i] > S[j] && S[j] * 2 > N) g = 0;
		if (g){
			sz.push_back(N - S[i]);
			for (int j : G[i]) if (S[i] > S[j]) sz.push_back(S[j]);
			break;
		}
	}

	for (auto s : sz){
		for (int j=N;j>=0;j--) if (cnt[j]){
			for (int k=1;k<=s;k++){
				long long seq = fact[s] * ifact[s-k] % mod;
				seq = seq * seq % mod * ifact[k] % mod;
				if (k & 1) cnt[j+k] = (cnt[j+k] + mod - cnt[j] * seq % mod) % mod;
				else cnt[j+k] = (cnt[j+k] + cnt[j] * seq % mod) % mod;
			}
		}
	}

	long long ans = 0;
	for (int j=0;j<=N;j++) ans = (ans + cnt[j] * fact[N-j]) % mod;
	printf ("%lld\n",ans);

	return 0;
}

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

#define F first 
#define S second

using namespace std;

typedef long long LL;
typedef pair<int, int> PII;

const int N = 200010, M = 2 * N;

int n;
PII a[N];

int main()
{
	scanf("%d", &n);
	for (int i = 0; i < n; i ++ ) scanf("%d%d", &a[i].S, &a[i].F);
	sort(a, a + n);
	
	int cur = 0, ok = 1;
	for (int i = 0; i < n; i ++ )
		if (cur + a[i].S <= a[i].F) cur += a[i].S;
		else
		{
			ok = 0;
			break;
		}
		
	if (ok) puts("Yes");
	else puts("No");
    return 0;
}

Measured memory_bytes: 1792
#include<stdio.h>
int main()
{
  int a,b;
  while(1)
    {
      scanf("%d%d",&a,&b);
      if(a==0&&b==0) break;
      if(a>b){
	printf("%d %d\n",b,a);
      }
      else
	{
	  printf("%d %d\n",a,b);
	}
    }
  return 0;
}

Measured memory_bytes: 600
import java.util.*;
import java.io.*;

public class Main {
	static int mod = (int) 1e9 + 7;
	static int DX[] = { -1, 0, 1, 0 }, DY[] = { 0, -1, 0, 1 };

	public static void main(String[] args) {
		FastScanner fs = new FastScanner(System.in);
		int n = fs.nextInt();
		int p[] = fs.nextIntArray(n);	
		int min = Integer.MAX_VALUE/2;
		int cnt = 0;
		for (int i=0;i<n;i++) {
			if(min<p[i])continue;
			else {
				min = p[i];
				cnt++;	
			}
		}
		System.out.println(cnt);
	}
}

//高速なScanner
class FastScanner {
	private BufferedReader reader = null;
	private StringTokenizer tokenizer = null;

	public FastScanner(InputStream in) {
		reader = new BufferedReader(new InputStreamReader(in));
		tokenizer = null;
	}

	public String next() {
		if (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				tokenizer = new StringTokenizer(reader.readLine());
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken();
	}

	public String nextLine() {
		if (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				return reader.readLine();
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken("\n");
	}

	public long nextLong() {
		return Long.parseLong(next());
	}

	public int nextInt() {
		return Integer.parseInt(next());
	}

	public double nextDouble() {
		return Double.parseDouble(next());
	}

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

	public long[] nextLongArray(int n) {
		long[] a = new long[n];
		for (int i = 0; i < n; i++)
			a[i] = nextLong();
		return a;
	}
}

Measured memory_bytes: 46156
def MI():return map(int,input().split())
def LI():return list(MI())

def factorization(n):
  arr=[]
  temp=n
  for i in range(2,int(n**0.5)+1):
    if temp%i==0:
      cnt=0
      while temp%i==0:
        cnt+=1
        temp//=i
      arr.append([i,cnt])      
  if temp!=1:arr.append([temp,1])
  if arr==[]:arr.append([n,1])
  return arr

def make_divisors(n):
  divisors=[]
  for i in range(1,int(n**0.5)+1):
    if n%i==0:
      divisors.append(i)
      if i!=n//i:
        divisors.append(n//i)
  divisors.sort()
  return divisors[1:]

n=int(input())

l=[]
for k in make_divisors(n):
  NN=int(n)
  while NN>=k:
    if NN%k==0:
      NN=NN//k
    else:
      NN=NN%k
  if NN==1:l+=k,

ll=(l+make_divisors(n-1))

print(len(ll))


Measured memory_bytes: 3188
package main

import "fmt"

func main() {
	var a, b, c string
	fmt.Scan(&a, &b, &c)
	t := byte('a')
	for {
		if t == 'a' {
			if len(a) == 0 {
				fmt.Println("A")
				return
			}
			t = a[0]
			a = a[1:]
		} else if t == 'b' {
			if len(b) == 0 {
				fmt.Println("B")
				return
			}
			t = b[0]
			b = b[1:]
		} else if t == 'c' {
			if len(c) == 0 {
				fmt.Println("C")
				return
			}
			t = c[0]
			c = c[1:]
		}
	}
}


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

using namespace std;

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

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S;
    cin >> S;
    ll N = S.length();
    FOR(i, N, 1) {
        bool e = true;
        REP(j, (N - 2 * i) / 2) {
            if (S[j] != S[(N - 2 * i) / 2 + j])
                e = false;
        }
        if (e) {
            cout << N - 2 * i << endl;
            break;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
#include <functional>
#include <cctype>

using namespace std;

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

int main()
{
	int N;
	vector<int> A;
	int temp;
	int c = 0;

	cin >> N;
	A.reserve(N);

	REP(i, N)
		cin >> A[i];

	for(int i = N - 1; i >= 0; --i) {
		for(int j = 0; j < i; ++j) {
			if(A[j] > A[j + 1]) {
				temp = A[j];
				A[j] = A[j + 1];
				A[j + 1] = temp;
				++c;
			}
		}
	}
	REP(i, N) {
		cout << A[i];
		(i == N - 1)?
			cout << endl : cout << ' ';
	}

	cout << c << endl;
	return 0;
}

Measured memory_bytes: 1196
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<cmath>
#include<utility>
#include<set>
#include<complex>
#define vi vector<int>
#define vvi vector<vector<int> >
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define CC puts("-------ok--------");
#define all(in) in.begin(), in.end()
#define bv vector<bool>
using namespace std;
typedef pair<int, int>PA;
using namespace std;
#define MAX  999999
int main (){
    // ?´???°??????sqrt(max)??§??????
    vector<bool>check(MAX+1);
    rep(i, MAX+1)
    check[i] = true;
    vector<int>Primenumber(MAX+1,0); //Primearray
    int counter =0;                  //Primearray counter;
    for(int i = 2; i<MAX+1;i++){
        if(check[i]){
            for(int j = 2;i*j<MAX;j++)
                check[i*j] = false;//?´???°??????Primearray???????´??????????????????°?????¨???false???
            Primenumber[counter] = i;
            counter++;
        }}
        int n;
        while(cin>>n,n){
            int ans=0;
            for(int k=n+1; k<=2*n;k++)
                if(check[k])ans++;
            cout<<ans<<endl;
        }
}

Measured memory_bytes: 6580
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using u32 = uint32_t;
using vi = vector<int>;    using vvi = vector<vi>;
using vb = vector<bool>;   using vvb = vector<vb>;
using vl = vector<ll>;     using vvl = vector<vl>;
using vd = vector<double>; using vvd = vector<vd>;

#define MAXC(c, x) (c = max(c, x))
#define MINC(c, x) (c = min(c, x))

#define REP(i,n) for(auto i = 0 * (n), i##_len = (n); i < i##_len; ++i)
#define ALL(c) (c).begin(), (c).end()
#define FOR(i,s,n) for(ll i=s, i##_len=(ll)(n); i<i##_len; ++i)
#define TEN(x) ((ll)1e##x)
const ll mod = TEN(9) + 7;

const ll INF = 1e9;
int main() {
#ifdef INPUT_FROM_FILE
	ifstream cin("sample.in");
	ofstream cout("sample.out");
#endif
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(50);

	ll n; cin >> n;
	vvl g(n);
	REP(i, n - 1) {
		ll a, b; cin >> a >> b;
		a--, b--;
		g[a].push_back(b);
		g[b].push_back(a);
	}

	vl c;
	ll c_mi = TEN(10);
	{
		function<ll(ll, ll)> dfs = [&](ll cur, ll prev) {
			ll ma = 0;
			for (ll next : g[cur]) if (next != prev) {
				MAXC(ma, dfs(next, cur) + 1);
			}
			return ma;
		};
		REP(i, n) {
			ll d = dfs(i, -1);
			if (d < c_mi) {
				c.clear();
			}
			if (d <= c_mi) {
				c.push_back(i);
				c_mi = d;
			}
		}
	}

	auto f = [&](vl c) {
		vvl depth;
		{
			function<void(ll, ll, ll)> dfs = [&](ll cur, ll prev, ll d) {
				if (depth.size() <= d) depth.push_back(vl());
				depth[d].push_back(cur);
				for (ll next : g[cur]) if (next != prev) {
					dfs(next, cur, d + 1);
				}
			};
			if (c.size() == 1) {
				for (ll next : g[c.front()]) dfs(next, c.front(), 0);
			}
			else {
				dfs(c[0], c[1], 0);
				dfs(c[1], c[0], 0);
			}
		}

		ll ans = 0, prev = 1;
		for (ll i = depth.size() - 1; i >= 0; --i) {
			vl sz;
			for (ll j = 0; j < depth[i].size(); ++j) {
				sz.push_back(g[depth[i][j]].size() - 1);
				if (g[depth[i][j]].size() == 1) ans++;
			}
			sort(ALL(sz));
			reverse(ALL(sz));
			REP(i, sz.size()) {
				ans += (sz.front() - sz[i]) * prev;
				if (sz[i] == 0 && sz.front() > sz[i]) ans--;
			}
			prev *= max(1ll, sz.front());
		}
		return pair<ll, ll>(depth.size() + (c.size() == 1), ans);
	};

	auto p = f(c);
	if (c.size() == 1) {
		for (ll next : g[c.front()]) {
			MINC(p, f({ c.front(), next }));
		}
	}

	cout << p.first << " " << p.second << endl;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <numeric>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <iterator>
#include <math.h>
#include <cmath>
#include <set>   
#include <bitset>
//#include <boost/math/common_factor_rt.hpp>

#define ll long long
using namespace std;
ll l = 1000000007;

int main()
{
	int n, k;
	cin >> n >> k;

	if (n % 2 == 0) {
		if (n / 2 >= k) {
			cout << "YES" << endl;
		}
		else {
			cout << "NO" << endl;
		}
	}
	else {
		if (n / 2 + 1 >= k) {
			cout << "YES" << endl;
		}
		else {
			cout << "NO" << endl;
		}
	}

	

}



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

const int N = (int) 2e6 + 10 ;
const int inf = (int) 2e9 ;

map< string , int > cnt ;

int main(){
//    freopen("in.txt" , "r" , stdin ) ;
    int n ; scanf("%d" , &n ) ;
    string s , last ;
    cin >> last ;
    cnt[last] = 1 ;
    int f = 1 ;
    for( int i = 2 ; i <= n ; i++ ) {
        cin >> s ;
        if( cnt[s] != 0 || last[ last.size() - 1 ] != s[0] ) {
            f = 0 ;
        }
        cnt[s] += 1 ;
        last = s ;
    }
    if( f == 1 ) printf("Yes\n") ;
    else printf("No\n") ;
    return 0 ;
}


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map.Entry;
import java.util.PriorityQueue;
import java.util.Scanner;

class Main {
    static final int MOD = 1000000007;
    static final int INF = 1 << 30;

    Main() {
        Scanner sc = new Scanner(System.in);
        long ans = 1;
        int N = sc.nextInt();
        int M = sc.nextInt();
        int[] sx = new int[N];
        int[] sy = new int[N];
        int[] cx = new int[M];
        int[] cy = new int[M];
        for(int i=0;i<N;i++){
            sx[i]=sc.nextInt();
            sy[i]=sc.nextInt();
        }
        for(int i=0;i<M;i++){
            cx[i]=sc.nextInt();
            cy[i]=sc.nextInt();            
        }
        for(int i=0;i<N;i++){
            int dist = Math.abs(sx[i]-cx[0])+Math.abs(sy[i]-cy[0]);
            int ck = 0;
            for(int j=1;j<M;j++){
                int nd = Math.abs(sx[i]-cx[j])+Math.abs(sy[i]-cy[j]);
                if(nd<dist){
                    ck=j;
                    dist=nd;
                }
            }
            System.out.println(ck+1);
        }
    }

    public static void main(String[] args) {
        new Main();
    }
}


Measured memory_bytes: 21972
open System

// prelude
let readStr () = stdin.ReadLine()

let read f = readStr() |> f
let reads f = readStr().Split() |> Array.map f

let pair = function
| [|a; b|] -> (a, b)
| _ -> failwith "owatta"

let triple = function
| [|a; b; c|] -> (a, b, c)
| _ -> failwith "owatta"

let readPair f g =
  let (a,b) = readStr().Split() |> pair
  (f a, g b)

let readTriple f g h =
  let (a,b,c) = readStr().Split() |> triple
  (f a, g b, h c)

let inc n = n + 1
let dec n = n - 1

let inline flip f a b = f b a
let rec fix f = fun x -> (f (fix f)) x

module Option =
  let getOr defaultValue = function
  | Some x -> x
  | None -> defaultValue

module Array =
  let modify (arr: _ []) i f =
    arr.[i] <- f arr.[i]

module Array2D =
  let modify (arr: _ [,]) i j f =
    arr.[i, j] <- f arr.[i, j]

// start
let A,B = readPair int int
printfn "%d" (A*B)

Measured memory_bytes: 30068
def main():
    N = int(input())
    W = [input() for _ in range(N)]
    p = W[0][-1]
    S = set(W)

    if len(W) != len(S):
        print("No")
        return

    del W[0]

    for w in W:
        if w[0] == p:
            p = w[-1]
        else:
            print("No")
            return

    print("Yes")


if __name__ == "__main__":
    main()

Measured memory_bytes: 3064
R = 1000000
p = [1]*R
p[0] = p[1] = 0
p[4::2] = [0 for i in range(4,R,2)]
for i in range(3,int(R**0.5)+1,2):
    if p[i]:
        p[2*i::i] = [0]*len(p[2*i::i])
while True:
    try:print sum(p[:int(raw_input())+1])
    except:break

Measured memory_bytes: 36972
#include <bits/stdc++.h>
#define pb push_back
#define ll long long
#define hell 1000000007
#define PI 3.14159265358979323846
using namespace std;
ll expo(ll base,ll p)
{
    if(p==0ll)
        return 1ll;
if(p%2==0)
    return expo((base*base)%hell,p/2);
else
    return (base*expo((base*base)%hell,p/2))%hell;
}
ll fac[1000005],inv[1000005];
void cal()
{
    fac[0]=1;
    for(ll i=1;i<=1000000;i++)
        fac[i]=(fac[i-1]*i)%hell;
    inv[1000000]=expo(fac[1000000],hell-2);
    for(ll i=99999;i>=0;i--)
        inv[i]=(inv[i+1]*(i+1))%hell;
}
ll ncr(ll n,ll r)
{
    return (((fac[n]*inv[r])%hell)*inv[n-r])%hell;
}
int main()
{
   ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t=1;
    //cin>>t;
    //int c=0;
    while(t--) {
     ll n,i,j,q,s=0,l,r;
     cin>>n;
     vector<ll> v1,v2;
     for(i=0;i<n;i++)
     {
         cin>>l>>r;
         v1.pb(l+r);
         v2.pb(l-r);
     }
     sort(v1.begin(),v1.end());
     sort(v2.begin(),v2.end());
     cout<<max(v1[n-1]-v1[0],v2[n-1]-v2[0]);
    }

}


Measured memory_bytes: 6684
#include <iostream>
#include <vector>
#include <cmath>
#include <queue>
#include <deque>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <unordered_map>
#include <iomanip>
#include <sstream>
#include <numeric>
using namespace std;
#define ll long long int
#define ld long double
#define vi vector<ll>
#define vvi vector<vi>
#define vs vector<string>
#define pi pair<ll,ll>
#define pb push_back
#define pf push_front
#define eb emplace_back
#define mp make_pair
#define fs first
#define se second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);
int main() {
    ll N,W;
    cin>>N>>W;
    vi dp(W+1,0);
    for(ll i=0;i<N;i++){
        ll wt,val;
        cin>>wt>>val;
        for(ll j=(W-wt);j>=0;j--){
            dp[j+wt] = max(dp[j+wt],dp[j]+val);
        }
    }

    ll answer = 0;
    for(ll i=0;i<=W;i++){
        answer = max(answer,dp[i]);
    }
    cout<<answer<<endl;
}




Measured memory_bytes: 1024
import numpy as np
n, C = map(int,input().split())
cha = [[0] for _ in range(C+1)]
stc = [list(map(int, input().split())) for _ in range(n)]
stc.sort()
result = np.zeros(2*10**5)
for s, t, c in stc:
    if cha[c] == s:
        result[2*s+1:2*t] += 1
    else:
        result[2*s-1:2*t] += 1
    cha[c] = t
print(int(max(result)))

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





int main() {
  int n,k;
  cin>>n>>k;
  int answer=0;
  
  for (int i=0;i<n;i++){
    int x;
    cin>>x;
    answer+=min(2*(x), 2*(k-x));
  }
  
  cout<<answer<<endl;
}

  













Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lvector vector<ll>
#define P pair<ll,ll> 
#define rep(i,n) for(ll (i)=0; (i)<(n); ++(i))
#define print(a) cout << (a) << endl

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n,a,ans=0;cin>>n;
  lvector v(9,0);
  rep(i,n) {
    cin>>a;
    a/=400;
    a=min(a,8ll);
    v[a]++;
  }
  rep(i,8) if(v[i]>0) ans++;
  ll mx=ans,mn=max(ans,1ll);
  if(v[8]>0) mx+=max(v[8],1ll);
  printf("%lld %lld\n",mn,mx);
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <tuple>
#include <queue>
using namespace std;

const long MAXV=1000000;

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

    vector<long> blacklist(MAXV+1,0);
    vector<long> exist(MAXV+1,0);
    vector<long> A(N, 0);
    for(long i=0;i<N;i++){
        cin >> A[i];
        if(!exist[A[i]]){
            for(long v=A[i]+A[i];v<=MAXV;v+=A[i]){
                blacklist[v]++;
            }
        }
        exist[A[i]]++;
    }


    long count=0;
    for(long i=0;i<N;i++){
        if(blacklist[A[i]] || exist[A[i]]>1) count++;
    }

    cout << N-count << endl;

    return 0;
}


Measured memory_bytes: 20416
#include <iostream>
#include <iomanip>
#include <string>
#include <stack>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <map>
#include <set>
#include <queue>
#include <list>
using namespace std;
using pii  = pair<int,int>;
using ll=long long;
using ld=long double;
#define pb push_back
#define mp make_pair
#define stpr setprecision
#define rep(i,n) for(ll i=0;i<(n);++i)
#define REP(i,a,b) for(ll i=(a);i<(b);++i)
#define crep(i) for(char i='a';i<='z';++i)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define ALL(x) (x).begin(),(x).end()
#define endl '\n'
long long gcd(long long a, long long b){return (b == 0 ? a : gcd(b, a%b));}
long long lcm(long long a, long long b){return a*b/gcd(a,b);}
constexpr ll MOD=1000000007;
constexpr ld EPS=10e-8;
template<typename T> istream& operator>>(istream& is,vector<T>& v){for(auto&& x:v)is >> x;return is;}
template<typename T,typename U> istream& operator>>(istream& is, pair<T,U>& p){ is >> p.first; is >> p.second; return is;}
template<typename T,typename U> ostream& operator>>(ostream& os, const pair<T,U>& p){ os << p.first << ' ' << p.second; return os;}
template<class T> ostream& operator<<(ostream& os, vector<T>& v){
    for(auto i=begin(v); i != end(v); ++i){
        if(i !=begin(v)) os << ' ';
        os << *i;
    }
    return os;
}

int main(){
    string S;
    cin >> S;
    rep(i,S.size()-1){
        if(S[i]=='A'&&S[i+1]=='C'){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
}

Measured memory_bytes: 256