akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cmath>
using namespace std;

const int MAX_S = 6;
const int INF = 1<<24;
const double EPS = 1e-5;
double r;
int s;
int w[MAX_S];

bool equals(double a, double b) {
  return fabs(a-b) <= EPS;
}

double calc() {
  double res = -1.0;
  double pos[MAX_S];
  int g[MAX_S];
  int t[MAX_S];
  for(int i = 1; i <= s-1; ++i) t[i-1] = i;

  do {
    fill(pos, pos+s, 0.0);
    fill(g, g+s, 0);
    int cnt = 1;
    for(int k = 0; k < s-1; ++k) {
      int a, b;
      for(a = t[k]-1; a >= 0 && g[a] == g[t[k]-1]; --a) ; ++a;
      for(b = t[k]; b < s && g[b] == g[t[k]]; ++b);

      int sumA = accumulate(&w[a], &w[t[k]], 0);
      int sumB = accumulate(&w[t[k]], &w[b], 0);
      double d;

      d = (double)sumB/(sumA+sumB);
      for(int i = a; i < t[k]; ++i) {
	pos[i] -= d;
	g[i] = cnt;
      }
      ++cnt;

      d = (double)sumA/(sumA+sumB);
      for(int i = t[k]; i < b; ++i) {
	pos[i] += d;
	g[i] = cnt;
      }
      ++cnt;
    }

    sort(pos, pos+s);
    double newV = pos[s-1] - pos[0];
    if(!equals(newV, r) && newV < r) res = max(res, newV);

  } while(next_permutation(t, t+s-1));
  return res;
}

double solve() {
  sort(w, w+s);
  double res = -1.0;
  do {
    res = max(res, calc());
  } while(next_permutation(w, w+s));
  return res;
}

int main() {
  int T;
  cin >> T;
  for(int tc = 1; tc <= T; ++tc) {
    cin >> r;
    cin >> s;
    for(int i = 0; i < s; ++i) {
      cin >> w[i];
    }
    double ans = solve();
    if(ans == -1) printf("%d\n", -1);
    else printf("%.16f\n", ans);
  }
  return 0;
}

Measured memory_bytes: 984
#include <cstdio>
#define ll long long int
using namespace std;
ll H, W, ans;
int main()
{
	scanf("%lld%lld", &H, &W);
	ll temp = H*W;
	if(H==1||W==1)
	{
		printf("1\n");
		return 0;
	}
	if(temp%2==0)
	    printf("%lld\n", temp/2);
	else printf("%lld\n", (temp+1)/2);
	return 0;
}

Measured memory_bytes: 128
fun main(args:Array<String>){
    val line = readLine()!!.split(" ").map { it.toInt() }
    val n = line[0]
    val x = line[1]
    var d = 0
    var result = 1
    val list = readLine()!!.split(" ").map{it.toInt()}
    for(i in 1..n){
        val l = list[i-1]
        d += l
        if(d<=x)result++
    }
    println(result)
}


Measured memory_bytes: 37988
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll sum=0;
int main()
{
	int ans=1e9;int flag=true,n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		int x,y;
		scanf("%d%d",&x,&y);
		sum+=x;
//		cout<<x<<" "<<sum<<endl;
		if(x>y)ans=min(ans,y);
		if(x!=y)flag=false;
	}
	if(flag)puts("0");else printf("%lld\n",sum-ans);
	return 0;
}

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

int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    map<int,int> C;
    for(int i=0; i<N; ++i) {
        cin >> A[i];
        for(int d=-1; d<=1; ++d) C[A[i]+d] += 1;
    }

    int M = -1;
    int X = 0;
    for(auto itr = C.begin(); itr != C.end(); ++itr) {
        if(itr->second > M) {
            M = itr->second;
            X = itr->first;
        }
    }
    int res = 0;
    for(int i=0; i<N; ++i) {
        if(abs(X-A[i]) < 2) ++res;
    }
    cout << res << endl;
}

Measured memory_bytes: 5120
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <cmath>
#include <iomanip>
#include <functional>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) (int)(x).size()
using namespace std;
using ll = long long;
constexpr int inf = 1000000000;
constexpr ll INF = 1000000000000000000;

int main() {
    int N;
    cin >> N;
    int MAX = -inf, MIN = inf;
    rep(i, N) {
        int a;
        cin >> a;
        MAX = max(MAX, a);
        MIN = min(MIN, a);
    }
    cout << MAX - MIN << "\n";
    return 0;
}


Measured memory_bytes: 3524
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define all(x) x.begin(), x.end()
#define MOD 1000000007
#define vi vector < int >
#define pii pair < int, int >
#define INF (int)1e9
#define pb push_back
#define fastIO ios::sync_with_stdio(0); cin.tie(0);

string k;
int d, n;

int cache[10005][105][2];

int dpSol(int i, int rem, bool big_or_not)
{
    if(i == n)
    {
        if(rem == 0)
            return 1;
        return 0;
    }
    
    int &res = cache[i][rem][big_or_not];
    if(res != -1)
        return res;

    int maxnum = 9;
    if(big_or_not)
        maxnum = k[i] - '0';
        
    ll ans = 0;
    for(int j = 0; j <= maxnum; ++j)
    {
        int f = big_or_not;
        if(j < (k[i] - '0'))
            f = 0;
        ans = (ans + dpSol(i + 1, (rem + j) % d, f)) % MOD;
    }
    
    return res = ans;
}

int main()
{
    fastIO
    cin >> k;
    cin >> d;
    
    n = k.size();
    
    memset(cache, -1, sizeof(cache));
    cout << (dpSol(0, 0, 1) - 1 + MOD) % MOD;

    return 0;
}

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

int main(){
    int mo[10];
    for (int i=0; i<10; i++) {
        cin>>mo[i];
    }
     for (int i=0; i<3; i++) {
        int idx = 0;
        for (int j=0; j<10; j++) {
            if (mo[j] > mo[idx]) {
                idx = j;
            }
        }
        cout << mo[idx] << endl;
        mo[idx] = 0;
    }

    return 0;
}

Measured memory_bytes: 3064
#include <stdio.h>

int main(void){
  int a[100],i,n;
  scanf("%d",&n);
  for(i = 0; i < n; i++){
    a[i] = 0;
    scanf("%d",&a[i]);
  }
  for(i = n - 1; i >= 0; i--){
    printf("%d",a[i]);
    if(i != 0){
      printf(" ");
    }
  }
  printf("\n");
  return 0;
}


Measured memory_bytes: 2044
#include<bits/stdc++.h>
#define fi first
#define se second
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define rep2(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define rev(i, n) for (int (i) = (n)-1; (i) >= 0; (i)--)
#define rev2(i, a, b) for (int (i) = (a)-1; (i) >= (b); (i)--)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define pb push_back
#define eb emplace_back
#define yn {puts("Yes");}else {puts("No");}
using namespace std;
using ll = long long;
using P = pair<int, int>;
using Pll = pair<long long, long long>;
template<class T> using Vec = vector<T>;
template<class T> using VVec = vector<vector<T>>;
long long TEN(int i) {return !i ? 1 : TEN(i-1)*10LL;}
template<class T, class U> 
bool chmin(T& a, const U& b) {if (a > b) {a = b; return 1;} return 0;}
template<class T, class U> 
bool chmax(T& a, const U& b) {if (a < b) {a = b; return 1;} return 0;}

struct IoSetup {
	IoSetup() {
		cin.tie(nullptr);
		ios::sync_with_stdio(false);
		cout << fixed << setprecision(10);
	}
} iosetup;

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//

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

	if (x == 0) cout << 1 << endl;
	else cout << 0 << endl;

	return 0;
}

Measured memory_bytes: 3652
#pragma GCC target("avx2")
#pragma GCC optimize("03")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std; typedef long double ld; typedef long long ll;
typedef unsigned long long ull;
#define endl "\n"
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define rep(i,n) for(int i=0;i<(n);i++)
#define PII pair<int, int>
#define PLL pair<ll, ll>
#define ALL(x) (x).begin(), (x).end()
constexpr int INF=1<<30; constexpr ll LINF=1LL<<60; constexpr ll mod=1e9+7; constexpr int NIL = -1;
template<class T>vector<T> vec(int len, T elem) { return vector<T>(len, elem); } // auto dp = vec(52, vec(103, vec(103, INF)));
template<class T>inline bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>inline bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
template<class T>inline int popcount(T a) {return __builtin_popcount(a);}
template<class T>inline T emod(T a, T p) { return (a%p + p) % p;}
//-------------------
int main() {
    cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(15);
    int n; cin >> n;
    ll mx = 0;
    ll res = 0;
    rep(i, n) {
        ll a; cin >> a;
        if(mx <= a) chmax(mx, a);
        else {
            res += mx - a;
        }
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 3608
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<cstdio>
#include<cstdlib>
using namespace std;

int main() {
	string S;
	cin >> S;

	int muri = 0;

	for (int i = 0; i < S.size(); ++i) {
		if (S[i] == 'x') {
			muri++;
		}
	}

	if (muri >= 8) {
		cout << "NO" << endl;
	}
	else {
		cout << "YES" << endl;
	}
}

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

using namespace std;
int main()
{
    string s,t;
    cin>>s>>t;
    int a,b;
    a=s.size();
    if (t.size()>s.size())
    {
        t.erase(a);
        //cout <<t<<endl;

        if (s.compare(t)==0)
        {
            cout<<"Yes"<<endl;
        }
        else
            cout<<"No"<<endl;
    }
    else
        cout<<"No"<<endl;



    return 0;
}


Measured memory_bytes: 3592
import sys
import math
from collections import Counter
import itertools
#from functools import reduce

# 入力を整数に変換して受け取る
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def MI1(): return map(int1, sys.stdin.readline().split())
# 入力全てを整数に変換したものの配列を受け取る
def LI(): return list(map(int, sys.stdin.readline().split()))
# 入力全てを整数に変換して1引いたものの配列を受け取る
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SR(): return sys.stdin.readline().rstrip()

ascii_lowercase = 'abcdefghijklmnopqrstuvwxyz'
ascii_uppercase = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
ascii_uppercase2 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ'

# リストを改行区切りで出力する
p2D = lambda x: print(*x, sep="\n")
p2E = lambda x: print(''.join(x))
p2S = lambda x: print(*x, sep=" ")

# ###########################################

N=II()

L=list()

for n in range(1, int(N**0.5)+1):
    if N%n==0:
        L.append((n+int(N/n))-2)

print(min(L))



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

int main() {
    int n; cin >> n;
    vector<int> a(n);
    for (auto& e : a) scanf("%d", &e);
    a.push_back(-1);
    
    int t = 1, ans = 0;
    for (int i = 0; i <= n - 1; i++) {
        if (a[i] == a[i+1]) t++;
        else {
            if (t != 0) ans += (t/2);
            t = 1;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let _n = read::<u32>();
    let k = read::<u32>() - 1;
    let s = read::<String>();
    for (i, c) in s.chars().enumerate() {
        if i == k as usize {
            print!("{}", ((c as u8) + 0x20) as char);
        }
        else {
            print!("{}", c);
        }
    }
    print!("\n");
}


Measured memory_bytes: 4352
#include <iostream>
#include <vector>
#include <string>

using namespace std;

const int maxn = 1e5, maxb = 22;

long long inf = 1e18;
long long mn[30];
int tmp[30];

long long min(long long x, long long y){return (x < y ? x : y);}

int main()
{
	long long n;
	cin >> n;
	for (int i = 0; i < 30; i++){mn[i] = inf;}
	for (int i = 0; i < n; i++)
	{
		string s;
		cin >> s;
		for (int j = 0; j < 30; j++){tmp[j] = 0;}
		for (int j = 0; j < s.size(); j++)
		{
			tmp[int(s[j] - 'a')]++;
		}
		for (int j = 0; j < 27; j++)
		{
			mn[j] = min(mn[j], tmp[j]);
		}
	}
	string ans;
	for (int i = 0; i < 26; i++)
	{
		if (mn[i] == inf){continue;}
		for (int j = 0; j < mn[i]; j++)
		{
			ans += char(i + 'a');
		}
	}
	cout << ans;

	return 0;
}
	
	
	
	
	
	
	
	
	
	


Measured memory_bytes: 256
N,M=map(int,input().split())
l = [list(map(int, input().split())) for i in range(N)]
new=[0 for i in range(M)]
for i in range(N):
    for j in range(M):
        new[j]+=l[i][j]
    for z in l[i]:
        print(z,end=" ")
    print(sum(l[i]))
for c in new:
    print(c,end=" ")
print(sum(new))



Measured memory_bytes: 6224
#include<iostream>
#include<math.h>
#include<algorithm>
#define ll long long int
#define FOR(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define REP(i,n) FOR(i,0,n)
#define REP1(i,n) FOR(i,1,n)

using namespace std;

int main(){
	int N, T;
	cin >> N >> T;
	int c[N], t[N];
	REP(i,N){
		cin >> c[i] >> t[i];
	} 
	int m = 2000;
	REP(i,N){
		if(t[i] <= T){
			m = min(c[i], m);
		}
	}
	if(m == 2000) cout << "TLE" << endl;
	else cout << m << endl;
	return 0;
}


Measured memory_bytes: 256
/**************************
*                         *
*  Nothing Is Impossible  *
*                         *
**************************/
#include <algorithm>
#include <pthread.h>
#include <iostream>
#include <fstream>
#include <ctype.h>
#include <string>
#include <vector>
#include <thread>
#include <math.h>
#include <queue>
#include <stack>
#include <tuple>
#include <cmath>
#include <set>
#include <map>
#define GetRand(Min, Max) ((rand()%(int)(((Max) + 1)-(Min))) + (Min))
#define Rep(i, min, max) for(ll i = min; i < max; ++i)
#define PB push_back
#define MP make_pair
typedef long long ll;
typedef long double ld;
using namespace std;

void Solve(){
	int n;	cin >> n;
	int dp[n][3], grid[n][3];
	Rep(i,0,n){
		cin >> grid[i][0] >> grid[i][1] >> grid[i][2];
	}
	int ans;
	dp[0][0] = grid[0][0];	dp[0][1] = grid[0][1];
	dp[0][2] = grid[0][2];
	Rep(i,1,n){
		dp[i][0] = grid[i][0]+max(dp[i-1][1],dp[i-1][2]);
		dp[i][1] = grid[i][1]+max(dp[i-1][0],dp[i-1][2]);
		dp[i][2] = grid[i][2]+max(dp[i-1][0],dp[i-1][1]);
	}
	ans = max(dp[n-1][0],dp[n-1][1]);
	ans = max(ans,dp[n-1][2]);
	cout << ans << endl;
}

int main(){
	ios::sync_with_stdio(NULL);
	cin.tie(NULL); cout.tie(NULL);
	int t = 1;
	//int t;	cin >> t;
	while(t--) Solve();
	return 0;
}

Measured memory_bytes: 2688
#include<stdio.h>
#include<string.h>

int main()
{
	char a[1000005];
	scanf("%s",a);
	long long x=0,y=strlen(a)-1,lose=1;
	long long anc=0;
	while(x<=y)
	{
		if(a[x]!=a[y])
		{
			if(a[x]=='x')
			{
				anc++;
				x++;
			}
			else
				if(a[y]=='x')
				{
					anc++;
					y--;
				}
				else
				{
					lose=0;
					break;
				}
		}
		else
		{
			x++;
			y--;
		}
			
			
	}
		
	if(lose)
		printf("%lld\n",anc);
	else
		printf("-1\n");
	
	return 0;
}

Measured memory_bytes: 256
n, k = map(int, input().split())
h = list(map(int, input().split()))
dp = [float('inf')] * n
dp[0] = 0
for i in range(n):
	for j in range(1, k + 1):
		if i + j < n:
			dp[i + j] = min(dp[i + j], dp[i] + abs(h[i + j] - h[i]))
print(dp[-1])

Measured memory_bytes: 55264
s = gets()
# s = "35753"
ss = s.split('')
min = 1000000
ss.each_with_index do |v, i|
  if i + 3 <= s.length
    a = s[i]
    b = s[i + 1]
    c = s[i + 2]
    num = ((a + b + c).to_i - 753).abs
    min = min > num ? num : min
  end
end
p min


Measured memory_bytes: 1788
import java.io.BufferedReader;
import java.io.InputStreamReader;

class Main {
  public static void main(String[] args) throws Exception{
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
      char[] cl = br.readLine().toCharArray();
      StringBuffer sb = new StringBuffer("");
      for (char c : cl){
        if (c == '0' || c == '1' ) {
          sb.append(c);
        } else {
          if(!sb.toString().isEmpty()){
            sb.delete(sb.toString().length() - 1,sb.toString().length());
          }
        }
      }
      System.out.println(sb.toString());
  }
}

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

/* REPmacro */
#define REP(i,n) for(int i=0,i##_len=(n);i<i##_len;++i)
#define REPR(i,n) for(int i=((int)(n)-1);i>=0;--i)
#define FOR(i,m,n) for(int i=(int)(m);i<(int)(n);++i)

/*alias*/
#define ALL(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define MP make_pair 

#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev

/*using*/
using ll = long long;
using ull = unsigned long long;
using unsi = unsigned;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using pii = pair<int, int>;
using db = double;
using plex = complex<double>;
using vs = vector<string>;

/*template*/
template<class T>inline bool amax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>inline bool amin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

/* func */

/*struct*/
struct aaa{
    aaa(){
        cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);
    };
}aaaaaaa;

/* const */
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7; //10^9
const db EPS = 1e-9;
const int dx[] = {0, 1, 0, -1, 1, -1, 1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};

//#define int ll
//#define int long long

int findAndreturnAns(string s, int i){

  int tmp{};
  int tmp2{};

  for(int k = i; k < s.size(); ++k){

     if(s[k] == 'A' || s[k] == 'T' || s[k] == 'G' || s[k] == 'C'){
       tmp = k;
       break;
     }
  }
  
  for(int k = tmp; k < s.size(); ++k){

    if(s[k] != 'A' && s[k] != 'T' && s[k] != 'G' && s[k] != 'C'){
      tmp2 = k;
      break;
    }
    
    if(k == s.size()-1)
      tmp2 = k+1;
  }
  
  return tmp2-tmp;
}

signed main()
{
  string s{}; cin >> s;
  
  vector<int> v1(s.size());
  
  for(int i = 0; i < s.size(); ++i)
     v1.EB(findAndreturnAns(s,i));
  
  cout << *max_element(ALL(v1));
  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
typedef long long ll;
struct edge { ll s, t, x; };
typedef pair<ll, ll> P;
typedef pair<ll,P> event;
const ll MAX = 510000;
const ll MOD = 1000000007;

int main() {
  ll N,K;
  cin>>N>>K;
  vector<ll>A(N);
  ll sum=0ll;
  rep(i,N){cin>>A[i];sum+=A[i];}
  ll n=sum;
  vector< ll > ret;
  for(ll i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      ret.push_back(i);
      if(i * i != n) ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  ll ans=0ll;
  for(ll d:ret){
    vector<ll>B(N);
    vector<ll>mae(N+1);
    vector<ll>usi(N+1);
    mae[N]=0ll;usi[N]=0ll;
    rep(i,N){B[i]=A[i]%d;mae[i]=0ll;usi[i]=0ll;}
    sort(B.begin(),B.end());
    mae[0]=0ll;
    usi[N]=0ll;
    rep(i,N){mae[i+1]=mae[i]+B[i];}
    rep(i,N){usi[N-1-i]=usi[N-i]+(d-B[N-1-i]);}
    int flag=-1;
    rep(i,N+1){
      if(mae[i]==usi[i]&&mae[i]<=K){flag=1;}
    }
    if(flag==1){ans=max(ans,d);}
  }
  cout<<ans;
}


Measured memory_bytes: 3672
#include <bits/stdc++.h>
struct UnionFind {
    int sz;
    std::vector<int> par;
    UnionFind(int sz) {
        this->sz = sz;
        par.clear();
        par.resize(sz, -1);
    }
    int root(int x) {
        return par[x] < 0 ? x : par[x] = root(par[x]);
    }
    void unite(int a, int b) {
        int roota = root(a);
        int rootb = root(b);
        if(roota == rootb) return;
        if(par[rootb] < par[roota]) std::swap(roota, rootb);
        par[roota] += par[rootb];
        par[rootb] = roota;
    }
    bool same(int a, int b) {
        return (root(a) == root(b));
    }
    int size(int a) {
        return -par[root(a)];
    }
};
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using vi = vector<ll>;
using vvi = vector<vector<ll>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const double eps = 1e-10;
const ll MOD = 1000000007;
const ll INF = 1000000000;
const ll LINF = 1ll<<50;
template<typename T>
void printv(const vector<T>& s) {
  for(ll i=0;i<(ll)(s.size());++i) {
    cout << s[i];
    if(i == (ll)(s.size())-1) cout << endl;
    else cout << " ";
  }
}
signed main() {
  cin.tie(0);
  cout << fixed << setprecision(10);
  ll n, m; cin >> n >> m;
  vector<P> p(m);
  for(ll i=0;i<m;++i) {
    cin >> p[i].first >> p[i].second;
  }
  reverse(p.begin(), p.end());
  UnionFind uf(n);
  ll ma = n * (n-1) / 2;
  ll now = 0;
  vector<ll> ans;
  for(ll i=0;i<m;++i) {
    ans.push_back(ma - now);
    ll a = p[i].first - 1, b = p[i].second - 1;
    ll sza = uf.size(a), szb = uf.size(b);
    if(uf.same(a, b)) continue;
    now -= sza * (sza - 1) / 2 + szb * (szb - 1) / 2;
    uf.unite(a, b);
    sza = uf.size(a);
    now += sza * (sza - 1) / 2;
  }
  reverse(ans.begin(), ans.end());
  for(ll i=0;i<m;++i) {
    cout << ans[i] << endl;
  }
}


Measured memory_bytes: 4212
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
#define MAX_N 200005

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

    priority_queue<int> q;
    rep(i,n){
        int x; cin >> x;
        q.push(x);
    }

    rep(i,m){
        int x  = q.top();
        q.pop();
        x /= 2;
        q.push(x);
    }

    ll ans = 0;
    rep(i,n){
        ans += q.top();
        q.pop();
    }
    cout << ans << endl;
    return 0;
}
 
 


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

#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl;
typedef long long ll;
typedef unsigned long long ull;

int main()
{
    int m, f, r;
    while (1)
    {
        cin >> m >> f >> r;
        if (m == -1 && f == -1 && r == -1)
        {
            break;
        }
        int sum = m + f;
        if (m == -1 || f == -1)
        {
            OP("F")
        }
        else if (sum >= 80)
        {
            OP("A")
        }
        else if (sum >= 65 && sum < 80)
        {
            OP("B")
        }
        else if (sum >= 50 && sum < 65)
        {
            OP("C")
        }
        else if (sum >= 30 && sum < 50)
        {
            if (r >= 50)
            {
                OP("C")
            }
            else
            {
                OP("D")
            }
        }
        else if (sum < 30)
        {
            OP("F")
        }
    }

    return 0;
}


Measured memory_bytes: 3100
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce


sys.setrecursionlimit(2147483647)
INF = 1 << 100
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007


n = I()
a, b = LS()
ans = ''
for i in range(n):
    ans += a[i]
    ans += b[i]

print(ans)


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

#ifdef HOME
#define db(x) cerr << #x << " = " << x << endl
#define db3(x, y, z) cerr << "(" << #x << ", " << #y << ", " << #z << ") = (" << x << ", " << y << ", " << z << ")" << endl
#define db2(x, y) cerr << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")" << endl
#define dbv(a) cerr << #a << " = "; for (auto xxx: a) cerr << xxx  << " "; cerr << endl
#else
#define db(x) ;
#define db3(x, y, z) ;
#define db2(x, y) ;
#define dbv(a) ;
#endif

using namespace std;
typedef long long ll;
typedef double dbl;


const int INF = 1.01e9;

ll solve(int n, vector<int> a, vector<int> b) {
    set<pair<int, int>> st;
    for (int i = 0; i < n; i++) st.insert({b[i], i});

    ll ans = 0;
    while (!st.empty()) {
        auto it = st.rbegin();
        int i = it->second;
        st.erase(*it);
        if (b[i] == a[i]) continue;
        else if (b[i] < a[i]) return -1;
        else if (b[i] > a[i]) {
            int t = b[(i - 1 + n) % n] + b[(i + 1) % n];
            if (b[i] <= t) return -1;
            if ((b[i] - a[i]) % t == 0) {
                ans += (b[i] - a[i]) / t;
                b[i] = a[i];
            } else {
                ans += b[i] / t;
                b[i] %= t;
            }
            st.insert({b[i], i});
        } else assert(0);
    }
    return ans;
}

int main() {
#ifdef HOME
    assert(freopen("in", "r", stdin));
#endif

    int n;
    vector<int> a(n), b(n);
    while (scanf("%d", &n) == 1) {
        vector<int> a(n), b(n);
        for (int i = 0; i < n; i++) scanf("%d", &a[i]);
        for (int i = 0; i < n; i++) scanf("%d", &b[i]);
        cout << solve(n, a, b) << endl;
    }

#ifdef HOME
    cerr << "time: " << clock() * 1.0 / CLOCKS_PER_SEC << endl;
#endif
}


Measured memory_bytes: 12800
n = int(input())
a = sorted((tuple(map(int, input().split())) for i in range(n)))
a.append((10 ** 18, 1))
mo = 998244353
dp = [0] * (n + 1)
dp[n] = 1
f = list(range(n))
fr = list(range(n))
bd = [x + d for x, d in a]
def getF(u):
    if f[f[u]] != f[u]:
        f[u] = getF(f[u])
        return f[u]
    return f[u]
def uniF(u, v):
    u = getF(u)
    v = getF(v)
    if u == v:
        return
    f[u] = v
    fr[v] = max(fr[v], fr[u])
    bd[v] = max(bd[v], bd[u])
for i in range(n - 1, -1, -1):
    cur = i
    while fr[getF(cur)] + 1 < n and a[fr[getF(cur)] + 1][0] < bd[getF(cur)]:
        uniF(cur, fr[getF(cur)] + 1)
    dp[i] = (dp[i + 1] + dp[fr[getF(cur)] + 1]) % mo
print(dp[0])

Measured memory_bytes: 93144
n,k = map(int,input().split())
P = list(map(int,input().split()))
C = list(map(int,input().split()))
g = [[0]*(n) for _ in range(n)]
A = [n]*n
# for i in range(n):
#     tmp = 0
#     idx = i
#     cnt = 0
#     set_ =set()
#     while cnt<n:
#         if C[idx] not in set_:
#             tmp += C[idx]
#             set_.add(C[idx])
#             g[i][cnt] = tmp
#             idx = P[idx]-1
#             cnt += 1
#         else:
#             p = len(set_)
#             A[i] = p
#             break
ans = -float('inf')

for i in range(n):
    S = []
    idx = P[i]-1
    S.append(C[idx])
    while idx != i:
        idx = P[idx]-1
        S.append(S[-1] +C[idx])
    v,w = k//len(S),k%len(S)
    if k<=len(S):
        val = max(S[:k])
    elif S[-1]<=0:
        val = max(S)
    else:
        val1 = S[-1] *(v-1)
        val1 += max(S)
        val2 = S[-1]*v
        if w!=0:
            val2 += max(0,max(S[:w]))
        val = max(val1,val2)
    ans = max(ans,val)
# for i in range(n):
#     v,w = k//A[i],k%A[i]
#     if A[i]<k:
#         if g[i][A[i]-1]<=0:
#             val = max(g[i][:A[i]])
#         else:
#             val1 = (v-1)*g[i][A[i]-1]
#             val1 += max(g[i][:A[i]])
#             val2 = v*g[i][A[i]-1]
#             if w!=0:
#                 val2 += max(0,max(g[i][:w]))
#             val = max(val1,val2)
#     else:
#         val = max(g[i][:k])
#     ans = max(ans,val)
print(ans)

Measured memory_bytes: 276876
#include <bits/stdc++.h>
using namespace std;
int a;
bool isPrime(int n){
	for(int i=2;i<sqrt(n);++i)
		if(n%i==0)return false;
	return true;
}
int main(){
	cin>>a;
	while(!isPrime(a++));
	cout<<a-1;
}

Measured memory_bytes: 256
program answer
  implicit none
  integer :: A, B, K, i, c, d
  read(*,*) A, B, K

  c=A
  d=B
  do i = 1, K
     if(mod(i,2)==1) then
     if(mod(c,2)==1) then
        c=c-1
        c=c/2
        d=d+c
     else
        c=c/2
        d=d+c
     end if

     else
  
     if(mod(d,2)==1) then
        d=d-1
        d=d/2
        c=c+d
     else
        d=d/2
        c=c+d
     end if
     end if
  end do

  write(*,*) c, d
  stop
 end program answer

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

#pragma GCC optimize("O3")
using namespace std;
#define ll long long
#define ull unsigned long long
#define rep(i,n,N) for(ll i=n;i<=N;++i)
#define rap(i,n,N) for(ll i=n;i>=N;--i)
#define mp make_pair
#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define fi first
#define se second
#define ff fi.fi
#define fs fi.se
#define sf se.fi
#define ss se.se
#define lc (id<<1)
#define rc ((id<<1)|1)
#define db(x) cout << ">>>>>> " << #x << " -> " << x << endl;
#define all(x) x.begin(),x.end()
#define pii pair<int,int> 
#define pll pair<ll,ll>
#define piii pair<int,pii>
#define piiii pair<pii,pii>
#define psi pair<string,int>
#define endl "\n"
const int MAX = 3e5+5;
const ll MAX2 = 11;
const ll MOD = 1000000007;
const ll INF = 2e18;
const int dr[]={1,0,-1,0,1,1,-1,-1,0};
const int dc[]={0,1,0,-1,1,-1,1,-1,0};
const double pi = acos(-1);
const double EPS = 1e-9;
const int block = 450;

ll tc,n,a,b,x,ans;

int main(){
//	cout<<fixed<<setprecision(15);
//    freopen("input.txt", "r", stdin);
//	freopen("output.txt","w",stdout);
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cin>>tc;
    while(tc--){
    	cin>>n>>x;
    	ans = 0;
    	rep(i,2,n)ans+=127, x^=127;
    	cout<<ans+x<<endl;
	}
	return 0;
}//

Measured memory_bytes: 256
import java.util.Scanner;


public class Main {
	static int N;
	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		 N = sc.nextInt();
		 sc.close();

		 int p = (int)(Math.pow(10,9)+7);


		 long ans = 1 ;
		 for(int i = 1 ; i < N+1 ; i++){
			 ans = (ans*i)%p;
		 }

		 System.out.println(ans);

	}
}

Measured memory_bytes: 21972
#include <stdio.h>
#include <string.h>
#include <ctype.h>

int P,Q,R;
char *p;

int formula(){
  int l,r;
  char c = *p++;
  if(isdigit(c)) return c-'0';
  if(isupper(c)) return (c == 'P' ? P : c == 'Q' ? Q : R);
  if(c == '-') return 2-formula();
  if(c == '('){
    l = formula();
    if(*p++ == '*'){
      r = formula();
      *p++;
      return (l < r ? l : r);
    }else{
      r = formula();
      *p++;
      return (l > r ? l : r);
    }  
  }
  return 0;
}

int main(){
  int ans;
  char s[1000];
  while(scanf("%s",s), strcmp(s,".") != 0){
    ans = 0; 
    for(P = 0 ; P < 3 ; P++){
      for(Q = 0 ; Q < 3 ; Q++){
        for(R = 0 ; R < 3 ; R++){
          p = s;
          if(formula() == 2) ans++;
        }
      }
    }
    printf("%d\n",ans);
  }
  return 0;
}

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


def main():
    A, B, M = map(int, input().split())
    al = list(map(int, input().split()))
    bl = list(map(int, input().split()))
    disc = []
    for i in range(M):
        x, y, c = map(int, input().split())
        disc.append({"x": x, "y": y, "c": c})

    # 割引券なしの最小値
    a_min = min(al)
    b_min = min(bl)
    ans = a_min + b_min

    # 割引券をつかう場合
    for d in disc:
        c = al[d["x"] - 1] + bl[d["y"] - 1] - d["c"]
        ans = min(ans, c)

    print(ans)


if __name__ == '__main__':
    main()


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

int main() {
  int n;
  cin >> n;
  
  if(n <= 111){
    cout << 111 << endl;
  }
  
  else if(n <= 222){
    cout << 222 << endl;
  }
  
  else if(n <= 333){
    cout << 333 << endl;
  }
  
  else if(n <= 444){
    cout << 444 << endl;
  }
  
  else if(n <= 555){
    cout << 555 << endl;
  }
  
  else if(n <= 666){
    cout << 666 << endl;
  }
  
  else if(n <= 777){
    cout << 777 << endl;
  }
  
  else if(n <= 888){
    cout << 888 << endl;
  }
  
  else{
    cout << 999 << endl;
  }
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<math.h>
#include<set>
#include<vector>
#include<map>
#include<functional>
#include<iomanip>
#include<queue>
#include<deque>
#include<string>
#include<random>
#include<numeric>
#include<string>
typedef long long ll;
using namespace std;

ll gcd(ll a, ll b) {
	if (a<b) { return gcd(b, a); }
	else if (a%b) { return gcd(b, a%b); }
	else { return b; }
}
int main() {
	ll N;
	cin >> N;
	ll a[3][110];
	ll max = 0;
	for (ll i = 0; i < 2; i++) {
		for (ll j = 0; j < N; j++) {
			cin >> a[i][j];
		}
	}
	for (ll i = 0; i < N; i++) {
		ll sum = 0;
		for (ll j = 0; j <= i; j++)sum += a[0][j];
		for (ll j = i; j < N; j++)sum += a[1][j];
		if (sum > max) max = sum;
	}
	cout << max << endl;

}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**7)
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return sys.stdin.readline().strip()
INF = 10 ** 18
MOD = 10 ** 9 + 7

def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = MOD
N = 2001
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

def main(): 
    n, k = LI()

    m = n-k

    for i in range(1, k+1):
        print(cmb(m+1, i, MOD) * cmb(k-1, i-1, MOD) % MOD)


main()

Measured memory_bytes: 3572
#include <iostream>
#include <climits>
#include <vector>
#include <algorithm>
#define ll long long
using namespace std;

void lazy_query(ll k,ll l,ll r, vector<ll>& node, vector<ll>& lazy, ll n) {
	node[k] += lazy[k] * (r - l);
	if (k < n - 1) {
		lazy[2 * k + 1] += lazy[k];
		lazy[2 * k + 2] += lazy[k];
	}
	lazy[k] = 0;
}

void add(ll a, ll b, ll x, ll k, ll l, ll r, vector<ll>&node, vector<ll>& lazy, ll n) {
	lazy_query(k, l, r, node, lazy, n);
	if (r <= a || b <= l)return;
	if (a <= l && r <= b) {
		lazy[k] += x;
		lazy_query(k, l, r, node, lazy, n);
		return;
	}
	else {
		add(a, b, x, 2 * k + 1, l, (l + r) / 2, node, lazy, n);
		add(a, b, x, 2 * k + 2, (l + r) / 2, r, node, lazy, n);
		node[k] = node[2 * k + 1] + node[2 * k + 2];
		return;
	}
}

ll getSum(ll a, ll b, ll k, ll l, ll r, vector<ll>&node, vector<ll>& lazy, ll n) {
	lazy_query(k, l, r, node, lazy, n);
	if (r <= a || b <= l)return 0;
	if (a <= l && r <= b) {
		return node[k];
	}
	else {
		ll vl = getSum(a, b, 2 * k + 1, l, (l + r) / 2, node, lazy, n);
		ll vr = getSum(a, b, 2 * k + 2, (l + r) / 2, r, node, lazy, n);
		node[k] = node[2 * k + 1] + node[2 * k + 2];
		return vr + vl;
	}
}

int main() {
	cin.tie(0); ios::sync_with_stdio(false);
	int n_, q;  cin >> n_ >> q;
	int n = 1;
	while (n < n_) n *= 2;
	vector<ll> node(2 * n - 1, 0);
	vector<ll> lazy(2 * n - 1, 0);

	for (int i = 0; i < q; i++) {
		int com; cin >> com;
		if (com == 0) {
			ll s, t, x; cin >> s >> t >> x;
			add(s - 1, t, x, 0, 0, n, node, lazy, n);
		}
		else {
			ll s, t; cin >> s >> t;
			cout << getSum(s - 1, t, 0, 0, n, node, lazy, n) << endl;
		}
	}
}

Measured memory_bytes: 7036
#if __cplusplus > 199711L      /* C++11 */
#include <unordered_map>
#include <unordered_set>
#include <forward_list>
#include <array>
#endif                         /* C++11 */
#include <cstdio>
#include <cmath>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <climits>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <algorithm>
#include <set>
#include <map>
#include <list>
#include <deque>
#include <vector>
#include <string>
#include <bitset>
#define y0 qvya13579
#define y1 qvyb24680
#define j0 qvja13579
#define j1 qvjb24680
#define next qvne13579xt
#define prev qvpr13579ev
#define INF 1000000007
#define PI acos(-1.0)
#define endl "\n"
#define IOS cin.tie(0);ios::sync_with_stdio(false)
#define M_P make_pair
#define P_B push_back
#define U_B upper_bound
#define L_B lower_bound
#define P_Q priority_queue
#define FIR first
#define SEC second
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define REP_R(i,n) for(int i=((int)(n)-1);i>=0;--i)
#define FOR(i,m,n) for(int i=((int)(m));i<(int)(n);++i)
#define FOR_R(i,m,n) for(int i=((int)(m)-1);i>=(int)(n);--i)
#define ALL(v) (v).begin(),(v).end()
#define RALL(v) (v).rbegin(),(v).rend()
#define SIZ(x) ((int)(x).size())
#define COUT(x) cout<<(x)<<endl
#define CIN(x) cin>>(x)
#define CIN2(x,y) cin>>(x)>>(y)
#define CIN3(x,y,z) cin>>(x)>>(y)>>(z)
#define CIN4(x,y,z,w) cin>>(x)>>(y)>>(z)>>(w)
#define SCAND(x) scanf("%d",&(x))
#define SCAND2(x,y) scanf("%d%d",&(x),&(y))
#define SCAND3(x,y,z) scanf("%d%d%d",&(x),&(y),&(z))
#define SCAND4(x,y,z,w) scanf("%d%d%d%d",&(x),&(y),&(z),&(w))
#define SCANLLD(x) scanf("%lld",&(x))
#define SCANLLD2(x,y) scanf("%lld%lld",&(x),&(y))
#define SCANLLD3(x,y,z) scanf("%lld%lld%lld",&(x),&(y),&(z))
#define SCANLLD4(x,y,z,w) scanf("%lld%lld%lld%lld",&(x),&(y),&(z),&(w))
#define PRINTD(x) printf("%d\n",(x))
#define PRINTLLD(x) printf("%lld\n",(x))
typedef long long int lli;
using namespace std;

int ctoi(char c)
{
  if( c >= '0' and c <= '9' )
    {
      return (int)(c-'0');
    }

  return -1;
}

int alphabet_pos(char c) 
{
  if( c >= 'a' and c <= 'z' )
    {
      return (int)(c-'a');
    }

  return -1;
}


int alphabet_pos_capital(char c)
{
  if( c >= 'A' and c <= 'Z' )
    {
      return (int)(c-'A');
    }

  return -1;
}


vector<string> split(string str, char ch)
{
  int first = 0;
  int last = str.find_first_of(ch);
  
  if(last == string::npos)
    {
      last = SIZ(str);
    }

  vector<string> result;

  while( first < SIZ(str) )
    {
      string Ssubstr(str, first, last - first);
      result.push_back(Ssubstr);
      first = last + 1;
      last = str.find_first_of(ch, first);

      if(last == string::npos)
	{
	  last = SIZ(str);
	}
    }
  
  return result;
}

/*--------------- the end of the template --------------------*/









int main()
{
  //IOS; /* making cin faster */
  int N;
  string S;

  CIN(S);
  N = stoi(S);

  int cnt = 0;
  
  REP(i,SIZ(S))
    {
      cnt += ctoi(S[i]);
      
    }

  if( N % cnt == 0 )
    {
      printf("Yes\n");
      
    }
  else
    {
      printf("No\n");
    }

}


Measured memory_bytes: 256
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys


def input():
    return sys.stdin.readline()


def resolve():
    k, n = map(int, input().split())
    a_list = list(map(int, input().split()))

    max_distance = 0

    for i in range(len(a_list)):
        if i == 0:
            continue
        else:
            distance = a_list[i] - a_list[i-1]
            if max_distance < distance:
                max_distance = distance
                max_address_1 = i - 1
                max_address_2 = i

    first_a = a_list[0]
    last_a = a_list[n-1]

    distance = first_a + (k - last_a)

    if max_distance <= distance:
        # 時計回りで計算
        move_distance = last_a - first_a
    else:
        # 反時計回りで計算
        move_distance = a_list[max_address_1] + (k - a_list[max_address_2])

    print(move_distance)




if __name__ == "__main__":
    resolve()



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

ll h, w;

ll h_div(){
	if(h % 3 == 0 || w % 3 == 0) return 0;
	ll h_case1 = h / 3, h_case2 = h / 3 + 1;
	ll s1_case1 = h_case1 * w, s2_case1 = (h - h_case1) * (w / 2), s3_case1 = h * w - (s1_case1 + s2_case1); 
	ll s1_case2 = h_case2 * w, s2_case2 = (h - h_case2) * (w / 2), s3_case2 = h * w - (s1_case2 + s2_case2); 
	ll dif_case1 = max(s1_case1, max(s2_case1, s3_case1)) - min(s1_case1, min(s2_case1, s3_case1));
	ll dif_case2 = max(s1_case2, max(s2_case2, s3_case2)) - min(s1_case2, min(s2_case2, s3_case2));
	return min(dif_case1, dif_case2);
}

ll w_div(){
	if(h % 3 == 0 || w % 3 == 0) return 0;
	ll w_case1 = w / 3, w_case2 = w / 3 + 1;
	ll s1_case1 = w_case1 * h, s2_case1 = (w - w_case1) * (h / 2), s3_case1 = h * w - (s1_case1 + s2_case1); 
	ll s1_case2 = w_case2 * h, s2_case2 = (w - w_case2) * (h / 2), s3_case2 = h * w - (s1_case2 + s2_case2); 
	ll dif_case1 = max(s1_case1, max(s2_case1, s3_case1)) - min(s1_case1, min(s2_case1, s3_case1));
	ll dif_case2 = max(s1_case2, max(s2_case2, s3_case2)) - min(s1_case2, min(s2_case2, s3_case2));
	return min(dif_case1, dif_case2);
}

int main(){
	cin >> h >> w;
	cout << min(min(h_div(), w_div()), min(h, w)) << endl;
	return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
inline void rd(int &x){
  int k;
  int m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void rd(long long &x){
  int k;
  int m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(long long x){
  int s=0;
  int m=0;
  char f[20];
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
template<class S, class T> inline S chmin(S &a, T b){
  if(a>b){
    a=b;
  }
  return a;
}
int N;
long long A[200000];
int main(){
  int i;
  long long res = 4611686016279904256LL;
  long long s;
  long long c = 0;
  rd(N);
  {
    int Lj4PdHRW;
    for(Lj4PdHRW=(0);Lj4PdHRW<(N);Lj4PdHRW++){
      rd(A[Lj4PdHRW]);
    }
  }
  {
    int e98WHCEY;
    long long cTE1_r3A;
    if(N==0){
      cTE1_r3A = 0;
    }
    else{
      cTE1_r3A = A[0];
      for(e98WHCEY=(1);e98WHCEY<(N);e98WHCEY++){
        cTE1_r3A += A[e98WHCEY];
      }
    }
    s =cTE1_r3A;
  }
  for(i=(0);i<(N-1);i++){
    c += A[i];
    chmin(res, abs(s-2*c));
  }
  wt_L(res);
  wt_L('\n');
  return 0;
}
// cLay varsion 20191123-1

// --- original code ---
// int N; ll A[2d5];
// {
//   ll res = ll_inf, s, c = 0;
//   rd(N,A(N));
//   s = sum(A(N));
//   rep(i,N-1){
//     c += A[i];
//     res <?= abs(s-2*c);
//   }
//   wt(res);
// }


Measured memory_bytes: 1792
n=input()
l=len(n)
k=int(input())
def f(n,k):
  l=len(n)
  if l<k:return 0
  if n[0]=="0":return f(n[1:],k)
  if k==1:
    ans=((l-1)*9)+int(n[0])
  if k==2:
    ans=((l-1)*(l-2)//2)*81+(int(n[0])-1)*((l-1)*9)
    ans+=f(n[1:],k-1)
  if k==3:
    ans=(int(n[0])-1)*((l-1)*(l-2)//2)*81+((l-1)*(l-2)*(l-3)//6)*9*9*9
    ans+=f(n[1:],k-1)
  return ans
print(f(n,k))

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

using namespace std;

int main(void){
  int N;
  cin >> N;
  
  vector<int> W(N);
  vector<int> csum(N);
  
  for(int i=0;i<N;i++){
    cin >> W[i];
  }
  csum[0] = W[0];
  for(int i=1;i<N;i++){
    csum[i] = W[i] + csum[i-1];
  }
  int abs_min = csum[N-1];
  for(int i=1;i<(N-1);i++){
  	abs_min = min(abs_min,abs(csum[N-1] - 2*csum[i]));
  }
  
  cout << abs_min << endl;
  return 0;
}
  
  
  


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

int main(){
	long long x,y;
	cin >> x >> y;
	
	long long two = 2;
	int ans = 0;
	for(int i=1;i<100;i++){
		if(x*two > y){
			ans = i;
			break;
		}
		two *= 2;
	}
	
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
/**
 * Created at 7:17 on 2019/03/07
 */

import java.io.*;
import java.util.*;

public class Main {

  static FastScanner sc = new FastScanner();

  public static void main(String[] args) {

    int N = sc.nextInt();

    for (int i=1; i<=9; i++) {
      int a = i * 100 + i * 10 + i;
      if (a >= N) {
        System.out.println(a);
        return;
      }
    }

  }

  static class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;

    private boolean hasNextByte() {
      if (ptr < buflen) {
        return true;
      } else {
        ptr = 0;
        try {
          buflen = in.read(buffer);
        } catch (IOException e) {
          e.printStackTrace();
        }
        if (buflen <= 0) {
          return false;
        }
      }
      return true;
    }

    private int readByte() {
      if (hasNextByte()) return buffer[ptr++];
      else return -1;
    }

    private static boolean isPrintableChar(int c) {
      return 33 <= c && c <= 126;
    }

    private void skipUnprintable() {
      while (hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;
    }

    public boolean hasNext() {
      skipUnprintable();
      return hasNextByte();
    }

    public String next() {
      if (!hasNext()) throw new NoSuchElementException();
      StringBuilder sb = new StringBuilder();
      int b = readByte();
      while (isPrintableChar(b)) {
        sb.appendCodePoint(b);
        b = readByte();
      }
      return sb.toString();
    }

    public long nextLong() {
      if (!hasNext()) throw new NoSuchElementException();
      long n = 0;
      boolean minus = false;
      int b = readByte();
      if (b == '-') {
        minus = true;
        b = readByte();
      }
      if (b < '0' || '9' < b) {
        throw new NumberFormatException();
      }
      while (true) {
        if ('0' <= b && b <= '9') {
          n *= 10;
          n += b - '0';
        } else if (b == -1 || !isPrintableChar(b)) {
          return minus ? -n : n;
        } else {
          throw new NumberFormatException();
        }
        b = readByte();
      }
    }

    public int nextInt() {
      return (int) nextLong();
    }
  }

}


Measured memory_bytes: 21204
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <algorithm>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> pll;

// to container
template <class C>
void input(C &c)
{
    for_each(c.begin(), c.end(), [](auto &i) { cin >> i; });
}

// to number, string
template <class T>
T input()
{
    T data;
    cin >> data;
    return data;
}

int main()
{
    int N = input<int>();
    string S = input<string>();

    bool res;
    if (N % 2 == 0)
    {
        if (S.substr(0, N / 2) == S.substr(N / 2, N))
            res = true;
        else
        {
            res = false;
        }
    }
    else
    {
        res = false;
    }

    cout << (res ? "Yes" : "No") << endl;
    return 0;
}

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



int main()
{
vector <char> yoyo;
bool y=false;
string s,t,p="";

cin>>s>>t;	
char l;

int o=s.size();


for(int i=0;i<o;i++){
	yoyo.push_back(s[i]);
	
}



for(int j=0;j<o;j++){

l=yoyo[o-1];
yoyo.pop_back();
yoyo.insert(yoyo.begin()+0,l);

for(int j=0;j<o;j++){
	p+=yoyo[j];
}
if(p==t)
	{
		y=true;
		break;
	}
else{
	p="";
	continue;
}
}
if(y==true)
	cout<<"Yes";
else
	cout<<"No";	





}


/*#include<bits/stdc++.h>


void jep (vector <string> &yoyo);
using namespace std;
int main(){
int n,c,y=0,x=0;

string s,t,n;

cin>>s>>t;

n=s[s.size()-1];


}
void jep (vector <string> yoyo){
char x,l;
string s;	
for(int i=0;i<s.size();i++){
	yoyo.push_back(cin>>x);
		
}
l=yoyo[0];
yoyo.pop_back();
yoyo.push_back(l);

}*/

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

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

int main() {
    int N, X;
    cin >> N >> X;
    vector<int> v(N);
    for (int i = 0; i < N; i++) {
        int x;
        cin >> x;
        v[i] = abs(x - X);
    }

    int res = 0;
    for (int i = 0; i < N; i++)
        res = gcd(res, v[i]);

    cout << res << endl;
    return 0;
}

Measured memory_bytes: 640