akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
int main() {
	int n;
	string a,b;
	cin >> n;
	while(n--) {
		cin >> a >> b;
		string ret = "";
		reverse(a.begin(),a.end());
		reverse(b.begin(),b.end());
		int a_len = a.size(),b_len = b.size();
		int num = max(a_len,b_len),carry = 0,v;
		char tmp[1];
		for(int i = 0; i < num; i++) {
			if(a_len <= i || b_len <= i) v = carry + (b_len <= i ? a[i] : b[i]) - '0';
			else v = carry + a[i] + b[i] - '0' * 2;
			carry = v / 10;
			sprintf(tmp,"%d",v % 10);
			ret += tmp;
		}
		sprintf(tmp,"%d",carry);
		if(carry != 0) ret += tmp;
		reverse(ret.begin(),ret.end());
		cout << (ret.size() > 80 ? "overflow" : ret) << endl;
	}
	return 0;
}

Measured memory_bytes: 1252
#include <bits/stdc++.h>
using namespace std;
#define PII pair<int, int>
#define PLL pair<LL, LL>
#define VI vector<int>
#define VPII vector<PII>
#define LL long long
#define LD long double
#define f first
#define s second
#define MP make_pair
#define PB push_back
#define pb pop_back
#define ALL(c) (c).begin(), (c).end()
#define SIZ(c) (int)(c).size()
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i, b, e) for(int i = (b); i <= (int)(e); ++i)
#define FORD(i, b, e) for(int i = (b); i >= (int)(e); --i)

#define Sim template<class n
Sim, class s> ostream & operator << (ostream &p, pair<n, s> x)
{return p << "<" << x.f << ", " << x.s << ">";}
Sim> auto operator << (ostream &p, n y) -> 
typename enable_if<!is_same<n, string>::value, decltype(y.begin(), p)>::type 
{int o = 0; p << "{"; for(auto c: y) {if(o++) p << ", "; p << c;} return p << "}";}
void dor() {cerr << endl;}
Sim, class...s> void dor(n p, s...y) {cerr << p << " "; dor(y...);}
Sim, class s> void mini(n &p, s y) {if(p>y) p = y;}
Sim, class s> void maxi(n &p, s y) {if(p<y) p = y;}
#ifdef DEB
#define debug(...) dor(__FUNCTION__, ":", __LINE__, ": ", __VA_ARGS__)
#else
#define debug(...)
#endif 

#define I(x) #x " = ", (x), " "
#define A(a, i) #a "[" #i " = ", i, "] = ", a[i], " "
const LL mod = 1e9 + 7;

LL A[100];

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	int n;
	string s;
	cin >> n >> s;
	for (auto x : s)
	{
		A[x - 'a']++;
	}
	LL res = 1;
	FOR(i, 0, 25)
	{
		res = res * (A[i] + 1) % mod;
	}
	
	res = (res + mod - 1) % mod;
	
	cout << res << "\n";
	return 0;
}

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

using namespace std;

int main(void) {
	int a, b;
	char c;

	vector<int> v;
	while (cin >> a >> c >> b) {
		if (c == '?') {
			break;
		}

		int ans;
		switch (c) {
			case '+':
				ans = a + b;
				break;
			case '-':
				ans = a - b;
				break;
			case '*':
				ans = a * b;
				break;
			case '/':
				ans = a / b;
				break;
			default:
				break;
		}
		v.push_back(ans);
	}

	vector<int>::iterator i;

	for (i = v.begin(); i != v.end(); i++) {
		cout << *i << endl;
	}

	return 0;
}

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

const int64_t MOD=1e9+7;

int main(){

  string S;
  cin>>S;
  reverse(S.begin(),S.end());

  int N=S.size();
  vector<int> modinv={1,4,3,12,9,10};
  vector<int> mod={1,10,9,12,3,4};

  //dp[i][j]はS[i-1]までの'?'を0から9にしたときに出来得る j mod 13なる数の総数
  vector<vector<int64_t>> dp(N+1,vector<int64_t>(13));
    if(S[0]=='?'){
      for(int j=0;j<10;++j) dp[1][j]=1;
    }
    else{
      int a=S[0]-'0';
      dp[1][a]=1;
    }

  for(int i=1;i<N;++i){
    for(int j=0;j<13;++j){
      if(S[i]=='?'){
          for(int k=0;k<13;++k){
            int a=((modinv[i%6]*(j-k))%13+13)%13;
            if(a<10){
              dp[i+1][j] += dp[i][k];
              dp[i+1][j] %= MOD;
            }
          }
        }
      else{
        int b=S[i]-'0';
        int k=((j-mod[i%6]*b)%13+13)%13;
        dp[i+1][j] = dp[i][k];
        dp[i+1][j] %= MOD;
        }
      }
  }

  cout<<dp[N][5]<<endl;
}

Measured memory_bytes: 13696
let [| H; W; K; |] = stdin.ReadLine().Split() |> Array.map int
let CArrExtended =
    [| for _ in 1..H -> stdin.ReadLine().ToCharArray() |]

let blackCount (num: int): option<int> =
    let bitArray num : bool[] = 
        [| 
            let mutable tmp = num
            for _ in 0..11 do 
                yield tmp % 2 = 1
                tmp <- tmp / 2
        |]
    
    let blackCount (bitArray: bool[]): option<int>=
        if bitArray.[H..5] |> Array.contains true then None
        elif bitArray.[6+W..] |> Array.contains true then None
        else
        let bitArrayRow = bitArray.[0..H-1]
        let bitArrayCollumn = bitArray.[6..5+W]
        [|0..5|] |> Array.allPairs [|0..5|]
        |> Array.filter (fun (y, x) ->           
            CArrExtended |> Array.tryItem y |> Option.bind (Array.tryItem x) 
            |> Option.map (fun x -> x = '#') 
            |> Option.defaultValue false            
                && not (bitArrayRow |> Array.tryItem y |> Option.defaultValue false )  
                && not (bitArrayCollumn |> Array.tryItem x |> Option.defaultValue false ))
        |> Array.length |> Some
    
    num |> bitArray |> blackCount

[| 0..((pown 2 12) - 1) |] |>
Array.map blackCount
|> Array.filter (fun x -> x |> Option.map (fun x -> x = K) |> Option.defaultValue false)
|> Array.length
|> stdout.WriteLine

Measured memory_bytes: 47472
#![allow(unused_variables, dead_code, clippy::many_single_char_names, non_upper_case_globals, unused_imports, unused_macros)]
use std::{
    collections::{BTreeMap, HashSet, HashMap, VecDeque},
    io::{stdin, stdout, StdinLock, StdoutLock, BufReader, BufWriter, prelude::*},
    mem::swap,
    str::FromStr,
};

struct Reader<'a> {
    stdin: BufReader<StdinLock<'a>>
}

impl<'a> Reader<'a> {
    fn new(stdin: BufReader<StdinLock<'a/*'*/>>) -> Self {
        Self {stdin}
    }
    fn read_str(&mut self) -> String {
        let mut s = String::with_capacity(100);
        self.stdin.read_line(&mut s).unwrap();

        if s.ends_with('\n') { s.pop(); if s.ends_with('\r') { s.pop(); } }
        s
    }
    fn read_int<T: FromStr>(&mut self) -> T {
        match self.read_str().parse::<T>() {
            Ok(n) => n,
            _ => panic!()
        }
    }
}

macro_rules! pipe_read {
    ($r: expr, str, $($x: ident),+) => {
        let t = $r.read_str();
        let mut it = t.split(' ');
        $($x = it.next().unwrap();)+
    };
    ($r: expr, $t: ty, $($x: ident),+) => {
        let t = $r.read_str();
        let mut it = t.split(' ').map(|x| x.parse::<$t>().unwrap());
        $($x = it.next().unwrap();)+
    }
}

macro_rules! pipe {
    ($r: expr, str, $($x: ident),+) => {
        pipe_read!($r, str, $($x),+);
    };
    (declare $r: expr, str, $($x: ident),+) => {
        $(let $x: $t;)+
        pipe_read!($r, str, $($x),+);
    };
    ($r: expr, $t: ty, $($x: ident),+) => {
        pipe_read!($r, $t, $($x),+);
    };
    (declare $r: expr, $t: ty, $($x: ident),+) => {
        $(let $x: $t;)+
        pipe_read!($r, $t, $($x),+);
    };
}

const M: usize = 1_000_000;

fn main() {
    let stdin = stdin();
    let stdout = stdout();
    unsafe {
        solve(&mut Reader::new(BufReader::with_capacity(M, stdin.lock())), &mut BufWriter::with_capacity(M, stdout.lock()));
    }
}

const ROWS: usize = 1;
const COLS: usize = 100001;
static mut dp: [usize; COLS] = [0; COLS];

unsafe fn solve(r: &mut Reader, w: &mut BufWriter<StdoutLock>) {
    pipe!(declare r, usize, n, w_cap);
    let mut _w = Vec::with_capacity(n);
    let mut v = Vec::with_capacity(n);

    for _ in 0..n {
        let t = r.read_str();
        let mut t = t.split(' ').map(|x| x.parse::<usize>().unwrap());
        _w.push(t.next().unwrap());
        v.push(t.next().unwrap());
    }

    for (wi, vi) in _w.into_iter().zip(v.into_iter()) {
        for ii in 0..=w_cap-wi {
            dp[ii] = dp[ii].max(dp[ii+wi]+vi);
        }
    }
    write!(w, "{}", dp[0]).unwrap();
}


Measured memory_bytes: 2940
#include <bits/stdc++.h>
       
using namespace std;
       
#define ll long long
#define vi vector<int> 
#define pb push_back
#define sz(s) (int)s.size() 
#define all(v) v.begin(), v.end()
       
string s;
       
int main (){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> s;
    for (int i = 0; i < 6; i++) {
    	if (s[2] == s[3] && s[4] == s[5]) {
    		cout << "Yes";
    		return 0;
		}
	}
	cout << "No";
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define REP(i, b, n) for (Int i = b; i < Int(n); i++)
#define rep(i, n) REP(i, 0, n)
using namespace std;
using Int = long long;
Int inf = 1000000000000000001LL;
using vi = vector<Int>;
using vvi = vector<vi>;
using mapis = unordered_map<Int,string>;
using mapii = unordered_map<Int,Int>;
using pii = pair<Int,Int>;

Int GCD(Int a, Int b){
    if(b==0) return a;
    if(a < b) return GCD(b, a);
    unsigned r;
    while ((r=a%b)) {
        a = b;
        b = r;
    }
    return b;
}
int binary_search_index(Int Y, vi &q){
    int left = 0, right = q.size() - 1;
    while (right >= left) {
        int mid = left + (right - left) / 2;
        if (q[mid] == Y) return mid;
        else if (q[mid] > Y) right = mid - 1;
        else if (q[mid] < Y) left = mid + 1;
    }
    return -1;
}


Int combination(Int n, Int r) {
    if(n == 1){return 0;}
    if ( r * 2 > n ) r = n - r;
    uintmax_t dividend = 1;
    uintmax_t divisor  = 1;
    for ( unsigned int i = 1; i <= r; ++i ) {
        dividend *= (n-i+1);
        divisor  *= i;
    }
    return dividend / divisor;
}

unsigned GetDigit(Int num){
    return std::to_string(num).length();
}
int ctoi(char c) {
    if (c >= '0' && c <= '9') {
        return c - '0';
    }
    return 0;
}

int ans =0;

void dfs(string bit, int length,vector<vector<pii>> &answers){
    if(bit.size() == length){
        int tmp_ans = 0;
        int count_shoujiki = 0;
        rep(i,length){
            if(bit[i] =='1'){
                count_shoujiki++;
                bool goal = true;
                rep(j,answers[i].size()){
                    int x = answers[i][j].first;
                    int y = answers[i][j].second;

                    if (ctoi(bit[x]) != y) {goal = false;}
                }

                if(goal){
                    tmp_ans++;
                }
            }
        }
        if(tmp_ans == count_shoujiki){
            ans = max(ans,count_shoujiki);
        }

        return;
    }
    dfs(bit+"1", length, answers);
    dfs(bit+"0", length, answers);
    return ;
}

int main() {
    Int N,M;

    cin >> N>>M;

    map<Int,Int> clears;
    map<Int,Int> penalties;


    rep(i,M){
        Int problem;
        string s;
        cin >> problem >> s;

        if(s=="WA"){
            if(clears[problem]==0){
                penalties[problem]++;
            }
        }else{
            if(clears[problem]==0){
                clears[problem]++;
            }
        }
    }
    Int clear =0;
    Int pena = 0;
    rep(i,N){
        clear += clears[i+1];
    }

    rep(i,N){
        if(clears[i+1]==1){
            pena += penalties[i+1];
        }
    }

    cout << clear << " " << pena <<endl;



    return 0;
}

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

int main(void) {
  ll H, W;
  cin >> H >> W;
  vector<string> S(H);
  REP(i, 0, H) cin >> S[i];

  const ll INF = 1LL << 60;
  vector<vector<ll>> dist(H, vector<ll>(W, INF));

  struct state {
    ll y, x, d;
  };
  queue<state> q;
  REP(i, 0, H) REP(j, 0, W) {
    if (S[i][j] == '#') {
      q.push((state) { i, j, 0 });
    }
  }

  while (q.size()) {
    ll y = q.front().y, x = q.front().x, d = q.front().d;
    q.pop();

    if (dist[y][x] <= d) continue;
    dist[y][x] = d;

    ll dd[5] = { 0, 1, 0, -1, 0 };
    REP(i, 0, 4) {
      ll ny = y + dd[i], nx = x + dd[i + 1];
      if (0 <= ny && ny < H && 0 <= nx && nx < W) {
        q.push((state) { ny, nx, d + 1 });
      }
    }
  }

  ll ans = 0;
  REP(i, 0, H) REP(j, 0, W) ans = max(ans, dist[i][j]);
  cout << ans << endl;
}

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

int main() { 
  int a,b,c,d,e;
  cin>>a>>b>>c>>d>>e;
  if(a==0)cout<<1<<endl;
  if(b==0)cout<<2<<endl;
  if(c==0)cout<<3<<endl;
  if(d==0)cout<<4<<endl;
  if(e==0)cout<<5<<endl;
}


Measured memory_bytes: 3624
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int asc(const void *a, const void *b)
{
    return *(long int *)a - *(long int *)b;
}
int dis(const void *a, const void *b)
{
    return *(long int *)b - *(long int *)a;
}
int main()
{
    char s[111];
    int k;
    scanf("%d %s", &k, s);
    int l;
    l = strlen(s);
    if (l <= k)
    {
        printf("%s", s);
    }
    else
    {
        for (int i = 0; i < k; i++)
        {
            printf("%c", s[i]);
        }
        printf("...");
    }
    return 0;
}

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

using namespace std;
typedef long long ll;

signed main() {
  string s;
  cin >> s;
  if(s[0] == 'R' && s[1] == 'R' && s[2] == 'R') {
    cout << 3 << endl;
  } else if((s[0] == 'R' && s[1] == 'R') || (s[1] == 'R' && s[2] == 'R')) {
    cout << 2 << endl;
  } else if(s[0] != 'R' && s[1] != 'R' && s[2] != 'R') {
    cout << 0 << endl;
  } else {
    cout << 1 << endl;
  }
  return 0;
}


Measured memory_bytes: 3640
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace Tasks
{
    public class D
    {
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            Solve();
            Console.Out.Flush();
        }

        public static void Solve()
        {
            var N = int.Parse(Console.ReadLine());
            var S = Console.ReadLine();


            var answer = Enumerable.Repeat('-', N).ToArray();

            Func<char[], int, bool> check = (char[] array, int current) =>
            {
                var left = (current - 1 + N) % N;
                var right = (current + 1) % N;
                var isEmpty = array[right] == '-';

                if (array[current] == 'S')
                {
                    if (isEmpty)
                    {
                        if (S[current] == 'o') array[right] = array[left];
                        else array[right] = array[left] == 'S' ? 'W' : 'S';
                        return true;
                    }
                    else
                    {
                        var same = array[left] == array[right];
                        if (S[current] == 'o') return same;
                        else return !same;
                    }
                }
                else
                {
                    if (isEmpty)
                    {
                        if (S[current] == 'o') array[right] = array[left] == 'S' ? 'W' : 'S';
                        else array[right] = array[left];
                        return true;
                    }
                    else
                    {
                        var same = array[left] == array[right];
                        if (S[current] == 'o') return !same;
                        else return same;
                    }
                }
            };

            var ok = true;
            for (var bit = 0; bit < 1 << 3; bit++)
            {
                answer = Enumerable.Repeat('-', N).ToArray();
                answer[0] = (bit >> 1 & 1) == 1 ? 'S' : 'W';
                answer[1] = (bit >> 0 & 1) == 1 ? 'S' : 'W';
                answer[N - 1] = (bit >> 2 & 1) == 1 ? 'S' : 'W';
                ok = true;
                for (var i = 0; i < N; i++)
                {
                    ok = check(answer, i);
                    if (!ok) break;
                }
                if (ok) break;
            }

            Console.WriteLine(ok ? new string(answer) : "-1");
        }
    }
}


Measured memory_bytes: 30040
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n;
  cin >> n;
  int tmp[n] = {0};
  int flag = 1;
  int result = 0;
  
  for (int i = 0; i < n; i++){
    cin >> tmp[i];
  }
  
  while(flag){
	for (int i = 0; i < n; i++){
      if(tmp[i] % 2 == 1){
        flag = 0;
        break;
      } else {
      	tmp[i] /= 2;
      }
  	}
    if(flag == 1) result++;
  }
  
  cout << result << endl;
}


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

int main() {
    int n;
    string s;
    cin >> n >> s;

    vector<int> dir(n, 0);
    for (int i = 0; i < n; ++i) {
        if (s[i] == 'E') {
            dir[i] = 1;
        }
    }

    vector<int> cum(n, 0);
    for (int i = 0; i < n; ++i) {
        cum[i+1] = cum[i] + dir[i];
    }

    int ans = n;
    for (int i = 0; i < n; ++i) {
        int e, w;
        w = i - cum[i];
        e = cum[n] - cum[i+1];
        ans = min(ans, w+e);
    }

    cout << ans << endl;

    return 0;
}

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

int h[100001];

signed main(){

  int N,K; cin >> N >> K;
  for(int i = 0; i < N; i++){
    cin >> h[i];
  }

  sort(h,h+N);
  int ans = 1e9;
  for(int i = 0; i+K-1 < N; i++){
    ans = min(ans,h[i+K-1]-h[i]);
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1024
from sys import stdin
import math
import fractions

k = int(stdin.readline().rstrip())
a, b = [int(x) for x in stdin.readline().rstrip().split()]

result = 0
flag = False
for i in range(10000):
    result += k
    if (a <= result and b >= result):
        print('OK')
        flag = True
        break

if (flag == False):
    print('NG')

Measured memory_bytes: 10420
// tsukasa_diary's programing contest code template
#include <bits/stdc++.h>
using namespace std;
#define TSUKASA_DIARY_S_TEMPLATE
// define
#define for_(i,a,b) for(int i=(a);i<(b);++i)
#define for_rev(i,a,b) for(int i=(a);i>=(b);--i)
#define allof(a) (a).begin(),(a).end()
#define minit(a,b) memset(a,b,sizeof(a))
#define size_of(a) int((a).size())
#define cauto const auto
// typedef
typedef long long lint;
typedef double Double;
typedef pair< int, int > pii;
template< typename T > using Vec = vector< T >;
template< typename T > using Matrix = Vec< Vec< T > >;
template< typename T > using USet = unordered_set< T >;
template< typename T, class C > using MyUSet = unordered_set< T, C >;
template< typename T, typename F > using UMap = unordered_map< T, F >;
template< typename T, typename F, class C > using MyUMap = unordered_map< T, F, C >;
// hash
class PiiHash { public: size_t operator () (const pii& p) const { return (p.first << 16) | p.second; } };
// popcount
inline int POPCNT(int x) { return __builtin_popcount(x); }
inline int POPCNT(lint x) { return __builtin_popcount(x); }
// inf
const int iINF = 1L << 30;
const lint lINF = 1LL << 60;
// eps
const Double EPS = 1e-9;
const Double PI = acos(-1);
// inrange
template< typename T >
inline bool in_range(T v, T mi, T mx) { return mi <= v && v < mx; }
template< typename T >
inline bool in_range(T x, T y, T W, T H) { return in_range(x,0,W) && in_range(y,0,H); }
// neighbor clockwise
const int DX[4] = {0,1,0,-1}, DY[4] = {-1,0,1,0};
const int DX_[8] = {0,1,1,1,0,-1,-1,-1}, DY_[8] = {-1,-1,0,1,1,1,0,-1};
// variable update
template< typename T > inline void modAdd(T& a, T b, T mod) { a = (a + b) % mod; }
template< typename T > inline void minUpdate(T& a, T b) { a = min(a, b); }
template< typename T > inline void maxUpdate(T& a, T b) { a = max(a, b); }
// converter
template< typename F, typename T >
inline void convert(F& from, T& to) {
	stringstream ss;
	ss << from; ss >> to;
}



int N, K;
Vec< Vec< int > > adj;
Vec< pii > edges;
Vec< bool > vis;

void dfs(int v, int p, int d, int cap) {
	if (d > cap) return;
	vis[v] = true;
	for (int u : adj[v]) if (u != p) dfs(u, v, d + 1, cap);
}

void solve() {
	int ans = 0;
	
	if (K % 2 == 0) {
		for_(v,0,N) {
			vis.assign(N, false);
			dfs(v, -1, 0, K / 2);
			int ans_v = 0;
			for_(u,0,N) if (vis[u]) ++ans_v;
			maxUpdate(ans, ans_v);
		}
	} else {
		for (pii p : edges) {
			vis.assign(N, false);
			dfs(p.first, -1, 0, K / 2);
			dfs(p.second, -1, 0, K / 2);
			int ans_v = 0;
			for_(u,0,N) if (vis[u]) ++ans_v;
			maxUpdate(ans, ans_v);
		}
	}
	
	cout << N - ans << endl;
}

int main() {
	cin >> N >> K;
	adj.assign(N, Vec< int >());
	for_(i,0,N-1) {
		int a, b;
		cin >> a >> b;
		--a; --b;
		adj[a].push_back(b);
		adj[b].push_back(a);
		edges.push_back(pii(a,b));
	}
	
	solve();
}

Measured memory_bytes: 384
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
 
# 遅延評価で加えてあげるだけ
 
N,Q = map(int,input().split())
AB = [[int(x) for x in input().split()] for _ in range(N-1)]
PX = [[int(x) for x in input().split()] for _ in range(Q)]
 
graph = [[] for _ in range(N+1)]
for a,b in AB:
    graph[a].append(b)
    graph[b].append(a)
 
value = [0] * (N+1)
for p,x in PX:
    value[p] += x
    
q = [(1,0)]
while q:
    x,parent = q.pop()
    value[x] += value[parent]
    for y in graph[x]:
        if y == parent:
            continue
        q.append((y,x))
 
answer = ' '.join(map(str,value[1:]))
print(answer)

Measured memory_bytes: 150556
#include <bits/stdc++.h>
using namespace std;
 
int main() {
	int N;
  	cin >> N;
    int K;
  	cin >> K;
  	int l=1;
  
  	for (int i=0; i<N; i++) {
    	if (l * 2 < l + K) {
        	l = l *2;
        }
      	else{
        	l = l + K;
        }
    }
  	cout << l;
  
}
















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

int t[6][2] = {
  {1, 2},
  {-1, 3},
  {1, -1},
  {4, 5},
  {5, 2},
  {2, 1}
};

int main(){
  string s;

  while(cin >> s, s != "#"){
    int n = s.length();
    int now = 0;

    for(int i = 0; i < n; i++){
      int flg = s[i] - '0';
      int to = t[now][flg];
      if(to == -1){
        now = -1;
        break;
      }
      else{
        now = to;
      }
    }

    cout << (now == 5 ? "Yes" : "No") << endl;
  }
}

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

using tlll = tuple<ll,ll,ll>;



int main() {

    ll N;
    cin >> N;
    
    for(ll i;i<N;i++){
        cout << "ACL";
        
    }
    cout << endl;
}



Measured memory_bytes: 3604
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();

		ArrayList<Integer> list = new ArrayList<>();


		for (int i = 0; i < N; i++) {
			list.add(sc.nextInt());
		}
		Collections.sort(list);

		int sum = 0;

		for (int i = 0; i < N; i++) {
			if (i == N-1) {
				sum += list.get(i)/2;
				break;
			}
			sum += list.get(i);
		}
		System.out.println(sum);
	}

}


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

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

  int ans = 0;

  rep(i,4){
    if(s.at(i) == '+')
      ans += 1;
    else
    {
      ans -= 1;
    }
  }
  cout << ans;
}


Measured memory_bytes: 3600
import sys
def S(): return sys.stdin.readline().rstrip()
def SL(): return map(str,sys.stdin.readline().rstrip().split())
def I(): return int(sys.stdin.readline().rstrip())
def IL(): return map(int,sys.stdin.readline().rstrip().split())

def Main():
    n,x,y = IL()
    x -= 1
    y -= 1
    dist = [0]*(n-1)
    for i in range(n):
        for j in range(i+1,n):
            dist[min(abs(j-i),abs(j-x)+abs(x-i),abs(y-j)+abs(x-i)+1)-1] += 1
    for rep in dist:
        print(rep)
    return

if __name__=='__main__':
    Main()

Measured memory_bytes: 74748
#include <iostream>

using namespace std;

int main() {
  int x1, y1, x2, y2;
  cin >> x1 >> y1 >> x2 >> y2;

  int dx = x2 - x1;
  int dy = y2 - y1;

  int x = x2;
  int y = y2;
  for (int c = 0; c < 2; c++) {
    if (c > 0) cout << " ";
    swap(dx, dy);
    dx = -dx;
    x += dx;
    y += dy;
    cout << x << " " << y;
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 256
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let n = read::<usize>();
    let mut min_count = vec![50; 26];
    for i in 0..n {
        let mut count = vec![0; 26];
        let s = read::<String>().chars().collect::<Vec<_>>();
        for ch in s {
            count[ch.to_digit(36).unwrap() as usize - 10] += 1;
        }
        for i in 0..26 {
            min_count[i] = min(min_count[i], count[i]);
        }
    }
    for i in 0..26 {
        for _ in 0..min_count[i] {
            print!("{}", std::char::from_digit(i as u32 + 10, 36).unwrap());
        }
    }
    println!("");
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


Measured memory_bytes: 4352
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        int max;
        int min;
        long sum = 0;
        String delimiter = " ";
        Scanner sc = new Scanner(System.in);
        List<Integer> list = new ArrayList<>();
        int loop = sc.nextInt();
        
        for(int i = 0; i < loop; i++) {
            list.add(sc.nextInt());
        }
        
        Collections.sort(list);
        
        max = list.get(loop - 1);
        min = list.get(0);
        for(int num : list) {
            sum += num;
        }
        
        System.out.println(min + delimiter + max + delimiter + sum);
        
    }
}

Measured memory_bytes: 42788
#include "bits/stdc++.h"
using namespace std;
void __dump(int x){cerr << x;}
void __dump(long long x){cerr << x;}
void __dump(long double x){cerr << fixed << setprecision(3) << x;}
void __dump(char x){cerr << '\'' << x << '\'';}
void __dump(const string &x){cerr << '"' << x << '"';}
void __dump(const char *x){cerr << '"' << x << '"';}
void __dump(bool x){cerr << (x ? "true" : "false");}
void _dump(){cerr << "\n";}
template <typename T, typename U> void __dump(const pair<T, U> &x){cerr << '{'; __dump(x.first); cerr << ','; __dump(x.second); cerr << '}';}
template <typename T, typename U, typename V> void __dump(const tuple<T, U, V> &x){cerr << '{'; __dump(get<0>(x)); cerr << ',';  __dump(get<1>(x)); cerr << ',';  __dump(get<2>(x)); cerr << '}';}
template <typename T> void __dump(const T& x){int f=0; cerr << '{'; for(auto&i:x) cerr << (f++ ? "," : ""), __dump(i); cerr << "}";}
template <typename T, typename ... U> void _dump(T t, U ... u){__dump(t); if(sizeof...(u)) cerr << ", "; _dump(u...);}
#define dump(x ...) cerr  <<  "|| "  <<  # x  <<  "  =  ", _dump(x) 
//#define int long long
#define FAST ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define size(x) (int)x.size()
#define all(x) x.begin(),x.end()
#define ln '\n'
#define __ ' '
#define LL long long
#define LD long double
#define pii pair<int,int>
const int INF = 2e9;
const int NN = 1e5;
int n,m;
vector<pii> queries[NN+3];
set<pair<LL,int>> dist_end;
set<pair<int,LL>> end_dist;

int main(){ FAST
	cin >> n >> m;
	for(int i=1; i<=m; ++i){
		int l,r,cost; cin >> l >> r >> cost;
		queries[l].emplace_back(r,cost);
	}

	dist_end.insert({0, 1});
	end_dist.insert({1, 0});
	for(int i=1; i<=n; ++i){
		assert(dist_end.empty() == end_dist.empty());
		while(!end_dist.empty() && end_dist.begin()->first < i){
			int en; LL d;
			tie(en, d) = *end_dist.begin();
			end_dist.erase({en, d});
			dist_end.erase({d, en});
		}
		if(dist_end.empty()){
			cout << -1 << ln;
			return 0;
		}

		LL curDist = dist_end.begin()->first;

		if(i == n){
			cout << curDist << ln;
			return 0;
		}

		for(auto ele: queries[i]){
			int en; LL cost;
			tie(en, cost) = ele;
			dist_end.insert({curDist + cost, en});
			end_dist.insert({en, curDist + cost});
		}
	}

	assert(false);
}

Measured memory_bytes: 11392
#include<bits/stdc++.h>
using namespace std;
char ch[10][10];
int ans;
int r[10],c[10];
int n,m,k;
void dfs(int R,int C)
{
	if (R<=n)
	{
		r[R]=1;dfs(R+1,C);
		r[R]=0;dfs(R+1,C);
	}
	else
	if (C<=m)
	{
		c[C]=1;dfs(R,C+1);
		c[C]=0;dfs(R,C+1);
	}
	else
	{
		char mp[10][10]={};
		for (int i=1;i<=n;i++)
			for (int j=1;j<=m;j++) mp[i][j]=ch[i][j];
		for (int i=1;i<=n;i++)
			if (r[i]==1) for (int j=1;j<=m;j++) mp[i][j]='.';
		for (int i=1;i<=m;i++)
			if (c[i]==1) for (int j=1;j<=n;j++) mp[j][i]='.';
		int cnt=0;
		for (int i=1;i<=n;i++)
			for (int j=1;j<=m;j++)
				if (mp[i][j]=='#') cnt++;
		if (cnt==k) ans++;
	}
}
int main()
{
	cin>>n>>m>>k;
	for (int i=1;i<=n;i++)
		for (int j=1;j<=m;j++) cin>>ch[i][j];
	dfs(1,1);
	cout<<ans<<endl;
	return 0;
}


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

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

  int cnt=0;
  vector<int> v(n);
  for(int i=0; i<n; i++){
  	cin >> v[i];
    if((i+1)%2==1 && v[i]%2==1) cnt++;
  }
    
  cout << cnt << endl;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define all(v) v.begin(), v.end()
#define sz(v) v.size()
#define INF 100000000000000 //10^14
template <typename T>
bool chmax(T &a, const T& b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T>
bool chmin(T &a, const T& b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
  if ((x += a.x) >= mod) x -= mod;
  return *this;
  }
  mint& operator-=(const mint a) {
  if ((x += mod-a.x) >= mod) x -= mod;
  return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
  if (!t) return 1;
  mint a = pow(t>>1);
  a *= a;
  if (t&1) a *= *this;
  return a;
  }
  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

// Sieve of Eratosthenes
// https://youtu.be/UTVg7wzMWQc?t=2774
struct Sieve {
  using P = pair<int, int>;
  int n;
  vector<int> f, primes; //f.at(x)はxの最小素因数
  Sieve(int n=1):n(n), f(n+1) {
  f[0] = f[1] = -1;
  for (ll i = 2; i <= n; ++i) {
    if (f[i]) continue; //ここでf[i]==0なら素数
    primes.push_back(i);
    f[i] = i;
    for (ll j = i*i; j <= n; j += i) {
  if (!f[j]) f[j] = i;
    }
  }
  }
  bool isPrime(int x) { return f[x] == x;}
  vector<int> factorList(int x) { //xの素因数を小さい順に列挙
  vector<int> res;
  while (x != 1) {
    res.push_back(f[x]);
    x /= f[x];
  }
  return res;
  }
  vector<P> factor(int x) {
  vector<int> fl = factorList(x);
  if (fl.size() == 0) return {};
  vector<P> res(1, P(fl[0], 0));
  for (int p : fl) { //ここでランレングス圧縮
    if (res.back().first == p) {
  res.back().second++;
    } else {
  res.emplace_back(p, 1);
    }
  }
  return res;
  }
};
// Sieve sieve(N);でN以下の各自然数の最小素因数を調べ上げる
// sieve.factor(M)でMの素因数分解

int main()
{
    ll N;
    cin >> N;
    Sieve sieve(N);
    vector<ll> pf(0);
    for(auto p : sieve.primes){
        ll i = 1;
        ll cnt = 0;
        ll q = p;
        while(q <= N){
            cnt += N / q;
            q *= p;
        }
        pf.push_back(cnt);
    }
    mint ans = 1;
    for(auto c : pf){
        ans *= c + 1;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<deque>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<string>
#define rep(i,n,m) for(int i=(n);i<(int)(m);i++)
#define reps(i,n,m) for(int i=(n);i<=(int)(m);i++)
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define lb lower_bound
#define ub upper_bound
#define LB(a,x) lb(all(a), x) - a.begin()
#define UB(a,x) ub(all(a), x) - a.begin()
#define printfdouble(x) printf("%.12f\n",(x))
#define MOD 1000000007
#define itn int
#define enld endl
#define ednl endl
#define icn cin
#define stirng string
using namespace std;
typedef long long ll;
const double pi = 3.141592653589793;
using Graph = vector<vector<int>>;
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;}
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    string s; cin >> s;
    rep(i,0,(1<<3)){
        int sum = 0;
        sum += (int)(s[0]-'0');
        char op[3];
        rep(j,0,3){
            if(i & (1<<(2-j))){
                op[j] = '+';
                sum += (int)(s[j+1]-'0');
            }else{
                op[j] = '-';
                sum -= (int)(s[j+1]-'0');
            }
        }
        if(sum == 7){
            cout << s[0] << op[0] << s[1] << op[1] << s[2] << op[2] << s[3] << "=7" << endl;
            return 0;
        }
    }
}

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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
#define LL long long
LL n;
LL x[100000];

#define MOD 1000000007
#define FACT_MAX 1000000

LL fact[FACT_MAX];

class Combinatrics{
private:
  long long mod = MOD;
  int fact_max = FACT_MAX;
public:
  Combinatrics(){
    fact[0]=1;
    for(int i=1;i<fact_max;i++)
      fact[i] = (fact[i-1]*i)%mod;
  }
  
  long long power(long long n, long long e){
    long long ret = 1;
    long long b = n;
    while(e){
      if(e%2!=0)
	ret*=b;
      ret%=mod;
      b*=b;
      b%=mod;
      e/=2;
    }
    return ret;
  }

  long long inv(long long n){
    return power(n,mod-2);
  }

  long long div(long long n1,long long n2){
    return n1*power(n2,mod-2)%mod;
  }
  
  long long nck(int n,int k){
    if(k>n || k<0) return 0LL;
    if(k==n || k==0) return 1LL;
    return (fact[n]*inv(fact[n-k])%mod)*inv(fact[k])%mod;
  }
};


int main(){
  cin>>n;
  REP(i,n)cin>>x[i];
  LL ret=0,acm=0;
  Combinatrics comb;
  REP(i,n-1){
    acm=(acm+comb.div(1,i+1))%MOD;
    ret=(ret+((fact[(int)n-1]*acm%MOD)*(x[i+1]-x[i])%MOD))%MOD;
  }
  cout<<ret<<endl;
  return 0;
}


Measured memory_bytes: 8832
#include <bits/stdc++.h>
using namespace std;
char m;
int h,w,arr[1009][1009],moder=1e9+7;
int main()
{
    cin>>h>>w;
    memset(arr,0,sizeof(arr));
    for(int i=1;i<=h;i++)
    {
        for(int j=1;j<=w;j++)
        {
             cin>>m;
             if(m=='#')
                arr[i][j]=-1;
        }
    }
    for(int i=h;i>0;i--)
    {
        if(arr[i][w]==0)
            arr[i][w]=1;
        else if(arr[i][w]==-1)
            break;
    }
    for(int i=w;i>0;i--)
    {
        if(arr[h][i]==0)
            arr[h][i]=1;
        else if(arr[h][i]==-1)
            break;
    }
    for(int i=h-1;i>0;i--)
    {
        for(int j=w-1;j>0;j--)
        {
            if(arr[i][j]==-1)
                continue;
            arr[i][j]=arr[i][j]%moder;
            if(arr[i+1][j]>(-1))
                arr[i][j]+=arr[i+1][j]%moder;
            arr[i][j]%=moder;
            if(arr[i][j+1]>-1)
                arr[i][j]+=arr[i][j+1]%moder;
            arr[i][j]%=moder;
        }
    }
    /*for(int i=1;i<=h;i++)
    {
        for(int j=1;j<=w;j++)
        {
            cout<<arr[i][j]<<"\t";
        }
        cout<<"\n";
    }*/
    cout<<arr[1][1]%moder;
}


Measured memory_bytes: 4224
#include <cstdio>
#include <climits>
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <stack>
#include <algorithm>
#include <iomanip>
#include <map>
#include <queue>
#include <functional>
#include <numeric>
#include <chrono>
#include <cstdlib>
using ll = long long;
using namespace std;

const ll MOD = 1e9 + 7;
const double pi = acos(-1);
#define REP(i, n) for (int(i) = 0; (i) < (n); ++(i))
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
#define EPS 1e-4
// bool operator<(const pair<int, int> &a, const pair<int, int> &b)
// {
//     if (a.first == b.first)
//         return a.second < b.second;
//     return a.first < b.first;
// };

/*unsigned int xor128(void)
{
    static unsigned int x = 123456789, y = 362436069, z = 521288629, w = 88675123;
    unsigned int t = (x ^ (x << 11));
    x = y;
    y = z;
    z = w;
    return (w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)));
}
unsigned int xor128rnd(unsigned int m)
{
    return xor128() % m;
}*/

bool operator<(const pair<int, int> &a, const pair<int, int> &b)
{
    if (a.first == b.first)
    {
        return a.second < b.second;
    }
    return a.first < b.first;
}

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

    int N;
    cin >> N;
    string A, B, C;
    cin >> A >> B >> C;
    int ans = 0;
    for (int i = 0; i < N; ++i)
    {
        if (A[i] != B[i] && B[i] != C[i] && A[i] != C[i])
        {
            ans += 2;
        }
        else if (A[i] != B[i] && A[i] == C[i])
            ans++;
        else if (A[i] != C[i] && B[i] == C[i])
            ans++;
        else if (B[i] != C[i] && A[i] == B[i])
            ans++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)
#define VL vector<ll>
#define VS vector<string>
#define VB vector<bool>
#define VP vector<pair<ll,ll>>
#define VVL vector<vector<ll>>
#define VVP vector<vector<pair<ll,ll>>>
#define PL pair<ll,ll>
#define ALL(v) (v).begin(), (v).end()
ll d1[4] = {1, -1, 0, 0};
ll d2[4] = {0, 0, 1, -1};

int main(){
    ll n;
    cin >> n;
    VL a(n), b(n), c(n);
    
    rep(i, 0, n) cin >> a[i];
    rep(i, 0, n) cin >> b[i];

    ll suma = accumulate(ALL(a), 0LL);
    ll sumb = accumulate(ALL(b), 0LL);
    if(sumb > suma) {
        cout << -1 << endl;
        return 0;
    }

    VL diff(n);
    rep(i, 0, n) diff[i] = a[i] - b[i];
    sort(ALL(diff));
    ll neg = 0, ans = 0;
    rep(i, 0, n) {
        cerr << diff[i] << " ";
        if(diff[i] < 0){
            neg -= diff[i];
            ans++;
        }else{
            break;
        }
    }    
    cerr << endl;
    reverse(ALL(diff));
    ll pos = 0;
    rep(i, 0, n){
        if(pos < neg) {
            pos += diff[i];
            ans++;
        }else{
            break;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 6284
#include <iostream>
#include <map>

using namespace std;

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

int main() {
  
  int N; while(cin >> N&&N){
  map<int,int> cnt; rep(i, N) { int x; cin >> x; cnt[x] ++; }
  bool ans = 0;
  for(auto i: cnt) { if(i.second > N/2) { ans = 1; cout << i.first << endl; } }
  if(!ans) cout << "NO COLOR\n";}
  
  return 0;
}

Measured memory_bytes: 2736
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <iomanip>
using namespace std;

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

  string s;
  cin >> s;
  cout << s[0] << s.size() - 2 << s[s.size()-1] << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-3;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
typedef pair<ld, ld> LDP;
const int max_v = 100001;
int n, x; ll w[100], v[100];
ll dp[1<<17];
int main() {
	cin >> n>>x;
	rep(i, n)cin >> w[i] >> v[i];
	rep(i, max_v)dp[i] = INF;
	dp[0] = 0;
	rep(i, n) {
		per(j, max_v) {
			if (dp[j]==INF)continue;
			dp[j + v[i]] = min(dp[j + v[i]], dp[j] + w[i]);
		}
	}
	ll ans = 0;
	rep(i, max_v)if (dp[i] <= x)ans = i;
	cout << ans << endl;
	//stop
	return 0;
}

Measured memory_bytes: 1024
import java.util.Scanner;


public class Main {
	private	static	Scanner		m_stdin = null;
	private	static	double[]	m_point = null;

	static {
		m_stdin = new Scanner(System.in);
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		double[][]	aMatrix = null;
		int			nMax    = m_stdin.nextInt();

		for (int nLoop = 0; nLoop < nMax; nLoop++) {
			aMatrix = parseMatrix();
			calc(aMatrix);
		}
	}

	private static double[][] parseMatrix() {
		double[][]	aMatrix = null;

		double	dx1 = m_stdin.nextDouble();
		double	dy1 = m_stdin.nextDouble();
		double	dx2 = m_stdin.nextDouble();
		double	dy2 = m_stdin.nextDouble();
		double	dx3 = m_stdin.nextDouble();
		double	dy3 = m_stdin.nextDouble();

		aMatrix = new double[3][3];

		aMatrix[0][0] = (dx2 - dx1) * 2.0;
		aMatrix[0][1] = (dy2 - dy1) * 2.0;
		aMatrix[0][2] = (dx2 * dx2) - (dx1 * dx1) + (dy2 * dy2) - (dy1 * dy1);

		aMatrix[1][0] = (dx3 - dx2) * 2.0;
		aMatrix[1][1] = (dy3 - dy2) * 2.0;
		aMatrix[1][2] = (dx3 * dx3) - (dx2 * dx2) + (dy3 * dy3) - (dy2 * dy2);

		aMatrix[2][0] = (dx1 - dx3) * 2.0;
		aMatrix[2][1] = (dy1 - dy3) * 2.0;
		aMatrix[2][2] = (dx1 * dx1) - (dx3 * dx3) + (dy1 * dy1) - (dy3 * dy3);

		m_point = new double[2];
		m_point[0] = dx1;
		m_point[1] = dy1;

		return aMatrix;
	}

	private static void calc(double[][] aMatrix) {
		int nFinRow = 0;
		int nActRow = -1;

		for(int nCols = 0; nCols < aMatrix[0].length - 1; nCols++) {
			nActRow = -1;

			// 全ての行のnCols番目の列の要素が1になるように行の要素を除算する
			for(int nRols = 0; nRols < aMatrix.length; nRols++) {
				if ((nFinRow & 1 << nRols) != 0) {
					continue;
				}

				if (aMatrix[nRols][nCols] != 0.0) {
					if (nActRow == -1) {
						nActRow = nRols;
						nFinRow = nFinRow | 1 << nRols;
					}

					for(int nLoop = aMatrix[0].length - 1; nLoop >= nCols; nLoop--) {
						aMatrix[nRols][nLoop] /= aMatrix[nRols][nCols];
					}
				}
			}

			// 全ての列の要素から最初に要素を1にした列の要素を減算する
			for(int nRols = 0; nRols < aMatrix.length; nRols++) {
				if (aMatrix[nRols][nCols] != 0.0 && nRols != nActRow) {
					for(int nLoop = aMatrix[0].length - 1; nLoop >= nCols; nLoop--) {
						double	dWork = aMatrix[nRols][nCols] * aMatrix[nActRow][nLoop];
						aMatrix[nRols][nLoop] -= dWork;
					}
				}
			}
		}

		{
			double da = 0.0;
			double db = 0.0;
			double dr = 0.0;

			for(int nRols = 0; nRols < aMatrix.length; nRols++) {
				if (aMatrix[nRols][0] == 1.0) {
					da = aMatrix[nRols][2];
				}
				if (aMatrix[nRols][1] == 1.0) {
					db = aMatrix[nRols][2];
				}
			}

			dr = Math.sqrt(((m_point[0] - da) * (m_point[0] - da)) + ((m_point[1] - db) * (m_point[1] - db)));

			System.out.printf("%.3f %.3f %.3f\n", da, db, dr);
		}
	}
}

Measured memory_bytes: 20732
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;

namespace C_GrandGarden
{
    public class Program
    {
        public static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            var h_list = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            int[] flowerBed = new int[n];

            int water_count = 0;
            var dis_list = flowerBed.Select((x, i) => h_list[i] - x).ToArray();

            for (int i = 0; i < n;)
            {
                //差が0以外になるまで増やす
                i += dis_list.BeginEnd(i, n).TakeWhile(x => x == 0).Count();
                var count = dis_list.BeginEnd(i, n).TakeWhile(x => x > 0).Count();

                water_count += Watering(flowerBed, h_list, i, i + count);

                i += count;
            }

            Console.WriteLine(water_count);
        }

        public static int Watering(int[] flowerBed, int[] h_list, int begin, int end)
        {
            if (begin >= end)
            {
                return 0;
            }

            for (int i = begin; i < end; i++)
            {
                flowerBed[i]++;
            }

            int water_count = 1;
            var dis_list = flowerBed.Select((x, i) => h_list[i] - x).ToArray();

            for (int i = begin; i < end;)
            {
                //差が0以外になるまで増やす
                i += dis_list.BeginEnd(i, end).TakeWhile(x => x == 0).Count();
                var count = dis_list.BeginEnd(i, end).TakeWhile(x => x > 0).Count();

                water_count += Watering(flowerBed, h_list, i, i + count);

                i += count;
            }

            return water_count;
        }

    }

    public static class Extensions
    {
        public static IEnumerable<T> BeginEnd<T>(this T[] list, int begin, int end)
        {
            for (int i = begin; i < end; i++)
            {
                yield return list[i];
            }
        }
    }
}


Measured memory_bytes: 17612
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <functional>
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000

int A[21][21];
int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, M, C;
    cin >> N >> M >> C;
    int B[21];
    
    rep(i, M) cin >> B[i];
    rep(i, N) rep(j, M) cin >> A[i][j];
    int ans = 0;
    rep(i, N) {
        int sum = 0;
        rep(j, M) {
            sum += A[i][j] * B[j];
        }
        if(sum + C > 0) ans++;
    }
    cout << ans << endl;

    return 0;
}


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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define pb push_back
#define rep(i, a, n) for(int i = (a); i < (n); i++)
#define dep(i, a, n) for(int i = (a); i >= (n); i--)
#define mod (ll)(1e9+7)
#define int ll

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

signed main() {
  ll n, a[200001];
  map<int, int> mp;
  cin >> n;

  rep(i, 0, n) cin >> a[i];
  rep(i, 1, n) {
    a[i] += a[i - 1];
    mp[a[i]]++;
  }
  mp[a[0]]++;
  cout << endl;
  int ans = 0;
  for(auto it = mp.begin(); it != mp.end(); it++) {
    if(it->second > 1) {
      rep(i, 0, it->second - 1) ans += i + 1;
    }
  }
  ans += mp[0];
  cout << ans << endl;
}


Measured memory_bytes: 14336