akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define REV(v) reverse(v.begin(), v.end());
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, start, stop) for (int i = start; i < stop; i++)
#define FORR(i, start, stop) for (int i = start; i > stop; i--)
#define SORT(v, n) sort(v, v + n);
#define SORTR(v, n) sort(v, v + n,greater<int>());
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.begin(), v.end(),greater<int>());
#define REMOVE(v,n) remove(vector<int> v,v+v.size(),int n)
#define ll long long
#define ull unsigned long long
#define pb(a) push_back(a)
#define INF 999999999
#define V(v,i,j) vector(v.begin() + i, v.begin() + j)
#define INSERT(va,vb) va.insert(va.end(), vb.begin(), vb.end())
using namespace std;
typedef vector<int> vint;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;
int dy[] = {0, 0, 1, -1};
int dx[] = {1, -1, 0, 0};
const int MOD = 1000000007;
void chmin(int &a, int b) { if (a > b) a = b; }

//vector< vector<int> > v (size1, vector<int>(size2) );

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

    int N,T;
    cin>>N>>T;
    int c,t;
    ll ans=100000;
    FOR(i,0,N){
        cin>>c>>t;
        if((t<=T) && (c<=ans)){
            ans=c;
        }
    }
    
    if(ans==100000) cout<<"TLE"<<endl;
    else cout<<ans<<endl;


}

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

typedef long long ll;

int main(){
  ll n;
  cin >> n;
  ll a,b,c;
  for(ll i=1;i<=3500;i++){
    for(ll j=1;j<=3500;j++){
      if(4*i*j-i*n-j*n>0){
        if((i*j*n)%(4*i*j-i*n-j*n)==0){
          a=i,b=j,c=(i*j*n)/(4*i*j-i*n-j*n);
        }
      }
    }
  }
  cout << a << " " << b << " " << c << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
	int n;
	long long int W;
	scanf("%d %lld", &n, &W);
	int i, j;
	long long int w[102];
	int v[102];
	for (i = 0; i < n; i++)
		scanf("%lld %d", &w[i], &v[i]);
	long long int dp[2][100005];
	for (i = 0; i < 100005; i++)
		dp[0][i] = dp[1][i] = -1;
	dp[0][0] = dp[1][0] = 0;
	for (i = 0; i < n; i++)
	{
		for (j = 0; j < 100005; j++)
		{
			if (dp[0][j] >= 0)
			{
				if (dp[0][j] + w[i] <= W)
				{
					if (dp[1][j + v[i]] < 0)
						dp[1][j + v[i]] = dp[0][j] + w[i];
					if (dp[1][j + v[i]] > dp[0][j] + w[i])
						dp[1][j + v[i]] = dp[0][j] + w[i];
				}
			}
		}
		for (j = 0; j < 100005; j++)
			dp[0][j] = dp[1][j];
	}
	int ans = -1;
	for (i = 0; i < 100005; i++)
		if (dp[0][i] >= 0)
			ans = i;
	printf("%d\n", ans);
	return 0;
}

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

using namespace std;


int main (){
	int arr[4];
	int i;
	for(i=0; i<3; i++){
		cin>>arr[i];
	}
	sort(arr, arr+i);

	if(arr[0] == arr[1] && (arr[0] != arr[2] && arr[1] != arr[2])){
		cout<<"Yes"<<endl;
	}
	else if(arr[2] == arr[1] && (arr[0] != arr[2] && arr[1] != arr[0])){
		cout<<"Yes"<<endl;
	}
	else if(arr[2] == arr[0] && (arr[1] != arr[2] && arr[1] != arr[0])){
		cout<<"Yes"<<endl;
	}
	else cout<<"No"<<endl;

	return 0;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

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

  for(int i = a ; i < a+k && i < b+1 ; i++ ){
    cout << i << endl;
  }
  
  int dif = (b-a+1)-2*k;
  
  if(dif > 0){
    for(int j = b-k+1 ; j < b+1 ; j++){
      cout << j << endl;
    }
  }else{
  	for(int j = b-dif-k+1 ; j < b+1 ; j++){
      cout << j << endl;
  	}
  }
  
}

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

int main(){
    int n, x, h, i, j, ans;
    while(cin >> n >> x && n >= 3 && x >= 0){
        ans = 0;
        for(h = 1; h <= n - 2; h++){
            for(i = h + 1; i <= n - 1; i++){
                for(j = i + 1; j <= n; j++){
                   if(h + i + j == x)
                       ans++;
                }
            }
        }
        cout << ans << endl;
    }
}

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

// template {{{  0 
// using {{{ 1
using ll = long long int;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vii = vector<pii>;
using vll = vector<pll>;
// }}} 1
// definition {{{ 1
// scaning {{{ 2
#define Scd(x) scanf("%d", &x)
#define Scd2(x,y) scanf("%d%d", &x, &y)
#define Scd3(x,y,z) scanf("%d%d%d", &x, &y, &z)
#define Scll(x) scanf("%lld", &x)
#define Scll2(x,y) scanf("%lld%lld", &x, &y)
#define Scll3(x,y,z) scanf("%lld%lld%lld", &x, &y, &z)
#define Scc(c) scanf("%c", &c);
#define Scs(s) scanf("%s", s);
#define Scstr(s) scanf("%s", &s);
// }}} 2
// constants {{{ 2
#define EPS (1e-7)
#define INF (2e9)
#define PI (acos(-1))
// }}} 2
// systems {{{ 2
#define Repe(x,y,z) for(int x = z; x < y; x++)
#define Rep(x,y) Repe(x,y,0)
#define RRepe(x,y,z) for(int x = y-z-1; x >= 0; x--)
#define RRep(x,y) RRepe(x,y,0)
// }}} 2
// output {{{ 2
#define YesNo(a) (a)?printf("Yes\n"):printf("No\n")
#define YESNO(a) (a)?printf("YES\n"):printf("NO\n")
#define SpaceNewLine(a) Rep(i,a.size())cout<<a[i]<<(i==a.size()-1?'\n':' ')
// }}} 2
// }}} 1
// input {{{ 1
// }}} 1
// }}} 0

int main() {
    // setup {{{ 1
    cin.tie(0);
    ios::sync_with_stdio(false);
    // }}}

    int N;
    Scd(N);

    bool ans = 1;

    int cnt = 0;

    int tn = N;
    while( tn ) { if( tn&1 ) cnt++; tn >>=1; }

    if( cnt == 1 ) ans = false;

    YesNo(ans);

    if( ans ){
        int NN = N;
        if( N % 2 == 0 ){
            int n = 0x10000000;
            while( (n & N) == 0 ) n >>= 1;
            printf ("%d %d\n", N, N-n+1);
            printf ("%d %d\n", N+N, N+n);
            NN--;
        }
        while( NN > 1 ){
            printf("%d %d\n", NN-1, NN );
            printf("%d %d\n", NN, 1 );
            printf("%d %d\n", 1, NN-1+N );
            printf("%d %d\n", NN-1+N, NN+N );
            NN -= 2;
        }
        printf ("%d %d\n", N+1,2 );
    }

    return 0;
}



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

int n, k, temp;
bool is[10];

int check(int num)
{
	bool flag = true;
	while(num)
	{
		if(flag == false)
			break;
		if(is[num % 10])
			flag = false;
		num /= 10;
	}
	return flag;
}

int main()
{
	cin >> n >> k;
	for(int i = 1; i <= k; ++i)
	{
		cin >> temp;
		is[temp] = true;
	}
	int ans = n;
	while(check(ans) == false)
		ans++;
	cout << ans << endl;
} 

Measured memory_bytes: 256
#include <stdio.h>
#define N 10000000
#define MAX 100
#define WHITE 0
#define BLACK 2
#define GRAY 1

void sssp(void);
int A[MAX][MAX]={0},color[MAX],d[MAX],p[MAX];
int i,j,n,m,min;

int main(){
  int u,v,c,k;
  
  scanf("%d",&n);
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      A[i][j] = N;
    }
  }
  for(i=0;i<n;i++){
    scanf("%d %d", &u,&k);
    for(j=0;j<k;j++){
      scanf("%d %d",&v,&c);
      A[u][v] = c;
    }
  }

  sssp();

  return 0;
}


void sssp(){
  int i,m,k;
  
  for(i=0;i<n;i++){
    d[i] = N;
    color[i] = WHITE;
  }
  d[0] = 0;
  color[0] = GRAY;

  while(1){
    min = N;
    m = -1;
    for(i=0;i<n;i++)
      if(d[i] < min && color[i] != BLACK){
        m = i;
        min = d[i];
      }
      if(m == -1) break;
      
    
    color[m] = BLACK;
    
    for(k=0;k<n;k++){
      if(color[k] != BLACK && A[m][k] != N){
        if(d[k] > d[m] + A[m][k]){
          d[k] = d[m] + A[m][k];
          color[k] = GRAY;
        }
      }
    }
  }

  for(i=0;i<n;i++){
    if(d[i] == N){
      printf("%d -1\n",i);
    }
    else{
      printf("%d %d\n",i,d[i]);
    }
  }
  
}



Measured memory_bytes: 2048
#include<bits/stdc++.h>
 
using namespace std;
 
struct I{
    I(){
        ios::sync_with_stdio(false);cin.tie(0);
    }
}cww;
typedef long long  LL;
typedef vector<LL> V;
#define cnt(l,r) (__builtin_popcountll(l)+__builtin_popcountll(r))
typedef tuple<LL,LL> P;
typedef map<P,int> Map;
int dfs(LL rest1,LL rest2,V &v1,V &v2,Map &memo){
    // cout<<rest1<<" "<<rest2<<endl;
    if(cnt(rest1,rest2)==1)return 0;
    if(memo.count(P(rest1,rest2)))
        return memo[P(rest1,rest2)];
    int res=114514;
    int n=v1.size();
    for(int i=0;i<n;i++){
        int ans=0;
        LL nxt1,nxt2;
        nxt1=rest1&v1[i];
        nxt2=rest2&v2[i];
        if(nxt1==rest1&&nxt2==rest2)continue;
        if(nxt1==0&&nxt2==0)continue;
        ans=max(ans,1+dfs(nxt1,nxt2,v1,v2,memo));
        nxt1=rest1-nxt1;
        nxt2=rest2-nxt2;
        ans=max(ans,1+dfs(nxt1,nxt2,v1,v2,memo));
        res=min(res,ans);
    }   
    return memo[P(rest1,rest2)]=res;
}
int main(){
    for(int n,m;cin>>n>>m,n+m;){
        V v1(n,0),v2(n,0);
        for(int i=0;i<m;i++){
            string s;
            cin>>s;
            for(int j=0;j<n;j++){
                if(s[j]=='1'){
                    if(i<64)
                        v1[j]|=(1ll<<i);
                    else
                        v2[j]|=(1ll<<(i-64));
                }
            }
        }
        Map memo;
        LL r1=1,r2=1;
        if(m<=63){
            r1=(r1<<m)-1;
            r2=0;
        }
        else if(m==64){
            r1=-1;
            r2=0;
        }
        else if(m==128){
            r1=-1;
            r2=-1;
        }
        else{
            r1=-1;
            r2=(r2<<(m-64))-1;
        }
        cout<<dfs(r1,r2,v1,v2,memo)<<endl;
    }
    return 0;
}
  

Measured memory_bytes: 4364
import java.util.Scanner;

class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int num =sc.nextInt();
		int count;
		
		int number[][]= new int[num][3];
		int score[]=new int[num];
		
		for(int i=0; i<num; i++)
			for(int j=0; j<3; j++)
				number[i][j]=sc.nextInt();
		
		
		for(int i=0; i<3; i++){    //何回目？
			for(int j=0; j<num; j++){     //今どこ参照してる？
				int sco=number[j][i];     //一致したらスルーでしなかったら足す
				count=0;
				while(true){
					if(count==num){
						score[j]+=sco;
						break;
					}
					else if(count!=j && sco==number[count][i])
						break;
						
					count++;
					}
				}
			}
		
		
		for(int i=0; i<num; i++)
			System.out.println(score[i]);
		
	}

}

Measured memory_bytes: 20812
import java.util.*;
class Main{
  public static void main(String[] args){
    Scanner scan=new Scanner(System.in);
    int A=scan.nextInt();
    int B=scan.nextInt();
    if(A<B*2){
      System.out.println(0);
    }else{
      System.out.println(A-B*2);
    }
  }
}

Measured memory_bytes: 23252
#include <bits/stdc++.h>
using namespace std;
 
string to_string(string s) { return '"' + s + '"'; }
string to_string(bool b) { return b ? "true" : "false"; }
template <size_t N> string to_string(bitset<N> bs) {
  string res;
  for (size_t i = 0; i < N; ++i) res += '0' + bs[i];
  return res;
}
string to_string(vector<bool> v) {
  string res = "{";
  for (bool e : v) res += to_string(e) + ", ";
  return res += "}";
}
template <class T, class U> string to_string(pair<T, U> p);
template <class C> string to_string(C c) {
  string res = "{";
  for (auto e : c) res += to_string(e) + ", ";
  return res += "}";
}
template <class T, class U> string to_string(pair<T, U> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
void debug() { cerr << '\n'; }
template <class Head, class... Tail> void debug(Head head, Tail... tail) {
  cerr << '\t' << to_string(head), debug(tail...);
}
#ifdef LOCAL
#define DEBUG(...) cerr << "[" << #__VA_ARGS__ << "]:", debug(__VA_ARGS__)
#else
#define DEBUG(...)
#endif
 
int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n, k, c;
  cin >> n >> k >> c;
  string s;
  cin >> s;
  vector<int> b(n, -1);
  {
    int i = 0;
    for (int t = 0; t < k; ++t) {
      while (s[i] == 'x') {
        ++i;
      }
      b[i] = t;
      i += c + 1;
    }
  }
  DEBUG(b);
  vector<int> dp(3 * n);
  for (int i = n; i--; ) {
    dp[i] = dp[i + 1];
    if (s[i] == 'o') {
      dp[i] = max(dp[i], 1 + dp[i + c + 1]);
    }
  }
  DEBUG(dp);
  for (int i = 0; i < n; ++i) {
    if (b[i] != -1 and b[i] + dp[i + 1] < k) {
      cout << i + 1 << '\n';
    }
  }
}

Measured memory_bytes: 5012
from collections import deque 
N, K = map(int,input().split())
Xlist = list(map(int,input().split()))
Ans = 10**13
for i in range(len(Xlist)-K+1):
    Xleft = Xlist[i]
    Xright = Xlist[i+K-1]
    Dis = min(abs(Xleft),abs(Xright))+(Xright-Xleft)
    Ans = min(Dis,Ans)
print(Ans)
    

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

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

    string s;
    cin >> s;
    int k;
    cin >> k;

    map<char, vector<int>> mp;
    REP(i, s.size()) mp[s[i]].push_back(i);

    set<string> st;
    for(int i = 0; i <= 25; i++){
        if(mp[char('a' + i)].size() == 0) continue;
        
        int idx = 0, now, cnt = 0;
        if(mp[char('a' + i)].size() > 1){
            for(auto j : mp[char('a' + i)]){
                if(idx){
                    if((int)j - now == 1) cnt++;
                    else{
                        if(cnt > 0) st.insert(string(cnt, char('a' + i)));
                        cnt = 0;
                    } 
                }else{
                    idx++;
                    now = (int)j;
                }
            }
        }
        if(st.size() > k) break;

        int bw = 0, now2, idx2 = 0;
        for(auto j : mp[char('a' + i)]){
            if(idx2){
                bw = max(bw, j - now2);
                now2 = j;
            }
            else{
                idx++;
                now2 = j;
            }
        }
        bw = max(bw, (int)s.size() - now2);

        for(auto j : mp['a' + i]){
            string tmp = "";
            for(int k = (int)j; k <= (int)j + bw; k++){
                if(k == s.size()) break;
                tmp += s[k];
                st.insert(tmp);
            }
        }
        if(st.size() > k) break;

        for(int j = 0; j < s.size(); j++){
            if(char('a' + i) == s[j]){
                string tmp = "";
                for(int k = j; k < s.size(); k++){
                    tmp += s[k];
                    st.insert(tmp);
                }
                if(st.size() >= 5) break;
            }
        }
    }

    vector<string> A;
    for(auto x : st) A.push_back(x);
    sort(A.begin(), A.end());
    cout << A[k - 1] << endl;

    /*
    for(auto x : A){
        cout << x << " ";
    }
    cout << endl;
    */

    return 0;
}

Measured memory_bytes: 19968
program main;
var k, a, b, c, sum : LongInt;

function gcd(p, q : integer) : integer;
var r : integer;
begin
  while q > 0 do begin
    r := p mod q;
    p := q;
    q := r;
  end;
  gcd := p;
end;

begin
  readln(K);

  sum := 0;
  for a := 1 to K do
    for b := 1 to K do
      for c := 1 to K do
        sum := sum + gcd(gcd(a, b), c);

  writeln(sum);
end.

Measured memory_bytes: 1356
package main

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

var (
	readString func() string
	stdout     *bufio.Writer
)

func init() {
	readString = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readIntSlice(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = readInt()
	}
	return b
}

func readLengthAndSlice() (int, []int) {
	n := readInt()
	return n, readIntSlice(n)
}

func printf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(stdout, f, args...)
}

func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(stdout, args...)
}

func eprintln(args ...interface{}) (int, error) {
	return fmt.Fprintln(os.Stderr, args...)
}

// readString() string
// readInt() int
// readIntSlice(n int) []int
// readLengthAndSlice() []int

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

func main() {
	defer stdout.Flush()
	h := readInt()
	w := readInt()
	_, a := readLengthAndSlice()

	f := make([][]int, h)
	for i := range f {
		f[i] = make([]int, w)
	}

	l := 0
	r := w - 1
	t := 0
	b := h - 1

	c, d := 0, 0
	value := func() int {
		if a[d] == 0 {
			d++
		}
		a[d]--
		c++
		return d + 1
	}

	for {
		for j := l; j <= r; j++ {
			f[t][j] = value()
		}
		t++
		if c == h*w {
			break
		}
		for i := t; i <= b; i++ {
			f[i][r] = value()
		}
		r--
		if c == h*w {
			break
		}
		for j := r; j >= l; j-- {
			f[b][j] = value()
		}
		b--
		if c == h*w {
			break
		}
		for i := b; i >= t; i-- {
			f[i][l] = value()
		}
		l++
		if c == h*w {
			break
		}
	}

	for i := 0; i < h; i++ {
		sp := ""
		for j := 0; j < w; j++ {
			printf("%s%d", sp, f[i][j])
			sp = " "
		}
		println()
	}
}

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


Measured memory_bytes: 1152
/*
 * main.c
 *
 *  Created on: 2020/03/28
 *      Author: family
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define MAX(a,b) (a > b ? a : b)
#define MIN(a,b) (a > b ? b : a)
typedef long long int ll;
typedef unsigned long long int ull;

int sort_inc(const void *a, const void *b) { return (*(int*)a - *(int*)b);}
int sort_dec(const void* a, const void* b) { return (*(int*)b - *(int*)a);}
int sort_dec_ll(const void *a, const void *b) {
    ll da = *(ll*)a, db = *(ll*)b;    int val = 0;
    if(da > db) { val = -1; }
    else if (da == db) { val = 0; }
    else { val = 1; }
    return val;
}
int sort_inc_ll(const void *a, const void *b) {
    ll da = *(ll*)a, db = *(ll*)b;    int val = 0;
    if(da > db) { val = 1; }
    else if (da == db) { val = 0; }
    else { val = -1; }
    return val;
}
int sort_dic(const void *a, const void *b) {
    char *pa = (char *)a;    char *pb = (char *)b;    int i = 0, val = 0, N = 10;
    for (i = 0; i < N; i++) {
    	char da = pa[i], db = pb[i];
    	if (da == db) continue;
  		if (da > db) val = 1; else val = -1;
        break;
    }
    return val;
}

void yesno(int ans) {
	if (ans == 1) {	printf("Yes\n");
	} else {		printf("No\n");	}
	return;
}

void okng(int ans) {
	if (ans == 1) { printf("OK\n");
	} else { 		printf("NG\n");	}
	return;
}


ll A[100001] = {0};
#define MAX_VAL (1000000000000000000LL)
int main()
{
	ll N = 0;
	scanf("%lld", &N);
	int i = 0, zero = 0;
	for (i = 0; i < N; i++) {
		scanf("%lld", &A[i]);
		if (A[i] == 0) {
			zero = 1;
		}
	}
	ll ans = 1;
	for (i = 0; i < N; i++) {
		if (zero == 1) {
			ans = 0;
			break;
		}
		ll div = MAX_VAL / ans;
		if (div >= A[i]) {
			ans *= A[i];
			//printf("%lld %lld %lld\n", ans, div, A[i]);
		} else {
			ans = -1;
		}
	}
	printf("%lld\n", ans);
	//yesno(ans);
	//okng(ans);
	return 0;
}


Measured memory_bytes: 2512
import bisect
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
A.sort()
C.sort()
counter = 0
for b in B:
    counter += bisect.bisect_left(A, b)*(N-bisect.bisect_right(C, b))

print(counter)


Measured memory_bytes: 23220
#include <math.h>
#include <utility>
#include <string>
#include <vector>
#include <algorithm>
#include <iostream>
using namespace std;
 
int a[92][92] = {0};
int m;
int n;
int s;
 
int kansu( int x, int y, int c ) {
    a[x][y] = 0;
    
    if ( a[x+1][y] == 1 ) {
        kansu( x+1, y, c+1 );
    }
    if ( a[x-1][y] == 1 ) {
        kansu( x-1, y, c+1 );
    }
    if ( a[x][y+1] == 1 ) {
        kansu( x, y+1, c+1 );
    }
    if ( a[x][y-1] == 1 ) {
        kansu( x, y-1, c+1 );
    }
    s = max( s, c );
    a[x][y] = 1;
    return 0;
}
 
int main(){
    while(true) {
        cin >> m >> n;
        if ( m == 0 ) break;
        for ( int i = 0; i < n+2; i++ ) {
            for ( int j = 0; j < m+2; j++ ) {
                if ( i == 0 || i == n+1 || j == 0 || j == m+1 ) {
                    a[j][i]=0;
                }else {
                    cin >> a[j][i];
                }
            }
        }
        s = 0;
        for ( int i = 1; i < n+1; i++ ) {
            for ( int j = 1; j < m+1; j++ ) {
                if ( a[j][i]==1 ) kansu( j, i, 1 );
            }
        }
        cout << s << endl;
    }
    return 0;
}

Measured memory_bytes: 1188
#include <iostream>
using namespace  std;
int main()
{
    int S;
    int h,m,s;
    cin >> S;
    s = S % 60;
    h = (S - s) / 3600;
    m = (S - h*3600 - s) / 60;
    cout << h << ":" << m << ":" << s << endl;
    return 0;
}


Measured memory_bytes: 3088
//Utkarsh.25dec
#include <bits/stdc++.h>
#include <chrono>
#include <random>
#define ll long long int
#define ull unsigned long long int
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define rep(i,n) for(ll i=0;i<n;i++)
#define loop(i,a,b) for(ll i=a;i<=b;i++)
#define vi vector <int>
#define vs vector <string>
#define vc vector <char>
#define vl vector <ll>
#define all(c) (c).begin(),(c).end()
#define max3(a,b,c) max(max(a,b),c)
#define min3(a,b,c) min(min(a,b),c)
#define deb(x) cerr<<#x<<' '<<'='<<' '<<x<<'\n'
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
// ordered_set s ; s.order_of_key(val)  no. of elements strictly less than val
// s.find_by_order(i)  itertor to ith element (0 indexed)
typedef vector<vector<ll>> matrix;
ll power(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll modInverse(ll a){return power(a,mod-2);}
const int N=500023;
bool vis[N];
vector <int> adj[N];
void solve()
{
    string s;
    cin>>s;
    for(auto ch:s)
    {
        if(ch=='?')
            cout<<'D';
        else
            cout<<ch;
    }
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int T=1;
    //cin>>T;
    int t=0;
    while(t++<T)
    {
        //cout<<"Case #"<<t<<":"<<' ';
        solve();
        //cout<<'\n';
    }
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
}

Measured memory_bytes: 15696
#include <iostream>
#include <algorithm>
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <cstring>
#include <utility>
#include <vector>
#include <complex>
#include <valarray>
#include <fstream>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <numeric>

#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define all(X) (X).begin(),(X).end()
#define mod(n, m) (((n)%(m)+(m))%m)
#define fi first
#define sc second
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
const int INFINT = 1 << 30;                          // 1.07x10^ 9
const ll INFLL = 1LL << 60;                          // 1.15x10^18
const double EPS = 1e-10;
const int MOD = 1000000007;

int N;
int A[2][100];
int sum[2][100];


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

  cin >> N;
  rep(i, 2)rep(j, N) cin >> A[i][j];

  sum[0][0] = A[0][0];
  for (int j = 1; j < N; ++j) sum[0][j] = sum[0][j-1] + A[0][j];
  sum[1][0] = A[1][0];
  for (int j = 1; j < N; ++j) sum[1][j] = sum[1][j-1] + A[1][j];

  int ans = 0;
  for (int i = 0; i < N; ++i) {
    ans = max(ans, sum[0][i] + sum[1][N-1] - sum[1][i] + A[1][i]);
  }

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


Measured memory_bytes: 384
#include<bits/stdc++.h>
#define LL long long
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPA(i,n) for(int i=1;i<(n);++i)
#define foreach(i, n) for(auto &i:(n))
#define PII pair<int,int>
#define PLI pair<long long, int>
#define PLL pair<long long, long long>
#define MOD ((int)1e9 + 7)
#define INF ((int)1e9+5)
#define INFLL ((LL)4e18)
#define ALL(x) (x).begin(),(x).end()
#define BIT(x) (1 << (x))
using namespace std;

bool check(vector<int> line){
	for(int i=0;i<line.size()-1;++i){
		if(line[i] > line[i+1])return false;
	}
	return true;
}

int main(){
	int n;
	cin >> n;
	vector<LL> A(n+1), B(n);
	foreach(i, A)cin>>i;
	foreach(i, B)cin>>i;
	LL ans = 0;
	for(int i=0;i<n;++i){
		LL d = min(A[i], B[i]);
		ans+=d;
		A[i]-=d;
		B[i]-=d;
		d = min(A[i+1], B[i]);
		ans+=d;
		A[i+1]-=d;
		B[i]-=d;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(false)
using namespace std;
#define inf (0x3f3f3f3f)
typedef long long int LL;
const int maxn = 3e5 + 20;
LL sum[maxn];
void work() {
    int n;
    cin >> n;
    for (int i = 1; i <= n; ++i) {
        int val;
        cin >> val;
        sum[i] = sum[i - 1] + val;
    }
    LL ans = 1e18;
    for (int i = 2; i <= n; ++i) {
        ans = min(ans, abs(sum[i - 1] - sum[n] + sum[i - 1]));
    }
    cout << ans << endl;
}

int main() {
#ifdef local
    freopen("data.txt", "r", stdin);
//    freopen("data.txt", "w", stdout);
#endif
    work();
    return 0;
}


Measured memory_bytes: 1792
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define LEN 100005

typedef struct pp{
  char name[100];
  int t;
}P;

P Q[LEN+1];
int head, tail, n;

int isEmpty(){
  return head == tail;
}

int isFull(){
    return head == (tail + 1) % LEN;
}

void enqueue(P x){
  if (isFull()) {
      printf("overflow\n");
      exit(1);
  } 
  Q[tail] = x;
  if (tail + 1 == LEN)
    tail = 0;
  else
    tail++;
}

P dequeue(){
 if (isEmpty()) {
    printf("underflow\n");
    exit(1);
  } 	    
  P x = Q[head];
  if (head + 1 == LEN)
    head = 0;
  else
    head++;
  return x;
}

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

int main(){
  int elaps = 0, c;
  int i, q;
  P u;

  scanf("%d %d", &n, &q);

  for ( i = 1; i <= n; i++){
    scanf("%s", Q[i].name);
    scanf("%d", &Q[i].t);
  }

  head =1, tail = n+1;
  
  while (head != tail) {
    u = dequeue();
    c = min(q,u.t);
    u.t -= c;
    elaps += c;
    if (u.t>0){
      enqueue(u);
    } else {
      printf("%s %d\n", u.name, elaps);
    }
  }

  return 0;
}



Measured memory_bytes: 11856
open Batteries
module EnumL = Enum.Labels
module ListL = List.Labels
module ArrayL = Array.Labels

let dbg0 x = Printf.eprintf "[debug]%s\n" @@ dump x
let dbg1 x = dbg0 x; x

let id = identity

let (++) n m = List.range n `To m
let (++-) n m = if n >= m then List.range n `Downto m else []
let (++^) n m = if n < m then List.range n `To (pred m) else []

let scan fmt = Scanf.sscanf (read_line ()) fmt

let scan_lines n fmt f =
  if n = 0 then []
  else List.map (fun _ -> scan fmt f) (1 ++ n)

let scan_list sep cnv =
  let line = read_line () in
  (match sep with
   | None -> List.map String.of_char @@ String.to_list line
   | Some sep -> String.split_on_char sep line)
  |> List.map cnv

let scan_array ?sep cnv = Array.of_list @@ scan_list sep cnv

let scan_matrix n m e ?sep conv =
  let arr = Array.make_matrix n m e in
  ListL.iter (0 ++^ n)
    ~f:(fun i -> arr.(i) <- Array.of_list @@ scan_list sep conv);
  arr

let rec powerset e =
  match Enum.get e with
  | None -> Enum.singleton @@ Enum.empty ()
  | Some v ->
    let f = powerset e in
    let g = Enum.clone f in
    EnumL.map f ~f:(fun x -> let y = Enum.clone x in push y v; y)
    |>  Enum.append g

let permutations l =
  let rec aux l =
    let rec interleave x = function
      | [] -> [[x]]
      | (hd::tl) as lst ->
        (x::lst) ::
        (ListL.map ~f:(List.cons hd)  @@ interleave x tl)
    in
    match l with
    | [] -> [[]]
    | hd::tl -> List.concat @@ List.map (interleave hd) @@ aux tl in
  let l = List.sort (List.compare Int.compare) @@ aux @@ List.of_enum l in
  List.enum % ListL.map ~f:List.enum @@ l

let intersection l =
  EnumL.filter ~f:(fun x -> EnumL.exists ~f:((=) x) @@ Enum.clone l)

let zip l m =
  let n = min (List.length l) (List.length m) in
  List.combine (List.take n l) (List.take n m)

let lower_bound n f =
  let rec aux l u =
    if u - l > 1 then
      let m = (l + u) / 2 in
      if f m then aux l m
      else aux m u
    else u in aux (-1) n

let between n x m = n <= x && x < m

let (a,b,c,d) = scan "%d %d %d %d" Tuple4.make

let () =
  (if (c+pred b)/b <= (a+pred d)/d then "Yes" else "No")
  |> Printf.printf "%s\n"


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

public class Main{

    static int h;
    static int a[]=new int[2000000];
    
    public static void main(String args[]) throws IOException{
	BufferedReader br=new BufferedReader(new InputStreamReader(System.in));

	
	while(true){
	    String str[]=br.readLine().split(" ");

	    if(str[0].equals("end"))
		break;

	    if(str[0].equals("insert")){
		insert(Integer.parseInt(str[1]));
	    }else{
		System.out.println(extract());
	    }
	}
    }

    static int extract(){
	if(h<1)
	    return Integer.MIN_VALUE;
	int max=a[1];
	a[1]=a[h--];
	maxHeapify(1);
	return max;
    }

    static void insert(int k){
	h++;
	a[h]=Integer.MIN_VALUE;
	increaseKey(h,k);
    }

    static void increaseKey(int i,int k){
	if(k<a[i])
	    return;
	a[i]=k;
	while(i>1 && a[getParent(i)]<a[i]){
	    int temp=a[getParent(i)];
	    a[getParent(i)]=a[i];
	    a[i]=temp;
	    i=getParent(i);
	}
    }

    static void maxHeapify(int i){
	    int left=getLeft(i);
	    int right=getRight(i);

	    int max=0;

	    if(left<=h && a[left]>a[i]){
		max=left;
	    }else{
		max=i;
	    }

	    if(right<=h && a[right]>a[max]){
		max=right;
	    }

	    if(max!=i){
		int temp=a[i];
		a[i]=a[max];
		a[max]=temp;
		maxHeapify(max);	
	    }
    }
    
    static int getParent(int i){
	return i/2;
    }

    static int getLeft(int i){
	return 2*i;
    }

    static int getRight(int i){
	return 2*i+1;
    }
}



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

int main() {
    int H, N;
    cin >> H >> N;
    vector<int>A(N);
    for (int i = 0; i < N; ++i) {
        cin >> A[i];
    }
    for (int i = 0; i < N; ++i) {
        H -= A[i];
        if (H <= 0) break;
    }
    if (H <= 0) cout << "Yes" << "\n";
    else cout << "No" << "\n";
    return 0;
}

Measured memory_bytes: 640
<?php
list($n, $k) = explode(" ", trim(fgets(STDIN)));

for($i = 0; $i < $n; $i++){
    $array[] = (int)trim(fgets(STDIN));
}
sort($array);

$min = pow(10,10);
for($i = 0; $i < $n - $k + 1; $i++){
    $diff = $array[$i + $k - 1] - $array[$i];
    $min = min($min, $diff);
}
echo $min;

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

int main() {
	string s;
	cin >> s;
	int counter=0;
	if (s[0]=='1') ++counter;
	if (s[1]=='1') ++counter;
	if (s[2]=='1') ++counter;
	cout<< counter <<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define all(V) V.begin(),V.end()
using ll = long long;
const ll MOD = 1000000007;

ll fact[100010], inv[100010], fr[100010];
ll N;

ll modpow(ll x, ll y) {
	ll ans = 1;
	while (y) {
		if (y & 1)ans *= x;
		x *= x;
		ans %= MOD;
		x %= MOD;
		y /= 2;
	}
	return ans;
}

ll ncr(ll r) {
	return fact[N] * inv[N - r] % MOD * inv[r] % MOD;
}

ll f(ll x) {
	ll per = fact[N - x] * fact[x - 1] % MOD;
	ll com = ncr(x);
	return per * com % MOD;
}

int main() {
	fact[0] = 1, inv[0] = 1;
	for (ll i = 1;i < 100010;i++)fact[i] = fact[i - 1] * i % MOD, inv[i] = modpow(fact[i], MOD - 2);
	cin >> N;
	vector<ll> A(N), B(N);
	for (int i = 0;i < N;i++)cin >> A[i];

	for (int i = 1;i <= N;i++) {
		fr[i] = (f(i) + fr[i - 1]) % MOD;
	}

	for (int i = 0;i < N;i++) {
		B[i] = fr[i + 1] + fr[N - i] - fr[1];
		B[i] %= MOD;if (B[i] < 0)B[i] += MOD;
	}
	ll ans = 0;
	for (int i = 0;i < N;i++) {
		ans += A[i] * B[i];
		ans %= MOD;
	}
	cout << ans << endl;
}

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

const int N_MAX=1000;
typedef long long int LLI;

int main() {
  int N;
  LLI x[N_MAX];
  LLI y[N_MAX];

  cin >> N;
  for (int i = 0; i < N; ++i) {
    cin >> x[i] >> y[i];
  }

  bool impossible = false;
  bool odd;
  for (int i = 0; i < N; ++i) {
    if (!i) {
      odd = abs(x[i] + y[i]) % 2;
    } else if (odd != abs(x[i] + y[i]) % 2) {
      impossible = true;
    }
  }

  if (impossible) {
    cout << -1 << endl;
    return 0;
  }

  LLI k = 0;
  for (int i = 0; i < N; ++i) {
    if (!odd) {
      --x[i];
    }
    k = max(k, abs(x[i] + y[i]));
    k = max(k, abs(x[i] - y[i]));
  }
  int m = 0;
  LLI mm = 1;
  while (mm <= k) {
    m += 1;
    mm <<= 1;
  }

  if (!odd) {
    cout << m + 1 << endl;
    cout << 1 << " ";
  } else {
    cout << m << endl;
  }
  LLI p = 1;
  for (int i = 0; i < m; ++i) {
    if (!i) {
      cout << p;
    } else {
      cout << " " << p;
    }
    p <<= 1;
  }
  cout << endl;

  for (int i = 0; i < N; ++i) {
    if (!odd) {
      cout << "R";
    }
    LLI u = x[i] + y[i];
    LLI v = x[i] - y[i];
    LLI a = ((1 << m) - 1 - u) / 2;
    LLI b = ((1 << m) - 1 - v) / 2;

    for (int i = 0; i < m; ++i) {
      char d;
      if (a & 1) {
        if (b & 1) {
          d = 'L';
        } else {
          d = 'D';
        }
      } else {
        if (b & 1) {
          d = 'U';
        } else {
          d = 'R';
        }
      }
      a >>= 1;
      b >>= 1;
      cout << d;
    }
    cout << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
typedef struct{
char *s[11];
int score;
int order;
}R;
 R r[101];
int cmp(const R *u,const R *v){
  int t=strcmp(u->s,v->s);
  if(t)return t;
  return (v->score)-(u->score);
}
int main(void){
int n;
 
scanf("%d",&n);
for(int i=0;i<n;i++){
	scanf("%s%d",r[i].s,&r[i].score);
  r[i].order=i;
  //	printf("%d %s %d\n",r[i].order,r[i].s,r[i].score);
}
  
  qsort(r,n,sizeof(R),cmp);
  for(int i=0;i<n;i++){
	printf("%d\n",r[i].order+1);}
  return 0;
}

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

int main(){
    int a;
    cin >> a;
    int ans = pow(a, 3) + pow(a, 2) + a;
    cout << ans << endl;
    return 0;
}

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

int main() {
    int Q; cin >> Q;
    for (int q = 0; q < Q; ++q) {
        int a, b, c, d; cin >> a >> b >> c >> d;
        --a, --b, --c, --d;
        int res = 0;
        for (int i = a; i <= c; ++i) {
            for (int j = b; j <= d; ++j) {
                if (i % 2 == 0 && j % 2 == 1) continue;
                ++res;
            }
        }
        cout << res << endl;
    }
}



Measured memory_bytes: 3076
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>

using namespace std;

int n;
long long a[100005];

long long total;
int bit[64];
int tbit[64];


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

	for(int i=0;i<n;i++){
		total ^= a[i];
		int cnt =0;
		int tmpa = a[i];
		while((tmpa%2) == 0){
			cnt++;
			tmpa /= 2;
		}
		bit[cnt]++;
	}

	//cout<<total<<endl;

	for(int i=0;i<40;i++){
		tbit[i] = total % 2;
		total /= 2;
	}

	//for(int i=0;i<4;i++) cout<<tbit[i]<<" ";cout<<endl;
	//for(int i=0;i<4;i++) cout<<bit[i]<<" ";cout<<endl;


	int ans = 0;
	for(int i=40;i>=0;i--){
		if(tbit[i] == 1){
			if(bit[i] > 0){
				bit[i]--;
				ans++;
				for(int j=i;j>=0;j--) tbit[j] ^= 1;
			} else {
				cout<<"-1"<<endl;
				return 0;
			}
		}
	}
	cout<<ans<<endl;
	return 0;

}


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



int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
#ifndef ONLINE_JUDGE
  freopen("in", "r", stdin);
  freopen("out", "w", stdout);
#endif

  int n;
  cin >> n;
  long long k;
  cin >> k;
  vector<long long> V(n);
  for (auto& i : V) cin >> i;

  int l = 0;
  int r = 2'000'000'000;
  while (r - l > 1) {
    int mid = (l + r) >> 1;
    long long ans = 0;
    for (int i = 0; i < n; ++i) {
      ans += V[i] / mid;
      if (V[i] % mid == 0) --ans;
    }
    if (ans <= k) r = mid;
    else l = mid;
  }
  cout << r;
  return 0;
}


Measured memory_bytes: 4724
#include <bits/stdc++.h>
using namespace std;
#define INF 1<<30
#define endl '\n'
#define maxn 100005
#define FASTIO ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
typedef long long ll;
const double PI = acos(-1.0);
#define dbg(x) cerr << #x << " = " << x << endl;
#define dbg2(x, y) cerr << #x << " = " << x << ", " << #y << " = " << y << endl;
#define dbg3(x, y, z) cerr << #x << " = " << x << ", " << #y << " = " << y << ", " << #z << " = " << z << endl;

const ll mod = 1e9 + 7;

ll gcd(ll x, ll  y){
    if(x<y){
        ll z = x;
        x = y;
        y = z;
    }
    if(x % y == 0)return y;
    else return gcd( y, x % y);
}

int main()
{
    FASTIO
    /*
    //double start_time = clock();
#ifndef ONLINE_JUDGE
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    freopen("error.txt", "w", stderr);
#endif
//*/
    int T;
    // cin >> T;
    T = 1;
    for(int cs = 1; cs <= T; cs++)
    {
        ll a,b,c,d;
        cin >> a >> b >> c >> d;
        ll tot = b - a + 1;
        ll lcm = c*d/gcd(c,d);
        a--;
        //cerr << lcm << endl;
        ll divide = (b/c) + b/d - a/c - a/d - b/lcm + a/lcm;
        //divide += (b/d) - (a/d);
        //divide -= 
        //cerr << (b/c) <<" "<< (b/d) << " "<< b/(c * d) << " "<< (a - 1)/c << " "<< (a - 1)/d<<endl;
        //cerr << tot << " "<<divide << endl;
        ll ans = tot - divide;
        cout << ans << endl;
    }

    //double end_time = clock();
    //printf( "Time = %lf ms\n", ( (end_time - start_time) / CLOCKS_PER_SEC)*1000);

    return 0;
}


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

using namespace std;

const long long modulo = 1e9+7;

const int SIZE_LIMIT = 2e3+5;
long long dp[SIZE_LIMIT][SIZE_LIMIT];

int main() {
  long long n;
  scanf("%lld", &n);
  
  for (int a = 0; a <= n; ++a) {
    dp[a][1] = 1;
  }
  for (int b = 1; b <= n; ++b) {
    dp[0][b] = 1;
  }
  for (int a = 1; a <= n; ++a) {
    for (int b = 2; b <= n; ++b) {
      dp[a][b] = (dp[a][b-1]+dp[a-1][b]) % modulo;
    }
  }
  
  long long ans = 0;
  for (int k = 1; k <= n/3; ++k) {
    ans = (ans + dp[n-3*k][k]) % modulo;
  }
  printf("%lld\n", ans);

  return 0;
}

Measured memory_bytes: 35056
#include <algorithm>
#include <cmath>
#include <iostream>
using namespace std;

int main() {
  long H, W;
  cin >> H >> W;
  
  long ans = H * W;
  long S1, S2, S3;
  for (int w1 = 1; w1 < W; w1++) {
    S1 = H * w1;
    if (H % 2 == 0 || (W - w1) % 2 == 0) {
      S2 = H * (W - w1) / 2; // == S3
      ans = min(ans, abs(S1 - S2));
    } else if (H <= W - w1) {
      S2 = H * ((W - w1) / 2);
      S3 = S2 + H;
      ans = min(ans, max({S1, S2, S3}) - min({S1, S2, S3}));
    } else {
      S2 = (W - w1) * (H / 2);
      S3 = S2 + (W - w1);
      ans = min(ans, max({S1, S2, S3}) - min({S1, S2, S3}));
    }
  }
  for (int h1 = 1; h1 < H; h1++) {
    S1 = W * h1;
    if (W % 2 == 0 || (H - h1) % 2 == 0) {
      S2 = W * (H - h1) / 2; // == S3
      ans = min(ans, abs(S1 - S2));
    } else if (W <= H - h1) {
      S2 = W * ((H - h1) / 2);
      S3 = S2 + W;
      ans = min(ans, max({S1, S2, S3}) - min({S1, S2, S3}));
    } else {
      S2 = (H - h1) * (W / 2);
      S3 = S2 + (H - h1);
      ans = min(ans, max({S1, S2, S3}) - min({S1, S2, S3}));
    }
  }
  
  cout << ans << endl;
  return 0;
}

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

using namespace std;

#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define REV(i,n) for(ll (i) = (n) - 1;(i) >= 0;--i)
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {REP(WW,n)cerr << v[WW] << ' ';cerr << endl << endl;}
#define SHOW2d(v,WW,HH) {REP(W_,WW){REP(H_,HH)cerr << v[W_][H_] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 1000000007

typedef long long ll;
typedef pair<ll,ll> P;

bool check(vector<ll> &v, ll mid) {
	vector<P> now;
	now.EB(0,-1);
	REP(i,v.size()){
		if(now.back().FI < v[i]){
			now.EB(v[i],0);
		}
		else {
			if(mid <= 1)return false;
			while(now.back().FI > v[i])now.pop_back();
			if(now.back().FI < v[i])now.EB(v[i],0);
			int tmp = now.back().FI;
			int top = now.back().FI;
			while(now.back().FI == top && now.back().SE == mid - 1){
				top = now.back().FI - 1;
				now.pop_back();
			}
			if(now.back().FI != top)now.EB(top,0);
			now.back().SE++;
			if(now.back().FI != tmp)now.EB(tmp,0);
			if(now.front().SE > -1)return false;
		}
		//REP(i,now.size())cout << "(" << now[i].FI << "," << now[i].SE << ") ";cout << endl;
	}
	return true;
}

int main(){
	
	ll n;cin >> n;
	vector<ll> v(n);
	REP(i,n)cin >> v[i];
	
	ll l = 0;
	ll r = 222222;
	
	while(r - l > 1){
		ll mid = (l + r) / 2;
		//cout << l << " " << r << " " << mid << endl;
		if(check(v,mid))r = mid;
		else l = mid;
	}
	
	cout << r << endl;
	
	return 0;
}


Measured memory_bytes: 9088
import java.io.IOException;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {

		new Main().run();
	}

	private void run() throws IOException {
		Scanner scanner = new Scanner(System.in);
		String str = scanner.next();
		int n = scanner.nextInt();
		int ans = 0;
		while (n-- > 0) {
			String s = scanner.next();
			s += s;
			if (s.contains(str))
				ans++;
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 17192
import java.util.Arrays;
import java.util.Scanner;


public class Main{

	public static void main(String[] args) {

		int[] hurui = new int[1000000];
		Arrays.fill(hurui, 1);
		for(int i=2 ; i < 1000000 ; i++) {
			if(hurui[i] == 0)
				continue;
			for(int j=2 ; i*j < 1000000 ; j++) {
				hurui[i*j] = 0;
			}
		}

		hurui[1] = 0;
		for(int i=2 ; i<1000000 ; i++) {
			hurui[i] += hurui[i-1];
		}


		Scanner s = new Scanner(System.in);
		while(s.hasNext()) {
			int input = Integer.parseInt(s.nextLine());
			System.out.println(hurui[input]);
		}
	}

}

Measured memory_bytes: 30616
n=int(input())

z=[]

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

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

f=factorization(n)

count=0
for i in f:
  if i[0]==1:
    pass
  else:
    a=i[1]
    c=1
    while True:
      if a>=c:
        a-=c
        count+=1
        c+=1
      else:
        break
      
print(count)

Measured memory_bytes: 9472
from sys import stdin
import fractions
from functools import reduce

n = int(stdin.readline().rstrip())
arg = list(map(int, stdin.readline().rstrip().split()))


def lcm(*numbers):
    return reduce(lambda x, y: (x * y) // fractions.gcd(x, y), numbers, 1)


divided = lcm(*arg) - 1
res = sum(map(lambda x: divided % x, arg))
print(res)


Measured memory_bytes: 5368
#include <iostream>
#include <algorithm>
#include <string>
#include <cstdio>
#include <cmath>
#include <stack>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <numeric>
#include <iomanip>
 
 
int main()
{
	long long n;
 
	std::cin >> n;
 
	std::cout << n * 800 - (n / 15) * 200 << std::endl;
	return 0;
}

Measured memory_bytes: 256
// ########################################################
// ################ MaxBipartiteMatching ##################
// Hopcroft ( E * sqrt(V) )

#include <bits/stdc++.h>

using namespace std;

const int MAXN1 = 50000;
const int MAXN2 = 50000;
const int MAXM = 150000;

int n1, n2, edges, last[MAXN1], prev[MAXM], head[MAXM],E;
int matching[MAXN2], dist[MAXN1], Q[MAXN1];
bool used[MAXN1], vis[MAXN1];

void init(int _n1, int _n2) {
  n1 = _n1;
  n2 = _n2;
  edges = 0;
  fill(last, last + n1, -1);
}

void addEdge(int u, int v) {
  head[edges] = v;
  prev[edges] = last[u];
  last[u] = edges++;
}

void bfs() {
  fill(dist, dist + n1, -1);
  int sizeQ = 0;
  for (int u = 0; u < n1; ++u) {
    if (!used[u]) {
      Q[sizeQ++] = u;
      dist[u] = 0;
    }
  }
  for (int i = 0; i < sizeQ; i++) {
    int u1 = Q[i];
    for (int e = last[u1]; e >= 0; e = prev[e]) {
      int u2 = matching[head[e]];
      if (u2 >= 0 && dist[u2] < 0) {
	dist[u2] = dist[u1] + 1;
	Q[sizeQ++] = u2;
      }
    }
  }
}

bool dfs(int u1) {
  vis[u1] = true;
  for (int e = last[u1]; e >= 0; e = prev[e]) {
    int v = head[e];
    int u2 = matching[v];
    if (u2 < 0 || !vis[u2] && dist[u2] == dist[u1] + 1 && dfs(u2)) {
      matching[v] = u1;
      used[u1] = true;
      return true;
    }
  }
  return false;
}

int maxMatching() {
  fill(used, used + n1, false);
  fill(matching, matching + n2, -1);
  for (int res = 0;;) {
    bfs();
    fill(vis, vis + n1, false);
    int f = 0;
    for (int u = 0; u < n1; ++u)
      if (!used[u] && dfs(u))
	++f;
    if (!f)
      return res;
    res += f;
  }
}

int main()
{
  cin>>n1>>n2>>E;
  memset(last,-1,sizeof last);
  while(E--)
    {
      int u,v;
      cin>>u>>v;//0-based
      addEdge(u,v);
    }
  cout <<maxMatching()<< endl;
}

Measured memory_bytes: 3372
/**
 *    author:  tourist
 *    created: 16.12.2019 11:36:49       
**/
#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<pair<int, int>> ret;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if ((i + j) % 2 == 1 && (i % 3 == 0 || i == n - 1 || j == 0 || j == n - 1)) {
        ret.emplace_back(i, j);
      }
    }
  }
  cout << ret.size() << '\n';
  for (auto& p : ret) {
    cout << p.first << " " << p.second << '\n';
  }
  return 0;
}


Measured memory_bytes: 2928
# abc 157
import sys
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
read = sys.stdin.buffer.read
sys.setrecursionlimit(10 ** 7)

A = []
A.extend(map(int, readline().split()))
A.extend(map(int, readline().split()))
A.extend(map(int, readline().split()))

bingo = [0,0,0, 0,0,0, 0,0,0]

N = int(readline().strip())

for _ in range(0, N):
    b = int(readline().strip())
    for i, number in enumerate(A):
        if b == number:
            bingo[i] = 1

if bingo[0] and bingo[3] and bingo[6]: # 縦
    print("Yes")
elif bingo[1] and bingo[4] and bingo[7]:
    print("Yes")
elif bingo[2] and bingo[5] and bingo[8]:
    print("Yes")
elif bingo[0] and bingo[1] and bingo[2]: # 横
    print("Yes")
elif bingo[3] and bingo[4] and bingo[5]:
    print("Yes")
elif bingo[6] and bingo[7] and bingo[8]:
    print("Yes")
elif bingo[0] and bingo[4] and bingo[8]: # 斜め
    print("Yes")
elif bingo[2] and bingo[4] and bingo[6]:
    print("Yes")
else:
    print('No')

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

int main() {
  int N;
  std::string s;
  cin >> N;
  cin >> s;
  int r_num = 0, b_num = 0;
  for (int i = 0; i < N; ++i) {
    if (s[i] == 'R') {
      r_num++;
    } else {
      b_num++;
    }
  }
  if (r_num > b_num) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
n,m=list(map(int, input().split()))
PY=[list(map(int, input().split())) + [0] for i in range(m)] 
d={}
for i in sorted(PY, key=lambda x: x[1]):
    if i[0] in d:
        d[i[0]] += 1
    else:
        d[i[0]] = 1
    i[2] = d[i[0]]
for i in PY:
    print(str(i[0]).zfill(6) + str(i[2]).zfill(6))

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

constexpr int inf = 0x3f3f3f3f;

int solve(const vector<int>& v) {
  int n = v.size();
  vector<int> dp(n << 8 | 1, -inf);
  dp[0] = 0;
  for (int a : v) {
    auto ndp = dp;
    ndp[a] = 1;
    for (int i = 1; i < (int)dp.size(); ++i) {
      if (dp[i] == -inf) {
        continue;
      }
      if ((i & -i) < a) {
        continue;
      }
      ndp[i + a] = max(ndp[i + a], dp[i] + 1);
    }
    swap(dp, ndp);
  }
  int res = 0;
  for (int i = 1; i < (int)dp.size(); i *= 2) {
    res = max(res, dp[i]);
  }
  return res;
}

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n;
  while (cin >> n, n) {
    vector<vector<int>> v(500);
    while (n--) {
      int a;
      cin >> a;
      int tz = __builtin_ctz(a);
      v[a >> tz].push_back(1 << tz);
    }
    int res = 0;
    for (const auto& e : v) {
      res = max(res, solve(e));
    }
    cout << res << '\n';
  }
}



Measured memory_bytes: 4984