akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <cassert>
#include <memory>
#include <stack>
#include <set>
#include <map>

#define MAX_SIZE 100000000
typedef long long ll;
typedef unsigned long long ull;
using namespace std;

int main() {
  string s; cin>>s;
  vector<bool> vec(26,false);
  for(auto c : s) {
    int idx = c - 'a';
    vec[idx] = true;
  }

  for(int i = 0; i < 26; i++) {
    if(!vec[i]) {
      char c = i + 'a';
      cout << c << endl;
      exit(0);
    }
  }

  cout << "None" << endl;
}


Measured memory_bytes: 512
s = int(input())
a = {s}
a_i = s


def f(n):
    if n % 2 == 0:
        return n//2
    else:
        return 3*n + 1


ans = 1
for _ in range(10**6+1):
    a_i = f(a_i)
    ans += 1
    if a_i in a:
        print(ans)
        break
    else:
        a.add(a_i)

Measured memory_bytes: 3060
#include<stdio.h>
#include<string.h>
int main()
{
  char S[200001],T[200001];int a=0;
  if(!scanf("%s %s",S,T))return 0;
  for(int i=0;i<(int)strlen(S);i++){if(S[i]!=T[i])a++;}
  return printf("%d\n",a),0;
}

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

int main() {
  ll n; cin >> n; if (n&1) return puts("0") * 0;
  n/=10; ll an = 0;
  while(n > 0) {
    an += n;
    n/=5;
  }
  cout << an << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,s,e) for(int i=(s); i<(e);i++)
#define rep(i,n) REP(i,0,n)
#define rep1(i,n) REP(i,1,n)
#define repe(i,n) for(auto &&i:n)
#define all(v) (v).begin(),(v).end()
#define decimal fixed<<setprecision(20)
#define fastcin() cin.tie(0);ios::sync_with_stdio(false)
using namespace std;
using LL = long long;
using Graph = vector<vector<int>>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = 1e9;
const LL LLINF = 1e16;

int main(){
    fastcin();

    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >>a[i];
    int ans = 0;
    rep(i, n)REP(j, i+1, n) ans += a[i]*a[j];
    cout << ans << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n)for(int i=0;i<(n);i++)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
using ll = long long;
using P = pair<int, int>;

int main(){
    int x, y; cin >> x >> y;
    cout << x+y/2 << endl;
}

Measured memory_bytes: 256
from collections import deque

h, w = map(int, input().split())
maze = []
for _ in range(h):
    maze.append(input())


def bfs(sy, sx):
    num_table = [[-1]*w for _ in range(h)]
    # start地点を0とする
    num_table[sy][sx] = 0
    # queueを定義する
    queue = deque([[sy, sx]])
    # queueに値が入っている間loopを回す
    while queue:
        # 左から一つづつ取り出す
        y, x = queue.popleft()
        for dy, dx in ([1, 0], [-1, 0], [0, 1], [0, -1]):
            ny, nx = y + dy, x + dx
            if 0 <= ny < h and 0 <= nx < w and maze[ny][nx] == '.' and num_table[ny][nx] == -1:
                # チェックしたポイントは隣の数値+1する
                num_table[ny][nx] = num_table[y][x] + 1
                m = num_table[ny][nx]
                # 新規にqueueに追加する
                queue.append([ny, nx])
    return m


ans = 0
# start地点を全てのマスにおいてbfsする
for y in range(h):
    for x in range(w):
        if maze[y][x] == ".":
            ans = max(ans, bfs(y, x))
print(ans)



Measured memory_bytes: 3316
s = str(input())
t = str(input())

sr = s[::-1]
tr = t[::-1]

for i in range(len(sr)-len(tr)+1):
  srp = sr[i:i+len(tr)]
  for j in range(len(srp)):
    if srp[j] != '?' and srp[j] != tr[j]:
      break
  else:
    ans = sr.replace('?', 'a')
    ans = ans[0:i] + tr + ans[i+len(tr):]
    print(ans[::-1])
    exit()
else:
  print('UNRESTORABLE')

Measured memory_bytes: 3064
n=int(input())
l=list(map(int, input().split()))
ans=10000000000000000000000000000000000000000000000000000000000000000
for i in range(min(l), max(l)+1):
  cnt=0
  for s in l:
    cnt+=(s-i)**2    
  ans=min(ans, cnt)
print(ans)

Measured memory_bytes: 9112
c = []
for i in range(3):
    c.append(list(map(int, input().split())))
    
def is_check(a, b, c):
    for j in range(3):
        for k in range(3):
            if c[j][k] != (a[j] + b[k]):
                return False
    return True

for i in range(c[0][0] + 1):
    a1 = i
    b1 = c[0][0] - a1
    b2 = c[0][1] - a1
    b3 = c[0][2] - a1
    a2 = c[1][0] - b1
    a3 = c[2][0] - b1
    
    if not (b1 >= 0 and b1 <= 100
        and b2 >= 0 and b2 <= 100
        and b3 >= 0 and b3 <= 100
        and a2 >= 0 and a2 <= 100
        and a3 >= 0 and a3 <= 100) :
        continue
    
    a = [a1, a2, a3]
    b = [b1, b2, b3]
    
    is_ok = is_check(a, b, c)

    if is_ok:
        print('Yes')
        break

else:
    print('No')

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

using namespace std;
using ll = long long;
using vec = vector<int>;

#define rep(i, n)  for(int (i) = 0; (i) < (n); ++(i))
#define rrep(i, n) for(int (i) = (n); (i) >= 0; --(i))
#define Sort(a)    sort(a.begin(), a.end())
#define gSort(a)   sort(a.begin(), a.end(), greater<int>())
#define pout(n, a) cout << fixed << setprecision(n) << (a)
#define Cast(dig, n) static_cast<std::bitset<(dig)>>(n)

const int INF = 2147483647;
const ll  MOD = 1000000007;

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

    bool ans = false;

    for(int i = a; i <= b; ++i) {
        if(i % k == 0) {
            ans = true;
            break;
        }
    }

    cout << ((ans)?"OK":"NG");
}

Measured memory_bytes: 3624
import math
a, b, h, m = map(int, input().split())
rh = h * 30 + 30 * (m/60)
rm = 360 * (m/60)
r = abs(rh-rm)
if r >= 180:
    r = 360 - r
    
cc = a**2 + b**2 - 2 * a* b * math.cos(math.radians(r))
c = math.sqrt(cc)
print(c)

Measured memory_bytes: 9508
#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n) for(long long i = (n-1);i>=0;i--)
#define ITR(itr,mp) for(auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define RITR(itr,mp) for(auto itr = (mp).rbegin(); itr != (mp).rend(); ++itr)
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<P> Graph;

ll C[51][51]; // C[n][k] -> nCk
 
void comb_table(int N){ 
	for(int i=0;i<=N;++i){
		for(int j=0;j<=i;++j){
			if(j==0 or j==i){
				C[i][j]=1LL;
			}else{
				C[i][j]=(C[i-1][j-1]+C[i-1][j]);
			}
		}
	}
}

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

  ll n,a,b;
  cin >> n >> a >> b;
  
  map <ll,ll>v;
  
  REP(i,n){
    ll x;
    cin >> x;
    v[x]++;
  }
  
  double ave = 0;
  ll limit = a;
  ll cmb = 1;
  RITR(itr,v){
    if(limit >= itr->second){
      ave += itr->first*itr->second;
      limit -= itr->second;
    }
    else{
      ave += itr->first*limit;
      comb_table(n);
      if(itr != v.rbegin()){
        cmb = C[itr->second][limit];
        limit = 0;
      }
      else{
        cmb = 0;
        while(limit <= b){
          cmb += C[itr->second][limit];
          limit++;
        }
        limit = 0;
      }
    }
    if(limit == 0) break;
  }
  
  ave /= a;
  
  cout << fixed << ave << endl;
  cout << cmb << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
const double EPS = 1e-10;
struct Point{
  double x,y;
  Point(){}
  Point(double x,double y):x(x),y(y){}
  Point operator+(Point a){return Point(x+a.x,y+a.y);}
  Point operator-(Point a){return Point(x-a.x,y-a.y);}
};
typedef Point Vector;

struct Segment{
  Point p1,p2;
  Segment(){}
  Segment(Point p1,Point p2):p1(p1),p2(p2){}
};
typedef Segment Line;

double dot(Vector a,Vector b){
  return a.x*b.x+a.y*b.y;
}

double cross(Vector a,Vector b){
  return a.x*b.y-a.y*b.x;
}

double norm(Vector a){
  return dot(a,a);
}

double abs(Vector a){
  return sqrt(norm(a));
}

/*
1
-1
2
-2
0
 */
Int ccw(Point p0,Point p1,Point p2){
  Vector a=p1-p0;
  Vector b=p2-p0;
  if(cross(a,b) > EPS) return 1;
  if(cross(a,b) < -EPS) return -1;
  if(dot(a,b) < -EPS) return 2;
  if(norm(a)<norm(b)) return -2;
  return 0;
}

bool intersectSS(Point p1,Point p2,Point p3,Point p4){
  return (ccw(p1,p2,p3)*ccw(p1,p2,p4) <= 0 && ccw(p3,p4,p1)*ccw(p3,p4,p2) <= 0);
}

bool intersectSS(Segment s1,Segment s2){
  return intersectSS(s1.p1,s1.p2,s2.p1,s2.p2);
}

double getDistanceLP(Line l,Point p){
  return abs(cross(l.p2-l.p1,p-l.p1)/abs(l.p2-l.p1));
}

double getDistanceSP(Segment s,Point p){
  if(dot(s.p2-s.p1,p-s.p1) < 0.0) return abs(p-s.p1);
  if(dot(s.p1-s.p2,p-s.p2) < 0.0) return abs(p-s.p2);
  return getDistanceLP(s,p);
}
double getDistanceSS(Segment s1,Segment s2){
  if(intersectSS(s1,s2)) return 0.0;
  return min({getDistanceSP(s1,s2.p1),getDistanceSP(s1,s2.p2),
	getDistanceSP(s2,s1.p1),getDistanceSP(s2,s1.p2)});
}

Int cnt[111][111];
signed main(){  
  cin.tie(0);
  ios::sync_with_stdio(0);
  Int n;
  cin>>n;
  vector<Segment> vs(n);
  memset(cnt,0,sizeof(cnt));
  for(Int i=0;i<n;i++){
    Int x1,y1,x2,y2;
    cin>>x1>>y1>>x2>>y2;
    cnt[x1][y1]++;
    cnt[x2][y2]++;
    vs[i]=Segment(Point(x1,y1),Point(x2,y2));
  }
  cout<<fixed<<setprecision(12);
  for(Int i=0;i<111;i++){
    for(Int j=0;j<111;j++){
      if(cnt[i][j]>1){
	cout<<0.0<<endl;
	return 0;
      }
    }
  }
  assert(n<5555);
  double ans=getDistanceSS(vs[0],vs[1]);
  for(Int i=0;i<n;i++)
    for(Int j=i+1;j<n;j++)
      ans=min(ans,getDistanceSS(vs[i],vs[j]));
  cout<<ans<<endl;
  return 0;
}



Measured memory_bytes: 5632
#include <bits/stdc++.h>
#define N 15
using namespace std;
int n,m,k[N],s[N][N],p[N],cnt,mod[N];
void dfs(int x){
	if(x==n+1){
		for(int i=1;i<=m;i++){
			int sum=0;
			for(int j=1;j<=k[i];j++)
				sum+=p[s[i][j]];
			if(sum%2!=mod[i])return;
		}
		cnt++;return;
	}
	p[x]=1,dfs(x+1);
	p[x]=0,dfs(x+1);
}
int main(){
	cin>>n>>m;
	for(int i=1;i<=m;i++){
		cin>>k[i];
		for(int j=1;j<=k[i];j++)cin>>s[i][j];
	}
	for(int i=1;i<=m;i++)cin>>mod[i],mod[i]%=2;
	dfs(1);
	cout<<cnt<<endl;
	return 0;
}

Measured memory_bytes: 3636
#ABC147.B
S = input()
n = len(S)
count =0
if n%2==1:
    S1 = S[:n//2]
    S2 = S[((n+3)//2)-1:][::-1]
    for i in range(n//2):
        if S1[i]!=S2[i]:
            count +=1
elif n%2 ==0:
    S1 = S[:n//2]
    S2 = S[n//2:][::-1]
    for i in range(n//2):
        if S[i]!=S2[i]:
            count+=1
print(count)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main(void){
    int n;
    int count=0;
    cin>>n;
    int b1=0,b2=0,b4=0;
    for(int i=0,j=0,k=0;i<n;i++){
        int s;
        cin>>s;
        if(s%4==0)b4++;
        else if(s%2==0)b2++;
        else b1++;
    }
    if(b2==0){
        if(b1<=b4+1){
            cout<<"Yes"<<endl;
        }
        else cout<<"No"<<endl;
    }
    else{
        b1+=1;
        if(b1<=b4+1){
            cout<<"Yes"<<endl;
        }
        else cout<<"No"<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
import java.util.*;
import static java.lang.Math.*;
import static java.util.Arrays.*;

public class Main {

	int INF = 1 << 28;

	void run() {
		Scanner sc = new Scanner(System.in);
		int t = sc.nextInt();
		for(int c=0;c<t;c++) {
			int n = sc.nextInt();
			int saizo[] = new int[n];
			for(int i=0;i<n;i++) {
				saizo[i] = sc.nextInt();
			}
			
			int up = 0;
			int down = 0;
			for(int i=0;i<n-1;i++) {
				up = max(up, saizo[i+1] - saizo[i]);
				down = max(down, saizo[i] - saizo[i+1]);
			}
			System.out.println(up + " " + down);
		}
	}

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

	void debug(Object... os) {
		System.err.println(Arrays.deepToString(os));
	}
}

Measured memory_bytes: 12000
import collections, bisect

s = input()
t = input()

n = len(s)
d = collections.defaultdict(list)
for i, c in enumerate(s):
    d[c].append(i + 1)

m = len(t)
x = [0] * (m + 1) # 長さを記録
y = [0] * (m + 1) # 添え字を記録

for i in range(1, m + 1):
    c = t[i - 1]
    if not c in d:
        print(-1)
        exit()
    
    a = y[i - 1]
    ptr = bisect.bisect_right(d[c], y[i - 1])
    if ptr == len(d[c]):
        b = d[c][0]
    else:
        b = d[c][ptr]
    
    y[i] = b
    if a < b:
        x[i] = x[i - 1] + b - a
    else:
        x[i] = x[i - 1] + n - a + b
    
print(x[-1])


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

int main(){
  int H,W;
  cin >> H >> W;
  vector<vector<char>> data(H,vector<char>(W));
  vector<vector<int>> ref(H,vector<int>(W));
  for(int i=0; i<H; i++){
    for(int j=0; j<W; j++){
      cin >> data.at(i).at(j);
    }
  }
  
  for(int i=0; i<H; i++){
    
    bool ans = false;
    
    for(int j=0; j<W; j++){
      if(data.at(i).at(j) == '#'){
        ans = true;
        break;
      }
    }
    if(ans == false){
      for(int j=0; j<W; j++){
        ref.at(i).at(j) = 1;
      }
    }
  }
  
  for(int i=0; i<W; i++){
    
    bool ans = false;
    
    for(int j=0; j<H; j++){
      if(data.at(j).at(i) == '#'){
        ans = true;
        break;
      }
    }
    if(ans == false){
      for(int j=0; j<H; j++){
        ref.at(j).at(i) = 1;
      }
    }
  }
  
  for(int i=0; i<H; i++){
    
    bool check = false;
    for(int j=0; j<W; j++){
      if(ref.at(i).at(j) != 1){
        cout << data.at(i).at(j);
      }
      if(ref.at(i).at(j) == 0){
        check = true;
      }
    }
    if(check == true){
      cout << endl;
    }
  }
}

Measured memory_bytes: 256
<?php
fscanf(STDIN, "%d %d %d", $x, $a, $b);
if($a >= $b) {
    echo 'delicious'. "\n";
} elseif($b - $a <= $x) {
    echo 'safe'. "\n";
} elseif($b - $a > $x) {
    echo 'dangerous'. "\n";
}

Measured memory_bytes: 4728
#include <iostream>
#include <iomanip>
#include <cmath>
#include <string>
#include <vector>
#include <cstdlib>
#include <map>
#include <queue>
#include <deque>
#include <algorithm>
#include <stack>
#include <functional>
#include <sstream>
#define rep(i,j,n) for(i=j;i<(n);i++)
#define rrep(i,j,n) for(i=(n)-1;i>j-1;i--)
typedef long long int lli;
#define N 1000000007
#define M 998244353

using namespace std;

int main(){
    lli n,a,b=0;
    string s;
    lli i,j;
    cin>>n>>s;
    a=count(s.begin(),s.end(),'R');
    rep(i,0,a){
        if(s[i]=='R'){
            b++;
        }
    }
    cout<<a-b<<endl;
}


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

signed main(){
  int A,B;
  cin>>A>>B;
  string ans="Impossible";
  if(A%3==0||B%3==0||(A+B)%3==0)ans="Possible";
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 3592
N=int(input())
ls=list(map(int,input().split()))
if ls[0]!=0:
  print(0)
  exit()
sls=sorted(ls)
if sls[1]==0:
  print(0)
  exit()
i=1
a=1
b=1
c=1
while i<N-1:
  if sls[i+1]==sls[i]:
    c+=1
  elif sls[i+1]==sls[i]+1:
    a=a*(b**c)
    b=c
    c=1
  else:
    a=0
    break
  i+=1
a=a*(b**c)
print(a%998244353)

Measured memory_bytes: 14396
#include <stdio.h>
#include <math.h>
int main(void){
  int n,i,sum=0;
  int s[1000];
  double ave,SUM=0,a;
  
  while(scanf("%d",&n),n!=0){
      for(i=0;i<n;i++){
          scanf("%d",&s[i]);
          sum+=s[i];
      }
      ave=(double)sum/n;
      for(i=0;i<n;i++){
        SUM+=(s[i]-ave)*(s[i]-ave);
      }
      a=sqrt(SUM/n);
      
      printf("%f\n",a);
      sum=0;
      SUM=0;
  }

  return 0;
}



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

int main(){
    string S;
    cin >> S;
    int size = (int)(S.length()); 
    vector<int> a(size);
    vector<int> R(size);
    vector<int> L(size);
    for(int i = 0,i_R = 0, i_L = 0; i < size; i++){
        if(S[i] == 'R'){
            R[i_R] = i;
            i_R++;
        }else{
            L[i_L] = i;
            i_L++;
        }
    }
    int j_R,j_L,d;
    j_R = j_L = -1;
    for(int i = 0; i< size; i++){
        if(S[i] == 'R'){
            j_R++;
            d = abs(R[j_R]-L[j_L+1]);
            if(d % 2 == 0) a[i + d]++;
            else a[i + d - 1]++;
        }else{
            j_L++;
            d = abs(R[j_R]-L[j_L]);
            if(d % 2 == 0) a[i - d]++;
            else a[i - d + 1]++;
        }
    }
    for(int i = 0; i < size; i++){
        cout << a[i] << " ";
    }
    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define rep(i,n) for (int i=0;i<(int)(n);i++)
#define codefor int test;scanf("%d",&test);while(test--)
#define INT(...) int __VA_ARGS__;in(__VA_ARGS__)
#define LL(...) ll __VA_ARGS__;in(__VA_ARGS__)
#define yn(ans) if(ans)printf("Yes\n");else printf("No\n")
#define YN(ans) if(ans)printf("YES\n");else printf("NO\n")
#define vector2d(type,name,h,...) vector<vector<type>>name(h,vector<type>(__VA_ARGS__))
#define umap unordered_map
#define uset unordered_set
using namespace std;
using ll = long long;
const int MOD=1000000007;
//入力系
void scan(int& a){scanf("%d",&a);}
void scan(long long& a){scanf("%lld",&a);}
template<class T> void scan(T& a){cin>>a;}
template<class T> void scan(vector<T>& vec){for(auto&& it:vec)scan(it);}
void in(){}
template <class Head, class... Tail> void in(Head& head, Tail&... tail){scan(head);in(tail...);}
//出力系
void print(const int& a){printf("%d",a);}
void print(const long long& a){printf("%lld",a);}
void print(const double& a){printf("%.15lf",a);}
template<class T> void print(const T& a){cout<<a;}
template<class T> void print(const vector<T>& vec){if(vec.empty())return;print(vec[0]);for(auto it=vec.begin();++it!= vec.end();){putchar(' ');print(*it);}}
void out(){putchar('\n');}
template<class T> void out(const T& t){print(t);putchar('\n');}
template <class Head, class... Tail> void out(const Head& head,const Tail&... tail){print(head);putchar(' ');out(tail...);}
//デバッグ系
template<class T> void dprint(const T& a){cerr<<a;}
template<class T> void dprint(const vector<T>& vec){if(vec.empty())return;cerr<<vec[0];for(auto it=vec.begin();++it!= vec.end();){cerr<<" "<<*it;}}
void debug(){cerr<<endl;}
template<class T> void debug(const T& t){dprint(t);cerr<<endl;}
template <class Head, class... Tail> void debug(const Head& head, const Tail&... tail){dprint(head);cerr<<" ";debug(tail...);}
ll intpow(ll a, ll b){ ll ans = 1; while(b){ if(b & 1) ans *= a; a *= a; b /= 2; } return ans; }
ll modpow(ll a, ll b, ll p){ ll ans = 1; while(b){ if(b & 1) (ans *= a) %= p; (a *= a) %= p; b /= 2; } return ans; }

int main(){
    INT(x);
    out((x-30)/2);
}


Measured memory_bytes: 3192
def Q(x):
    print("?",x,flush=True)
    return int(input())

x=Q("A")
if x==128:
    L=128
else:    
    y=Q("A"*x)
    z=Q("A"*(x+1))

    if z==y:
        L=x+1
    else:
        L=x

S=[chr(i) for i in range(48,58)]+[chr(i) for i in range(65,91)]+[chr(i) for i in range(97,123)]
K=[-1]*62

for i in range(62):
    K[i]=L-Q(S[i]*L)

import heapq
A=[(K[i],S[i]*K[i]) for i in range(62)]
heapq.heapify(A)

while A[0][0]==0:
    heapq.heappop(A)

while len(A)>1:
    x,y=heapq.heappop(A)
    z,w=heapq.heappop(A)

    ind=0
    for i in range(len(w)):
        while Q(y[:ind]+w[i]+y[ind:])>=L-x-i:
            ind+=1
        y=y[:ind]+w[i]+y[ind:]
        ind+=1
    heapq.heappush(A,(x+z,y))
    
print("!",A[0][1],flush=True)

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

void solve()
{
    int n;
    cin >> n;
    map<string, int> mp;
    rep(i, n)
    {
        string s;
        cin >> s;
        mp[s]++;
    }
    int m;
    cin >> m;
    vector<string> t(m);
    rep(i, m) cin >> t[i];
    bool ok = true;
    rep(i, m)
    {
        if (mp[t[i]] > 0)
        {
            mp[t[i]]--;
        }
        else
            ok = false;
    }
    if (ok)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
}

int main()
{
    solve();
    return 0;
}

Measured memory_bytes: 25096
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;

int main(){
	char n[5];
	scanf("%s", n);
	int len = strlen(n);
	int flag;
	for(int i = 0; i < (len+1)/2; i++){
		if(n[i] != n[len-i-1]){
			printf("No\n");
			return 0;
		}
	}
	printf("Yes\n");
	return 0;
}

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

using namespace std;

int main(void){
	while(1){
		int n; cin >> n;
		if(!n) break;

		int smin= 9999, smax=-1, sum = 0;
		for(int i=0; i<n; i++){
			int tmp;
			cin >> tmp;
			sum += tmp;
			smin = min(smin, tmp);
			smax = max(smax, tmp);
		}

		cout << (sum - smin - smax) /(n-2) << endl;


	}
}


Measured memory_bytes: 3080
import sys
from fractions import Fraction

def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())

N, K = LI()


kakuritu = []
for i in range(1,N+1):
    count = 0
    while i < K:
        i *= 2
        count += 1
    kakuritu.append(N*(2**count))
result = 0
for kaku in kakuritu:
    result += Fraction(1, kaku)


print(result.numerator / result.denominator)

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

#define ll long long

using namespace std;

void
solve() {
  int n, m;
  int h[100005];

  cin>>n>>m;
  for (int i=1; i<=n; i++)
    cin>>h[i];

  int a, b;
  bool bad[100005] = {false};
  for (int i=0; i<m; i++) {
    cin>>a>>b;
    if (h[a] >= h[b])
      bad[b] = true;
    if (h[b] >= h[a])
      bad[a] = true;
  }

  int ans = 0;
  for (int i=1; i<=n; i++)
    if (!bad[i])
      ans++;
  cout<<ans<<endl;
}

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

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

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

  return 0;
}



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

int main() {
  int n,k; cin>>n>>k;
  string s; cin>>s;
  
  vector<int> nums;
  int now=1;
  int cnt=0;
  rep(i, n) {
    if (s[i]==(char)('0'+now)) cnt++;
	else {
      nums.push_back(cnt);
      now^=1;
      cnt=1;
	}
  }
  if (cnt!=0) nums.push_back(cnt);
  if (nums.size()%2==0) nums.push_back(0);
  int add=2*k+1;
  int ans = 0;
  int left = 0;  
  int right = 0; 
  int tmp = 0;
  rep(i, nums.size()) {
    if (i%2==1) continue;
    int nextleft=i;
	int nextright=min(i+add, (int)nums.size());
	while (nextleft > left) {
      tmp -= nums[left];
      left++;
    }
	while (nextright>right) {
      tmp+=nums[right];
      right++;
    }
    ans=max(tmp, ans);
  }
  cout << ans << endl;
}


Measured memory_bytes: 1020
#include<stdio.h>

int main(){
  long n,a,b,c,i,box[10000],cnt=1,dp[100000]={},max=0,j,k;
  scanf("%ld",&n);
  box[0]=1;
  for(i=6;i<=n;i*=6)
    box[cnt++]=i;
  for(i=9;i<=n;i*=9)
    box[cnt++]=i;
  dp[0]=1;
  for(i=1;i<=n;i++){
    for(j=max;j>=0;j--){
      if(dp[j]==1){
        for(k=0;k<cnt;k++){
          if(j+box[k]<=n){
            dp[j+box[k]]=1;
            if(j+box[k]>max)
              max=j+box[k];
          }
        }
      }
    }
    if(dp[n]==1){
      printf("%ld\n",i);
      return 0;
    }
  }
}

Measured memory_bytes: 896
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <list>

using namespace std;

#ifdef _MSC_VER
#define __typeof__ decltype
template <class T> int __builtin_popcount(T n) { return n ? 1 + __builtin_popcount(n & (n - 1)) : 0; }
#endif

#define foreach(it, c) for (__typeof__((c).begin()) it=(c).begin(); it != (c).end(); ++it)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define popcount __builtin_popcount
	
#define rep(i, n) for (int i = 0; i < n; ++i)

template <class T> void max_swap(T& a, const T& b) { a = max(a, b); }
template <class T> void min_swap(T& a, const T& b) { a = min(a, b); }

const double EPS = 1e-10;
typedef long long ll;
typedef pair<int, int> pint;


int main()
{
	const int MAX = 1000000;
	static bool is_prime[MAX + 1];
	fill(is_prime, is_prime + (MAX + 1), true);
	is_prime[0] = is_prime[1] = false;
	for (int i = 2; i <= MAX; ++i)
		if (is_prime[i])
			for (int j = i*2; j <= MAX; j += i)
				is_prime[j] = false;

	int a, d, n;
	while (scanf("%d%d%d", &a, &d, &n), a)
	{
		int res = a;
		for (int p = 0; ; res += d)
		{
			if (is_prime[res])
			{
				if (++p == n)
					break;
			}
		}
		printf("%d\n", res);
	}
}

Measured memory_bytes: 0
"""everything has a cost!"""

from math import *
import random, functools, collections, sys

__author__ = 'p7x'


# sys.stdin = open('in.txt', 'r')
# sys.stdout = open('out.txt', 'w')
# sys.stderr = open('err.txt', 'w')


if __name__ == '__main__':
    s = input()
    t = input()
    cnt = 0
    for i in range(len(s)):
        if (s[i] != t[i]): cnt += 1
    print(cnt)


Measured memory_bytes: 83840
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
 
#define rep(i,n) for(int i = 0;i<n;i++)
const long long MOD = 1000000007;

int main(){
  int n;cin >> n;
  int a[n];
  rep(i,n) cin >> a[i];
  int ans = 0;
  sort(a,a+n);
  for(int i = 0; i<n; i++){
    for(int j = i+1; j<n; j++){
      for(int k = j+1; k<n;k++){
        if(a[k] < a[i]+ a[j]) ans++;
      }
    }
  }
  cout << ans << "\n";
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<string>
#include<vector>
#include<stack>
#include<set>
#include<map>
#include<utility>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<climits>
using namespace std;

typedef long long ll;
#define MOD 1000000007;

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
        char s[100],s1[100],s2[100];
        int i,j,len,len1,len2;
        scanf("%s %s %s",&s,&s1,&s2);
        len=strlen(s);
        len1=strlen(s1);
        len2=strlen(s2);
        if(s[len-1]==s1[0] && s1[len1-1]==s2[0])
                cout<<"YES"<<endl;
        else
            cout<<"NO"<<endl;

return 0;
}


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

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

using namespace std;

class Eratosthenes_sieve{
	vector<bool> er;
	vector<int> p;
public:
	Eratosthenes_sieve(int n):er(n+1,true){
		if(n>=0) er[0]=false;
		if(n>=1) er[1]=false;
		for(int i=2;i*i<=n;i++) if(er[i]) for(int j=i*i;j<=n;j+=i) er[j]=false;
		rep(i,n+1) if(er[i]) p.emplace_back(i);
	}

	vector<int> primes()const{ return p; }

	bool is_prime(int a)const{
		assert(a<=(int)er.size()-1);
		return a>=0 && er[a];
	}
};

Eratosthenes_sieve E(1e6);

int main(){
	int n; scanf("%d",&n);
	vector<int> a(n);
	rep(i,n) scanf("%d",&a[i]);

	int g=a[0];
	rep(i,n-1) g=gcd(g,a[i+1]);
	if(g>=2){
		puts("not coprime");
		return 0;
	}

	vector<int> freq(1e6+1);
	rep(i,n) freq[a[i]]++;
	for(int p:E.primes()){
		int cnt=0;
		for(int x=p;x<=1e6;x+=p){
			cnt+=freq[x];
		}
		if(cnt>=2){
			puts("setwise coprime");
			return 0;
		}
	}
	puts("pairwise coprime");

	return 0;
}


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

typedef long long LL;

void fastIO_test(void)
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
}

void solve(void)
{
    string s, t;
    cin >> s >> t;
    LL k = (LL)t.length();
    LL ans = INT_MAX;
    for(LL i=0; i<s.length()-k+1; i++)
    {
        LL nch = 0;
        LL p = 0;
        for(LL j=i; j<i+k, p<k; j++)
        {
            if(s[j]!=t[p])
            {
                nch++;
            }
            p++;
        }
        ans = min(ans, nch);
    }
    cout << ans << "\n";
}

int main()
{
    fastIO_test();

    LL t=1;
    //cin >> t;
    while (t--)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 3640
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>
#include <cstring>
#include <cmath>
#include <stack>
#include <iomanip>
#include <tuple>
#include <functional>
#include <cfloat>
#include <map>
#include <set>
#include <array>
#include <stdio.h>
#include <string.h>
using ll = long long;
using ull = unsigned long long;
using namespace std;
#define int long long
#define CONTAINS_VEC(v,n) (find((v).begin(), (v).end(), (n)) != (v).end())
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ARY_SORT(a, size) sort((a), (a)+(size))
#define REMOVE(v,a) (v.erase(remove((v).begin(), (v).end(), (a)), (v).end()))
#define REVERSE(v) (reverse((v).begin(), (v).end()))
#define ARY_REVERSE(v,a) (reverse((v), (v)+(a)))
#define REP(i, n) for (int (i)=0; (i) < (n); (i)++)
#define CONTAINS_MAP(m, a) (m).find((a)) != m.end()
#define CONTAINS_SET(m, a) (m).find((a)) != m.end()
void YesNo(bool b) { cout << (b ? "Yes" : "No") << endl; }
void YESNO(bool b) { cout << (b ? "YES" : "NO") << endl; }

signed main()
{
	int a[3];
	cin >> a[0] >> a[1] >> a[2];
	ARY_SORT(a, 3);
	ARY_REVERSE(a, 3);
	cout << (a[0] * 10 + a[1] + a[2]) << endl;
}



Measured memory_bytes: 3196
#include<iostream>
#include<algorithm>
#include<set>
#define int long long
#define for0(i, n) for(int i = 0; i < (n); i++)
#define mp make_pair
using namespace std;
typedef pair<int, int> P;
set<P>s; multiset<P>ms;
int h, w, n, ans[20];
signed main() {
	cin >> h >> w >> n;
	while (n--) {
		int x, y; cin >> x >> y;
		for (int i = -1; i <= 1; i++)for (int j = -1; j <= 1; j++) if (1 < x + i && x + i < h && 1 < y + j && y + j < w) {
			s.insert(mp(x + i, y + j));
			ms.insert(mp(x + i, y + j));
		}
	}
	ans[0] = (h - 2) * (w - 2);
	for (P p1 : s) {
		ans[0]--; ans[ms.count(p1)]++;
	}
	for0(i, 10)cout << ans[i] << endl;
}

Measured memory_bytes: 112768
#include<bits/stdc++.h>
#define ll long long
#define lld long long double
#define pb push_back
#define mp make_pair
#define M 1000000007
using namespace std;

int f(int *a, int n, int k) {
	vector<int>dp(n, INT_MAX);
	dp[0] = 0;
	for (int i = 0; i < n; i++) {
		for (int j = i + 1; j <= i + k; j++) {
			if (j < n)
				dp[j] = min(dp[j], abs(a[i] - a[j]) + dp[i]);
		}
	}
	return dp[n - 1];
}


int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
// #ifndef ONLINE_JUDGE
// 	freopen("input.txt", "r", stdin);
// 	freopen("output.txt", "w", stdout);
// #endif
	int n, k;
	cin >> n >> k;
	int a[n];
	for (int i = 0; i < n; i++) cin >> a[i];
	cout << f(a, n, k);
	return 0;
}

Measured memory_bytes: 1024
#include<iostream>  
#include <bits/stdc++.h> 
using namespace std;  
int main() 
{
  unsigned long int n,k;
  cin>>n;
  cin>>k;
  unsigned long int h[n],temp,i=0;
  for(i=0;i<n;i++){
    cin>>temp;
    h[i]=temp;
  }
  sort(h, h+n);
  unsigned long long int t,count =0;
  if(k<n){
  for(t=0;t<n-k;t++){
     count=count+h[t];
  }
  cout<<count;}
  else{
    cout<<"0";
  }
  return 0;
}

Measured memory_bytes: 1792
#ライブラリインポート
from collections import defaultdict

#入力受け取り
def getlist():
	return list(map(int, input().split()))

#処理内容
def main():
	N, K = getlist()
	R, S, P = getlist()
	T = input()
	ans = 0
	DPr = [0] * N
	DPs = [0] * N
	DPp = [0] * N
	#初期化
	for k in range(K):	
		if T[k] == "r":
			DPp[k] = P
		elif T[k] == "s":
			DPr[k] = R
		else:
			DPs[k] = S
	for i in range(K, N):
		now = i
		pre = i - K
	
		if T[now] == "r":
			DPr[now] = max(DPs[pre], DPp[pre])
			DPs[now] = max(DPr[pre], DPp[pre])
			DPp[now] = max(DPr[pre] + P, DPs[pre] + P)
		elif T[now] == "s":
			DPr[now] = max(DPs[pre] + R, DPp[pre] + R)
			DPs[now] = max(DPr[pre], DPp[pre])
			DPp[now] = max(DPr[pre], DPs[pre])
		else:
			DPr[now] = max(DPs[pre], DPp[pre])
			DPs[now] = max(DPr[pre] + S, DPp[pre] + S)
			DPp[now] = max(DPr[pre], DPs[pre])
	# print(DPr)
	# print(DPs)
	# print(DPp)
	for i in range(K):
		ans += max(DPr[N - 1 - i], DPs[N - 1 - i], DPp[N - 1 - i])

	print(ans)

if __name__ == '__main__':
	main()

Measured memory_bytes: 49392
#include <bits/stdc++.h>
// #include <iostream>
// #include <algorithm>
// #include <string>
// #include <vector>
// #include <queue>
// #include <stack>
// #include <set>
// #include <map>

#define rep(i,a,n) for(int i=a; i<n; i++)
#define repr(i,a,n) for(int i=a;i >= n;i--)
#define INF 999999999
#define pb(a) push_back(a)

int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
using namespace std;

typedef pair<int, int> pii;
typedef long long int ll;
typedef vector<pii> VP;

int main(void) {
    int n, l; cin >> n >> l;
    int a[100010], b[100010];
    rep(i,0,n) cin >> a[i];
    int m = 0, m_i;
    rep(i,0,n-1) {
        b[i] = a[i+1] + a[i];
        if(m < b[i]) {
            m = b[i];
            m_i = i;
        }
    }

    if(m < l) {
        cout << "Impossible" << endl;
        return 0;
    }
    else {
        cout << "Possible" << endl;
        rep(i,0,n-1) {
            if(i != m_i) cout << i+1 << endl;
            else if(i == m_i) break;
        }
        repr(i,n-2,0) {
            if(i != m_i) cout << i+1 << endl;
            else if(i == m_i) break;
        }
        cout << m_i + 1 << endl;
    }

    return 0;
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll,ll>;
#define REP(i, n) for (ll i = 0; i < (int)(n); i++)
#define RREP(i, n) for (ll i = (int)(n)-1; i > -1 ; i--)
#define IN(T, x) T x;cin >> x;
#define AIN(T, a, n) vector<T> a(n);REP(i, n){cin >> a[i];}
#define A2IN(T1, a, T2, b, n) vector<T1> a(n);vector<T2> b(n);REP(i, n){cin >> a[i] >> b[i];}
#define ALL(a) (a).begin(),(a).end()
#define SORT(a) sort(ALL(a))
#define RSORT(a) SORT(a);reverse(ALL(a))
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}
#define OUT(x) cout << x << endl
#define BOUT(b) if(b){OUT("Yes");}else{OUT("No");}
const ll MOD = 100000007;
const ll INF = 10e9;


int main() {
  IN(ll, D);
  IN(ll ,N);
  if(N == 100)
    if (D == 2)
      OUT(1010000);
  	else
      OUT(101 * pow(100,D));
  else
  	OUT(N * pow(100,D));
}




Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define ff first
#define ss second
#define pb push_back
typedef long long ll;
#define db(x) cerr<<__LINE__<<": "<<#x<<" = "<<(x)<<'\n'
const int inf = 1e9+7;
const int N = 1e6+9;

void solve() {
	int a, b, n;
	for(int i=1;i<=5;++i) {
		cin>>a;
		if(a==0) cout<<i<<endl;
	}
}
int main() {
    ios_base::sync_with_stdio(0);
    int T=1 ,cas=0;
    while(T--) {
    	solve();
    }
    return 0;
}

// ll, reset, 1, bottom

Measured memory_bytes: 3596
#include<stdio.h>
int main(void){
  int i,sum=0;
  int v[4];
  for(i=0;i<4;i++){
    scanf("%d",&v[i]);
    sum+=v[i];
  }
  printf("%d\n",sum/60);
  printf("%d\n",sum%60);
  return(0);
}

Measured memory_bytes: 596
/* 
 * Project: AtCoder Beginners Contest 160 C - Traveling Salesman around Lake
 * Author: toms74209200 <https://github.com/toms74209200>
 *
 * Created on 2020/07/15
 * Copyright (c) 2020 toms74209200
 * 
 * This software is released under the MIT License.
 * http://opensource.org/licenses/mit-license.php
 */
#include <cstdio>
#include <vector>
#include <algorithm>
#include <numeric>
using namespace std;

int k;
int n;
vector<int> a;

void solve() {
    vector<int> diff;
    diff.push_back(k+*a.begin()-a[n-1]);
    for (auto i=a.begin();i!=a.end();i++) {
        diff.push_back(*(i+1) - *i);
    }
    sort(diff.begin(), diff.end()-1);
    // for (auto i=diff.begin();i!=diff.end()-1;i++) {
    //     printf("%d\n", *i);
    // }
    int sum = accumulate(diff.begin(), diff.end()-2, 0);
    printf("%d\n", sum);
}

int main() {

    scanf("%d", &k);
    scanf("%d", &n);
    for (int i=0;i<n;i++) {
        int tmp;
        scanf("%d", &tmp);
        a.push_back(tmp);
    }

    solve();

}

Measured memory_bytes: 5224
/*input
100000 100000
*/
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define F first
#define S second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define pb push_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define YY cout<<"YES\n"
#define NN cout<<"NO\n"
#define yy cout<<"Yes\n"
#define nn cout<<"No\n"
#ifdef leowang
#define debug(...) do{\
	fprintf(stderr,"%s - %d : (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
	_DO(__VA_ARGS__);\
}while(0)
template<typename I> void _DO(I&&x){cerr<<x<<endl;}
template<typename I,typename...T> void _DO(I&&x,T&&...tail){cerr<<x<<", ";_DO(tail...);}
#else
#define debug(...)
#endif
template<typename T1,typename T2>
ostream& operator<<(ostream& out,pair<T1,T2> P){
	out<<'('<<P.F<<','<<P.S<<')';
	return out;
}

//}}}
const ll maxn=300005;
const ll maxlg=__lg(maxn)+2;
const ll INF64=8000000000000000000LL;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const double PI=acos(-1);
//const ll p=880301;
//const ll P=31;

ll mypow(ll a,ll b){
	ll res=1LL;
	while(b){
		if(b&1) res=res*a%MOD;
		a=a*a%MOD;
		
		b>>=1;
	}
	return res;
}

ll get(ll n,ll m){
	ll id=n/3;
	vector<ll> a,b;
	a.pb(id*m);
	a.pb((n-id)*(m/2));
	a.pb((n-id)*(m-m/2));
	sort(ALL(a));
	id++;
	b.pb(id*m);
	b.pb((n-id)*(m/2));
	b.pb((n-id)*(m-m/2));
	sort(ALL(b));
	return min(a[2]-a[0],b[2]-b[0]);
}

int main()
{
	IOS;
	ll n,m;
	cin>>n>>m;
	ll ans=INF64;	
	if(n%3)	ans=min(ans,m);
	else ans=0;
	if(m%3) ans=min(ans,n);
	else ans=0;
	ans=min(ans,get(n,m));
	ans=min(ans,get(m,n));
	cout<<ans<<'\n';
	return 0;
}


Measured memory_bytes: 256
using System;
    class Program
    {
        static void Main(string[] args)
        {
            //入力
            string[] input = Console.ReadLine().Split(' ');
            int a = int.Parse(input[0]);
            int b = int.Parse(input[1]);
            int c = int.Parse(input[2]);
            //出力
            if ((b - a) == (c - b))
            {
                Console.WriteLine("YES");
            }
            else
            {
                Console.WriteLine("NO");
            }
        }
    }

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

using ld = long double;
using pii = pair<int, int>;

constexpr ld INF = 1e16;

struct edge {
    int to;
    ld cost;
};

using edges = vector<edge>;
using graph = vector<edges>;

int main() {
    ld xs, ys, xt, yt;
    cin >> xs >> ys >> xt >> yt;
    int N;
    cin >> N;
    vector<ld> x(N + 2), y(N + 2), r(N + 2);
    x[N] = xs; y[N] = ys;
    x[N + 1] = xt; y[N + 1] = yt;
    for(int i = 0; i < N; ++i) {
        cin >> x[i] >> y[i] >> r[i];
    }
    graph g(N + 2);
    for(int i = 0; i < N + 2; ++i) {
        for(int j = i + 1; j < N + 2; ++j) {
            ld dist = hypot(x[i] - x[j], y[i] - y[j]);
            dist = max((ld)0, dist - (r[i] + r[j]));
            g[i].push_back(edge{j, dist});
            g[j].push_back(edge{i, dist});
        }
    }
    vector<ld> d(N + 2, INF);
    d[N] = 0;
    priority_queue<pii, vector<pii>, greater<pii>> que;
    que.push(make_pair(0, N));
    while(!que.empty()) {
        auto p = que.top();
        que.pop();
        int v = p.second;
        if(d[v] < p.first) {
            continue;
        }
        for(auto& e : g[v]) {
            if(d[e.to] > d[v] + e.cost) {
                d[e.to] = d[v] + e.cost;
                que.push(make_pair(d[e.to], e.to));
            }
        }
    }
    cout << fixed << setprecision(10) << d[N + 1] << endl;
}


Measured memory_bytes: 34932
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
int c[4];
int main()
{
	int i;
	char s[301];
	cin >> s;
	for (i = 0; i < strlen(s); i++)
	{
		if (s[i] == 'K')
			c[0]++;
		if (s[i] == 'U')
			c[1]++;
		if (s[i] == 'P')
			c[2]++;
		if (s[i] == 'C')
			c[3]++;
	}
	sort(c, c+4);
	cout << c[0] << endl;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
#define rep(i, l, r) for(int i = (l), i##end = (r);i <= i##end;++i)
using std::cin; using std::cout;
const int maxn = 200200;
typedef long long ll;
const int mod = 998244353;
inline ll pow(ll a,int b,int ans = 1) {
	for(;b;b >>= 1,a = a * a % mod) if(b & 1)
		ans = ans * a % mod;
	return ans;
}
inline ll inverse(int x){ return pow(x, mod - 2); }
int a[maxn], n;
struct T{ int to, nxt; } way[maxn << 1];
int h[maxn], num;
inline void link(int x,int y) {
	way[++num] = {y, h[x]}, h[x] = num;
	way[++num] = {x, h[y]}, h[y] = num;
}
inline int dfs(int x,int f) {
	for(int i = h[x];i;i=way[i].nxt) if(way[i].to != f && a[way[i].to] < a[x]) 
		if(!dfs(way[i].to,x)) return 1;
	return 0;
}
int main() {
	std::ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cin >> n;
	rep(i, 1, n) cin >> a[i];
	rep(i, 1, n - 1) { int x, y; cin >> x >> y, link(x, y); }
	rep(i, 1, n) if(dfs(i, 0)) cout << i << ' ';
}


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

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

int gcd(vector<int> &a){
    int ret = a[0];
    for(int i=1; i<a.size(); i++)
        ret = gcd(ret, a[i]);
    return ret;
}

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

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define MAXN 110
using namespace std;

int coord[MAXN];

int main(){
    int n;

    cin>>n;

    for(int i=0; i<n; i++)
        cin >> coord[i];

    int res = 9999999;

    for(int i=0; i<=100; i++){
        int val = 0;
        for(int j=0; j<n; j++){
            val += (i-coord[j])*(i-coord[j]);
        }
        res = min(res,val);
    }

    cout << res << endl;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String[] numbers = sc.nextLine().split(" ", 0);
    for (int i = 0; i < numbers.length; i++) {
      if (numbers[i].equals("0")) {
        System.out.println(i + 1);
        break;
      }
    }
  }
}


Measured memory_bytes: 35628
#include<stdio.h>
#include<string.h>
int main()
{
	char s[100000+1000];
	char s1[100000+1000];
	scanf("%s",s);
	int l=strlen(s);
	int j=0;
	s1[0]=s[0];
	for(int i=1; i<l; i++)
	{
		if(s[i] != s1[j])
		{
			j++;
			s1[j]=s[i];
		}
	}
	//printf("%s\n",s1);
	printf("%d\n",strlen(s1)-1);
	return 0;
}

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

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

int main(void) {
  int a, b;
  cin >> a >> b;
  int g = gcd(a, b);
  cout << (long long)a * (long long)b / g << endl;
  return 0;
}

Measured memory_bytes: 256
import sys
#sys.setrecursionlimit(n)
import heapq
import re
import bisect
import random
import math
import itertools
from collections import defaultdict, deque
from copy import deepcopy
from decimal import *

readl= lambda: list(map(int, sys.stdin.readline().split()))
readt= lambda: tuple(map(int, sys.stdin.readline().split()))
read = lambda: sys.stdin.readline().rstrip()
readi = lambda: int(read())
readmi = lambda: map(int, sys.stdin.readline().split())
readms = lambda: map(str, sys.stdin.readline().split())

a, b = readmi()

su = 0
for i in range(1, a + 1):
    for j in range(10, b + 1):
        t = str(j)
        tt = list(t)
        if int(tt[0]) >= 2 and int(tt[1]) >= 2:
            if i == int(tt[0]) * int(tt[1]):
                su += 1
print(su)

Measured memory_bytes: 8136
#include <iostream>
using namespace std;
bool so[1000001];
int main() {

  so[0] = so[1] = 1;
  for(int i=2;i*i<=1000000;i++){
    if(so[i] == 0){
      for(int j=2;j<=1000000/i;j++) so[i*j] = 1;
    }
  }
  // for(int i=0;i<1000001;i++)if(so[i] == 0) cout << i<<endl;
  
  while(1){
    int a,d,n;
    cin>>a>>d>>n;
    if(a == 0 &&d == 0 && n == 0) break;

    int ans = a;
    int cnt = 0;
    while(1) {
      if(so[ans] == 0) cnt++;
      if(cnt == n) break;
      ans += d;
    }

    cout << ans <<endl;

  }

  return 0;
}

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

int main() {
	int N, M; cin >> N >> M;
	int from1[200010], toN[200010];
	for(int i=1; i<=N; ++i){
	    from1[i]=0;
	    toN[i]=0;
	}
	bool flag=false;
	int a, b;
	for(int i=0; i<M; ++i){
	    cin >> a >> b;
	    if(a==1){
	        from1[b]=1;
	        if(toN[b]){
	            flag=true;
	            break;
	        }
	    }
	    else if(b==N){
	        toN[a]=1;
	        if(from1[a]){
	            flag=true;
	            break;
	        }
	    }
	}
	if(flag) cout << "POSSIBLE" << endl;
	else cout << "IMPOSSIBLE" << endl;
	return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
typedef long long ll;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)
	
using namespace std;
const int MAX_H=2000,MAX_W=2000;
int H,W;
string S[MAX_H];
typedef pair<int,int> P;
int bad[MAX_H-1][MAX_W-1];
int main(){
	cin>>H>>W;
	REP(i,H){
		cin>>S[i];
	}
	REP(h,H-1){
		REP(w,W-1){
			int cnt=0;
			REP(i,2){
				REP(j,2){
					if (S[h+i][w+j]=='#'){
						cnt++;
					}
				}
			}
			if (cnt&1){
				bad[h][w]=1;
			}
		}
	}
	int ans=max(H,W);
	REP(i,W-1){
		bad[0][i]=1-bad[0][i];
	}
	REP(h,H-2){
		REP(w,W-1){
			if (bad[h+1][w]==1){
				bad[h+1][w]=0;
			}else{
				bad[h+1][w]=bad[h][w]+1;
			}
		}
	}
	REP(h,H-1){
		stack<P> st;
		REP(w,W-1){
			int tem=w;
			while(!st.empty() && st.top().second>bad[h][w]+1){
				P p=st.top();
				st.pop();
				ans=max(ans,(w-p.first+1)*p.second);
				tem=p.first;
			}
			st.push(P(tem,bad[h][w]+1));
		}
		while(!st.empty()){
			P p=st.top();
			st.pop();
			ans=max(ans,((W-p.first)*p.second));
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 19968
#include<algorithm>
#include<iostream>
#include<utility>
#include<climits>

typedef std::pair<int, int> P;

const int ST_SIZE = 1 << 21;
int sz;
P dat[ST_SIZE];

void init( int n )
{
	sz = 1;
	while( sz < n )
		sz *= 2;

	for( int i = 0; i != 2 * sz - 1; ++i )
		dat[i] = P( 0, 0 );

	return;
}

void add( int k, int a )
{
	k += sz - 1;
	dat[k].first += a;

	while( k > 0 )
	{
		k = ( k - 1 ) / 2;
		dat[k] = std::max( dat[k * 2 + 1], dat[k * 2 + 2] );
	}

	return;
}

P query( int a, int b, int k, int l, int r )
{
	if( r <= a || b <= l )
		return P( INT_MIN, INT_MIN );

	if( a <= l && r <= b )
		return dat[k];
	
	P vl = query( a, b, k * 2 + 1, l, ( l + r ) / 2 ),
	  vr = query( a, b, k * 2 + 2, ( l + r ) / 2, r );

	return std::max( vl, vr );
}

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

	init( n );

	for( int i = 0; i != n; ++i )
		dat[i+sz-1].second = -i;

	for( int i = 0; i != q; ++i )
	{
		int a, v;
		std::cin >> a >> v;

		P p = query( a - 1, a, 0, 0, n );
		add( a - 1, v );

		p = query( 0, n, 0, 0, n );

		std::cout << -p.second + 1 << " " << p.first << std::endl;
	}

	return 0;
}

Measured memory_bytes: 17544
#include <iostream>
#include <vector>
#include <cstring>
#include <string>
#include <algorithm>
#include <iomanip>
using namespace std;

int N, K;
vector<int> D;

bool ok(string s) {
	for(char c : s) {
		for(int d : D) {
			if(c - '0' == d) return false;
		}
	}
	return true;
}

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


	cin >> N >> K;

	D = vector<int>(K);
	for(int i = 0; i < K; i++) {
		cin >> D[i];
	}

	for(int i = N; i < 100000; i++) {
		if(ok(to_string(i))) {
			cout << i << endl;
			return 0;
		}
	}
}

Measured memory_bytes: 256