akhauriyash/Code-Regression huggingface dataset:
#include <iostream> 
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<iomanip>
#include<sstream>
#include<cmath>
#include<bitset>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define req(i,n) for(long long int i = 1;i <=  n; i++)
#define rrep(i,n) for(int i = n -1;i >= 0;i--)
typedef long long int ll;
typedef long double ld;
const ll INF = (1 << 31);
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T & val) {
    std::fill((T*)array, (T*)(array + N), val);
}
int n, ans = 0; string s,t="810";
vector<char> c = { '0','1','2','3','4','5','6','7','8','9' };
int main() {
    int h, w; cin >> h >> w >> n;
    vector<int> a(n);
    vector<vector<int>> f(h, vector<int>(w)), b(h, vector<int>(w));
    rep(i, n) cin >> a[i];
    int id = 1;
    rep(i, h) {
        if (i % 2 == 0) {
            rep(j, w) {
                if (a[id - 1] > 0) {
                    f[i][j] = id;
                    a[id - 1]--;
                }
                if (a[id - 1] == 0) id++;
            }
        }
        else {
            rep(j, w) {
                if (a[id - 1] > 0) {
                    b[i][j] = id;
                    a[id - 1]--;
                }
                if (a[id - 1] == 0) id++;
            }
        }
    }
    rep(i, h) {
        if (i % 2 == 0) {
            rep(j, w) {
                cout << f[i][j] << " ";
            }cout << endl;
        }
        else {
            rrep(j, w) {
                cout << b[i][j] << " ";
            }cout << endl;
        }
    }
}

Measured memory_bytes: 384
import Control.Monad.State

main = do
    inputs <- getLine >> getInts
    putStrLn . show $ evalState div2 (inputs, 0)
div2 :: State ([Int], Int) Int
div2 = do
    (arr, cnt)<- get
    if all (\x -> mod x 2 == 0) arr 
    then modify(\_ -> (map (\x -> div x 2)arr,cnt+1)) >> div2
    else return cnt

getInts = map read . words <$> getLine


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

int main(){
    ll s;
    cin >> s;
    ll x0=0,y0=0;
    ll x1=1e9,y1=1;
    ll x2,y2;
    y2 = s/x1 + 1;
    if(y2==1e9+1) y2--;
    x2 =x1*y2-s;
    printf("%d %d %d %d %d %d\n",x0,y0,x1,y1,x2,y2);
    return 0;
}

Measured memory_bytes: 256
def checks(a):
  if a=="C" or a=="T" or a=="G"or a=="A":
    return True
  else:
    return False
s=str(input())
cnt=0
ans=0
for a in s:
  if checks(a):
    cnt+=1
    ans=max(cnt, ans)
  else:
    cnt=0
print(ans)

Measured memory_bytes: 2940
#include<bits/stdc++.h>
/*#include<iostream>
#include<stdio.h>
#include<ctype.h>
#include<string.h>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<climits>*/
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define rep1(i,a,b) for(int i=a;i<=(b);++i)
#define per(i,a,b) for(int i=a;i>(b);--i)
#define per1(i,a,b) for(int i=a;i>=(b);--i)
#define LL long long
#define inf 0x7f7f7f7f
#define N 35
using namespace std;

int main()
{
	stack<int> S;
	int a,b;
	string s;
	
	while(cin>>s)
	{
		if(s[0]=='+')
		{
			a=S.top(); S.pop();
			b=S.top(); S.pop();
			S.push(a+b);	
		}
		else if(s[0]=='-')
		{
			b=S.top(); S.pop();
			a=S.top(); S.pop();
			S.push(a-b);
		}
		else if(s[0]=='*')
		{
			a=S.top(); S.pop();
			b=S.top(); S.pop();
			S.push(a*b);
		}
		else
		{
			S.push(atoi(s.c_str()));
		}
	}
	
	cout<<S.top()<<endl;
}



Measured memory_bytes: 3172
from collections import defaultdict

mod = 10 ** 9 + 7

n = int(input())
s = input()

d = defaultdict(int)

ans = 0
for c in s:
    d[c] += 1
    t = 1
    for chr_, cnt in d.items():
        if chr_ == c:
            continue
        t *= cnt + 1
    ans = (ans + t) % mod
print(ans)


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

int main()
{
  bool prime[1000000];
  long long int ans[20000];
  ans[0]=0;
  int c=1;
  for(int i=0;i<1000000;i++)
    prime[i]=true;
  for(int i=2;i<1000000;i++)
    {
      if(prime[i])
	{
	  if(c<20000)
	    ans[c]=ans[c-1]+i;
	  c++;
	  for(int j=i+i;j<1000000;j+=i)
	    prime[j]=false;
	}
    }
  int n;
  for(;cin>>n,n;)
    {
      cout<<ans[n]<<endl;
    }
}

Measured memory_bytes: 2288
#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;
const double EPS = 1e-7;
const double INF = 1e12;
struct Vec {
    double x,y;
    Vec(){}
    Vec(double x,double y){ this->x=x,this->y=y; }
    void read(){ scanf("%lf%lf",&x,&y); }
    void prt() {printf("%.9f %.9f\n",x,y); }
    double len(){ return sqrt(x*x+y*y); }
    double len2(){ return x*x+y*y; }
    
    Vec operator+(const Vec&o)const{ return Vec(x+o.x,y+o.y); }
    Vec operator-(const Vec&o)const{ return Vec(x-o.x,y-o.y); }
    Vec operator*(const double&k)const{ return Vec(k*x,k*y); }
    double operator*(const Vec&o)const {return x*o.x+y*o.y; }
    double operator^(const Vec&o)const {return x*o.y-y*o.x; }
    Vec rotate(double ang){ return Vec(x*cos(ang)-y*sin(ang), x*sin(ang)+y*cos(ang)); }
    Vec change(double l){ if(len()<EPS) return *this; return (*this)*(l/len()); }
    double disToLine(Vec A, Vec B) {
        return abs((A-*this)^(B-*this))/(B-A).len();
    }
};

Vec Lineintersect(Vec A1,Vec A2,Vec B1,Vec B2) {
    if (abs((A2-A1)^(B2-B1)) < EPS) return Vec(INF,INF);
    return A1 + (A2 - A1) * ((abs((A2-A1)^(B2-B1)) - abs((A2-B1)^(B2-B1)) ) / abs((A2-A1)^(B2-B1)));
}

Vec Segintersect(Vec A1,Vec A2,Vec B1,Vec B2) {
    Vec P = Lineintersect(A1,A2,B1,B2);
    if ((P-A1)*(P-A2)<=0 && (P-B1)*(P-B2)<=0) return P; 
    return Vec(INF,INF);
}

Vec p1,p2;
int main(){
    p1.read(); p2.read();
    int q; scanf("%d",&q);
    while(q--){
        Vec p; p.read();
        double dis = p.disToLine(p1,p2);
        int sgn = ((p2-p1)^(p-p1))>=0?-1:+1;
        //(p2-p1).rotate(acos(-1)/2).prt();
        p=p+(p2-p1).rotate(acos(-1)/2).change(dis*2)*sgn;
        p.prt();
    }
}


Measured memory_bytes: 3244
#include<bits/stdc++.h>
using namespace std;
int main(){
	int a,b,c,d;scanf("%d%d%d%d",&a,&b,&c,&d);
	printf("%lld",max(1ll*b*c,max(1ll*b*d,max(1ll*a*c,1ll*a*d))));
	return 0;
}

Measured memory_bytes: 3824
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)

using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int INF = 100000000;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
int main(){
  int n,a,b;
  cin >> n >> a >>b;
  int allsum=0;
  for(int i=0;i<=n;i++){
    int sum=0;
    int m=i;
    rep(j,5){
      int n=m%10;
      m/=10;
      sum+=n;
    }
    if(sum>=a && sum<=b) allsum+=i;
  }
  cout << allsum << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;

#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, n) for(ll i = 1; i < n + 1; i++)
#define PI 3.14159265359
#define EPS 0.0000000001
#define MOD 1000000007
//cout << std::fixed << std::setprecision(15) << y << endl;


int main(){
    ll N;
    cin >> N;

    ll ans = 0;
    ll p[N + 1];
    cin >> p[1];
    REP(i, N - 1){
        cin >> p[i + 1];
        if(p[i] == i){
            if(p[i + 1] == i + 1 || i == 1){
                swap(p[i], p[i + 1]);
                ans++;
            }else{
                swap(p[i], p[i - 1]);
                ans++;
            }
        }
    }
    if(p[N] == N){
        swap(p[N], p[N - 1]);
        ans++;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 4304
from collections import deque

s = list(input())
q = int(input())

mae = deque()
usi = deque()
k = 0
m = 0
for i in range(q):
    a = input().split()
    if(a[0] == '1'):
        k += 1
    if(a[0] == '2'):
        if(k %2 == 0):
            if(a[1] == '1'):
                mae.appendleft(a[2])
            else:
                usi.append(a[2])
        else:
            if(a[1] == '1'):
                usi.append(a[2])
            else:
                mae.appendleft(a[2])
mae = list(mae)
usi = list(usi)

if(k % 2 == 1):
    mae = mae[::-1]
    usi=usi[::-1]
    s = s[::-1]
    s = ''.join(usi+s+mae)
else:
    s = ''.join(mae+s+usi)
print(s)




Measured memory_bytes: 11812
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 1e9+5;
const ll INFLL = 1e18l+5;

vector<int> dp(100001,0);
vector<int> indeg(100001,0);
vector<bool> vis(100001,0);
vector<int> g[100001];

void dfs(int a){
    if(vis[a]==true) return;
    vis[a]=true;
    for(int i : g[a]){
        dp[i]=max(dp[i],dp[a]+1);
        --indeg[i];
        if(indeg[i]==0) dfs(i);
    }
    
}
    

int main(){
    int v,e;
    cin>>v>>e;
    while(e--){
        int a,b;
        cin>>a>>b;
        g[a].push_back(b);
        indeg[b]++;
    }
    
    for(int i=1; i<=v; ++i){
        if(!vis[i]&&indeg[i]==0) dfs(i);
    }

    cout<<*max_element(dp.begin(),dp.end());
}

Measured memory_bytes: 14248
n = int(raw_input())
taro = 0
hanako = 0

for i in range(n):
    S = (raw_input()).split(" ")
    if (S[0] > S[1]):
        taro += 3
    elif (S[0] == S[1]):
        hanako += 1
        taro += 1
    else:
        hanako += 3

print str(taro) + " " + str(hanako)

Measured memory_bytes: 6416
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<vector>
#include<list>
#include<map>
#include<set>
#include<string>
#include<stack>
#include<queue>
#define null NULL
///delta不能初始化为0，因为这里所有的是值要更新为delta，delta=0的时候也要更新
///此处和RAQ有差别，需要注意一个data取不到的数据，不用下传的标志
#define maxn -1
#define inf (1<<31)-1
using namespace std;
/** 区间表示：[p->dl,p->dr]
 *  从0开始计数，[0,n-1]
 *  线段树RSQ
 *
 */

struct Node
{
    long long dl,dr,s,delta;
    Node *pl,*pr;
};
int n,q;

void build(Node *&p,int l,int r)
{
    p=(Node *)malloc(sizeof(Node));
    p->dl=l,p->dr=r,p->s=inf,p->delta=maxn;
    p->pl=null,p->pr=null;
    int mid=(l+r)/2;
    if(r>l)
    {
        build(p->pl,l,mid);
        build(p->pr,mid+1,r);
    }
}

void preorder(Node *p)
{
    if(p!=null)
    {
        printf("%lld %lld %lld %lld\n",p->dl,p->dr,p->s,p->delta);
        preorder(p->pl);
        preorder(p->pr);
    }
}
///在其他节点更新和查询的过程中都要向下延迟修改
void pushdown(Node *&p,int delta)
{
    p->pl->s = p->delta;
    p->pr->s = p->delta;
    p->pl->delta = p->delta;
    p->pr->delta = p->delta;
    ///注意delta的值，maxn表示不用下传
    p->delta=maxn;
}
///当前区间的更新只更新到某些节点，下边节点的更新需要下次延迟修改
void update(Node *&p,int l,int r,int data)
{
    ///[l,r]必然位于[p->dl,p->dr]子区间
    ///当前节点的所有数据都是正确的！！
    ///延迟修改-lazy-tag技术
    ///此处下行的是之前的数据
    if(p->delta!=maxn && p->dr>p->dl)
        pushdown(p,p->delta);

    if(p->dl==l && p->dr==r)
    {
        p->s=data;
        p->delta=data;
        return ;
    }
    int mid=(p->dl+p->dr)/2;
    if(r<=mid)
        update(p->pl,l,r,data);
    else if(l>mid)
        update(p->pr,l,r,data);
    else
        update(p->pl,l,mid,data),update(p->pr,mid+1,r,data);
    p->s=min(p->pl->s,p->pr->s);
}
///当前节点的所有数据都是正确的！！
///即使不正确，在进入到这个之前也被pushdown过了,，所以一定是正确的
long long query(Node *&p,int l,int r)
{
    ///一个查询区间最终必然被分成若干个小的区间和，最后一个定会完全和区间贴合
    if(p->delta!=maxn && p->dr>p->dl)
        pushdown(p,p->delta);

    if(p->dl==l &&p->dr==r)
        return p->s;
    int mid=(p->dl+p->dr)/2;
    ///判断查询区间与当前区间的位置关系
    //全部位于左侧
    if(r<=mid)
        return query(p->pl,l,r);
    //全部位于右侧
    else if(l>mid)
        return query(p->pr,l,r);
    //两个都有
    else
        return min(query(p->pl,l,mid),query(p->pr,mid+1,r));
}

int main()
{
    int i,type,tx,ty,x;
    Node *tree=null;
    scanf("%d%d",&n,&q);
    build(tree,0,n-1);
    for(i=0;i<q;i++)
    {
        scanf("%d",&type);
        if(type==0)
        {
            scanf("%d%d%d",&tx,&ty,&x);
            update(tree,tx,ty,x);
        }else
        {
            scanf("%d",&tx);
            long long ans=query(tree,tx,tx);
            printf("%lld\n",ans);
        }
    }
    return 0;
}



Measured memory_bytes: 15728
def gcd(a, b):
    if b == 0: return a
    return gcd(b, a % b)


N, K = map(int, input().split())
a = list(map(int, input().split()))

g = a[0]
for aa in a:
    g = gcd(g, aa)

d = (max(a) - K)
if d >= 0:
    if d % g == 0:
        print('POSSIBLE')
    else:
        print('IMPOSSIBLE')
else:
    print('IMPOSSIBLE')


Measured memory_bytes: 14252
S = input()
K = int(input())

curr = S[0]
tmp = ""
T = []
for s in S:
    if s == curr:
        tmp += s
    else:
        T.append(tmp)
        curr = s
        tmp = s
T.append(tmp)

if len(T) == 1:
    res = (len(S) * K) // 2
    print(res)
    exit(0)

res = 0
t_first = T[0]
t_last = T[-1]

if t_first[0] != t_last[0]:
    res += (len(t_first) // 2) * K
    res += (len(t_last) // 2) * K
else:
    res += len(t_first) // 2
    res += len(t_last) // 2
    res += (len(t_first + t_last) // 2) * (K - 1)

for t in T[1:-1]:
    res += (len(t) // 2) * K

print(res)


Measured memory_bytes: 38384
#include <stdio.h>

int main(void)
{
	int x,y=0;
	char s[5];
	scanf("%s",s);
	for(x=0;x<4;x++)
	{
		if(s[x] == '+') y++;
		else y--;
	}
	printf("%d",y);
	return 0;
}

Measured memory_bytes: 128
/* Author : Aaryan Srivastava ^__^ */ 
#include <bits/stdc++.h>
#include <random>
#include <chrono>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
#define pb push_back
#define popb pop_back
#define mt make_tuple 
#define eb emplace_back
#define mp make_pair
#define ff first
#define ss second 
#define ull unsigned long long  
#define pii pair<int, int>
#define piii pair<int,pii>
#define beg begin
#define rep(i,n) for(int (i) = 0 ; i < (n) ; i++)
#define repA(i,x,y) for(int i = (x) ; i <= (y) ; i++)
#define repD(i,x,y) for(int i = (x) ; i >= (y) ; i--)
#define all(c) (c).begin(),(c).end()
#define fill(a,val) memset(a,val,sizeof(a))
#define Randomize mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define int ll
using ll = long long;
const int N = 3*1e5 +5 ;
const int mod = 1e9 + 7 ;
const int inf = 1e18 ;
const int SZ = 101 ;
const double eps = 1e-9 ;
using namespace __gnu_pbds;
using namespace std;
using ordered_set =  tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ;

#ifdef AaryanS
#define mycout cout
#define mycerr cerr 
#endif

#ifndef AaryanS
#define mycout if(false) cout
#define mycerr if(false) cerr
#endif


void solve()
{
	int k ;
	cin >>k ;
	for(int i = 1; i <= k ; ++i){
		if(k%i) continue ;
		if(max(i, k/i) <= 9){
			cout << "Yes\n";
			return ;
		}
	}
	cout << "No\n";
}   

     
int32_t main(int32_t argc, char *argv[])
{
    double t1 = clock() ;
    ios::sync_with_stdio(0);    
    cin.tie(0); cout.tie(0);
    int TC = 1, t = 0;
    //cin >> TC ;
    while(t++ < TC)
    {
        //cout << "Case #" << t << ": " ;
        solve();
        //cout << endl ;
    }
    mycerr << "Time : " << 1000 *(clock() - t1)/CLOCKS_PER_SEC << " ms\n" ;
    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
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; }

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n;
	cin >> n;
	ll ans = n*(n-1)/2;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#define MAX 100005
#define NIL -1
struct Node_struct{int p, l, r;}; /*p: 親(parent), l: 一番左の子(left child), r:右の兄弟(right sibling)*/
typedef struct Node_struct Node;
Node T[MAX];
int D[MAX];

void print(int u){
  int i, c;
  printf("node %d: parent = %d, depth = %d, ", u, T[u].p, D[u]);

  if(T[u].p == NIL/*ここを埋める (fill this blank)*/) printf("root, ");
  else if(T[u].l == NIL/*ここを埋める(fill this blank)*/) printf("leaf, ");
  else printf("internal node, ");
  
  printf("[");
  for (i=0, c = T[u].l; c != NIL; i++, c = T[c].r){
    if(i) printf(", ");
    printf("%d", c);
  }
  printf("]\n");
  
}

void calcDepth(int u, int p){
  D[u] = p;
  if(T[u].r!=NIL/*ここを埋める(fill this blank)*/) calcDepth(T[u].r,p/*ここを埋める(fill this blank)*/);
  if(T[u].l!=NIL/*ここを埋める(fill this blank)*/) calcDepth(T[u].l,p+1/*ここを埋める(fill this blank)*/);
}

int main(){
  int i, j, k;
  int n;
  int id, sib, child;
  int root = NIL;
  scanf("%d", &n);
  for(i=0; i<n; i++) T[i].p = T[i].l = T[i].r = NIL;
  
  for(i=0; i<n; i++){
    scanf("%d %d", &id, &k);
    for(j = 0, sib = NIL; j<k; j++){ //子を入力する (input children)
      scanf("%d", &child);
      T[child].p = id;
      if(j == 0) T[id].l = child; //idの一番左の子 (the most left child of id)
      else T[sib].r = child; //左の兄弟に繋げる (connect to left sibling)
      sib = child;//次の子供の左の兄弟 (the left sibling of the next child)
    }
  }

  //根を求める (find the root)
  for(i=0; i<n; i++){
    if(T[i].p == -1) root = i;
  }
  
  //それぞれのノードの深さを求める (find depth of each node)
  calcDepth(root, 0);

  //出力 (output)
  for(i=0; i<n; i++) print(i);
  
  return 0;
}



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

#define ll long long
#define pb push_back
#define mk make_pair
#define fr first
#define sc second
#define vi vector < int >
#define pi pair < int, int >

const int M = 1007;
const int N = 13;
const int mod = 1e9 + 7;

ll dp[1 << N];
int n, m;

ll rec (int sub1, int sub2, int mask){
    if (!mask) {
        return dp[sub1] + dp[sub2];
    }
    int bit = mask & -mask;
    mask = mask ^ bit;
    return min(rec(sub1 | bit, sub2 | bit, mask), min(rec(sub1 | bit, sub2, mask), rec(sub1, sub2 | bit, mask)));
}

main(){
    cin >> n >> m;
    memset(dp, 0x3f3f3f3f, sizeof(dp));
    dp[0] = 0;
    for (int i = 1; i <= m; i++){
        int a, b, c;
        scanf("%d%d", &a, &b);
        int mask = 0;
        for (int j = 1; j <= b; j++){
            scanf("%d", &c);
            mask = mask | (1 << (c - 1));
        }
        dp[mask] = min(dp[mask], a * 1LL);
    }
    for (int i = 1; i <= (1 << n) - 1; i++){
        dp[i] = min(rec(0, 0, i), dp[i]);
    }
    if (dp[(1 << n) - 1] > (ll) 1e7 + 7)
        puts("-1");
    else
        cout << dp[(1 << n) - 1];
}


Measured memory_bytes: 256
local n,m=io.read("n","n")
local sum=0
local a={}
for i=1,n do
    input=io.read("n")
    a[i]=input
    sum=sum+input
end
table.sort(a)

local counter=m
for i=n,1,-1 do
    if a[i]>=sum/(4*m) then
        counter=counter-1
    end
end
print(counter<=0 and "Yes" or "No")

Measured memory_bytes: 2632
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <vector>
#include <utility>
#define maxn 100005
#define mod 1000000007
using namespace std;
typedef long long ll;
char s[maxn];
ll suma[maxn],sumb[maxn],sumc[maxn],sumq[maxn];
ll abc,abq,aqc,qbc,aqq,qbq,qqc,qqq,q;
ll modpow(ll x,ll y){
	if(y < 0) return 0;
	ll res = 1;
	while(y){
		if(y & 1) res = res * x % mod;
		y >>= 1;
		x = x * x % mod;
	}
	return res;
}
int main(){
	scanf("%s",s + 1);
	int n = strlen(s+1);
	for(int i=1;i<=n;i++){
		suma[i] = suma[i-1];
		if(s[i] == 'A') suma[i]++;
		sumb[i] = sumb[i-1];
		if(s[i] == 'B') sumb[i]++;
		sumc[i] = sumc[i-1];
		if(s[i] == 'C') sumc[i]++;
		sumq[i] = sumq[i-1];
		if(s[i] == '?') sumq[i]++;
	}
	for(int i=1;i<=n;i++){
		if(s[i] == 'B'){
			abc = (abc + suma[i-1] * (sumc[n] - sumc[i])) % mod;
			abq = (abq + suma[i-1] * (sumq[n] - sumq[i])) % mod;
			qbc = (qbc + sumq[i-1] * (sumc[n] - sumc[i])) % mod;
			qbq = (qbq + sumq[i-1] * (sumq[n] - sumq[i])) % mod;
		}else if(s[i] == '?'){
			q++;
			aqc = (aqc + suma[i-1] * (sumc[n] - sumc[i])) % mod;
			aqq = (aqq + suma[i-1] * (sumq[n] - sumq[i])) % mod;
			qqc = (qqc + sumq[i-1] * (sumc[n] - sumc[i])) % mod;
			qqq = (qqq + sumq[i-1] * (sumq[n] - sumq[i])) % mod;
		}
	}
	ll ans = modpow(3,q) * abc % mod;
	ans += (abq + aqc + qbc) * modpow(3,q-1) % mod;
	ans += (aqq + qbq + qqc) * modpow(3,q-2) % mod;
	ans += qqq * modpow(3,q-3) % mod;
	ans %= mod;
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 3584
#include<iostream>
#include<string>
#include<typeinfo>
#include<vector>
#include<algorithm>
#include<map>
#include<iomanip>
typedef long long int ll;
using namespace std;
int main()
{
	int a,b;
	cin >> a >> b;
	string s;
	cin >> s;
	int ans=1;
	for(int i=0; i<s.size(); i++){
		if(i==a){
			if(s.at(i) != '-'){
				ans = 0;
			}
		}else{
			if(s.at(i) < '0' || s.at(i) > '9' ){
				ans = 0;
			}
		}
	}
	if(ans){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}
	return 0;
}

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

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

    int a_min = 1000000;
    int b_min = 1000000;
    int a_pri[a];
    int b_pri[b];
    for(int i = 0; i < a; i++){
        cin >> a_pri[i];
        if(a_min > a_pri[i]){
            a_min = a_pri[i];
        }
    }
    for(int i = 0; i < b; i++){
        cin >> b_pri[i];
        if(b_min > b_pri[i]){
            b_min = b_pri[i];
        }
    }

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

    int ans = a_min + b_min;
    for(int i = 0; i < m; i++){
        int k = a_pri[x[i] - 1] + b_pri[y[i] - 1] - c[i];
        if(k < ans){
            ans = k;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 2176
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL, LL> P;

int main(){
    int a, b;
    cin >> a >> b;
    if(a > 9 || b > 9)  cout << -1 << endl;
    else    cout << (a*b) << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n;
int v[20],c[20],ans;
int main()
{
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>v[i];
	}
	for(int i=0;i<n;i++)
	{
		cin>>c[i];
	}
	for(int i=0;i<n;i++)
	{
		if(v[i]>c[i])
		  ans+=v[i]-c[i];
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <limits>
#include <climits>
#include <utility>
#include <algorithm>
#include <numeric>

using namespace std;

using ll = long long;
using ull = unsigned long long;

int main()
{
    int A, B;
    cin >> A >> B;

    string S;
    cin >> S;

    if (S[A] != '-') {
        cout << "No" << endl;
        return 0;
    }

    for (int i = 0; i < S.size(); ++i) {
        if (i == A) {
            continue;
        }

        int x = S[i] - '0';
        if (x < 0 || 9 < x) {
            cout << "No" << endl;
            return 0;
        }
    }

    cout << "Yes" << endl;

    return 0;
}


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

int main()
{
    ios::sync_with_stdio(false);
    int a[3];
    cin>>a[0]>>a[1]>>a[2];
    sort(a,a+3);
    int x=0;
    if(a[0]==a[1])x++;
    if(a[1]==a[2])x++;
    if(x==1)cout<<"Yes";
    else cout<<"No";
    return 0;
}


Measured memory_bytes: 256
import java.util.*;

class Main{
public static void main(String[] args){
	Scanner sc = new Scanner(System.in);
	int a = sc.nextInt();
	int b = sc.nextInt();
	int c = sc.nextInt();
	int d = sc.nextInt();
	if(a >= c) {
		if(a >= d) {
			System.out.println(0);
		} else if(a <= d && b >= d) {
			System.out.println(d - a);
		} else if(b <= d) {
			System.out.println(b - a);
		}
	} else {
		if(c >= b) {
			System.out.println(0);
		} else if(c <= b && b <= d) {
			System.out.println(b- c);
		} else if(b >= d) {
			System.out.println(d - c);
		}
	}
}
}


Measured memory_bytes: 23764
using System;
using System.Threading.Tasks;
using static System.Console;
using static System.Math;

class program{
  static void Main(string[] args){
    program p= new program();
      p.Run();
  }
  void Run(){
    int n= int.Parse(ReadLine());
    string[] inp= new string[2];
    string[] tmp=new string[n];
    string s="";
    int k=0;
    for(int i=0;i<n;i++){
      inp=ReadLine().Split();
      tmp[i]=exc1(inp[0],int.Parse(inp[1]),i+1);
    }
    Array.Sort(tmp);
    for(int j=0;j<n;j++){
      WriteLine(tmp[j].Remove(0,tmp[j].LastIndexOf("!")+1));
    }
  }
  
  string exc1(string s, int ind,int k){
    string tm =s;
    while(tm.Length<10){
      tm+="!";
    }
    int t=100-ind;
    string g=t.ToString();
    while(g.Length<3){
      g="!"+g;
    }
    tm+=g+"!"+k.ToString();
    return tm;
  }
  int[] Readint(){
    string[] inp= ReadLine().Split();
    int n=inp.Length;
    int[] res=new int[n];
    for(int i=0;i<n;i++){
      res[i]=int.Parse(inp[i]);
    }
    return res;
  }
}

Measured memory_bytes: 11360
#include<iostream>
#include<cmath>
#include<vector>
#include<algorithm>

using namespace std;

int isPrime(int num) {
  if(num < 2) {
    return 0;
  }
  for(int i=2; i<=sqrt(num); i++) {
    if(num%i == 0) {
      return 0;
    }
  }
  return 1;
}

int main() {
  int n, p;
  while(cin>>n>>p && (n!=-1 && p!=-1)) {
    vector<int> ansVec;
    vector<int> primeVec;
    for(int i=n+1; primeVec.size()<100; i++) {
      if(isPrime(i)) {
	primeVec.push_back(i);
	//cout<<i<<" ";
      }
    }
    while(ansVec.size() < p) {
      for(int i=0; i<100; i++) {
	for(int j=i; j<100; j++) {
	  ansVec.push_back(primeVec[i]+primeVec[j]);
	}
      }
    }
    sort(ansVec.begin(), ansVec.end());
    /*
    cout<<endl;
    for(int i=0; i<5; i++) {
      cout<<ansVec[i]<<" ";
    }
    cout<<endl;
    */
    cout<<ansVec[p-1]<<endl;
  }
}

Measured memory_bytes: 1276
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int top, S[1010];
void push(int x)
{
	S[++top] = x;
}
int pop()
{
	top--;
	return S[top + 1];
}
int main(void)
{
	int a, b;
	top = 0;
	char ch[100];

	while (scanf("%s", ch) != EOF)
	{
		/*if (ch == ' ' || ch == '\n')
			continue;*/
		if (ch[0] == '+')
		{
			a = pop();
			b = pop();
			push(a + b);
		}
		else if (ch[0] == '-')
		{
			a = pop();
			b = pop();
			push(b - a);
		}
		else if (ch[0] == '*')
		{
			a = pop();
			b = pop();
			push(a*b);
		}
		else if (ch[0] == '/')
		{
			a = pop();
			b = pop();
			push(a / b);
		}
		else
		{
			push(atoi(ch));
		}
	}
	printf("%d\n", pop());
	//system("pause");

	return 0;
}


Measured memory_bytes: 2080
#include<iostream>
using namespace std;
int main()
{
    int n,k;
    cin>>n>>k;
    int a[n];
    for(int i=0;i<n;i++)
    cin>>a[i];
    for(int i=k;i<n;i++)
    {
        if(a[i]>a[i-k])
        cout<<"Yes\n";
        else
        cout<<"No\n";
    }
}

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

#ifdef DEBUG
#define PRINT(x)\
    cout<<"func "<<__func__<<": line "<<__LINE__<<": "<<#x<<" = "<<(x)<<endl;
#define PRINTA(a,first,last)\
    cout<<"func "<<__func__<<": line "<<__LINE__<<": "<<#a<<"["<<(first)<<", "<<(last)<<")"<<endl;\
    for (int _i=(first);_i<(last);++_i){cout<<#a<<"["<<_i<<"] = "<<(a)[_i]<<endl;}
#define PRINTP(p)\
    cout<<"func "<<__func__<<": line "<<__LINE__<<": "<<#p<<" = ("<<(p.first)<<", "<<(p.second)<<")"<<endl;
#define PRINTI(a,i)\
    cout<<"func "<<__func__<<": line "<<__LINE__<<": "<<#a<<"["<<#i<<"] = "<<#a<<"["<<(i)<<"] = "<<(a)[i]<<endl;
#else
#define PRINT(x)
#define PRINTA(a,first,last)
#define PRINTP(p)
#define PRINTI(a,i)
#endif

#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);--i)
#define REP(i,n) for (int i=0;i<(n);++i)
#define RREP(i,n) for (int i=(n)-1;i>=0;--i)
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define MOD 1000000007
//#define MOD 998244353

using namespace std;

using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;

template <class T, class U> void amax(T& x, U y) {if (x < y) x = y;}
template <class T, class U> void amin(T& x, U y) {if (x > y) x = y;}

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

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

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, M, K;
    cin >> N >> M >> K;
    vector<int> A(N), B(M);
    REP(i, N) cin >> A[i];
    REP(i, M) cin >> B[i];
    vector<ll> A_sum(N + 1), B_sum(M + 1);
    REP(i, N) {
        A_sum[i + 1] = A_sum[i] + A[i];
    }
    REP(i, M) {
        B_sum[i + 1] = B_sum[i] + B[i];
    }
    int result = 0;
    REP(i, N + 1) {
        ll t = A_sum[i];
        if (t > K) break;
        PRINT(K - t);
        auto ub = upper_bound(all(B_sum), K - t);
        int num = distance(B_sum.begin(), ub) - 1;
        PRINT(num);
        amax(result, i + num);
    }
    cout << result << endl;
    return 0;
}


Measured memory_bytes: 7948
#include<iostream>
 
using namespace std;
 
int main(){
  int V,E;
  cin>>V>>E;
  int d[15][15];
  for(int i=0;i<V;i++){
    for(int j=0;j<V;j++){
      d[i][j]=-1;
    }
  }
  while(E--){
    int s,t,d_;
    cin>>s>>t>>d_;
    d[s][t]=d_;
  }
  int dp[1<<15][15];
  for(int i=0;i<V-1;i++){
    if(d[V-1][i]>=0){
      dp[1<<i][i]=d[V-1][i];
    }else{
      dp[1<<i][i]=1e9;
    }
  }
  for(int i=0;i<1<<V-1;i++){
    if(!(i&i-1))continue;
    for(int j=0;j<V-1;j++){
      if(!(i>>j&1))continue;
      dp[i][j]=1e9;
      int p=i^1<<j;
      for(int k=0;k<V-1;k++){
    if(!(p>>k&1)||d[k][j]<0)continue;
    dp[i][j]=min(dp[i][j],dp[p][k]+d[k][j]);
      }
    }
  }
  int b=1e9;
  for(int i=0;i<V-1;i++){
    if(d[i][V-1]<0)continue;
    b=min(b,dp[(1<<V-1)-1][i]+d[i][V-1]);
  }
  cout<<(b>1e8?-1:b)<<endl;
}


Measured memory_bytes: 4040
#include<bits/stdc++.h>
 
#define rep(i,n) for(ll i = 0;i < n;++i)
using namespace std;
using ll = long long;
 
const ll M = 1e9+7;// 10^9+7

ll mpow(ll x,ll y){// x^y(mod M)を計算
    ll ans = 1;
    while(y != 0){
        if(y&1){
            ans = ans * x % M;
        }
        x = x * x % M;
        y = y >> 1;
    }
    return ans % M;
}

ll comb(ll n,ll k){// nCk(mod 10^9+7)を計算 : nCk = n! * (k!)^(M-2) * ((n-k)!)^(M-2) (mod M)を使っている
    ll a=1,b=1,c=1;
    if(n == 0 && k == 0) return 1;
    if(n < k|| n < 0) return 0;
    for(ll i = 1;i <= n;++i){// n!を計算
        a = a * i % M;
    }
    for(ll i = 1;i <= k;++i){// k!を計算
        b = b * i % M;
    }
    for(ll i = 1;i <= (n-k);++i){// (n-k)!を計算
        c = c * i % M;
    }
    b = mpow(b,M-2);// (k!)^(M-2)を計算
    c = mpow(c,M-2);// ((n-k)!)^(M-2)を計算
    return a*b%M*c%M;
}


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

    ll x, y;
    cin >> x >> y;
    ll n = (x+y) / 3;
    if((x+y)%3 != 0){ //合計が3の倍数ではなかったら0
        cout << 0 << endl;
        return 0;
    }
    x -= n;
    y -= n;
    if(x < 0 || y < 0) { 
        cout << 0 << endl;
        return 0;
    }
    ll ans = comb(x+y,y)%M;
    cout << ans << endl;

    cout << endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#define MAX 100
int main() {
	int n,i,j,l,r,a,g[MAX][MAX];
	scanf("%d",&n);
	for(i=0;i<n;i++){
		for(j=0;j<n;j++)g[i][j]=0;
	}
	
	for(i=0;i<n;i++){
		scanf("%d %d",&l,&r);
		for(j=0;j<r;j++){
			scanf("%d",&a);
			g[l-1][a-1] = 1;
		}
	}
	for(i=0;i<n;i++){
		for(j=0;j<n;j++){
			if (j > 0) printf(" ");
			printf("%d", g[i][j]);
		}
		printf("\n");
	}
	return 0;
}


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

int main(){
	ll N, K;
	cin >> N >> K;
	vector<ll> H(N);
	for(auto &h : H) cin >> h;
	sort(H.begin(), H.end());
	ll ans = 0;
	for(int i=N-1;i>=0;i--) {
		if(K > 0) {
			K--;
		} else {
			ans += H[i];
		}
	}
	cout << ans << endl;
}

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

using vi = vector<int>;
using vll = vector<long long>;

constexpr long long mod = 1000000007;

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

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

    long long n;
    cin >> n;

    long long ans = 0;
    for (long long i = 1; i <= n; i++){
        if(i%3==0||i%5==0){

        }else{
            ans += i;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll INF = mod * mod;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)

int main()
{
    int N, K; cin >> N >> K;

    int h[100005];
    rep(i, N) cin >> h[i];

    int ans = 0;
    rep(i, N)
    {
        if (h[i] >= K) ans++;
    }

    cout << ans << endl;
}

Measured memory_bytes: 640
#include<iostream>
using namespace std;
#define MAX 2000000

int H, A[MAX+1];

void maxHeapify(int i){
  int l, r, largest;
  l = 2 * i;
  r = 2 * i + 1;

  if (l <= H && A[l] > A[i]) largest = l;
  else largest = i;
  if (r <= H && A[r] > A[largest]) largest = r;

  if (i != largest){
    swap(A[i], A[largest]);
    maxHeapify(largest);
  }

}

int main(){

  cin >> H;
  for (int i=1; i<=H; i++) cin >> A[i];

  for (int i=H; i>=1; i--){
    maxHeapify(i);
  }

  for (int i=1; i<=H; i++){
    cout << " ";
    cout << A[i];
  }
  cout << endl;

  return 0;
}



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

int main() {
  int N;
  cin>>N;
  
  int max_element = N/6+1;
  vector<int> f(N, 0);
  for(int x=1; x<=max_element; x++){
    for(int y=x; y<=max_element; y++){
      for(int z=y; z<=max_element; z++){
        int cal=x*x+y*y+z*z+x*y+y*z+z*x;
        if(cal<=N){
          int plus=3;
          if(x==y && y==z){
            plus=1;
          }
          else if(x!=y && y!=z && z!=x){
            plus=6;
          }
          f.at(cal-1) += plus;
        }
        else{
          break;
        }
      }
    }
  }
  for(int i=0;i<N;i++){
    cout<<f.at(i)<<endl;
  }
}

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

using namespace std;

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

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

using ll = long long;
using vll = V<ll>;

#define FOR(i,a,b) for(ll i=(a);i<(b);i++)

void Solve();

signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<setprecision(20)<<fixed;
  Solve();
}

/****************************************\
| Thank you for viewing my code:)        |
| Written by RedSpica a.k.a. RanseMirage |
| Twitter:@asakaakasaka                  | 
\****************************************/

void Solve(){
  ll n;
    cin>>n;
  vll A(n);
  ll ans=1LL<<60;
  ll all=0;
  FOR(i,0,n){
    cin>>A[i];
    all+=A[i];
    if(i>0){
      A[i]+=A[i-1];
    }
  }

  FOR(i,0,n){
    ll a=abs(2*A[i]-all);
    chmin(ans,a);
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 1792
#include <vector>
#include <math.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <queue>
#include <iomanip>
#include <deque>
#include <cctype>
#include <unordered_map>

using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<long, long>;
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;
#define rep(i, n) for(int i = 0; i<n; i++)
#define rep_s(i, start, n) for(int i= start;  i<n; i++)
#define rep_down(i, n) for(int i = n-1; i>=0; i--)
#define rep_down_s(i, n, start) for(int i = n-1; i>=start; i--)
#define ALL(a) (a).begin(), (a).end()
#define ALL_str(a) (a).cbegin(), (a).cend()

string alphabet_upper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
string alphabet_lower  = "abcdefghijklmnopqrstuvwxyz";
string numbers = "0123456789";
/*
for (iterator = hash.begin(); iterator != hash.end(); iterator++)
{
// ここで、要素毎の操作を行います。
std::pair<std::string, CMyClass> element = *iterator;

}
*/
/*
using edge = struct {int to; ll cost;};
vector<edge> tree[limit];
ll depth[limit];

void dfs(int v, int p, ll d){
  depth[v] = d;
  //cout <<"v: " << v << endl;
  for (auto &e: tree[v]){
    //cout << "e.to: " << e.to << endl;
    if (e.to == p) continue;
    dfs(e.to, v, d+e.cost);
  }
}
*/
int keta_sum(int num){
  int dig, sum = 0;
  while(num){
    dig = num % 10;
    sum = sum + dig;
    num = num / 10;
  }
  return sum;
}

ll binary_search(ll left_key, ll border, ll low, ll high) {
     // 配列 a の左端と右端
    ll mid = (low+high)/2;
    while (high > low+1) {
       mid = (low+high)/2;
        if (left_key*mid>border) high = mid;
        else if (left_key*mid<border) low = mid;
        else {
          mid =mid-1;
          break;
        }
    }
    return mid;
}

bool IsPrime(ll a){
  ll b = sqrt(a);
  b++;
  while(b-->=2){
    if (a%b==0) return false;
  }
  return true;
}

ll gcd(ll a, ll b){
  ll tmp;
  if(a<b){
    tmp = a;
    a = b;
    b = tmp;
  }

  ll r = a % b;
  while(r!=0){
    a = b;
    b = r;
    r = a % b;
  }
  return b;
}

struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

int main(void){
  ll N, M, A, B, C, D, E, F, K,L, W, H, P, Q, R, X, Y;
  ll ans;
  string S, T;
  cin >> N >> K;
  vector<ll> vec_chr;
  ll h[N];
  rep(i, N){
    cin >> h[i];
    vec_chr.push_back(h[i]);
  }
  sort(ALL(vec_chr));
  ll min_ans = 1e+9;
  rep(i, N-K+1) min_ans = min(min_ans, vec_chr[i+K-1]-vec_chr[i]);
  
  cout << min_ans << endl;

}


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

int main(){
  int a,b; cin >> a >> b;
  int ans = 0;
  for(int i = 0; i < max(a,b); i++){
    if(abs(a-i)==abs(b-i)){
      ans = i;
      break;
    }
  }
  if(ans==0) cout << "IMPOSSIBLE" << endl;
  else{
    cout << ans << endl;
  }
}


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


int main() {

	int N;
	cin >> N;
	float* values = new float[N];
	for (int i = 0; i < N; i++) cin >> values[i];

	sort(values, values + N);

	float ans = 0;

	for (int i = 1; i < N; i++) {
		values[i] = (values[i] + values[i - 1]) / 2;
	}

	cout << values[N-1] << endl;

	return 0;
}

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

using namespace std;
typedef long long int ll;
ll a, b, c, d, dap;
int main() {
    
    ll n, i, a[200001];
    string s;
    cin>>n;
    for(i=1;i<=n;i++)
    {
        scanf("%lld", a+i);
    }
    
    sort(a+1, a+(n+1));
    dap=a[n];
    for(i=1;i<(n-1);i++)
    {
        dap+=a[n-(i+1)/2];
    }
    
    
    cout<<dap;
    
    
    return 0;
}

Measured memory_bytes: 5228
#include <iostream>
#include<vector>
using namespace std;
int main(void){
    int n,m;
    cin >> n >> m;
    int ac = 0,wa = 0;
    vector<bool> AC(n);
    vector<int> WA(n,0);
    for(int i = 0;i < m;i++){
        int p;
        string s;
        cin >> p >> s;
        p--;
        
        if(AC[p])continue;
        
        if(s == "AC"){
            ac++;
            AC[p] = true;
            wa += WA[p];
        }else{
            WA[p]++;
        }
    }
    cout << ac << " " << wa << endl;
    return 0;
}


Measured memory_bytes: 640
#[allow(unused_imports)]
use std::cmp;

// Input macro from https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
  (source = $s:expr, $($r:tt)*) => {
    let mut iter = $s.split_whitespace();
    input_inner!{iter, $($r)*}
  };
  ($($r:tt)*) => {
    #[allow(unused_mut)]
    let mut s = {
      use std::io::Read;
      let mut s = String::new();
      std::io::stdin().read_to_string(&mut s).unwrap();
      s
    };
    let mut iter = s.split_whitespace();
    input_inner!{iter, $($r)*}
  };
}

macro_rules! input_inner {
  ($iter:expr) => {};
  ($iter:expr, ) => {};

  ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
    let $var = read_value!($iter, $t);
    input_inner!{$iter $($r)*}
  };
}

macro_rules! read_value {
  ($iter:expr, ( $($t:tt),* )) => {
    ( $(read_value!($iter, $t)),* )
  };

  ($iter:expr, [ $t:tt ; $len:expr ]) => {
    (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
  };

  ($iter:expr, chars) => {
    read_value!($iter, String).chars().collect::<Vec<char>>()
  };

  ($iter:expr, usize1) => {
    read_value!($iter, usize) - 1
  };

  ($iter:expr, $t:ty) => {
    $iter.next().unwrap().parse::<$t>().expect("Parse error")
  };
}

fn main() {
  input!{
    h: usize,
    w: usize,
    fld: [[i32; w]; h]
  }
  let mut fld = fld;
  let mut ops = vec![];
  for i in 0..h {
    if i % 2 == 0 {
      for j in 0..w-1 {
        if fld[i][j] % 2 == 1 {
          fld[i][j+1] += 1;
          ops.push((i, j, i, j+1));
        }
      }
      if i + 1 < h && fld[i][w-1] % 2 == 1 {
        fld[i+1][w-1] += 1;
        ops.push((i, w-1, i+1, w-1));
      }
    } else {
      for j in (1..w).rev() {
        if fld[i][j] % 2 == 1 {
          fld[i][j-1] += 1;
          ops.push((i, j, i, j-1));
        }
      }
      if i + 1 < h && fld[i][0] % 2 == 1 {
        fld[i+1][0] += 1;
        ops.push((i, 0, i+1, 0));
      }
    }
  }
  println!("{}", ops.len());
  for &(a, b, c, d) in &ops {
    println!("{} {} {} {}", a+1, b+1, c+1, d+1);
  }
}


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

using namespace std;

#define int long long
#define all(v) (v).begin(), (v).end()
#define resz(v, ...) (v).clear(), (v).resize(__VA_ARGS__)
#define reps(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep(i, n) reps(i, 0, n)

template<class T1, class T2> void chmin(T1 &a, T2 b){if(a>b)a=b;}
template<class T1, class T2> void chmax(T1 &a, T2 b){if(a<b)a=b;}

using Pi = pair<int, int>;
using Tapris = tuple<int, int, int>;
using vint = vector<int>;

const int inf = 1LL << 55;
const int mod = 1e9 + 7;

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

  int n;
  cin >> n;
  vint a(n);
  rep(i, n) cin >> a[i];
  int ans = 0;
  vint x(n+1), s(n+1);
  rep(i, n) {
    x[i+1] = x[i]^a[i];
    s[i+1] = s[i]+a[i];
  }
  rep(i, n) {
    int lb = -1, ub = i+1;
    while(lb+1 < ub) {
      int mb = (lb+ub)/2;
      if((x[i+1]^x[mb]) == s[i+1]-s[mb]) ub = mb;
      else lb = mb;
    }
    //cout<<i+1<<" "<<lb<<" "<<ub<<endl;
    ans += i+1-ub;
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 4992
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			long a = scanner.nextLong();
			long b = scanner.nextLong();
			scanner.nextLong();
			long k = scanner.nextLong();

			if (k % 2 == 0) {
				System.out.println(a - b);
			} else {
				System.out.println(b - a);
			}
		}
	}
}


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

int main(){
	int H,W;
	cin >> H >> W;
	int h,w;
	cin >> h >> w;

	cout << H*W-h*W-w*H+h*w << endl;

	return 0;
}

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

using namespace std;

long long int N,M,K,L,R,H,W;

const long long int MOD=1000000007;



int main(){
	
	vector<int>v(1000001,1);
	v[0]=0;
	v[1]=0;
	for(int i=2;i<=1000000;i++){
		for(int j=i*2;j<=1000000;j+=i){
			v[j]=0;
		}
	}
	while(cin>>N>>M>>K,N){
		N-=M;
		while(K){
			N+=M;
			K-=v[N];
		}
		cout<<N<<endl;
	}
	return 0;
}


Measured memory_bytes: 6580
#include <iostream>

using namespace std;

typedef long long ll;

int main() {
	int n;
	while ( cin >> n, n ) {
		int dp[50] = {0}; dp[0] = 1;
		for (int i = 0; i < n; ++i) {
			dp[i+1] += dp[i];
			dp[i+2] += dp[i];
			dp[i+3] += dp[i];
		}
		int ans = dp[n] / 3650 + (dp[n] % 3650 ? 1 : 0);
		cout << ans << endl;
	}
}

Measured memory_bytes: 1160
main = do
    [k, _] <- map readAsInt . words <$> getLine
    aList <- map readAsInt . words <$> getLine
    print $ solve k aList

readAsInt :: String -> Int
readAsInt = read

solve :: Int -> [Int] -> Int
solve k aList = 
    let distances = fst $ foldl (\(ds, lastPos) ai -> ((ai - lastPos) : ds, ai ))
                                ([], last aList - k)
                                aList
    in k - maximum distances

Measured memory_bytes: 115068
s = input()
ans = 1
flag = 0
cut = 1

for i in range(1,len(s)):
    if flag == 1:
        flag = 0
        cut = 2
        ans += 1
        continue
    if s[i-1] == s[i] and cut == 1:
        flag = 1
        continue
    else:
        cut = 1
    ans += 1
print(ans)


Measured memory_bytes: 3500
#include<stdio.h>
int main(void){
    int n,m,i;
    int wana[10000],detame[10000];
    int susumu=1;
    int cnt;
    scanf("%d %d",&n,&m);
    while(n!=0 && m!=0){
        cnt=0;
        susumu=1;
        for(i=1;i<=n;i++){
            scanf("%d",&wana[i]);
        }
        for(i=0;i<m;i++){
            scanf("%d",&detame[i]);
        }
        for(i=0;i<m;i++){
            cnt++;
            susumu+=detame[i];
            susumu+=wana[susumu];
            if(susumu>=n){
                printf("%d\n",cnt);
                break;
            }
        }
        scanf("%d %d",&n,&m);
    }
    return 0;
}

Measured memory_bytes: 2732
a, b = map(int, input().split())
x = [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 1]
if x.index(a) > x.index(b):
    print('Alice')
elif x.index(a) < x.index(b):
    print('Bob')
else:
    print('Draw')

Measured memory_bytes: 3060