akhauriyash/Code-Regression huggingface dataset:
// Best practice
 
#include<bits/stdc++.h>
 
#define int         long long
#define pb          push_back
#define pf          emplace_front
#define all(a)      (a).begin(),(a).end()
#define rall(a)     (a).rbegin(),(a).rend()
#define pii 		pair<int,int>
#define psi 		pair<string,int>
#define vi 			vector<int>
#define vpii  		vector<pii>
#define vvi 		vector<vi>
#define sz(x)	    (int)(x).size()
#define x           first
#define y           second
#define endl        '\n'
#define tezz        ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define MOD         1000000007
#define hell        998244353
#define prec(n) 	fixed<<setprecision(n)
#define ini(a, i) 	memset(a, i, sizeof(a))
#define output(x)   cout << (x ? "YES" : "NO")<<endl;
using namespace std;
 
#define debug(vec) cout<<(#vec)<<" : [ "; for (auto& i: vec) cout<<i<<" "; cout<< "]" << endl
#define debugp(vec) cout<<(#vec)<<" : [ "; for (auto& i: vec) cout<<"("<<i.x<<","<<i.y<<")"<<" "; cout<< "]" << endl
#define trace(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args);cout << endl; }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cout << "[" << *it << ": " << a << "]\t";
    err(++it, args...);
}
 
// const int dx[4] = { -1, 1, 0, 0};
// const int dy[4] = {0, 0, -1, 1};
// int dX[] = { -1, -1, -1, 0, 0, 1, 1, 1 };
// int dY[] = { -1, 0, 1, -1, 1, -1, 0, 1 };
 
 
// Code from Here -------------------------------------------------------------------------------

const int nax = 2e5+5;
set<int> adj[nax];
int vis[nax];

int dfs(int k){
	vis[k]=1;
	int ans = 0;
	for(auto it: adj[k]){
		if(!vis[it]){
			ans += dfs(it);
		}
	}
	return ans+1;
}

signed main() {
	tezz
 

	int n, m, p, q;
	cin >> n >> m;	
	for(int i=0; i<m; i++){
		cin >> p >> q;
		adj[p].insert(q);
		adj[q].insert(p);
	}
	int ans = 1;
	for(int i=1; i<=n; i++){
		if(!vis[i]){
			ans = max(ans, dfs(i));
		}
	}
	cout << ans << endl;
 
	return 0;
}  

Measured memory_bytes: 42716
def popcount(i):
    assert 0 <= i < 0x100000000
    i = i - ((i >> 1) & 0x55555555)
    i = (i & 0x33333333) + ((i >> 2) & 0x33333333)
    return (((i + (i >> 4) & 0xF0F0F0F) * 0x1010101) & 0xffffffff) >> 24

N = int(input())
A = [list(map(int, input().split())) for _ in range(N)]
mod = 10**9+7

dp = [0]*(2**N)
dp[0] = 1

for S in range(1, 2**N):
    p = popcount(S)
    j = S & -S
    S2 = S
    for _ in range(p):
        if A[p-1][j.bit_length() - 1]:
            dp[S] = (dp[S - j] + dp[S])%mod
        S2 -= j
        j = S2 & -S2 
print(dp[-1])

Measured memory_bytes: 59484
from heapq import heapify,heappop,heappush

N = int(input())
task_list = []#締め切り、所要時間
heapify(task_list)
for i in range(0,N,1):
    a,b = map(int,input().split())
    heappush(task_list,[b,a])

now_time = 0
while len(task_list)>0:
    b,a = heappop(task_list)
    now_time += a
    if now_time > b:
        print("No")
        exit()
print("Yes")


Measured memory_bytes: 34816
#include <bits/stdc++.h>
using namespace std;
bool jishojun_hikaku(string x, string y) {
    for(int i = 0; i < x.size(); i++) {
        if(x.at(i)<y.at(i)) return true;
    }
    return false;
}

int main() {
    string s, t;
    cin >> s >> t;
    
    int m = s.size();
    int n = t.size();
    string ans, UNRESTORABLE;
    for(int i = 0; i < m; i++) {
        ans += '{';
        UNRESTORABLE += '{';
    }
    
    for(int i = 0; i < m-n+1; i++) {
        //条件1を満たすものを探す
        string tmp;
        for(int j = 0; j < i; j++) tmp += '?';
        tmp += t;
        for(int j = i+n; j < m; j++) tmp += '?';
        
        bool jouken_1 = true;
        for(int j = 0; j < m; j++) {
            if(!(tmp.at(j)=='?' || s.at(j)=='?' || tmp.at(j)==s.at(j))) jouken_1 = false;
        }
        if(!jouken_1) continue;
        
        //辞書順最強にする
        for(int j = 0; j < m; j++) {
            if(s.at(j)=='?' && tmp.at(j)=='?') tmp.at(j) = 'a';
            else if(s.at(j)!='?') tmp.at(j) = s.at(j);
        }

        //ansと比較
        if(jishojun_hikaku(tmp, ans)) ans = tmp;
    }
    
    if(ans == UNRESTORABLE) cout << "UNRESTORABLE" << endl;
    else cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
	int a[7]={1,3,5,7,8,10,12}, b[4]={4,6,9,11};
	int i, x, y, flagx=0, flagy=0;
	
	scanf("%d %d", &x, &y);
	
	for(i=0; i<7; i++){
	    if(x==a[i]){
	        flagx=1;
	    }
	    if(y==a[i]){
	        flagy=1;
	    }
	    
	}
	
	
	for(i=0; i<4; i++){
	    if(x==b[i]){
	        flagx=2;
	    }
	    if(y==b[i]){
	        flagy=2;
	    }
	    
	}
	
	if(flagx==flagy){
	    printf("Yes\n");
	}else{
	    printf("No\n");
	}
	
	
	
	
	return 0;
}

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

// 無限大を表す値
const long long INF = 1LL<<60;

// 辺を表す型，ここでは重みを表す型を long long 型とします
struct Edge {
    int to; // 隣接頂点番号
    long long w; // 重み
    Edge(int to, long long w) : to(to), w(w) {}
};

// 重み付きグラフを表す型，各頂点の隣接リストを辺集合で表す
typedef vector<vector<Edge> > Graph;

// 緩和処理 (更新が行われたときは true を返し，行われないときは false を返す)
bool chmin(long long& a, long long b) {
    if (a > b) {
        a = b;
        return true;
    }
    else return false;
}

int main() {
    // 頂点数と辺数，始点
    int N, M, s; cin >> N >> M >> s;

    // グラフ
    Graph G(N);
    for (int i = 0; i < M; ++i) {
        int a, b, w;
        cin >> a >> b >> w;
        G[a].push_back(Edge(b, w));
    }

    // Dijkstra 法
    vector<long long> dist(N, INF);
    dist[s] = 0;

    // (d[v], v) のペアを要素としたヒープを作ります
    priority_queue<pair<long long, int>,
                   vector<pair<long long, int> >,
                   greater<pair<long long, int> > > que;
    que.push(make_pair(dist[s], s));

    // Dijkstra 法の反復を開始
    while (!que.empty()) {
        // v: 使用済みでない頂点のうち d[v] が最小の頂点
        // d: v に対するキー値
        int v = que.top().second;
        long long d = que.top().first;
        que.pop();

        // d > dist[v] は，(d, v) がゴミであることを意味する
        if (d > dist[v]) continue; 

        // 頂点 v を始点とした辺たちを緩和
        for (auto e : G[v]) {
            if (chmin(dist[e.to], dist[v] + e.w)) {
                // 更新があるならヒープに新たに追加
                que.push(make_pair(dist[e.to], e.to)); 
            }
        }
    }
    
    // 結果出力
    for (int v = 0; v < N; ++v) {
        if (dist[v] < INF) cout << dist[v] << endl;
        else cout << "INF" << endl;
    }
}



Measured memory_bytes: 19296
import java.util.*;
class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int b = sc.nextInt();
    int c = sc.nextInt();
    int x = sc.nextInt();
    int y = sc.nextInt();
	double xr = (x*60 + y)/2.0;
    double yr = 6.0*y;
    double e = Math.max(xr-yr, yr-xr);
    double r = Math.sqrt(b*b + c*c - 2*b*c*Math.cos(Math.toRadians(e)));
 	
    System.out.println(r);
  }
 
}

Measured memory_bytes: 27184
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>

using namespace std;

void bfs(int S, int X, int Y, int N, vector<int>& ar)
{
    vector<bool> f(N, false);

    int cnt = 0;
    queue<pair<int, int>> next;
    next.push({cnt, S});

    while(!next.empty())
    {
        auto [step, now] = next.front(); next.pop();

        if(f[now]) continue;

        f[now] = true;
        ar[now] = step;

        if(now == X) next.push({step+1, Y});
        if(now == Y) next.push({step+1, X});
        if(now - 1 >= 0) next.push({step+1, now-1});
        if(now + 1 < N) next.push({step+1, now+1});
    }
}

int main()
{
    int N, X, Y; cin >> N >> X >> Y;

    vector<vector<int>> ar(N, vector<int>(N, 0));

    for(int i=0; i<N; ++i)
    {
        bfs(i, X-1, Y-1, N, ar[i]);
        sort(ar[i].begin(), ar[i].end());
    }

    for(int k=1; k<=N-1; ++k)
    {
        int ans = 0;
        for(int i=0; i<N; ++i)
        {
            auto itr = lower_bound(ar[i].begin(), ar[i].end(), k);
            auto itr2 = upper_bound(ar[i].begin(), ar[i].end(), k);

            if(*itr == k) ans += itr2 - itr;
        }

        cout << ans / 2 << endl;
    }
}

Measured memory_bytes: 18992
package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scanln(&n)

	a := make([]int, n)

	for i := 0; i < n; i++ {
		fmt.Scan(&a[i])
	}

	fmt.Println(logic(a))
}

func logic(a []int) int {
	sum := 0
	for i, num := range a {
		if i == len(a)-1 {
			return sum
		}

		for j := i + 1; j < len(a); j++ {
			sum += num * a[j]
		}
	}
	return sum
}


Measured memory_bytes: 512
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
#include<limits.h>
#include<deque>
#include<cstdio>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int N = 1000000;
const int mod = 998244353;
const ll INF = 1LL << 60;
#define rep(i,n) for(ll i=(ll)0;i<(ll)n;++i)
#define ALL(x) x.begin(),x.end()
#define pp pair<ll,ll>
#define fi first
#define se second
#define pb push_back
#define fix(n) fixed<<setprecision(n)
#define itr vector<ll>::iterator
ll n, v[200010],sum[200010],l[200010],r[200010],ans=INF;
int main() {
	cin >> n;
	rep(i, n)cin >> v[i], sum[i] = (i == 0 ? v[i] : sum[i - 1] + v[i]);
	for (ll i = 1; i <= n - 3;++i) {
		ll mn=INF;
		if (i == 1)l[i] = 0;
		else {
			for (ll j = l[i - 1]; j < i; ++j) {
				if (mn < abs(sum[i] - sum[j] - sum[j])) { l[i] = j - 1; break; }
				else mn = abs(sum[i] - sum[j] - sum[j]);
				if (j == i - 1)l[i] = j;
			}
		}
	}
	for (ll i = n - 3; i >= 1; --i) {
		ll mn = INF;
		if (i == n - 3)r[i] = n - 2;
		else {
			for (ll j = r[i + 1]; j > i; --j) {
				if (mn < abs(sum[n - 1] - sum[j] - (sum[j] - sum[i]))) { r[i] = j + 1; break; }
				else mn = abs(sum[n - 1] - sum[j] - (sum[j] - sum[i]));
				if (j == i + 1)r[i] = j;
			}
		}
	}
	for (int i = 1; i <= n - 3; ++i) {
		ll mx = max({ sum[l[i]],sum[i] - sum[l[i]],sum[r[i]] - sum[i],sum[n - 1] - sum[r[i]] });
		ll mn = min({ sum[l[i]],sum[i] - sum[l[i]],sum[r[i]] - sum[i],sum[n - 1] - sum[r[i]] });
		//cout << sum[l[i]]<<","<<sum[i] - sum[l[i]]<<","<< sum[r[i]] - sum[i]<<","<< sum[n - 1] - sum[r[i]] << endl;
		ans = min(ans,mx-mn);
	}
	cout << ans << endl;
	return 0;
}

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

class Node{
public:
  int location;
  int p,l,r;
  Node(){}
};

class Point{
public:
  int id,x,y;
  Point(){}
  Point(int id,int x,int y):id(id),x(x),y(y){}
  bool operator < (const Point &p) const{
    return (id < p.id);
  }
  void print(){
    printf("%d\n",id);
  }
};

static const int MAX = 1000000;
static const int NIL = -1;

int N;
Point P[MAX];
Node T[MAX];
int np;

bool lessX(const Point &p1, const Point &p2){return p1.x < p2.x;}
bool lessY(const Point &p1, const Point &p2){return p1.y < p2.y;}

int makeKDTree(int l,int r,int depth){
  if(!(l<r))return(NIL);
  int mid=(l+r)/2;
  int t = np++;
  
  if(depth%2 == 0)sort(P+l,P+r,lessX);
  else sort(P+l,P+r,lessY);
  
  T[t].location=mid;
  T[t].l = makeKDTree(l,mid,depth+1);
  T[t].r = makeKDTree(mid+1,r,depth+1);

  return t;
}

void find(int v,int sx,int tx,int sy,int ty,int depth,vector<Point> &ans){
  int x = P[T[v].location].x;
  int y = P[T[v].location].y;

  if(sx<=x && x<=tx && sy<=y && y<=ty)ans.push_back(P[T[v].location]);
  
  if(depth%2 == 0){
    if(T[v].l != NIL)if(sx<=x)find(T[v].l,sx,tx,sy,ty,depth+1,ans);
    if(T[v].r != NIL)if(x<=tx)find(T[v].r,sx,tx,sy,ty,depth+1,ans);
  }
  else{
    if(T[v].l != NIL)if(sy<=y)find(T[v].l,sx,tx,sy,ty,depth+1,ans);
    if(T[v].r != NIL)if(y<=ty)find(T[v].r,sx,tx,sy,ty,depth+1,ans);
  }
}



int main(){
  int x,y;
  scanf("%d",&N);
  for(int i=0;i<N;i++){
    scanf("%d %d",&x,&y);
    P[i] = Point(i,x,y);
    T[i].l = T[i].r = T[i].p = NIL;
  }

  np=0;
  
  int root = makeKDTree(0,N,0);
  
  int q;
  scanf("%d",&q);
  int sx,tx,sy,ty;
  vector<Point>ans;
  for(int i=0;i<q;i++){
    scanf("%d %d %d %d",&sx,&tx,&sy,&ty);
    ans.clear();
    find(root,sx,tx,sy,ty,0,ans);
    sort(ans.begin(),ans.end());
    for(int j=0;j<ans.size();j++)ans[j].print();
    printf("\n");
  }

  return(0);
}

Measured memory_bytes: 16424
N, M = map(int, input().split())
I = [N + 1 for i in range(N)]
for i in range(M):
  a, b = map(int, input().split())
  I[a - 1] = min(I[a - 1], b - 1)
cut = 0
for i in range(N - 1):
  if I[i] == i + 1:
    cut += 1
  else:
    I[i + 1] = min(I[i + 1], I[i])
print(cut)

Measured memory_bytes: 7088
# ans = len(list(more_itertools.unique_justseen(S))) - 1
# としたいが、more_itertoolsは入っていないみたいなので、
# https://github.com/erikrose/more-itertools/blob/master/more_itertools/recipes.py
# にある実装を流用している

def c_1d_reversi(S):
    # 端の同じ色の石は1個の石を置けばひっくり返せる
    # 連続した石をひとまとめにしたとき、何個の石があるかが解を導く

    def unique_justseen(iterable, key=None):
        from itertools import groupby
        from operator import itemgetter
        return map(next, map(itemgetter(1), groupby(iterable, key)))

    ans = len(list(unique_justseen(S))) - 1
    return ans

S = input()
print(c_1d_reversi(S))

Measured memory_bytes: 4132
#include <bits/stdc++.h>
#define ll long long
#define INF 999999999
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<n;++i)

using namespace std;

typedef pair<int,int>P;

const int MAX_N = 10005;

int dp[2][MAX_N/2][2];
int a[MAX_N];
int n;

int main()
{
	scanf("%d",&n);
	for(int i=1;i<n;i++){
		scanf("%d",&a[i]);
	}
	rep(i,2){
		rep(j,n/2+1){
			rep(k,2){
				dp[i][j][k] = INF;
			}
		}
	}
	rep(k,2){
		dp[0][0][k] = 0;
	}
	rep(i,n){
		rep(j,n/2+1){
			rep(k,2){
				dp[(i+1)%2][j][k] = INF;
			}
		}
		rep(j,n/2){
			dp[(i+1)%2][j+1][0] = min(dp[(i+1)%2][j+1][0],min(dp[i%2][j][0],dp[i%2][j][1]+a[i]));
			dp[(i+1)%2][j][1] = min(dp[(i+1)%2][j][1],min(dp[i%2][j][1],dp[i%2][j][0]+a[i]));
		}
	}
	int ans = INF;
	rep(k,2){
		ans = min(ans,dp[0][n/2][k]);
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 3308
#include <iostream>
#include <algorithm>
#include <vector>

int main () {
  int n;
  std::cin >> n;
  long int sum = 0;
  std::vector<int> a;
  for (int i = 0; i < n; i++)
  {
    int elem;
    std::cin >> elem;
    a.push_back(elem);
    sum += elem;
  }
  std::sort(a.begin(), a.end());

  std::cout << a.front() << " " << a.back() << " " << sum << std::endl;
  return 0;
}


Measured memory_bytes: 3180
// AtCoder Beginner Contest 126 - Problem B: Changing a Character (https://atcoder.jp/contests/abc126/tasks/abc126_b)
#include <bits/stdc++.h>

using namespace std;

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

    auto a = stoi(S.substr(0, 2)), b = stoi(S.substr(2));
    int f = 0;

    if (1 <= a and a <= 12)
        f |= 1;

    if (1 <= b and b <= 12)
        f |= 2;

    switch (f) {
    case 1:
        cout << "MMYY\n";
        break;
 
    case 2:
        cout << "YYMM\n";
        break;
 
    case 3:
        cout << "AMBIGUOUS\n";
        break;
 
    default:
        cout << "NA\n";
        break;
    }
 
    return 0;
}


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

int main(){
  int N,M;
  cin >> N >> M;
  vector<int> H(N);
  vector<vector<int>> near(N,vector<int>()); 
  int A,B;
  for(int i=0; i<N; i++){
    cin >> H[i];
  }
  for(int i=0; i<M; i++){
    cin >> A >> B;
    A--; B--;
    near[A].push_back(B);
    near[B].push_back(A);
  }
  int ans,moto,flag;
  ans =0;
  for(int i=0; i<N; i++){
    flag = 0;
    moto = H[i];
    for(int j=0; j<near[i].size(); j++){
      if(H[near[i][j]] >= moto){flag = 1;break;}
    }
    if(flag == 0) ans++;
  }
  cout << ans;
  return 0;
}

Measured memory_bytes: 8804
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <map>
#include <cstring>
#include <cmath>
using namespace std;
#define MAXH 1000000001
#define MAXW 1000000007
#define INF 1000000007
#define MAXN 100001
#define MOD 1000000007
typedef long long ll;
typedef pair<ll, ll> P;


template<typename T>
T pow(T i, T n){
    T re;
    if(n == 0) return 1;
    re = pow(i, n / 2);
    if(n % 2 == 0){
        return re * re;
    }else{
        return i * re * re;
    }
}
ll gcd(ll a, ll b){
    if(b == 0) return a;
    return gcd(b, a % b);
}

ll N, T;
ll A[MAXN], B[MAXN] ;

int main(){
    cin >> N >> T;
    for(int i = 0;i < N;i++){
        cin >> A[i];
    }

    ll mint = INF;
    for(int i = 0;i < N;i++){
        if(A[i] < mint){
            mint = A[i];
        }
        B[i] = A[i] - mint;
    }
    sort(B, B + N, greater<int>());
    ll ans = 0;
    for(int i = 0;i < N;i++){
        if(B[0] != B[i])break;
        ans++;
    }

    printf("%lld\n", ans);
    return 0;
}


        

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

bool onmp(int x,int y){return x>=0&&y>=0&&x<n&&y<n;}

bool check(const vector<string> &A){
  for(int i=0;i<n;i++)
    for(int j=0;j<n;j++)if(A[i][j]=='#')return 0;
  return 1;
}

int count(int x,int y,const vector<string> &A){
  int res=0;  
  for(int i=-1;i<=1;i++)
    for(int j=-1;j<=1;j++){
      int nx = x+i,ny = y+j;
      if((i||j)&&onmp(nx,ny))res += A[ny][nx]!='.';
    }
  return res;
}

vector<string> mkmp(const vector<string> &A){
  vector<string> res=A;
  for(int i=0;i<n;i++)
    for(int j=0;j<n;j++){
      int cnt = count(j,i,A);
      if(A[i][j]=='#')res[i][j]=(cnt==2||cnt==3)? '#':'.';
      if(A[i][j]=='.')res[i][j]=(cnt==3)? '#':'.';
      if(A[i][j]=='@')res[i][j]='@';
    }
  return res;
}


void getPos(vector<string>&A,int &x,int &y){
  for(int i=0;i<n&&x==-1;i++)
    for(int j=0;j<n&&x==-1;j++) if(A[i][j]=='@')x=j,y=i;
}

struct dat{
  int cost;
  vector<string> A;
};

int bfs(vector<string>start){
  queue<vector<string> > Q;
  map<vector<string>,int>D;
  Q.push(start);
  D[start]=0;

  while(!Q.empty()){
    vector<string> A=Q.front();Q.pop();
    int cost = D[A];
    int x = -1,y=-1;
    getPos(A,x,y);
    if(check(A))return cost;
    if(cost>=10)continue;

    A[y][x] = '.';
    for(int dy=-1;dy<=1;dy++)
      for(int dx=-1;dx<=1;dx++){
	int nx = x+dx,ny = y+dy;
	if((!dx&&!dy)||!onmp(nx,ny)||A[ny][nx]=='#')continue;
	A[ny][nx] = '@';
	vector<string> nA = mkmp(A);
	if(!D.count(nA))Q.push(nA),D[nA] = cost+1;
	A[ny][nx] = '.';
      }
  }
  return -1;
}

int main(){
  while(cin>>n,n){
    vector<string> mp(n);
    for(int i=0;i<n;i++)cin>>mp[i];
    cout<<bfs(mp)<<endl;
  }
  return 0;
}

Measured memory_bytes: 13632
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define z 500000000000000000
#define sh 500000

int main()
{

	
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int n,k,i;
	cin>>n>>k;
	int ar[n+1];
	for(i=1;i<=n;i++)
		cin>>ar[i];
	int dp[n+1];
	for(i=1;i<=n;i++)
		dp[i]=INT_MAX;
	dp[1]=0;
	
	for(i=2;i<=n;i++)
	{
		for(int j=1;j<=k&&(i-j)>0;j++)
			dp[i]=min(dp[i-j]+abs(ar[i]-ar[i-j]),dp[i]);
	}
	cout<<dp[n];

}

Measured memory_bytes: 1024
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>

using namespace std;
using ll = long long;

int main() {
    int N;cin >> N;
    ll ans = 0LL;
    for (int i = 0; i < N; ++i) {
        ll a; cin >> a;
        ans += a - 1LL;
    }
    cout << ans << endl;
    
    return 0;
}


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

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



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

// macro
#define rep(i,n) for(i=0;i<n;i++)
#define ll long long
#define all(v) v.begin(), v.end()

// code starts
int main()
{
  int n,q;cin>>n>>q;
  vector<int> s(n);
  vector<int> t(n);
  vector<int> x(n);
  vector<int> d(q);
  int i;
  rep(i,n)cin>>s[i]>>t[i]>>x[i];
  rep(i,q)cin>>d[i];
  vector<int> eve(n*2);
  vector<int> mode(n*2);
  vector<int> pl(n*2);
  rep(i,n)
  {
    eve[i]=s[i]-x[i];
    mode[i]=1;
    pl[i]=x[i];
  }
  rep(i,n)
  {
    eve[n+i]=t[i]-x[i];
    mode[n+i]=-1;
    pl[n+i]=x[i];
  }
  vector<tuple<int,int,int>> et(n*2);
  rep(i,n*2)
  {
    et[i]=make_tuple(eve[i],mode[i],pl[i]);
  }
  sort(all(et));
  set<int> ss;
  int next=get<0>(et[0]);
  int now=0;
  rep(i,q)
  {
    while(next<=d[i]&&now<n*2)
    {
      if(get<1>(et[now])==1)
      {
        ss.insert(get<2>(et[now]));
      }
      if(get<1>(et[now])==-1)
      {
        ss.erase(get<2>(et[now]));
      }
      now++;
      next=get<0>(et[now]);
    }
    if(ss.empty())
    {
      cout<<-1<<endl;
      continue;
    }
    cout<<*ss.begin()<<endl;
  }
}

Measured memory_bytes: 23168
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<cmath>
#include<string>
#include<functional>
using namespace std;
typedef	long long int ll;

int main(){
    int a, b;
    cin >> a >> b;
    if(a >= 9 || b >= 9) cout << ":(" << endl;
    else cout << "Yay!" << endl;
    return 0;
}

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

int main(){

    int x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;
    
    cout << x2 - (y2 - y1) << " " << y2 + (x2 - x1) << " " << x1 - (y2 - y1) << " " << y1 + (x2 - x1) << endl;

    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target ("avx2")
#include <bits/stdc++.h>
using namespace std ;
#define ll long long
void FastInputOutput(){
    ios_base :: sync_with_stdio( 0 ) ;
    cin.tie( 0 ) ;
    cout.tie( 0 ) ;
}

inline int D(){
    int t ;
    scanf( "%d" , &t ) ;
    return t ;
}
inline ll LLD(){
    ll t ;
    scanf( "%lld" , &t ) ;
    return t ;
}

ll power(ll x, ll p, ll m){
    ll res = 1;
    while(p){
        if(p&1)    res = (res * x)%m;
        x = (x * x)%m;
        p >>= 1;
    }
    return res;
}


int main(){
    printf(D() < 1000 ? "ABC" : "ABD");
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <cmath>
#include <cstring>
#include <ctime>
#include <unordered_map>
#include <iomanip>
using namespace std;

#define fi first
#define se second
#define pb push_back
#define all(v) (v).begin(),(v).end()

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pii;

template<class T> ostream& operator<<(ostream& stream, const vector<T> v){ stream << "["; for (int i=0; i<(int)v.size(); i++) cout << v[i] << " "; stream << "]"; return stream; }
ll fpow(ll x, ll p, ll m){ll r=1; for (;p>>=1;){ if (p&1) r=r*x%m; x=x*x%m; } return r;}
int gcd(int a, int b){ if (!b) return a; return gcd(b,a%b);}
ll gcd(ll a, ll b){ if (!b) return a; return gcd(b,a%b);}

string s;
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> s;

    cout << s.substr(0,(int)s.length()-8);
	return 0;
}


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

int main()
{
	string N;
	cin >> N;
	if (N[0] == N[1] && N[1] == N[2]) cout << "Yes" << endl;
	else if (N[1] == N[2] && N[2] == N[3]) cout << "Yes" << endl;
	else
	{
		cout << "No" << endl;
	}
}


Measured memory_bytes: 256
n = int(input())
l = list(map(int,input().split()))

anslist = []

while l:
    for i in range(len(l)-1,-1,-1):
        if l[i] == i+1:
            anslist.append(l.pop(i))
            break
    else:
        print(-1)
        exit()

anslist.reverse()
for i in anslist:
    print(i)

Measured memory_bytes: 63488
#include<iostream>
#include<string>
#include<algorithm>
#define P 1000000007
#define MAX 100005
using namespace std;
 
int main(){
  string s;
  long long a[MAX], c[MAX], q[MAX];
  a[0] = 0; c[0] = 0; q[0] = 0;
  long long ans0 = 0, ans1 = 0, ans2 = 0, ans3 = 0, ans = 0;
  long long power = 1;
  cin >> s;
  
  for(int i = 0; i < s.size(); ++i){
    a[i+1] = a[i] + ((s[i] == 'A') ? 1 : 0);
    c[i+1] = c[i] + ((s[i] == 'C') ? 1 : 0);
    q[i+1] = q[i] + ((s[i] == '?') ? 1 : 0);
  }
  
  for(int i = 0; i < s.size(); ++i){
    if(s[i] == 'B'){
      ans0 += a[i] * (c[s.size()] - c[i+1]);
      ans1 += q[i] * (c[s.size()] - c[i+1]) + a[i] * (q[s.size()] - q[i+1]);
      ans2 += q[i] * (q[s.size()] - q[i+1]);
    }
    if(s[i] == '?'){
      ans1 += a[i] * (c[s.size()] - c[i+1]);
      ans2 += q[i] * (c[s.size()] - c[i+1]) + a[i] * (q[s.size()] - q[i+1]);
      ans3 += q[i] * (q[s.size()] - q[i+1]);
    }
  }
  ans0 %= P; ans1 %= P; ans2 %= P; ans3 %= P;
  
  if(q[s.size()] >= 3){
    for(int i = 0; i < q[s.size()]-3; ++i)
      power = power * 3 % P;
    ans = (ans0 * 27 + ans1 * 9 + ans2 * 3 + ans3)%P*power%P;
  }else if(q[s.size()] == 2){
    ans = (ans0 * 9 + ans1 * 3 + ans2) % P;
  }else if(q[s.size()] == 1){
    ans = (ans0 * 3 + ans1) % P;
  }else if(q[s.size()] == 0){
    ans = ans0;
  }
  cout << ans << endl;
}


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

#define int long long
typedef vector< int > vi;
typedef vector< vi > vvi;
typedef pair< int,int > ii;
#define sz(a) int((a).size())
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(typeof((c)).begin() i = (c).begin(); i != (c).end(); i++)
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
const int N=1e5+5;
const int INF = 1e9;

 

 
int32_t main()
{
	IOS;
	int n,k,cnt =0;
	cin>>n>>k;
	vector <char> v(n);
	for(int i =0; i<n; i++) cin>>v[i];

	//debug
	// for(int i=0; i<n; i++) cout<<v[i];
	// for(int i=0; i<n; i++) cout<<b[i];
	// for(int i=0; i<n-1; i++) cout<<c[i];

	for(int i=1; i<n; i++)
		if(v[i-1] == v[i])
			cnt++;

	cnt = min(n-1, cnt+2*k);
	cout<<cnt<<endl;

	return 0;
}



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

using namespace std;
using ll = long long;
using P = pair<int, int>;
using LP = pair<ll, ll>;

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

    int n;
    cin>>n;

    int temp = n;
    int d = 0;
    while (temp > 0) {
        d++;
        temp /= 10;
    }

    ll ans = 0;
    ll p = 1;
    rep(i, d / 2) {
        ans += 9 * p;
        p *= 100;
    }
    if (d % 2 == 1) {
        ans += n - p + 1;
    }
    cout<<ans<<endl;
}

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

using namespace std;

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

typedef long long i64;
typedef pair<i64, i64> pii;

constexpr int INF = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;

signed main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> a(n + 1);
  reps(i, 1, n) cin >> a[i];

  vector<int> put(n + 1);
  vector<int> b;
  for (int i = n; i >= 1; --i) {
    int cnt  = 0;
    for (int j = i; j <= n; j += i) {
      cnt ^= put[j];
    }
    if (cnt != a[i]) {
      put[i] = 1;
      b.push_back(i);
    }
  }

  cout << b.size() << "\n";
  for (int i = 0; i < b.size(); ++i) {
    cout << b[i];
    if (i < b.size() - 1) cout << ' ';
    else cout << "\n";
  }

  return 0;
}

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

int main()
{
	string s;
	cin >> s;
	int n = s.length();
	
	int i = 0;
	int j = n - 1;
	int res = 0;
	while (i < j) {
		if (s[i] != s[j]) {
			if (s[i] != 'x'&&s[j] != 'x') {
				cout << -1 << endl;
				return 0;
			}
			if (s[i] == 'x') {
				i++;
			}
			else {
				j--;
			}
			res++;
		}
		else {
			i++;
			j--;
		}
	}

	cout << res << endl;

	return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <utility>
#include <stdint.h>
#include <map>
#include <vector>
#include <string>

using namespace std;

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

  map<map<char, int>, int> S;
  
  for (int n=0; n<N; ++n) {
    string s;
    cin >> s;
    map<char, int> m;
    for (char c : s) {
      if (m.count(c) == 0)
	m[c] = 1;
      else
	++m[c];
    }
    if (S.count(m) == 0)
      S[m] = 1;
    else
      ++S[m];
  }

  uint64_t count = 0;
  for (auto s : S) {
    //cerr << ' ' << s.second << endl;
    count += (uint64_t)s.second * (uint64_t)(s.second-1) / 2;
  }

  cout << count << endl;

  return 0;
}


Measured memory_bytes: 49152
#include <bits/stdc++.h>
using namespace std;
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
typedef long long ll;
typedef unsigned long long ull;
#define FIN ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define forr(i, a, b) for(ll i = (a); i < (ll) (b); i++)
#define forn(i, n) forr(i, 0, n)
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define DBG(x) cerr << #x << " = " << (x) << endl
#define MOD 1000000007
#define MAXN 100005
ll dp[MAXN][3];
void solve(vector< vector<ll> > &a, int n)
{
    forn(i,MAXN)
    {
        forn(j,3)
        {
            dp[i][j]=(pow(10,9)+5)*(ll)(-1);
        }
    }
    dp[0][0]=a[0][0], dp[0][1]=a[0][1], dp[0][2]=a[0][2];
    forr(i,1,n)
    {
        forn(j,3)
        {
            forn(k,3)
            {
                if(j==k)
                {
                    continue;
                }
                else dp[i][j]=max(dp[i][j],dp[i-1][k]+a[i][j]);
            }
        }

    }
    cout << max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2])) << "\n";
}

int main() {
    FIN;
    int n;
    cin >> n;
    vector< vector<ll> > arreglo(n);
    forn(i,n) arreglo[i].resize(3);
    forn(i,n)
    {
        forn(j,3) cin >> arreglo[i][j];
    }
    solve(arreglo, n);
    return 0;
}


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

int main(){
	int n,c,k;
	cin >> n >> c >> k;
	int t[n];
	for(int i=0;i<n;i++)
		cin >> t[i];
	sort(t,t+n);
	int cur=0,curl=t[0]+k,ans=1;
	for(int i=0;i<n;i++){
		if(t[i]<=curl && cur<c){
			cur+=1;
		}
		else{
			cur=1;
			curl=t[i]+k;
			ans+=1;
		}
	}
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>

using namespace std;
typedef long long ll;

int main() {
    int N, M;
    cin >> N >> M;
    int k;
    vector<vector<int>> s(M, vector<int>(N, 0));
    for(int i = 0; i < M; i++) {
        cin >> k;
        for(int j = 0; j < k; j++) {
            int t;
            cin >> t;
            t--;
            s[i][t] = 1;
        }
    }
    vector<int> p(M);
    for(int i = 0; i < M; i++) {
        cin >> p[i];
    }
    int ans = 0;
    for(int bit = 0; bit < (1 << N); bit++) {
        int lit = 0;
        for(int l = 0; l < M; l++) {
            int count = 0;
            for(int sw = 0; sw < N; sw++) {
                if(bit >> sw & 1 && s[l][sw] == 1) {
                    count++;
                }
            }
            if(count % 2 == p[l]) lit++;
        }
        if(lit == M) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3652
io = STDIN
s,t=io.gets.chomp.split
a,b=io.gets.split.map(&:to_i)
u=io.gets.chomp
if s==u
  puts "#{a-1} #{b}"
elsif t==u
  puts "#{a} #{b-1}"
else
  puts "#{a} #{b}"
end


Measured memory_bytes: 1788
#include<stdio.h>
int main(void)
{
  int n,count=0;;
  char a[128],b[128],c[128];
  scanf("%d %s %s %s",&n,a,b,c);
  for(int i=0;i<n;i++){
    if(a[i]!=b[i]&&a[i]!=c[i]&&b[i]!=c[i]){
      count+=2;
    }else if(a[i]!=b[i]||a[i]!=c[i]||b[i]!=c[i]){
      count++;
    }
    //printf("%d\n",count);

  }

  printf("%d\n",count);
  return 0;
}


Measured memory_bytes: 1708
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "iomanip"
#include "cmath"

using namespace std;

const long long int MOD = 1000000007;

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

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

	string s;
	cin >> s;
	int n = s.size();
	if (n == 1) {
		cout << 1 << endl;
		return 0;
	}
	s.push_back('"');
	vector<int>v;
	char bef = '8';
	int box = 0;
	for (auto i : s) {
		if (bef == i) {
			box++;
		}
		else {
			v.push_back(box);
			bef = i;
			box = 1;
		}
	}
	v.push_back(0);
	if (v.size() == 4) {
		cout << max(v[1], v[2]) << endl;
		return 0;
	}
	N = v.size();
	for (int i = 1; i < N; i++) {
		v[i] += v[i - 1];
	}
	int ans = INT_MAX;
	for (int i = 1; i < N; i++) {
		ans = min(ans, max(v[i],n - v[i]));
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 720
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5+5;
typedef long long ll;
ll abi[maxn];
int N;
int h[maxn],b[maxn];
void update(int pos,ll v){
    for (;pos<= N;pos+=pos&-pos)
        abi[pos] = max(abi[pos],v);
}
ll query(int pos){
    ll sum = 0;
    for (;pos;pos-=pos&-pos)
        sum = max(abi[pos],sum);
    return sum;
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    //freopen(".in","r",stdin);
    cin >> N;
    for (int i = 1; i <= N;i++){
        cin >> h[i];
    }
    for (int i = 1; i <= N;i++){
        cin >> b[i];
    }
    for (int i = 1; i <= N;i++){
        ll x = query(h[i]-1)+b[i];
        update(h[i],x);
    }
    cout << query(N);
    return 0;
}


Measured memory_bytes: 3328
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
#include <cstdio>
#include <cstring>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>

typedef long long ll;
typedef unsigned long long ull;
using namespace std;

#define FALSE printf("false\n");
#define TRUE printf("true\n");
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i = 0;i < ((int)(n));++i)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define test(a) cout<<"line:"<<__LINE__<<"["<<(#a)<<": "<<(a)<<"]"<<endl

const int INF = 1e9+7;
const ll INFL = 9*1e18;

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

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

#define SUM(vec) accumulate(all(vec),0LL) // 配列の中身を全部足す
template<typename T>void print(T&& x){cout<<x<<endl;}// 改行付き出力
ll inline digit(ll num){int tmp = 0;while(num){tmp++;num/=10;}return tmp;} // 桁数
template<typename T>inline T digitSum(T num){T sum = 0;while(num){sum+=num%10;num/=10;}return sum;} // 各桁の和
template<typename T>inline T gcd(T a,T b){if(b == 0)return a;return gcd(b,a%b);} // 最大公約数
template<typename T>inline T lcm(T a, T b){T g = gcd(a,b);return a/g*b;} // 最小公倍数
template<typename T>inline T power(T a,T b){T tmp=1;rep(i,b){tmp*=a;}return tmp;} // 累乗
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 ctoi(char c){return c-'0';}

void dfs(string s,int size){
  int last = 0;
  rep(i,size)chmax(last,s[i]-'a');
  last += 2;
  if(s.length() == 0)last--;
  if(s.length() == size){
    print(s);
  }else{
    rep(i,last){
      dfs(s+(char)(i+'a'),size);
    }
  }
}

// TODO: write
int main() {
  int n;cin>>n;
  string s;
  dfs(s,n);
  
  return 0;
}


Measured memory_bytes: 1536
#include<stdio.h>

int main(){

	long long a, b, gcd, lcm, pool, swap;
	
	while(scanf("%ld%ld", &a, &b) != EOF){
		
		gcd = a;
		pool = b;
		lcm = 0;

		while(gcd != pool){
			if(gcd < pool){
				
				swap = gcd;
				gcd = pool;
				pool = swap;
				
			}
			gcd = gcd - pool;
		
		}

	lcm = (a * b) / gcd;
	
	printf("%d %d\n", gcd, lcm);
	
	}
	
    return 0;
}

Measured memory_bytes: 596
// ------------------------------------
// Date:2018/ 3/10
// Problem:ABC 070 TransitTreePath d.cpp
//
// ------------------------------------

// dijkstraはパスが一意に定まらない時に使う。

#include <bits/stdc++.h>

using namespace std;

#define EACH(i,a) for (auto&& i : a)
#define FOR(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RFOR(i,a,b) for(int i=(int)b-1;i>=(int)a;--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define debug(x) cerr << #x << ":" << x << endl

typedef long long ll;

static const int INF = 1000000001;
static const int MAX_N = 101010;

struct Line {
  Line(int _to, int _cost)
    : to(_to), cost(_cost) {}
  int to;
  int cost;
};

vector< Line > l[MAX_N];
// d[to]
ll d[MAX_N];


int N;

void bfs(int start)
{
  // q(to)
  queue< int > q;
  q.push(start);
  while(!q.empty()) {
    int from = q.front();
    q.pop();
    REP(to, l[from].size()) {
      Line ml = l[from][to];
      if (d[ml.to] >= 0) continue;
      d[ml.to] = d[from] + ml.cost;
      q.push(ml.to);
    }
  }
}

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

  memset(d, -1ll, sizeof(d));
  cin >> N;

  REP(i, N - 1) {
    int a, b, c;
    cin >> a >> b >> c;
    a--;
    b--;
    l[a].emplace_back(Line(b, c));
    l[b].emplace_back(Line(a, c));
  }

  
  int Q, K;
  cin >> Q >> K;

  d[K - 1] = 0;
  bfs(K - 1);
  
  REP(i, Q) {
    int x, y;
    cin >> x >> y;
    cout << d[x - 1] + d[y - 1] << endl;
  }
  
  
  return 0;
}



Measured memory_bytes: 9856
#include <bits/stdc++.h>
#define int long long
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef pair<int,int>P;
#define fi first
#define se second
int h,w;
int dp[100009];
signed main(){
  int n,k;
  cin>>n>>k;
  if(k==0){
    cout<<n*n<<endl;
    return 0;
  }
  int sum=0;
  for(int i=k+1;i<=n;i++){
    int p=n/i;
    int x=n%i;
    sum+=(i-k)*p;
    if(x>=k)sum+=(x-k+1);
  }
  cout<<sum<<endl;
}

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

using namespace std;

int main(){
    int N;
    while(cin >> N){
        string A, B, C; cin >> A >> B >> C;
        int res = 0;
        for(int i=0;i<N;i++){
            if(A[i] == B[i] && B[i] == C[i]) continue;
            if(A[i] == B[i] || B[i] == C[i] || C[i] == A[i]) res++;
            else res += 2;
        }
        cout << res << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <queue>

using namespace std;

const int nmax = 1e9 + 7;
const long long INF = 1e16;
typedef long long ll;

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

  vector < pair<int, int> > AB(N);
  for (int i = 0; i < N; i++){
    int A, B; cin >> A >> B;
    AB[i] = make_pair(A, B);
  }
  sort(AB.begin(), AB.end());
  
  int ans = 0, now = 0;
  priority_queue <int> money;
  money.push(0);
  for (int i = 0; i <= M; i++){
    for (int j = now; j < N; j++){
      if (AB[j].first == i){
        money.push(AB[j].second);
        now++;
      }else{
        break;
      }
    }
    ans += money.top();
    if (money.top() != 0){
      money.pop();
    }
    
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1660
package main

import (
	"bufio"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func scanInt() int {
	sc.Scan()
	iv, _ := strconv.Atoi(sc.Text())
	return iv
}

func init() {
	sc.Split(bufio.ScanWords)
}

func main() {
	h, w, n := scanInt(), scanInt(), scanInt()
	a := make([]int, n)
	for i := range a {
		a[i] = scanInt()
	}

	ans := make([][]int, h)
	for i := range ans {
		ans[i] = make([]int, w)
	}

	x, y, d := -1, 0, 1
	for i, v := range a {
		for j := 0; j < v; j++ {
			if d == 1 {
				x++
				if x == w {
					x--
					y++
					d = -1
				}
			} else {
				x--
				if x == -1 {
					x++
					y++
					d = 1
				}
			}
			ans[y][x] = i + 1
		}
	}

	var wr = bufio.NewWriter(os.Stdout)
	for i := range ans {
		for j := range ans[i] {
			wr.WriteString(strconv.Itoa(ans[i][j]))
			if j < len(ans[i])-1 {
				wr.WriteString(" ")
			} else {
				wr.WriteString("\n")
			}
		}
	}
	wr.Flush()
}


Measured memory_bytes: 896
#include<bits/stdc++.h>
typedef long long ll;
#define REP(i,n) for(int i = 0;i < (n);i++)
#define rep(i,m,n) for(int i = (m);i < (n);i++)
#define P pair<int,int>
#define pb push_back
#define mk make_pair
using namespace std;
#define Vec(a) vector <int> a
#define F first
#define S second
const int INF = 1 << 20;
const int MOD = 1e9+7;





int main(){
    int a,b,q;
    cin >> a >> b >> q;
    vector <ll> s(a);
    vector <ll> t(b);
    REP(i,a){
        cin >> s[i];
    }
    REP(i,b){
        cin >> t[i];
    }
    REP(i,q){
        ll x;
        cin >> x;
        int sf,tf;
        sf = lower_bound(s.begin(),s.end(),x) - s.begin();
        tf = lower_bound(t.begin(),t.end(),x) - t.begin();
        
        if(1){
            ll res = 100000000000000;
            ll c = 1000000000000000 , d = 1000000000000;
            if(s[a-1] >= x)
                c = s[sf] - x;

            //cout << t[1] << "   " << x << endl;
            if(t[b-1] >= x){ 
                d = t[tf] - x;
            }

            ll cc = 10000000000000000, dd = 10000000000000000;
            if(s[0] <= x)
                cc = x - s[sf-1];
            if(t[0] <= x) 
                dd = x - t[tf-1];

            //cout << c << "   " << d << "   " << cc << "    " << dd << endl;
 
            res = min(res, max(c,d));
            if(c == 0)
                cc = 0;
            if(d == 0)
                dd = 0;
              
            res = min(res,min(cc,d) * 2 + max(cc,d));
            res = min(res,min(dd,c) * 2 + max(dd,c));
            res = min(res,max(cc,dd));
            cout << res << endl; continue;
        }
        
    }

    return 0;
}


Measured memory_bytes: 2944
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

using boost::multiprecision::cpp_int;
using namespace std;

#if __has_include("print.hpp")
  #include "print.hpp"
#endif

#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()
#define MOD 1000000007

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

typedef long long ll;
typedef pair<ll, ll> p;


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int a, b;
  cin >> a >> b;
  cout << a * b << endl;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define INF 1000000000
using namespace std;

int main()
{
  int N, M, Q;
  cin >> N >> M >> Q;
  int L, R, p, q;
  vector<vector<int>> start(N + 1, vector<int>(0));
  vector<vector<int>> end(N + 1, vector<int>(0));
  vector<vector<int>> dp(N + 1, vector<int>(N + 1, 0));
  for (int i = 0; i < M; ++i)
  {
    cin >> L >> R;
    start.at(L - 1).push_back(R - 1);
    end.at(R - 1).push_back(L - 1);
    if (L == 1 && R == 1)
    {
      dp.at(0).at(0) += 1;
    }
  }

  for (int i = 0; i < N; ++i)
  {
    for (int j = i; j < N; ++j)
    {
      // cout << "i" << i << j;
      int dec = 0, inc = 0;
      for (int k = 0; k < start.at(i).size(); ++k)
      {
        if (start.at(i).at(k) <= j)
        {
          dec += 1;
        }
      }
      for (int k = 0; k < end.at(j + 1).size(); ++k)
      {
        if (end.at(j + 1).at(k) >= i)
        {
          inc += 1;
        }
      }
      dp.at(i + 1).at(j) = dp.at(i).at(j) - dec;
      dp.at(i).at(j + 1) = dp.at(i).at(j) + inc;
      // cout << "inc" << inc << dec << endl;
    }
  }
  for (int i = 0; i < Q; ++i)
  {
    cin >> p >> q;
    cout << dp.at(p - 1).at(q - 1) << endl;
  }
  // for (int i = 0; i < N; ++i)
  // {
  //   for (int j = 0; j < N; ++j)
  //   {
  //     cout << dp.at(i).at(j);
  //   }
  //   cout << endl;
  // }
}


Measured memory_bytes: 4480
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp15
{
    class Class177
    {
        static void Main()
        {
            var S = Console.ReadLine();
            char color = S[0];
            int count = 0;
            for(int i = 0; i < S.Length; i++)
            {
                if (color == S[i]) continue;
                color = S[i];
                count++;
            }
            Console.WriteLine(count);
        }
    }
}


Measured memory_bytes: 13140
#include <cstdio>
#include <algorithm>
#include <cctype>
#include <cstring>
#include <vector>
using namespace std;
inline int read(int f = 1, int 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;
}
const int N = 2e5+5;
int n, k, c[2], f[3], a[3][N], d[N], p[N]; vector<int> e[N];
void dfs(int x, int fa)
{ ++c[d[x]]; for(auto y:e[x]) if(y != fa) d[y] = d[x]^1, dfs(y, x); }
int main()
{
    n = read(); for(int i = 1, x, y; i < n; ++i) x = read(), y = read(), e[x].push_back(y), e[y].push_back(x);
    dfs(1, 0), k = c[0]<c[1]?0:1;
    for(int i = 1; i <= n; ++i) a[i%3][(i-1)/3+1] = i;
    if(c[k] <= n/3)
    {
        for(int i = 1; i <= n; ++i)
            if(d[i] == k) p[i] = a[0][++f[0]];
            else if(f[2] < (n+1)/3) p[i] = a[2][++f[2]];
            else if(f[1] < (n+2)/3) p[i] = a[1][++f[1]];
            else p[i] = a[0][++f[0]];
    }
    else 
    {
        for(int i = 1; i <= n; ++i)
            if(d[i] == k) 
            {
                if(f[2] < (n+1)/3) p[i] = a[2][++f[2]];
                else p[i] = a[0][++f[0]];
            }
            else if(f[1] < (n+2)/3) p[i] = a[1][++f[1]];
            else p[i] = a[0][++f[0]];     
    }
    for(int i = 1; i <= n; ++i) printf("%d ", p[i]); puts("");
    return 0;
}

Measured memory_bytes: 21248
#include "bits/stdc++.h"
using namespace std;
#define int long long
#define endl '\n'
int mod=1e9+7;
int mod2=998244353;
const int INF=1e9;

signed main(){
  int k,a,b;
  cin>>k>>a>>b;
  int p=a-b;
  if(k<=a){
    cout<<1<<endl;
    return 0;
  }
  if(p<=0){
    cout<<-1<<endl;
    return 0;
  }
  int ans=(k-a)/p;
  if((k-a)%p!=0)ans++;
  cout<<ans*2+1<<endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
#include <string.h>
int main(void) {
	int a, b, c, d;
	scanf("%d%d%d%d", &a, &b, &c, &d);

	if (abs(a - c) <= d || (abs(a - b) <= d && abs(b - c) <= d)) {
		printf("Yes");
	}
	else printf("No");
	
	return 0;

}

Measured memory_bytes: 128
N,M = [int(i) for i in input().split()]
s = [0] * M
c = [0] * M
for i in range(M):
    s[i],c[i] = [int(j) for j in input().split()]
find = [False] * N
if N == 1:
    for i in range(10):
        i = str(i)
        count = 0
        for j in range(M):
            if i[s[j]-1] != str(c[j]):
                continue
            count +=1
        if count == M:
            print(i)
            exit()
    print(-1)
    exit()
if N == 2:
    for i in range(10,100):
        count = 0
        for j in range(M):
            i = str(i)
            if i[s[j]-1] != str(c[j]):
                continue
            count +=1
        if count == M:
            print(i)
            exit()
    print(-1)
    exit()
if N == 3:
    for i in range(100,1000):
        count = 0
        i = str(i)
        for j in range(M):
            if i[s[j]-1] == str(c[j]):
                count+=1
        if count == M:
            print(i)
            exit()
    print(-1)
    exit()

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <cstring>

using namespace std;
// ascending order
#define vsort(v) sort(v.begin(), v.end())
// descending order
#define vsort_r(v) sort(v.begin(), v.end(), greater<int>())
#define vunique(v) unique(v.begin(), v.end())
#define mp make_pair
#define ts(x) to_string(x)
#define rep(i, a, b) for(int i = (int)a; i < (int)b; i++)
#define repm(i, a, b) for(int i = (int)a; i > (int)b; i--)
#define bit(a) bitset<8>(a)
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1e18;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, a;
	cin >> n >> a;
	int tmp = n * n;
	int ans = tmp - a;
	cout << ans << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
    int n;
    cin>>n;
    while(n--)
    {
        int t,a,b;
        cin>>t>>a>>b;
        if(abs(a)+abs(b)>t||((int)(abs(a)+abs(b))%2)^(t%2))
        {
            cout<<"No"<<endl;
            return 0;
        }
    }
    cout<<"Yes"<<endl;
    return 0;
}

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

int main(){
  int n;
  int cnt = 0;
  cin >> n;
  for(int i = 0; i < n; i++){
    int a;
    cin >> a;
    while(a % 2 == 0){
      cnt++;
      a /= 2;
    }
  }
  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 256