akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<math.h>
#include<cstring>
using namespace std;
const int inf=1<<30;
int main(){
  int H,W;bool canvas[60][60],ans=true;cin>>H>>W;
  char tmp;
  memset(canvas,false,sizeof(canvas));
  for(int h=1;h<=H;h++){
    for(int w=1;w<=W;w++){
      cin>>tmp;
      if(tmp=='#')canvas[h][w]=true;
    }
  }
  for(int h=1;h<=H;h++){
    for(int w=1;w<=W;w++){
      //if(canvas[h][w])printf("canvas[%d][%d] is painted.\n",h,w);
      if(canvas[h][w])if((!canvas[h][w-1]&&!canvas[h][w+1])&&(!canvas[h+1][w]&&!canvas[h-1][w])){
        //printf("canvas[%d][%d] cannot be painted.\n",h,w);
        ans=false;
      }
    }
  }
  if(ans)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順

int main() {
    ll N, WM; cin >> N >> WM;
    ll w0, v0; cin >> w0 >> v0;
    ll w1, w2, w3;
    w1 = w0 + 1;
    w2 = w1 + 1;
    w3 = w2 + 1;
    vector<ll> V0, V1, V2, V3; 
    V0.emplace_back(v0);
    for (int i = 1; i < N; i++) {
        ll w, v; cin >> w >> v;
        switch (w - w0) {
        case 0:
            V0.emplace_back(v);
            break;
        case 1:
            V1.emplace_back(v);
            break;
        case 2:
            V2.emplace_back(v);
            break;
        case 3:
            V3.emplace_back(v);
            break;
        default:
            fprintf(stderr, "This must not happen");
            exit(1);
        }
    }

    sort(V0.begin(), V0.end(), greater<ll>());
    if (V0.size() > 0) for (auto x = V0.begin() + 1; x != V0.end(); x++) {*x += *(x - 1);}
    sort(V1.begin(), V1.end(), greater<ll>());
    if (V1.size() > 0) for (auto x = V1.begin() + 1; x != V1.end(); x++) {*x += *(x - 1);}
    sort(V2.begin(), V2.end(), greater<ll>());
    if (V2.size() > 0) for (auto x = V2.begin() + 1; x != V2.end(); x++) {*x += *(x - 1);}
    sort(V3.begin(), V3.end(), greater<ll>());
    if (V3.size() > 0) for (auto x = V3.begin() + 1; x != V3.end(); x++) {*x += *(x - 1);}

    ll ma = 0;
    for (int i = 0; i <= V0.size(); i++) {
        for (int j = 0; j <= V1.size(); j++) {
            for (int k = 0; k <= V2.size(); k++) {
                for (int m = 0; m <= V3.size(); m++) {
                    ll W = w0 * i + w1 * j + w2 * k + w3 * m;
                    if (W > WM) break;
                    ll V = 0;
                    if (i > 0) V += V0[i-1];
                    if (j > 0) V += V1[j-1];
                    if (k > 0) V += V2[k-1];
                    if (m > 0) V += V3[m-1];
                    ma = max(ma, V);
                }
            }
        }
    }
    cout << ma << endl;
}


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

int main(){
    int n,x;
    char ch;
    scanf("%d",&n);
    int card[4][13]={0};

    for (int i = 0; i < n; i++)
    {
        scanf("%c",&ch);
        scanf("%c %d",&ch,&x);
        if(ch == 'S'){
            card[0][x-1]=1;
        }else if(ch == 'H'){
            card[1][x-1]=1;
        }else if(ch == 'C'){
            card[2][x-1]=1;
        }else if(ch == 'D'){
            card[3][x-1]=1;
        }
    }
    for (int i = 0; i < 4; i++)
    {
        for (int j = 0; j < 13; j++)
        {
            if(!card[i][j]){
                if(i==0)printf("S %d\n",j+1);
                else if(i==1)printf("H %d\n",j+1);
                else if(i==2)printf("C %d\n",j+1);
                else if(i==3)printf("D %d\n",j+1);
            }
        }
        
    }
    
    
}


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

long long l[100];

int main() {
    int n; cin >> n; 
    l[0] = 2;
    l[1] = 1;
    for (int i = 2; i <= n; ++i) l[i] = l[i - 1] + l[i - 2];
    cout << l[n] << endl;
}


Measured memory_bytes: 384
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<cstring>
#include<map>
#include<vector>
#include<queue>
#include<stack>
#include<climits>
#include<set>
#include<utility>
#include<typeinfo>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef set<int> S;
#define rep(i, n) for(int i=0; i<n; i++)
const ll MOD=1e9+7;

int main(){	

	int a, b, c, d, cnt[10] = {};
	cin >> a >> b >> c >> d;
	cnt[a]++;
	cnt[b]++;
	cnt[c]++;
	cnt[d]++;
	if(cnt[1] == 1 && cnt[9] == 1 && cnt[7] == 1 && cnt[4] == 1){
		cout << "YES" << endl;
	} else {
		cout << "NO" << endl;
	}

	return 0;
}

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

int main() {
    int a,b,c,k;
    int cnt = 0;
    cin >> a >> b >> c;
    cin >> k;
    while(a >= b){
        b *= 2;
        cnt++;
    }
    while(b >= c){
        c *= 2;
        cnt++;
    }
    cout << ((cnt <= k) ? "Yes" : "No") << endl;
}


Measured memory_bytes: 3540
#include <stdio.h>
#include<math.h>
#include <algorithm>
using namespace std;

int value[100],weight[100];
int N,W;
int** table;


int func(int index,int sum_w,int sum_v){
	if(table[W-sum_w][index] != 0){
		return sum_v + table[W-sum_w][index];
	}else{
		if(index < N-1){
			if(W-sum_w >= weight[index]){
				table[W-sum_w][index] = max(func(index+1,sum_w+weight[index],value[index]),func(index+1,sum_w,0));
				return sum_v + table[W-sum_w][index];
			}else{
				table[W-sum_w][index] = func(index+1,sum_w,0);
				return sum_v + table[W-sum_w][index];
			}

		}else{
			if(W-sum_w >= weight[index]){
				table[W-sum_w][index] = value[index];
				return sum_v + value[index];
			}else{
				table[W-sum_w][index] = 0;
				return sum_v;
			}
		}
	}
}

int main(){

	scanf("%d %d",&N,&W);

	table = new int*[10001];
	for(int i = 0; i < 10001; i++){
		table[i] = new int[100];
		for(int k=0;k < 100;k++)table[i][k] = 0;
	}

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

	printf("%d\n",func(0,0,0));

    return 0;
}

Measured memory_bytes: 6896
#include<stdio.h>

int main()
{
	int a,b;
	char op;
	while(scanf("%d %c %d",&a, &op,&b))
	{
		if(op == '?')
		{
			break;
		}
		else if(op =='+')
		{
			printf("%d\n",a+b);
		}
		else if(op =='-')
		{
			printf("%d\n",a-b);
		}
		else if(op =='*')
		{
			printf("%d\n",a*b);
		}
		else if(op =='/')
		{
			printf("%d\n",a/b);
		}
    }
	
	return 0;
 } 


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

#define NIL -1
struct node
{
	int left;
	int right;
	int parent;
};
struct node tree[100005];
int D[100005];
void rec(int u,int p)
{
	D[u]=p;
	if((tree[u].right)!=NIL)
		rec(tree[u].right,p);
	if((tree[u].left)!=NIL)
		rec(tree[u].left,p+1);
}

void print(int i)
{
	int j,c;
	cout<<"node "<<i<<": ";
	cout<<"parent = "<<tree[i].parent<<", ";
	cout<<"depth = "<<D[i]<<", ";
	if(tree[i].parent==NIL)
		cout<<"root, ";
	else if(tree[i].left==NIL)
		cout<<"leaf, ";
	else
		cout<<"internal node, ";
	cout<<"[";
	for(j=0,c=tree[i].left;c!=NIL;j++,c=tree[c].right)
	{
		if(j)
			cout<<", ";
		cout<<c;
	}
	cout<<"]"<<endl;
}
int main()
{
	int n;
	int num,c,l,r,nod;
	cin>>n;
	for(int i=0;i<n;i++)
	{
		tree[i].parent=NIL;
		tree[i].left=NIL;
		tree[i].right=NIL;
	}
	for(int i=0;i<n;i++)
	{
		cin>>c>>num;
		for(int j=0;j<num;j++)
		{
			cin>>nod;
			if(j==0)
				tree[c].left=nod;
			else
				tree[l].right=nod;
			l=nod;
			tree[nod].parent=c;
		}
	}
	for(int i=0;i<n;i++)
	{
		if((tree[i].parent)==NIL)
		{
			r=i;
			break;
		}
	}
	rec(r,0);
	for(int i=0;i<n;i++)
		print(i);
	return 0;
}


Measured memory_bytes: 7792
#include<iostream>
#define N 1000001
using namespace std;
int main(){
  int n;
  int p[N]={0};
  for(int i=3;i<=N;i+=2) p[i] = 1;
  p[2] = 1;
  for(int i=3;i<=1000;i+=2){
    if(p[i]==1){
      for(int j=2*i;j<=N;j+=i) p[j] = 0;
    }
  }
  while(cin>>n){
    int count = 0;
    if(n==0) break;
    int j = n - 2;
    if(p[j]==1) count++; 
    for(int i=3;i<=n/2;i+=2){
      if(p[i]){
	j = n - i;
	if(p[j]) count++;
      }
    }
    cout << count << endl;
  }
  return 0;
}

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

using namespace std;

typedef long long ll;

#ifdef RED
  mt19937 rnd(228);
#else
  mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
#endif

const int N = (int)1e6 + 5;

int main() {
#ifdef RED
  freopen("a.in", "r", stdin);
#endif
  ios_base :: sync_with_stdio(0);
  cin.tie(0);
  string s;
  cin >> s;
  int cur = 0;
  for (auto x : s) {
    ++cur;
    if (cur % 2 != 0) {
      if (x != 'R' && x != 'U' && x != 'D') {
        cout << "No";
        return 0;
      }
    }else {
      if (x != 'L' && x != 'U' && x != 'D') {
        cout << "No";
        return 0;
      }
    }
  }
  cout << "Yes";
  return 0;
}


Measured memory_bytes: 256
/// Swift5 -> Swift2.2

extension String {
    // split(separator:maxSplits:omittingEmptySubsequences:)
    func split(separator separator: Character) -> [String] {
        return self.characters.split(separator).map(String.init)
    }
}
extension Array {
    // init(repeating:count:)
    init(repeating: Element, count: Int) {
        self.init(count: count, repeatedValue: repeating)
    }
    // lastIndex(where:)
    func lastIndex(where predicate: (Element) -> Bool) -> Int? {
      	for i in stride(from: count - 1, through: 0, by: -1) {
          	if predicate(self[i]) {
              	return i
            }
        }
      	return nil
    }
}
extension Array where Element: Comparable {
    // sorted()
    func sorted() -> [Element] {
        return self.sort( { $0 < $1 } )
    }
    // max()
    func max() -> Element? {
        guard self.count > 0 else { return nil }
        return self.reduce(self.first!) { return Swift.max($0, $1) }
    }
}
extension String {
    // Sequence#enumerated()
  	// public func enumerate<Seq : SequenceType>(base: Seq) -> EnumerateSequence<Seq>
    func enumerated() -> EnumerateSequence<[Character]> {
        return Array(self.characters).enumerate()
    }
}
// stride(from:through:by:)
func stride(from start: Int, through end: Int, by stride: Int) -> StrideThrough<Int> {
    return start.stride(through: end, by: stride)
}
// stride(from:to:by)
func stride(from start: Int, to end: Int, by stride: Int) -> StrideTo<Int> {
    return start.stride(to: end, by: stride)
}

/// end


let N = Int(readLine()!)!

print(N >= 1000 ? "ABD" : "ABC")


Measured memory_bytes: 3696
use std::vec::Vec;

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>().split_whitespace().map(|e| e.parse().ok().unwrap()).collect()
}

fn main() {
    let (a, b) = {
      let v: Vec<i64> = read_vec();
      (v[0], v[1])
    };

    let mut t = vec![a + b, a - b, a * b];
    t.sort();
    println!("{}", t[2])
}


Measured memory_bytes: 4352
def A(i,x):
 while i<n+2:t[i]+=x;i+=i&-i
(n,q),c,*z=[[*map(int,t.split())]for t in open(0)]
a=[0]*q
j,*b=t=[0]*9**6
for i in sorted(range(q),key=lambda x:z[x][1]):
 l,r=z[i]
 while j<r:d=c[j];j+=1;A(b[d]+1,1);b[d]=j;A(j+1,-1)
 while l:a[i]+=t[l];l-=l&-l
print(*a)

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

ll n,a,ans;
pair<ll,ll> p[100009];

int main(){
    cin>>n;
    rep(i,n){
        cin>>a;
        p[i]={a,i};
    }
    sort(p,p+n);
    rep(i,n){
        if(abs(p[i].second-i)%2==1)ans++;
    }
    cout<<ans/2<<endl;
}

Measured memory_bytes: 1792
def perm(N):
    if N==0:return 0
    a=1
    for i in range(1,N+1):
        a*=i
    return a

def getposi(P):
    N=len(P)
    l=list(range(1,N+1))
    a = 0
    for i,num in enumerate(P):
        a+=perm(N-i-1)*l.index(num)
        l.remove(num)
    return a

stdin = open(0).read().split('\n')
N = int(stdin[0])
P = list(map(int,stdin[1].split()))
Q = list(map(int,stdin[2].split()))

a=getposi(P)
b=getposi(Q)

print(abs(a-b))

Measured memory_bytes: 3064
import java.util.Scanner;

class Main {
    void solve() {
        Scanner in = new Scanner(System.in);
        int a = in.nextInt(), b = in.nextInt(), c = in.nextInt();
        System.out.println(a == b ? c : b == c ? a : b);
    }

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


Measured memory_bytes: 22100
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using Map = map<ll,ll>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
const ll INF=1LL<<60;
const ll MOD=1000000007;




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

    vector<ll> ans(0);

    //右からM桁目を確定させる
    ll M=0;
    while(N!=0){
        ll d=pow(-2LL,M+1);
        if(N%d!=0){
            ans.emplace_back(1);
            N-=pow(-2LL,M);
        }
        else ans.emplace_back(0);
        M++;
    }
    if(ans.empty()){
        cout<<0<<endl;return 0;
    }
    ll j=ans.size();
    for(ll i=j-1;i>=0;i--){
        cout<<ans[i]
    ;}cout<<endl;
    

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main() {
    int a, b, c, i=0, count=0;
    cin >> a >> b >> c;
    for ( i = a; i < b+1; i++)
    {
        if (c%i==0)
        {
            count+=1;
        }
        
    }
    cout << count << endl;
    
	return 0;
}


Measured memory_bytes: 3128
from sys import stdin

def main():
    n=int(input())
    As=list(map(int, stdin.readline().split()))
    As.sort()
    check=[0]*(10**6+10)
    for a in As:
        count=1
        while a*count < 10**6+2 and a*count < As[-1]+1:
            if check[a*count]<2:
                check[a*count]+=1
            count+=1
    ans=0
    for a in As:
        if check[a]==1:
            ans+=1
    print(ans)


if __name__ == '__main__':
    main()

Measured memory_bytes: 31248
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <limits.h>
#include <math.h>
#include <time.h>
#include <queue>
#include <stdarg.h>
#include <map>
#include <vector>
#include <algorithm>
#include <stack>
#include <iostream>
#include <numeric>
#include <set>

#define ll long long

using namespace std;

void
print_path(vector<int> & path) {
  cout<<"=== path ==="<<endl;

  for (auto next : path)
    cout<<next<<" => ";
  cout<<endl;
}

void
solve() {
  int n, u, v;
  cin>>n>>u>>v;

  int a, b;
  vector<vector<int>> link(n+1);
  for (int i=0; i<n-1; i++) {
    cin>>a>>b;
    link[a].push_back(b);
    link[b].push_back(a);
  }

  map<int, int> parent;
  map<int, int> level;
  stack<int> now;
  now.push(v);
  parent[v] = -1;
  level[v] = 0;
  while (now.size() > 0) {
    int p = now.top();
    now.pop();

    for (auto next : link[p]) {
      if (parent[next] != 0) continue;

      parent[next] = p;
      level[next] = level[p] + 1;
      now.push(next);
    }
  }

  vector<int> path;
  int node = u;
  while (node != v) {
    path.push_back(node);
    node = parent[node];
  }
  path.push_back(v);

  int runner = 0, catcher = path.size()-1; 
  int ans = 0;
  while (catcher - runner > 2) {
    runner++;
    catcher--;
    ans++;
  }

  u = path[runner];
  v = path[catcher];

  stack<int> far;
  far.push(u);
  int tail = u;
  while (far.size() > 0) {
    auto p = far.top();
    far.pop();

    for (auto next : link[p]) {
      if (level[next] <= level[p]) continue;

      far.push(next);
      if (level[next] > level[tail])
        tail = next;
    }
  }

  path.clear();
  node = tail;
  while (node != v) {
    path.push_back(node);
    node = parent[node];
  }
  path.push_back(v);
  reverse(path.begin(), path.end());

  catcher = 0;
  runner = 0;
  for (int i=0; i<path.size(); i++)
    if (path[i] == u) {
      runner = i;
      break;
    }

  while (1) {
    if (runner + 1 < path.size()) {
      runner++;
      catcher++;
      ans++;
    }
    else {
      if (path[runner-1] == path[catcher]) {
        break;
      }
      else {
        ans++;
        break;
      }
    }
  }

  cout<<ans<<endl;
}

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

  int t = 1;
  //cin>>t;

  while (t > 0) {
    t--;
    solve();
  }

  return 0;
}



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

using ll = long long int;

const int MAX = (int)(1e5 + 5);
const ll INF = (ll)(1e10 + 5);

const int MAX_H = (int)(1e2 + 5);
const int MAX_W = (int)(1e1 + 5);
const ll MOD = (ll)(1e9 + 7);

int h, w, k;

ll dp[MAX_H][MAX_W];
bool arr[MAX_W];

ll ans;

bool check() {
  for (int l = 1; l <= w - 1; ++l) {
    if (arr[l] && arr[l + 1]) {
      return false;
    }
  }

  return true;
}

int main(void) {
  // Here your code !
  scanf("%d %d %d", &h, &w, &k);

  dp[0][1] = 1LL;

  arr[0] = false; // guard

  for (int i = 0; i < h; ++i) {
    for (int j = 1; j <= w; ++j) {
      for (int k = 0; k < 1 << (w - 1); ++k) {

        for (int l = 0; l < w - 1; ++l) {
          arr[l + 1] = ((k >> l & 1) == 1) ? true : false;
        }

        if (!check()) continue;  // in-valid pattern

        if (arr[j]) {
          dp[i + 1][j + 1] += dp[i][j];
          dp[i + 1][j + 1] %= MOD;
        } else if (arr[j - 1]) {
          dp[i + 1][j - 1] += dp[i][j];
          dp[i + 1][j - 1] %= MOD;
        } else {
          dp[i + 1][j] += dp[i][j];
          dp[i + 1][j] %= MOD;
        }
      }
    }
  }

  ans = dp[h][k];

  printf("%lld\n", ans);

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string a,b;
    cin>>a>>b;
    int i,p,q,m;
    p=a.size();
    q=b.size();
    m=min(p,q);
    for(i=0;i<m;i++)
    {
        cout<<a[i]<<b[i];
    }
    if(m==p)
    {
        for(i=m;i<q;i++)
            cout<<b[i];
    }
    else
    {
        for(i=m;i<p;i++)
            cout<<a[i];
    }
    cout<<endl;
}





Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<queue>
#include<set>
#include<map>
#include<stack>
#include<bitset>

#define pb push_back
#define mp make_pair

using namespace std;

typedef unsigned int u32;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double lod;
typedef pair<int,int> PR;
typedef vector<int> VI;

const lod pi=acos(-1);
const int oo=1<<30;
const LL OO=1e18;

const int N=2e5;

int gi() {
	int w=0;bool q=1;char c=getchar();
	while ((c<'0'||c>'9') && c!='-') c=getchar();
	if (c=='-') q=0,c=getchar();
	while (c>='0'&&c <= '9') w=w*10+c-'0',c=getchar();
	return q? w:-w;
}

int a[N],b[N],c[N];
int s[N];

int main()
{
	int n=gi(),i,k;LL sum=0,ans=0;
	for (i=1;i<=n;i++) a[i]=gi();
	for (i=1;i<=n;i++) b[i]=gi();
	for (i=1;i<=n;i++) c[i]=gi();
	sort(a+1,a+1+n);
	sort(b+1,b+1+n);
	sort(c+1,c+1+n);
	for (i=k=1;i<=n;i++) {
		while (k<=n&&b[i]>a[k]) k++;
		s[i]=k-1;	
	}
	for (i=k=1;i<=n;i++) {
		while (k<=n&&c[i]>b[k]) sum+=s[k++];
		ans+=sum;
	}
	cout<<ans<<endl;
	return 0;
}


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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG2(x,y) cout<<#x<<": "<<x<<" "<<#y<<": "<<y<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define DEBUG_ARR(v,n) cout<<#v<<":";REP(i,n)cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

int main() {
    ios::sync_with_stdio(false); cin.tie(0);
    int p,q,r;
    cin>>p>>q>>r;
    int ans = min(p+q, q+r);
    ans = min(ans, r+p);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
while True:
    m, f, r = map(int, input().split())
    if m == -1 and f == -1 and r == -1:
        break
    if m == -1 or f == -1:
        print('F')
        continue
    s = m + f
    if s >= 80:
        print('A')
    elif s >= 65:
        print('B')
    elif s >= 50:
        print('C')
    elif s >= 30:
        if r >= 50:
            print('C')
        else:
            print('D')
    else:
        print('F')
        

Measured memory_bytes: 7676
#include<iostream>
#include<algorithm>
#include<math.h>
#include<vector>
#include<map>
#include<set>

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

using namespace std;
using ll = long long;

int main() {
    int A, B; cin >> A >> B;
    int ans = 6 - A - B;
    cout << ans << endl;
    return 0;
}


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

int main() {
  ll n; cin >> n;
  vector<ll> a(n), b(n);
  vector<pair<ll, ll>> c;
  for(int i = 0; i < n; ++i) cin >> a[i];
  for(int i = 0; i < n; ++i) cin >> b[i];
  for(int i = 0; i < n; ++i) c.emplace_back(b[i], a[i]);
  sort(a.begin(), a.end());
  sort(b.begin(), b.end());
  for(int i = 0; i < n; ++i) {
    if(a[i] > b[i]) {
      cout << "No" << endl;
      return 0;
    }
  }
  // N-1回なら揃う。
  // N-2回でできるか
  sort(c.begin(), c.end());
  // a[0]が含まれるサイクル長を考える。
  // n未満だったらok
  int tmp = 0, len = 1;
  while(true) {
    if(c[tmp].second == a[0]) {
      if(len < n) {
        cout << "Yes" << endl;
        return 0;
      }
      break;
    }
    tmp = lower_bound(a.begin(), a.end(), c[tmp].second) - a.begin();
    ++len;
  }

  // この時点でサイクルが1こしかない。ので置換がn-1回必要。
  for(int i = 0; i < n-1; ++i) {
    if(b[i] >= a[i+1]) {
      cout << "Yes" << endl;
      return 0;
    }
  }

  cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 3956
#include<stdio.h>
int main()
{
    int a,b,c,count=0,i;
    scanf("%d %d %d",&a,&b,&c);
    for(i=a;i<=b;i++){
        if(c%i==0){
            count++;
        }
    }
    printf("%d\n",count);
    return 0;
}



Measured memory_bytes: 2064
#include <bits/stdc++.h>
using namespace std;
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,n1,n2) for(int i=n1;i<n2;i++)
#define bFOR(i,n1,n2) for(int i=n1;i>=n2;i--)
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

typedef long long int ll;
typedef pair<ll,ll> Pi;
const int INF=(ll)(1LL<<30)-1;
const double INFd=100000000000.0;
const ll INFl=(ll)9223372036854775807;
const int MAX=10000;
const ll MOD=(ll)1e9+7;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a, b)*b;}
int dx[4]={0,1,0,-1},dy[4]={-1,0,1,0};

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

int t,d,l;
int x[100100];
int wave[100100];

int main(){
	while(1){
		cin>>t>>d>>l;
		if(t==0&&d==0&&l==0)break;
		REP(i,100100)wave[i]=0;
		for(int i=1;i<=t;i++){
			int ll;
			cin>>ll;
			if(ll>=l){
				for(int j=0;j<d&&i+j<t;j++){
					wave[i+j]=1;
				}
			}
		}
		int ans=0;
		for(int i=1;i<t;i++){
			if(wave[i]==1)ans++;
		}
		cout<<ans<<endl;
	}
	return 0;
}


Measured memory_bytes: 3480
N, K = map(int, input().split())
mod = 10**9 + 7

def factorial(n):
    num = 1
    for i in range(1, n+1):
        num = (num * i) % mod
    return num 

# aのb乗をpで割った余を計算する
def calc(a, b, p):
    if b == 0:
        return 1
    if b % 2 == 0:
        d = calc(a, b//2, p)
        return (d**2) % p
    else:
        return (a * calc(a, b-1, p)) % p

for i in range(1, K+1):
    if i > N-K+1:
        print(0)
    else:
        ans = (factorial(N-K+1)*calc(factorial(i), mod-2, mod)*calc(factorial(N-K+1-i), mod-2, mod)) % mod
        ans = (ans * ((factorial(K-1)*calc(factorial(i-1), mod-2, mod)*calc(factorial(K-i), mod-2, mod)) % mod)) % mod
        print(ans)


Measured memory_bytes: 3316
n = int(input())
lst = []
flag = True
tmp = input()
lst.append(tmp)
for i in range(n-1):
    w = input()
    if w in lst:
        flag = False
    if tmp[-1] != w[0]:
        flag = False
    lst.append(w)
    tmp = w

print('Yes' if flag == True else 'No')

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

int main() {
  
  string W;
  cin >> W;
  
  if (W == "MON") {
    cout << 6 << endl;
  }
  else if (W == "TUE") {
    cout << 5 << endl;
  }
  else if (W == "WED") {
    cout << 4 << endl;
  }
  else if (W == "THU") {
    cout << 3 << endl;
  }
  else if (W == "FRI") {
    cout << 2 << endl;
  }
  else if (W == "SAT") {
    cout << 1 << endl;
  }
  else {
    cout << 7 << endl;
  }
}

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

#define rep(i, b) for( int i = 0; i < b; i++ )
#define repi(i, a, b) for( int i = a; i < b; i++ )
#define MAX 100000
typedef vector<int> vec;

bool prime[MAX];
vec v;

void pcalc(){
    rep(i, MAX){
        prime[i] = true;
    }
    prime[0] = false;
    prime[1] = false;
    repi(i, 2, MAX/2){
        if( prime[i] ){
            v.push_back(i);
            for( int j = i*2; j < MAX/2; j += i ){
                prime[j] = false;
            }
        }
    }
}

int main(){
    pcalc();
    int m, a, b;
    while( cin >> m >> a >> b, m ){
        int w, h, max = 0;
        for( int i = 0; v.size() && v[i] * v[i] <= m; i++ ){
            for( int j = i; v.size() && v[i] * v[j] <= m; j++ ){
                int p = v[i], q = v[j];
                if( p*b >= a*q && p*q > max ){
                    max = p*q;
                    w = p;
                    h = q;
                }
            }
        }
        /*
        rep(i, v.size()){
            if( v[i].first * v[i].second > ans.first * ans.second ){
                ans = make_pair(v[i].first, v[i].second);
            }
        }
        */
        cout << w << ' ' << h << endl;
    }
}

Measured memory_bytes: 1368
//https://codeforces.com/contest/1334/problem/A
//BROWNIE TK

#include <bits/stdc++.h>
using namespace std;

typedef long long int lli;
typedef unsigned long long int ulli;
typedef long double ldb;

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define pb push_back
#define popb pop_back()
#define pf push_front
#define popf pop_front()

#define si size()
#define be begin()
#define en end()
#define all(v) v.be, v.en

#define le length()
#define mp make_pair
#define mt make_tuple
#define acc(v) accumulate(all(v), 0)
#define F first
#define S second

#define pll pair<lli, lli>
#define pii pair<int, int>
#define pil pair<int, lli>

#define forz(i, n) for (int i = 0; i < n; i++)
#define fore(i, m, n) for (int i = m; i <= n; i++)
#define rforz(i, n) for (int i = n - 1; i >= 0; i--)
#define rfore(i, m, n) for (int i = n; i >= m; i--)

#define deci(n) fixed << setprecision(n)
#define high(n) __builtin_popcount(n)
#define highll(n) __builtin_popcountll(n)
#define parity(n) __builtin_parity(n)
#define ctz(n) __builtin_ctz(n)

#define bset(a, p) ((a) | (1ll << (p)))
#define bchk(a, p) ((a) & (1ll << (p)))
#define bxor(a, p) ((a) ^ (1ll << (p)));
#define brem(a, p) (bchk(a, p) ? (bxor(a, p)) : (a))
/*SOME BITMASK KNOWLEDGE
1)x & (x - 1):sets the last one bit of x to zero
power of two exactly when x & (x − 1) = 0.
2)x & -x:sets all the one bits to zero, except last one bit
3)x | (x - 1):inverts all the bits after the last one bit*/

#define lb lower_bound
#define ub upper_bound
#define er equal_range

#define findnot find_first_not_of

#define maxe *max_element
#define mine *min_element

#define mod2 1000000007
#define mod 998244353
#define gcd __gcd
#define kira ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)

#define endl "\n"
#define p0(a) cout << a << " "
#define p1(a) cout << a << endl
#define p2(a, b) cout << a << " " << b << endl
#define p3(a, b, c) cout << a << " " << b << " " << c << endl
#define p4(a, b, c, d) cout << a << " " << b << " " << c << " " << d << endl

#define oset tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define osetlli tree<lli, null_type, less<lli>, rb_tree_tag, tree_order_statistics_node_update>
//member functions :
//1. order_of_key(k) : number of elements sbtriectly lesser than k
//2. find_by_order(k) : k-th element in the set
#define ofk order_of_key
#define fbo find_by_order

/*STD funcions*/
lli power(lli x, lli y, lli p)
{
    lli res = 1;
    x = x % p;
    while (y > 0)
    {
        if (y & 1)
            res = (res * x) % p;
        y = y >> 1;
        x = (x * x) % p;
    }
    return res;
}
lli modi(lli a, lli m) { return power(a, m - 2, m); }
/*CODE BEGINS*/

int main()
{
    kira;
    string t="Fizz",f="Buzz";
    string b=t+f;
    lli n;
    cin>>n;
    lli sum=0;
    for(int i=1;i<=n;i++)
    {
        if(i%15==0){}
        else if(i%3==0){}
        else if(i%5==0){}
        else sum+=i;
    }
    p1(sum);
    return 0;
}


Measured memory_bytes: 3656
import sys
import math
from os import path

if(path.exists('input.txt')):
    sys.stdin = open("input.txt","r")
    sys.stdout = open("output.txt","w")
    
n,d = map(int,input().split())
count = 0
for i in range(n):
    x,y = map(int,input().split())
    if(math.sqrt((x**2)+(y**2))<=d):
        count +=1
print(count)

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

using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

#define REP(i, l, n) for(int i=(l), i##_len=(n); i<i##_len; ++i)
#define ALL(x) (x).begin(),(x).end()
#define pb push_back

ll gcd(ll a,ll b){return b ? gcd(b,a%b) : a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

char alpha[26] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};

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

int main(){
    int a, b, c, d; cin >> a >> b >> c >> d;
    int f = 1;
    while(1){
        if(f == 1){
            c -= b;
            if(c <= 0){
                cout << "Yes" << endl;
                return 0;
            }
        }else{
            a -= d;
            if(a <= 0){
                cout << "No" << endl;
                return 0;
            }
        }
        f *= -1;
    }
}

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

#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define FOR(e, c) for (auto &e : c)
#define SORT(v, n) sort(v, v + n);
#define vsort(v) sort(v.begin(), v.end());
#define rvisort(v) sort(v.begin(), v.end(), greater<int>());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
// #define int long long
#define sz(x) int(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using ul = unsigned long;

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; }

int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
int LCM(int a, int b) { return a * b / GCD(a, b); }

inline bool inside(int y, int x, int H, int W) {
    return (y >= 0 && x >= 0 && y < H && x < W);
}

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;


signed main()
{
  string s; cin>>s;
  int k; cin>>k;
  
  vector<string> a;
  rep(i,s.size()){
    for(int j=i;j<min((int)s.size(),i+k);j++){
      a.push_back(s.substr(i,(j-i+1)));
    }
  }
  vsort(a);
  string pre=a[0];
  if(k==1){
    cout<<pre<<endl;
    return 0;
  }
  string ans;
  int cnt=1;
  int i=0;
  for(auto e: a){
    i++;
    if(pre==a[i])continue;
    pre=a[i];
    cnt++;
    if(cnt==k) {
      ans=a[i];
      break;
    }
  }
  cout<<ans<<endl;
}


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

long long n,k,now=1,a[223456][60];
int d(long long now,int k){
  if(!a[now][k])a[now][k]=d(d(now,k-1),k-1);
  return a[now][k];
}

int main(){
  cin>>n>>k;
  for(int i=1;i<=n;i++)cin>>a[i][0];
  for(int i=0;i<60;i++)if((k>>i)&1)now=d(now,i);
  cout<<now<<endl;
}


Measured memory_bytes: 97360
/* basic header */
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <cstring>
#include <cmath>
#include <cstdint>
#include <climits>
#include <float.h>
/* STL */
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <array>
#include <iterator>
/* define */
#define ll long long
#define dou double
#define pb emplace_back
#define mp make_pair
#define fir first
#define sec second
#define init(a,b) fill(begin(a),end(a),b)
#define sot(a,b) sort(a+1,a+1+b)
#define rep1(i,a,b) for(int i=a;i<=b;++i)
#define rep0(i,a,b) for(int i=a;i<b;++i)
#define repa(i,a) for(auto &i:a)
#define eps 1e-8
#define int_inf 0x3f3f3f3f
#define ll_inf 0x7f7f7f7f7f7f7f7f
#define lson curPos<<1
#define rson curPos<<1|1
/* namespace */
using namespace std;
/* header end */

string s;

int hefa(int x, int y)
{
    if ((x * 10 + y) <= 12 && (x * 10 + y) > 0) return 1; else return 0;
}

int main()
{
    cin >> s;
    int a = s[0] - '0', b = s[1] - '0', c = s[2] - '0', d = s[3] - '0';
    if (hefa(a, b) && hefa(c, d)) puts("AMBIGUOUS");
    else if (hefa(a, b) && !hefa(c, d)) puts("MMYY");
    else if (!hefa(a, b) && hefa(c, d)) puts("YYMM");
    else puts("NA");
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <stdlib.h>
#include <algorithm>
using namespace std;

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

    int ans = 4;
    while(1)
    {
        if (n == 1 || n == 2 || n == 4){
            break;
        }
        if (n % 2 == 0)
        {
            n /= 2;
        }
        else
        {
            n = 3 * n + 1;
        }
        ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include<iomanip>

using namespace std;

int main()
{
	ios::sync_with_stdio(false);
	int s[31] = {};
	for (int i = 0; i<28; i++)
	{
		int h;
		cin >> h;
		s[h] = 1;
	}
	for (int i = 1; i<31; i++)
	{
		if (s[i] == 0)cout << i << endl;
	}
	cin >> s[0];
	return 0;
}

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

int main(){
    int k;
    int a, b;

    bool ans = false;

    cin >> k;
    cin >> a >> b;

    for(int i = a; i <= b; i++){
        if(i % k == 0){
            ans = true;
            break;
        }
    }
    if(ans == true){
        cout << "OK" << endl;
    }
    else{
        cout << "NG" << endl;
    }
}

Measured memory_bytes: 3572
n = gets.to_i
a = gets.split("\s").map(&:to_i).sort
result = 10000000

a[0].step(a[-1]) do |num|
  sum = 0
  a.each do |elem|
    sum += (num - elem) ** 2
  end
  if(result > sum)
    result = sum
  end
end

puts result

Measured memory_bytes: 1788
using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
	public static void Main(String[] args)
	{
		// スペース区切りの整数の入力
		var input = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();

		var A = input[0];
		var B = input[1];

		if (B % A == 0)
		{
			Console.WriteLine(A + B);
		}
		else
		{
			Console.WriteLine(B - A);
		}
	}
}



Measured memory_bytes: 13396
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int x,y,N;
int rez;
vector<pair<int,pair<int,int> > > V;
vector<pair<int,int> > X,Y;
int T[100005];
int fi(int x)
{
    if(T[x]<0)return x;
    return T[x]=fi(T[x]);
}
void u(int x,int y,int cost)
{
    x=fi(x);
    y=fi(y);
    if(x==y)return ;
    rez+=cost;
    if(T[x]<T[y]){T[x]+=T[y];T[y]=x;}
    else {T[y]+=T[x];T[x]=y;}
}
int main()
{
    cin>>N;
    for(int i=1;i<=N;i++)
    {
        T[i]=-1;
        cin>>x>>y;
        X.push_back(make_pair(x,i));
        Y.push_back(make_pair(y,i));
    }
    sort(X.begin(),X.end());
    sort(Y.begin(),Y.end());
    for(int i=0;i<N-1;i++)
    {
        V.push_back(make_pair(X[i+1].first-X[i].first,make_pair(X[i].second,X[i+1].second)));
        V.push_back(make_pair(Y[i+1].first-Y[i].first,make_pair(Y[i].second,Y[i+1].second)));
    }
    sort(V.begin(),V.end());
    for(auto it:V)
    {
        u(it.second.first,it.second.second,it.first);
    }
    cout<<rez;
    return 0;
}


Measured memory_bytes: 7528
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
vector<pair<ll,ll>> p;
int main(){
	int i,n;
	cin >> n;
	for(i=0;i<n;i++){
		ll a,b; cin >> a >> b;
		p.push_back({b,a});
	}
	sort(p.begin(),p.end());
	ll now = 0;
	for(i=0;i<n;i++){
		if(now + p[i].second>p[i].first){
			cout << "No" << endl;
			return 0;
		}else{
			now += p[i].second;
		}
	}
	cout << "Yes" << endl;
}

Measured memory_bytes: 6256
#include <iostream>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <stdio.h> 
#include <map>
#include <cmath>
#include <cstring>
#include <stack>
#include <queue>
#include <set>
#include <sstream>
#include <vector>
#include <algorithm>
using namespace std;

int main() {
	int n,a;
	cin>>n>>a;
	long long sum = 0;
	for (int i=0; i<a; i++) {
		int t;
		cin>>t;
		sum+=t;
	}
	
	if(sum<n) {
		cout << "No";
	} else {
		cout << "Yes";
	}
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <set>
#include <map>
#define rep(i, n)   for(int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;

int main(){
    string s;   cin>>s;
    int n = s.size();
    if(s[n-1] == 's'){
        s += "es";
    }else{
        s.push_back('s');
    }
    cout << s << endl;
}


Measured memory_bytes: 3624
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class AtCoderA
{
    static void Main()
    {
        var sc = new Scanner();

        long d = sc.NextLong();
        long[] c = sc.LongArray();
        long[,] s = new long[d, 26];
        for (int i = 0; i < d; i++)
        {
            for (int j = 0; j < 26; j++)
            {
                s[i, j] = sc.NextLong();
            }
        }

        long[] last = new long[26];

        for (int i = 0; i < d; i++)
        {
            long maxDiff = long.MinValue;
            long answerIndex = 0;
            long secondDiff = long.MinValue;
            long secondIndex = 0;
            long nextMaxScore = 0;
            for (int j = 0; j < 26; j++)
            {
                long diff = 0;
                diff += s[i, j];
                diff += c[j] * (i + 1 - last[j]);
                if (diff > maxDiff)
                {
                    secondDiff = maxDiff;
                    maxDiff = diff;
                    secondIndex = answerIndex;
                    answerIndex = j;
                }
                if (i != d - 1 && s[i + 1, j] > nextMaxScore)
                {
                    nextMaxScore = s[i + 1, j];
                }
            }
            if ((i != d - 1) && (s[i + 1, answerIndex] > s[i, answerIndex]) && (s[i + 1, answerIndex] == nextMaxScore))
            {
                answerIndex = secondIndex;
            }
            last[answerIndex] = i;
            Console.WriteLine(answerIndex + 1);
        }
    }

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}


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

int main(void){

    int A,B,C,X,Y; cin>>A>>B>>C>>X>>Y;
    int max_ABmaisu=max(2*X,2*Y);
    int max_Amai=X, max_Bmai=Y;
    int ans=1e+9;

    for (int ABmai = 0; ABmai <= max_ABmaisu; ++ABmai) {
        int Amai = ABmai/2 >= X ? 0 : X - ABmai/2;
        int Bmai = ABmai/2 >= Y ? 0 : Y - ABmai/2;
        int Akane = Amai*A, Bkane = Bmai*B, ABkane = ABmai*C;
        ans = min(ans, Akane+Bkane+ABkane);
    }

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int C,N;
char A[1000][1000];
int t[1000][1000];
int total=0;

bool check(int x,int y){
  return (A[x][y]==A[N-1-x][y] && A[x][y]==A[x][N-1-y]);
}

void update(int x,int y){
  total-=t[x][y];
  t[x][y]=check(x,y);
  total+=t[x][y];
}

void change(int x,int y){
  A[x][y]='0'+'1'-A[x][y];
  update(x,y);
  update(N-1-x,y);
  update(x,N-1-y);
}

int solve(){
  return (total==N*N);
}

int main(){
  cin>>C>>N;
  for(int i=0;i<N;i++){
    for(int j=0;j<N;j++){
      cin>>A[i][j];
    }
  }

  for(int i=0;i<N;i++){
    for(int j=0;j<N;j++){
      t[i][j]=check(i,j);
      total+=t[i][j];
    }
  }

  int ans=solve();
  for(int i=0;i<C-1;i++){
    int k;
    cin>>k;
    for(int j=0;j<k;j++){
      int x,y;
      cin>>x>>y;
      x--,y--;
      change(x,y);
    }
    ans+=solve();
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 7972
////////////////////////// Author
////////////////////////// Nasim Hossain Rabbi
////////////////////////// JU-CSE28
////////////////////////// CF - imnasim3.1415
////////////////////////// UVA - imnasim3.1415
////////////////////////// Mail - imnasim3.1415@gmail.com
#include<bits/stdc++.h>
using namespace std;
#define E end()
#define B begin()
#define sz size()
#define EM empty()
#define fi first
#define se second
#define cl clear()
#define sqr(a) (a*a)
#define mk make_pair
#define pb push_back
string en="\n";
string sp=" ";
string t="hello";
string Y="YES\n";
string N="NO\n";
#define rep(i,n) for(i=0;i<n;i++)
#define Rep(i,n) for(i=1;i<=n;i++)
#define per(i,n) for(i=n-1;i>=0;i--)
#define peR(i,n) for(i=n;i>0;i--)
#define mem(a,b) memset(a,b,sizeof(a))
#define all(cont) cont.begin(),cont.end()
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL)
#define pi 3.1415926535897932384626433832795
#define vi vector<long long>
#define vs  vector<string>
#define MX LLONG_MAX
#define MN LLONG_MIN
#define MOD 1000000007
#define vp(vi,x) cin>>x; vi.pb(x);
#define bsearch(a,x) binary_search(all(a),x)
#define LB(a,x) (lower_bound(all(a),x)-a.B)
#define UB(a,x) (upper_bound(all(a),x)-a.B)
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
bool isprm(LL a){for(LL i=2;i*i<=a;i++){if(a%i==0)return false;}return true;}
bool palin(string a){for(int i=0;i<a.sz;i++){if(a.at(i)!=a.at(a.sz-i-1))return 0;} return 1;}
bool isVowel(char ch){ ch=toupper(ch); if(ch=='A'||ch=='U'||ch=='I'||ch=='O'||ch=='E') return true; return false;}
int toInt(string s){int sm;stringstream ss(s);ss>>sm;return sm;}
LL bpow(LL a,LL b){if(b==0)return 1;LL r=bpow(a,b/2);if(b%2)return r*r*a;else return r*r;}
LL binpow(LL a,LL b){LL r=1;while(b>0){if(b&1)r=r*a;a=a*a;b>>=1;}return r;}
LL binpow(LL a,LL b,LL m){a%=m;LL r=1;while(b>0){if(b&1) r=r*a%m;a=a*a%m; b>>=1;}return r;}
template<typename T>inline T gcd(T a,T b){if(a<0)return gcd(-a,b);if(b<0)return gcd(a,-b);return (b==0)?a:gcd(b,a%b);}
template<typename T>inline T lcm(T a,T b) {if(a<0)return lcm(-a,b);if(b<0)return lcm(a,-b);return a*(b/gcd(a,b));}
int main()
{
//    fast;
    LL i,j,k,n,m,l,s=0,x,y,tc=1,p,q,a,b,c=0;
    bool f=0,ff=0;
    string st;
    while(cin>>n>>k)
    {
        bitset<11>dig;
        rep(i,k)
        {
            cin>>x;
            dig[x]=1;
        }
        while(1)
        {
            a=n,f=0;
            while(a)
            {
                if(dig[a%10])
                {
                    f=1;
                    break;
                }
                a=a/10;
            }
            if(!f)
            {
                cout<<n<<en;
                break;
            }
            n++;
        }
    }
}





Measured memory_bytes: 3636
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

void findAC(char*,int*,int);

int main(void)
{
    int n,q=0,l,r,i;
    scanf("%d %d",&n,&q);
    char *s=(char*)malloc(sizeof(char)*n);
    int *loc=(int*)malloc(sizeof(int)*n);
    scanf("%s",s);
    findAC(s,loc,n);
    while(q>0)
    {
        scanf("%d %d",&l,&r);
        l--;r--;
        printf("%d\n",loc[r]-loc[l]);
        q--;
    }
    free(s);free(loc);
    return 0;
}

void findAC(char *s,int *loc,int n)
{
    int i=0,same=0,isAC=0;
    while(i<n)
    {
        if(*(s+i)=='A') isAC=1;
        else if(*(s+i)=='C' && isAC==1)
        {
            isAC=0;
            same++;
        }
        else isAC=0;
        loc[i]=same;
        i++;
    }
    return;
}





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

#define pi 3.141592654
#define fix(n) cout << fixed << setprecision(n)

#define rep(i,a,b) for(int i=a;i<b;i++)
#define ren(i,a,b) for(int i=a;i>=b;i--)

#define si(d)  scanf("%d",&d)
#define sll(d) scanf("%lld",&d)
#define pin(d) printf("%d\n",d)
#define pln(d) printf("%lld\n",d)
#define nl 	   printf("\n")

#define ll long long
#define ull unsigned long long

#define mp make_pair
#define pb push_back
#define fi first
#define se second

#define vi vector<int>
#define pii pair<int,int> 
#define piii pair<pair<int,int>,int> 

#define chalne_de continue
int mod=1000000007;
const int N = 1000005;

ll gcd(ll a , ll b)
{
    if ( b == 0)
    return a;
    return gcd( b, a % b);
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	//freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
	ll n, a, b;
	cin >> n >> a >> b;
	double sum = 0.0;
	vi v;
	rep(i,0,n)
	{
		int x;
		cin >> x;
		v.pb(x);
	}
	 a -= b;
	sort(v.begin(),v.end());
	ll l = 1, r = 1000000000,id;
	while ( l <= r)
	{
		ll mid = (l+r)/2;
		ll ans = 0;
		for ( int i = 0; i < n; i ++)
		{
			ll x = v[i] - mid * b;
			if ( x > 0)
				ans += (x+a-1) / a;
		}
		if ( ans <= mid)
		{
			id = mid;
			r = mid - 1;
		}
		else
			l = mid + 1;

	}
	cout << id << endl;
	return 0;
}


Measured memory_bytes: 892
import sys
#sys.setrecursionlimit(100000)

MOD = 1000000007  # type: int

def cmb(n, r):
    shi=bo=1
    for i in range(r):
        shi*=(n-i)
        shi%=MOD
        bo*=(r-i)
        bo%=MOD
    return shi*pow(bo,MOD-2,MOD)

def solve(n: int, a: int, b: int):
    print((pow(2,n)-cmb(n,a)-cmb(n,b)-1)%MOD)
    return

# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    n = int(next(tokens))  # type: int
    a = int(next(tokens))  # type: int
    b = int(next(tokens))  # type: int
    solve(n, a, b)

if __name__ == '__main__':
    main()


Measured memory_bytes: 280908
# coding: utf-8

l = 10 ** 5
num = [0] * (l + 1)
n, k = map(int, raw_input().split())

for _ in xrange(n):
    a, b = map(int, raw_input().split())
    num[a] += b

for i in xrange(1, l+1):
    k -= num[i]
    if k <= 0:
        print i
        break


Measured memory_bytes: 4868
N,M = map(int,input().split())

A = list(map(int,input().split()))

ans = 0

slis = [0]

for i in range(N):

    slis.append(slis[-1] + A[i])


dic = {}


for j in range(len(slis)):

    i = slis[j]

    if i % M not in dic:
        dic[i % M] = 1

    else:
        dic[i % M] += 1

for i in dic:
        
    if dic[i] >= 2:

        ans += dic[i] * (dic[i] - 1) // 2

print (ans)


Measured memory_bytes: 16552