akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

typedef long long          ll;
typedef unsigned long long ull;
typedef vector<int>	       vi;
typedef vector<bool>       vb;
typedef map<int, int>      mii;
typedef pair<int, int>     ii;

#define INF                0x3f3f3f3f
#define INFLL              0x3f3f3f3f3f3f3f3f
#define each(x, s)         for(auto& x : s)
#define loop(x)	           for(int i = 0;i < x;i++)
#define vloop(v, x)        for(int v = 0;v < x;v++)
#define avg(l, r)          l + (r - l) / 2
#define iter(a)            a.begin(), a.end()
#define riter(a)           a.rbegin(), a.rend()
#define endl               "\n"

const ll mod = 1000000007;

typedef tuple<ll, ll, ll> tup;

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

	int n, m;
	cin >> n >> m;
	vector<vector<ll>> cs(8);
	ll x, y, z;
	loop(n) {
		cin >> x >> y >> z;
		loop(8) {
			cs[i].push_back(x * (i & 4 ? 1 : -1) + y * (i & 2 ? 1 : -1) + z * (i & 1 ? 1 : -1));
		}
	}
	ll ans = 0;
	loop(8) {
		sort(riter(cs[i]));
		ll sum = 0;
		vloop(j, m) sum += cs[i][j];
		ans = max(sum, ans);
	}
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 384
#include <iostream>
#include<map>
using namespace std;
typedef long long ll;
ll n,s[26],d[365][26],t[365],ans,u[26],q,a,b;
int main(void){
    cin>>n;
    for(int i=0;i<26;i++){
        cin>>s[i];
    }
    for(int i=0;i<n;i++){
        for(int j=0;j<26;j++){
            cin>>d[i][j];
        }
    }
    for(int i=0;i<n;i++){cin>>t[i];}
    
    
    
    cin>>q;
    while(q--){
        cin>>a>>b;
        t[a-1]=b;
        ans=0;
        for(int i=0;i<26;i++)u[i]=0;
        for(int i=0;i<n;i++){
            ans+=d[i][t[i]-1];
            u[t[i]-1]=i+1;
            for(int j=0;j<26;j++){
                ans-=s[j]*(i+1-u[j]);
            }
        }
        cout<<ans<<endl;
    }
}


Measured memory_bytes: 3704
#include <stdio.h>
#include <stdlib.h>
#include <iostream>

using namespace std;
#define lli long ling int;

int main()
{
    int N;
    scanf("%d", &N);

    int a, b;
    a = N / 10;
    b = N % 10;
    if (b == 7) {
        printf("Yes\n");
        return 0;
    }

    b = a % 10;
    a /= 10;
    if (b == 7) {
        printf("Yes\n");
        return 0;
    }

    b = a % 10;
    if (b == 7) {
        printf("Yes\n");
        return 0;
    }
    
    printf("No\n");

    return 0;
}

Measured memory_bytes: 3764
import sys
sys.setrecursionlimit(1000000000)
import math
from math import gcd
def lcm(a, b): return a * b // gcd(a, b)
from itertools import count, permutations, chain
from functools import lru_cache
from collections import deque, defaultdict
from pprint import pprint
ii = lambda: int(input())
mis = lambda: map(int, input().split())
lmis = lambda: list(mis())
INF = float('inf')
N1097 = 10**9 + 7

def meg(f, ok, ng):
    while abs(ok-ng)>1:
        mid = (ok+ng)//2
        if f(mid):
            ok=mid
        else:
            ng=mid
    return ok

def get_inv(n, modp):
    return pow(n, modp-2, modp)

def factorials_list(n, modp):    # 10**6
    fs = [1]
    for i in range(1, n+1):
        fs.append(fs[-1] * i % modp)
    return fs

def invs_list(n, fs, modp):     # 10**6
    invs = [get_inv(fs[-1], modp)]
    for i in range(n, 1-1, -1):
        invs.append(invs[-1] * i % modp)
    invs.reverse()
    return invs

def comb(n, k, modp):
    num = 1
    for i in range(n, n-k, -1):
        num = num * i % modp
    den = 1
    for i in range(2, k+1):
        den = den * i % modp
    return num * get_inv(den, modp) % modp

def comb_from_list(n, k, modp, fs, invs):   
    return fs[n] * invs[n-k] * invs[k] % modp

#

class UnionFindEx:
    def __init__(self, size):
        #正なら根の番号、負ならグループサイズ
        self.roots = [-1] * size
    def getRootID(self, i):
        r = self.roots[i]
        if r < 0:   #負なら根
            return i
        else:
            r = self.getRootID(r)
            self.roots[i] = r
            return r
    def getGroupSize(self, i):
        return -self.roots[self.getRootID(i)]
    def connect(self, i, j):
        r1, r2 = self.getRootID(i), self.getRootID(j)
        if r1 == r2:
            return False
        if self.getGroupSize(r1) < self.getGroupSize(r2):
            r1, r2 = r2, r1
        self.roots[r1] += self.roots[r2]    #サイズ更新
        self.roots[r2] = r1
        return True

Yes = 'Yes'
No = 'No'

def main(X=None):
    if X is None:
        X = ii()
    for a in range(-100000, 100000):
        b5 = a**5 - X
        b = meg(lambda v: v**5<=b5, -10000000, 10000000)
        if a**5 - X == b**5:
            print(a, b)
            return

main()



Measured memory_bytes: 9988
#include <iostream> // cout, endl, cin
using namespace std;
//四角枠
void yoke(long long int h, long long int w)
{
  for (long long int i = 0; i < h; i++)
  {
    for (long long int j = 0; j < w; j++)
    {
      if(i == 0||i == h - 1) cout << "#";
      else if(j == 0||j == w - 1) cout << "#";
      else cout << ".";
    }
    cout << endl;
  }
}

int main()
{
  while(1)
  {
    long long int H , W;
    cin >> H >> W;
    if(H == 0&&W == 0) return 0;
    yoke(H, W);
    cout << endl;
  }
}


Measured memory_bytes: 3016
# your code goes here
n, m = map(int, input().split())
DT = []
RS = []
for i in range(m):
    a, b = map(int, input().split())
    DT.append((a, b, i))
    RS.append('')
DT.sort()
ss = 0
dfz = -1
for I in DT:
    if (I[0] != dfz):
        ss = 0
        dfz = I[0]
    ss += 1
    RS[I[2]] = '%06d%06d' % (I[0], ss)
for I in RS:
    print(I)


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

#define rep(i, a, b) for(int i=a; i<=b; i++)
#define trav(a, x) for(auto& a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int) x.size()
#define pb push_back
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
const int MOD = 1e9+7;

int n;

struct M {
	ll arr[50][50];

	void init(ll init[50][50]){
		rep(i, 0, n-1){
			rep(j, 0, n-1){
				arr[i][j]=init[i][j];
			}
		}
	}

	M operator*(M other){
		M res;
		rep(i, 0, n-1){
			rep(j, 0, n-1){
				res.arr[i][j]=0;
			}
		}
		rep(i, 0, n-1){
			rep(j, 0, n-1){
				rep(k, 0, n-1){
					res.arr[i][k]=((ll)res.arr[i][k]+(ll)arr[i][j]%MOD*(ll)other.arr[j][k]%MOD)%MOD;
				}
			}
		}
		return res;
	}

	M pow(M m, ll n){
		M res=I();
		while(n){
			if(n&1) res=res*m;
			m=m*m;
			n >>= 1;
		}
		return res;
	}

	static M I() {
        M m;
        rep(i, 0, n-1){
        	rep(j, 0, n-1){
        		if(i==j) m.arr[i][i]=1;
        		else m.arr[i][j]=0;
        	}
        }
        return m;
    }
};

ll k;

int main(){
  // freopen("input.txt", "r", stdin); 
  // freopen("output.txt", "w", stdout);
  cin.sync_with_stdio(0); cin.tie();
  cin.exceptions(cin.failbit);

  cin >> n >> k;
  ll adj[50][50];
  rep(i, 0, n-1){
  	rep(j, 0, n-1){
  		cin >> adj[i][j];
  	}
  }

  M m;
  m.init(adj);

  M res=m.pow(m, k);

  ll ans=0;
  rep(i, 0, n-1){
  	rep(j, 0, n-1){
  		ans=(ans+res.arr[i][j])%MOD;
  	}
  }
  cout << ans;
}

Measured memory_bytes: 3800
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned int uint;
typedef unsigned char uchar;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;

#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();i++)
#define RFOR(i,c) for(__typeof((c).rbegin())i=(c).rbegin();i!=(c).rend();i++)
#define ALL(container) (container).begin(), (container).end()
#define RALL(container) (container).rbegin(), (container).rend()
#define SZ(container) ((int)container.size())
#define mp(a,b) make_pair(a, b)
#define pb push_back
#define eb emplace_back
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define __builtin_popcount __builtin_popcountll

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 (a>b) { a=b; return 1; } return 0; }
template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {
    os<<"["; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"]"; return os;
}
template<class T> ostream& operator<<(ostream &os, const set<T> &t) {
    os<<"{"; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"}"; return os;
}
template<class S, class T> ostream& operator<<(ostream &os, const map<S, T> &t) {
    os<<"{"; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"}"; return os;
}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}
template<class S, class T> pair<S,T> operator+(const pair<S,T> &s, const pair<S,T> &t){ return pair<S,T>(s.first+t.first, s.second+t.second);}
template<class S, class T> pair<S,T> operator-(const pair<S,T> &s, const pair<S,T> &t){ return pair<S,T>(s.first-t.first, s.second-t.second);}

const int INF = 1<<28;
const double EPS = 1e-8;
const int MOD = 1000000007;


ll T, n, m;
class BIT {
    int n;
    vector<ll> vs;
public:
    BIT(int size) {
        n = size;
        vs = vector<ll>(n);
    }
    //O(log n)
    void add(int k, ll a) {
        for(int i = k; i < n; i |= i + 1) vs[i] += a;
    }
    //[s,t)	O(log n)
    ll sum(int s, int t) {
        if(s > 0) return sum(0, t) - sum(0, s);
        ll res = 0;
        for(int i = t - 1; i >= 0; i = (i & (i + 1)) - 1) res += vs[i];
        return res;
    }
};


int check(int x, const vi& d) {
    int cur = n;
    BIT bit(n * 2);
    bit.add(cur, 1);
    ll sum = 0;
    REP(i, n) {
        cur += (x <= d[i] ? 1 : -1);
        sum += bit.sum(0, cur + 1);
        bit.add(cur, 1);
    }
    return (n * (n + 1) / 2 + 1) / 2 <= sum;
}

int main(int argc, char *argv[]){
    ios::sync_with_stdio(false);
    while(cin >> n){
        vi d(n);
        REP(i, n) cin >> d[i];
        int l=0, r=MOD;
        while(l+1 < r) {
            int mid = (l+r) / 2;
            if (check(mid, d)) l = mid;
            else r = mid;
        }
        cout << l << endl;
    }
    return 0;
}


Measured memory_bytes: 2276
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<tuple>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<deque>
#include<cmath>
#include<stack>
#include<string.h>
#include <iomanip>
#define rep(i,n) for(int i = 0;i<n;i++)
#define _GLIBCXX_DEBUG
using ll = long long; 
using namespace std;
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() {
    int n;
    cin >> n;
    vector<int>a(n);
    rep(i,n) cin >> a[i];
    int maxv = 0;
    int maxv_2 = 0;
    rep(i,n) {
        maxv = max(maxv,a[i]);
    }
    int val = 0;
    rep(i,n) {
        if(a[i] == maxv) val = i;
    }
    rep(i,n) {
        if(i == val) continue;
        maxv_2 = max(maxv_2,a[i]);
    }
    rep(i,n) {
        if(i==val) {
            cout << maxv_2 << endl;
            continue;
        }    
        cout << maxv << endl;
    }

}

Measured memory_bytes: 2432
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef pair<int, int> P;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()

void YN(bool flg){if(flg) cout << "YES" << endl; else cout << "NO" << endl;}
void Yn(bool flg){if(flg) cout << "Yes" << endl; else cout << "No" << endl;}
void yn(bool flg){if(flg) cout << "yes" << endl; else cout << "no" << endl;}

int main() {
   int n;
   cin >> n;
   cout << (n + 1) / 2 << endl;

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void) {

  int n;
  int seq[8],max[8],min[8];
  long imax,imin;
  char c;
  int i,j,k,temp;

  scanf("%d",&n);

  for(k=0;k<n;k++) {
    
    c=getchar();
    for(i=0;i<8;i++) {
      c=getchar();
      seq[i]=c-'0';
    }
    //printf("%d\n",seq[0]);
    for(i=0;i<8;i++) max[i]=seq[i];
    //for(i=0;i<8;i++) printf("%d ",max[i]);
    //puts("");
    for(i=0;i<7;i++) {
      for(j=0;j<7-i;j++) {
	if(max[j]<max[j+1]) {
	  temp=max[j];
	  max[j]=max[j+1];
	  max[j+1]=temp;
	}
      }
    }
    //for(i=0;i<8;i++) printf("%d ",max[i]);
    //puts("");
    imax=10000000*max[0]+1000000*max[1]+100000*max[2]+10000*max[3]+1000*max[4]+100*max[5]+10*max[6]+max[7];
    //printf("%ld\n",imax);
    for(i=0;i<8;i++) min[i]=seq[i];

    for(i=0;i<7;i++) {
      for(j=0;j<7-i;j++) {
	if(min[j]>min[j+1]) {
	  temp=min[j];
	  min[j]=min[j+1];
	  min[j+1]=temp;
	}
      }
    }
    //for(i=0;i<8;i++) printf("%d ",min[i]);
    //puts("");
    imin=10000000*min[0]+1000000*min[1]+100000*min[2]+10000*min[3]+1000*min[4]+100*min[5]+10*min[6]+min[7];
    //printf("%ld\n",imin);
    printf("%ld\n",imax-imin);
    
  }

  return 0;

}

Measured memory_bytes: 0
from collections import deque


n = int(input())
info = [list(map(int, input().split())) for i in range(n-1)]

tree = [[] for i in range(n)]
for i in range(n-1):
    a, b = info[i]
    a -= 1
    b -= 1
    tree[a].append(b)
    tree[b].append(a)
ans = 0
for i in range(n):
    ans = max(ans, len(tree[i]))

memo = {}
for i in range(n-1):
    tmp = tuple(sorted(info[i]))
    memo[tmp] = i

edge = [-1]*(n-1)

q = deque([0])
while q:
    pos = q.pop()
    li = []
    position = []
    used = set([])
    for next_pos in tree[pos]:
        tmp = tuple(sorted([next_pos+1, pos+1]))
        if edge[memo[tmp]] == -1:
            li.append(tmp)
            position.append(next_pos)
        else:
            used.add(edge[memo[tuple(sorted([next_pos+1, pos+1]))]])
    cnt = 1
    for i in li:
        while True:
            if cnt not in used:
                edge[memo[i]] = cnt
                cnt += 1
                break
            else:
                cnt += 1
    for i in position:
        q.append(i)

print(ans)
for i in edge:
    print(i)

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

int main(){
  int h, w;
  while(1){
    cin >> h >> w;
    if(h+w==0) break;
    else{
      rep(i, h){
        rep(j, w){
          cout << "#";
        }
        cout << endl;
      }
    }
    cout << endl;
  }

}



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

// http://www.prefield.com/algorithm/misc/dice.html
enum FACE { TOP, BOTTOM, FRONT, BACK, LEFT, RIGHT };
class dice {
public:
	dice(int top,int front,int right,int left,int back,int bottom) {
		id[TOP] = top; id[FRONT] = front; id[RIGHT] = right;
		id[LEFT] = left; id[BACK] = back; id[BOTTOM] = bottom;
	}
	int& operator[] (FACE f) { return id[f]; }
	const int& operator[] (FACE f) const { return id[f]; }
	bool operator==(const dice &b) const {
		const dice &a = *this;
		return a[TOP] == b[TOP] && a[BOTTOM] == b[BOTTOM] &&
			a[FRONT] == b[FRONT] && a[BACK] == b[BACK] &&
			 a[LEFT] == b[LEFT] && a[RIGHT] == b[RIGHT];
	}
	void roll_north() { roll(TOP, FRONT, BOTTOM, BACK); }
	void roll_south() { roll(TOP, BACK, BOTTOM, FRONT); }
	void roll_east() { roll(TOP, LEFT, BOTTOM, RIGHT); }
	void roll_west() { roll(TOP, RIGHT, BOTTOM, LEFT); }
	void roll_right() { roll(FRONT, LEFT, BACK, RIGHT); }
	void roll_left() { roll(FRONT, RIGHT, BACK, LEFT); }
	void all_rolls(set<long long> &s){
		for (int k = 0; k < 6; (k&1?roll_east():roll_north()),++k)
			for (int i = 0; i < 4; roll_right(), ++i)
				s.insert(((long long)id[TOP]<<40) | ((long long)id[FRONT]<<32) | (id[RIGHT]<<24) | (id[LEFT]<<16) | (id[BACK]<<8) | (id[BOTTOM]<<0));
	}
private:
	void roll(FACE a, FACE b, FACE c, FACE d){
		int tmp = id[a];
		id[a] = id[b]; id[b] = id[c];
		id[c] = id[d]; id[d] = tmp;
	}
	int id[6];
};

int main(){
	string str;
	int d[6];
	int n,i,j,r;
	for(;cin>>n,n;){
		set<long long>s;
		for(r=i=0;i<n;i++){
			for(j=0;j<6;j++)cin>>str,d[j]=str[0];
			long long x=((long long)d[0]<<40) | ((long long)d[1]<<32) | (d[2]<<24) | (d[3]<<16) | (d[4]<<8) | (d[5]<<0);
			if(s.find(x)!=s.end())r++;
			else{
				dice di(d[0],d[1],d[2],d[3],d[4],d[5]);
				di.all_rolls(s);
			}
		}
		cout<<r<<endl;
	}
}

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

using namespace std;

#define ll long long
#define M 1005000
#define ii pair<ll, ll>
#define fi first
#define se second



int main(){
    ios::sync_with_stdio(false); cin.tie(0);
    
    ll k, x;
    set<ll> s;
    cin >> k >> x;
    for (ll i = x - k + 1; i <= x + k - 1; i++) s.insert(i);
    for (ll u : s) cout << u << " ";
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <vector>
#include <queue>
#include <set>
#include <iostream>
#include <iomanip>
using namespace std;
typedef long long LL;
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)

int main(){
    int N;
    cin >> N;
    vector<int> p(N);
    REP(i,N)cin>>p[i];

    LL ans = 0;
    REP(i,N){
        if(p[i]==i+1){
            ans++;
            if(i+1!=N){
                p[i+1]=p[i];
            }
        }
    }

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

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

using namespace std;

int main(){
  int n,m,i,j;
  cin >> n >> m;
  bool ch[n+1]={};
  int cnt[n+1];
  ch[1]=true;
  for(i=1;i<=n;i++)cnt[i]=1;
  for(i=0;i<m;i++){
    int x,y;
    cin >> x >> y;
    cnt[x]--;
    cnt[y]++;
    if(ch[x])ch[y]=true;
    if(cnt[x]==0)ch[x]=false;
  }
  int ret = 0;
  for(i=1;i<=n;i++)if(ch[i])ret++;
  cout << ret << endl;
  return 0;
}


Measured memory_bytes: 768
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < (n); i++)
#define REPR(i, n) for(int i = (n); i >= 0; i--)
#define FOR(i, m, n) for(int i = (m); i < (n); i++)
#define INF 1e9
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << #x << ": " << x << endl;

using namespace std;
typedef long long ll;

signed main() {
  int a, b, c, d, turn = 1;
  cin >> a >> b >> c >> d;
  while(a > 0 && c > 0) {
    if(turn == 1)
      c -= b;
    else
      a -= d;
    turn *= -1;
  }

  if(turn == -1) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}


Measured memory_bytes: 3636
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) {

		BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
		String inStr = "";
		int N = 0;
		String A = "";
		String B = "";
		String C = "";
		try {
			inStr = new String(input.readLine());
			N = Integer.valueOf(inStr);
			A = new String(input.readLine());
			B = new String(input.readLine());
			C = new String(input.readLine());
		} catch (IOException e) {
			e.printStackTrace();
		}

		exec(N, A, B, C);

	}

	private static void exec(int _N, String _A, String _B, String _C) {

		int cnt = 0;
		for (int i = 0; i < _N; i++) {
			String tmpA = _A.substring(i, i+1);
			String tmpB = _B.substring(i, i+1);
			String tmpC = _C.substring(i, i+1);
			if (tmpA.equals(tmpB)) {
				if (!tmpA.equals(tmpC)) {
					cnt++;
				}
			} else {
				if (tmpA.equals(tmpC)) {
					cnt++;
				} else {
					if (tmpB.equals(tmpC)) {
						cnt++;
					} else {
						cnt++;
						cnt++;
					}
				}
			}
		}

		System.out.println(cnt);
	}

}


Measured memory_bytes: 23124
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define INF 1<<30
#define LINF 1LL<<60
#define MAX_V 100000

struct edge{
    int to;
    int cap;
    int cost;
    int rev;
    edge(){}
    edge(int to,int cap,int cost,int rev):to(to),cap(cap),cost(cost),rev(rev){}
};

int V;
vector<edge> G[MAX_V];
int dist[MAX_V];
int prevv[MAX_V],preve[MAX_V];

void add_edge(int from,int to,int cap,int cost){
    G[from].push_back(edge(to,cap,cost,(int)G[to].size()));
    G[to].push_back(edge(from,0,-cost,(int)G[from].size()-1));
}

int min_cost_flow(int s,int t,int f){
    int res=0;
    while(f>0){
        fill(dist,dist+V,INF);
        dist[s]=0;
        bool update = true;
        while(update){
            update = false;
            for(int v=0; v<V ;v++){
                if(dist[v]==INF) continue;
                for(int i=0; i<G[v].size(); i++){
                    edge &e = G[v][i];
                    if(e.cap > 0 && dist[e.to] > dist[v]+e.cost) {
                        dist[e.to] = dist[v] + e.cost;
                        prevv[e.to] = v;
                        preve[e.to] = i;
                        update = true;
                    }
                }
            }
        }
        if(dist[t]==INF) return -1;
        
        int d = f;
        for(int v=t; v!=s; v=prevv[v])d=min(d,G[prevv[v]][preve[v]].cap);
        f -= d;
        res += d*dist[t];
        for(int v=t; v!=s; v=prevv[v]){
            edge &e = G[prevv[v]][preve[v]];
            e.cap -= d;
            G[v][e.rev].cap += d;
        }
    }
    return res;
}

int main() {
    int E, F; cin >> V >> E >> F;
    for (int i = 0; i < E;i++) {
        int u, v, c, d; cin >> u >> v >> c >> d;
        add_edge(u,v,c,d);
    }
    cout << min_cost_flow(0,V-1,F) << endl;
    return 0;
}



Measured memory_bytes: 5504
#include<stdio.h>
int main(void)
{
    int n,i;
    while(1){
        scanf("%d",&n);
        if(n==0) break;
        int k,a=0,b=0;
        for(i=0;i<n;i++){
            scanf("%d",&k);
            if(a==0&&k>=2) a=1;
            if(k!=0) b++;
        }
        if(a==0) printf("NA\n");
        else printf("%d\n",b+1);
    }
    return 0;
}

Measured memory_bytes: 612
#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<int,int>;

int main(){
    ll a,b,k;
    cin >> a >> b >> k;
    ll x = min(a,k);
    a -= x;
    k -=x;
    b -= min(b,k);

    cout << a << " " << b << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <algorithm>
#include <iostream>
#include <complex>
#include <cstdio>
#include <cmath>
#include <utility>
#include <vector>
using namespace std;
using W = double;
using P = complex<W>;
using L = pair<P,P>;
using C = pair<P,W>;
using Poly = vector<P>;
#define X real()
#define Y imag()
const W EPS = (1e-10), pi = acos(-1);
double dot(P a, P b){ return a.X * b.X + a.Y * b.Y;}
W cross(P a, P b){ return a.X * b.Y - a.Y * b.X;}
W ps_dist(P a, L s){
  P sf = s.first, ss = s.second;
  if(dot(ss-sf,a-sf) >= 0 && dot(sf-ss,a-ss) >= 0)
    return abs(cross(sf-ss,a-ss))/abs(sf-ss);
  return min(abs(a-sf), abs(a-ss));
} 

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 inf = 1e9;

using pdi = pair<double,int>;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n,m;
    cin >> n >> m;
    vector<P> p(n+1);
    double x,y;
    cin >> x >> y;
    p[0] = P(x,y);
    for(int i=1; i<=n; i++){
        cin >> x >> y;
        p[i] = P(x,y);
    }
    bool fst = true;
    vector<bool> used(n+1,false);
    used[0] = true;
    double ans = 0;
    priority_queue<pdi,vector<pdi>,greater<pdi>> que;
    vector<double> dist(n+1);
    for(int i=1; i<=n; i++){
        dist[i] = abs(p[i]-p[0]);
        que.emplace(abs(p[i]-p[0]),i);
    }
    for(int i=0; i<m; i++){
        pdi mn = pdi(inf,inf);
        while(used[que.top().second]) que.pop();
        int id = que.top().second;
        que.pop();
        double res = inf;
        int root;
        for(int j=0; j<=n; j++){
            if(used[j]){
                if(chmin(res,abs(p[id]-p[j]))){
                    root = j;
                }
            }
        }
        ans += res;
        used[id] = true;
        L line = L(p[id],p[root]);
        for(int j=0; j<=n; j++){
            if(used[j]) continue;
            if(chmin(dist[j],abs(p[j]-p[id]))){
                que.emplace(abs(p[j]-p[id]),j);
            }
            if(chmin(dist[j],ps_dist(p[j],line))){
                que.emplace(ps_dist(p[j],line),j);
            }
        }
    }
    cout << fixed << setprecision(10) << ans << endl;
    return 0;
}


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

int main(){

  long long now = 100;
  long long count = 0;
  long long X;
  cin >> X;

  while(1){
    count ++;
    now *= 1.01;
    if(now>=X) break;
  }

  cout << count << endl;
}

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

struct s_ymd {
	int y, m, d;
	bool operator!=(const s_ymd& s){
		return y != s.y || m != s.m || d != s.d;
	}
};

int main() {
	vector<s_ymd> v(2); int ans = 0;
	auto f_sort = [](const s_ymd& l, const s_ymd& r) {
		return l.y == r.y ? l.m == r.m ? l.d < r.d : l.m < r.m : l.y < r.y;
	};
	for (int i = 0; i < 2; i++) cin >> v[i].y >> v[i].m >> v[i].d;
	if (v[0] != v[1]) sort(v.begin(), v.end(), f_sort);
	ans += v[1].y - v[0].y;
	if (v[0].m < v[1].m) ans++;
	else if (v[0].m == v[1].m && v[0].d < v[1].d) ans++;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3100
#include<stdio.h>
int main(){
	int n,i,j;
	long long sum=0;
	scanf("%d",&n);
	int health[n+1];
	for(i=0;i<n;i++){
		scanf("%d",&health[i]);
	}
	for(i=0;i<n-1;i++)
		for(j=i+1;j<n;j++)
			sum+=health[i]*health[j];
	printf("%Ld",sum);
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <queue>

using namespace std;

const unsigned int INFTY = 1 << 31;

int n;
bool *visited;
vector<pair<unsigned int,unsigned int> > *Graph;
unsigned int *d;

//本题不包含负权路径，使用狄克斯特拉算法
/*void dijkstra(int u) {
	priority_queue<pair<int,int> > PQ;

	for (int i=0; i<n; i++) {
		d[i] = INFTY;
		visited[i] = false;
	}

	d[u] = 0;
	PQ.push(make_pair(0,u));

	while (!PQ.empty()) {
		pair<int,int> f = PQ.top();
		PQ.pop();
		int u = f.second;
		
		visited[u] = true;
		
		if (d[u] < f.first * -1) {
			continue;
		}
		const vector<pair<int,int> > & n_points = Graph[u];

		for (int i = 0; i<n_points.size(); i++) {
			pair<int,int> p = n_points[i];
			int & v = p.first;
			int & w = p.second;
			if (!visited[v] && d[v] > d[u] + w) {
				d[v] = d[u] + w;
				PQ.push(make_pair(-1*d[v],v));
			}
		}
	}
}*/

void dijkstra(int u) {
	for (int i=0; i<n; i++) {
		d[i] = INFTY;
		visited[i] = false;
	}
	d[u] = 0;
	priority_queue<pair<int,unsigned int> >PQ;
	PQ.push(make_pair(0,u));
	while (!PQ.empty()) {
		u = PQ.top().second;
		PQ.pop();

		visited[u] = true;

		const vector<pair<unsigned int,unsigned int> > & n_points = Graph[u];
		for (int i=0; i<n_points.size(); i++) {
			pair<unsigned int,unsigned int> f = n_points[i];
			unsigned int & v = f.first;
			unsigned int & w = f.second;
			if (!visited[v] && d[v] > d[u] + w) {
				d[v] = d[u] + w;
				PQ.push(make_pair(-1*d[v],v));
			}
		}
	}
}

int main() {
	int e,r;
	cin >> n >> e >> r;
	Graph = new vector<pair<unsigned int,unsigned int> >[n];
	visited = new bool[n];
	d = new unsigned int[n];
	
	for (int i=0; i<e; i++) {
		unsigned int s,t,d;
		cin >> s >> t >> d;
		Graph[s].push_back(make_pair(t,d));
	}
	dijkstra(r);
	for (int v=0;v<n;v++) {
		if (d[v] == INFTY) {
			cout << "INF" << endl;
		} else {
			cout << d[v] << endl;
		}
	}
	delete[] Graph;
	delete[] visited;
	delete[] d;
	return 0;
}


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

int main(){
  int N;
  int T;
  cin >> N >>T;
  long long t[N]={0};
  for(int i=0;i<N;++i){
    cin >> t[i];
  }
  int X=T;
  for(int i=0;i<N-1;++i){
    if(t[i+1]-t[i]>=T){
      X+=T;
    }
    else{
      X+=t[i+1]-t[i];
    }
  }
  cout << X;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define ll long long int
#define FastIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
using namespace std;

int main(void)
{
    FastIO;
    
    ll n,s=0,m=0;
    cin>>n;
    ll a[n][3];
    for(ll i=0;i<n;i++)
    {
    	cin>>a[i][0]>>a[i][1];
	}
	for(ll i=0;i<n;i++)
	{
		if(a[i][0]==a[i][1])
		{
			s++;
			m=max(m,s);
		}
		else
		{
			s=0;
		}
	}
	if(m>=3)
	{
		cout<<"Yes";
	}
	else
	{
		cout<<"No";
	}
    
    return 0;
}

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

int	main()
{
	int	N;
	string	S;
	cin >> N >> S;
	unordered_map<char, unordered_map<char, unordered_set<char>>> u_map;
	for (char c : S) {
		for	(auto &u_key_val: u_map) {
			auto &c_map = u_key_val.second;
			for (auto &c_key_val : c_map)
				c_key_val.second.insert(c);
			if (!c_map.count(c))
				c_map[c] = unordered_set<char>();
		}
		if (!u_map.count(c))
			u_map[c] = unordered_map<char, unordered_set<char>>();
	}
	int	cnt = 0;
	for (auto &u_key_val : u_map) {
		auto &c_map = u_key_val.second;
		for (auto &c_key_val : c_map) {
			cnt += c_key_val.second.size();
		}
	}
	cout << cnt << endl;
}


Measured memory_bytes: 384
#include<cstdio>
using namespace std;
int n,cnt,now;
int main()
{
	scanf("%d",&n);
	for (int i=1;i<=n;++i)
	{
		scanf("%d",&now);
		if (now==cnt+1)
			++cnt;
	}
	if (cnt)
		printf("%d",n-cnt);
	else
		puts("-1");
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <algorithm>
#include <utility>
#include <stdio.h>
typedef long long ll;
const int INF = 1e9+1;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;
using namespace std;

int main() {
	int n, m;
	int left, right;
	cin >> n >> m;
	left = 0;
	right = n;
	vector<int> l(m), r(m);
	for (int i = 0; i < m; i++)cin >> l.at(i) >> r.at(i);

	for (int i = 0; i < m; i++) {
		if (l.at(i) >= left && r.at(i) <= right) { left = l.at(i); right = r.at(i); }
		else if (l.at(i) <= left && r.at(i) <= right && r.at(i) >= left) { left = left; right = r.at(i); }
		else if (l.at(i) >= left && r.at(i) >= right&&l.at(i)<=right) { left = l.at(i); right = right; }
		else if (l.at(i) <= left && r.at(i) >= right) { left = left; right = right; }
		else { cout << 0 << endl; return 0; }
	}
	cout << right - left +1<< endl;
	return 0;
}

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

// why am I so weak

int n, m;
int l[300055], r[300055];

int dat[400055];
int inter[400055];

typedef pair<int, int> P;

#define ft first
#define sd second

vector<int> event[100055];

void update(int id, int x, int y, int l, int r) {
	if (l > y || r < x) return;

	if (l <= x && y <= r) {
		dat[id]++;
		return;
	}

	int mid = (x + y) >> 1;

	update(id + id, x, mid, l, r);
	update(id + id + 1, mid + 1, y, l, r);
}
void update2(int id, int x, int y, int l, int r) {
	if (l > y || r < x) return;

	if (l <= x && y <= r) {
		inter[id]++;
		return;
	}

	int mid = (x + y) >> 1;

	update2(id + id, x, mid, l, r);
	update2(id + id + 1, mid + 1, y, l, r);
}
int query(int id, int x, int y, int w) {
	if (x == y) return dat[id];

	int mid = (x + y) >> 1;

	if (w <= mid) return dat[id] + query(id + id, x, mid, w);
	else return dat[id] + query(id + id + 1, mid + 1, y, w);
}
int query2(int id, int x, int y, int w) {
	if (x == y) return inter[id];

	int mid = (x + y) >> 1;


	if (w <= mid) return inter[id] + query2(id + id, x, mid, w);
	else return inter[id] + query2(id + id + 1, mid + 1, y, w);
}
int main() {
	scanf("%d %d", &n, &m);

	for (int i = 0; i < n; i++) {
		scanf("%d %d", &l[i], &r[i]);

		update(1, 1, m, 1, r[i] - l[i] + 1);
		event[r[i] - l[i] + 2].push_back(i);
	}

	for (int i = 1; i <= m; i++) {
		int res = query(1, 1, m, i);

		for (auto u : event[i]) {
			update2(1, 1, m, l[u], r[u]);
		}

		for (int j = i; j <= m; j += i) {
			res += query2(1, 1, m, j);
		}

		printf("%d\n", res);
	}

	return 0;
}


Measured memory_bytes: 10752
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath>
#include <math.h> // sqrt()
#include <iomanip>
#define rep(i , n) for (int i = 0; i < (int)(n); i++)

using namespace std;

int main() {
    int n, it, it2;
    it = 0;
    it2 = 0;
    char a;
    cin >> n;
    int sum = n;
    vector<char> str;
    rep(i , n){
        cin >> a;
        str.push_back(a);
    }
    rep(i , n){
        if (i == 0){
            
            it2 = int(count(str.begin() + 1, str.end(), 'E'));
        }
        else{
            if (str.at(i - 1) == 'W')
                it++;
            if (str.at(i) == 'E')
                it2--;
        }
        
        
        sum = min(sum , it + it2);
        
    }
    cout << sum  << endl;
    
}


Measured memory_bytes: 892
from fractions import gcd
n,x = map(int,input().split())
l = list(map(int,input().split()))
l.append(x)
l.sort()
skyks = l[1]-l[0]
for i in range(1,n):
    y = l[i+1]-l[i]
    skyks = gcd(skyks,y)
print(skyks)

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

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

    int A, B;
    cin >> A >> B;

    string U;
    cin >> U;
    if (S == U)
    {
        cout << A - 1 << " " << B << endl;
    }
    else
    {
        cout << A << " " << B - 1 << endl;
    }
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static final int BIG_NUM = 2000000000;
	public static final int MOD = 1000000007;

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();

		if(N <= 1){

			System.out.println(1);
			return;

		}

		long table[] = new long[N+1];

		table[0] = 1;
		table[1] = 1;

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

		System.out.println(table[N]);
	}
}



Measured memory_bytes: 26172
import java.util.Scanner;

public class Main{
    public static void main(String[] arg){
        int a, b, c;
        Scanner scan = new Scanner(System.in);
        a = scan.nextInt();
        b = scan.nextInt();
        c = scan.nextInt();
        if(a < b){
            if(b < c){
            	System.out.println("Yes");
            }else{
            	System.out.println("No");
        	}
        }else{
            System.out.println("No");
        }
    }
}


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

int main(){
	map<string,int>mp1,mp2;
	int n;scanf("%d",&n);
	rep(i,n){
		string s;cin>>s;
		mp1[s]++;
	}
	int m;scanf("%d",&m);
	rep(i,m){
		string s;cin>>s;
		mp2[s]++;
	}
	int Max=0;
	for(auto p:mp1){
		Max=max(Max,p.second-mp2[p.first]);
	}
	cout<<Max<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#define MARK 4
#define RANK 13
#define CHECK 1	
int main(void)
{
	int n,rank,a,i,k;
	char mark;
	int card[MARK]={0,0,0,0};
	char mk[MARK]={'S','H','C','D'};
	scanf("%d", &n);
	for(i=0; i<n; i++){
		scanf(" %c %d", &mark, &rank);
		if(mark == 'S'){
			a=1;
			a <<= rank;
			card[0] += a;
		}else if(mark == 'H'){
			a=1;
			a <<= rank;
			card[1] += a;
		}else if(mark == 'C'){
			a=1;
			a <<= rank;
			card[2] += a;
		}else if(mark == 'D'){
			a=1; 
			a <<= rank;
			card[3] += a;
		}
	}
	for(i=0; i<MARK; i++){
		for(k=0; k<RANK; k++){
			card[i] >>= 1;
			if((card[i] & CHECK) == 0){
				printf("%c %d\n", mk[i], k+1);
			}
		}
	}
	return 0;
}

Measured memory_bytes: 596
#include <stdio.h>          // printf(), scanf()

const int N = 10;

int
main(int argc, char **argv)
{
	long n;
	int a[N];
	int i, j;

	while (scanf("%ld", &n) != EOF)
	{
		for (i = N - 1; i >= 0; --i)
		{
			a[i] = n % 10;
			n /= 10;
		}

		for (i = N - 1; i >= 1; --i)
		{
			for (j = 0; j < i; ++j)
				a[j] = (a[j] + a[j + 1]) % 10;
		}

		printf("%d\n", a[0]);
	}

	return 0;
}

Measured memory_bytes: 596
#include <iostream>
#include <vector>
#include <string>
#include <math.h>
#include <algorithm>
#include <set>
#include <iomanip>
#include <stdio.h>
#include <sstream>
#include <string>
using namespace std;
int main(void){
    long long int n, a, b;
    cin>>n>>a>>b;
    if(a>=n){
        cout<<n<<endl;
    }else if(a+b>=n){
        cout<<a<<endl;
    }else{
        long long int ans=(n/(a+b))*a;
        if(n%(a+b)<=a){
            ans+=n%(a+b);
        }else{
            ans+=a;
        }
        cout<<ans<<endl;
    }
}


Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<algorithm>
#include<math.h>
#include <string.h>
using namespace std;

int main(){
	long long int i,j,m,n,w;//1 2 3 4 5  12
	long long int a,b;
	while(cin>>n>>m){
		if(n<=m){
			if(n<=(m/2)){
				a=(m-2*n)/4;
				cout<<a+n<<endl;
			}else if(n>(m/2)){
				cout<<m/2<<endl;
			}
		}else if(n>m){
			cout<<m/2<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner scanner = new Scanner(System.in);
    int n = scanner.nextInt(); //判定金額
    int cates = 4;
    int donuts = 7;
    int sum = 0;
    boolean result = false;
    
    for(int i = 0; sum < n; i++){
      sum = donuts*i;
      if((n-sum)<0){
        break;
      }
      else if((n-sum)%cates==0){
        result = true;
        break;
      }
    }
    
    if(result){
      System.out.println("Yes");
    }
    else{
      System.out.println("No");
    }
    
	}
}

Measured memory_bytes: 20948
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<stack>
#include<queue>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
using namespace std;

int main(){
    string s;
    int cnt[26] = {};
    cin >> s;
    for(char c : s){
        cnt[c - 'a']++;
    }
    for(int i = 0;i < 26;i++){
        if(!cnt[i]){
            cout << (char)(i + 'a') << endl;
            return 0;
        }
    }
    cout << "None" << endl;
    return 0;
    
    
    
    
    
    
    
    
}

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

#define ull unsigned long long int
#define ll long long int
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(),x.end()
#define MOD (ull)(double)(1e9 + 7)
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vll vector<ll>
#define vpii vector<pii>
#define vpll vector<pll>
#define vvi vector<vi>
#define vvll vector<vll>
#define vs vector<string>
#define pull pair<ull, ull>
#define m_p make_pair
#define debug(x) cout << #x << " " << x << endl

const long double PI = 3.141592653589793238462643383279502884197169399;

// Find Set LSB = (x&(-x)), isPowerOfTwo = (x & (x-1))

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	int tt=1;
	//cin >> tt;
	
	while(tt--){
		string s;
		cin >> s;
		
		cout << s[0] << s[1] << s[2];
	}
}


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

using namespace std;

#define pb push_back
#define mp make_pair
#define eb emplace_back


typedef long long ll;
typedef long double ld;


const ll inf = 2e9;
const ll base = 998244353;
ll mod = 1e9 + 7;



int main() {
//    srand(time(NULL));
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr);
//    std::random_device rd;
//    std::mt19937 g(rd());
    auto start = clock();


    ll n; cin >> n;
    vector<ll> a(n);
    ll k; cin >> k;
    for (ll i = 0; i < n; ++i) cin >> a[i];
    vector<ll> pref(n + 1);
    pref[0] = 0;
    for (ll i = 0; i < n; ++i) {
        pref[i + 1] = pref[i] + a[i];
    }
    for (ll i = 1; i < n + 1; ++i) {
        pref[i] -= i;
    }
    map<ll, ll> cnt;
    ll ans = 0;
    for (ll i = n; i >= 0; --i) {
        if (i + k < n + 1) {
            cnt[(pref[i + k]) % k]--;
        }
        ans += cnt[(pref[i]) % k];
        cnt[(pref[i]) % k]++;
    }
    cout << ans << endl;


    std::cerr << double(clock() - start) / CLOCKS_PER_SEC << std::endl;
    return 0;
}

Measured memory_bytes: 15872
#include <iostream>
// #include <cassert>
#include <vector>
#include <algorithm>
#include <climits>

#include <stack>
#include <queue>
// #include <deque>
// #include <set>
// #include <map>
// #include <string>
// #include <unordered_set>
// #include <unordered_map>

#include <tuple>
// #include <cmath>
// #include <numeric>

using namespace std;


typedef long long ll;
typedef pair<long,long> pll;
typedef pair<int,int> pii;
typedef pair<int,long> pil;
typedef pair<long,int> pli;
typedef pair<long long, long long> pllll;
typedef pair<long long, int> plli;
typedef pair<int,long long> pill;
typedef vector<vector<long long>> vvll;
typedef vector<vector<long>> vvl;
typedef vector<vector<int>> vvi;
typedef vector<int> vi;
typedef vector<long> vl;
typedef vector<long long> vll;

#define emplace_back pb
const char el = '\n';

int a[3][3];
bool seen[3][3];
/*
Edge cases:


*/

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

    vector<pii> pos(101,{-1,-1});
    for (int i = 0; i<3; ++i)
        for (int j =0; j<3; ++j) {
            cin>>a[i][j];
            pos[a[i][j]]= {i,j};
        }
    int n; cin>>n; cin.ignore();


    for (int k = 0; k<n; ++k) {
        int b; cin>>b; 
        auto pr = pos[b];
        int i = pr.first, j = pr.second;
        if (i>-1) {

            seen[i][j]=true;
        }
    }
    bool bingo=false;


    //check all rows and cols;
    for (int i = 0; i<3; ++i) {
        bool rowgood = true;
        bool colgood = true;
        for (int j = 0; j<3; ++j) {

            rowgood &= seen[i][j];
            colgood &= seen[j][i];
        }
        bingo |= rowgood;
        bingo |= colgood;
    }
    //check diagonals;
    bool diag1good = true;
    bool diag2good = true;
    for (int i = 0; i<3; ++i) {

        diag1good &= (seen[i][i]);
        diag2good &= (seen[i][2-i]);
    }
    bingo |= diag1good; bingo |= diag2good;

    if (bingo) {
        cout<<"Yes";
    } else {
        cout<<"No";
    } cout<<el;

    


}

Measured memory_bytes: 256
#include <algorithm>
#include <cctype>
#include <cstring>
#include <cstdio>
using namespace std;
typedef long long int64;
inline int64 read(int64 f = 1, int64 x = 0, char ch = ' ')
{
    while(!isdigit(ch = getchar())) if(ch == '-') f = -1;
    while(isdigit(ch)) x = x*10+ch-'0', ch = getchar();
    return f*x;
}
int64 n, x;
int main()
{
    n = read(), x = read(); 
    printf("%lld\n", 3*(n-__gcd(n, x)));
    return 0;
}

Measured memory_bytes: 128
#include <stdio.h>

int main(void){
	long long a, b, x;
	long long counter=0;

	scanf("%lld", &a);
	scanf("%lld", &b);
	scanf("%lld", &x);

	long long num_min = a%x ? (a/x+1)*x : a;
	long long num_max = b/x * x;
  

	printf("%lld", (num_max-num_min)/x + 1);
	return 0;
}

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

class line
{
public:
    long long a;
    long long b;

    line()
    {
        ;
    }

    line(long long A, long long B)
    {
        a = A;
        b = B;
    }

    long long eval(long long x)
    {
        return a*x + b;
    }
};

vector<line> L;

void insert(line k)
{
    if(L.size() <= 1) L.push_back(k);
    else
    {
        line l1 = L[L.size()-2];
        line l2 = L[L.size()-1];
       if((l2.b - l1.b) >= (l2.b - k.b)*(l1.a - l2.a)/(k.a - l2.a))
        {
            L.pop_back();
            insert(k);
        }
        else L.push_back(k);
    }
}

long long b_search(long long x, long long a, long long b)
{
    if(a == b) return L[a].eval(x);
    long long m = (a+b)/2;
    if((L[m+1].b - L[m].b) < x*(L[m].a - L[m+1].a)) return b_search(x, m+1, b);
    else return b_search(x, a, m);
}

int main()
{
    long long N, C;
    cin >> N >> C;

    long long h[N+1];
    for(long long i = 1; i <= N; i++) cin >> h[i];

    long long DP[N+1];
    DP[1] = 0;
    insert(line(-2*h[1], h[1]*h[1]));
    for(long long i = 2; i <= N; i++)
    {
        DP[i] = C + h[i]*h[i] + b_search(h[i], 0, L.size()-1);
        insert(line(-2*h[i], DP[i] + h[i]*h[i]));
    }
    cout << DP[N] << '\n';
    return 0;

    //DP[1] = 0;
    //DP[i] = C + h[i]^2 + min{1 <= j < i; (-2*h[j])*h[i] + (DP[j] + h[j]^2)}
}

Measured memory_bytes: 9200
#include<bits/stdc++.h>
	using namespace std;
	#define ll long long int
	#define pb push_back
	#define f first
	#define s second
	const int mod=1e9+7;
	#define all(x) x.begin(),x.end()
	#define endl '\n'
	#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
	//int arr[900006]
	int main(){
		IOS;
		int n,k;
		cin>>n>>k;
		int arr[n+1];
		int cnt=0;
		vector<int>adj[100005];
		for(int i=1;i<=n;i++)cin>>arr[i];
		for(int i=0;i<k;i++){
			int a,b;
			cin>>a>>b;
			adj[a].push_back(b);
			adj[b].push_back(a);
		}
		
		for(int i=1;i<=n;i++){
			bool f=1;
			for(auto u:adj[i]){
				if(arr[i]<=arr[u])f=0;
			}
			if(f)cnt++;
		}
		cout<<cnt<<endl;
		return 0;
	}


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

string S,T;

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

    int ans = 0;
    for(int i = 0;i < S.length();i++){
        if(S[i] != T[i]){
            ans++;
        }
    }
    cout << ans << endl;
}

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

public class Main {

  public static void main(String[] args) {
    // printTestValue();
    d();
  }

  public static void dTest() {
    long startTime = System.currentTimeMillis();
    d();
    long endTime = System.currentTimeMillis();
    System.out.println("処理時間：" + (endTime - startTime) + " ms");
  }

  public static void d() {

    try (Scanner sc = new Scanner(System.in)) {

      int listSize = Integer.parseInt(sc.next());
      Integer[] inputList = new Integer[listSize];
      for (int x = 0; x < listSize; x++) {
        inputList[x] = Integer.parseInt(sc.next());
      }
      Arrays.parallelSort(inputList);
      int[] resultList = new int[1000010];

      for (int checkNum : inputList) {
        if (resultList[checkNum] != 0) {
          resultList[checkNum]++;
          continue;
        }
        for (int targetMultiply = checkNum; targetMultiply < resultList.length;
          targetMultiply += checkNum) {
          resultList[targetMultiply]++;
        }
      }
      int ans = 0;
      for (int input : inputList) {
        if (resultList[input] == 1) ans++;
      }

      System.out.println(ans);

    } catch (Exception e) {
      System.out.println("エラー" + e);
    }
  }
  //
  // void tempCode() {
  // try (Scanner sc = new Scanner(System.in)) {
  // int a = Integer.parseInt(sc.next());
  // String b = sc.next();
  // }
  // }

  public static void printTestValue() {
    int valueA = (int) (2 * Math.pow(10d, 5d));
    int valueB = (int) Math.pow(10d, 6d);
    System.out.println(valueA);
    for (int x = 0; x < valueA; x++) {
      System.out.println(
        Math.round(Math.random() * Math.random() * Math.random() * valueB
          + Math.random() * 100));
    }
  }
}


Measured memory_bytes: 63864
#include "bits/stdc++.h"
using namespace std;
using ll = long long; using ull = unsigned long long;
#define int ll
using vb = vector<bool>; using vvb = vector<vb>;
using vi = vector<int>; using vvi = vector<vi>;
using vl = vector<ll>; using vvl = vector<vl>;
using pii = pair<int,int>; using pll = pair<ll,ll>;
#define FOR(i,a,b) for(ll i = (a); i < (ll)(b); ++i)
#define REP(i,n) FOR(i,0,n)
#define RFOR(i,a,b) for(ll i = (ll)(b)-1;i >= a;--i)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define eb(val) emplace_back(val)
const double PI = acos(-1);
const double EPS = 1e-10;
const ll MOD = 1e9+7;
void cioacc(){//accelerate cin/cout
  cin.tie(0);
  ios::sync_with_stdio(false);
}
pair<vl,vb> eratosthenes_sieve(ll n){
  vb is_prime(n+1,true);
  vl prime;
  is_prime[0] = false;
  is_prime[1] = false;
  FOR(i,2,sqrt(n)+1){
    if(!is_prime[i]) continue;
    for(ll j=2*i;j<=n;j+=i) is_prime[j] = false;
    prime.eb(i);
  }
  return {prime,is_prime};
}
signed main(){
  int n;
  cin >> n;
  vi s(n);
  REP(i,n) cin >> s[i];
  int q;
  cin >> q;
  int ans = 0;
  REP(i,q){
    int t;
    cin >> t;
    if(find(ALL(s),t)!=s.end()) ++ ans;
  }
  cout << ans << endl;
}



Measured memory_bytes: 3104