akhauriyash/Code-Regression huggingface dataset:
/*

                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . __
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                    prayer
*/

// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(long long i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) {rep(_,v.size())cout<<" "<<v[_];cout<<endl;}
#define show2d(v) {rep(__,v.size())show1d(v[__]);}
using namespace std;
//kaewasuretyuui
typedef long long ll;
#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
#define mt make_tuple
typedef tuple<int,int,int,int> tp;
typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
#define yes cout<<"Yes\n"
#define no cout<<"No\n"

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

	int n;
	cin>>n;
	vi in(n);
	rep(i,n)cin>>in[i];
	int out=inf;
	rep(i,n){
		int a=0,b=0;
		rep(j,n)if(j<i)a+=in[j];else b+=in[j];
		cmin(out,abs(a-b));
	}
	cout<<out<<endl;
}


Measured memory_bytes: 256
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<unordered_map>
#include<array>
#include<map>
#include<bitset>
#include<iomanip>
#include<list>
#include <numeric>
using namespace std;
typedef unsigned long long int ulint;
typedef long long int llint;
typedef long double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
#define RE return 0
//ios::sync_with_stdio(false);
//std::cin.tie(0);
//<< setprecision(20)
const int mod=(int)1e9+7;
const llint big=(llint)(2.19e15+1);
const long double pai=3.141592653589793238462643383279502884197;
const long double ena=2.71828182845904523536;
const long double eps=1e-7;
template <class T,class U>bool mineq(T& a,U b){if(a>b){a=b;return true;}return false;}
template <class T,class U>bool maxeq(T& a,U b){if(a<b){a=b;return true;}return false;}
template <class T> void soun(T& ar)
{sort(ar.begin(),ar.end());ar.erase(unique(ar.begin(),ar.end()),ar.end());}
llint gcd(llint a,llint b){if(a%b==0){return b;}else{return gcd(b,a%b);}}
llint lcm(llint a,llint b){return a/gcd(a,b) *b;}
template<class T,class U> auto LB(T& ve,U in){return lower_bound(ve.begin(),ve.end(),in);}
template<class T,class U> auto UB(T& ve,U in){return upper_bound(ve.begin(),ve.end(),in);}
template<class T,class U> auto LBI(T& ve,U in){return LB(ve,in)-ve.begin();}
template<class T,class U> auto UBI(T& ve,U in){return UB(ve,in)-ve.begin();}
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());}
int main(void){
	int i,j,n,m;cin>>n>>m;
	int ar[100][100]={0};
	for(i=0;i<n;i++){
		for(j=0;j<m;j++){
			cin>>ar[i][j];
		}
	}
	int br[100]={0};
	for(i=0;i<m;i++){cin>>br[i];}
	for(i=0;i<n;i++){
		int ans=0;
		for(j=0;j<m;j++){ans+=ar[i][j]*br[j];}
		cout<<ans<<endl;
	}
	RE;
}


Measured memory_bytes: 3156
#include <algorithm>
#include<stdio.h>
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include <stack>
#include <queue>
#include<map>
#include <set>
#include<math.h>
using namespace std;
#define int long long
#define ll long long
#define rep(i,n) for(ll i=0;i<n;++i)
#define Rep(i,n) for(ll i=1;i<=n;++i)
#define loop(i,m,n) for(ll i=m;i<n;++i)
#define ggr getchar(); getchar();return 0;
#define pie 3.141592653589793238462643383279
#define elif else if
#define P pair<ll,ll>
#define prique priority_queue<ll>
#define all(a)  (a).begin(),(a).end()
const int mod = 1000000007;
const int mod2 = 998244353;
int bin(int bina) {
	int ans = 0;
	for (int i = 0; bina > 0; i++)
	{
		ans = ans + (bina % 2) * pow(10, i);
		bina = bina / 2;
	}
	return ans;
}
bool prime(int n) {
	for (ll i = 2; i <= sqrt(n); i++) {
		if (n % i == 0)return false;
	}
	return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x * y / gcd(x, y);
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i; res %= mod;
	}
	return res;
}
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x,y)* mod_pow(kai(y,y), mod - 2, mod) % mod;
}
int per(int n, int r) {
	r = n - r;
	int sum = 1;
	int i;
	for (i = n; i >= r + 1; i--)sum *= i;
	return sum;
}
struct UnionFind {
	vector<int> par;

	UnionFind(int n) : par(n, -1) { }

	int root(int x) {
		if (par[x] < 0) return x;
		else return par[x] = root(par[x]);
	}

	bool issame(int x, int y) {
		return root(x) == root(y);
	}

	bool merge(int x, int y) {
		x = root(x); y = root(y);
		if (x == y) return false;
		if (par[x] > par[y]) swap(x, y);
		par[x] += par[y];
		par[y] = x;
		return true;
	}

	int size(int x) {
		return -par[root(x)];
	}
};
int n, a[300010];
signed main() {
	cin >> n;
	rep(i, n) {
		cin >> a[i];
	}
	int ans = 0;
	rep(i, 60) {
		int s1 = 0, s0 = 0;
		rep(j, n) {
			if ((a[j] >> i) & 1)s1++;
			else s0++;
		}
		int iwa = (1ll << i) % mod;
		int ta = s0 * s1 % mod;
		iwa = iwa * ta % mod;
		ans = (ans + iwa) % mod;
	}
	cout << ans << endl;
}


Measured memory_bytes: 2560
//============================================================================
// Name        : AOL.cpp
// Author      : Akari Fujii
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
using namespace std;

int main() {
    int n;
    int m;
    int a[1001];
    int b[1001];
    int tokuten[1001]={};

    cin>>n>>m;

    for(int i=1; i<n+1; i++){
    	cin>>a[i];
	}
    for(int j=1; j<m+1; j++){
    	cin>>b[j];

    }

    for(int j=1; j<m+1; j++){
    	int s=0;

    	for(int i=1; i<n+1; i++){
    		if((s==0)&&(a[i]<=b[j])){
    			tokuten[i]+=1;
        		s++;
    		}
    	}
    }
    int big=tokuten[1];
    int bign=1;
    for(int i=2; i<n+1; i++){
     	if(big<tokuten[i]){
     		big=tokuten[i];
     		bign=i;
     	}
    }
    cout<<bign<<endl;



    }

Measured memory_bytes: 3092
#include <stdio.h>
#include <math.h>

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

	int ans = (int)(sqrt((double)X * 2));
	for (; ans * (ans + 1) / 2 >= X; ans--);
	
	printf("%d\n", ans + 1);
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 128
module WeightedDirectedGraph
  (Vertex : sig
    type t
    val compare : t -> t -> int
  end)
  (Weight : sig
    type t
    val zero : t
    val ( + ) : t -> t -> t
    val compare : t -> t -> int
  end) :
sig
  val dijkstra :
    (* 隣接リスト *)
    (Vertex.t -> (Vertex.t * Weight.t) list) ->
    (* 始点 *)
    Vertex.t ->
    (* 始点から辿り着けなければNoneを返す *)
    (Vertex.t -> Weight.t option)
end =
struct
  module WMap = Map.Make (Weight)
  module VMap = Map.Make (Vertex)

  (* ダイクストラ法のメインループ *)
  (* d に入っていない頂点への距離は無限大とみなす *)
  let rec dijkstra_aux e (d, q) =
    match WMap.min_binding q with
    | exception Not_found -> d
    | (w, us) ->
        dijkstra_aux e @@ List.fold_left (fun (d, q) u ->
          if Weight.compare (VMap.find u d) w < 0
          (* 既に頂点uを訪れていた *)
          then (d, q)
          (* w = d.(u) *)
          else List.fold_left (fun (d, q) (v, c) ->
            let open Weight in
            if
              (* d.(v) <= d.(u) + c *)
              try Weight.compare (VMap.find v d) (w + c) <= 0
              with Not_found -> false (* d.(v) は無限大 *)
            then (d, q)
            else
              VMap.add v (w + c) d,
              WMap.add (w + c) (v :: try WMap.find (w + c) q with Not_found -> []) q)
          (d, q) (e u)) (d, WMap.remove w q) us

  let dijkstra e s =
    let d =
      dijkstra_aux e
        (VMap.singleton s Weight.zero, WMap.singleton Weight.zero [s]) in
    fun t -> try Some (VMap.find t d) with Not_found -> None
end

module Int = struct
  type t = int
  let zero = 0
  let ( + ) = ( + )
  let compare = compare
end

module G = WeightedDirectedGraph (Int) (Int)

let () = Scanf.scanf "%d\n" @@ fun k ->
  let Some d = G.dijkstra (fun i -> [((i + 1) mod k, 1); (i * 10 mod k, 0)]) 1 0 in
  Printf.printf "%d\n" @@ 1 + d

Measured memory_bytes: 14464
#include<iostream>

using namespace std;

int main() {
	long long int a, b, c, d;
	cin >> a >> b >> c >> d;
	 if (a*b < c*d) {
		cout << c*d<< endl;
	}
	else  {
		cout << a*b << endl;
	}
	return 0;
}

Measured memory_bytes: 256
<?php
define('MOD', 10 ** 9 + 7);
init(100);
list($n) = strs();
list($k) = ints();
$l = strlen($n);
if ($k > $l) exit('0');
$cnt = nCr2($l, $k) * (9 ** $k);
$cnt -= (9 - (int) $n[0]) * nCr2($l - 1, $k - 1) * (9 ** ($k - 1));
$notzero = 1;
$i = 1;
while ($notzero < $k) {
    $cnt -= (9 - (int) $n[$i]) * nCr2($l - $i - 1, $k - ($notzero + 1)) * (9 ** ($k - ($notzero + 1)));
    if ($n[$i] !== '0') ++$notzero;
    ++$i;
}
echo $cnt;
function strs()
{
    return explode(' ', trim(fgets(STDIN)));
}
function ints()
{
    return array_map('intval', explode(' ', trim(fgets(STDIN))));
}
// 足し算
function modAdd($x, $y)
{
    return ($x + $y) % MOD;
}

// 引き算
function modSub($x, $y)
{
    return ($x + MOD - $y) % MOD;
}

// 掛け算
function modMul($x, $y)
{
    return ($x * $y) % MOD;
}

// 割り算
function modDiv($x, $y)
{
    return modMul($x, modPow($y, MOD - 2));
}

// 累乗（繰り返し二乗法）
function modPow($n, $x)
{
    if ($x === 0) return 1;
    $res = (modPow($n, $x >> 1) ** 2) % MOD;
    if ($x % 2 === 1) $res = modMul($res, $n);
    return $res;
}

// 階乗
function modFac($n)
{
    if ($n === 0) return 1;
    return modMul($n, modFac($n - 1));
}

// 順列
function nPr($n, $r)
{
    if ($r === 0) return 1;
    return modMul(nPr($n, $r - 1), $n - $r + 1);
}

// 組み合わせ
function nCr($n, $r)
{
    $r = min($r, $n - $r);
    if ($r === 0) return 1;
    return modDiv(nPr($n, $r), modFac($r));
}

// 階乗、逆元を前処理
function init($n)
{
    global $fact, $ifact;
    $fact[0] = 1;
    for ($i = 1; $i <= $n; ++$i) $fact[$i] = modMul($fact[$i - 1], $i);
    $ifact[$n] = modDiv(1, $fact[$n]);
    for ($i = $n; $i >= 1; --$i)
        $ifact[$i - 1] = modMul($ifact[$i], $i);
}

// 順列（前処理）
function nPr2($n, $r)
{
    global $fact, $ifact;
    return modMul($fact[$n], $ifact[$n - $r]);
}

// 組み合わせ（前処理）
function nCr2($n, $r)
{
    global $fact, $ifact;
    return modMul(modMul($fact[$n], $ifact[$r]), $ifact[$n - $r]);
}


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

#define int long long
#define DBG 1
#define dump(o) if(DBG){cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) if(DBG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define each(it,c) for(auto it=(c).begin();it!=(c).end();it++)
#define all(c) c.begin(),c.end()
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9 + 7);

signed main() {
	int n, x; cin >> n >> x; vector<int>v(n); rep(i, 0, n)cin >> v[i];
	int ans = 0;
	rep(i, 0, n - 1) {
		if (v[i] + v[i + 1] > x) {
			ans += v[i] + v[i + 1] - x;

			v[i + 1] = v[i + 1] - (v[i] + v[i + 1] - x);
			if (v[i + 1] < 0) {
				v[i] += v[i + 1];
				v[i + 1] = 0;
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
using namespace std;
 
int main() {
  int n,y,a=0,a1,b=0,b1,c=0,c1;
  cin >> n >> y;
  
  while(c<n+1){
    b=0;
    while(b<(n-c+1)){
      a=n-b-c;
      a1=a*10000; b1=b*5000; c1=c*1000;
      if((a1+b1+c1)==y){
        cout << a << " " << b << " " << c << endl;
        exit(0);
      }
      b++;
    }
    c++;
  }
  
  cout << "-1 -1 -1" << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int i,j,n,x;
  i=0;
  while(1){
    scanf("%d",&x); 
    if(x==0){
      break;
    }
 
    i++;
    if(x!=0){
      printf("Case %d: %d\n",i,x); 
    }
  }
  return (0);
}

      

Measured memory_bytes: 596
#include <memory.h>

#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <utility>
#include <vector>

using namespace std;

#define mod 1000000007

int main() {
	int n;
	cin >> n;
	int a[100000];
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	long long int ans = 1;
	long long int cnt[100000] = {};
	for (int i = 0; i < n; i++) {
		if (a[i] == 0)
			ans = (ans * max((long long int)0, 3 - cnt[a[i]])) % mod;
		else
			ans = (ans * max((long long int)0, (cnt[a[i] - 1] - cnt[a[i]]))) %
			      mod;
		cnt[a[i]]++;
	}

	cout << ans << endl;
}

Measured memory_bytes: 1408
N = int(input())
A = list(map(int, input().split()))
B = [0]
for i in range(1, N):
    if A[i - 1] - A[i] > 0:
        B.append(A[i - 1] - A[i])
        A[i] += A[i - 1] - A[i]
print(sum(B))

Measured memory_bytes: 32228
#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
using namespace std;
typedef long long ll;
typedef pair<int,int>P;

int main(){
	string s;cin>>s;
	ll sum=0;
	int A=0;
	int mode=0;
	rep(i,s.size()){
		if(s[i]=='A'){
			if(mode!=0){
				A=1;
				mode=0;
			}
			else A++;
		}
		if(s[i]=='B'){
			if(mode!=0){
				A=0;
				mode=0;
			}
			else mode=1;
		}
		if(s[i]=='C'){
			if(mode!=1){
				A=0;
				mode=0;
			}
			else{
				sum+=A;
				mode=0;
			}
		}
	}
	cout<<sum<<endl;
}


Measured memory_bytes: 640
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int h = sc.nextInt();
        int w = sc.nextInt();

        char cs[][] = new char[h][w];
        for (int i = 0; i < h; i++) {
            String s = sc.next();
            cs[i] = s.toCharArray();
        }

        int spaceRow[] = new int[h];
        for (int i = 0; i < h; i++) {
            boolean space = true;
            for (int j = 0; j < w; j++) {
                if (cs[i][j] == '#') {
                    space = false;
                    break;
                }
            }

            if (space) {
                spaceRow[i] = 1;
            }
        }

        int spaceCol[] = new int[w];
        for (int i = 0; i < w; i++) {
            boolean space = true;
            for (int j = 0; j < h; j++) {
                if (cs[j][i] == '#') {
                    space = false;
                    break;
                }
            }

            if (space) {
                spaceCol[i] = 1;
            }
        }

        for (int i = 0; i < h; i++) {
            if (spaceRow[i] == 1) continue;
            for (int j = 0; j < w; j++) {
                if (spaceCol[j] == 1) continue;
                System.out.print(cs[i][j]);
            }
            System.out.println();
        }
    }
}


Measured memory_bytes: 25184
#%%
import sys
def input():
    return sys.stdin.readline().rstrip()

def main():
    n = int(input())
    l = [int(x) for x in input().split()]

    cnt = 0
    for i in range(n-2):
        if l[i] < l[i+1] < l[i+2]:
            cnt = cnt + 1
        if l[i] > l[i+1] > l[i+2]:
            cnt = cnt + 1

    print(cnt)
    
# %%
if __name__ == '__main__':
    main()

# %%
# from atcoder_test import doTest
# doTest("abc132","b",main)

Measured memory_bytes: 3064
#define _USE_MATH_DEFINES
#include <cmath>
#include <string>
#include <vector>
#include <utility>
#include <iostream>
#include <algorithm>
#include <unordered_map>
#include <numeric>
#include <array>
#include <float.h>
#include <memory>
#include <functional>
#include <iomanip>
#include <random>

using namespace std;

int main() {
  array<pair<pair<int,string>, vector<int>>, 3> arr;
  auto* f = &arr[0];
  for (auto&& val : arr) {
    val.first.first = 0;
    string str;
    cin >> str;
    val.second.reserve(str.size());
    for (auto&& ch : str) {
      val.second.emplace_back(ch - 'a');
    }
  }
  arr[0].first.second = "A";
  arr[1].first.second = "B";
  arr[2].first.second = "C";
  while (f->first.first != f->second.size()) {
    f = &arr[f->second[f->first.first++]];
  }
  cout << f->first.second << endl;
}


Measured memory_bytes: 256
using System.Linq;
using System;
using static System.Console;
class E { static void Main() => new K(); }
class K
{
	const int MOD = 1000000007;
	public K()
	{
		var I = ReadLine().Split().Select(int.Parse).ToArray();
		int N = I[0], X = I[1], Y = I[2], Z = I[3];
		var M = 1 << (X + Y + Z);
		var m = M - 1;
		var n = (1 << (Z - 1)) | (1 << (Y + Z - 1)) | (1 << (X + Y + Z - 1));
		var d = new long[N + 1, M];
		d[0, 0] = 1;
		for (var i = 0; i < N; i++) for (var s = 0; s < M; s++) if (d[i, s] != 0) for (var a = 1; a <= 10; a++)
		{
			var t = ((s << a) | (1 << (a - 1))) & m;
			if ((t & n) != n) d[i + 1, t] = (d[i + 1, t] + d[i, s]) % MOD;
		}
		var p = 1L;
		for (var i = 0; i < N; i++) p = p * 10 % MOD;
		for (var s = 0; s < M; s++) p += MOD - d[N, s];
		WriteLine(p % MOD);
	}
}

Measured memory_bytes: 52064
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <vector>
#include <functional>
#include <stack>
#include <utility>
#include <map>
#include <queue>
#include <set>

using namespace std;

int main() {
	string a, b, c;
	cin >> a >> b >> c;
	if (a[a.size() - 1] == b[0] && b[b.size() - 1] == c[0])
		cout << "YES" << endl;
	else
		cout << "NO" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define REP(i, n) for (signed long long i = 0; i < (n); i++)
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;

int main() {
  ll n;
  cin >> n;
  vector<ll> v, x;
  REP(i, n) {
    ll a;
    cin >> a;
    v.pb(a);
    x.pb(a);
  }
  sort(v.begin(), v.end());
  for (auto &a : x) {
    if (a < v[v.size() / 2])
      cout << v[v.size() / 2] << endl;
    else {
      cout << v[v.size() / 2 - 1] << endl;
    }
  }
}


Measured memory_bytes: 5476
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

bool visited[225816];
ll v[225816];
int p[225816];

vector<int> g[225816];
queue<int> que;

int main(void){
	int n,q,i,a,b;
	ll x;
	cin >> n >> q;
	for(i=1; i<n; ++i){
		cin >> a >> b;
		--a; --b;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	for(i=0; i<q; ++i){
		cin >> a >> x;
		--a;
		v[a] += x;
	}
	p[0] = n;
	que.push(0);
	while(!que.empty()){
		a = que.front();
		que.pop();
		visited[a] = true;
		v[a] += v[p[a]];
		for(i=(g[a].l_ength()-1); i>=0; --i){
			b = g[a][i];
			if(visited[b]){
				continue;
			}
			p[b] = a;
			que.push(b);
		}
	}
	for(i=0; i<n; ++i){
		cout << ((i)?" ":"") << v[i];
	}
	cout << endl;
	return 0;
}


Measured memory_bytes: 17908
#include <iostream>
#include <algorithm>
#include <utility>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <math.h>
#include <string.h>
#include <iomanip>
#include <numeric>
#include <cstdlib>
#include <cstdint>
#include <cmath>
#include <functional>
#include <limits>
#include <cassert>
#include <bitset>

using namespace std;

/* template */

using ll = long long;

void debug_out() { std::cout << std::endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cout << H << " ";
  debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cout << "debug: "; debug_out(__VA_ARGS__)
#else
#define debug(...) 
#endif

#define rep(i, a, n) for (int i = (int)(a); i < (int)(n); i++)
#define rrep(i, a, n) for (int i = ((int)(n-1)); i >= (int)(a); i--)
#define Rep(i, a, n) for (long long i = (long long)(a); i< (long long)(n); i++)
#define RRep(i, a, n) for (long long i = ((long long)(n-1ll)); i>=(long long)(a); i--)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()

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

struct Edge{
    int to;
    ll weight;
    Edge(int t, ll w) : to(t), weight(w){ }
};

struct edge{
    int from;
    int to;
    ll weight;
    edge(int f,int t,ll w) : from(f), to(t), weight(w){ }
};


using Graph = vector<vector<Edge>>;
using graph = vector<vector<int>>;
using edges = vector<edge>;

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

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

template <class T>
T lcm(T a, T b){
    return (a*b)/gcd(a,b);
}

bool isPalindrome(string s){
    string t = s;
    reverse(all(t));
    return s==t;
}

constexpr ll LNF = 1LL<<60;

constexpr int INF = 1e9+7;

const double PI=3.14159265358979323846;


vector<int> dx = {-1,0,1,0,-1,1,-1,1};
vector<int> dy = {0,-1,0,1,1,-1,-1,1};

/* template */

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    set<int> s;
    rep(i,0,n){
        int d; cin >> d;
        s.insert(d);
    }
    cout << s.size() << endl;
} 

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

#define ll long long
#define mtv(kit) cout<<#kit<<" - "<<kit<<"\n";
#define ff first
#define ss second
#define pb push_back
#define rep(i,a,b) for(i=a;i<b;i++)
#define pii pair<ll , ll>
#define all(x) x.begin(),x.end()
#define nl "\n"
#define ump unordered_map

ll power(ll n, ll m){
    ll res = 1;
    while(m){
        if(m&1)res*=n;
        n = n * n;
        m>>= 1;
    }
    return res;
}
void doit(){
    ll n,m,i,j,k1,k2,ans=0,k;
    cin >> n >> m >> k;
    vector< string>v(n);
    rep(i,0,n)cin >> v[i];
    ll ilim=power(2LL,n);
    ll jlim=power(2LL,m);
    for(i = 0; i < ilim; i++){
        for(j = 0; j < jlim; j++){
            ll cou = 0;
            for(k1 = 0; k1 < n; k1++){
                for(k2 = 0; k2 < m; k2++){
                    if((i&(1LL << k1)) || (j&(1LL << k2)))continue;
                    if(v[k1][k2]=='#') cou++;
                }
            }
            if(cou == k)ans++;
        }
    }
    cout << ans << nl;
}

int main() {
#ifndef ONLINE_JUDGE
    freopen("input1.txt","r",stdin);
    freopen("output1.txt","w",stdout);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll t = 1;
    // cin >> t;
    for(ll i = 1; i <= t; i++){
        doit();
    }
}


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

int main()
{
    ios::sync_with_stdio(false);

    int N; cin >> N;
    auto adjacency_list = vector<vector<int>>(N);
    for (auto i = 0; i < N-1; i++)
    {
        int a, b; cin >> a >> b;
        a--; b--;

        adjacency_list[a].push_back(b);
        adjacency_list[b].push_back(a);
    }

    struct State { int vertex, mark; };
    const auto compare = [](const State a, const State b) { return a.mark < b.mark; };
    auto queue = priority_queue<State, vector<State>, decltype(compare)>(compare);

    auto seen = vector<bool>(N);
    auto marks = vector<int>(N);
    int K; cin >> K;
    for (auto i = 0; i < K; i++)
    {
        int v, m; cin >> v >> m;
        v--;

        seen[v] = true;
        marks[v] = m;
        queue.push({v, m});
    }

    while (!queue.empty())
    {
        const auto s = queue.top(); queue.pop();
        for (const auto w : adjacency_list[s.vertex]) if (!seen[w])
        {
            seen[w] = true;
            marks[w] = marks[s.vertex]-1;
            queue.push({w, marks[w]});
        }
    }

    auto ok = true;
    for (auto v = 0; v < N; v++)
        for (auto w : adjacency_list[v])
            ok &= abs(marks[v]-marks[w]) == 1;

    if (ok)
    {
        cout << "Yes" << "\n";
        for (const auto x : marks) cout << x << "\n";
    }
    else cout << "No" << "\n";
}



Measured memory_bytes: 7924
n = int(input())
s = [int(input()) for i in range(n)]
s = sorted(s)
if sum(s)%10!=0:
    print(sum(s))
else:
    for i in range(n):
        if (sum(s)-s[i])%10!=0:
            print(sum(s)-s[i])
            exit()
    else:
        print("0")

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
template<class T> istream& operator >> (istream& s, vector<T>& v)
{ for (T& x: v) { s >> x; } return s;}

int main(){
    int n,k;
    cin >> n >> k;
    string s; cin >> s;
    char cur = '2';
    vector<pair<char, int>> sp;
    rep(i, s.size()){
        if(cur != s[i]){
            sp.push_back(make_pair(s[i], 1));
            cur = s[i];
        }
        else sp[sp.size()-1].second++;
    }
    vector<int> sum(sp.size()+1);
    rep(i,sp.size()) sum[i+1] += sum[i] + sp[i].second;
    int ma = 0;
    rep(i,sp.size()){
        int num;
        if(sp[i].first == '1') num = i+2*k;
        else num = i+2*k-1;
        if(num >= sp.size()) num = (int)sp.size()-1;
        ma = max(ma, sum[num+1]-sum[i]);
    }
    cout << ma << endl;
    return 0;
}

Measured memory_bytes: 1652
#include <bits/stdc++.h>
#define SORT(x) sort(x.begin(),x.end())
#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++)
#define repr(i, m, n) for(int i = m; i >= n; i--)
#define INF (1e9)
#define PI (acos(-1))
#define MOD 1000000007
using namespace std;
typedef long long ll;

ll ct;
struct edge{ll to;}; //edgeパラメータ
struct graph{
  ll N; //ノードの個数
  vector<vector<edge> > G; //G[辺の元]((.to辺の先,.costコスト),...)

  vector<bool> visited;

  graph(ll n){ //グラフ生成時
    N = n;
    G.resize(N); //Edge情報
    visited.resize(N); //Node情報,深さ
    rep(i,N){visited[i] = false;}
  }
  void add_edge(ll s, ll t){
    G[s].emplace_back((edge){t});
  }

  void dfs(ll v=0){
    visited[v]=true;
    bool lastv=true;
    rep(i,N){
      if(!visited[i]) lastv=false;
    }
    if(lastv){
      ct++;
      visited[v]=false;
      return;
    }
    for(auto E : G[v]){ // E つなぐエッジ
      if(visited[E.to]) continue;
      dfs(E.to); //まだ行ってないなら
    }
    visited[v]=false;
  }
};



void Main(){

  int M,N;

  cin>>N>>M;

  graph g(N);

  rep(i,M){
    int a,b;
    cin>>a>>b;
    g.add_edge(a-1,b-1);
    g.add_edge(b-1,a-1);
  }

  g.dfs(0);

  cout << ct <<"\n";
}
//-----------------------------------
int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  Main();
}
//-----------------------------------


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <utility>
#include <memory>
#include <functional>
#include <deque>
#include <cctype>
#include <numeric>
#include <ctime>
#include <bitset>
#include <cctype>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cstring>
#include <string>
#include <sstream>
#include <algorithm>
#include <iomanip>

using namespace std;

//define
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define dump(x)  cerr << #x << " = " << (x) << endl;

#define INF (INT_MAX/2)
#define PI (2*acos(0.0))
#define EPS (1e-8)

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<ll> vll;
typedef vector<vector<ll> > vvll;

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

int main(void) {
  ios_base::sync_with_stdio(0);
  int _d, n, m, ans;
  while (cin >> _d, _d) {
    cin >> n >> m;
    
    vector<int> d(n+1), k(m);
    
    for (int i = 0; i < n - 1; i++) cin >> d[i];
    for (int i = 0; i < m; i++) cin >> k[i];
    d[n-1] = 0; d[n] = _d;

    sort(d.begin(), d.end());
    
    ans = 0;
    for (int i = 0; i < m; i++) {
      int target = k[i];
      int l = 0, u = n + 1, mid, min_dist;
      while (l + 1 < u) {
        mid = (l + u) / 2;
        if (target - d[mid] >= 0) l = mid;
        else u = mid;
      }
      min_dist = min(target - d[l], d[l+1] - target);
      ans += min_dist;
    }
    
    cout << ans << endl;
  }
  return 0; 
}

Measured memory_bytes: 1528
h, w = map(int, input().split())
s = [0] * h
for i in range(h):
    s[i] = list(input())

h_cnt = [[0] * w for _ in range(h)]
w_cnt = [[0] * w for _ in range(h)]

for i in range(h):
    dot_cnt, beg_sec = 0, 0
    for j in range(w):
        if s[i][j] == '#':
            if dot_cnt > 0:
                for k in range(beg_sec, j):
                    w_cnt[i][k] = dot_cnt
                beg_sec = j+1
                dot_cnt = 0
            else:
                w_cnt[i][j] = 0
                beg_sec += 1
        else:
            dot_cnt += 1
    if dot_cnt > 0:
        for k in range(beg_sec, w):
            w_cnt[i][k] = dot_cnt

for i in range(w):
    dot_cnt, beg_sec = 0, 0
    for j in range(h):
        if s[j][i] == '#':
            if dot_cnt > 0:
                for k in range(beg_sec, j):
                    h_cnt[k][i] = dot_cnt
                beg_sec = j+1
                dot_cnt = 0
            else:
                h_cnt[j][i] = 0
                beg_sec += 1
        else:
            dot_cnt += 1
    if dot_cnt > 0:
        for k in range(beg_sec, h):
            h_cnt[k][i] = dot_cnt

ans = 0
for i in range(h):
    for j in range(w):
        ans = max(ans, h_cnt[i][j] + w_cnt[i][j] - 1)
print(ans)

Measured memory_bytes: 247176
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <climits>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <fstream>

using namespace std;
#define TOSTRING(x) #x
#define SZ(x) (int)(x).size()
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REPR(i,n) for(int i=(n)-1;i>=0;i--)
#define ALL(s) (s).begin(), (s).end()
#define so(V) sort(ALL(V))
#define rev(V) reverse(ALL(V))
#define uni(v) v.erase( unique(ALL(v)) , v.end());
#define PAU system("pause")

typedef long long unsigned int llu;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef vector<vb> vvb;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;
const int INF = (1 << 28);
const double PI = acos(-1);

//フローで殴る解法

struct Edge {
	int to, cap, rev;
	// 行き先,容量,逆辺
	Edge(){}
	Edge(int _to,int _cap,int _rev) {
		to = _to;
		cap = _cap;
		rev = _rev;
	}
};

typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

struct Flow {
	Graph G;
	vb used;
	int V;
	Flow() {}
	Flow(int _V) {
		V = _V;
		G = Graph(V);
	}
	//fromからtoまでの容量capの辺を張る。
	void add_edge(int from, int to, int cap) {
		G[from].push_back(Edge(to, cap,SZ(G[to])));
		G[to].push_back(Edge(from, 0, SZ(G[from]) - 1));
	}
	
	int dfs(int v, int t, int f) {
		if (v == t)return f;
		used[v] = true;
		for (Edge &e : G[v]) {

			if (!used[e.to] && e.cap > 0) {
				int d = dfs(e.to, t, min(f, e.cap));
				if (d > 0) {
					e.cap -= d;
					G[e.to][e.rev].cap += d;
					return d;
				}
			}
		}
		return 0;
	}

	int max_flow(int s, int t) {
		int flow = 0;
		while (true) {
			used = vb(V,false);
			int f = dfs(s, t, INF);
			if (f == 0)return flow;
			flow += f;
		}
	}
};

typedef pair<int, int> P;
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N;
	cin >> N;
	int s = 2 * N, t = 2 * N + 1;
	Flow F(2*N + 2);//s->red->blue->t
	vector<P> VP;
	REP(i, N) {
		int a, b;
		cin >> a >> b;
		VP.push_back(P(a, b));
		F.add_edge(s, i, 1);
	}
	REP(i, N) {
		int c, d;
		cin >> c >> d;
		F.add_edge(i + N, t, 1);
		REP(j, N) {
			if (c > VP[j].first && d > VP[j].second) {
				F.add_edge(j, i+N, 1);
			}
		}
	}
	cout << F.max_flow(s,t) << endl;
	PAU;
	return 0;
}


Measured memory_bytes: 632
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;

class Program
{
    static void Main(string[] args)
    {
        var K = int.Parse(ReadLine());
        var AB = ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
        var (A, B) = (AB[0], AB[1]);

        var ok = false;
        for (int i = K; i <= 1000; i+=K)
        {
            if(A <= i && i <= B)
            {
                ok = true;
                break;
            }
        }

        WriteLine(ok ? "OK" : "NG");
    }
}


Measured memory_bytes: 28244
import collections
s = list(input())
n = len(s)
mod = [0]*(n+1)
pow10 = 1
for i in range(n):
    mod[i+1] = (mod[i] + int(s[-1-i])*pow10)%2019
    pow10 = pow10*10%2019
d = collections.Counter(mod)
ans = 0
for i in d.values():
    ans += i*(i-1)//2
print(ans)


Measured memory_bytes: 85232
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF=1001001001;
const int mod=1e9+7;

int64_t N,M,V,P;
vector<int64_t>A;

bool f(int i){//iは0インデックス
  if(i<=P-1){return true;}
  int64_t imx=A[i]+M;
  if(imx<A[P-1]){return false;}
  int64_t sum=0;
  sum+=(P-1)*M;
  sum+=(N-i)*M;//iは0インデックス
  for(int j=P-1;j<i;j++){
    sum+=max((int64_t)0,imx-A[j]);
  }
  return sum>=M*V;
}
int main(){
  cin>>N>>M>>V>>P;
  A.resize(N);
  for(int i=0;i<N;i++){
    cin>>A[i];
  }
  sort(A.rbegin(),A.rend());
  
  int l=-1,r=N;
  while(r-l>1){
    int mid=(r+l)/2;
    if(f(mid)){l=mid;}
    else{r=mid;}
  }
  cout<<l+1<<endl;//l,rは0インデックス
  return 0;
}

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

#define N 1000001
#define M 10001

int main(){
    int i,j,tl,pl,flag;
    char t[N],p[M];

    scanf("%s",t);
    tl=strlen(t);
    

    scanf("%s",p);
    pl=strlen(p);

    for(i=0;i<tl;i++){
        /*if(t[i]==p[0]) flag=0;
        for(j=0;j<pl;j++){
            if(t[i+j]!=p[j]) flag=1;
        }*/
        if(strncmp(&t[i],p,pl)==0) printf("%d\n",i);
    }

    return 0;
}

Measured memory_bytes: 1548
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int mod=1e9+7;
struct mat
{
	int a[4][4];
	mat(){memset(a,0,sizeof(a));}
	void init(){for(int i=0;i<4;i++)a[i][i]=1;}
	mat operator*(const mat&b)const
	{
		mat c;
		for(int k=0;k<4;k++)for(int i=0;i<4;i++)for(int j=0;j<4;j++)c.a[i][j]=(c.a[i][j]+1ll*a[i][k]*b.a[k][j])%mod;
		return c;
	}
}ans,p,q;
mat pw(mat a,int b){mat r;r.init();for(;b;b>>=1,a=a*a)if(b&1)r=r*a;return r;}
int main()
{
	int n,m,lst=0;scanf("%d%d",&n,&m);ans.init();
	p.a[0][0]=2;p.a[0][1]=1;p.a[0][2]=1;p.a[0][3]=1;
	p.a[1][0]=1;p.a[1][1]=1;p.a[1][2]=0;p.a[1][3]=1;
	p.a[2][0]=1;p.a[2][1]=0;p.a[2][2]=1;p.a[2][3]=1;
	p.a[3][0]=1;p.a[3][1]=0;p.a[3][2]=0;p.a[3][3]=1;
	q.a[0][0]=1;q.a[0][1]=1;q.a[0][2]=1;q.a[0][3]=1;
	q.a[1][0]=0;q.a[1][1]=1;q.a[1][2]=0;q.a[1][3]=1;
	q.a[2][0]=0;q.a[2][1]=0;q.a[2][2]=1;q.a[2][3]=1;
	q.a[3][0]=0;q.a[3][1]=0;q.a[3][2]=0;q.a[3][3]=1;
	while(m--){int x;scanf("%d",&x);ans=ans*pw(p,x-lst-1)*q;lst=x;}
	ans=ans*pw(p,n-lst);
	printf("%d\n",ans.a[0][3]);
	return 0;
}

Measured memory_bytes: 256
K, N = map(int, input().split())
An = list(map(int, input().split()))

Bn = [0] * N
for i in range(N-1):
    Bn[i] = An[i+1] - An[i]

Bn[-1] = K - An[-1] + An[0]
print(sum(Bn) - max(Bn))

Measured memory_bytes: 26436
#include <stdio.h>

int main(void) {
    int n, m, c, count = 0;
    scanf("%d%d%d", &n, &m, &c);
    int b[m], a[n][m];
    for(int i = 0; i < m; i++) {
        scanf("%d", &b[i]);
    }
    for(int i = 0; i < n; i++) {
        for(int j = 0; j < m; j++) {
            scanf("%d", &a[i][j]);
        }
    }
    for(int i = 0; i < n; i++) {
        int total = 0;
        for(int j = 0; j < m; j++) {
            total += a[i][j] * b[j];
        }
        if(total + c > 0) {
            count++;
        }
    }
    printf("%d\n", count);
    return 0;
}


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

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> d(k);
  for(int i = 0; i < k; i++){
    cin >> d.at(i);
  }

  for(int i = n; i <= 100000; i++){
    int a = i;
    bool flag = true;
    while( a > 0 ){
      int m = a % 10;
      a /= 10;
      for(int j = 0; j < k; j++){
        if(m == d.at(j)){
          flag = false;
        }
      }
    }
    if(flag){
      cout << i << endl;
      return 0;
    }
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);

using namespace std;

namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;const double INF = 1e12, EPS = 1e-9;

int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	map<int,int> m;
	int n, ans = 0; cin >> n;
	rep(i, n){
		int a; cin >> a;
		++m[a];
	}
	for(int b = 31; b >= 0; b--){
		ll x = 1ll << b;
		for(auto i : m){
			if(x == 2 * i.first){
				ans += i.second / 2;
				m[i.first] %= 2;
				continue;
			}
			if(i.second && m.count(x - i.first) && m[x - i.first] > 0){
				int u = min(i.second, m[x - i.first]);
				ans += u;
				m[i.first] -= u;
				m[x - i.first] -= u;
			}
		}
		vi er;
		for(auto i : m) if(i.second == 0) er.pb(i.first);
		for(int i : er) m.erase(i);
	}
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 10236
#include <stdio.h>
n,i,a[210000],b[1100000],A=0;
#define r for(i=0;i<n;i++)
int main(){
	scanf("%d",&n);r scanf("%d",a+i);r b[a[i]]++;
	r{	int flag=b[a[i]]==1;
		if(a[i]!=1)flag&=b[1]==0;
		for(int d=2;d*d<=a[i];d++)if(a[i]%d==0)flag&=b[d]==0&&b[a[i]/d]==0;
		if(flag)A++;
	}
	
	printf("%d",A);
}

Measured memory_bytes: 6348
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repe(i, n) for (int i = 0; i <= (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define reps(i, s, n) for (int i = (s); i < (n); ++i)
#define repse(i, s, n) for (int i = (s); i <= (n); ++i)
#define repsr(i, n, s) for (int i = (n); i >= (s); --i)
const int64_t inf = (int64_t)1e18;
const int64_t mod = (int64_t)1e9 + 7;

int N;
int64_t A, B, C;
int64_t ls[8];

int64_t solve(int i, int used[8]) {
  if (i == N) {
    int64_t a = 0, b = 0, c = 0;
    int64_t cnt_a = 0, cnt_b = 0, cnt_c = 0;
    rep(j, N) {
      if (used[j] == 1) {
        a += ls[j];
        cnt_a++;
      }
      else if (used[j] == 2) {
        b += ls[j];
        cnt_b++;
      }
      else if (used[j] == 3) {
        c += ls[j];
        cnt_c++;
      }
    }
    if (!cnt_a || !cnt_b || !cnt_c) return inf;
    a = abs(a - A) + (cnt_a - 1) * 10;
    b = abs(b - B) + (cnt_b - 1) * 10;
    c = abs(c - C) + (cnt_c - 1) * 10;
    return a + b + c;
  }
  int64_t res = inf;
  rep(j, 4) {
    used[i] = j;
    int64_t v = solve(i + 1, used);
    res = min(res, v);
  }
  return res;
}

int main() {
  cin >> N >> A >> B >> C;
  rep(i, N) cin >> ls[i];
  int used[8] = {};
  cout << solve(0, used) << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
#include <list>
#include <stack>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#define mkp make_pair
#define fi first
#define se second
#define pt(num) cout << num << "\n"
#define max(a, b) ((a)>(b) ? (a):(b))
#define min(a, b) ((a)<(b) ? (a):(b))
#define chmax(a, b) (a<b ? a=b : 0)
#define chmin(a, b) (a>b ? a=b : 0)
#define INF 1000000000000000000
#define MOD 1000000007LL
#define MAX 100010
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef map<ll, ll> Map;



int main(void) {
    ll N;
    cin >> N;
    double t, a;
    cin >> t >> a;
    double h;
    ll i;
    ll ans=0;
    double min=INF;
    for(i=0; i<N; i++) {
        cin >> h;
        if(min>abs(t-h*0.006-a)) {
            min=abs(t-h*0.006-a);
            ans=i+1;
        }
    }
    
    pt(ans);
    
    
    
    
}

























Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <climits>
#include <utility>
typedef long long ll;
using namespace std;

int main(int argc, char *argv[]) {
  ll n, i, j;
  cin >> n;

  vector<ll> s(n+1,1LL);
  ll sum = 0LL;
  sum += 1LL;
  
  for(i=2;i<=n;i++){
    for(j=i;j<=n;j+=i){
      s[j] += 1LL;
    }
    sum += i * s[i];
  }

  cout << sum << endl;

  return 0;
}


Measured memory_bytes: 81348
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;
//inline int in() { int x; scanf("%d",&x); return x;}
inline ll in() { ll x; cin >> x; return x; }
template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>inline ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define dame { puts("-1"); return 0;}
#define yn {puts("YES");}else{puts("NO");}
const int MX = 200005;

// maxとmaxより後ろにあるminが2離れたらNo
int main() {
  int n = in();
  vector<ll> h; rep(i,n) h.pb(in());
  ll max = 0;
  rep(i,n) {
    if (h[i]>max)
      max = h[i];
    else if (h[i] <= max - 2) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  return 0;
}


Measured memory_bytes: 1400
#include <bits/stdc++.h>
const long long INF = 1LL << 60;
const long long MOD = 1000000007;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rep1(i, n) for (ll i = 1; i <= (n); ++i)
#define rrep(i, n) for (ll i = (n - 1); i >= 0; --i)
#define perm(c) sort(ALL(c));for(bool c##p=1;c##p;c##p=next_permutation(ALL(c)))
#define ALL(obj) (obj).begin(), (obj).end()
#define pb push_back
#define to_s to_string
#define len(v) (ll)v.size()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define print(x) cout << (x) << '\n'
#define drop(x) cout << (x) << '\n', exit(0)
#define debug(x) cout << #x << ": " << (x) << '\n'
using namespace std;
using ll = long long;
typedef pair<ll, ll> P;
typedef vector<ll> vec;
typedef vector<vector<ll>> vec2;
typedef vector<vector<vector<ll>>> vec3;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
ll devc(ll x, ll y) { return 1 + (x - 1) / y; }

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(20);

    ll N, P;
    cin >> N >> P;
    vec2 f(N + 1, vec(2, 0));

    f[0][0] = 1;
    rep1(i, N){
        ll a;
        cin >> a;
        if(a % 2 == 0) rep(j, 2) f[i][j] = 2 * f[i - 1][j]; 
        else rep(j, 2) f[i][j] = f[i - 1][0] + f[i - 1][1];
    }

    print(f[N][P]);

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n;
  cin >> n;
  string d;

  int ac = 0, wa = 0, tle = 0, re = 0;
  
  for(int i = 1; i <= n; i++) {
    cin >> d;

    if(d == "AC") {
      ac++;
    } else if(d == "WA") {
      wa++;
    } else if(d == "TLE") {
      tle++;
    } else if(d == "RE") {
      re++;
    }
  }
  cout << "AC x " << ac << endl;
  cout << "WA x " << wa << endl;
  cout << "TLE x " << tle << endl;
  cout << "RE x " << re << endl;
}

Measured memory_bytes: 3628
#include <iostream>

using namespace std;

int main ()
{
   string s;
   cin>>s;
   int max=0;
   int shuma=0;
   for(int i=0;i<s.length();i++)
   {
       if(s[i]=='A' || s[i]=='T' || s[i]=='G' || s[i]=='C')
       {
           shuma++;
       }
       else
        shuma=0;
       if(shuma>max)
        max=shuma;
   }
   cout<<max<<endl;
    return 0;
}


Measured memory_bytes: 256