akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
using namespace std;
static const int MAX = 1000;
static const int VMAX = 10000;

int n, A[MAX], s;
int B[MAX], T[VMAX+1];

int solve() {
    int ans = 0;

    bool V[MAX];
    for ( int i = 0; i < n; i++) {
        B[i] = A[i];
        V[i] = false;
    }
    sort(B, B+n);
    for (int i=0; i<n; i++) T[B[i]] = i;
    for (int i=0; i<n; i++) {
        if (V[i]) continue;
        int cur = i;
        int S = 0;
        int m = VMAX;
        int an = 0;
        while (1) {
            V[cur] = true;
            an++;
            int v = A[cur];
            m = min(m, v);
            S += v;
            cur = T[v];
            if (V[cur]) break;
        }
        ans += min(S+(an-2)*m, m+S+(an+1)*s);
    }
    return ans;
}

int main() {
    cin >> n;
    s = VMAX;
    for ( int i=0; i<n; i++) {
        cin >> A[i];
        s = min(s, A[i]);
    }
    int ans = solve();
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3168
#ifndef BZ
#pragma GCC optimize "-O3"
#endif
#include <bits/stdc++.h>

#define FASTIO
#define ALL(v) (v).begin(), (v).end()
#define rep(i, l, r) for (int i = (l); i < (r); ++i)

#ifdef FASTIO
#define scanf abacaba
#define printf abacaba
#endif

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

using namespace std;


/*
ll pw(ll a, ll b) {
	ll ans = 1; while (b) {
		while (!(b & 1)) b >>= 1, a = (a * a) % MOD;
		ans = (ans * a) % MOD, --b;
	} return ans;
}
*/

const int MAXN = 120000;

vector<int> eds[MAXN];

int n, m;

void no() {
	cout << "No\n";
	exit(0);
}

int main() {
#ifdef FASTIO
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#endif
	cin >> n >> m;
	for (int i = 0; i < m; ++i) {
		int a, b;
		cin >> a >> b;
		--a, --b;
		eds[a].push_back(b);
		eds[b].push_back(a);
	}
	for (int i = 0; i < n; ++i)
		if (eds[i].size() % 2 != 0)
			no();
	vector<int> vv;
	for (int i = 0; i < n; ++i) {
		if (eds[i].size() == 4) {
			vv.push_back(i);
		}
		else if (eds[i].size() >= 6) {
			cout << "Yes\n";
			return 0;
		}
	}
	if (vv.size() > 2) {
		cout << "Yes\n";
		return 0;
	}
	else if (vv.size() == 2) {
		int fl = 0;
		for (int i: eds[vv[0]]) {
			int pr = vv[0];
			int x = i;
			while (x != vv[0] && x != vv[1]) {
				int nw = eds[x][0] ^ eds[x][1] ^ pr;
				pr = x;
				x = nw;
			}
			if (x == vv[0]) {
				fl = 1;
				break;
			}
		}
		if (fl) {
			cout << "Yes\n";
			return 0;
		}
		else {
			no();
		}
	}
	else {
		no();
	}
	return 0;
}




Measured memory_bytes: 6144
#include <algorithm>
#include <cstdint>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <cfloat>

using namespace std;

using lint=int64_t;
using uint=uint32_t;
using ulint=uint64_t;

template<class T>
using vector2d=vector<vector<T>>;

template<class T>
bool UpdateMax(T &a, const T &b){
  if(a<b){
    a=b;
    return true;
  }else{
    return false;
  }
}

template<class T>
bool UpdateMin(T &a, const T &b){
  if(a>b){
    a=b;
    return true;
  }else{
    return false;
  }
}

template <class T>
void OutVec(const vector<T>& vec){
  for(int i = 0; i < vec.size() - 1; ++i){
    cout<<vec[i]<<" ";
  }
  cout<<vec.back()<<endl;
}

template <class T>
void OutVec2d(const vector2d<T>& vec){
  for(auto v:vec){
    OutVec(v);
  }
}

int main(){
  cout << std::fixed << std::setprecision(16);
  cin.tie(nullptr);
  std::ios::sync_with_stdio(false);

  lint n,m,k;
  cin>>n>>m>>k;
  vector<lint> a(n),b(m);
  for(int i=0;i<n;i++){
    cin>>a[i];
  }
  for(int i=0;i<m;i++){
    cin>>b[i];
  }

  int a_itr=0;
  lint cum=0;
  while(cum+a[a_itr]<=k){
    cum+=a[a_itr];
    a_itr++;
    if(a_itr==n) break;
  }
  int b_itr=0;
  while(b_itr<m&&cum+b[b_itr]<=k){
    cum+=b[b_itr];
    b_itr++;
  }
  int result=a_itr+b_itr;

  while(a_itr>0){
    a_itr--;
    cum-=a[a_itr];
    while(b_itr<m&&cum+b[b_itr]<=k){
      cum+=b[b_itr];
      b_itr++;
    }
    UpdateMax(result,a_itr+b_itr);
  }
  cout<<result<<endl;


  return 0;
}




Measured memory_bytes: 6364
h, w = map(int, input().split())
g = []
for i in range(h):
    g.append(input())
flg = [[0] * w for _ in range(h)]

for i in range(h):
    if all(c == "." for c in g[i]):
        for j in range(w):
            flg[i][j] = 1

for j in range(w):
    if all(d[j] == "." for d in g):
        for i in range(h):
            flg[i][j] = 1

res = []
for i in range(h):
    su = ""
    for j in range(w):
        if not flg[i][j]:
            su += g[i][j]
    if su:
        res.append(su)
print(*res, sep="\n")


Measured memory_bytes: 3188
n,m=map(int,input().split())
a=[1]*n
b=[0]*n
b[0]=1
for _ in range(m):
    x,y=map(int,input().split())
    x-=1
    y-=1
    if a[x]>1:
        if b[x]==1:
            b[y]=1
        a[x]-=1
        a[y]+=1
    else:
        if b[x]==1:
            b[x]=0
            b[y]=1
        a[x]-=1
        a[y]+=1
print(sum(b))

Measured memory_bytes: 4596
a,b,c,d = map(int, input().split())

ans = max(a*c,a*d,b*c,b*d)
if a*b <= 0 or c*d <= 0:
    ans = max(0,ans)

print(ans)

# if b>=0 and d>= 0:
#     ans = b*d
# elif b < 0 and d >= 0:
#     if c <= 0: ans = max(ans,0)
#     else: ans = b*c
# elif b >= 0 and d < 0:
#     if a <= 0: ans = 0
#     else: ans = a*d
# else:
#     ans = a*c

# if a <= 0 and c <= 0:
#     ans = max(ans,a*c)

# print(ans)

Measured memory_bytes: 61576
/*
ID: jerrywcy
LINK:
LANG: C++
STATUS:
*/
#include <bits/stdc++.h>

#define init(array,x) memset(array,x,sizeof(array))
#define pb push_back

using namespace std;

const int inf=0x3f3f3f3f;

int m,k;

int main()
{
	ios::sync_with_stdio(false);
	cin>>m>>k;
	if (k>=(1<<m)){
		puts("-1");
		return 0;
	}
	if (m==1){
		if (k==0)puts("0 0 1 1");
		else puts("-1");
		return 0;
	}
	printf("%d ",k);
	for (int i=0;i<(1<<m);i++)if (i!=k)printf("%d ",i);
	printf("%d ",k);
	for (int i=(1<<m)-1;i>=0;i--)if (i!=k)printf("%d ",i);

	return 0;
}



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

using namespace std;

int main() {
  int n;
  cin >> n; 
    while (n > 0) {
   int k = n % 10; 
   if (k == 7) {
       cout << "Yes" << endl; 
       return 0;

    }
    n = n / 10; 
    }
    cout << "No" << endl;
    return 0; 
}


Measured memory_bytes: 3636
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <cmath>
#include <map>
#include <climits>

using namespace std;
#define rep(i, n) for(int i = 0; i < (n); ++i)
typedef long long ll;

int main()
{
  int n, m;
  cin >> n >> m;
  vector<int> h(n);
  rep(i, n)
  {
    cin >> h[i];
  }
  int a, b;
  vector<bool> obs(n, true);
  rep(i, m)
  {
    cin >> a >> b;
    a--;b--;
    obs[a] = obs[a] && h[a] > h[b];
    obs[b] = obs[b] && h[b] > h[a];
  }
  int ans = 0;
  rep(i, n)
  {
    if(obs[i])
      ++ans;
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3788
from collections import defaultdict
b = defaultdict(int)
c = defaultdict(int)
n = int(input())
a = map(int, input().split())

for idx,i in enumerate(a, start=1):
  b[i - idx] += 1
  c[i + idx] += 1
ans = 0
for k,v in b.items():
  ans += (v * c[-1 * k])
print(ans)

Measured memory_bytes: 69900
import java.io.BufferedReader; 
import java.io.IOException; 
import java.io.InputStreamReader; 
import java.util.Scanner; 
import java.util.StringTokenizer; 
import java.util.*;
  
public class Main
{ 
    //By shwetank_verma
    static class FastReader 
    { 
        BufferedReader br; 
        StringTokenizer st; 
  
        public FastReader() 
        { 
            br = new BufferedReader(new
                     InputStreamReader(System.in)); 
        } 
  
        String next() 
        { 
            while (st == null || !st.hasMoreElements()) 
            { 
                try
                { 
                    st = new StringTokenizer(br.readLine()); 
                } 
                catch (IOException  e) 
                { 
                    e.printStackTrace(); 
                } 
            } 
            return st.nextToken(); 
        } 
  
        int nextInt() 
        { 
            return Integer.parseInt(next()); 
        } 
  
        long nextLong() 
        { 
            return Long.parseLong(next()); 
        } 
  
        double nextDouble() 
        { 
            return Double.parseDouble(next()); 
        } 
  
        String nextLine() 
        { 
            String str = ""; 
            try
            { 
                str = br.readLine(); 
            } 
            catch (IOException e) 
            { 
                e.printStackTrace(); 
            } 
            return str; 
        } 
    } 
    static int mod=1000000007;
    static boolean primes[]=new boolean[1000007];
    
    static boolean seive(int n){
        Arrays.fill(primes,true);
        primes[0]=primes[1]=false;
        for(int i=2;i*i<=n;i++){
            if(primes[i]==true){
                for(int p=i*i;p<=n;p+=i){
                    primes[p]=false;
                }
            }
        }
        if(n<1000007){
            return primes[n];
        }
        return false;
        
    }
    static int gcd(int a,int b){
        if(b==0)
        return a;
        return gcd(b,a%b);
    }
    static long GCD(long a,long b){
        if(b==0)
        return a;
        return GCD(b,a%b);
    }
    
  
    public static void main(String[] args) 
    { 
        FastReader sc=new FastReader(); 
        try{
           
                String s1=sc.next();
                String s2=sc.next();
                char ch1[]=s1.toCharArray();
                char ch2[]=s2.toCharArray();
                int cnt=0;
                for(int i=0;i<s1.length();i++) {
                    int val=Math.abs(ch1[i]-ch2[i]);
                    if(val!=0)
                    	cnt++;
                }
               System.out.println(cnt);
            
        }catch(Exception e){
            return;
        }
    } 
}



Measured memory_bytes: 38660
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

const r = 1000000000

func main() {
	sc.Split(bufio.ScanWords)

	S := getInt()
	a := r
	b := 1

	var c, d int
	if S == int(1e18) {
		c = 0
		d = r

	} else if S/r == 0 {
		c = S
		d = 0
	} else {
		c = r - S%r
		d = S/r + 1
	}

	out(0, 0, a, b, c, d)
}


Measured memory_bytes: 640
# coding: utf-8
H, W = map(int, input().split())
grid = [['*'] * (W + 2)]
for _ in range(H):
    grid.append(['*'] + list(input()) + ['*'])
grid.append(['*'] * (W + 2))

def check(i, j):
    re = 0
    for p in range(3):
        for q in range(3):
            if grid[i - 1 + p][j - 1 + q] == '#':
                re += 1
    return re

for i in range(1, H + 1):
    for j in range(1, W + 1):
        if grid[i][j] == '.':
            grid[i][j] = check(i, j)

for i in range(1, H + 1):
    for j in range(1, W + 1):
        print(grid[i][j], end='')
    print()

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

#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <string>
#include <functional>
#include <math.h>
#include <map>

typedef long long ll;
typedef unsigned long long ull;

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

const double INF = std::numeric_limits<double>::infinity() ;
const int MOD = 1e9+7;

using namespace std;

template <typename _Ty>
ostream& operator << (ostream& ostr, const vector<_Ty>& v) {if (v.empty()) {ostr << "{ }"; return ostr;}
    ostr << "{" << v.front(); for (auto itr = ++v.begin(); itr != v.end(); itr++) {ostr << ", " << *itr;}
    ostr << "}";
    return ostr;}

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }


int main(void){
  ios::sync_with_stdio(false);
  char c;
  cin >> c;

  char res;

  bool flag = false;
  for (char moji='a'; moji<='z'; ++moji){
    if (moji == c){
      flag = true;
    }
    else if (flag){
   res = moji;
   break;
    }}

  cout << res << endl;

  return 0;
}



Measured memory_bytes: 256
#pragma warning(disable: 4996)
#include <string>
#include <vector>
#include <iostream>
#include <cstdio>
#include <sstream>
#include <fstream>
#include <math.h>

using namespace std;
typedef long long ll;
#define rep(i,n) for (int i = 0; i < (n); i++)

int main() {
    int n, k;
    cin >> n >> k;
    double a[200000];
    rep(i, n) {
        cin >> a[i];
        a[i] = log10(a[i]) + 1;
    }

    double p = 1;

    rep(i, k)p *= a[i];

    for (int i = k; i < n; i++) {
       
        if (a[i] > a[i - k])cout << "Yes" << endl;
        else cout << "No" << endl;
        
    }

   
return 0;
}

Measured memory_bytes: 5012
#include <stdio.h>
int main(){
int W,H,x,y,r;
scanf("%d %d %d %d %d\n",&W,&H,&x,&y,&r);
if (x+r<=W && x-r>=0 && y+r<=H && y-r>=0)
printf("Yes\n");
else printf("No\n");
return 0;
}


Measured memory_bytes: 2128
import java.util.Scanner;

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author rn-sshawish
 */
public class Main {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int x = input.nextInt();
        int a = input.nextInt();
        int b = input.nextInt();
        x-= a;
        x= x%b;
        System.out.println(x);
    }
}


Measured memory_bytes: 23252
// Problem : B - Trick or Treat
// Contest : AtCoder - AtCoder Beginner Contest 166
// URL : https://atcoder.jp/contests/abc166/tasks/abc166_b
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>

int n, k, sum[105];

int main() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= k; ++i) {
    int s; scanf("%d", &s);
    for (int j = 1; j <= s; ++j) {
      int tmp; scanf("%d", &tmp);
      ++sum[tmp];
    }
  }
  int res = 0;
  for (int i = 1; i <= n; ++i) if (sum[i] == 0) ++res;
  printf("%d\n", res);
  return 0;
}

Measured memory_bytes: 3828
def xgcd(a, b):
    x0, y0, x1, y1 = 1, 0, 0, 1
    while b != 0:
        q, a, b = a // b, b, a % b
        x0, x1 = x1, x0 - q * x1
        y0, y1 = y1, y0 - q * y1
    return a, x0, y0
  
def modinv(a, m):
    g, x, y = xgcd(a, m)
    if g != 1:
        raise Exception('modular inverse does not exist')
    else:
        return x % m
x, y = map(int, input().split())
inf = 10**9+7
if (x+y)%3 > 0:
  print(0)
else:
  n = (x+y)//3
  c = [1 for i in range(n+1)]
  invc = [1 for i in range(n+1)]
  for i in range(1, n+1):
    c[i] = c[i-1]*i % inf
    invc[i] = modinv(c[i], inf)
  cnt=-1
  for i in range(n+1):
    if (i+2*(n-i)==x)&(2*i+(n-i)==y):
      cnt = i
      break
  if cnt < 0:
    ans = 0
  else:
    ans = (c[n] * invc[cnt] * invc[n-cnt]) % inf
  print(ans)

Measured memory_bytes: 91916
table1 = {"'"=>"000000", ","=>"000011", "-"=>"10010001", "."=>"010001",
  "?"=>"000001", "A"=>"100101", "B"=>"10011010", "C"=>"0101", "D"=>"0001",
  "E"=>"110", "F"=>"01001", "G"=>"10011011", "H"=>"010000", "I"=>"0111",
  "J"=>"10011000", "K"=>"0110", "L"=>"00100", "M"=>"10011001",
  "N"=>"10011110", "O"=>"00101", "P"=>"111", "Q"=>"10011111", "R"=>"1000",
  "S"=>"00110", "T"=>"00111", "U"=>"10011100", "V"=>"10011101",
  "W"=>"000010", "X"=>"10010010", "Y"=>"10010011", "Z"=>"10010000", " "=>"101"}
table2 = {"00000"=>"A", "00001"=>"B", "00010"=>"C", "00011"=>"D", "00100"=>"E",
  "00101"=>"F", "00110"=>"G", "00111"=>"H", "01000"=>"I", "01001"=>"J",
  "01010"=>"K", "01011"=>"L", "01100"=>"M", "01101"=>"N", "01110"=>"O",
  "01111"=>"P", "10000"=>"Q", "10001"=>"R", "10010"=>"S", "10011"=>"T",
  "10100"=>"U", "10101"=>"V", "10110"=>"W", "10111"=>"X", "11000"=>"Y",
  "11001"=>"Z", "11010"=>" ", "11011"=>".", "11100"=>",", "11101"=>"-",
  "11110"=>"'", "11111"=>"?"}
table1 = table1.invert.sort_by {|a| a.first}
table2 = table2.invert

$<.readlines.map(&:chomp).each do |text|
  result = ""
  text.each_char {|c| result += table2[c]}
  
  convert = ->(txt, converted = "") {
    table1.each do |k, v|
      l = k.length
      converted = convert.(txt[l..-1], converted + v) if txt[0, l] == k
    end
    converted
  }
  puts convert.(result)
end


Measured memory_bytes: 7260
#include<iostream>

using namespace std;

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

int main(){
    int n;
    cin >> n;
    int a[n];
    rep(i, n) cin >> a[i];
    int x = 0;
    rep(i, n){
        if (i % 2 == 0) {
            x += a[i];
        }else{
            x -= a[i];
        }
    }
    int ans = x;
    
    rep(i, n){
        if (i == 0) {
            cout << ans;
            cout << " ";
            continue;
        }
        ans = 2 * a[i-1] - ans;
        cout << ans;
        cout << " ";
    }
    cout << endl;
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
#define ll          long long int
#define pll         pair<ll,ll>
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define mod         1000000007
#define inf         1000000000000000000LL
#define vl          vector<ll>
#define F           first
#define S           second
#define ld          long double
#define fix(n)      cout<<fixed<<setprecision(n)
#define rep(i,a,b)  for(ll i=a;i<b;i++)
#define pi          3.14159265358979323

bool edge[105][105];

void solve()
{
       ll n,k; cin>>n>>k;
       ll mx=(n-1)*(n-2)/2;
       if(k>mx)
       {
              cout<<-1<<endl;
              return;
       }
       for(ll i=2; i<=n; i++) edge[1][i]=1;
       // mx pairs right now
       ll dif=mx-k;
       // have to make mx-k connections
       for(ll i=2; i<=n && (dif>0); i++)
       {
              for(ll j=i+1; j<=n && (dif>0); j++)
              {
                     if(!edge[i][j])
                     {
                            edge[i][j]=1;
                            dif--;
                            //if(dif==0) break;
                     }
              }
              //if(dif==0)break;
       }
       ll cnt=0;
       vector<pll>ans;
       for(ll i=1; i<=n; i++)
       {
              for(ll j=i+1; j<=n; j++)
              {
                     if(edge[i][j])
                     {
                            cnt++;
                            ans.push_back({i,j});
                     }
              }
       }
       cout<<cnt<<endl;
       for(auto x:ans) cout<<x.F<<" "<<x.S<<endl;
}


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


Measured memory_bytes: 512
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <chrono>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <sstream>

using namespace std;


int main(int argc, char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(12);

    int h, w;
    cin >> h >> w;

    int sx, sy;
    int tx, ty;
    cin >> sx >> sy;
    cin >> tx >> ty;
    --sx, --sy;
    --tx, --ty;

    vector<string> M(h);
    for (int i = 0; i < h; ++i) {
        cin >> M[i];
    }

    const int INF = 1 << 28;
    vector<vector<int>> dis(h, vector<int>(w, INF));
    dis[sx][sy] = 0;

    deque<pair<int,int>> que;
    que.emplace_back(sx, sy);

    while (!que.empty()) {
        int x = que.front().first;
        int y = que.front().second;
        que.pop_front();
        if (x == tx && y == ty) {
            break;
        }

        for (int i = -2; i <= 2; ++i) {
            for (int j = -2; j <= 2; ++j) {
                int nx = x + i, ny = y + j;
                if (nx == x && ny == y) {
                    continue;
                }
                if (nx >= 0 && nx < h && ny >= 0 && ny < w && M[nx][ny] == '.') {
                    int w = 1;
                    if (abs(nx - x) + abs(ny - y) == 1) {
                        w = 0;
                    }
                    if (dis[nx][ny] > dis[x][y] + w) {
                        dis[nx][ny] = dis[x][y] + w;
                        if (w == 0) {
                            que.emplace_front(nx, ny);
                        } else {
                            que.emplace_back(nx, ny);
                        }
                    }
                }
            }
        }
    }

    if (dis[tx][ty] < INF) {
        cout << dis[tx][ty] << '\n';
    } else {
        cout << -1 << "\n";
    }

    return 0;
}

Measured memory_bytes: 8736
#include <iostream>
#include <algorithm>
#include <complex>

using namespace std;

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

  int cake[16];

  for (int i = 0; i < 16; i++) {
    if (i % 2 == 0) {
      if (a > 0) {
        cake[i] = 1;
        a--;
      }
    }
    else {
      if (b > 0) {
        cake[i] = 0;
        b--;
      }
    }
  }

  if (a <= 0 && b <= 0) {
      cout << "Yay!" << endl;
  }
  else {
      cout << ":(" << endl;
  }

  return 0;
}


Measured memory_bytes: 256
from itertools import product, permutations
expressions = [
	"((({0} {4} {1}) {5} {2}) {6} {3})",
	"(({0} {4} {1}) {5} ({2} {6} {3}))",
	"(({0} {4} ({1} {5} {2})) {6} {3})",
	"({0} {4} (({1} {5} {2}) {6} {3}))",
	"({0} {4} ({1} {5} ({2} {6} {3})))",
]
def solve(nums):
	for exp in expressions:
		for n in permutations(nums):
			for ops in product("+-*", repeat=3):
				f = exp.format(*(n + ops))
				if eval(f) == 10:
					return f
while True:
	line = raw_input()
	if line == "0 0 0 0": break
	res = solve(map(int, line.split()))
	if res is None:
		print 0
	else:
		print res

Measured memory_bytes: 4392
from collections import defaultdict
h, w = map(int, input().split())

a = [list(input()) for _ in range(h)]
d = defaultdict(int)
for i in range(h):
    for j in range(w):
        d[ord(a[i][j]) - ord('a')] += 1

odd = 0
two = 0
four = 0
for i in range(26):
    four += d[i] // 4
    d[i] %= 4
    if d[i] % 2 == 0:
        two += d[i] // 2
    else:
        odd += 1

if h % 2 == 1 and w % 2 == 1:
    if odd == 1 and two <= h // 2 + w // 2:
        print('Yes')
    else:
        print('No')
elif h % 2 == 1:
    if odd == 0 and two <= w // 2:
        print('Yes')
    else:
        print('No')
elif w % 2 == 1:
    if odd == 0 and two <= h // 2:
        print('Yes')
    else:
        print('No')
else:
    if odd == 0 and two == 0:
        print('Yes')
    else:
        print('No')


Measured memory_bytes: 9504
#include<algorithm>
#include<climits>
#include<cmath>
#include<iomanip>
#include<iostream>
#include<list>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<utility>
#include<vector>

using namespace std;

#define lint long long
#define REP(i, x, n) for(int i = x ; i < n ; i++)
#define rep(i, n) REP(i, 0, n)
#define repr(i, n) for(int i = n - 1 ; i >= 0 ; i--)
#define SORT(c) sort((c).begin(), (c).end())
#define SORT_INV(c) sort((c).begin(), (c).end(), greater<int>())
#define IINF (int)(1e9+10)
#define LLINF (lint)(1e18+10)

int main(){
    lint a, b, c, d, e, f;
    cin >> a >> b >> c >> d >> e >> f;
    lint water = max((f/(100*a))*(100*a), (f/(100*b))*(100*b)), sugar = 0;
    for(lint i = 0 ; i*100 <= f ; i += a){
        for(lint j = 0 ; j*100 <= f ; j += b){
            for(lint k = 0 ; k <= (i+j)*e ; k += c){
                for(lint l = 0 ; k+l <= (i+j)*e ; l += d){
                    if((i+j)*100+k+l > f){
                        break;
                    }
                    if(sugar*((i+j)*100+k+l) < (water+sugar)*(k+l)){
                        water = (i+j)*100;
                        sugar = k+l;
                    }
                }
            }
        }
    }
    cout << water+sugar << " " << sugar << endl;
    return 0;
}

Measured memory_bytes: 256
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <queue>
#include <algorithm>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <unordered_map>
#include <unordered_set>
#include <cmath>
#include <cstdlib>
#include <memory.h>
#include <ctime>
#include <bitset>

using namespace std;

#define ABS(a) ((a>0)?a:-(a))
#define MIN(a,b) ((a<b)?(a):(b))
#define MAX(a,b) ((a<b)?(b):(a))
#define FOR(i,a,n) for (int i=(a);i<(n);++i)
#define FI(i,n) for (int i=0; i<(n); ++i)
#define pnt pair <int, int>
#define mp make_pair
#define PI 3.1415926535897
#define MEMS(a,b) memset(a,b,sizeof(a))
#define LL long long
#define U unsigned

LL solve(int h, int w) {
	LL res = 1000000000000000000ll;
	FOR(i, 1, h) {
		LL s1 = (i * 1ll * w);
		int left = h - i;
		if (left > 1) {
			LL val1 = left / 2;
			LL val2 = left - val1;
			LL s2 = val1*w;
			LL s3 = val2*w;
			LL nowRes = ABS(s1 - s2);
			nowRes = max(nowRes, ABS(s1 - s3));
			nowRes = max(nowRes, ABS(s2 - s3));
			res = min(res, nowRes);
		}
		if (w > 1) {
			LL val1 = w / 2;
			LL val2 = w - val1;
			LL s2 = val1*left;
			LL s3 = val2*left;
			LL nowRes = ABS(s1 - s2);
			nowRes = max(nowRes, ABS(s1 - s3));
			nowRes = max(nowRes, ABS(s2 - s3));
			res = min(res, nowRes);
		}
	}
	return res;
}

int main()
{
#ifdef Fcdkbear
	freopen("in.txt", "r", stdin);
	//freopen("out.txt", "w", stdout);
	double beg = clock();
#endif

	int h, w;
	cin >> h >> w;
	LL res = min(solve(h, w), solve(w, h));
	cout << res << endl;

#ifdef Fcdkbear
	double end = clock();
	fprintf(stderr, "*** Total time = %.3lf ***\n", (end - beg) / CLOCKS_PER_SEC);
#endif
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int a,b,c;
	scanf("%d %d %d",&a,&b,&c);
	if(a==b && a==c){
		printf("1\n");
	}
	else if(a==b || b==c || c==a){
		printf("2\n");
	}
	else{
		printf("3\n");
	}
	return 0;
}

Measured memory_bytes: 128
import math
a, b, h, m = map(int, input().split())
angle_a = ((60 * h + m)/360)* math.pi
angle_b = (m / 30) * math.pi
l = a**2 + b**2 - 2*a*b*math.cos(angle_a-angle_b)
ans = l**0.5
print(ans)

Measured memory_bytes: 9440
#include<stdio.h>

int main(void){
    int h, m, s;
    h = 0;
    m = 0;

    scanf("%d", &s);
    if(s >= 60){
        if(s >= 3600){
            h = s/3600;
            s %= 3600;
        }
        m = s/60;
        s %= 60;
    }
    printf("%d:%d:%d\n", h, m, s);
    return 0;
}


Measured memory_bytes: 2140
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <cmath>
#include <complex> // complex<double> a(1.2 , 2.3);// real(): 1.2, imag()2.3
using namespace std;

#define MOD 1000000007
#define ll long long
#define ld long double
#define FOR(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rmsame(a) sort(all(a)),a.erase(unique(all(a)), a.end())
#define rmvector(a,b) rep(i,a.size())rep(j,b.size())if(a[i]==b[j]){a.erase(a.begin()+i);i--;break;}
template<typename X> bool exist(vector<X> vec, X item){return find(all(vec), item)!=vec.end();}

bool D[10];

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

  ll N, K;
  cin >> N >> K;
  //vector<ll> D;
  rep(i,K){
    ll inp; cin >> inp;
    D[inp]=true;
  }
  N--;

  bool flag = true;
  while(flag){
    flag = false;
    N++;
    string str= to_string(N);
    rep(i,str.size()){
      if(D[(str[i]-'0')])flag=true;
    }
  }

  cout << N << endl;
  //cout << fixed << setprecision(16) << ans << endl;
  return 0;
}


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

using namespace std;

#define ll long long
#define mod 1000000007

void solve(){
	int n,x,t;
	cin>>n>>x>>t;
	int d = n / x;
	int rem = n % x;
	cout<<d * t + (rem > 0 ? t:0);
}

int main(){
	int t = 1;
	while(t--){
		solve();
	}
	return 0;
}

Measured memory_bytes: 3592
import fractions
def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)
n = int(input())
res = -1
for i in range(n):
    t = int(input())
    if res == -1:
        res = t
    else:
        res = lcm(res, t)
print(res)

Measured memory_bytes: 64620
package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	D := ReadInt()
	s := ""
	switch D {
	case 25:
		s = "Christmas"
	case 24:
		s = "Christmas Eve"
	case 23:
		s = "Christmas Eve Eve"
	case 22:
		s = "Christmas Eve Eve Eve"
	}
	fmt.Println(s)
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int)       { Scan(&i); return }
func ReadString() (s string) { Scan(&s); return }
func ReadInts(n int) []int {
	v := make([]int, n)
	for i := 0; i < n; i++ {
		Scan(&v[i])
	}
	return v
}


Measured memory_bytes: 1840
#include<stdio.h>
int main(){
    int A[100];
    int N,i,sw;

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

    sw=selectionSort(A,N);
    for(i=0;i<N;i++){
        if(i>0){
            printf(" ");
        }
        printf("%d",A[i]);
    }
    printf("\n");
    printf("%d",sw);
    printf("\n");
    return 0;
}
int selectionSort(int a[],int n){
    int i,j,sw=0,minj,t;
    for(i=0;i<n;i++){
        minj=i;
        for(j=i;j<n;j++){
            if(a[j]<a[minj]){
                minj=j;
            }
        }
        if(minj!=i){
            t=a[i];
            a[i]=a[minj];
            a[minj]=t;
            sw++;
        }
    }
    return sw;
}

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

int main()
{
    int n, m, l, i, I, x = 0, y = 0, z;
    long long a[101][101], b[101][101], c[101][101] = {0};

    scanf("%d%d%d", &n, &m, &l);
    
    while(y < n+m)
    {
    	x = 0;
    	while(scanf("%d", &z))
    	{
    		if(y < n)
    		{
    			a[y][x] = z;
			}
			else
			{
				b[y-n][x] = z;
			}
			char c = getchar();
			if(c == '\n') break;
			x++;
		}
		y++;
	}
	
    for(i = 0 ; i < n ; i++)
    {
        for(I = 0 ; I < l ; I++)
        {
            for(y = 0 ; y < m ; y++)
            {
                c[i][I] += (a[i][y]*b[y][I]);
            }
        }
    }
    
    for(i = 0 ; i < n ; i++)
    {
        for(I = 0 ; I < l ; I++)
        {
            printf("%lld", c[i][I]);
            if(I != l-1) printf(" ");
        }
        printf("\n");
    }
    return 0;
}


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

#define ll long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define uniqueV(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define debug3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define debugB(value, size) cerr<<#value<<": "<<bitset<size>(value) << endl;
#define line() cerr << "---------------" << endl;

const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, -1, 1};
const double PI = 3.14159265358979323846;

template<typename T>
void printA(vector<T> &printArray, char between = ' ') {
   int paSize = printArray.size();
   for (int i = 0; i < paSize; i++) { cerr << printArray[i] << between;}
   if (between != '\n') {cerr << endl;}
}

// ------------------------------------------------------------------------------------------

string s;
int k;
set<string> S;

int main() {
   cin >> s >> k;
   int n = s.size();

   rep (i, n) {
      // 1文字
      string t = "";
      t += s[i];
      S.insert(t);

      // 2文字
      t = s.substr(i, 2);
      if (t.size() == 2) S.insert(t);

      // 3文字
      t = s.substr(i, 3);
      if (t.size() == 3) S.insert(t);

      // 4文字
      t = s.substr(i, 4);
      if (t.size() == 4) S.insert(t);

      // 5文字
      t = s.substr(i, 5);
      if (t.size() == 5) S.insert(t);
   }

   int cnt = 1;
   for (string tt : S) {
      if (cnt == k) {
         cout << tt << endl;
         return 0;
      }
      cnt++;
      // debug(tt)
   }


   // rep (i, n) {
   //    string t = "";
   //    repp (j, i, n) {
   //       t.push_back(s[j]);
   //       S.insert(t);
   //    }
   // }

   // int cnt = 1;
   // for (string tt : S) {
   //    if (cnt == k) {
   //       cout << tt << endl;
   //       return 0;
   //    }
   //    cnt++;
   // }


   return 0;
}

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

typedef long long ll;

using namespace std;

int main(){
 ll A,B,C; cin >> A >> B >> C;
  
  ll a = A; ll b = B; ll c = C;
  int cnt = 0;
  while( a % 2 == 0 && b % 2 == 0 && c % 2 == 0){
    ll s = a; ll t = b; ll u = c;
    
    a = ( s + t ) / 2; b = ( t + u ) / 2; c = ( u + s) / 2;
    cnt++;
    if( a == A && b == B && c == C){ cout << "-1" << endl; return 0;}
  }
  
  cout << cnt << endl; return 0;}

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

ll calc(ll h){
  if (h == 1)
    return 1;
  return 2 * calc(h/2) + 1;
}

int main(void)
{
  ll h;
  cin >> h;
  
  cout << calc(h) << endl;
  
  return 0;
}

Measured memory_bytes: 3632
use std::io;
use std::str::FromStr;

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

fn input_vec() -> Vec<usize> {
    let mut line: String = String::new();
    io::stdin().read_line(&mut line);
    line.split_whitespace().map(|s| s.parse().unwrap()).collect()
}

fn main() {
    let n: usize = input();
    let mut a_vec = input_vec();
    let mut nums = vec![false; 1_000_001];

    a_vec.sort_by(|x, y| y.cmp(&x));
    
    let mut i = 0;
    while i < a_vec.len() {
        let a = a_vec[i];
        if nums[a] {
            nums[a] = false;
            while i < a_vec.len() && a_vec[i] == a {
                i += 1;
            }
            if i == a_vec.len() {
                break;
            }
        }
        let a = a_vec[i];
        nums[a] = true;
        for i in 2..1_000_000 {
            if a * i > 1_000_000 {
                break;
            }
            nums[a * i] = false;
        }
        i += 1;
    }
    let mut count = 0;
    for n in nums {
        if n {
            count += 1;
        }
    }
    println!("{}", count);
}


Measured memory_bytes: 5272
#include <iostream>
#include <stack>
#include <map>
#include <algorithm>
#include <queue>
#include <math.h>
#include <string.h>

using namespace std;

int B, A;
int t[2000];

int main(int argc, char** argv) {
    cin >> A >> B;
    int d = B - A;
    t[0] = 0;
    for (int i=1; i<=999; i++) {
        t[i] = t[i - 1] + i;
    }
    cout << t[d - 1] - A << endl;
    // cout << t[d] - B << endl;
}

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

using namespace std ; 

const int N = 1e6 + 7 ; 

int main(){
    ios_base::sync_with_stdio(0); 
    cin.tie(0) ; 
   // freopen("in.in" , "r" , stdin) ; 
    double r ; 
    cin>>r ; 
    cout<<fixed<<setprecision(20) << 2.0 * acos(-1)* r ;

    return 0 ; 
}

Measured memory_bytes: 3804
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int a=sc.nextInt();
        int b=sc.nextInt();
        for(int i=1;i<=10;i++){
            b*=n;
            b-=a;
        System.out.println(b);
            
        }
    }
}


Measured memory_bytes: 22868
# include <iostream>
# include <algorithm>
#include <array>
# include <cassert>
#include <cctype>
#include <climits>
#include <numeric>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <tuple>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
# include <chrono>
# include <random>
# include <limits.h>
# include <unordered_map>
# include <unordered_set>
# include <deque>
# include <cstdio>
# include <cstring>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
constexpr long long MOD = 1000000000 + 7;
constexpr long long INF = std::numeric_limits<long long>::max();
const double PI = acos(-1);
#define fir first
#define sec second
typedef pair<LL, LL> Pll;
typedef pair<LL, pair<LL, LL>> Ppll;
typedef pair<LL, pair<LL, bitset<100001>>> Pbll;
typedef pair<LL, pair<LL, vector<LL>>> Pvll;
typedef pair<LL, LL> Vec2;
struct Tll { LL first, second, third; };
typedef pair<LL, Tll> Ptll;
#define rep(i,rept) for(LL i=0;i<rept;i++)
#define Mfor(i,mf) for(LL i=mf-1;i>=0;i--)
LL h, w, n, m, k, s, t, q, ans, sum, last, cnt,d[1000000],c[1000000];
struct Edge { LL to,cost; };
Pll a[1000000], b[1000000];
vector<Edge>vec[100000];
string str;
bool f=0;
void YN(bool f) {
	if (f)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;
}
void yn(bool f) {
	if (f)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}
int main() {
	cin >> n >> m;
	rep(i, n) {
		cin >> a[i].first >> a[i].second;
	}
	rep(i, m) {
		LL x, y;
		cin >> x >> y;
		b[i].first = x, b[i].second = y;
	}
	rep(i,n){
		sum = INF;LL  num = 0;
		rep(j, m) {
			if (abs(a[i].first - b[j].first) + abs(a[i].second - b[j].second) < sum) {
				sum = abs(a[i].first - b[j].first) + abs(a[i].second - b[j].second);
				num = j + 1;
			}
		}
		cout << num << endl;
	}
	return 0;
}

Measured memory_bytes: 6400
#include <iostream>
#include<time.h>
#include<string>
#include<cstring>
#include <cstdio>
#include<utility>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<bitset>
#include<queue>
#include<stack>
#include<set>
#include <limits>
#include <climits>
#include <numeric>
#include<cassert>
#include<cctype>
#include<iterator>
#include<unordered_map>
#include <cassert>
#include <bit>
#include <cstdint>
using namespace std;
typedef long long ll;
typedef unsigned long long LL;
typedef vector<ll>VI;
typedef vector<bool>VB;
typedef pair<ll,ll>P;
typedef pair<double,double>P_D;
#define VV(T) vector<vector<T>>
#define PI 3.1415926535897932384626433832795
#define rep(i, n) for (ll i = 0; i < (ll)n; i++)
#define reprev(i, n) for (ll i = (ll)n - 1; i >= 0; i--)
#define bitrep(bit,A) for(int bit=A; ;bit=(bit-1)&A)
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) (ll)((a).size())
#define c_max(a, b) (((ll)a)>((ll)b)?(a):(b))
#define c_min(a,b) (((ll)a)<((ll)b)?(a):(b))
#define chmax(x,a) x=c_max(x,a)
#define chmin(x,a) x=c_min(x,a)
#define vmax(v) *max_element(ALL(v))
#define vmin(v) *min_element(ALL(v))
#define SORT(c) stable_sort(ALL(c))
#define $(x) {cout<<#x<<" = " <<(x)<<endl;}
#define fi first
#define se second
#define MAX 100100//5
#define MAX2 200100
#define MAX_6 1001001//6
#define MAX_7 10010010//7
#define SENTINEL 2000000000//9
#define NIL -1
const int MOD = 1000000007;
#define INF 1<<30
#define INFTY 1LL<<61
#define MAX_INT INT_MAX
#define Endl '\n'
#define greater greater<int>()
inline ll GCD(ll a,ll b){return b?GCD(b,a%b):a;}
inline ll lcm(ll a,ll b){return a*b/GCD(a,b);}
using Edge=pair<int,ll>;
using Graph=vector<vector<ll> >;//ll or Edge
using Edge=pair<int,ll>;
//const int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
// g++ -o a a.cpp -Wall -lm -std=c++17

int main(){
    ll n;cin>>n;
    int a[MAX2];
    rep(i,n)cin>>a[i];
    sort(a,a+n,greater);
    ll ans=0;
    for(int i=1;i<n;i++){
        ans+=1LL*a[i/2];

    }
    cout<<ans<<endl;
}

Measured memory_bytes: 4364
#include <iostream>
#include <math.h>
#include <numeric>
#include <vector>
#include <algorithm>

using namespace std;
#define n_max 100000

int main()
{
    int N; 
    long int sum = 0;
    vector<int> a;

    cin >> N;

    for(int i = 0; i < 3 * N; i++){
        int tmp;
        cin >> tmp;
        a.push_back(tmp);
    }

    sort(a.begin(), a.end());

    for(int i = 3 * N - 2; i > N - 1 ; i-=2) {
        //cout << "i -> " << i << ", a[i] -> " << a[i] << endl;
        sum += a[i];
    }

    cout << sum << endl;

    return 0;
}


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

#define INF 1234567890
#define ll long long

int N, M, K;
int g[11][1111];

int main()
{
	scanf("%d %d %d", &N, &M, &K);
	for(int i=0; i<N; i++)
		for(int j=0; j<M; j++)
			scanf("%1d", &g[i][j]);

	int res = INF;
	for(int b=0; b<(1<<N-1); b++)
	{
		vector<vector<int> > v;
		int sy = 0, ey;
		for(int k=0; k<N-1; k++)
		{
			if (b&(1<<k))
			{
				ey = k;
				v.push_back(vector<int>(M, 0));
				for(int i=sy; i<=ey; i++)
					for(int j=0; j<M; j++)
						v.back()[j] += g[i][j];
				sy = k+1;
			}
		}
		if (sy < N)
		{
			ey = N-1;
			v.push_back(vector<int>(M, 0));
			for(int i=sy; i<=ey; i++)
				for(int j=0; j<M; j++)
					v.back()[j] += g[i][j];
		}

		// printf("%d :\n", b);
		// for(int i=0; i<v.size(); i++)
		// {
		// 	for(int j=0; j<M; j++)
		// 		printf("%d ", v[i][j]);
		// 	printf("\n");
		// }
		// printf("\n");

		vector<int> sum(v.size(), 0);
		int cnt = __builtin_popcount(b);
		for(int j=0; j<M; j++)
		{
			int ok = 1;
			for(int i=0; i<v.size(); i++)
			{
				if (v[i][j] > K) cnt = INF;
				sum[i] += v[i][j];
				if (sum[i] > K)
				{
					ok = 0;
					break;
				}
			}
			if (ok == 0)
			{
				for(int i=0; i<v.size(); i++)
					sum[i] = v[i][j];
				cnt++;
			}
		}
		res = min(res, cnt);
	}
	printf("%d", res);
	return 0;
}

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

using namespace std;


class combination {
public:

//N????????§?????????????????°??£??\??????
	combination( long long int combinationThreshold = 1e7 ) {
		( *this ).combinationThreshold = combinationThreshold + 2;
	}

	//a^p % mod
	long long int powmod( long long int A, long long int P, long long int M = LLONG_MAX ) {
		long long int ans = 1;
		long long int mul = A;
		for( ; P > 0; P >>= 1, mul = ( mul*mul ) % M ) {
			if( ( P & 1 ) == 1 ) ans = ( ans*mul ) % M;
		}
		return ans;
	}

	//nCk mod m
	long long int cb( long long int N, long long int K, long long int M = LLONG_MAX ) {
		if( N < combinationThreshold ) {// ???????¨????O(N)??????????????????O(1)
			if( inv.size() == 0 ) {
				inv = vector<long long int>( combinationThreshold );
				inv[1] = 1;
				for( long long int i = 2; i < combinationThreshold; i++ ) {
					inv[i] = M - ( M / i )*inv[M%i] % M;
				}
				fact = vector<long long int>( combinationThreshold );
				fact[0] = 1;
				revFact = vector<long long int>
					( combinationThreshold );
				revFact[0] = 1;
				for( long long int i = 1; i < combinationThreshold; i++ ) {
					fact[i] = ( fact[i - 1] * i ) % M;
					revFact[i] = ( revFact[i - 1] * inv[i] ) % M;
				}
			}
			return ( ( ( fact[N] * revFact[K] ) % M )*revFact[N - K] ) % M;
		} else {
			return cbOnce( N, K, M );
		}
	}

	//???????????????????????? O(K + log(M))
	long long int cbOnce( long long int N, long long int K, long long int M = LLONG_MAX ) {
		//if( K > N / 2 ) return cb( N, N - K, M );
		long long int ans = 1;
		long long int div = 1;
		for( long long int i = 0; i < K; i++ ) {
			ans *= N - i;
			ans %= M;
			div *= i + 1;
			div %= M;
		}
		ans *= powmod( div, M - 2, M );
		return ans%M;
	}

private:
	vector<vector<long long int>>C;//3000??\????????????
	vector<long long int>fact;//??????
	vector<long long int>revFact;//???????????????
	vector<long long int>inv;//mod p??§?????????

	long long int combinationThreshold;//N????????§?????????????????°??\?????????
};


long long int mod = 1000000007LL;

int main() {
	long long int N, M, K;
	cin >> N >> M >> K;
	combination cb( N + M + 2 * K );
	long long int ans = 0;
	for( long long int i = 0; i <= K; i++ ) {
		long long int j = K - i;
		long long int X = ( cb.cb( N + 2 * i, i, mod ) *( N + 1 ) % mod*cb.powmod( ( N + i + 1 ), mod - 2, mod ) ) % mod;
		long long int Y = ( cb.cb( M + 2 * j, j, mod ) *( M + 1 ) % mod*cb.powmod( ( M + j + 1 ), mod - 2, mod ) ) % mod;
		ans += X*Y%mod*cb.cb( N + M + 2 * K, N + 2 * i, mod );
		ans %= mod;
	}
	cout << ans << endl;

}

Measured memory_bytes: 8056
#include "bits/stdc++.h"

using namespace std;

//using Matrix = vector< vector<int> >;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9 + 10;
//const ll INF = 1e18 + 10LL;
int dx[5] = {0, 0, 1, -1, 0}, dy[5] = {1, -1, 0, 0, 0};
const double EPS = 1e-10;
bool cmp(P a, P b) { return a.second < b.second; } //End sort (Interval scheduling problem)
ll MOD = 1e9 + 7;

int n;
string s;

bool can;

string gen(string str) {

	for (int i = 2; i < n; i++) {
		if (str[i - 1] == 'S' && s[i - 1] == 'o') str += str[i - 2];
		else if (str[i - 1] == 'S' && s[i - 1] == 'x') {
			if (str[i - 2] == 'S') str += 'W';
			else str += 'S';
		}
		else if (str[i - 1] == 'W' && s[i - 1] == 'o') {
			if (str[i - 2] == 'S') str += 'W';
			else str += 'S';
		}
		else if (str[i - 1] == 'W' && s[i - 1] == 'x') {
			str += str[i - 2];
		}
	}

	return str;

	/*
	if (str[i - 1] == 'S' && s[i - 1] == 'o') return gen(str + str[i - 2], i + 1);
	else if (str[i - 1] == 'S' && s[i - 1] == 'x') {
		if (str[i - 2] == 'S') return gen(str + 'W', i + 1);
		else return gen(str + 'S', i + 1);
	}
	else if (str[i - 1] == 'W' && s[i - 1] == 'o') {
		if (str[i - 2] == 'S') return gen(str + 'W', i + 1);
		else return gen(str + 'S', i + 1);
	}
	else if (str[i - 1] == 'W' && s[i - 1] == 'x') {
		return gen(str + str[i - 2], i + 1);
	}
	*/
}

bool check(string str) {
	str += str.substr(0, 2);

	for (int i = 1; i <= n; i++) {
		if (str[i] == 'S') {
			if (s[i % n] == 'o' && str[i - 1] != str[i + 1]) return false;
			if (s[i % n] == 'x' && str[i - 1] == str[i + 1]) return false;
		}
		else if (str[i] == 'W') {
			if (s[i % n] == 'o' && str[i - 1] == str[i + 1]) return false;
			if (s[i % n] == 'x' && str[i - 1] != str[i + 1]) return false;
		}
	}

	return true;
}

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

	string S = gen("SS");
	if (check(S)) {
		cout<< S <<endl;
		return 0;
	}

	S.clear();
	S = gen("SW");
	if (check(S)) {
		cout<< S <<endl;
		return 0;
	}

	S.clear();
	S = gen("WS");
	if (check(S)) {
		cout<< S <<endl;
		return 0;
	}

	S.clear();
	S = gen("WW");
	if (check(S)) {
		cout<< S <<endl;
		return 0;
	}

	cout<< -1 <<endl;
	
	return 0;
}

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

constexpr int inf = 1e9;
constexpr ll linf = 1e18;

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

    int n; cin >> n;

    static int imos[1001][1001];
    memset(imos, 0x00, sizeof(imos));

    for (int i = 0; i < n; i++) {
        int x1, y1, x2, y2;
        cin >> x1 >> y1 >> x2 >> y2;
        imos[x1][y1]++;
        imos[x1][y2]--;
        imos[x2][y1]--;
        imos[x2][y2]++;
    }

    for (int i = 0; i <= 1000; i++) {
        for (int j = 1; j <= 1000; j++) {
            imos[i][j] += imos[i][j - 1];
        }
    }
    for (int i = 1; i <= 1000; i++) {
        for (int j = 0; j <= 1000; j++) {
            imos[i][j] += imos[i - 1][j];
        }
    }
    int ans = 0;
    for (int i = 0; i <= 1000; i++) {
        ans = max(ans, *max_element(imos[i], imos[i] + 1001));
    }

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


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

int main() {
  int N, D;
  cin >> N >> D;
  vector<vector<int>> v(N, vector<int>(D));
  for (int i = 0; i < N; i++)
    for (int j = 0; j < D; j++) cin >> v[i][j];

  int ans = 0;
  for (int i = 0; i < N; i++) {
    for (int j = i + 1; j < N; j++) {
      double d = 0.0;
      for (int k = 0; k < D; k++)
        d += pow(v[i][k] - v[j][k], 2);
      d = sqrt(d);
      if (d == floor(d)) ans++;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256