akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <bitset>
#include <tuple>
#include <set>
#include <map>
#define range(i, r) for(int i=0;i<r;i++)
#define ranges(i, l, r) for(int i=l;i<r;i++)
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi std::vector<std::vector<int> >
#define vvl std::vector<std::vector<ll> >
#define MODs 1000000007;
#define MODn 1000000009;
typedef long long int ll;
using namespace std;

int main(int argc, char const *argv[]) {
  ll N, K, X=-1, Y=-1;
  std::cin >> N >> K;
  std::vector<ll> a(N);
  map<ll, ll> dic;
  std::vector<ll> num(N, 0);
  ll count=0;
  for(ll i=0;i<N;i++) {
    std::cin >> a[i];
    if(dic.find(a[i])==dic.end()){
      dic.insert(make_pair(a[i],count));
      num[count]=i;
      count++;
    }
  }
  std::vector<ll> last(N+1,0), last_itr(N+1,0);
  last[N]=-1;
  map<ll, ll> pre;
  for(ll i=N-1;i>=0;i--){
    if(pre.size()==0){
      pre.insert(make_pair(a[i],i));
      last[i]=a[i];
      last_itr[i]=i;
    }else if(pre.find(a[i])==pre.end()){
      pre.insert(make_pair(a[i],i));
      last[i]=a[i];
      last_itr[i]=i;
    }else{
      last[i]=last[(*pre.find(a[i])).second+1];
      last_itr[i]=last_itr[(*pre.find(a[i])).second+1];
      pre.erase(a[i]);
      pre.insert(make_pair(a[i],i));
    }
  }

  std::vector<ll> yy(N+1,0);
  std::vector<ll> dp(N+1,0);
  if(last[0]==-1){
    std::cout << '\n';
    return 0;
  }
  dp[0] = last[0];
  for(ll i=1;i<N+1;i++){
    dp[i] = last[num[(*dic.find(dp[i-1])).second]+1];
    yy[i] = num[(*dic.find(dp[i-1])).second]+1;
    if(dp[i]==-1){
      X = i+1;
      break;
    }
  }

  if(X==-1) return 0;


  map<ll, ll> ans;
  map<ll, ll> ans_itr;
  if(K%X==0){
    std::cout << '\n';
    return 0;
  }else{
    count=0;
    for(ll i=yy[K%X-1];i<N;i++){
      if(ans.size()==0){
        ans.insert(make_pair(a[i],count));
        ans_itr.insert(make_pair(count,a[i]));
        count++;
      }else if(ans.find(a[i])==ans.end()){
        ans.insert(make_pair(a[i],count));
        ans_itr.insert(make_pair(count,a[i]));
        count++;
      }else{
        ll target = (*ans.find(a[i])).second;
        for(ll j=count-1;j>=target;j--){
          ans.erase((*ans_itr.find(j)).second);
          ans_itr.erase(j);
          count--;
        }
      }
    }
    auto itr = ans_itr.begin();
    for(ll i=0;i<ans_itr.size();i++){
      std::cout << (*itr).second;
      if(i!=ans_itr.size()-1) std::cout  << " ";
      itr++;
    }
    std::cout << '\n';
  }
  return 0;
}


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

int main() {
	int c,p,q,r,i,j;
	string a,b,t,s;
	cin >> a >> c;
	for (i = 0; i < c; i++) {
		cin >> b;
		if (b == "print") {
			cin >> p >> q;
			cout << a.substr(p, q - p + 1)<<endl;
		}
		if (b == "reverse") {
			cin >> p >> q;
			t = a.substr(p, q - p + 1);
			for (j = 0; j < q - p + 1;j++) {
				a.replace(p+j, 1, t.substr(q - p - j,1));
			}
		}
		if (b == "replace") {
			cin >> p >> q >> s;
			a.replace(p, q - p + 1, s);
		}
	}
	return 0;
}

Measured memory_bytes: 3212
#define _USE_MATH_DEFINES
#include<iostream>
#include<string>
#include<queue>
#include<cmath>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<random>
#include<functional>
#include<algorithm>
#include<stack>
#include<cstdio>
#include<cstring>
#include<bitset>
#include<unordered_map>
#include<climits>
#include<fstream>
#include<time.h>
#include<cassert>

using namespace std;
typedef long long ll;
typedef long double ld;
#define all(a) (a).begin(),(a).end()
#define EPS (1e-13)
#define bit(n,k) ((n>>k)&1)
const ll Mod = 1e9 + 7;
const ll mod = 998244353;
struct H {
	ll x, y;
	bool operator<(const H& b) const {
		if (x != b.x) return x < b.x;
		return y < b.y;
	}
	bool operator>(const H& b) const {
		if (x != b.x) return x > b.x;
		return y > b.y;
	}
	bool operator==(const H& b) const { return x == b.x && y == b.y; }
	bool operator!=(const H& b) const { return (*this) != b; }
};
struct P {
	ll pos, cost;
	bool operator<(const P& b) const { return cost < b.cost; }
	bool operator>(const P& b) const { return cost > b.cost; }
};
struct B {
	ll to, cost;
};
struct E {
	ll from, to, cost;
	bool operator<(const E& b) const { return cost < b.cost; }
	bool operator>(const E& b) const { return cost > b.cost; }
};
template<typename T, typename U>
void chmin(T& a, U b) {
	if (a > b) a = b;
}
template<typename T, typename U>
void chmax(T& a, U b) {
	if (a < b) a = b;
}
template<typename T>
T max_0(T a) {
	if (a < 0) return 0;
	return a;
}
template<typename T>
T min_0(T a) {
	if (a > 0) return 0;
	return a;
}
ll read() {
	ll u;
	ll k = scanf("%lld", &u);
	return u;
}
ll gcd(ll i, ll j) {
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcd(j % i, i);
}
ll mod_pow(ll x, ll n, ll p) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res * x % p;
		x = x * x % p;
		n >>= 1;
	}
	return res;
}//x^n%p
ll bitcount(ll x) {
	int sum = 0;
	for (int i = 0; i < 20; i++)
		if ((1ll << i) & x) sum++;
	return sum;
}
/*ll fact_[200000];
ll comb(ll x, ll y, ll mod = Mod) {
	if (!fact_[0]) {
		fact_[0] = 1;
		for (int i = 1; i < 200000; i++) {
			fact_[i] = fact_[i - 1] * i % mod;
		}
	}
	if (x < y) return 0;
	return mod_pow(fact_[x], mod, mod) *
		mod_pow(fact_[x - y], mod - 2, mod) % mod *
		mod_pow(fact_[y], mod - 2, mod) % mod;
}//xCy*/
const ll Inf = 3023372036854775807;
const int inf = 1500000000;
#define int long long
//----------------------------------------------------
signed main() {
	if (read() + read() + read() >= 22) cout << "bust\n";
	else cout << "win\n";
}

Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define pb push_back
typedef long long ll;
const int INF = 100100100;
const int MOD = (int)1e9 + 7;

int main()
{
  ll n, k, sum = 0;
  cin >> n >> k;
  vector<ll> h(n);
  rep(i, n)
  {
    cin >> h.at(i);
    sum += h.at(i);
  }
  sort(h.begin(), h.end(), greater<ll>());
  rep(i , min(k,n) )
  {
    sum -= h.at(i);
  }
  cout << sum << endl;
}

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

int calc(int a) { return a * (a - 1) / 2; }

int main() {
  ios_base::sync_with_stdio(false), cin.tie(NULL);

  int n;
  cin >> n;
  vector<int64_t> a(n + 1);
  uint64_t ans = 0;
  unordered_map<uint64_t, int> cnt;
  cnt[0] = 1;
  for (int i = 0; i < n; ++i) {
    int t;
    cin >> t;
    a[i + 1] = a[i] + t;
    ans += cnt[a[i + 1]];
    cnt[a[i + 1]]++;
  }
  cout << ans << "\n";
}


Measured memory_bytes: 10056
// Aizu Vol0 0027: What day is today?
// 2017.7.28

#include <stdio.h>

int dayOfWeek(int year, int month, int day)
{
	if (month == 1 || month == 2) {
		year--;
		month += 12;
	}
	return (year + year / 4 - year / 100 + year / 400
		+ (13 * month + 8) / 5 + day) % 7;
}

int main()
{
	int m, d;
	char *day[7] = {
		"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"
	};
	
	while (1) {
		scanf("%d%d", &m, &d);
		if (m == 0 || d == 0) break;
		puts(day[dayOfWeek(2004, m, d)]);
	}
	return 0;
}

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    
    string s0,t,s1;
    cin >> s0 >> t;
    
    vector<string> arr;
    vector<string> ans;
    
    if(s0.size() < t.size()) cout << "UNRESTORABLE" << endl;
    else {
        for(int i = 0 ; i <= (s0.size() - t.size()); i++){
            s1 = s0;
            for(int j = 0; j < t.size(); j++){
                s1[i + j] = t[j];
            }
            for(int k = 0; k < s1.size(); k++){
                if(s1[k] == '?') s1[k] = 'a';
            }
            arr.push_back(s1);
        }
        
        for(int i = 0 ; i < arr.size(); i++){
            bool flag = true;
            for(int j = 0 ; j < s0.size(); j++){
                if(arr[i][j] == s0[j]);
                else if(s0[j] == '?');
                else flag = false;
            }
            if(flag) ans.push_back(arr[i]);
        }
        
        sort(ans.begin(), ans.end());
        
        if(ans.size() == 0) cout << "UNRESTORABLE" << endl;
        else cout << ans[0] << endl;
    }
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
from collections import Counter
def main():
    N, P = map(int, input().split())
    S = list(map(int, input().rstrip("\r\n")))
    S.reverse()
    ans = 0
    if P == 2 or P == 5:
        for i in range(N):
            if S[i] % P == 0:ans += N-i
    else:
        A = [0] * N
        tenpow = 1
        for i in range(N):
            A[i] = (S[i]*tenpow) % P
            tenpow *= 10
            tenpow %= P
        D = [0] * (N+1)
        for i in range(N):
            D[i+1] = (D[i] + A[i]) % P
        c = Counter(D)
        for v in c.values():
            ans += v*(v-1)//2
    print(ans)
if __name__ == "__main__":
    main()

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

using namespace std;
using ll=int64_t;
using pii = pair<int, int>;
using pli = pair<ll, int>;
using mii = map<int, int>;
using vi=vector<int>;
using vii=vector<vi>;
using vl=vector<ll>;
using vll=vector<vl>;
using tpi=tuple<int, int, int>;

int main() {
    using spi=multiset<pii>;

    int N;
    cin >> N;

    vi v(N + 1);
    for (auto i = 1; i <= N; i++) {
        int p;
        cin >> p;
        v[p] = i;
    }

    spi s;

    s.emplace(0, 0);
    s.emplace(0, 0);
    s.emplace(N + 1, N + 1);
    s.emplace(N + 1, N + 1);

    ll ans = 0;
    for (auto i = N; i >= 1; i--) {
        auto iter = s.emplace(v[i], i);

        auto r1 = next(iter, 1);
        auto r2 = next(iter, 2);
        auto l1 = prev(iter, 1);
        auto l2 = prev(iter, 2);
        ll tmp = ((*r2).first - (*r1).first) * (v[i] - (*l1).first);
        ans += i * tmp;
        tmp = ((*l1).first - (*l2).first) * ((*r1).first - v[i]);
        ans += i * tmp;
    }

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


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

int h,w;

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


int main(void){
	cin >> h >> w;
	char board[h+2][w+2];
	for(int i = 0; i < h+2; ++i){
		for(int j = 0; j < w+2; ++j){
			board[i][j] = '.';
		}
	}
	for(int i = 0; i < h; ++i){
		for(int j = 0; j < w; ++j){
			cin >> board[i+1][j+1];
		}
	}


	for(int i = 0; i < h; ++i){
		for(int j = 0; j < w; ++j){
			if(board[i][j]=='#'){
				int k = 0;
				for(k = 0; k < 4; k++){
					if(board[i+dx[k]][j+dx[k+1]]=='#')	break;
				}
				if(k==4){
						cout << "No" << endl;
						return 0;
				}
			}
		}
	}
	cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc=new Scanner(System.in);
		
		int n=sc.nextInt();		//夏休みの日数
		int m=sc.nextInt();		//夏休みの宿題の数
		int count=0;
		
		for(int i=0;i<m;i++) {
			int m1=sc.nextInt();	//1番目の宿題
			count=count+m1;
		}
		
		count=n-count;
		
		if(count>=0) {
			System.out.println(count);
		}else {
			System.out.println(-1);
		}
		
		sc.close();
	}

}

Measured memory_bytes: 39224
#include<iostream>//itp14c.cpp
using namespace std;
int main(void)
{
	int a,b;
	char op;
	while(1){
		cin>>a>>op>>b;
		if(op=='?') break;
		if(op=='+') cout<<a+b<<endl;
		else if(op=='-') cout<<a-b<<endl;
		else if(op=='*') cout<<a*b<<endl;
		else cout<<a/b<<endl;
	}
	return 0;
}	


Measured memory_bytes: 3088
import java.util.*;

class Main{
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		int[][] isExist = new int[4][13];
		char ch;
		
		for(int i = 0; i < 4; i++)
			for(int j = 0; j < 13; j++)
				isExist[i][j] = 0;
		
		int n = sc.nextInt();
		
		for(int i = 0; i < n; i++){
			String mark = sc.next();
			int num = sc.nextInt();
			
			if(mark.equals("S"))
				isExist[0][num-1] = 1;
			else if(mark.equals("H"))
				isExist[1][num-1] = 1;
			else if(mark.equals("C"))
				isExist[2][num-1] = 1;
			else
				isExist[3][num-1] = 1;
		}
		
		for(int i = 0; i < 4; i++){
			if(i == 0)
				ch = 'S';
			else if(i == 1)
				ch = 'H';
			else if(i == 2)
				ch = 'C';
			else
				ch = 'D';
			
			for(int j = 0; j < 13; j++){
				if(isExist[i][j] == 0)
					System.out.println(ch + " " + (j + 1));
			}
		}
	}
}

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


int main() {
  int k;
  cin >> k;
  int ans = (k/2) * (k/2);
  if(k%2) ans = (k/2) * (k-k/2);
  cout << ans << endl;
  return 0;
  
}

Measured memory_bytes: 256
import java.util.*;

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

            HashMap<Integer, Integer> map = new HashMap<>();
            Queue<int[]> que = new ArrayDeque<int[]>();
            int[] state = {0,1,2,3,4,5,6,7,0};
            int[] give = new int[8];
            map.put(key(state), 0);
            que.add(state.clone());
                while (que.size() > 0) {
                    state = que.remove();
                    if (state[8] != 0 && state[8] != 4) {
                        int[] temp = state.clone();
                        temp[temp[8]] = temp[temp[8] - 1];
                        temp[temp[8] - 1] = 0;
                        temp[8] -= 1;
                        if (!map.containsKey(key(temp))) {
                            map.put(key(temp), map.get(key(state)) + 1);
                            que.add(temp.clone());
                        }
                    }
                    if (state[8] != 3 && state[8] != 7) {
                        int[] temp = state.clone();
                        temp[temp[8]] = temp[temp[8] + 1];
                        temp[temp[8] + 1] = 0;
                        temp[8] += 1;
                        if (!map.containsKey(key(temp))) {
                            map.put(key(temp), map.get(key(state)) + 1);
                            que.add(temp.clone());
                        }
                    }
                    if (state[8] < 4) {
                        int[] temp = state.clone();
                        temp[temp[8]] = temp[temp[8] + 4];
                        temp[temp[8] + 4] = 0;
                        temp[8] += 4;
                        if (!map.containsKey(key(temp))) {
                            map.put(key(temp), map.get(key(state)) + 1);
                            que.add(temp.clone());
                        }
                    } else {
                        int[] temp = state.clone();
                        temp[temp[8]] = temp[temp[8] - 4];
                        temp[temp[8] - 4] = 0;
                        temp[8] -= 4;
                        if (!map.containsKey(key(temp))) {
                            map.put(key(temp), map.get(key(state)) + 1);
                            que.add(temp.clone());
                        }
                    }
                }
        while (sc.hasNext()) {
            for (int i = 0; i < 8; i++) {
                give[i] = sc.nextInt();
            }
            System.out.println(map.get(key(give)));
        }
    }


    public static int key(int[] a) {
        int j = 1, key = 0;
        for (int i = 0; i < 8; i++) {
            key += a[i] * j;
            j *= 10;
        }
        return key;
    }

}



Measured memory_bytes: 44888
#include<stdio.h>
#define M 500001
int h;

void maxHeapify(int *A,int i){
  int l,r,largest;
  l=2*i;
  r=2*i+1;
  if(l<=h && A[l]>A[i])
    largest=l;
  else
    largest=i;
  if(l<=h && A[r]>A[largest])
    largest = r;
  if(largest != i){
    int tmp;
    tmp=A[i];
    A[i]=A[largest];
    A[largest]=tmp;
    maxHeapify(A,largest);
  }
}

void buildMaxHeap(int *A){
  for(int i=h/2;i>0;i--) maxHeapify(A,i);
}

int main(){
  int i,heap[M];
  scanf("%d",&h);
  for(i=1;i<=h;i++)
    scanf("%d",&heap[i]);
  buildMaxHeap(heap);
  for(i=1;i<=h;i++)
    printf(" %d",heap[i]);
  printf("\n");
  return 0;
}



Measured memory_bytes: 3672
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

vector<ll>a,b;
int main() {
	ll n,m;
	cin>>n>>m;
	for(ll i=0;i<m;i++){
		ll x;
		cin>>x;
		a.push_back(x);
	}
	sort(a.begin(),a.end());
	for(ll i=0;i<m-1;i++){
		ll now=a[i+1]-a[i];
		b.push_back(now);
	}
	sort(b.begin(),b.end());
	ll sum=m-n;
	ll ans=0;
	for(ll i=0;i<sum;i++){
		ans+=b[i];
	}
	cout <<ans;
	// your code goes here
	return 0;
}

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

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

Measured memory_bytes: 4004
import java.io.*;
public class Main {
	
	public static void main(String[] args) throws IOException {
		int a, b, c, sum = 0;

		String[] str = new BufferedReader(new InputStreamReader(System.in)).readLine().split("\\s+");
		
		a = Integer.parseInt(str[0]);
		b = Integer.parseInt(str[1]);
		c = Integer.parseInt(str[2]);
				
		for (int i = a; i <= b; i++) sum += c %i == 0 ? 1 : 0;
				
		System.out.println(sum);
	}
}

Measured memory_bytes: 24548
a = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51}
z = io.read("*n")
print(a[z])


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

template<typename T> void drop(const T &x){cout<<x<<'\n';exit(0);}

const long long mod = 998244353;

void milkshake() {
  int n, k;
  cin >> n >> k;
  vector<int> l(k), r(k);
  for(int i = 0; i < k; i++) {
    cin >> l[i] >> r[i];
  }
  vector<int> dp(n+1);
  vector<int> dps(n+1);
  dp[1] = dps[1] = 1;
  for(int i = 2; i <= n; i++) {
    for(int j = 0; j < k; j++) {
      int li = i - r[j];
      li = max(li, 1);
      int ri = i - l[j];
      if(ri < 1) continue;
      dp[i] = ((__int64_t)dp[i] + dps[ri] - dps[li-1]) % mod;
    }
    dps[i] = ((__int64_t)dps[i-1] + dp[i]) % mod;
  }
  cout << (dp[n] + mod) % mod << '\n';
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int T=1;
  //cin >> T;
  while(T--) milkshake();

  return 0;
}


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

int main() {
	string s;
	char c[26];
	bool a=true;
	for(int i=0;i<26;i++) c[i]=0;
	cin>>s;
	for(int i=0;i<26;i++) c[i]=s[i];
	for(int i=0;i<26;i++){
	    if(c[i]!=0){
	        for(int j=0;j<i;j++){
	            if(c[i]==c[j]) a=false;
	        }
	    }
	}
	if(a) cout<<"yes"<<endl;
	else cout<<"no"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
#define all(v) (v).begin(), (v).end()

const ll m = 1000000000000000000;
#define debug(x) cout<<#x<<" = "<<(x)<<endl

#define debug2(x,y) cout<<"("<<#x<<","<<#y<<") = ("<<(x)<<","<<(y)<<")\n"

int main(){
  int N;cin>>N;
  ll ans = 1;
  vector<ll> A(N);
  vector<double> B(N);
  for(int i=0; i<N; i++){
    cin>>A[i];
    B[i] = log10(A[i]);
  }
  if(find(all(A), 0) != A.end()){
    cout<<0<<endl;
    return 0;
  }
  double logans = 0;
  for(int i=0; i<N; i++){
    ans *= A[i];
    logans += B[i];
  }
  if(logans > 18){
    //cout<<"logans"<<endl;
    cout<<-1<<endl;
    return 0;
  }
  if(ans > m){
    cout<<-1<<endl;
    return 0;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 4780
#include<bits/stdc++.h>
#define itn int
#define ll long long
#define ri register itn
using namespace std;
char a[50005];
int bj;
int main(){
//freopen(".in","r",stdin);
//freopen(".out","w",stdout);
//ios::sync_with_stdio(0);cin.tie(0);
gets(a+1);
int s=strlen(a+1);
for(int i=1;i<=s;i++){
	if(a[i]=='C')
	bj=1;
	if(a[i]=='F'&&bj==1){
		cout<<"Yes";
		return 0;
	}
}
	cout<<"No";
	return 0;

return 0;
}


Measured memory_bytes: 256
import sys, os

f = lambda:list(map(int,input().split()))
if 'local' in os.environ :
    sys.stdin = open('./input.txt', 'r')

def solve():
    n , m = f()
    cnt = min(n*2, m)
    ans = cnt//2
    remain = m - ans*2


    print(ans + remain//4)

solve()


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


def main():
    n, m, d = map(int, raw_input().split())
    if d == 0:
        unit = n
    else:
        unit = (d - 1) * 2 + (n - (d - 1) * 2 - 1) * 2
    print unit * 1.0 / n / n * (m - 1)


if __name__ == '__main__':
    main()


Measured memory_bytes: 28012
#include<bits/stdc++.h>
#define ll long long
#define eps 1e-8
#define INF 0x3f3f3f3f
#define pb push_back
#define endl '\n'
#define IO ios::sync_with_stdio(false)
using namespace std;
const ll maxn = 1e6 + 5;
const ll mod = 1e9 + 7;
ll a,b,c,n,m,t,k,num[maxn];
ll q,sum[maxn];
string str;
int main(){
    IO;
    cin >> n;
    for(int i = 1; i <= n; i++)
        cin >> num[i];
    ll g = num[1];
    for(int i = 2; i <= n; i++)
        g ^= num[i];
    for(int i = 1; i <= n; i++)
        cout << (num[i] ^ g) << " ";
    return 0;
}


Measured memory_bytes: 5148
#include <iostream>
#include <map>

using ll = long long int;

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

	ll a[200010];
	for (int i = 0; i < n; ++i)
		std::cin >> a[i];

	std::map<int, int> mapa1;
	std::map<int, int> mapa2;
	for (int i = 0; i < n; ++i) {
		++mapa1[(i+1) - a[i]];
	}

	ll ans = 0;
	for (int i = 0; i < n; ++i) {
		ans += mapa1[(i+1) + a[i]];
	}

	std::cout << ans;
}

Measured memory_bytes: 21992
#include  <iostream>
#include  <stdio.h>
#include <algorithm>
using namespace std;
#include <vector>
#define rep(i,n) for (int i = 0; i < (n) ; i++)
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define ll long long
#define ull unsigned long long
#define vint vector<int>
#define vll vector<ll>

#include <math.h>
//#include <stack>
//#include <queue>

/*
int standerd = int(pow(10.0,9.0)) + 7;
*/
string ans_Yes = "Yes"; 
string ans_No = "No"; 
string ans_yes = "yes"; 
string ans_no = "no"; 

#define MAXV 1000000

ll VALM[MAXV]={};
ll VALP[MAXV]={};
ll C;
ll N;
ll M;
ll K;

int main(){

    cin >> N;
    ll H[N+1];
    for( int ni = 1 ; ni <=N ; ni++ ){
        ll tmp;
        cin >> tmp;
        H[ni]=tmp;
    }

    ll cnt=0;
    for( int ni = N ; ni >=1 ; ni-- ){
        ll hi = H[ni];
        if(hi<MAXV){
            if(ni+hi<MAXV){
                VALP[ni+hi]++;
                cnt+=VALM[ni+hi];
            }
            if(ni-hi>=0){
                VALM[ni-hi]++;
            }
        }
    }

    cout << cnt << endl;
    

}

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

long long n;
vector<int> a, cnt, dep;
vector<vector<int>> memo;
queue<int> qu;

int main() {
  cin >> n;
  a.resize(n);
  cnt.assign(n, 0);
  dep.assign(n, 1);
  memo.resize(n);
  for (int i = 1; i < n; ++i) {
    cin >> a[i];
    ++cnt[--a[i]];
  }
  for (int i = 1; i < n; ++i)
    if (cnt[i] == 0) qu.push(i);
  int res = 1;
  while (qu.size()) {
    int now = qu.front();
    qu.pop();
    sort(memo[now].begin(), memo[now].end(), greater<int>());
    int len = memo[now].size(), nmax = 1;
    for (int i = 0; i < len; ++i) nmax = max(nmax, memo[now][i] + i + 1);
    dep[now] = nmax;
    res = max(res, dep[now]);
    memo[a[now]].push_back(nmax);
    if (--cnt[a[now]] == 0) qu.push(a[now]);
  }
  cout << res - 1 << endl;

  return 0;
}


Measured memory_bytes: 6912
#include<iostream>
#include<vector>
#include<math.h>
#include<map>
#include<queue>
#include<algorithm>
#include<functional>
using namespace std;
#define INF int(1e9)
#define N 100000
#define MP make_pair
typedef pair<int, int> P;
typedef pair<pair<P, P>, P>PP;
int n, a, b;
P *mia, *mib;
P seg1[4 * (2 * N + 1)], seg2[4 * (2 * N + 1)];
priority_queue<PP, vector<PP>, greater<PP> > pq;

void init(P aa[], int nn)
{
	n = 1;
	while (n < nn) n *= 2;

	for (int i = 0; i < n * 2 - 1; i++)
		aa[i] = MP(INF,INF);
}


void update(P aa[], int k, int c, int nn)
{
	int num = k;
	k += nn - 1;
	aa[k] = MP(c, num);
	int cc = nn;
	while (k != 0)
	{
		k = (k - 1) / 2;
		if (aa[k].first <= c)
			break;
		aa[k] = MP(c, num);
	}
}

P* query(int s, int e, int k, int l, int r, P aa[])
{
	if (r <= s || l >= e) return NULL;
	if (r <= e && s <= l) 
	{
		return aa + k;
	}
	else
	{
		P* vl = query(s, e, k * 2 + 1, l, (l + r) / 2, aa);
		P* vr = query(s, e, k * 2 + 2, (l + r) / 2, r, aa);
		if (vl == NULL)
		{
			if (vr == NULL)
			{
				return NULL;
			}
			else
			{
				return vr;
			}
		}
		if (vr == NULL)
		{
			return vl;
		}
		return *vl < *vr ? vl : vr;
	}
}
bool solve2(int s, int e)
{
	if (e - s <= 0)
	{
		return false;
	}
	if (s % 2) 
	{
		mia = query(s, e, 0, 0, n, seg2);
		if ((*mia).first == INF)
		{
			return false;
		}
		mib = query((*mia).second, e, 0, 0, n, seg1);
	}
	else
	{
		mia = query(s , e, 0, 0, n, seg1);
		if ((*mia).first == INF)
		{
			return false;
		}
		mib = query((*mia).second, e, 0, 0, n, seg2);
	}
	return true;
}

void solve()
{
	
	if (pq.empty())
	{
		return;
	}
	cout << pq.top().first.first.first << " " << pq.top().first.second.first << " ";
	int s = pq.top().second.first, e = pq.top().second.second, se = pq.top().first.first.second, es = pq.top().first.second.second;
	pq.pop();
	if (solve2(s, se))
	{
		pq.push(MP(MP(*mia, *mib), MP(s, se)));
	}
	if (solve2(se + 1, es))
	{
		pq.push(MP(MP(*mia, *mib), MP(se + 1, es)));
	}
	if (solve2(es + 1, e))
	{
		pq.push(MP(MP(*mia, *mib), MP(es + 1, e)));
	}
	solve();
}

int main() 
{
	cin >> n;
	int nn = n;
	init(seg1, n);
	init(seg2, n);
	for (int i = 0; i < nn; i+=2)
	{
		cin >> a >> b;
		update(seg1, i, a, n);
		update(seg2, i + 1, b, n);
	}
	if (solve2(0, n))
	{
		pq.push(MP(MP(*mia, *mib), MP(0, n)));
	}
	solve();
	cout << endl;
}

Measured memory_bytes: 25844
#include <iostream>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <string>
#include <algorithm>
using namespace std;
struct Ques {
   bool ac;
   int waCount;
};

int main() {
    int N, K, M;
    cin >> N >> M;
    
    map<int, Ques> m;

    for (int i= 0; i < M; i++) {
        int p; 
        cin >> p;
        string s;
        cin >> s;

        if (m.find(p) == m.cend()) {
            Ques q;
            q.ac = false;
            q.waCount = 0;
            m.insert(pair<int, Ques>(p, q));
        }
        if (!m[p].ac) {
           if(s == "WA") m[p].waCount++;
           else m[p].ac = true;
        }
    }

    int ac = 0;
    int wa = 0;
    for (auto ite = m.cbegin(); ite != m.cend(); ite++) {
        if (ite->second.ac) {
            ac++;
            wa += ite->second.waCount;
        }
    }

    cout << ac << ' ' << wa << endl;  
    return 0;
}


Measured memory_bytes: 6528
#include<iostream>
#include<algorithm>
#include<math.h>
#include<cstdio>
#include<ctype.h>
#include<stdio.h>
#include<set>
#include<vector>
#include<map>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<numeric>
#include<string>
using namespace std;
typedef long long ll;
ll prime(ll x) {
	ll i;
	if (x < 2)return 0;
	else if (x == 2) return 1;
	if (x % 2 == 0) return 0;
	for (i = 3; i*i <= x; i += 2) {
		if (x%i == 0) return 0;
	}
	return 1;
}
ll gcd(ll a, ll b) {
	if (a<b) { return gcd(b, a); }
	else if (a%b) { return gcd(b, a%b); }
	else { return b; }
}

ll MOD = 1000000007;
int main() {
	ll N;
	cin >> N;
	ll A[N + 100];
	ll cnt = 0;
	for (ll i = 0; i < N; i++) {
		cin >> A[i];
		if (A[i] % 2 == 1) {
			cnt++;
		}
	}
	if (cnt % 2 == 0)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;
	}
	

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define ll          long long int
#define pb          push_back
#define pll         pair<ll,ll>
#define pq          priority_queue
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define mod         1000000007
#define inf         INT_MAX
#define vl          vector<ll>
#define vvl         vector<vector<ll>>
#define F           first
#define S           second
#define db          double
#define sz(x)       (ll)x.size()
#define fix(n)      cout<<fixed<<setprecision(n)
#define rep(i,a,b)  for(ll i=a;i<b;i++)

const int N=3005;

ll n,a[N];
ll dp[N][N][2];

ll f(ll i,ll j,ll t)
{
    if(i>j) return 0;
    if(i==j) return (t==0)?a[i]:(-1*a[i]);
    if(dp[i][j][t]) return dp[i][j][t];
    if(t==0) dp[i][j][t]=max(a[i]+f(i+1,j,1),a[j]+f(i,j-1,1));
    else dp[i][j][t]=min(f(i+1,j,0)-a[i],f(i,j-1,0)-a[j]);
    return dp[i][j][t];
}


void solve()
{
    cin>>n;
    rep(i,1,n+1)cin>>a[i];
    ll ans=f(1,n,0);
    cout<<ans;
}

int main()
{
    ll T=1;
    //cin>>T;
    while(T--)
        solve();
    return 0;
}


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

int main() {
    int h, w;
    cin >> h >> w;
    vector<string> c(h);

    for (int i = 0; i < h; i++) {
        cin >> c[i];
        cout << c[i] << endl;
        cout << c[i] << endl;
    }

    return 0;
} 

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

constexpr int P = 998244353;

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

    int n, s;
    cin >> n >> s;
    
    int dp[3001] = {};
    dp[0] = 1;

    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;

        for (int j = s; j >= a; j--) {
            dp[j] *= 2;
            if (dp[j] >= P) dp[j] -= P;
            dp[j] += dp[j - a];
            if (dp[j] >= P) dp[j] -= P;
        }
        for (int j = a - 1; j >= 0; j--) {
            dp[j] *= 2;
            if (dp[j] >= P) dp[j] -= P;
        }
    }

    cout << dp[s] << endl;

    return 0;
}

Measured memory_bytes: 3668
#!/usr/bin/python3
# -*- coding: utf-8 -*-


import numpy as np
from itertools import accumulate


N, K = [int(x) for x in input().split()]

n = range(N+1)
# print((n + 10**100)%(10**9+7))

if K > N:
    print(1)
    exit(0)

combi = np.array(range(N+1-(K-1)))+K
S = 0

minsum = list(accumulate(n))

maxsum = list(accumulate(n[::-1]))

for c in combi:
    # S += len(set(np.sum(np.array(list(itertools.combinations(n, c))),axis=1)))
    # itertools.combinations(n, c)
    min_num = (minsum[c-1]-1) % 1000000007
    max_num = maxsum[c-1] % 1000000007
    # print(min_num, max_num)
    if (max_num-min_num) < 0:
        S += ((max_num-min_num) + 1000000007)
    else:
        S += (max_num-min_num)
    S %= 1000000007
print(S)



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

using namespace std;

typedef long long ll;

int main () {
  int a, b;
  cin >> a >> b;
  if (b == 1) {
	  cout << 0;
  }
  else {
	  int r = a;
	  int ans = 1;
	  while (r < b) {
		  ++ans;
		  r += a - 1;
	  }
	  cout << ans;
	}
}


Measured memory_bytes: 384
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <iterator>
#include <assert.h>
#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 INF 2140000000
const long long MOD = 1000000007;
using namespace std;

char str[2000][2005];
int  cnt[2005][2005];
int  cnt2[2005][2005];
int  cnt3[2005][2005];

int main(int argc, char* argv[])
{
    int n,m,Q;
    scanf("%d%d%d", &n, &m, &Q);

    int i,j;
    for(i=0; i<n; i++) {
        scanf("%s", str[i]);
        for(j=0; j<m; j++) {
            cnt[i+1][j+1]=cnt[i+1][j] + (str[i][j]=='1'? 1:0);
            if(j>0) {
                cnt2[i+1][j+1]=cnt2[i+1][j]+((str[i][j]=='1' && str[i][j-1]=='1')? 1:0);
            }
            if(i>0) {
                cnt3[i+1][j+1]=cnt3[i+1][j]+((str[i][j]=='1' && str[i-1][j]=='1')? 1:0);
            }
        }
    }
    for(j=0; j<=m; j++) {
        for(i=0; i<n; i++) {
            cnt[i+1][j]+=cnt[i][j];
            cnt2[i+1][j]+=cnt2[i][j];
            cnt3[i+1][j]+=cnt3[i][j];
        }
    }

    int q;
    for(q=0; q<Q; q++) {
        int x0,y0,x1,y1;
        scanf("%d%d%d%d", &x0, &y0, &x1, &y1);

        int tmp=cnt[x1][y1]-cnt[x0-1][y1]-cnt[x1][y0-1]+cnt[x0-1][y0-1];
        int tmp2=(y1==y0? 0: cnt2[x1][y1]-cnt2[x0-1][y1]-cnt2[x1][y0]+cnt2[x0-1][y0]);
        int tmp3=(x1==x0? 0: cnt3[x1][y1]-cnt3[x0][y1]-cnt3[x1][y0-1]+cnt3[x0][y0-1]);
        printf("%d\n", tmp-tmp2-tmp3);
    }

    return 0;
}


Measured memory_bytes: 52736
#include <vector>
#include <cstdio>

void add(const int &index, const int &value, std::vector<int> &vec){
	vec.at(index) += value;
	if (index != 0){
		add((index - 1) >> 1, value, vec);
	}
}
int get_sum(const int &start, const int &end, const std::vector<int> &vec){
	if (start == end){
		return vec.at(start);
	}else if (start > end){
		return 0;
	}else{
		int sum = get_sum(start  >> 1, ((end - 2) >> 1) , vec);
		if (start % 2 == 0){
			sum += vec.at(start);
		}
		if (end % 2 == 1){
			sum += vec.at(end);
		}
		return sum;
	}
}
int main(){
	int n, q;
	std::scanf("%d %d", &n, &q);
	int size = 2;
	while (n != 1){
		n >>= 1;
		size <<= 1;
	}
	std::vector<int> vec(size * 2 - 1, 0);
	--size;
	for (auto i = 0; i < q; ++i){
		int com, x, y;
		std::scanf("%d %d %d", &com, &x, &y);
		if (com == 0){
			add(size + x, y, vec);
		}else{
			std::printf("%d\n", get_sum(size + x, size + y, vec));
		}
	}
}

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

int main()
{
  int h, w;
  cin >> h >> w;

  int move_count = 0;
  string s;
  int a[h][w];
  for (auto i = 0; i < h; i++) {
    for (auto j = 0; j < w; j++) {
      cin >> a[i][j];
      if (j != 0 && a[i][j - 1] % 2 != 0) {
	s += to_string(i + 1) + " " + to_string(j) + " " +
	  to_string(i + 1) + " " + to_string(j + 1) + "\n";
	a[i][j]++;
	move_count++;
      }
      if (j == w - 1 && i != 0 && a[i - 1][j] % 2 != 0) {
	s += to_string(i) + " " + to_string(j + 1) + " " +
	  to_string(i + 1) + " " + to_string(j + 1) + "\n";
	a[i][j]++;
	move_count++;
      }
    }
  }
  cout << move_count << endl;
  cout << s;
}


Measured memory_bytes: 5124
#include<bits/stdc++.h>
using namespace std;
int N;
int main() {
    cin >> N;
    int a[N];
    for (int i = 0; i < N; i++)
    {
        cin >> a[i];
    }

    vector<int> b;
    b.push_back(a[N-1]);
    for (int i = 1; i < N; i++)
    {
        if(a[N-1-i] >= b[b.size()-1]) b.push_back(a[N-1-i]);
        else{
            auto c = upper_bound(b.begin(), b.end(), a[N-1-i]);
            b[c - b.begin()] = a[N-1-i];
        }
    }

    cout << b.size() << endl;
}

Measured memory_bytes: 1276
#include <iostream>
#include <cmath>
#include <algorithm>
#include <climits>
#include <vector>
#include <string>
#include <set>
#include <iomanip>
#include <map>
#define rep(i,n) for (int i=0;i<(n);++i)
#define REP(i,n) for (int i=0;i<=(n);++i)
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
const int INF = 10000000;

int gcd(int a,int b){return b?gcd(b,a%b):a;}

int main() {
    int n; cin >> n;
    int a = 0, w = 0, t = 0, r = 0;
    rep(i, n) {
        string str;
        cin >> str;
        if(str == "AC") ++a;
        else if(str == "WA") ++w;
        else if(str == "TLE") ++t;
        else ++r;
    }
    cout << "AC x " << a << endl;
    cout << "WA x " << w << endl;
    cout << "TLE x " << t << endl;
    cout << "RE x " << r << endl;

}

Measured memory_bytes: 3608
#include<bits/stdc++.h>
using namespace std;
bool isprime(long long n){
    long long i;
    if(n<=1) return false;
    if(n==2) return true;
    if(n%2==0) return false;
    for(i=3;i<=sqrt(n)+1;i++){
        if(n%i==0) return false;
    }
    return true;

}
int main(){
    long long x, ans=0;
    cin >> x;
    while(ans==0){
        if(isprime(x)) ans=x;
        else x++;
    }
    cout << ans << endl;
}

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

#define ll long long int
#define vi vector<int>

int main() {

    ll N;
    cin >> N;

    ll ans = 0;
    for (ll i = 1; i <= N; ++i) {
        if (i%3 == 0 || i%5 == 0) {
            continue;
        }
        ans += i;
    }

    cout << ans << endl;

    return 0;
}


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

#define rep2(x,fr,to) for(int x=(fr);x<(to);x++)
#define rep(x,to) for(int x=0;x<(to);x++)
#define repr(x,fr,to) for(int x=(fr);x>=(to);x--)
#define all(c) c.begin(),c.end()
#define sz(v) (int)v.size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<ll,int> pii;
typedef vector<ll> VL; const int MD = (int)1e9 + 7;
void dbg(){ cerr << "\n"; } template <typename T,typename ...T2> void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }
template <class T, class T2> void amax(T& a,T2 b){ if(a < b) a = b;}

int main()
{
	cin.tie(0); ios_base::sync_with_stdio(false);
	int n, m;
	cin >>n >>m;
	vector<VI> d(m, VI(4));
	rep(i, m){ cin >>d[i][1] >>d[i][0]; d[i][2]=i;}
	VI zm(n+1, 1) ;
	sort(all(d));
	for(auto& x: d) x[3] = zm[x[1]]++;
	sort(all(d), [](auto l, auto r){return l[2] < r[2];});
	
	for(auto& x: d) printf("%06d%06d\n", x[1], x[3]);
	
	return 0;
}


Measured memory_bytes: 7424
#include<bits/stdc++.h>
#include<math.h>
#include<vector>
using namespace std;
#define MAX 100009
#define MOD 1000000007
#define EPS 0.0000000001
struct Quad
{
    int a,b,c,d;
} arr[MAX];
vector<int> A;
long long score,temp;
int N,M,Q;
void backtrack(int index,int m=1)
{
    int i;
    //printf("b(%d,%d)\n",index,m);
    if(index==N)
    {
        temp=0;
        for(i=0;i<Q;i++)
        {
            if(A[arr[i].b]-A[arr[i].a]==arr[i].c)
                temp=temp+arr[i].d;
        }
        score=max(score,temp);
        return;
    }
    for(i=m;i<=M;i++)
    {
        A.push_back(i);
        backtrack(index+1,i);
        A.pop_back();
    }
}
int main()
{
    int i;
    scanf("%d %d %d",&N,&M,&Q);
    for(i=0;i<Q;i++)
    {
        scanf("%d %d %d %d",&arr[i].a,&arr[i].b,&arr[i].c,&arr[i].d);
        arr[i].a--;
        arr[i].b--;
    }
    backtrack(0);
    printf("%lld",score);
    return 0;
}


Measured memory_bytes: 3764
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
// order_of_key (val): returns the no. of values less than val
// find_by_order (k): returns the kth largest element.(0-based)

#define ll long long int
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define pi pair<ll,ll>
#define all(X) X.begin(),X.end()

// for pair comparison function(ascending order) use return (i1.ff < i2.ff);

/* string operations :
   str.substr (x,y) : returns a substring str[x],str[x+1],...str[x+y-1]
   str.substr (x) : returns a substring str[x],... end of string
   str.find(qtr) : returns the first occurenece of qtr in str */

const int M = (1<<20)+5;
const int md = 1e9+7;

ll pwr(ll a,ll n,ll m)
{
	ll p=1;
	while(n>0)
	{
		if(n%2==1)
			p=(p*a)%m;
		a=(a*a)%m;
		n=n/2;
	}
	return p;
}

ll w,h,r,cnt[15],br[15];
string str[15];
vector<pi> adj;

int check(int mask)
{
	int b = 1,i,j,k,s,e,fl,c = 0;
	adj.clear();
	for(i=0;i<h-1;++i)
	{
		if((mask>>i)&1)
		{
			adj.pb(pi(b,i+1));
			b = i+2;
		}
	}
	adj.pb(pi(b,h));

	for(j=0;j<(int)adj.size();++j)
		cnt[j] = br[j] = 0;

	for(i=1;i<=w;++i)
	{
		fl = 1;
		for(j=0;j<(int)adj.size();++j)
		{
			s = adj[j].ff;
			e = adj[j].ss;
			// cout << i << " " << j << " " << s << " " << e << " ";
			br[j] = 0;
			for(k=s;k<=e;++k)
				br[j]+=str[k-1][i-1]-'0';
			// cout << " " << br[j] << endl;
			if(br[j]>r)
				return -1;
			if(br[j]+cnt[j]>r)
				fl = 0;
		}
		if(fl == 1)
		{
			for(j=0;j<(int)adj.size();++j)
				cnt[j] += br[j];
		}
		else
		{
			for(j=0;j<(int)adj.size();++j)
				cnt[j] = br[j];
			++c;
		}
		// cout << i << endl;
		// for(j=0;j<(int)adj.size();++j)
		// 	cout << cnt[j] << " ";
		// cout << endl;
	}

	return c + (int)adj.size() - 1;
}

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

	ll i,res,ans;

	cin >> h >> w >> r;
	ans = h+w-2;
	for(i=0;i<h;++i)
		cin >> str[i];
	// cout << check(0) << endl;
	for(i=0;i<(1<<(h-1));++i)
	{
		res = check(i);
		if(res >= 0)
			ans = min(ans,res);
	}

	cout << ans << "\n";
	return 0;
}

	

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

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

	for(int i=0;i<s.size();i++){
		if(s[i] != 'a' && 'z' - s[i] + 1 <= K){
			K -= 'z' - s[i] + 1;
			s[i] = 'a';
		}
	}

	K = K % 26;
	while(K > 0){
		s[s.size() - 1] = (s[s.size() - 1] - 'a' + 1) % 26 + 'a';
		K--;
	}

	cout<<s<<endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(int (i) = (s);(i) <= (e);(i)++)
#define all(x) x.begin(),x.end()

int main() {
  i64 a,b,c;
  cin >> a >> b >> c;
  i64 m = min(b , c);
  c -= m;
  b -= m;
  i64 n = min(a, c);
  c -= n;
  a -= n;


  cout << n + m * 2 + min(1LL, c) + b << endl;
}


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

using namespace std;

char news[4]={'N','E','W','S'};
int to_x[4]={0, 1, -1, 0};
int to_y[4]={1, 0, 0, -1};

int main(){
    while(1){
        int gems;
        cin >> gems;
        if(gems==0) break;
        
        vector<vector<bool> > map(21,vector<bool>(21,false));
        int x,y;
        for(int i=0; i<gems; i++){
            cin >> x >> y;
            map[y][x] = true;
        }
        x = 10;
        y = 10;
        map[y][x] = false;
        
        int command, move;
        char direction;
        cin >> command;
        for(int i=0; i<command; i++){
            cin >> direction >> move;
            for(int j=0; j<4; j++){
                if(direction == news[j]){
                    for(int k=0; k<move; k++){
                        x+=to_x[j];
                        y+=to_y[j];
                        map[y][x] = false;
                    }
                }
            }
        }
        
        bool check = false;
        for(int i=0; i<=20; i++){
            for(int j=0; j<=20; j++){
                if(map[i][j] == true) check = true;
            }
        }
        if(check) cout << "No" << endl;
        else cout << "Yes" << endl;
    }
    
    return 0;
}

Measured memory_bytes: 3008
//#include<cstdio>
//#include<cassert>
//#include<iostream>
//#include<cstring>
//#include<algorithm>
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define MAX ((int)1e9 + 5)
#define MAXL ((ll)3e18 + 7)
#define MAX_X ((ll)1e5 + 2)
#define pi (2.0*acos(0))
#define M ((int)1e6 + 7)
#define MOD ((int)1e9 + 7)
#define NN ((int)3e6 + 7)
#define N ((int)1e5 + 5)
#define eps (0)
#define fastio ios_base::sync_with_stdio(false),cin.tie(NULL)
#define logn 29
#define endl "\n"
#define mp make_pair
#define BUCK 105
#define RIG ((idx<<1)|1)
#define LEF (idx<<1)
//#define int ll


using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;

/*fast io
ios_base::sync_with_stdio(false);
cin.tie(NULL);
*/




typedef tree < int,  null_type,  less < int >,  rb_tree_tag,  tree_order_statistics_node_update > o_set;
/// o_set s;
/// s.order_of_key(k) : Number of items strictly smaller than k .
/// *(s.find_by_order(k)) : K-th element in a set (counting from zero).


int arr[N];


int main()
{
    fastio;
    int n ;
    cin>>n;
    map < int , bool > pos;
    for(int i = 1 ; i<=n ; i++){
        cin>>arr[i];
        pos[arr[i]] = i&1;
    }
    sort(arr+1,arr+n+1);
    int ans = 0;
    for(int i = 1 ; i<=n ; i++){
        bool flag = pos[arr[i]];
        if(flag != (i&1)) ans++;
    }
    cout<<ans/2<<endl;
    return 0;
}

Measured memory_bytes: 5376
#ifndef Local
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma comment(linker, "/STACK:1024000000,1024000000")
#endif

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define popCnt(x) (__builtin_popcountll(x))
typedef long long Long;

// gp_hash_table<int, int> table;

int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#ifdef Local
  freopen("test.in", "r", stdin);
#else
#define endl '\n'
#endif


  int n;
  cin >> n;

  vector <int> vec(n);
  multiset<int> ms;

  for (int& x : vec) {
    cin >> x;
    ms.insert(x);
  }

  for (int x : vec) {
    ms.erase(ms.find(x));
    cout << *ms.rbegin() << endl;
    ms.insert(x);
  }

}


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

int main()
{
	int a,b;
	int c[3];
	cin >> a >> b;
	c[0] = a + b;
	c[1] = a - b;
	c[2] = a * b;
	sort(c,c + 3);
	cout << c[2];
}

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

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) cin >> a[i];
    int m;
    cin >> m;
    vector<int> b(m);
    for (int i = 0; i < m; i++) cin >> b[i];
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    int now = - 1;
    for (int i = 0; i < m; i++){
        bool flag = false;
        while (now < n - 1){
            now++;
            if (a[now] == b[i]) {
                flag = true;
                break;
            }
        }
        if (!flag){
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;
}

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

int main(){
  string str;
  cin >> str;
  for(int i=0;i<8;i++){
    int j=i,sum=str[0]-'0',count=1;
    string x(3,'+');
    while(count<4){
      if(j%2==0){
        sum+=str[count]-'0';
        count++;
      }
      if(j%2==1){
        sum-=str[count]-'0';
        x[count-1]='-';
        count++;
      }
      j/=2;
    }
    if(sum==7){
        cout << str[0] << x[0] << str[1] << x[1] << str[2] << x[2] << str[3] << "=7" << endl;
        return 0;
    }
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define f first
#define s second
#define pb push_back

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

    int h, w, n, ans;
    cin >> h >> w >> n;
    if (h >= w)
    {
        ans = n/h;
        if (n%h) ans++;
    }
    else
    {
        ans = n/w;
        if (n%w) ans++;
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 380
# https://qiita.com/_-_-_-_-_/items/34f933adc7be875e61d0
# abcde	s=input()	s='abcde'
# abcde	s=list(input())	s=['a', 'b', 'c', 'd', 'e']
# 5(1つだけ)	a=int(input())	a=5
# 1 2	| x,y = map(int,input().split())   |	x=1,y=2
# 1 2 3 4 5 ... n 　	li = input().split()	li=['1','2','3',...,'n']
# 1 2 3 4 5 ... n 　	li = inpl()	li=[1,2,3,4,5,...,n]
# FFFTFTTFF 　	li = input().split('T')	li=['FFF', 'F', '', 'FF']

# INPUT
# 3
# hoge
# foo
# bar
# ANSWER
# n=int(input())
# string_list=[input() for i in range(n)]

import math
import numpy as np
import copy
from collections import defaultdict, Counter
from itertools import product
from bisect import bisect_left, bisect_right
def inpl(): return list(map(int, input().split()))

A, B, K = map(int,input().split())

l = []
for i in range(1, min(A, B)+1):
    if A%i == 0 and B%i == 0:
        l.append(i)

print(l[::-1][K-1])

Measured memory_bytes: 21284