akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll A,B,Q;
ll s[(ll)(1e5+5)],t[(ll)(1e5+5)];
ll bisect(ll *to_search,ll l,ll r,ll r_max,ll num){
    if(num>to_search[r_max]) return r_max;
    if(num<to_search[0]) return 0;
    if(r-l<=100){
        ll ret=LLONG_MAX;
        for(int i=l;i<=r;i++){
            if(to_search[i]<=num) ret=i;
        }
        if(ret+1!=r_max+1)
            if(num-to_search[ret]>to_search[ret+1]-num){
                return ret+1;
            } 
        return ret;
    }
    if(num>=to_search[(l+r)/2]){
        return bisect(to_search,(l+r)/2,r,r_max,num);
    }
    else return bisect(to_search,l,(l+r)/2,r_max,num);
}
int main(){ 
    cin>>A>>B>>Q; getchar();
    for(int i=0;i<A;i++) {cin>>s[i]; getchar();}
    for(int i=0;i<B;i++) {cin>>t[i]; getchar();}
    for(int i=0;i<Q;i++){
        ll x;
        cin>>x; getchar();
        ll a=bisect(s,0,A-1,A-1,x);
        ll ans1=abs(s[a]-x)+abs(s[a]-t[bisect(t,0,B-1,B-1,s[a])]);

// cout<<"1."<<ans1<<endl;

        ll b=bisect(t,0,B-1,B-1,x);
        // cout<<ans1<<endl;
        ll bj=b;
        ll ans2=min(ans1,abs(t[(b)]-x)+abs(t[(b)]-s[bisect(s,0,A-1,A-1,t[b])]));
        if(s[a]==x){
            ll xyz=abs(t[b]-s[a]);
        } 
        //找s经过t
        //1.s
        if(s[a]<x){
            if(t[b]>x) b--;
            if(b==-1) b++;
            else if(t[b]>s[a]) ans2=min(ans2,x-min(s[a],t[b]));
        }
        // cout<<"b="<<b<<endl;
    else    if(s[a]>x){
            if(t[b]<x) b++;
            if(b==B) b--;
            else if(t[b]<s[a]) ans2=min(ans2,max(s[a],t[b])-x);
        } 

        b=bj;
        if(s[a]>=x)
        a--;
        else a++;
        if(a==-1) a++;
        if(a==A) a--;


ans2=min(ans2,abs(s[a]-x)+abs(s[a]-t[bisect(t,0,B-1,B-1,s[a])]));
// cout<<"4."<<ans2<<endl;
        if(s[b]>=x)
        b--;
        else b++;
        if(b==-1) b++;
        if(b==B) b--;

ans2=min(ans2,abs(t[(b)]-x)+abs(t[(b)]-s[bisect(s,0,A-1,A-1,t[b])]));
// cout<<"5."<<ans2<<endl;
b=bj;
if(s[a]<x){
            if(t[b]>x) b--;
            if(b==-1) b++;
            else if(t[b]>s[a]) ans2=min(ans2,x-min(s[a],t[b]));
        }
        // cout<<"b="<<b<<endl;
    else    if(s[a]>x){
            if(t[b]<x) b++;
            if(b==B) b--;
            else if(t[b]<s[a]) ans2=min(ans2,max(s[a],t[b])-x);
        } 
cout<<ans2<<endl;
    }
    return 0;
}


//////wa了好久，情况考虑不全！！！！！！！！！！！！！！！！！
/*
二分写得倒挺好的嘛！！！！！！！！！！

一开始只考虑了4（3）种情况！应该有8（6）种情况！！！！！！！！！！！！
*/

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

int main() {
  int K, T;
  cin >> K >> T;
  vector<int> A(T);
  for (int i = 0; i < T; i++) cin >> A.at(i);
  int mx = *max_element(A.begin(), A.end());
  int sum = accumulate(A.begin(), A.end(), 0);
  sum -= mx;
  mx--;
  int ans = mx - sum;
  if (ans < 0) ans = 0;
  cout << ans << "\n";
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
#define rep(i, n) for ( int i = 0; i < n; i++)
static const int MAX = 30;
int H, W, N;
char G[MAX][MAX], T[MAX][MAX];

bool isSolved(){
  rep(i, H) rep(j, W) if ( T[i][j] != '.' ) return false;
  return true;
}

bool remove(){
  /*
  cout << "bef" << endl;
  rep(i, H) {
    rep(j, W) cout << T[i][j];
    cout << endl;
  }
  cout << endl;
  */
  bool rem = false;
  bool R[MAX][MAX];
  rep(i, H) rep(j, W) R[i][j] = false;
  rep(i, H){
    int j = 0;
    int cnt = 1;
    while( j < W ){
      int s = j;
      while( j+1 < W && T[i][j] == T[i][j+1] ){ j++; cnt++;}
      if ( cnt >= N ){
	rem = true;
	for ( int k = s; k < s+cnt; k++ ) R[i][k] = true;
      }
      j++; cnt = 1;
    }
  }

  rep(j, W){
    int i = 0;
    int cnt = 1;
    while( i < H ){
      int s = i;
      while( i+1 < H && T[i][j] == T[i+1][j] ){ i++; cnt++;}
      if ( cnt >= N ){
	rem = true;
	for ( int k = s; k < s+cnt; k++ ) R[k][j] = true;
      }
      i++; cnt = 1;
    }
  }
  rep(i, H) rep(j, W) if ( R[i][j] ) T[i][j] = '.';

  /*
  rep(i, H) {
    rep(j, W) cout << T[i][j];
    cout << endl;
  }
  cout << endl;
  */
  return rem;
}

bool down(){
  int m = 0;
  while(1){
    bool moved = false;
    for ( int i = H-1; i >= 1; i-- ){
      rep(j, W){
	if ( T[i][j] == '.' && T[i-1][j] != '.' ){
	  moved = true;
	  m++;
	  swap(T[i][j], T[i-1][j]);
	}
      }
    }
    if ( !moved) break;
  }
  return m > 0;
}

bool solve(){
  down();
  while(1){
    if (!remove()) break;
    if (!down()) break;
  }
  return isSolved();
}

main(){
  cin >> H >> W >> N;
  rep(i, H) rep(j, W ) cin >> G[i][j];
  bool suc = false;
  rep(i, H) rep(j, W-1 ) {
    rep(a, H) rep(b, W ) T[a][b] = G[a][b];
    //   if ( T[i][j] == '.' || T[i][j+1] == '.' ) continue;
    swap(T[i][j], T[i][j+1]);
    if ( solve() ){
      suc = true;
      break;
    }
  }
  cout << (suc?"YES":"NO") << endl;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
#define LL long long
using namespace std;

int main()
{
	double n;
	int num;
	LL int tot=0;
	cin>>n;
	double odd=0,even=0;
	for(int i=0;i<n;i++)
	{
		cin>>num;
		if(num%2==0)
		{
			even++;
		}
		else
		{
			odd++;
		}
	}
	tot=pow(3,n)-pow(2,even);
	cout<<tot<<endl;
	return 0;
	
} 

Measured memory_bytes: 256
#include <functional>
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <queue>
#include <string>
#include <cstring>
#include <math.h>
using namespace std;


int main() {
    int a;
    int b;
    int c;
    int d;
 
   cin >> a >> b >> c >> d;
  
   cout << (a-c)*(b-d) << endl;
   
  return 0;
}

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

  
//#define FOR(i,0,n) for(int i=0;i<n;i++)
int main() {
  // your code goes here
  /*int t;
  cin>>t;
  while (t--)
  {*/
  char c; string s1=" "; cin>>c;

  s1=char('a'+(c-'a'+1)%26);
  cout<<s1;
  
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int sum_of_digits(int n){
    int res = 0;
    while (n){
        res += n % 10;
        n /= 10;
    }
    return res;
}

bool equal(int n){
    if (n % 10) return true;
    while (n){
        n /= 10;
        if (n == 1) return false;
        if (n % 10) return true;
    }
}

int main()
{
    int n;  cin >> n;
    if (equal(n)) cout << sum_of_digits(n) << endl;
    else cout << 10 << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int n,i,a,b,h=0;
  scanf("%d %d",&n,&b);
  for(i=1;i<n;i++){
    scanf("%d",&a);//printf("%d %d\n",a,h);
    if(b>a+1)goto END;
    if(b>a){
      if(h)goto END;
      h=1;
    }
    if(b<a)h=0;
    b=a;
  }
  printf("Yes\n");
  return 0;
 END:;
  printf("No\n");
  return 0;
}
    
      


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

// 構造体
struct num {
  int num_;
  int count_;
};

// 比較関数
bool cmp (const num &a, const num &b) {
  if (a.count_ < b.count_) {
    return true;
  }
  if (a.count_ > b.count_) {
    return false;
  }
  if (a.num_ > b.num_) {
    return true;
  }
  if (a.num_ < b.num_) {
    return false;
  }
  return false;
}

int main() {

  int N, K;
  cin >> N >> K;

  map<int,int> counts;
  for (int i = 0; i < N; i++) {
    int A;
    cin >> A;
    counts[A]++;
  }

  vector<num> nums;
  for (auto item:counts){
    num n_ = num();
    n_.num_ = item.first;
    n_.count_ = item.second;
    nums.push_back(n_);
  }

  // 比較関数で並び替え
  sort(nums.begin(), nums.end(), cmp);

  int answer = 0;

  if (K < nums.size()) {

    for (int i = 0; i < nums.size() - K; i++) {
      answer += nums[i].count_;
    }

  }

  cout << answer << endl;

  return 0;

}

Measured memory_bytes: 11768
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
    
int n ;
cin>>n;
vector<int> dp(10050,0);
for(int i=1;i<106;i++)
{
    for(int j=1;j<106;j++)
    {
        for(int k=1;k<106;k++) 
        {
        
            int temp = i*i+j*j+k*k+i*j+j*k+k*i;
        
        if(temp<=10040)
            dp[temp]++;
            
        }
    }
}
for(int i=1;i<=n;i++)
{
    cout<<dp[i]<<endl;
}


}

Measured memory_bytes: 3632
/* basic header */
#include <bits/stdc++.h>
/* define */
#define ll long long
#define dou double
#define pb emplace_back
#define mp make_pair
#define sot(a,b) sort(a+1,a+1+b)
#define rep1(i,a,b) for(int i=a;i<=b;++i)
#define rep0(i,a,b) for(int i=a;i<b;++i)
#define eps 1e-8
#define int_inf 0x3f3f3f3f
#define ll_inf 0x7f7f7f7f7f7f7f7f
#define lson (curpos<<1)
#define rson (curpos<<1|1)
/* namespace */
using namespace std;
/* header end */

const int maxn = 1e5 + 10;
int n;
string s[maxn];
ll ans = 0;

int main() {
    scanf("%d", &n);
    rep1(i, 1, n) {
        cin >> s[i];
        sort(s[i].begin(), s[i].end());
    }
    sort(s + 1, s + 1 + n);
    int cnt = 1;
    rep1(i, 2, n) {
        if (s[i] == s[i - 1]) cnt++;
        else {
            ans += (ll)cnt * (cnt - 1) / 2;
            cnt = 1;
        }
    }
    ans += (ll)cnt * (cnt - 1) / 2;
    printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 7296
//
// Created by 清水ヒロシ on 2018/11/20.
//
// from ALDS1_2_A: Bubble Sort
//

#include <iostream>

using namespace std;

void traceArr(int *arr, int n)
{
    for (int i=0; i<n; ++i) {
        if (i != 0) {
            cout << " ";
        }
        cout << arr[i];
    }
    cout << endl;
}

void bubbleSort()
{
    int N;
    cin >> N;
    int *arr = new int[N];
    for (int i=0; i<N; ++i) {
        cin >> *(arr + i);
    }
    int swapTime = 0;
    int tmp;
    for (int i=0; i<N-1; ++i) {
        for (int j=N-1; j>=i+1; --j) {
            if (arr[j] < arr[j-1]) {
                tmp = arr[j-1];
                arr[j-1] = arr[j];
                arr[j] = tmp;
                swapTime ++;
            }
        }
    }
    traceArr(arr, N);
    cout << swapTime << endl;
    delete[] arr;
}

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


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

#define int long long

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  int N;
  cin >> N;

  cout << 180*(N-2) << endl;
  
  return 0;
}


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

int main(){
    string w;
    cin >> w;
    int ans = 0;
    while(true){
        string t;
        cin >> t;
        if(t == "END_OF_TEXT") break;
        for(int i=0;i<t.size();++i) t[i] = tolower(t[i]);
        if(t == w) ans++;
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 3160
#設定
import sys
input = sys.stdin.buffer.readline

#ライブラリインポート
from collections import defaultdict

con = 10 ** 9 + 7
#入力受け取り
def getlist():
	return list(map(int, input().split()))

#処理内容
def main():
	A, B = getlist()
	ans = 100000000
	for i in range(10, 1001):
		a = int(i * 0.08 // 1)
		b = int(i * 0.1 // 1)
		if a == A and b == B:
			print(i)
			return

	print(-1)

 

if __name__ == '__main__':
	main()

Measured memory_bytes: 38384
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define mp make_pair
#define pb push_back
#define all(v) v.begin(), v.end()
#define ub upper_bound
#define lb lower_bound

int main(){
    fastio;
    int s, w;
    cin >> s >> w;
    if(w >= s) cout << "unsafe" << endl;
    else cout << "safe\n";
    
    return 0;
}

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

int main(){
  char s[10],t[10],u[10];
  int a,b;
  scanf("%s%s",s,t);
  scanf("%d%d",&a,&b);
  scanf("%s",u);

  if(s[0]==u[0])  a--;
  else b--;

  printf("%d %d",a,b);
  return 0;
}


Measured memory_bytes: 128
def power(x,y):
	res=1
	while y>0:
		if y%2==1:
			res=(res*x)
		y=y//2
		x=x*x
	return res

x=int(input())
for i in range(-1000,1001,1):
	rr=power(i,5)
	for j in range(-1000,1001,1):
		temp=rr-power(j,5)
		if temp==x:
			print(i,j)
			exit()

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

int main() {
  int n; cin >> n;
  double distx[n],disty[n];
  rep(i,n) cin>>distx[i]>>disty[i];
    
    vector<int> order(n);
    for (int i = 0; i < n; ++i) order[i] = i;

    double sum=0;
    int count=0;
    do {
        double temp_dist = 0;
        for (int i = 1; i < n; ++i) {
            temp_dist += sqrt((distx[order[i-1]]-distx[order[i]])*(distx[order[i-1]]-distx[order[i]])+(disty[order[i-1]]-disty[order[i]])*(disty[order[i-1]]-disty[order[i]]));
        }
            sum += temp_dist;
            count++;
    } while (next_permutation(order.begin(), order.end()));

    cout <<setprecision(10)<< sum/count << endl;

}

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

int main() {
	int N;
	cin >> N;
	vector<long long>A;
	int count = 0;
	for (int n = 0;n<N;++n) {
		int num = 0;
		cin >> num;
		if (0 == n) {
			A.push_back(num);
			count++;
		}
		else {
			if (A[count-1]!=num) {
				A.push_back(num);
				count++;
			}
		}
	}
	long long now = 1000;
	long long num = 0;
	long long num2 = 0;
	int size = A.size();
	{
		if (A[0] < A[1]) {
			num = now / A[0];
			now -= A[0]*(num);
			num2 = A[0];
		}
	}
	for (int n = 1; n < size-1; ++n) {
		if (A[n]>A[n-1]&&A[n]>A[n + 1]) {
			now += A[n] * num;
			num = 0;
			num2 = A[n];
		}		
		if (A[n] < A[n - 1] && A[n] < A[n + 1]) {
			num = now/A[n]; 
			now -= A[n] * num;
			num2 = A[n];
		}
		//cout << now <<" " <<num<<" "<<num2<<endl;
	} 
	{
		now += max(A[size-1],num2)*num;
	}
	//最終日は別処理
	cout << now <<endl;
	return 0;
}

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

int main() {
  long long a,b,c;
  cin>>a>>b>>c;
  
  long long x;
  long long y;
  x = a*a + b*b + c*c;
  y = 2*a*b + 2*b*c + 2*c*a;
  
  if(c-a-b<0) cout << "No" << endl;
  
  else{
    if(x>y) cout << "Yes" << endl;
    else cout << "No" << endl;
  }
  
}


Measured memory_bytes: 256
from itertools import*
from math import*
from collections import deque
from collections import defaultdict
from itertools import permutations
from heapq import*
from collections import Counter
from itertools import*
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf = 10**18
mod = 10**9+7
from functools import reduce
import sys
sys.setrecursionlimit(10**7)

n,k = map(int,input().split())
f = lambda x,y :(min(x,y),max(x,y))
xy = [tuple(map(int,input().split())) for _ in range(n)]
S = float("inf")
for (a,b) in combinations(range(n),2):
    for(c,d) in combinations(range(n),2):
        lx,rx = f(xy[a][0],xy[b][0])
        dy,uy = f(xy[c][1],xy[d][1])
        cnt = 0
        for i in xy:
            if lx<=i[0]<=rx and dy<=i[1]<=uy:
                cnt += 1
        if cnt >= k:
            S = min(S,(rx-lx)*(uy-dy))
print(S)


Measured memory_bytes: 58332
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int  k, sum;
  cin >> k;
  sum = 0;
  for(int i = 1; i <= k; i++){
    for(int j = 1; j <= k; j++){
      for(int l = 1; l <= k; l++){
        sum = sum + gcd(gcd(i, j), l);
      }
    }
  }
  
  cout << sum <<endl;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
#include <cassert>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
struct Edge
{
  int to;
  int weight;
  Edge(int t, int w) : to(t), weight(w) {}
};
//using Graph = vector<vector<Edge>>;
using Graph = vector<vector<int>>;

const long long INF = 1LL << 60;
const int INT_INF = 1000000000;
const double PI = acos(-1.0);

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

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  string s;
  cin >> s;
  int P = 0;
  for (int i = 0; i < s.size(); i++)
    if (s[i] == 'p')
      P++;
  int ans = s.size() / 2 - P;
  cout << ans << endl;
  return 0;
}

// 相手がP回パーを出したとする．まず自分が全てグーを出したと考えると得点は-P点．自分のグーをどれか一つパーに変えたとするとそのターンの相手の手がグーのとき 0->1より+1点．相手の手がパーの時-1->0より+1点．すなわち，自分や相手がどのターンでパーを出したかに寄らず得点は(自分がパーを出した回数) - (相手がパーを出した回数)になる．したがって出来るだけ多くパーを出せばよい．すなわちグー，パー，グー，パー，...とすればよくN / 2 - Pとなる．


Measured memory_bytes: 512
#include <stdio.h>
 
int main(){
  int i,j,n;
  int cnt=0;
  int mini;
  scanf("%d",&n);
  int A[n];
 
  for(i=0; i<n; i++)
    scanf("%d",&A[i]);
   
  for(i=0; i<n; i++){
    mini = i;
    for(j=i; j<n; j++)
      if(A[j] < A[mini])
    mini = j;
    if(mini != i){    
      int tmp = A[i];
      A[i] = A[mini];
      A[mini] = tmp;
      cnt++;
    }
  }
   
  for(i=0; i<n-1; i++)
    printf("%d ",A[i]);
   
  printf("%d\n%d\n",A[n-1],cnt);
  return 0;
}


Measured memory_bytes: 2144
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <stack>
#include <climits>
#include <map>
#include <set>

using namespace std;

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

const ll mod = 1000000007;
const int inf = 1e9;
const long long INF = 1LL << 60;

typedef pair<int, int> P;  // firstは最短距離、secondは頂点の番号
const int MAX_V = 100010;
struct edge {
    int to,cost;
};
int V;
vector<edge> G[MAX_V];  //重み付き有効グラフの隣接リスト表現
int d[MAX_V];

void dijkstra(int s){
    //greater<P>を指定することでfirstが小さい順に取り出せるようにする
    priority_queue<P, vector<P>,greater<P> > que;
    fill(d,d+V,inf);
    d[s] = 0;
    que.push(P(0,s));

     while(!que.empty()){
         P p = que.top(); que.pop();     // firstは最短距離、secondは頂点の番号
         int v = p.second;
         if(d[v] < p.first) continue;  
         for(int i = 0; i < G[v].size(); i++){
             edge e = G[v][i];
             if(d[e.to] > d[v] + e.cost){
                 d[e.to] = d[v] + e.cost;
                 que.push(P(d[e.to],e.to));
             }
         }
    }
}


int main()
{
    int e,r;
    cin >> V >> e >> r;
    for(int i = 0; i < e; i++){
        int s,t,u;
        cin >> s >> t >> u;
        struct edge e;
        e.to = t; e.cost = u;
        G[s].push_back(e);
    }
    dijkstra(r);
    for(int i = 0; i < V; i++){
        if(d[i] == inf){
            cout << "INF" << endl;
        }else{
            cout << d[i] << endl;
        }
    }
}



Measured memory_bytes: 12968
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(i=0;i<n;i++)
#define loop(i,a,n) for(i=a;i<n;i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

typedef vector<int> vi;
typedef pair<int,int> pii;

int main(void) {
  int i,j;
  ll a,b,n;
  while(cin>>a>>b>>n){
    rep(i,n)a*=10;
    a=a/b;
    ll ans=0;
    rep(i,n){
      ans+=a%10;
      a/=10;
    }
    cout<<ans<<endl;
  }
}

Measured memory_bytes: 3044
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) (x).begin(),(x).end()
#define uniq(x) (x).erase(unique(ALL(x)),(x).end())
#define SORT(x) sort(ALL(x))
#define REV(x) reverse(ALL(x))
#define foreach(it,x) for(__typeof((x).begin()) it=(x).begin();it!=(x).end();it++)
#define debug(x) cerr<<#x<<"="<<(x)<<endl
#define gett() cerr<<"Time:"<<clock()<<"ms."<<endl
int n;
string s;
long long dpa[100100],dpc[100100],dpq[100100];
long long powe[100100];
const long long MOD=1000000007;
int main(){
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>s;
	n=s.size();
	powe[0]=1LL;
	for(int i=1;i<=100000;i++)
		powe[i]=(powe[i-1]*3)%MOD;
	int q=0;
	for(int i=1;i<=n;i++){
		if(s[i-1]=='?')
			q++;
		dpa[i]=dpa[i-1];
		dpc[i]=dpc[i-1];
		dpq[i]=dpq[i-1];
		if(s[i-1]=='A')
			dpa[i]++;
		if(s[i-1]=='C')
			dpc[i]++;
		if(s[i-1]=='?')
			dpq[i]++;
	}
	long long res=0;
	for(int i=0;i<n;i++){
		long long pq=dpq[i]-dpq[0],pa=dpa[i]-dpa[0],fq=dpq[n]-dpq[i+1],fc=dpc[n]-dpc[i+1];
		if(s[i]=='B'){
			res=(res+pa*fc*powe[q]%MOD+pa*fq*(q==0?0:powe[q-1])%MOD+pq*fc*(q==0?0:powe[q-1])%MOD+pq*fq*(q<=1?0:powe[q-2])%MOD)%MOD;
		}
		if(s[i]=='?'){
			res=(res+pa*fc*(q==0?0:powe[q-1])%MOD+pa*fq*(q<=1?0:powe[q-2])%MOD+pq*fc*(q<=1?0:powe[q-2])%MOD+pq*fq*(q<=2?0:powe[q-3])%MOD)%MOD;
		}
	}
	cout<<res<<endl;
	return 0;
}


Measured memory_bytes: 3664
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int MOD=1e9+7;
int fami(int a,int b){
	int res=1;
	while(b){
		if(b&1)res=1ll*res*a%MOD;
		a=1ll*a*a%MOD;
		b>>=1; 
	}
	return res;
} 
int main()
{
  int n;
  cin>>n;
  cout<<((0ll+fami(10,n)-2*fami(9,n)+fami(8,n))%MOD+MOD)%MOD;


return 0;
}



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

using namespace std;
#define inf 1000000000
#define unvisited -1
#define visited 1
#define eps 1e-9
#define mp make_pair
#define pb push_back
#define pi acos(-1.0)
#define uint64 unsigned long long
#define FastSlowInput ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define debug if(true)
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;

bool isprime[1000001];
int prime[78500];

void sieve(int n) {
	int i,j;
	isprime[0] = isprime[1] = false;
	for(i=2;i*i<=n;i++){
		if(isprime[i]){
			for(j=i*i;j<=n;j+=i){
				isprime[j] = false;
			}
		}
	}
}


vii factorize(ll n) {
	ll pf_idx = 0, pf = prime[pf_idx];
	vii ans;
	while(pf*pf <= n){
		int cnt = 0;
		while(n % pf == 0) {
			cnt++;

			n /= pf;
		}
		if(cnt){
			ans.pb(ii(pf, cnt));
		}
	}
	if(n != 1){
		ans.pb(ii(n, 1));
	}
	return ans;
}

int main(){
	int i,j;
	memset(isprime, true, sizeof isprime);
	sieve(1000000);
	int cnt = 0;

	for(i=2;i<=1000000;i++){
		if(isprime[i]){
			prime[cnt++] = i;
		}
	}

	ll n;
	cin>>n;
	
	// vii fac = factorize(n);
	ll ans = 0;
	// if(fac.size() == 1){
	// 	//find num of divisor of fac[0].second;
	// 	int pangkat = fac[0].second;
	// 	for(i=1;i*i<=pangkat;i++){
	// 		if(pangkat % i == 0){
	// 			int div1 = i;
	// 			int div2 = pangkat / i;
	// 			if(div1 == div2){
	// 				printf("%d\n",div1);
	// 				ans++;
	// 			}else {
	// 				printf("%d %d\n",div1, div2);
	// 				ans+=2;
	// 			}
	// 		}
	// 	}
	// }

	//find divisors of n
	vector<ll> listDiv;
	for(ll i=1;i*i<=n;i++){
		if(n % i == 0){
			ll div1 = i;
			ll div2 = n/i;
			if(div1 == div2) {
				if(div1 != 1){
					listDiv.pb(div1);
				}
			}else{
				if(div1 != 1){
					listDiv.pb(div1);
				}
				if(div2 != 1){
					listDiv.pb(div2);
				}
			}
		}
	}

	for(i=0;i<listDiv.size();i++){
		ll bil = listDiv[i];

		ll temp = n;
		while(temp % bil == 0){
			temp /= bil;
		}
		temp %= bil;
		if(temp == 1){
			// printf("bil: %lld\n",bil);
			ans++;
		}
	}

	//find num divisor dr n-1
	ll angka = n-1;
	for(ll i=1;i*i<=angka;i++){
		if(angka % i == 0){
			ll div1 = i;
			ll div2 = angka / i;
			if(div1 == div2){
				if(div1 != 1){
					ans++;
				}
				// printf("%lld\n",div1);
				// ans++;
			}else{
				if(div1 != 1){
					ans++;
				}
				if(div2 != 1){
					ans++;
				}
				// printf("%lld %lld\n",div1, div2);
				// ans += 2;
			}
		}
	}

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

	return 0;
};

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

int main(void){
    int altitude[10];
    int tmp=0;
    for(int i=0;i<10;++i){
        scanf("%d",&altitude[i]);
    }
    for(int i=0;i<9;++i){
        for(int j=0;j<9;++j){
            if(altitude[j+1]>altitude[j]){
                tmp=altitude[j+1];
                altitude[j+1]=altitude[j];
                altitude[j]=tmp;
            }
        }
    }
    for(int i=0;i<3;++i){
        printf("%d\n",altitude[i]);
    }
    return 0;
}


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

int main(){
  int N,X,Y;cin >> N >> X >> Y;
  vector<int> L(N,0);
  for(int i=1;i<=N;i++){
    for(int j=i+1;j<=N;j++){
      int l = j-i;
      l = min(l,abs(X-i)+abs(Y-j)+1);
      l = min(l,abs(X-j)+abs(Y-i)+1);
      L[l] ++;
    }
  }
  for(int i=1;i<N;i++){
    cout << L[i] << endl;
  }
}

Measured memory_bytes: 3604
n, m = gets.split.map(&:to_i)
multiple_array = Array.new(n, 0)
n.times do |i|
  multiple_array[i] = gets.split.map(&:to_i)
end

multiple_array.sort_by! { |a, b| a }
ans = 0
buy_sum = 0

multiple_array.each do |a, b|
  buy = 0
  if m >= buy_sum + b
    buy = b
  else
    buy = m - buy_sum
  end
  buy_sum += buy
  ans += a * buy
  break if m == buy_sum
end

puts ans

Measured memory_bytes: 13688
#include <iostream>
#include <fstream>
#include <vector>
#include <cstring>


#define REP(i, n) for (long long i = 0; i < (n); i++) 
#define ll long long

using namespace std;

int main()
{
    //    std::ifstream in("input.txt");
//    std::cin.rdbuf(in.rdbuf());
    ll N,M,res;
    cin >> N >> M;

    ll dp[N+1];
    std::memset(dp, 0, sizeof dp);

    bool dan[N+1];
    std::memset(dan, true, sizeof dan);

    ll tmp;
    REP(i,M)
    {
        cin >> tmp;
        dan[tmp] = false;
    }

    dp[0] = 1;//1通り
    if(dan[1] == true)dp[1] = 1;//1段目が壊れてなければ1通り

    for(ll i = 2; i <= N; i++)
    {
        if(dan[i] == true)
        {
        dp[i] += dp[i-1]; 
        dp[i] += dp[i-2]; 
        }
        //else dp[i] = 0;
        dp[i] = dp[i] % 1000000007;

    }
    //1000000007
  
    cout << dp[N] << endl;

    return 0;
}



Measured memory_bytes: 1152
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <bitset>
#include <cassert>
using namespace std;
using ll = long long;

bool used[200003];

int main() {
	int M, K; cin >> M >> K;
	if (M == 1) {
		if (K == 0) cout << "0 0 1 1" << endl;
		else cout << -1 << endl;
		return 0;
	}
	if (K >= (1 << M)) {
		cout << -1 << endl;
		return 0;
	}
	auto two = [&](int b) {
		int ret = 1 << b;
		ret |= 1 << ((b + 1) % M);
		return ret;
	};
	vector<int> left, right;
	left.push_back(K);
	used[K] = true;
	for (int i = 0; i < (1 << M); i++) {
		if (used[i]) continue;
		right.push_back(i);
	}
	deque<int> ans;
	for (int i : left) ans.push_back(i);
	for (int i : right) ans.push_back(i);
	for (int i = left.size() - 1; i >= 0; i--) ans.push_back(left[i]);
	for (int i : right) ans.push_front(i);
	int a = (1 << (M + 1));
	for (int i = 0; i < a; i++) cout << ans[i] << " \n"[i == a - 1];
	return 0;
}

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

int main(){
    int k,n,b,length,ans,tmp,start,now,prev;
    now = -1;
    prev = 0;
    length = -1;
    cin >> k >> n;
    cin >> start;
    prev  = start;
    for (int i = 1; i < n+1; i++){
        cin >> now;
        if(i < n) tmp = now - prev;
        else tmp = start + k - now;
        length = max(length,tmp);
        prev = now;
    }
    ans = k - length;
    cout << ans << endl;

}

Measured memory_bytes: 384
#include<bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    ll INF =1e9+7;
    typedef pair<ll,ll> ii;
    #define f(i,a,b) for(long long i = a;i < b;i++)
    #define rf(i,a,b) for(long long i=a;i>=b;i--)
    #define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    #define w(t) while(t--)
    #define c(n); cin>>n;
    #define p(n) cout<<n;
    #define pl(n) cout<<n<<endl;
    #define ps(n); cout<<n<<" ";
    bool isSubSequence(string str1, string str2, int m, int n) {
        int j = 0;
        for (int i=0; i<n&&j<m; i++)
            if(str1[j] == str2[i])
                j++;
        return(j==m);
    }
    int main(void){
        fastio;
        ll n;
        c(n);
        string s;
        c(s);
        set<string>st;
        for(char c1 = '0';c1<='9';c1++){
                for(char c2 = '0';c2<='9';c2++){
                    for(char c3 = '0';c3<='9';c3++){
                            string k="";
                            k+=c1;
                            k+=c2;
                            k+=c3;
                            st.insert(k);
                    }
                }
        }
        int ans=0;
        for(string sd : st){
                if(isSubSequence(sd,s,sd.size(),n)){
                    ans++;
                }
        }
        pl(ans);
    }


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

public class Main {
    public static void main(String[] args) {
        MyScanner sc = new MyScanner();
        PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));
        int n = sc.nextInt(); int x = sc.nextInt(); int t = sc.nextInt();
        out.println((int)Math.ceil((double) n / x) * t);
        out.close();
    }


    //-----------MyScanner class for faster input----------
    public static class MyScanner {
        BufferedReader br;
        StringTokenizer st;

        public MyScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }


    }

}

Measured memory_bytes: 32936
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <cmath>
#include <unordered_map>

#define MaxN 200010

using namespace std;

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

int n;
int fa[MaxN], sz[MaxN];

int main() {
    scanf("%d", &n);
    for (int i = 2; i <= n; ++i) {
        scanf("%d", &fa[i]);
    }

    for (int i = n; i >= 1; --i) {
        sz[fa[i]]++;
    }
    for (int i = 1; i <= n; ++i) {
        printf("%d\n", sz[i]);
    }

    return 0;
}

Measured memory_bytes: 5228
#!/usr/bin/env python3
import sys


def contain(N, K, A, m, i):
    for j in range(i, min(i+K, N)):
        if A[j] == m:
            return True
    return False


def solve(N, K, A):
    m = min(A)
    a = 0
    i = 0

    while i < N:
        if A[i] == m:
            i += 1
        else:
            a += 1
            i += K + contain(N, K, A, m, i) - 2
            if i < N:
                A[i] = m
    return a


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))
    K = int(next(tokens))
    A = [int(next(tokens)) for _ in range(N)]
    print(solve(N, K, A))


if __name__ == '__main__':
    main()


Measured memory_bytes: 14068
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define rep1(i,n) for(int i=1; i<=(n); ++i)
#define repi(i,a,b) for(int i=a; i<=(b); ++i)
#define rrep(i,n) for(int i=(n-1); i>=0; --i)
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define pb push_back
#define mp make_pair
#define to_s to_string
#define sz(v) (int)v.size()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )
#define pr(x) cout<<(x)<<'\n'
#define debug(x) cout << #x << ": " << (x) << '\n'
#define yes "Yes"
#define no "No"
using ll = long long;
using namespace std;
typedef pair<int,int> P;
struct aaa{aaa(){ cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);};}aaaaaaa;
int MOD = 1e9 + 7;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return (a*b)/gcd(a,b);}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int A,B,C,D;
int t[150];
int main(){
    cin >> A >> B >> C >> D;
    t[A]++,t[B]--,t[C]++,t[D]--;
    rep(i,101) t[i+1] += t[i];
    int ct = 0;
    rep(i,101) if(t[i] == 2) ++ct;
    pr(ct);
}

Measured memory_bytes: 256
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

void main()
{
    auto N = readln.chomp.to!long;
    long r = long.max;
    for (long i = 1; i^^2 <= N; ++i) {
        if (N%i != 0) continue;
        r = min(r, i-1 + N/i-1);
    }
    writeln(r);
}

Measured memory_bytes: 256
#pragma region Include
#include <bits/stdc++.h>
// #include <algorithm>
// #include <bitset>
// #include <climits>
// #include <cmath>
// #include <iostream>
// #include <iterator>
// #include <map>
// #include <queue>
// #include <sstream>
// #include <stack>
// #include <string>
// #include <unordered_map>
// #include <unordered_set>
// #include <vector>
#pragma endregion

using namespace std;

#pragma region Macros
typedef pair<int, int> pii;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i, n) rep2(i, 0, n)
#define rep2(i, m, n) for (int i = m; i < (n); i++)
#define all(c) (c).begin(), (c).end()
#define newl "\n"
#define out(x) cout << (x) << newl
#define dump(x) \
  cout << "Line " << __LINE__ << " : " << #x << " = " << (x) << newl
template <class T>
using VV = vector<vector<T>>;
#define Uni(v) (v).erase(unique((v).begin(), (v).end()), (v).end());

template <typename T>
ostream& operator<<(ostream& os, vector<T>& vec) {
  os << "[";
  rep(i, vec.size()) os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
  os << "]";
  return os;
}

template <typename T>
ostream& operator<<(ostream& os, vector<vector<T>>& mat) {
  os << "[";
  rep(i, mat.size()) os << mat[i] << (i + 1 == mat.size() ? "" : ",\n ");
  os << "]";
  return os;
}

template <typename T>
istream& operator>>(istream& is, vector<T>& vec) {
  for (T& x : vec) is >> x;
  return is;
}

template <typename V, typename H>
void resize(vector<V>& vec, const H head) {
  vec.resize(head);
}

template <typename V, typename H, typename... T>
void resize(vector<V>& vec, const H& head, const T... tail) {
  vec.resize(head);
  for (auto& v : vec) resize(v, tail...);
}
constexpr double EPS = 1e-10;
const int INF = 0x3f3f3f3f;

string tostring(int i, int digit) {
  auto cur = cout.flags();
  stringstream ss;
  ss << setw(4) << setfill('0') << i;
  string ret = ss.str();
  cout.flags(cur);
  return ret;
}

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

#pragma endregion

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int H, N;
  cin >> H >> N;
  vi A(N);
  cin >> A;
  int sum = 0;
  rep(i, N) { sum += A[i]; }
  if (sum < H) {
    out("No");
  } else {
    out("Yes");
  }
  return 0;
}

Measured memory_bytes: 640
/*input
6 3
1 4 1
*/
#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())
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;
}
int a[maxn];
int main()
{
	IOS;
	int n,t;
	cin>>n>>t;
	REP(i,t) cin>>a[i];
	sort(a,a+t,greater<int>());

	cout<<a[0]-1-min(a[0]-1,n-a[0]);

	return 0;
}


Measured memory_bytes: 256
N, M, C = (int(i) for i in input().split()) 
B = [int(i) for i in input().split()] 

total = 0
for i in range(N):
    AA = [int(i) for i in input().split()] 
    val = C
    for j in range(M):
        val += AA[j] * B[j]
    if val > 0:
        total += 1

print(total)


Measured memory_bytes: 38384
#include<stdio.h>
int main()
{
	int N,K;
	int z = 1;
	scanf("%d",&N);
	scanf("%d",&K);
	for(int i=0;i<N;i++){
		if(z < K) {
		z = z * 2;
		}else{
			z = z + K;
		}
	}
	printf("%d\n", z);
	return 0;
}

Measured memory_bytes: 1732
import java.util.Scanner;
import java.lang.Integer;
import java.lang.StringBuilder;
import java.lang.Math;

public class Main {
  private static int N;
  private static int[] a;

  private static void print() {
    StringBuilder result = new StringBuilder();
    for (int i = 0; i < N; i++) {
      result.append(a[i]);
      result.append(" ");
    }
    System.out.println(result.toString().trim());
  }

  private static void sort() {
    int swapped = 0;
    if (N == 1) {
      print();
      System.out.println(swapped);
      return;
    }

    for (int i = 0; i < N; i++) {
      int minIndex = i;
      for (int j = i; j < N; j++) {
        if (a[j] < a[minIndex]) {
          minIndex = j;
        }
      }
      // swap
      if (minIndex != i) {
        int tmp = a[minIndex];
        a[minIndex] = a[i];
        a[i] = tmp;
        swapped++;
      }
    }
    print();
    System.out.println(swapped);
  }

  public static void main(String[] args) {
    Scanner in = new Scanner(System.in);
    N = in.nextInt();
    a = new int[N];
    for (int i = 0; i < N; i++) {
      a[i] = in.nextInt();
    }

    // sort a.
    sort();
    // a is now sorted.


  }
}

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

int main () {
	long long N;
	cin >> N;
	long long T=0;
	vector <int> V(N);
	vector <int> C(N);
	for (int i = 0; i < N; ++i){
		cin >> V[i];
	}
	for (int x = 0; x < N; ++x){
		cin >> C[x];
	}
	for (int y = 0; y < N; ++y)
	{
		if(V[y]-C[y]>0) {
			T=T+(V[y]-C[y]);
		}
	}

	cout << T;

}

Measured memory_bytes: 256
#include <stdio.h>

int n,A[50];

int solve(int i,int m)
{
	if(m==0)return 1;
	if(i>=n)return 0;
	int res = solve(i+1,m) || solve(i+1,m-A[i]);
	return res;
}

int main()
{
	int q,M,i;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%d",&A[i]);
	}
	scanf("%d",&q);
	for(i=0;i<q;i++)
	{
		scanf("%d",&M);
		if(solve(0,M))printf("yes\n");
		else printf("no\n");
	}

	return 0;
}



Measured memory_bytes: 2108
#include <bits/stdc++.h>
#define int long long
#define pii pair<int,int>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(c) (c).begin(),(c).end()
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define FINF(a) memset(a,0x3f,sizeof(a))
#define POW(n) (1LL<<(n))
#define IN(i,a,b) (a <= i && i <= b)
using namespace std;
template <typename T> inline bool CHMIN(T& a,T b) { if(a>b) { a=b; return 1; } return 0; }
template <typename T> inline bool CHMAX(T& a,T b) { if(a<b) { a=b; return 1; } return 0; }
template <typename T> inline void SORT(T& a) { sort(ALL(a)); }
template <typename T> inline void REV(T& a) { reverse(ALL(a)); }
template <typename T> inline void UNI(T& a) { sort(ALL(a)); a.erase(unique(ALL(a)),a.end()); }
const int MOD = 1000000007;
const int INF = 0x3f3f3f3f3f3f3f3f;
const double EPS = 1e-10;
/* ---------------------------------------------------------------------------------------------------- */

string A,B,C;

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);

  cin >> A >> B >> C;
  cout << (A.back() == B[0] && B.back() == C[0] ? "YES" : "NO") << endl;

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <set>
 
using namespace std;
int main() {
 
    string str;
    int length,i;
    set<char> alphabets;
    
    cin >> str;
 
    length = str.length();
 
    for(i = 0; i<length; i++){
        alphabets.insert(str[i]);
    }
    
    set<char>::iterator it;
 
     for(i = 'a';i <= 'z'; i++) {
        it = alphabets.find(i);
        if(it == alphabets.end()){
            cout << (char)i << endl;
            return 0;
        }
    }
    cout << "None" << endl;
    return 0;
}

Measured memory_bytes: 512
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
  int n; cin >> n;
  int d[100050];
  for(int i=0;i<n;i++) cin >> d[i];
  sort(d,d+n);
  cout << d[n/2]-d[n/2-1] << endl;
  return 0;
}

Measured memory_bytes: 768
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>


using namespace std;
int n,k;
long long num[55];
long long hand[55];
vector<long long> q;


bool cmp(long long a,long long b){
    return a>b;
}


long long solve(int l,int r){
    while(!q.empty())q.clear();
    long long ans=0;
    for(int i=1;i<=l;i++){
        ans+=num[i];
        q.push_back(num[i]);
    }
    for(int i=n;i>=n-r+1;i--){
        ans+=num[i];
        q.push_back(num[i]);
    }
    sort(q.begin(),q.end(),cmp);
    for(int i=0;i<k-r-l;i++){
        if(q.empty()) break;
        ans-=min(q[q.size()-1],(long long ) 0);
        q.pop_back();
    }
    return ans;
}


int main(){
    cin>>n>>k;
    for(int i=1;i<=n;i++){
        cin>>num[i];
    }
    long long maxn=0;
    for(int i=0;i<=k;i++){
        for(int j=0;j+i<=min(n,k);j++){
            maxn=max(solve(i,j),maxn);
        }
    }
    cout<<maxn;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define IOS                                                                    \
  ios::sync_with_stdio(0);                                                     \
  cin.tie(0);                                                                  \
  cout.tie(0)
#define pb push_back
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
using namespace std;
using ll = long long;
using vi = vector<int>;
using pii = pair<ll, ll>;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;
ll bpow(ll b, ll p, ll m = 1000000007LL) {
  ll rt = 1;
  for (; p; p >>= 1, b = b * b % m)
    if (p & 1)
      rt = rt * b % m;
  return rt;
}
int main() {
  IOS;
  long long a, b, c;
  cin >> a >> b >> c;
  if (c - a - b >= 0 && (c - a - b) * (c - a - b) > 4LL * a * b) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;cin>>N;
  vector<int>A(N);for(int i=0;i<N;i++)cin>>A[i];
  
  
  int s=0;
  for(int i=1;i<N;i++)s+=abs(A[i]-A[i-1]);
  s+=abs(A[N-1]);s+=abs(A[0]);
  
  
  for(int i=0;i<N;i++){
    if(i==0)cout<<s-abs(A[1]-A[0])-abs(A[0])+abs(A[1])<<endl;
    else if(i==N-1)cout<<s-abs(A[N-1]-A[N-2])-abs(A[N-1])+abs(A[N-2])<<endl;
    else cout<<s-abs(A[i+1]-A[i])-abs(A[i]-A[i-1])+abs(A[i+1]-A[i-1])<<endl;
  }
}

Measured memory_bytes: 1664
#include<bits/stdc++.h>
#define ll         long long
#define fl(i,n)    for(i=0;i<n;i++)
#define fld(i,a,b) for(i=a;i>b;i--)
#define fli(i,a,n) for(i=a;i<n;i++)
#define pb         push_back
#define mp         make_pair
#define F          first 
#define S          second
#define mod        1000000007
#define all(x)     x.begin(),x.end()    
#define speedup    ios_base::sync_with_stdio(false),cin.tie(0)
using namespace std;
void comp() {
	ll i,j,k,n,m;
	cin>>n>>m;
	cout<<n*m;
}

int main() {
    speedup;
    ll i=0,t;
    t=1;
    //cin>>t;
    while(t--) {
        comp();
    }
    return 0;
}

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

int main(){
    ll n,k,cnt=1,sum=0;
    cin>>n;
    if(n%2==1){
        cout<<0;
        return 0;
    }
    n/=10;
    while(n>0){
        k=n%5;
        sum+=k*cnt;
        cnt=cnt*5+1;
        n/=5;
    }
    cout<<sum;
}

Measured memory_bytes: 3632
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <random>
#include <cmath>
#include <chrono>
#include <cstring>
#include <algorithm>
#include <string>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cassert>
using namespace std;
using LL = long long;
#define eps 1e-8
#define fi first
#define se second
#define eb emplace_back
#define close std::ios::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr)
#define FOR(i, x, y) for (LL i = (x), _##i = (y); i < _##i; ++i)
#define FORD(i, x, y) for (LL i = (x), _##i = (y); i > _##i; --i)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define CASET int ___T; scanf("%d", &___T); for(int __CS=1;__CS<=___T;__CS++)
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
mt19937 dlsrand(random_device{}());
mt19937 mrand(std::chrono::system_clock::now().time_since_epoch().count()); 
int rnd(int x) { return mrand() % x;}
LL bin(LL x, LL n, LL MOD) {LL ret = MOD != 1;for (x %= MOD; n; n >>= 1, x = x * x % MOD)if (n & 1) ret = ret * x % MOD;return ret;}
inline LL get_inv(LL x, LL p) { return bin(x, p - 2, p); }
const double PI = acos(-1.0);
constexpr int maxn = 17;
constexpr int INF = 0x3f3f3f3f;
constexpr ll linf = 0x3f3f3f3f3f3f3f3f;
constexpr int mod = 1e9+7;
void add(int &a,int b) {a+=b; if(a>=mod) a-=mod;}
void dec(int &a,int b) {a-=b; if(a<0) a+=mod;}
int  a[maxn][maxn], n;
ll dp[1 << maxn], s[ 1<< maxn];
int main()
{
    cin >> n ;
    for(int i = 0; i < n ; i++){
        for(int j = 0; j < n ; j++){
            cin >> a[i][j];
        }
    }
    int end = 1 << n;
    for(int t = 0; t < end ; t++){
        ll cnt  = __builtin_popcount(t);
        vector<int > v;
        for(int i = 0; i < n; i++){
            if((t>>i) & 1)v.eb(i);
        }
        ll zz = 0ll;
        for(int i = 0; i < cnt ; i++){
            for(int j = i+1; j < cnt ; j++){
                zz += a[v[i]][v[j]];
            }
        }
        dp[t] = s[t] = zz;
    }
    for(int i = 0; i < end; i++){
        for(int j = i; j ; j=(j-1) & i){
            dp[i] = max(dp[i], dp[i^j] + s[j]);
        }
    }
    cout << dp[end - 1];
}


Measured memory_bytes: 1280
import collections
n = int(input())
a_list = list(map(int, input().split()))

plus_list = []
minus_list = []
for a in a_list:
    plus_list.append(a+1)
    minus_list.append(a-1)

a_list.extend(plus_list)
a_list.extend(minus_list)

c = collections.Counter(a_list)
print(c.most_common()[0][1])

Measured memory_bytes: 31708