akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define MAX_1 25
#define MAX_2 205

int A[MAX_1];
int dp[2005][2005];
int n, q;

int solve(int i, int m) {
	if (dp[i][m] != 0)
		return dp[i][m];

	if (m == 0)
		dp[i][m] = 1;
	else if (i >= n)
		dp[i][m] = 2;
	else if (solve(i + 1, m) == 1)
		dp[i][m] = 1;
	else if (solve(i + 1, m - A[i]) == 1) 
		dp[i][m] = 1;
	else 
		dp[i][m] = 2;

	return dp[i][m];
}

int main(void) {
	int i, m;
	cin >> n;
	for (i = 0; i < n; i++) {
		cin >> A[i];
	}
	cin >> q;
	for (i = 0; i < q; i++) {
		cin >> m;
		if (solve(0, m) == 1)
			cout << "yes" << endl;
		else 
			cout << "no" << endl;
	}

}


Measured memory_bytes: 3276
using System;
using System.Collections.Generic;
namespace alds17a
{
    class node{
        public int id;
        public node parent;
        public List<node> child;
        public int dep;

        public node(int setid)
        {
            id = setid;
            child=new List<node>();
        }
        public void addchild(node newchild)
        {
            child.Add(newchild);
            newchild.parent = this;
            newchild.setdep();
        }
        public void printparent()
        {
            try
            {
                Console.Write(this.parent.id);
            }
            catch (NullReferenceException)
            {
                Console.Write("-1");
            }
        }
        public void setdep()
        {
            if (parent == null)
            {
                dep = 0;
            }
            else
            {
                dep = parent.dep + 1;
            }
            foreach (node childs in child)
            {
                childs.setdep();
            }
            return;
        }
        public string nodetype()
        {
            if (dep == 0)
            {
                return "root";
            }
            else if (child.Count == 0)
            {
                return "leaf";
            }
            else
            {
                return "internal node";
            }
        }
    }
    class main
    {
        static void Main()
        {
            List<node> all=new List<node>();
            int n = int.Parse(Console.ReadLine());
            for (int i = 0; i < n; i++)
            {
                all.Add(new node(i));
            }
            for (int i = 0; i < n; i++)
            {
                string[] input = Console.ReadLine().Split(' ');
                int tgt = int.Parse(input[0]);
                int cn = int.Parse(input[1])+2;
                for (int j = 2; j < cn; j++)
                {
                    all[tgt].addchild(all[int.Parse(input[j])]);
                }
            }
            foreach (node target in all)
            {
                Console.Write("node ");
                Console.Write(target.id);
                Console.Write(": parent = ");
                target.printparent();
                Console.Write(", depth = ");
                Console.Write(target.dep);
                Console.Write(", ");
                Console.Write(target.nodetype());
                Console.Write(", [");
                if (target.child.Count != 0)
                {
                    Console.Write(target.child[0].id);
                    for (int i = 1; i < target.child.Count; i++)
                    {
                        Console.Write(", ");
                        Console.Write(target.child[i].id);
                    }
                }
                Console.WriteLine("]");
            }
        }
    }
}

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

// template {{{  0 
// using {{{ 1
using ll = long long int;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vii = vector<pii>;
using vll = vector<pll>;
// }}} 1
// definition {{{ 1
// scaning {{{ 2
#define Scd(x) scanf("%d", &x)
#define Scd2(x,y) scanf("%d%d", &x, &y)
#define Scd3(x,y,z) scanf("%d%d%d", &x, &y, &z)
#define Scll(x) scanf("%lld", &x)
#define Scll2(x,y) scanf("%lld%lld", &x, &y)
#define Scll3(x,y,z) scanf("%lld%lld%lld", &x, &y, &z)
#define Scc(c) scanf("%c", &c);
#define Scs(s) scanf("%s", s);
#define Scstr(s) scanf("%s", &s);
// }}} 2
// constants {{{ 2
#define EPS (1e-7)
#define INF (2e9)
#define PI (acos(-1))
// }}} 2
// systems {{{ 2
#define Repe(x,y,z) for(ll x = z; x < y; x++)
#define Rep(x,y) Repe(x,y,0)
#define RRepe(x,y,z) for(ll x = y-z-1; x >= 0; x--)
#define RRep(x,y) RRepe(x,y,0)
// }}} 2
// output {{{ 2
#define YesNo(a) (a)?printf("Yes\n"):printf("No\n")
#define YESNO(a) (a)?printf("YES\n"):printf("NO\n")
// }}} 2
// }}} 1
// input {{{ 1
// }}} 1
// }}} 0

int main() {

    int L;
    Scd(L);

    vi a(L);

    Rep(i,L){
        Scd(a[i]);
    }

    static ll dp[5][222222] = {};
    Rep(i,5) Rep(j,L+1) dp[i][j] = 1e16;
    dp[0][0] = 0;

    int co = 0;
    Rep(i,L){

        co = a[i];
        dp[0][i+1] = min( dp[0][i+1], dp[0][i] + co );

        co = a[i]==0? 2 : a[i]%2;
        dp[1][i+1] = min( dp[1][i+1], dp[0][i] + co );
        dp[1][i+1] = min( dp[1][i+1], dp[1][i] + co );

        co = (a[i]%2)^1;
        dp[2][i+1] = min( dp[2][i+1], dp[0][i] + co );
        dp[2][i+1] = min( dp[2][i+1], dp[1][i] + co );
        dp[2][i+1] = min( dp[2][i+1], dp[2][i] + co );

        co = a[i]==0? 2 : a[i]%2;
        dp[3][i+1] = min( dp[3][i+1], dp[0][i] + co );
        dp[3][i+1] = min( dp[3][i+1], dp[1][i] + co );
        dp[3][i+1] = min( dp[3][i+1], dp[2][i] + co );
        dp[3][i+1] = min( dp[3][i+1], dp[3][i] + co );

        co = a[i];
        dp[4][i+1] = min( dp[4][i+1], dp[0][i] + co );
        dp[4][i+1] = min( dp[4][i+1], dp[1][i] + co );
        dp[4][i+1] = min( dp[4][i+1], dp[2][i] + co );
        dp[4][i+1] = min( dp[4][i+1], dp[3][i] + co );
        dp[4][i+1] = min( dp[4][i+1], dp[4][i] + co );

    }

    ll ans = 1e15;

    Rep(i,5) ans = min( ans, dp[i][L] );

    printf ("%lld\n", ans );

    return 0;
}



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

using namespace std;

int a, b;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    
    cin >> a >> b;

    for(int i = 1; i <= 1000000; i++){
        int g = i * 8;
        g /= 100;
        int h = i / 10;
        if(g == a && h == b){
            cout << i << '\n';
            return 0;
        }
    }
    cout << -1 << '\n';
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

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

	int x = a / 4;
	int y = a / 7;

	for (int i = 0; i <= x; i++) {
		for (int j = 0; j <= y; j++) {
			if (4 * i + 7 * j == a) {
				cout << "Yes" << endl;
				return 0;
			}
		}
	}

	cout << "No" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define all(x) (x).begin(), (x).end()
using ll = long long;
using namespace std;
template <typename T> using vec = std::vector<T>;

int main() {
    ll N;
    cin >> N;
    string ans = "";

    string al = "zabcdefghijklmnopqrstuvwxyz";
    while (N > 0) {
        char c = al[N % 26];
        ans    = c + ans;
        if (N % 26 == 0) {
            N -= 26;
        } else {
            N -= (N % 26);
        }

        N /= 26;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3624
from sys import stdin

def main():
  read = stdin.readline
  A,B = list(read().split(" "))
  B = 100*int(B[0]) + 10*int(B[2]) + 1 * int(B[3])
  c = int(A) * B
  print(c//100)
  
  
  
if __name__ == "__main__":
  main()

Measured memory_bytes: 9172
# -*- coding: utf-8 -*-
n = int(input())
l = list(map(int, input().split()))

count = 0
for i in range(n-2):
    for j in range(i+1, n-1):
        if l[i] == l[j]:
            continue

        for k in range(j + 1, n):
            if l[k] in (l[i], l[j]):
                continue

            c = sorted([l[i], l[j], l[k]])
            if c[0] + c[1] > c[2]:
                count += 1

print(count)


Measured memory_bytes: 9196
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return 1;
    }
    return 0;
}
typedef long long int ll;

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define endl "\n"
const double EPS = 1e-7;
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
const double PI = acos(-1);
const int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

//-------------------------------------

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    ll n = (ll)s.size() + 1;

    vector<ll> id;
    id.push_back(-1);
    for (ll i = 0; i < (n - 1) - 1; i++)
    {
        if (s[i] == '>' && s[i + 1] == '<')
        {
            id.push_back(i);
        }
    }
    id.push_back(n - 2);

    ll ans = 0;
    for (ll a = 0; a < (ll)id.size() - 1; a++)
    {
        ll cnt = 0;
        for (ll i = id[a] + 1; i <= id[a + 1]; i++)
        {
            if (s[i] == s[i + 1])
            {
                cnt++;
            }
            else
            {
                break;
            }
        }
        cnt++;
        ll l = cnt;
        ll r = id[a + 1] - id[a] - cnt;
        if (l > r)
        {
            swap(l, r);
        }
        ans += (l - 1) * l / 2 + r * (r + 1) / 2;
    }
    cout << ans << endl;
}

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

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int[] arrivals = new int[100];
		int[] seats = new int[17];
		int[] end_seats = new int[17];
		int[] wait = new int[100];
		Arrays.fill(seats, -1);
		Arrays.fill(end_seats, -1);

		for (int i = 0; i < 100; i++) {
			arrivals[i] = 5 * i;
		}

		int porpos = 0;
		END: for (int time = 0;; time++) {
			
			for (int i = 0; i < 17; i++) {
				if (seats[i] != -1 && end_seats[i] <= time) {
					seats[i] = -1;
				}
			}
			
			LOOP:while (arrivals[porpos] <= time) {
				
				//System.out.println(porpos);
				
				boolean f_fount = false;
				for (int i = 0; i <= 17 - (porpos % 5 == 1 ? 5 : 2); i++) {
					boolean found = true;
					for (int j = 0; j < (porpos % 5 == 1 ? 5 : 2); j++) {
						if (seats[i + j] != -1) {
							found = false;
							break;
						}
					}

					if (found) {
						f_fount = true;
						
						for (int j = 0; j < (porpos % 5 == 1 ? 5 : 2); j++) {
							seats[i + j] = porpos;
							end_seats[i + j] = time + 17 * (porpos % 2) + 3
									* (porpos % 3) + 19;
							wait[porpos] = time - arrivals[porpos];

						}
						if (porpos == 99) {
							break END;
						}

						porpos++;
						break;
					}
				}
				
				if(!f_fount){
					break;
				}
			}
			
			//System.out.println("time = " + time + " : " + Arrays.toString(seats));
		}

		while (sc.hasNext()) {
			System.out.println(wait[sc.nextInt()]);
		}
	}

}

Measured memory_bytes: 12000
n = int(input())
restraunt = [[] for i in range(n)]
for i in range(n):
    s, p = input().split()
    p = int(p)
    restraunt[i] = [i+1, s, -p]
restraunt.sort(key = lambda restraunt: (restraunt[1], restraunt[2]))
for i in range(n):
    print(restraunt[i][0])

Measured memory_bytes: 3064
def partition(n_list, p, r):
    x = n_list[r-1]
    i = p - 1
    for j in range(p, r-1):
        if n_list[j] <= x:
            i += 1
            y = n_list[i]
            n_list[i] = n_list[j]
            n_list[j] = y
    y = n_list[i]
    n_list[r-1] = n_list[i+1]
    n_list[i+1] = f'[{x}]'

    
n = int(input())
n_list = list(map(int, input().split()))
partition(n_list, 0, n)
print(' '.join(list(map(str, n_list))))


Measured memory_bytes: 16396
N, K ,Q = map(int,input().split())
p = [0 for _ in range(N)]
for i in range(Q):
    a = int(input())
    p[a-1] += 1
for i in range(N):
    if (K-Q+p[i]) <= 0 :
        print("No")
    else :
        print("Yes")

Measured memory_bytes: 4680
/*
    -ensure correct output format
    -ensure printing required output
    -reread the problem statement
  */

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll>pll;
typedef pair<ll,pair<ll,ll>>plll;
#define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL));
#define vll(v) v.begin(),v.end()
#define all(x) x.rbegin(),x.rend()
#define min3(a, b, c)   min(a, min(b, c))
#define max3(a, b, c)   max(a, max(b, c))
#define F first
#define S second
#define in  freopen("input.txt", "r", stdin)
#define out  freopen("output.txt", "w", stdout)
#define minheap int,vector<int>,greater<int>
#define pb push_back
#define eb emplace_back
#define ischar(x)  (('a' <= x && x <= 'z') || ('A' <= x && x <= 'Z'))
#define isvowel(ch) ((ch=='a'||ch=='e'||ch=='i'||ch=='o'||ch=='u')||(ch=='A'|| ch=='E' || ch=='I'|| ch=='O'|| ch=='U'))
#define bug cout<<"BUG"<<endl;
const int Max = 1e5 + 10;
const int Mod = 1e9 + 7;
const double PI  =3.141592653589793238463;
bool compare(const pair<ll,ll> &a, const pair<ll,ll> &b)
{
       return (a.first > b.first);
}
ll lcm(ll a,ll b)
{
    if(a==0 || b==0)return 0;

    return a/__gcd(a,b)*b;
}

void input(ll ara[],ll n)
{
    for(ll i=0; i<n; i++)cin>>ara[i];
}
void print(ll ara[],ll n)
{
    for(ll i=0; i<n; i++)
        cout<<ara[i]<<" ";
    cout<<endl;
}


ll dp[Max+10][14];


int main()
{

   fastread();

   ll i,j,n,m,p,a,sum=0,k,t,b,c,d,cnt=0,q,l,r,ans=0;

      bool flag=false;

      string str;

      dp[0][0]=1;


      cin>>str;

      n=str.size();


      for(i=0; i<n; i++)
      {


            for(j=0; j<10; j++)
            {
                ll num=j;

                if(str[i]!='?')
                    num=str[i]-'0';


                for(k=0; k<=12; k++)
                {
        dp[i+1][((k*10)+num)%13]= (dp[i+1][((k*10)+num)%13]+dp[i][k])%Mod;
                }


                if(str[i]!='?')break;
            }
      }

      cout<<dp[n][5]<<endl;













}



Measured memory_bytes: 14684
#include <bits/stdc++.h>
#define all(x) (x).begin, (x).end()
using namespace std;
typedef long long int64;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<29;
const long long  INFL = 1e18;
const int MOD = 1000000007;
const int MAX = 210000;
const int MAX_NUM = 999999999;
void solve() {
	string S; cin >> S;
	if (S == "Sunny") {
		cout << "Cloudy" << endl;
	} else if(S == "Cloudy") {
		cout << "Rainy" << endl;
	} else {
		cout << "Sunny" << endl;
	}
	return;
}
int main() {
	solve();
	return 0;
}

Measured memory_bytes: 256
use proconio::input;

use rand::Rng;

struct State {
    c: Vec<i32>,
    s: Vec<Vec<i32>>,
    cur_seq: Vec<usize>,
    sat: i32,
}

impl State {
    fn init(&mut self) {
        let mut last = vec![0; 26];
        self.sat = 0;

        for i in 0..self.cur_seq.len() {
            self.sat += self.s[i][self.cur_seq[i]];
            last[self.cur_seq[i]] = (i + 1) as i32;

            for j in 0..26 {
                self.sat -= self.c[j] * ((i + 1 - last[j] as usize) as i32);
            }
        }
    }

    fn change(&mut self, d: usize, q: usize) {
        self.sat -= self.s[d][self.cur_seq[d]];
        self.sat += self.s[d][q];

        let mut last = vec![0; 26];
        for i in 0..self.cur_seq.len() {
            last[self.cur_seq[i]] = (i + 1) as i32;
            let j = self.cur_seq[d];
            self.sat += self.c[j] * ((i + 1 - last[j] as usize) as i32);
            self.sat += self.c[q] * ((i + 1 - last[q] as usize) as i32);
        }

        last = vec![0; 26];
        let p = self.cur_seq[d];
        self.cur_seq[d] = q;
        for i in 0..self.cur_seq.len() {
            last[self.cur_seq[i]] = (i + 1) as i32;

            self.sat -= self.c[p] * ((i + 1 - last[p] as usize) as i32);
            self.sat -= self.c[q] * ((i + 1 - last[q] as usize) as i32);
        }
    }
}

fn main() {
    input! {
        d: usize,
        c: [i32;26],
        s: [[i32;26]; d],
    }

    let mut state = State {
        c,
        s,
        cur_seq: vec![0; d],
        sat: 0,
    };

    let mut cur_ans = state.cur_seq.to_owned();
    let mut rng = rand::thread_rng();
    for j in 0..d {
        state.cur_seq[j] = rng.gen_range(0, 26);
    }
    state.init();
    let mut cur_sat = state.sat;

    for _ in 0..100000 {
        let d = rng.gen_range(0, d);
        let q = rng.gen_range(0, 26);
        if state.cur_seq[d] == q {
            continue;
        }
        state.change(d, q);
        if state.sat > cur_sat {
            dbg!(state.sat, cur_sat);
            cur_sat = state.sat;
            cur_ans = state.cur_seq.to_owned();
        }
    }

    dbg!(cur_sat);

    for i in cur_ans {
        println!("{}", i + 1);
    }
}


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

#ifdef BOI
#include "debug.h"
#else
#define debug(args...)
#endif

#define all(x) begin(x), end(x)
#define sz(x) (int) x.size()
#define eps 1e-7
#define inf 0x3f3f3f3f
#define endl '\n'

int main() {
    cin.tie(0)->sync_with_stdio(0), cin.exceptions(cin.failbit);
    long long n; cin >> n;

    long long ans = 0;

    for (long long i = 1; i < n; ++i) {
        ans += ((n - 1) / i);
    }

    cout << ans;
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
// type alias
typedef long long LL;
typedef pair<int,int> II;
typedef tuple<int,int,int> III;
typedef vector<int> VI;
typedef vector<string> VS;
typedef unordered_map<int,int> MAPII;
typedef unordered_set<int> SETI;
template<class T> using VV=vector<vector<T>>;
// minmax
template<class T> inline T SMIN(T& a, const T b) { return a=(a>b)?b:a; }
template<class T> inline T SMAX(T& a, const T b) { return a=(a<b)?b:a; }
// repetition
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define REPE(i,n)  for(int i=0;i<=(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define FORR(x,arr) for(auto& x:arr)
#define SZ(a) int((a).size())
// collection
#define ALL(c) (c).begin(),(c).end()
// DP
#define MINUS(dp) memset(dp, -1, sizeof(dp))
#define ZERO(dp) memset(dp, 0, sizeof(dp))
// stdout
#define println(args...) fprintf(stdout, ##args),putchar('\n');
// debug cerr
template<class Iter> void __kumaerrc(Iter begin, Iter end) { for(; begin!=end; ++begin) { cerr<<*begin<<','; } cerr<<endl; }
void __kumaerr(istream_iterator<string> it) { (void)it; cerr<<endl; }
template<typename T, typename... Args> void __kumaerr(istream_iterator<string> it, T a, Args... args) { cerr<<*it<<"="<<a<<", ",__kumaerr(++it, args...); }
template<typename S, typename T> std::ostream& operator<<(std::ostream& _os, const std::pair<S,T>& _p) { return _os<<"{"<<_p.first<<','<<_p.second<<"}"; }
#define __KUMATRACE__ true
#ifdef __KUMATRACE__
#define dump(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); __kumaerr(_it, args); }
#define dumpc(ar) { cerr<<#ar<<": "; FORR(x,(ar)) { cerr << x << ','; } cerr << endl; }
#define dumpC(beg,end) { cerr<<"~"<<#end<<": "; __kumaerrc(beg,end); }
#else
#define dump(args...)
#define dumpc(ar)
#define dumpC(beg,end)
#endif

// $ cp-batch DistMax | diff DistMax.out -
// $ g++ -std=c++14 -Wall -O2 -D_GLIBCXX_DEBUG -fsanitize=address DistMax.cpp && ./a.out

/*

 9/13/2020

 5:22-

 */

vector<II> ps;
int N;

void solve() {
  vector<int> as,bs;
  REP(i,N) {
    as.emplace_back(ps[i].first+ps[i].second);
    bs.emplace_back(ps[i].first-ps[i].second);
  }
  sort(ALL(as)),sort(ALL(bs));
  //dumpc(as);
  //dumpc(bs);
  int res=max(as[N-1]-as[0],bs[N-1]-bs[0]);
  cout<<res<<endl;
}

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

  cin>>N;
  ps=vector<II>(N);
  REP(i,N) cin>>ps[i].first>>ps[i].second;
  solve();

  return 0;
}


Measured memory_bytes: 6704
#include<iostream>
#include<stdio.h>
#include<vector>
#include<cmath>
#include<queue>
#include<string.h>
#include<map>
#include<set>
#include<algorithm>
#define ll long long
#define pi pair < ll,ll >
#define mp(a,b) make_pair(a,b)
#define rep(i,a,b) for(int i = a;i < b;i++)
#define N 300004
#define INF 1e9+7

using namespace std;

ll n;
bool can[N];

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

    cin >> n;

    can[0] = true;

    rep(i,1,n+1)
    {
        rep(j,100,106)
        {
            if(i-j<0)
                continue;

            can[i]|=can[i-j];
        }
    }

    cout << can[n];

    return 0;
}




Measured memory_bytes: 384
def COMinit(n, MOD):
    fact = [1, 1]
    fact_inv = [1, 1]
    inv = [0, 1]
    for i in range(2, n + 1):
        fact.append((fact[-1] * i) % MOD)
        inv.append((-inv[MOD % i] * (MOD // i)) % MOD)
        fact_inv.append((fact_inv[-1] * inv[i]) % MOD)
    return fact, fact_inv

MOD = 10**9+7
def resolve():
    def dfs1(r_topo, par):
        for idx in reversed(r_topo):
            for to in G[idx]:
                if to == par[idx]:
                    continue


    N = int(input())
    G = [[] for _ in range(N)]
    for _ in range(N-1):
        a, b = map(lambda x:int(x)-1, input().split())
        G[a].append(b)
        G[b].append(a)

    fact, fact_inv = COMinit(N, MOD)

    topo = []
    P = [-1] * N
    node = [0]
    while node:
        v = node.pop()
        topo.append(v)
        for to in G[v]:
            if to == P[v]:
                continue
            P[to] = v
            node.append(to)

    # 葉のサイズを格納
    size = [1]*N
    for e in reversed(topo):
        if e == 0:
            break
        size[P[e]] += size[e]

    dp1 = [1]*N
    for e in reversed(topo):
        dp1[e] = dp1[e] * fact[size[e] - 1] % MOD
        if e == 0:
            break
        dp1[P[e]] = (dp1[P[e]] * dp1[e] % MOD) * fact_inv[size[e]] % MOD

    dp2 = [0] * N
    dp2[0] = dp1[0]
    for e in topo[1:]:
        p = P[e]
        tmp = (dp2[p] * fact[N - 1 - size[e]] % MOD) * fact[size[e]] % MOD
        red = (tmp * fact_inv[N - 1] % MOD) * pow(dp1[e], MOD - 2, MOD) % MOD

        size_red = N - size[e]
        tmp = (dp1[e] * red % MOD) * fact[N - 1] % MOD
        dp2[e] = (tmp * fact_inv[size[e] - 1] % MOD) * fact_inv[size_red] % MOD

    print(*dp2, sep="\n")

if __name__ == "__main__":
    resolve()


Measured memory_bytes: 77604
#include <iostream>
#include <vector>
#include <string>

int N, M;
int array[200200];
std::vector<int> matchedPoint;
bool flag = false;

int main(){
    std::cin >> N >> M;
    int tmpa, tmpb;
    for(int i = 0; i < M; i++){
        std::cin >> tmpa >> tmpb;
        if(tmpa == 1){
            matchedPoint.push_back(tmpb);
        }
        if(tmpb == N){
            matchedPoint.push_back(tmpa);
        }
    }
    
    for(int i = 0; i < matchedPoint.size(); i++){
        if(array[matchedPoint[i]]){
            flag = true;
            break;
        }
        array[matchedPoint[i]]++;
    }

    std::string message;
    if(flag){
        message = "POSSIBLE";
    }
    else{
        message = "IMPOSSIBLE";
    }
    std::cout << message << std::endl;
    return 0;
}

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

void pfact(int n){
  for(int i=1;i<=sqrt(n);i++){
    if(n%i==0)cout<<i<<endl;
  }
  for(int j=sqrt(n);j>=1;j--){
    if(j*j==n)continue;
    if(n%j==0) cout<<(n/j)<<endl;
  }
}

int main(){
  int n;cin>>n;
  int t;cin>>t;
  for(int i=1;i<n;i++){
    int t2;cin>>t2;
    t=__gcd(t,t2);
  }
  pfact(t);
}



Measured memory_bytes: 3052
#include <stdio.h>
#define N 100000

int main(){
	
	int k;
	scanf("%d", &k);
	long long int lun[N];
	int start = 0,last = 8, now = 9;
	for(int i = 1; i < 10; i++){ lun[i-1] = (long long int)i; }
	while(now < N){
		for(int j = start; j <= last; j++){
			if(now >= N) break;
			if(lun[j]%10 == 0){
				lun[now++] = lun[j]*10;
				if( now < N ){ lun[now++] = lun[j]*10+1; }
			} else if(lun[j]%10 == 9){
				lun[now++] = lun[j]*10+8;
				if( now < N ){ lun[now++] = lun[j]*10+9; }
			} else {
				lun[now++] = lun[j]*10+lun[j]%10-1;
				if( now < N ){ lun[now++] = lun[j]*10+lun[j]%10; }
				if( now < N ){ lun[now++] = lun[j]*10+lun[j]%10+1; }
			}
		}
		start = last+1; last = now-1;
	}
	printf("%lld", lun[k-1]);
	
}

Measured memory_bytes: 896
import numpy as np
n = int(input())
p = np.array(list(map(float, input().split())))

head = np.zeros(n+1)
head[0] = 1
for i in range(n):
  #print(head)
  mask = np.r_[np.ones(i+1), np.zeros(n-i)]
  h1 = head * (1 - p[i]) * mask
  h2 = head * p[i] * mask
  head = h1 + np.r_[np.zeros(1), h2[:-1]]

print(sum(head[n//2+1:]))


Measured memory_bytes: 14664
from sys import stdin, stdout, setrecursionlimit
from collections import deque, defaultdict, Counter
from heapq import heappush, heappop
from functools import lru_cache
import math

#setrecursionlimit(10**6)
rl = lambda: stdin.readline()
rll = lambda: stdin.readline().split()
rli = lambda: map(int, stdin.readline().split())
rlf = lambda: map(float, stdin.readline().split())

INF, NINF = float('inf'), float('-inf')
MOD = 10**9 + 7

def main():
	n = int(rl())
	H = list(rli())
	maxx = H[0]
	ans = 0
	for i in range(1, n):
		if H[i] < maxx:
			ans += maxx - H[i]
		maxx = max(H[i], maxx)
	print(ans)
	stdout.close()

if __name__ == "__main__":
	main()

Measured memory_bytes: 92396
// #include <bits/stdc++.h>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <vector>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <string>
// #include <deque>
// #include <queue>
// #include <array>
// #include <ctime>
// #include <list>
#include <map>
#include <set>
// #include <complex>
// #include <cassert>
// #include <sstream>
// #include <forward_list>
// #include <unordered_set>
// #include <unordered_map> 
// #include <ctime>
 
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> // Common file  
#include <ext/pb_ds/tree_policy.hpp>  
#include <functional> // for less  
using namespace __gnu_pbds;  

// Declaring ordered_set 
typedef tree<int, 
    null_type, 
    less<int>, 
    rb_tree_tag, 
    tree_order_statistics_node_update>  
    ordered_set;  
 
#define int long long
#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define scani(n) scanf("%d",&n);
#define EPS 1e-9
#define arrinput for(int i=0; i<n; i++) cin>>arr[i];
#define sumarr for(int i=0; i<n; i++) sum+=arr[i];
#define for0(i,n) for(int i=0; i<n; i++)
#define for1(i,n) for(int i=1; i<=n; i++)
#define forr(i,n) for(int i=n-1; i>=0; i--)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
 
typedef long long ll;  
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<pii> vii;
 
const int MOD = 1e9+7;
const int n_ = 1e5+1000;
const long double PI = acos(-1.0);
 
ll gcd (ll a, ll b) {return ( a ? gcd(b%a, a) : b );}
ll power(ll a, ll n) {ll p = 1;while (n > 0) {if(n%2) {p = p * a;} n >>= 1; a *= a;} return p;}
ll power(ll a, ll n, ll mod) {ll p = 1;while (n > 0) {if(n%2) {p = p * a; p %= mod;} n >>= 1; a *= a; a %= mod;} return p % mod;}

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

	int n, a, b, c;
	cin>>n;
	int dp[n][3];
	memset(dp, 0, sizeof(dp));
	for0(i,n) {
		cin>>a>>b>>c;
		dp[i][0] = a + (i ? max(dp[i-1][1], dp[i-1][2]) : 0);
		dp[i][1] = b + (i ? max(dp[i-1][0], dp[i-1][2]) : 0);
		dp[i][2] = c + (i ? max(dp[i-1][0], dp[i-1][1]) : 0);
	}
	cout<<max({dp[n-1][0], dp[n-1][1], dp[n-1][2]});

	return 0;
}

Measured memory_bytes: 2560
#5
#1 3 5 4 2
#2
N=int(input())
li=list(map(int,input().split()))
cnt=0
for i in range(N-2):
  if li[i]<li[i+1]<li[i+2] or li[i+2]<li[i+1]<li[i]:
    cnt+=1
print(cnt)    

Measured memory_bytes: 3060
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    x = list(map(int, readline().split()))

    if x.count(5) == 2 and x.count(7) == 1:
        print("YES")
    else:
        print("NO")


if __name__ == '__main__':
    main()


Measured memory_bytes: 61840
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
int main(){
    int X,Y,Z;
    cin>>X>>Y>>Z;

    int A,B,C;
    A=X;B=Y;C=Z;
    swap(A,B);
    swap(A,C);
    cout<<A<<" "<<B<<" "<<C<<endl;
    return 0; 
}

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

/*Union Find*/
int par[100];

void init(int n){
  for(int i = 0; i < n; i++){
    par[i] = i;
  }
}

int find(int x){
  if(par[x] == x) return x;
  return par[x] = find(par[x]);
}

void unite(int x, int y){
  x = find(x);
  y = find(y);
  if(x == y) return;

  par[x] = y;
}

bool same(int x, int y){
  return find(x) == find(y);
}

/*Kruskal*/
struct edge {int u, v, cost;};

bool comp(const edge& e1, const edge& e2){
  return e1.cost < e2.cost;
}

vector<edge> es;
int N, M;

int kruskal(){
  vector<edge>::iterator it = es.begin();
  sort(it, it + M, comp);
  init(N);
  int res = 0;
  for(int i = 0; i < M; i++){
    edge e = es[i];
    if(!same(e.u, e.v)){
      unite(e.u, e.v);
      res += e.cost;
    }
  }
  return res;
}

int main(void){
  while(true){
    int a, b, cost;
    cin >> N >> M;
    if(N == 0 && M == 0) break;
    es.clear();
    for(int i = 0; i < M; i++){
      cin >> a >> b >> cost;
      edge tmp;
      tmp.u = a, tmp.v = b; tmp.cost = cost;
      es.push_back(tmp);
    }
    cout << kruskal() << endl;
  }
  return 0;
}

Measured memory_bytes: 1220
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int N = Integer.parseInt(scanner.next());
        int M = Integer.parseInt(scanner.next());

        // 県ごとに年を持つ
        TreeMap<Integer, int[]> yearMap = new TreeMap<>();
        for (int i = 0; i < M; i++) {
            int prefectureId = Integer.parseInt(scanner.next());
            int year = Integer.parseInt(scanner.next());

            int[] array = new int[2];
            array[0] = prefectureId;
            array[1] = i;
            yearMap.put(year, array);
        }

        String[] ans = new String[M];
        int[] indexArray = new int[N + 1];

        for (int[] array : yearMap.values()) {
            indexArray[array[0]]++; // 県ごとのindex
            ans[array[1]] = String.format("%06d%06d", array[0], indexArray[array[0]]);
        }
        for (int i = 0; i < M; i++) {
            System.out.println(ans[i]);
        }

        scanner.close();
    }
}


Measured memory_bytes: 114884
#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;

ll N, K, A[100001], B[100001];

int main(void) {
  cin >> N >> K;
  A[0] = B[0] = 0;
  REP(i, 0, N) cin >> A[i + 1];
  REP(i, 0, N) B[i + 1] = max(A[i + 1], 0LL);
  REP(i, 0, N) A[i + 1] += A[i];
  REP(i, 0, N) B[i + 1] += B[i];

  ll ans = 0;
  REP(i, 0, N - K + 1) {
    ll s = B[i] - B[0] + B[N] - B[i + K];
    ans = max({ ans, s, s + A[i + K] - A[i] });
  }
  cout << ans << endl;
}


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

int main() {
	// your code goes here
	int x;
	cin >> x;
	int deg = (90 + x) % 360;
	int k = 1;
	while(deg != 90){
	    deg += x;
	    deg %= 360;
	    k++;
	}
	cout << k << endl;
	return 0;
}


Measured memory_bytes: 3632
import java.util.*;

class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int rt = (int) Math.floor(Math.sqrt(N));
    int ans = 0;
    int i = Math.max(0,rt-1);
    while(i*i<=N){
      ans = i*i;
      i++;
    }
    
    System.out.println(ans);
  }   
}

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

using namespace std;
typedef long long ll;
const int INF = 0x3f3f3f3f;
const int maxn = 110000;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setiosflags(ios::fixed) << setprecision(12);
    ll N, K;
    cin >> N >> K;
    if (N >= K)
    {
        ll cur = N / K;
        ll ans = min(abs(cur * K - N), abs((cur + 1) * K - N));
        cout << ans << "\n";
    }
    else
    {
        ll ans = min(N, K - N);
        cout << ans << "\n";
    }
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
using namespace std;
int n,m,sum1,sum2,a[110];
int main(){
    scanf("%d",&n);
    sum1=0;
    for(int i=0;i<n;i++){
        scanf("%d",&a[i]);
        sum1+=a[i];
    }
    scanf("%d",&m);
    sum2=sum1;
    while(m--){
        int p,x;
        scanf("%d%d",&p,&x);
        if(x>=a[p-1]) sum1+=x-a[p-1];
        else sum1-=a[p-1]-x;
        printf("%d\n",sum1);
        sum1=sum2;
    }
    return 0;
}

Measured memory_bytes: 256
// AOJ ALDS1_3_C Doubly Linked List
// 2018.5.1 bal4u
 
#include <stdio.h>
 
#if 1
#define gc() getchar_unlocked()
#define pc(c) putchar_unlocked(c)
#else
#define gc() getchar()
#define pc(c) putchar(c)
#endif
 
int in()
{
	int n = 0, c = gc();
	do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');
	return n;
}
 
void skip(int k) { while (k--) gc(); }
 
void out(int n)
{
	int i;
	char ob[20];
 
	if (!n) { pc('0'); return; }
	i = 0; while (n) ob[i++] = n%10 + '0', n/=10;
	while (i--) pc(ob[i]); 
}
 
int que[1500005]; int top, end;
 
int main()
{
	int n, i, t;
	char op;
 
	n = in(); top = 0, end = 1;
	while (n--) {
		if (gc() == 'i') {
			skip(6);
			que[end++] = in();
		} else {
			skip(5);
			op = gc();
			if (op == 'L') {
				skip(4);
				top++;
			} else if (op == 'F') {
				skip(5);
				end--;
			} else {
				que[top] = t = in();
				i = end; while (que[--i] != t);
				if (i > top) {
					if (end - i < i - top) {
						while (++i < end) que[i-1] = que[i];
						end--;
					} else {
						while (--i > top) que[i+1] = que[i];
						top++;
					}
				}
			}
		}
	}
	i = end-1; out(que[i--]);
	while (i > top) pc(' '), out(que[i--]);
	pc('\n');
	return 0;
}



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

int main(){
  int n;
  int count1=0;
  int count2=0;
  cin >> n;
  
    for(int i=1;i<=n;i+=2){
      count1=0;
      for(int j=1;j<=n;j++){
        if(i%j==0){
          count1++;
        }
      }
      if(count1==8){
        count2++;
      }
    }
    cout << count2 << endl;
}

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

public class Main {


	public static void main(String[] args) throws IOException {
		BufferedReader bf = null;
		bf = new BufferedReader(new InputStreamReader(System.in));
		int a,b,c;
		String ans;
		String str;
		String[] s;
		str = bf.readLine();
		s = str.split(" ");
		a = Integer.parseInt(s[0]);
		b = Integer.parseInt(s[1]);
		c = Integer.parseInt(s[2]);
		if((a < c && c < b) || (a > c && c > b)) {
			ans = "Yes";
		} else {
			ans = "No";
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 23124
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize(2)
#pragma GCC optimize(3)
int main(){
    string str;
    cin>>str;
    int ps=str.find('C');
    if(ps==-1){
        puts("No");
        return 0;
    }
    if(str.find('F',ps)!=string::npos){
        puts("Yes");
    }else{
        puts("No");
    }
    return 0;
}

Measured memory_bytes: 256
def main ():
	n = int(input())
	a = list(map(int,input(). split ()))
    
	if 0 in a:
		print(0)
		return
	prod = 1
	for i in a:
		prod *= i
		if prod > 1000000000000000000:
			print(-1)
			return
	print(prod)
main ()


Measured memory_bytes: 21644
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <map>
#include <stack>
#include <string>
#include <list>
#include <queue>
#include <deque>
#include <math.h>
using namespace std;

typedef pair<int, int> P;
#define ll long long
#define int ll
#define INF (1LL<<60)
#define mod 1000000007
int dx[4] = { 0, 1, 0, -1 };
int dy[4] = { 1, 0, -1, 0 };

// aとbの最大公約数
ll gcd(ll a, ll b) {
	if (a < b) gcd(b, a);
	ll r;
	while ((r = a%b)) {
		a = b;
		b = r;
	}
	return b;
}

signed main(){
	int N, P, a[51], dp0[51], dp1[51];
	cin >> N >> P;
	for (int i = 0; i < N; i++){
		cin >> a[i];
		a[i] = a[i] % 2;
	}
	if (a[0] == 1){
		dp1[0] = 1; dp0[0] = 1;
	}
	else{
		dp1[0] = 0; dp0[0] = 2;
	}

	for (int i = 1; i < N; i++){
		if (a[i] == 1){
			dp0[i] = dp0[i - 1] + dp1[i-1];
			dp1[i] = dp0[i - 1] + dp1[i - 1];
		}
		else{
			dp0[i] = dp0[i - 1] * 2;
			dp1[i] = dp1[i - 1] * 2;
		}
	}

	cout << (P == 0 ? dp0[N - 1] : dp1[N - 1]) << endl;

	return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>

#define rep(i, x, n) for (int i = x; i < n; i++)
using namespace std;
const long long INF = 1LL << 60;
vector<long long> yaku(long long n)
{
    vector<long long> ret;
    for (long long i = 1; i * i <= n; i++)
    {
        if (n % i == 0)
        {
            ret.push_back(i);
            if (i * i != n)
            {
                ret.push_back(n / i);
            }
        }
    }
    return ret;
}
int main()
{
    long long N, K;
    cin >> N >> K;
    vector<long long> A(N);
    long long sum = 0;
    rep(i, 0, N)
    {
        cin >> A[i];
        sum += A[i];
    }
    vector<long long> v = yaku(sum);
    sort(v.begin(), v.end(), greater<long long>());
    // for (auto m : v)
    // {
    //     cout << m << endl;
    // }
    for (auto m : v)
    {
        vector<long long> modA(N);
        rep(i, 0, N)
        {
            modA[i] = A[i] % m;
        }
        sort(modA.begin(), modA.end());
        int l = 0;
        int r = N - 1;
        long long tmp = 0;
        bool kekka = false;
        long long count = 0;
        while (true)
        {
            //cout << m << "," << l << "," << r << endl;
            if (l == r)
            {
                if (tmp <= 0)
                {

                    count += modA[l];
                }
                if ((modA[l] + tmp) % m == 0 && count <= K)
                {
                    kekka = true;
                }
                break;
            }
            else if (modA[l] == 0)
            {
                l++;
                continue;
            }
            else if (tmp <= 0)
            {
                tmp += modA[l];
                count += modA[l];
                l++;
            }
            else
            {
                tmp -= m - modA[r];
                r--;
            }
        }
        if (kekka)
        {
            cout << m << endl;
            break;
        }
    }
}

Measured memory_bytes: 384
#include <iostream>
#include <iomanip>
#include <vector>
#include <unordered_map>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <array>
#include <tuple>
#include <string>
#include <algorithm>
#include <functional>
#include <cmath>
#include <numeric>
#include <bitset>
#include <cstdint>
#include <stdexcept>
using namespace std;

// 整数型

using i32 = int32_t;
using i64 = int64_t;
using u32 = uint32_t;
using u64 = uint64_t;

// [0,n)を昇順/降順でループ

#define rep(i, n) for (int i = 0; i < static_cast<int>(n); ++i)
#define repd(i, n) for (int i = static_cast<int>(n) - 1; i >= 0; --i)

// [a,b)を昇順/降順でループ

#define FOR(i, a, b) for (int i = static_cast<int>(a); i < static_cast<int>(b); ++i)
#define FORD(i, a, b) for (int i = static_cast<int>(b) - 1; i >= static_cast<int>(a); --i)

// デバッグ

#ifdef DEBUG
#include <cassert>
#define my_assert(x) assert(x)
#else
#define my_assert(x)
#define assert(x)
#endif

//////////////// //////////////// //////////////// //////////////// ////////////////
//////////////// //////////////// //////////////// //////////////// ////////////////

int main()
{
    // 高速な入出力
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    // 浮動小数の表示の精度
    cout << fixed << setprecision(15);

    vector<vector<int>> card(3, vector(3, 0));
    rep(i, 3)
    {
        rep(j, 3)
        {
            cin >> card[i][j];
        }
    }
    vector<vector<bool>> hit(3, vector(3, false));
    int n;
    cin >> n;
    rep(k, n)
    {
        int b;
        cin >> b;
        rep(i, 3)
        {
            rep(j, 3)
            {
                if (card[i][j] == b)
                {
                    hit[i][j] = true;
                }
            }
        }
    }
    bool bingo = false;
    rep(i, 3)
    {
        bingo = bingo || (hit[i][0] && hit[i][1] && hit[i][2]);
    }
    rep(j, 3)
    {
        bingo = bingo || (hit[0][j] && hit[1][j] && hit[2][j]);
    }
    bingo = bingo || (hit[0][0] && hit[1][1] && hit[2][2]);
    bingo = bingo || (hit[0][2] && hit[1][1] && hit[2][0]);
    cout << (bingo ? "Yes" : "No") << "\n";

    return 0;
}


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

#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
#define zeroend __builtin_ctz
#define ones __builtin_popcount
#define ends "\n"
#define space ' '
typedef long long ll;
typedef pair<int, int> pii;

/*
void solve(int i, int j, string s){
	if(i==0)
		ans.insert(s2.substr(0, j)+s);
	else if(j==0)
		ans.insert(s1.substr(0, i)+s);
	else if(s1[i-1]==s2[j-1])
		solve(i-1, j-1, s1[i-1]+s);
	else{
		if(dp[i-1][j]<=dp[i][j-1])
			solve(i-1, j, s1[i-1]+s);
		if(dp[i-1][j]>=dp[i][j-1])
			solve(i, j-1, s2[j-1]+s);
	}
}*/


/*
	cin >> n;
	for(int i=0; i<n; ++i)
		cin >> a[i];

	for(int i=1; i<n; ++i){
		for(int j=0; j<i; ++j){
			if(a[j]>a[i]&&low[i]<high[j]+1)
				low[i]=high[j]+1;
			else if(a[j]<a[i]&&high[i]<low[j]+1)
				high[i]=low[j]+1;
		}
		ans=max({ans, low[i], high[i]});
	}

	cout << ans << ends;


*/

const int N = 100, N2 = 1e5;

vector<ll> dp(N2+1, 1e10);
//array<ll, 3> dp;
//set<string> ans;
//vector<int> low(N, 1), high(N, 1);
ll v[N], m[N];

int n, w;
ll s=0;

int main(){
	cin >> n >> w;
	for(int i=0; i<n; ++i){
		cin >> m[i] >> v[i];
		s+=v[i];
	}
	dp[0]=0;	
	for(int i=1; i<=n; ++i){
		for(int j=s; j>=v[i-1]; --j){			
			if(dp[j-v[i-1]]+m[i-1]<=w){
				dp[j]=min(dp[j], dp[j-v[i-1]]+m[i-1]);
			}
		}
	}
	for(int i=s; i>=0; --i)
		if(dp[i]!=1e10){
			cout << i << ends;
			return 0;
		}

}

Measured memory_bytes: 3816
#include<bits/stdc++.h>
// __builtin_ctz : no of trailing zeros
#define int long long
#define pp pair<int,int>
#define mod 1000000007
#define trace(x) cerr<<#x<<": "<<x<<" "<<endl
#define trace2(x, y) cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z) cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define sa(a,n) for(int i =0 ; i<n ; i++) cin>>a[i]
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define scan() int n; cin>>n ; int a[n]; for(int i = 0 ; i<n ; i++) cin>>a[i]
#define print(a,n) for(int i = 0 ; i < n ; i++) cout<<a[i]<<' '
using namespace std;
int max(int x, int y)
{
    return x>y ? x : y;
}
int min(int x, int y)
{
    return x<y ? x : y;
}
void _(int&a , int b)
{
    a=(a%mod+b%mod)%mod;
    a=(a+mod)%mod;
}
int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    long double r;cin >> r;
    cout << setprecision(5)
     << 2*3.14159265358*r;
    }


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

int main() {
    ll a, b, x;
    cin >> a >> b >> x;

    ll bCounter = b / x + 1;
    ll aMinus1Counter = (a - 1) / x + 1;
    if (a >= 1) {
        cout << bCounter - aMinus1Counter << endl;
    } else {
        cout << bCounter << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <cstdio>

int main(){
    int a,b;
    scanf("%X %X",&a,&b);
    if(a>b){
        printf(">\n");
    }
    if(a<b){
        printf("<\n");
    }
    if(a==b){
        printf("=\n");
    }
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
#define Clear(a) a = decltype(a)();
typedef long long ll;
typedef pair<int,int> p;
//const ll big=998244353;
const ll big=1000000007;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
ll max(ll x,ll y){
if(x>y)return x;
else return y;
}
ll min(ll x,ll y){
if(x<y)return x;
else return y;
}
ll expm(ll x,ll y){
    if(y==0)return 1;//0^0=1
    if(x==1||x==0)return x;
    if(y%2==1)return (expm(x,y-1)*x)%big;
    ll t=expm(x,y/2);
    return (t*t)%big;
}
ll exp(ll x,ll y){
    if(y==0)return 1;//0^0=1
    if(x==1||y==0)return x;
    if(y%2==1)return exp(x,y-1)*x;
    ll t=exp(x,y/2);
    return t*t;
}
ll inv(ll x){
    return exp(x,big-2);
}


int main(){
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    cout << fixed << setprecision(10);
    /*--------------------------------*/
    
    int n;cin >> n;
    vector<int> a(n+2);
    a[0]=0;a[n+1]=0;
    rep(i,n){
        cin >> a[i+1];
    }
    ll len=0;
    rep(i,n+1)len+=abs(a[i+1]-a[i]);
    rep(i,n){
        if(a[i]<=a[i+1]&&a[i+1]<=a[i+2])cout << len << endl;
        else{
            cout << len-abs(a[i+1]-a[i])-abs(a[i+2]-a[i+1])+abs(a[i+2]-a[i]) << endl;
        }
    }
}

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

int main(){
  int n;
  deque<long long int> v;
  cin >> n;
  for(int i=0;i<n;i++){
    long long int a;
    cin >> a;
    if((i&1)==1){
      v.push_back(a);
    }
    else{
      v.push_front(a);
    }
  }
  if((n&1)==1){
    for(int i=0;i<n;i++){
      cout << v[i] << (i==n-1?"\n":" ");
    }
  }
  else{
    for(int i=n-1;i>=0;i--){
      cout << v[i] << (i==0?"\n": " ");
    }
  }
}

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

int main() {
    string S, S_s, S_e;
    int S_size;
    ostringstream oss;

    cin >> S;

    S_s = S[0];
    S_size = S.size();
    S_e = S[S_size -1];
    oss << S_size - 2;

    cout << S_s + oss.str() + S_e << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include<vector>
#include <math.h>
#include<stdio.h>
#include <climits>
#include<algorithm>
#include<string>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int a,b,c;//入力
	int i = 0, j = 0, d = 0, kari = 0, old = 0, flag = 0; //内部で使用;
	int ans = 0; //出力

	cin >> a>>b>>c;
	rep(i, 100000000) {
		if ((a * i) % b == c)ans++;
	}


	if (ans > 0) cout << "YES" << "\n";
	else         cout << "NO" << "\n";
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<map>
using namespace std;
string str,ans,ans2;
map<string,int> tab;
int main(){
	while(cin>>str){
		if(str.size()>ans2.size())	ans2 = str;
		tab[str]++;
		if(tab[ans]<tab[str])	ans = str;
	}
	cout << ans << ' ' << ans2 << endl;
	return 0;
}


Measured memory_bytes: 3048
using System;
using System.Linq;

namespace CF2016AB{
    public class Program{
        public static void Main(string[] args){
            var sr = new StreamReader();
            //---------------------------------
            var N = sr.Next<int>();
            var A = sr.Next<int>(N).Select(x => x - 1).ToArray();

            var res = 0;
            for(var i = 0; i < N; i++){
                if(A[A[i]] == i) res++;
            }

            Console.WriteLine(res / 2);
            //---------------------------------
        }
    }

    public class StreamReader{
        private readonly char[] _c = {' '};
        private int _index = -1;
        private string[] _input = new string[0];
        private readonly System.IO.StreamReader _sr = new System.IO.StreamReader(Console.OpenStandardInput());

        public T Next<T>(){
            if(_index == _input.Length - 1){
                _index = -1;
                while(true){
                    string rl = _sr.ReadLine();
                    if(rl == null){
                        if(typeof(T).IsClass) return default(T);
                        return (T)typeof(T).GetField("MinValue").GetValue(null);
                    }
                    if(rl != ""){
                        _input = rl.Split(_c, StringSplitOptions.RemoveEmptyEntries);
                        break;
                    }
                }
            }
            return (T)Convert.ChangeType(_input[++_index], typeof(T), System.Globalization.CultureInfo.InvariantCulture);
        }

        public T[] Next<T>(int x){
            var ret = new T[x];
            for(var i = 0; i < x; ++i) ret[i] = Next<T>();
            return ret;
        }

        public T[][] Next<T>(int y, int x){
            var ret = new T[y][];
            for(var i = 0; i < y; ++i) ret[i] = Next<T>(x);
            return ret;
        }
    }
}

Measured memory_bytes: 15576