akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Linq;

class Procon
{
    public Procon() { }
    static void Main(string[] agrs)
    {
        new Procon().Do();
    }

    Scanner cin;

    public void Do()
    {
        cin = new Scanner();

        int N = cin.nextInt();
        int M = cin.nextInt();
        bool[] b = new bool[N + 1];
        for (int i = 0; i < N; i++)
        {
            b[i] = true;
        }
        for (int i = 0; i < M; i++)
        {
            int tmp = cin.nextInt();
            b[tmp] = false;
        }

        int[] DP = new int[N + 1];
        DP[0] = 1;

        for (int i = 1; i <= N; i++)
        {
            DP[i] = 0;
            if (i - 1 >= 0 && b[i - 1])
            {
                DP[i] = (DP[i] + DP[i - 1]) % 1000000007;
            }
            if (i - 2 >= 0 && b[i - 2])
            {
                DP[i] = (DP[i] + DP[i - 2]) % 1000000007;
            }
        }

        Console.WriteLine(DP[N]);
    }
}

class Scanner
{
    string[] s;
    int i;
    int max_i;

    public Scanner()
    {
        s = new string[0];
        max_i = 0;
        i = 0;
    }

    public string nextString()
    {
        if (i >= s.Length)
        {
            s = Console.ReadLine().Split(' ');
            max_i = s.Length;
            i = 0;
            if (max_i == 0)
            {
                return "";
            }
            return s[i++];
        }
        else
        {
            return s[i++];
        }
    }

    public int nextInt()
    {
        return int.Parse(nextString());
    }

    public long nextLong()
    {
        return long.Parse(nextString());
    }

    public double nextDouble()
    {
        return double.Parse(nextString());
    }

    public string[] arrayString()
    {
        return Console.ReadLine().Split(' ');
    }

    public int[] arrayInt()
    {
        string[] str = Console.ReadLine().Split(' ');
        int[] array = new int[str.Length];
        for (int i = 0; i < str.Length; i++)
        {
            array[i] = int.Parse(str[i]);
        }
        return array;
    }

    public long[] arrayLong()
    {
        string[] str = Console.ReadLine().Split(' ');
        long[] array = new long[str.Length];
        for (int i = 0; i < str.Length; i++)
        {
            array[i] = long.Parse(str[i]);
        }
        return array;
    }

    public double[] arrayDouble()
    {
        string[] str = Console.ReadLine().Split(' ');
        double[] array = new double[str.Length];
        for (int i = 0; i < str.Length; i++)
        {
            array[i] = double.Parse(str[i]);
        }
        return array;
    }
}


Measured memory_bytes: 15440
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <tuple>
# include <unordered_map>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
constexpr int INF = 2000000000;
constexpr int HINF = INF / 2;
constexpr double DINF = 100000000000000000.0;
constexpr long long LINF = 9223372036854775807;
constexpr long long HLINF = 4500000000000000000;
const double PI = acos(-1);
int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
# define ALL(x)    (x).begin(),(x).end()
# define UNIQ(c)   (c).erase(unique(ALL((c))), end((c)))
# define mp        make_pair
# define eb        emplace_back
# define REP       (i, a) for (int i = 0; i < (a); i++)
# define INIT      std::ios::sync_with_stdio(false);std::cin.tie(0);

LL fact[222222];
const LL MOD = 1000000007;

LL power(LL x, LL n) {
	LL tmp = 1;

	if (n > 0) {
		tmp = power(x, n / 2);
		if (n % 2 == 0) tmp = (tmp*tmp) % MOD;
		else tmp = (((tmp*tmp) % MOD)*x) % MOD;
	}
	return tmp;
}

void f() {
	fact[0] = fact[1] = 1;
	for (LL i = 2; i < 222222; i++) fact[i] = (fact[i - 1] * i) % MOD;
}
//hCm%MOD
LL com(LL h, LL w) {
	return (fact[h + w] * power((fact[h] * fact[w]) % MOD, MOD - 2)) % MOD;
}

signed main() {
	LL h, w, a, b;
	cin >> h >> w >> a >> b;
	f();

	LL ans = com(h - 1, w - 1);

	LL sub = 0;

	for (LL i = h - a; i < h; i++) {
		sub += (com(i, b - 1) * com(h - 1 - i, w - 1 - b)) % MOD;
		sub %= MOD;
	}

	ans -= sub;

	while (ans < 0) ans += MOD;

	cout << ans%MOD << endl;

}

Measured memory_bytes: 1920
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
//xにはvectorなどのコンテナ
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素

int main(void)
{
  int i = 1;
  int x;
  cin >> x;
  while(x) {
    cout << "Case " << i << ": " << x << endl;
    i++;
    cin >> x;
  }
  return  0;
}



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

int main(){
    int N;
    cin >> N;
    vector<ll> A(N), B(N);
    ll sum = 0;
    ll remain = 1e10;
    for (int i = 0; i < N; i++) {
        cin >> A[i] >> B[i];
        sum += A[i];
        if (A[i] > B[i]) {
            remain = min(remain, B[i]);
        }
    }
    if (remain == 1e10) cout << 0 << endl;
    else cout << sum-remain << endl;
    return 0;
}

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

int d[10][10];



int main() {
    int n, m;
    cin >> n >> m;
    for (int i = 0; i < 10; ++i) for (int j = 0; j < 10; ++j) scanf("%d", &d[i][j]);

    for(int k = 0; k < 10; ++k) 
        for(int i = 0; i < 10; ++i)
            for(int j = 0; j < 10; ++j)
                d[i][j] = min(d[i][j], d[i][k] + d[k][j]);

    int res = 0;
    for(int i = 0; i < n; ++i) for(int j = 0; j < m; ++j) {
        int x; scanf("%d", &x);
        if(x == -1) continue;
        res += d[x][1];
    }
    printf("%d\n", res);
}

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

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep2(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> TUPLE;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;

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

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

    int N;
    while (cin >> N, N) {
        vector<P> v;
        v.emplace_back(0, 0);
        rep(i, N - 1) {
            int n, d;
            cin >> n >> d;
            int x = v[n].first + dx[d];
            int y = v[n].second + dy[d];
            v.emplace_back(x, y);
        }

        const int inf = 1e9;
        int x1 = -inf, x2 = inf, y1 = -inf, y2 = inf;
        for (auto& p : v) {
            x1 = max(x1, p.first);
            x2 = min(x2, p.first);
            y1 = max(y1, p.second);
            y2 = min(y2, p.second);
        }

        cout << x1 - x2 + 1 << " " << y1 - y2 + 1 << endl;
    }
}

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

using namespace std;

#define REP1(i,n) for(int i=1, i##_len=(n); i<i##_len; ++i)
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define pow(x) x*x
#define ll long long

static const ll MAX = 1000000;
static const ll INFTY = 1e12;
static const ll MOD = 1000000007;

template < typename T > inline string toString( const T &a ) { ostringstream oss; oss << a; return oss.str(); };

struct edge {
    ll to, cost;
};

using Graph = vector<vector<int>>;
using _Graph = vector<vector<edge>>;


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

// 深さ優先探索
vector<bool> seen;
vector<int> colors;

int H, W, N;
int sx, sy, gx, gy; 
vector<vector<char>> field;
vector<vector<int>> dist;
//vector<pair<int, int>> gx, gy;
deque<pair<int, int>> que;

typedef vector<vector<int> > Matrix;

const ll INF = 1e18;

int main() {

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

    cout << max(max((10*A+B+C),(A+10*B+C)), 10*C+A+B) << endl;

 

}

/*
みんな、くるくるぱーにな〜れ
　∧＿∧　
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
　　　　　　　　　　(¸.·´ (¸.·'* ☆
*/



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define YES cout<<"YES"<<endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define all(a) a.begin(),a.end()
#define SORT(a) sort(all(a))
#define int long long
#define FOR(i, m, n) for(int i = m;i < n;i++)
typedef vector<int> VI;
typedef vector<VI> VVI;
const int MOD=1000000007;
const long long INF = 1LL << 60;
//----------------------------------------------
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int n,a,b; cin >> n >> a >> b;
    if(n*a > b) cout << b << endl;
    else cout << n * a << endl;

    return 0;
}

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

ll arr[100005][2];

int main(){
  ios::sync_with_stdio(0); cin.tie(0), cout.tie(0);
  int n; cin >> n;
  ll ans = 0;
  for(int i = 0 ; i < n ; i++) cin >> arr[i][0] >> arr[i][1];
  while(n--){
    int a = arr[n][0], b = arr[n][1];
    a = (a+ans)%b;
    ans += (b-a)%b;
  }
  cout << ans;
}


Measured memory_bytes: 1792
#include<iostream>
#include<iomanip>
#include<string>
#include<vector>
#include<stack>
#include<set>
#include<map>
#include<utility>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<climits>
#include<bitset>
using namespace std;

#define rep(i,n) for(int i=0; i<(n); i++)
typedef long long ll;
const int mod=1e9+7;

int main(){
  int n;
  cin >> n;
  vector<int> f(n);
  rep(i,n){
    rep(j,10){
    	int tmp;
    	cin >> tmp;
    	tmp <<= j;
    	f[i] |= tmp;
    }
  }
  vector<vector<int>> p(n, vector<int>(11));
  rep(i,n){
    rep(j,11){
    	cin >> p[i][j];
    }
  }
  int ans=-1e9;
  for(int i=1; i<1<<10; i++){
  	int sum=0;
  	rep(j,n){
  		int tmp = f[j]&i, d=0;
  		rep(k,10){
  		  if(tmp>>k&1)
  		  	d++;
		  }
		  sum+=p[j][d];
  	}
  	ans = max(ans, sum);
  }
  cout << ans << endl;
  return 0;
}

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

int main() {
	int n; cin >> n;
	vector<vector<int>>G(n);
	vector<pair<int,int>>vp;	
	for (int i = 1; i < n; i++) {
		int a, b; cin >> a >> b;
		a--; b--;
		G[a].push_back(b);
		G[b].push_back(a);
		vp.push_back({ a,b });
	}

	int k = 0;
	map<pair<int, int>, int> I;
	vector<int>cs(n, 0), used(n, 0);
	queue<int>que;
	used[0] = 1;
	que.push(0);
	while (!que.empty()) {
		int v = que.front(); que.pop();
		if (k < G[v].size())k = G[v].size();
		int cur = 1;
		for (int u : G[v]) {
			if (used[u])continue;
			if (cur == cs[v])cur++;
			cs[u] = I[make_pair(u, v)] = I[make_pair(v, u)] = cur++;
			used[u] = 1;
			que.push(u);
		}
	}
	cout << k << endl;
	for (auto color : vp)cout << I[color] << endl;

	return 0;
}

Measured memory_bytes: 20084
import java.io.*;
import java.util.*;

public class Main{
	public static void main(String[] args) throws Exception{
		PrintWriter pw=new PrintWriter(System.out);
		MScanner sc = new MScanner(System.in);
		int n=sc.nextInt(),k=sc.nextInt();
		long[]smallestI=new long[n+1];
		int mod=(int)1e9+7;
		smallestI[0]=0;
		for(int i=1;i<=n;i++) {
			smallestI[i]=smallestI[i-1]+i;
		}
		long ans=0;
		for(int nums=k-1;nums<=n;nums++) {
			long smallestNums=smallestI[nums];
			long biggestNums=smallestI[n]-((n-nums-1)<0?0:smallestI[n-nums-1]);
//			System.out.println(smallestNums+" "+biggestNums+" "+nums);
			long inc=(biggestNums-smallestNums+1)%mod;
			ans=(ans+inc)%mod;
		}
		pw.println(ans);
		
		pw.flush();
	}
	static class MScanner {
		StringTokenizer st;
		BufferedReader br;
		public MScanner(InputStream system) {
			br = new BufferedReader(new InputStreamReader(system));
		}
 
		public MScanner(String file) throws Exception {
			br = new BufferedReader(new FileReader(file));
		}
 
		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}
		public int[] intArr(int n) throws IOException {
	        int[]in=new int[n];for(int i=0;i<n;i++)in[i]=nextInt();
	        return in;
		}
		public long[] longArr(int n) throws IOException {
	        long[]in=new long[n];for(int i=0;i<n;i++)in[i]=nextLong();
	        return in;
		}
		public int[] intSortedArr(int n) throws IOException {
	        int[]in=new int[n];for(int i=0;i<n;i++)in[i]=nextInt();
	        shuffle(in);
	        Arrays.sort(in);
	        return in;
		}
		public long[] longSortedArr(int n) throws IOException {
	        long[]in=new long[n];for(int i=0;i<n;i++)in[i]=nextLong();
	        shuffle(in);
	        Arrays.sort(in);
	        return in;
		}
		public Integer[] IntegerArr(int n) throws IOException {
	        Integer[]in=new Integer[n];for(int i=0;i<n;i++)in[i]=nextInt();
	        return in;
		}
		public Long[] LongArr(int n) throws IOException {
	        Long[]in=new Long[n];for(int i=0;i<n;i++)in[i]=nextLong();
	        return in;
		}
		public String nextLine() throws IOException {
			return br.readLine();
		}
 
		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}
 
		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}
 
		public char nextChar() throws IOException {
			return next().charAt(0);
		}
 
		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}
 
		public boolean ready() throws IOException {
			return br.ready();
		}
 
		public void waitForInput() throws InterruptedException {
			Thread.sleep(3000);
		}
	}
	static void shuffle(int[]in) {
		for(int i=0;i<in.length;i++) {
			int idx=(int)(Math.random()*in.length);
			int tmp=in[i];
			in[i]=in[idx];
			in[idx]=tmp;
		}
	}
	static void shuffle(long[]in) {
		for(int i=0;i<in.length;i++) {
			int idx=(int)(Math.random()*in.length);
			long tmp=in[i];
			in[i]=in[idx];
			in[idx]=tmp;
		}
	}
}

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

int main()
{
    string in_str;
    getline(cin, in_str);
    for(int i=0; i<in_str.length(); i++)
    {
        string tmp_str = in_str.substr(i, 5);
        if(tmp_str == "apple")
        {
            in_str.replace(i, 5, "peach");
        }
        else if(tmp_str == "peach")
        {
            in_str.replace(i, 5, "apple");
        }
        else
        {
            /* NOP */
        }
    }
    cout << in_str << endl;
    return 0;
}



Measured memory_bytes: 3168
#include <bits/stdc++.h>
using namespace std;
#define ll long long 
#define endl "\n"
#define pb push_back
#define f(i,n) for(i=0;i<n;i++)
#define F(i,a,b) for(i=a;a<=b;i++)
#define arr(a,n) for( i=0;i<n;i++)cin>>a[i];
#define fi first
#define se second
#define mp make_pair
#define mod 1000000007
#define YES cout<<"YES"<<endl;
#define Yes cout<<"Yes"<<endl;
#define NO cout<<"NO"<<endl;
#define No cout<<"No"<<endl;
#define yes cout<<"yes"<<endl;
#define no cout<<"no"<<endl;
#define vi vector<ll>
#define ed end()
#define bg begin()
#define sz size()
#define ln length()
#define s() sort(a,a+n);
#define sr() sort(a,a+n,greater<ll>());
#define v()  sort(v.begin(),v.end());
#define vr() sort(v.begin(),v.end(),greater<ll>());
#define mod 1000000007
#define fast() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
ll gcd(ll a, ll b){if(!b)return a;return gcd(b, a % b);}
ll power(ll x,ll y,ll p){ll res=1;x%=p;while(y>0){if(y&1)res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res;}
int main() {
  //#ifndef ONLINE_JUDGE
      // for getting input from input.txt
      ///freopen("input.txt", "r", stdin);
      // for writing output to output.txt
      //freopen("output.txt", "w", stdout);
  //#endif
fast();
//ll  t;cin>>t;while(t--)
{
  ll n,m,x,c=0,d=0;
  cin>>n>>m>>x;
  int a[n];
  for(int i=0;i<m;i++)
  {
    cin>>a[i];
    if(a[i]<x)
    {
         c++;
    }
    else
    {
      d++;
    }
    
    
  }
  
  cout<<min(c,d)<<endl;
  
  

}
return 0;
}

Measured memory_bytes: 256
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
use std::io::Read;
#[allow(dead_code)]
fn getline() -> String {
    let mut ret = String::new();
    std::io::stdin().read_line(&mut ret).ok().unwrap();
    ret
}
fn get_word() -> String {
    let mut stdin = std::io::stdin();
    let mut u8b: [u8; 1] = [0];
    loop {
        let mut buf: Vec<u8> = Vec::with_capacity(16);
        loop {
            let res = stdin.read(&mut u8b);
            if res.unwrap_or(0) == 0 || u8b[0] <= b' ' {
                break;
            } else {
                buf.push(u8b[0]);
            }
        }
        if buf.len() >= 1 {
            let ret = String::from_utf8(buf).unwrap();
            return ret;
        }
    }
}

#[allow(dead_code)]
fn get<T: std::str::FromStr>() -> T { get_word().parse().ok().unwrap() }

fn solve() {
    let mut s: Vec<_> = get_word().chars().collect();
    let t: Vec<_> = get_word().chars().collect();
    for _ in 0 .. s.len() + 1 {
        if s == t {
            println!("Yes");
            return;
        }
        let mut u = s[1..].to_vec();
        u.push(s[0]);
        s = u;
    }
    println!("No");
}

fn main() {
    // In order to avoid potential stack overflow, spawn a new thread.
    let stack_size = 104_857_600; // 100 MB
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}


Measured memory_bytes: 8572
#include<iostream>
using namespace std;
int main()
{
    // 整数の入力
    long a;
    cin >> a;
 
	long long i = 100;
	int k = 0;
	while (i < a) {
		i += i/100;
		k++;
	}

	cout << k << endl;

    return 0;
}



Measured memory_bytes: 3608
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <cassert>

using namespace std;
typedef long long LL;
template <typename F, typename S> std::ostream& operator<<(ostream& os, const pair<F,S>& p) {
    os << "(" << p.first << "," << p.second << ")"; return os; }
template <typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
    os << "["; for(const T& a: v){ os << a << ", "; } os << "]"; return os; }
template <typename K, typename V> ostream& operator<<(ostream& os, const map<K,V>& m) {
    os << "{"; for(const auto& p: m){ os << p.first <<":"<< p.second << ", "; } os << "}"; return os; }


// 剰余演算クラス
struct ModInt{
    static const LL MOD = 1e+9 + 7;
    LL v;
    ModInt():v(0){}
    ModInt(LL op):v(op){}
    ModInt operator+(ModInt op) const{ return (v + op) % MOD; }
    ModInt operator-(ModInt op) const{ return (v - op + MOD) % MOD; }
    ModInt operator*(ModInt op) const{ return (v * op) % MOD; }
    ModInt operator/(ModInt op) const{ return (v * op.inverse()) % MOD; }
    ModInt operator%(LL op) = delete;
    ModInt operator+=(ModInt op){ return v = (v + op) % MOD; }
    ModInt operator-=(ModInt op){ return v = (v - op + MOD) % MOD; }
    ModInt operator*=(ModInt op){ return v = (v * op) % MOD; }
    ModInt operator/=(ModInt op){ return v = (v * op.inverse()) % MOD; }
    ModInt operator-() const{ return MOD - v; }
    bool operator==(ModInt op) const{ return v == op.v; }
    bool operator!=(ModInt op) const{ return v != op.v; }
    ModInt inverse() const{ return pow(MOD-2); }
    ModInt pow(LL n) const{
        if(n < 0) return pow(MOD-1 + n);
        if(n == 0) return 1;
        ModInt res = pow(n/2);
        return res * res * ((n&1)?ModInt(v): ModInt(1));
    }
    LL get() const{ return v; }
private:
    operator LL() const{ return v; }
};
istream& operator>>(istream& st, ModInt& m){ st>>m.v; return st; }
ostream& operator<<(ostream& st, const ModInt& m){ st<<m.v; return st; }


vector<ModInt> factorial(LL n){
    vector<ModInt> res(n, 1);
    for(LL i = 2; i < n; ++i) res[i] = res[i-1] * ModInt(i);
    return res;
}

ModInt permutation(LL n, LL m, vector<ModInt>& factorial){
    if(m < 0 || n < m) return 0;
    if(m == 0) return 1;
    return factorial.at(n) / factorial.at(n-m);
}

ModInt combination(LL n, LL m, vector<ModInt>& factorial){
    if(m < 0 || n < m) return 0;
    if(m == 0) return 1;
    return factorial.at(n) / factorial.at(n-m) / factorial.at(m);
}


int main(){
    LL x, y;
    cin >> x >> y;
    if(x*2 < y || x > y*2 || (x+y)%3 != 0){
        cout << 0 << endl;
        return 0;
    }
    LL cnt = (x+y) / 3;
    LL diff = max(x, y) - min(x, y);
    if(diff > cnt){
        cout << 0 << endl;
        return 0;
    }
    vector<ModInt> f = factorial(2000000);
    cout << combination(cnt, (cnt-diff)/2, f) << endl;
    return 0;
}



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

int n;
bool s[504], t[504], bans=1;
unsigned long long u[504], v[504], ans[504][504];

int main() {
	cin >> n;
	for (int i = 0; i < n; i++)
    cin >> s[i];
	for (int i = 0; i < n; i++)
    cin >> t[i];
	for (int i = 0; i < n; i++)
    cin >> u[i];
	for (int i = 0; i < n; i++)
    cin >> v[i];
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			ans[i][j] = u[i];
		}
	}
	for (int j = 0; j < n; j++) {
		if (t[j]) {
			unsigned long long tmp = 0;
			for (int i = 0; i < n; i++)
            tmp|=ans[i][j];
			for (unsigned long long bit = 0; bit < 64; bit++) {
				if ((tmp&(1LL<<bit)) == ((v[j]&(1LL<<bit))))
                continue;
				if ((v[j]&(1LL<<bit))) {
					if (j & 1) {
						for (int i = 0; i < n; i++) {
							if (s[i])
                            continue;
							if ((ans[i][j]&(1LL<<bit)) == 0) {
								ans[i][j]|=(1LL<<bit);
								break;
							}
						}
					} else {
						for (int i = n - 1; i >= 0; i--) {
							if (s[i])
                            continue;
							if ((ans[i][j]&(1LL<<bit)) == 0) {
								ans[i][j]|=(1LL<<bit);
								break;
							}
						}
					}
				} else {
					for (int i = 0; i < n; i++)
                    ans[i][j]&=(~(1LL<<bit));
				}
			}
		} else {
			unsigned long long tmp = (~0);
			for (int i = 0; i < n; i++)
            tmp&=ans[i][j];
			for (unsigned long long bit = 0; bit < 64; bit++) {
				if ((tmp&(1LL<<bit)) == ((v[j]&(1LL<<bit))))
                continue;
				if ((v[j]&(1LL<<bit))) {
					for (int i = 0; i < n; i++)
                    ans[i][j]|=(1LL<<bit);
				} else {
					if (j&1){
						for (int i = 0; i < n; i++) {
							if (!s[i])
                            continue;
							if ((ans[i][j]&(1LL<<bit))) {
								ans[i][j]&=(~(1LL<<bit));
								break;
							}
						}
					} else {
						for (int i = n - 1; i >= 0; i--) {
							if (!s[i])
                            continue;
							if ((ans[i][j]&(1LL<<bit))) {
								ans[i][j]&=(~(1LL<<bit));
								break;
							}
						}
					}
				}
			}
		}
	}
	for (int i = 0; i < n; i++) {
			if (s[i]) {
				unsigned long long tmp = 0;
				for (int j = 0; j < n; j++)
                tmp|=ans[i][j];
				if (tmp != u[i])
                bans=0;
			} else {
				unsigned long long tmp=(~0);
				for (int j = 0; j < n; j++)
                tmp&=ans[i][j];
				if (tmp != u[i])
                bans=0;
			}
		}
		if (!bans) {
			cout << "-1\n";
			return 0;
		}
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				cout << ans[i][j] << " ";
			}
			cout << "\n";
		}
}


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

using namespace std;

int main() {

    int N;
    cin >> N;
    vector<int> p;
    int buf_p;
    for(int ni = 0 ; ni < N ; ni+=1){
        cin >> buf_p;
        p.push_back(buf_p);
    }

    vector<long long> a,b;
    for(int i = 0 ; i < N ; i+=1){
        a.push_back(1 + N*i);
        b.push_back(N*(N-1) + 1 - N*i);
    }

    long long apper = 1;
    for(int pi = 1 ; pi < N ; pi+=1){
        int index = p[pi]-1;
        if(index > N/2){
            a[index] += apper;
        }
        else{
            b[index] += apper;
        }
        apper +=1;
    }

    // cout << "a : ";
    for(auto _a : a) cout << _a << " ";
    cout << endl;
    // cout << "b : ";
    for(auto _b : b) cout << _b << " ";
    cout << endl;

//    for(auto _p : p) cout << a[_p-1]+b[_p-1] << " ";
//    cout << endl;
}


Measured memory_bytes: 1276
def gcd(x, y):
    while y != 0:
        x, y = y, x % y
    return x


assert gcd(12, 4) == 4
assert gcd(5, 8) == 1


def solve():
    N = int(input())
    A = [int(x) for x in input().split()]
    ans = A[0]
    for i in range(1, N):
        ans = gcd(ans, A[i])
    return ans


def main():
    print(solve())


if __name__ == '__main__':
    main()

Measured memory_bytes: 14252
#include<stdio.h>
int main(void)
{
	int v,w,x,y,z,n;
	
	scanf("%d",&n);
	
	w=n/15;
	v=w*200;
	z=800*n-v;
	printf("%d\n",z);
	
	return 0;
}
	
	
	

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define llu long long unsigned
int main()
{
    int t,a,b,x,y,z,n,mx,mn,tmp;
        int cnt=0,ans=0;
        string s="";
        vector<int>vc;
        map<int,int>mp;
        map<char,int>mc;
        scanf("%d",&x);
        char ch,ch2;
        if(x%10==0 || x%10==6 || x%10==1 || x%10==8){
            puts("pon");
        }
        else if(x%10==3){
            puts("bon");
        }
        else{
            puts("hon");
        }




    return 0;
}






Measured memory_bytes: 3688
# -*- coding: utf-8 -*-
from sys import stdin
# import numpy as np
# import sys
# sys.setrecursionlimit(10**4)

def _li(): return list(map(int, stdin.readline().split()))
def _li_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def _lf(): return list(map(float, stdin.readline().split()))
def _ls(): return stdin.readline().split()
def _i(): return int(stdin.readline())
def _f(): return float(stdin.readline())
def _s(): return stdin.readline()[:-1]


MOD = 10**9+7
N, M = _li()

a_list = []
for _ in range(M):
    a_list.append(_i())
a_list.append(-1)

ans = [1, 1]
a_index = 0
if a_list[a_index] == 1:
    ans[1] = 0
    a_index += 1

for i in range(2, N+1):
    if i == a_list[a_index]:
        ans = [ans[1], 0]
        a_index += 1
    else:
        ans = [ans[1], ans[0] + ans[1] % MOD]
    if ans[0] + ans[1] == 0:
        break
print(ans[1] % MOD)


Measured memory_bytes: 7076
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <cmath>
#include <climits>

#define X first
#define Y second
#define vsort(v) sort((v).begin(), (v).end())
#define vrev(v) reverse((v).begin(), (v).end())


//INT_MAX
//INT_MIN
//LLONG_MAX
//LLONG_MIN
//DBL_MIN
//DBL_MAX
//LDBL_MIN
//LDBL_MAX

// A-Z: 65~90
// a-z: 97~122
// |a-z| = 26

using namespace std;
using ll = long long;

int main(int argc, const char * argv[]) {
    vector<int> v(3);
    for (int i = 0; i < 3; i++) {
        cin >> v[i];
    }
    vsort(v);
    cout << v[2] * 10 + v[1] + v[0] << endl;
}


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

using namespace std;

int main()
{
	vector<int> data;
	int temp;

	for (int ix = 0; ix != 10; ++ix){
		cin >> temp;
		data.push_back(temp);
	}

	sort(data.begin(), data.end(), greater<int>());
	for (int ix = 0; ix != 3; ++ix)
		cout << data[ix] << endl;

	return 0;
}

Measured memory_bytes: 1216
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <algorithm>
#include <bitset>
#include <complex>

#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#define rep(i,n) for(int i=0;i<(n); i++)

using namespace std;
const int MAX = 100005;
const int INF=1e9+7;
typedef long long ll;


ll dp[105][100005] = {0};
int main(){
cin.tie(0);
ios::sync_with_stdio(0); //この2行はより速度を向上させる
// 追加２, 以降 cin の入力元が 'input.txt' になる
//提出時に消す！！


int N,W;
cin >> N >> W;

vector<ll> w(N),v(N);
rep(i,N) cin >> w[i] >> v[i];

for(int i=0;i<N;i++){
	for(int j=0;j<=W;j++){
		dp[i+1][j]=dp[i][j];
		if(j-w[i] >= 0){
			dp[i+1][j] = max(dp[i+1][j], dp[i][j-w[i]]+v[i]);
		}
	}
}
cout << dp[N][W] << endl;

return 0;
}

Measured memory_bytes: 79360
def gcd(x, y):
    return gcd(y, x % y) if x % y else y

def count(n):
    return (n // c) + (n // d) - (n // (c * d // gcd(c, d)))

a,b,c,d = map(int, input().split())

p = count(a-1)
q = count(b)
print((b - a + 1) - (q - p))


Measured memory_bytes: 2940
from sys import stdin


def count_samples_of_like_same_food(n, m, samples_and_like_foods):
    #all_samples_count = len(samples_and_like_foods)
    like_foods_num_dict = {}
    for samples_like_foods in samples_and_like_foods:
        #like_foods_set = tuple(set(like_foods))
        sample = samples_like_foods[0]
        like_foods = samples_like_foods[1:]
        #print(like_foods_set)
        for like_food in like_foods:
            if like_food not in like_foods_num_dict:
                like_foods_num_dict[like_food] = 1
            else:
                like_foods_num_dict[like_food] += 1

    same_like_food_samples_count = 0
    for key, value in like_foods_num_dict.items():
        #print(value, n)
        if value == n:
            same_like_food_samples_count += 1
        else:
            #raise
            pass

    #print(same_like_food_samples_count)
    return same_like_food_samples_count


def main():
    input_line_list = stdin.readlines()
    input_line_list = [y.rstrip() for y in input_line_list]
    n, m = [int(z) for z in input_line_list[0].split()]
    samples_and_like_foods = [x.split() for x in input_line_list[1:]]
    #print(n, m)
    #print(samples_and_like_foods)
    #print(input_line_list)
    #samples_and_like_foods = [like_foods_string.split() for like_foods_string in input_line_list]
    #print(samples_and_like_foods)
    print(count_samples_of_like_same_food(n, m, samples_and_like_foods))


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
from itertools import chain


N = int(input())
A = list(map(int, input().split()))

A.sort()

if N % 2 == 1:
    B = [[n] if n == 0 else [2*n, 2*n] for n in range(N//2+1)]
    B = list(chain.from_iterable(B))
    if A != B:
        print(0)
    else:
        print(2 ** (N//2) % (10**9+7))
else:
    B = [[2*n-1, 2*n-1] for n in range(1, N//2+1)]
    B = list(chain.from_iterable(B))
    if A != B:
        print(0)
    else:
        print(2**(N//2) % (10**9+7))


Measured memory_bytes: 16292
import math

def primes(x):
    if x < 2: return []

    primes = [i for i in range(x)]
    primes[1] = 0 # 1は素数ではない

    # エラトステネスのふるい
    for prime in primes:
        if prime > math.sqrt(x): break
        if prime == 0: continue
        for non_prime in range(2 * prime, x, prime): primes[non_prime] = 0

    return [prime for prime in primes if prime != 0]


X = int(input())
Ans = primes(500000)

for i in range(X, 500000):
    if i in Ans:
        print(i)
        exit()

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

class Challenge
{
    static void Main()
    {
        var N = int.Parse(Console.ReadLine());
      	if (N == 1) { Console.WriteLine("1"); return; }

      	var count_N = new int[N+1];
        for (int i=1; i<=N; i++)
        {
            var x = i;
            var count = 0;
            while(x%2 == 0)
            {
                x /= 2;
                count++;
            }
            count_N[i] = count;
        }
      
        Console.WriteLine( Array.IndexOf(count_N, count_N.Max()) );
    }
}


Measured memory_bytes: 13268
program main
implicit none

character*3 :: s
character*1 :: r
integer :: curLongest,totalLongest,i
read(*,*) s

r = 'R'

totalLongest = 0
curLongest = 0

do i=1,3
  if(s(i:i).eq.r) then
    ! write(*,*) s(i:i),r
    curLongest = curLongest + 1
  else
    curLongest = 0
  endif
  if(totalLongest.lt.curLongest) then
    totalLongest = curLongest
  endif
enddo

write(*,*) totalLongest
end program

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


int main(){
    int n;
    cin>>n;
    vector<string> a(n);
    rep(i,n){
        cin>>a[i];
    }
    rep(i,n-1){
        if(a[i][a[i].size()-1] != a[i+1][0]){
            cout << "No" << endl;
            return 0;
        }
        for(int j=i+1;j<n;j++){
            if(a[i]==a[j]){
                cout << "No" << endl;
                return 0;
            }
        }
    }
    cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 256
N,D = map(int, input().split())
count=0

inputs = [list(map(int, input().split())) for i in range(N)]

for i in range(len(inputs)-1):
    for j in range(i+1, len(inputs)):
        temp= 0
        for k in range(D):
            temp += (inputs[i][k]-inputs[j][k])**2
        temp = temp**(1/2)
        if int(temp) == temp:
            count+=1
print(count)

Measured memory_bytes: 3188
n = int(raw_input())
r = []
for i in xrange(1,n+1):
	rest,score = raw_input().split()
	score=int(score)
	r.append((rest,score,i))
r = sorted(r,key=lambda x:(x[0], -x[1], x[2]))
for x in r:
	print x[2]

Measured memory_bytes: 2568
#include<stdio.h>
int main(){
  int i=0,c,max=0;
  char mi,b,s[8030]={0};
  scanf("%s",s);
  while(s[i]){
    c=1;
    while(1){
      b=s[i];
      if(s[i]=='e'){
	if(s[(i+=3)]-'c')break;
      }
      else{
	if(s[(i+=7)]-'e')break;
      }
      c++;
    }
    if(max<c){
      max=c;
      mi=b;
    }
  }
  if(mi=='c')printf("chicken\n");
  else         printf("egg\n");
  return 0;
}

Measured memory_bytes: 524
import math
pi=3.1415926535897932
chk=0.0000001
a,b,x=map(int,input().split())
t=a*b/2
s=x/a
if abs(t-s)<chk:
    print(45.0)
elif t>s:
    h=[0,a]
    while 1:
        hs=(h[0]+h[1])/2
        w=b*hs/2
        if abs(w-s)<chk:
            break
        elif w>s:
            h[1]=hs
        elif w<s:
            h[0]=hs
    print(90-math.atan(hs/b)*180/pi)
else:
    h=[0,b]
    while 1:
        hs=(h[0]+h[1])/2
        w=(hs+b)*a/2
        if abs(w-s)<chk:
            break
        elif w>s:
            h[1]=hs
        elif w<s:
            h[0]=hs
    print(90-math.atan(a/(b-hs))*180/pi)

Measured memory_bytes: 38384
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007, INF=mod*mod*3LL;
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    ll n, m, k;
    cin >> n >> m >> k;
    ll a[n];
    for(int i=0;i<n;i++){
    	cin >> a[i];
    }
    deque<pair<ll,ll> > dq[k+1];
    for(ll i=0;i<n;i++){
    	for(ll j=k-1;j>=1;j--){
    		while(dq[j-1].size() && dq[j-1].front().second < i - m)dq[j-1].pop_front();
    		if(dq[j-1].empty()) continue;
    		ll v = a[i]*(j+1) + dq[j-1].front().first;
    		while(dq[j].size() && dq[j].back().first < v) dq[j].pop_back();
    		dq[j].push_back({v, i});
    	}
    	while(dq[0].size() && a[i] > dq[0].back().first) dq[0].pop_back();
    	dq[0].push_back({a[i],i});
    }
    cout << dq[k-1].front().first << endl;
    return 0;
}


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

long long gcd(long long a, long long b) {
  if(b == 0) return a;
  return gcd(b, a % b);
}

long long max(long long a, long long b){
    if (a > b) return a;
    else return b;
}

int main(void){
    // Your code here!
   int N;
   cin >> N;
   long long A[N];
   for(int i = 0; i < N; i++) cin >> A[i];
   
   long long dpl[N+1];
   long long dpr[N+1];
   
   dpl[0] = A[0];
   dpr[0] = A[N-1];
   for(int i = 0; i < N; i++){
       dpl[i+1] = gcd(dpl[i], A[i]);
   }
   
   for(int i = 0; i < N; i++){
       dpr[i+1] = gcd(dpr[i], A[N-1-i]);
   }
   

   int maxv = 0;
   for(int i = 2; i <= N-1; i++){
       maxv = max(maxv, gcd(dpl[i-1], dpr[N-i]));
   }
   
   maxv = max(maxv, dpr[N-1]);
   maxv = max(maxv, dpl[N-1]);

   cout << maxv << endl;
}


Measured memory_bytes: 2560
#include <stdio.h>

int main(int argc, const char * argv[]) {
    int m,f,r;
    while (1){
        scanf("%d %d %d",&m,&f,&r);
        if (m == -1 && f == -1 && r == -1){
            break;
        } else {
            if (m == -1 || f == -1){
                printf("F");
            } else if (80 <= m+f){
                printf("A");
            } else if (65 <= m+f){
                printf("B");
            } else if (50 <= m+f){
                printf("C");
            } else if (30 <= m+f && 50 <= r){
                printf("C");
            } else if (30 <= m+f){
                printf("D");
            } else if (m+f < 30){
                printf("F");
            }
            printf("\n");
        }
    }
    return 0;
}


Measured memory_bytes: 2036
import sys
import collections

N = int(sys.stdin.readline().strip().split()[0])

new = []
for i in range(N):
  tmp = sys.stdin.readline().strip().split()
  for j in range(len(tmp)-1):
    new.append(tmp[j+1])

c = collections.Counter(new)


cnt = 0
for i in range(len(c.most_common())):
  if int(c.most_common()[i][1]) == N:
    cnt += 1
  else:
    break
    
print(cnt)

Measured memory_bytes: 3316
#!/usr/bin/env python3
import sys
def input():
    return sys.stdin.readline()[:-1]

def main():
    A = input()
    B = input()
    C = input()

    w = 'a'
    while True:
        if w == 'a':
            if A == '':
                print('A')
                exit()
            w = A[0]
            A = A[1:]
        if w == 'b':
            if B == '':
                print('B')
                exit()
            w = B[0]
            B = B[1:]
        if w == 'c':
            if C == '':
                print('C')
                exit()
            w = C[0]
            C = C[1:]


if __name__ == '__main__':
    main()


Measured memory_bytes: 9104
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define rep2(i, s, n) for(int i=s; i<(n); ++i)
#define ALL(v) (v).begin(), (v).end()

using namespace std;

typedef long long ll;

static const int INTINF = (2147483647 >> 1); // 10^9 + 5000
static const ll LLINF = (9223372036854775807 >> 1);
static const int MAX = 1e5+1;
static const ll MOD = 1e9+7;

namespace Kunitaka{
    template<
        typename TYPE,
        std::size_t SIZE
    >
    std::size_t array_length(const TYPE (&array)[SIZE])
    {
        return SIZE;
    }
}
using namespace Kunitaka;
namespace Printer{
    void br(){
        cout << endl;
    }

    void loop_cnt(int i){
        cout << "i = " << i << endl;
    }

    void loop_cnt(int i, int j){
        cout << "i = " << i << ", " << "j = " << j << endl;
    }

    template<class T>
    void print(T x){
        cout << x << endl;
    }

    template<class T, class S>
    void print(T x, S y){
        cout << x << "," << y << endl;
    }

    template<class T, class S, class U>
    void print(T x, S y, U z){
        cout << x << "," << y << "," << z << endl;
    }

    template<class T, class S>
    void print(pair<T, S> p){
        cout << p.first << ", " << p.second << endl;
    }

    template<
        typename TYPE,
        std::size_t SIZE
    >
    void print(const TYPE (&array)[SIZE]){
        int lim = array_length(array);
        for(int i=0; i<lim; i++){
            if(i) cout << " ";
            cout << array[i];
        }
        cout << endl;
    }

    template<class S>
    void print(vector<S> v){
        for(int i=0; i<v.size(); i++){
            if(i) cout << " ";
            cout<< v[i];
        }
        cout << endl;
    }

    template<class S>
    void print(vector<vector<S> > vv){
        for(int i=0; i<vv.size(); i++){
            for(int j=0; j<vv[i].size(); j++){
                if(j) cout << " ";
                cout << vv[i][j];
            }
            cout << endl;
        }
    }

    void yesno(bool x){
        if(x) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
};
using namespace Printer;


int main(int argc, const char * argv[]) {
    //提出時、消す----//
    //--------------//


    // input
    cout << fixed << setprecision(10);
    ll N; cin >> N;
    if(N == 1){
        cout << 0 << endl;
        return 0;
    }

    ll ans = 0;

    for(ll i=1; i*i<N; i++){
        if(N%i != 0) continue;
        ll a = i;
        if(a >= N/a-1) continue;
        ans += N/a-1;
    }

    print(ans);
    
    return 0;
}


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

#define REP(i,n) for(int i=0; i<int(n); i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define VI vector<int>
#define VC vector<char>
#define FOREACH(x,a) for(auto& (x) : (a) )
using namespace std;

int main() {
	int d, n;
	cin >> d >> n;
	int a = pow(100, d);
	if (n == 100) {
		cout << 101 * a << endl;
	}
	else {
		cout << n*a << endl;
	}
	return 0;
}

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

using namespace std;

typedef long long  ll;

struct Edge {
    int src, dst, w;
    Edge(int src, int dst, int w) : src(src), dst(dst), w(w) {}
    Edge() {}
};
typedef vector<Edge>   Edges;
typedef vector<Edges>  Graph;

struct Node {
    int v, res, time;
    Node() {}
    Node(int v, int res, int time) : v(v), res(res), time(time) {}
};

int Solve(const Graph &g, const vector<int> &frozen,
          const int s, const int t, const int m)
{
    const int n = g.size();
    const int INF = n * n * m * m;
    vector<vector<int>> dp(n, vector<int>(m + 1, INF));
    queue<Node> que;

    dp[s][m] = 0;
    que.push(Node(s, m, 0));

    while (!que.empty()) {
        Node now = que.front();
        que.pop();

        if (frozen[now.v]) {
            for (auto e : g[now.v])
                for (int hp = now.res; hp <= m; ++hp) {
                    int time = now.time + e.w + hp - now.res;
                    int res = hp - e.w;
                    if (0 <= res && time < dp[e.dst][res]) {
                        dp[e.dst][res] = time;
                        if (e.dst != t)
                            que.push(Node(e.dst, res, time));
                    }
                }
        }
        else {
            for (auto e : g[now.v]) {
                int res = now.res - e.w;
                if (0 <= res && now.time + e.w < dp[e.dst][res]) {
                    dp[e.dst][res] = now.time + e.w;
                    if (e.dst != t)
                        que.push(Node(e.dst, res, dp[e.dst][res]));
                }
            }
        }
    }

    int ans = INF;
    for (int i = 0; i <= m; ++i)
        ans = min(ans, dp[t][i]);

    return (ans == INF ? -1 : ans);
}

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

    int n; // ????????°??????????????????0???n-1???
    int m; // ???????????????????????§?????¶?????????
    int l; // ??????????¨??????????????????°
    int k; // ?????¨????????´??\?????¶???????????°
    int a; // ??¬????????????
    int h; // ????§??§??????¬?????????????????¢?????????????????????

    while (true) {
        cin >> n >> m >> l >> k >> a >> h;
        if (n == 0 && m == 0 && l == 0 && k == 0 && a == 0 && h == 0)
            break;

        // ??????????¨??????????????????????
        vector<int> frozen(n, false);
        int tmp_f;
        frozen[a] = frozen[h] = true;
        for (int i = 0; i < l; ++i) {
            cin >> tmp_f;
            frozen[tmp_f] = true;
        }

        // ?????¨???????????¶??????????????±
        Graph g(n);
        int x, y, t;
        for (int i = 0; i < k; ++i) {
            cin >> x >> y >> t;
            g[x].push_back(Edge(x, y, t));
            g[y].push_back(Edge(y, x, t));
        }

        int res = Solve(g, frozen, a, h, m);
        if (res == -1)
            cout << "Help!" << endl;
        else
            cout << res << endl;
    }

    return 0;
}

Measured memory_bytes: 3296
n = int(input())
a = []
for i in range(n):
  x,y,z = map(int,input().split())
  a.append([x+y,x,y,z])
dp = [-1] * 20001
a.sort()
dp[0] = 0
for i in range(n):
  for j in range(20000,-1,-1):
    if dp[j] != -1 and a[i][2]>= j:
      dp[j+a[i][1]] = max(dp[j+a[i][1]],dp[j]+a[i][3])
print(max(dp)) 


Measured memory_bytes: 42092
#include <iostream>

int ncr(int n, int r)
{
	if (r > n)
		return 0;
	int ans = 1;
	for (int i = n; i > n - r; --i)
		ans *= i;
	for (int i = 2; i <= r; ++i)
		ans /= i;
	return ans;
}

int main()
{
	int n, m;
	std::cin >> n >> m;
	std::cout << ncr(n, 2) + ncr(m, 2) << '\n';
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define WHOLE(v) (v).begin(), (v).end()
#define REV_WHOLE(v) (v).rbegin(), (v).rend()
using i64 = int64_t;
using namespace std;
i64 ans = 0;

void recursive(string s, i64 x) {
    for (int i = 1; i < s.size(); i++) {
        recursive(s.substr(i), x + stoi(s.substr(0, i)));
    }
    ans += x + stoll(s);
}

int main() {
    string S;
    cin >> S;
    recursive(S, 0);
    cout << ans << endl;
    return 0;
}

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

using namespace std;

int v[3];

int main(){
	int a, b, c, d;
	
	a = b = c = d = 0;
	
	while(true){
		scanf("%d%d%d", &v[0], &v[1], &v[2]);
		
		sort(v, v + 3);
		
		if(v[2] < v[0] + v[1]){
			a++;
			
			if(v[2] * v[2] == v[0] * v[0] + v[1] * v[1])
			b++;
			else if(v[2] * v[2] > v[0] * v[0] + v[1] * v[1])
			d++;
			else
			c++;
		}
		else
		break;
	}
	
	printf("%d %d %d %d\n", a, b, c, d);
}



Measured memory_bytes: 3304
#include <stdio.h>
int main(){
    int n;
    scanf("%d",&n);
    int a[n];
    int i;
    for(i=0;i<n;i++)scanf("%d",&a[i]);
    int min=a[0];
    int samax=-1000000000;
    for(i=1;i<n;i++){
        if(samax<a[i]-min)
            samax=a[i]-min;
        if(min>a[i])
            min=a[i];
    }
    
    printf("%d\n",samax);
}



Measured memory_bytes: 2540
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int main() {
	char str0[11] = { NULL }, str1[11] = { NULL }, str2[100][22];
	int ryofactory,ruio, hideo, nagase;
	cin >> str0;
	ryofactory = strlen(str0);
	cin >> ruio;
	int j = 0;
	for (int i = ryofactory-1; i > -1;i--) {
		str1[j] = str0[i];
		j++;
	}
	for (int i = 0; i < ruio; i++) {
		cin >> str2[i];
		strncat(str2[i], str2[i],11);
	}
	j = 0;
	for (int i = 0; i < ruio; i++) {
		if (strstr(str2[i],str0) != 0) {
			j++;
		}
		/*else if (strcmp(str1, str1) != NULL) {
			j++;
		}*/
	}
	cout << j << endl;
}

Measured memory_bytes: 3076
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
#define rep(i, n) for(int i=0;i<(int)n;i++)
#define PI acos(-1)
#define fast_io ios_base::sync_with_stdio(false) ; cin.tie(0); cout.tie(0);
ll mod=1e9+7;

int main(){
    fast_io

    ll n,k;
    cin>>n>>k;
    vector<ll> a(n);
    rep(i,n) cin>>a[i];

    vector<ll> s;
    vector<ll> ord(n+1, -1);
    int c=1, l=0;
    {
        int v = 1;
        while(ord[v]==-1){
            ord[v]=s.size();
            s.push_back(v);
            v = a[v-1];
        }
        c = s.size()-ord[v];//周期
        l=ord[v];//尻尾を含めた経路
    }
    if(k<l) cout<<s[k]<<endl;
    else{
        k-=l;
        k%=c;
        cout<<s[l+k]<<endl;
    }
    return 0;
}

Measured memory_bytes: 8432