akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

#define int long long
#define all(v) (v).begin(), (v).end()
#define resz(v, ...) (v).clear(), (v).resize(__VA_ARGS__)
#define reps(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep(i, n) reps(i, 0, n)

template<class T1, class T2> void chmin(T1 &a, T2 b){if(a>b)a=b;}
template<class T1, class T2> void chmax(T1 &a, T2 b){if(a<b)a=b;}

using Pi = pair<int, int>;
using Ti = tuple<int, int, int>;
using vint = vector<int>;

const int inf = 1LL << 55;
const int mod = 1e9 + 7;

int dp[5005];

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

  int n;
  cin >> n;
  vint h(n), p(n);
  rep(i, n) cin >> h[i] >> p[i];
  vint id(n); iota(all(id), 0);
  auto cmp = [&](int i, int j) {
    return h[i]+p[i] < h[j]+p[j];
  };
  sort(all(id), cmp);
  fill(dp, dp+5005, inf);
  dp[0] = 0;
  for(int& i : id) {
    for(int j = n; j > 0; j--) {
      if(dp[j-1] == inf) continue;
      if(dp[j-1] > h[i]) continue;
      chmin(dp[j], dp[j-1]+p[i]);
      //cout<<j<<" "<<dp[j]<<endl;
    }
  }
  int ans = 0;
  rep(i, n+1) if(dp[i] < inf) ans = i;
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 384
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
#include<unordered_set>
#include<unordered_map>
#include<fstream>
#include<list>
#include<functional>
#include<bitset>
#include<complex>
#include<tuple>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pi;
typedef pair<double,double> pd;
typedef pair<double,ll> pdl;
#define F first
#define S second
const ll E=1e18+7;
const ll MOD=1000000007;

ll h,w;


int main(){
    cin>>h>>w;
    ll W=w;
    vector<string> A(h);
    ll ans=0;
    for(auto &I:A){cin>>I;}
    vector<set<pair<ll,char>>> YOKO(h),TATE(w);
    vector<vector<bool>> cnt(h,vector<bool>(w,false));
    queue<pll> Q;
    for(int i=0;i<h;i++){
        for(int t=0;t<w;t++){
            if(A[i][t]!='.'){YOKO[i].insert({t,A[i][t]}); TATE[t].insert({i,A[i][t]});}
            else{cnt[i][t]=true; Q.push({i,t});}
        }
    }
    while(!Q.empty()){
        pll w=Q.front(); Q.pop();
        /*
        cout<<w.F<<" "<<w.S<<endl;
        for(int i=0;i<h;i++){
            for(int t=0;t<W;t++){
                cout<<A[i][t];
            }
            cout<<endl;
        }
        */
        cnt[w.F][w.S]=false;
        pair<pll,char> c[4]={{{-1,-1},0},{{-1,-1},0},{{-1,-1},0},{{-1,-1},0}};
        if(!YOKO[w.F].empty()){
            auto I=YOKO[w.F].lower_bound({w.S,0});
            if(I!=YOKO[w.F].end()){c[0]={{w.F,I->F},I->S};}
            if(I!=YOKO[w.F].begin()){--I; c[1]={{w.F,I->F},I->S};}
        }
        if(!TATE[w.S].empty()){
            auto I=TATE[w.S].lower_bound({w.F,0});
            if(I!=TATE[w.S].end()){c[2]={{I->F,w.S},I->S};}
            if(I!=TATE[w.S].begin()){--I; c[3]={{I->F,w.S},I->S};}
        }
        vector<pll> erase={w};
        for(int i=1;i<4;i++){
            for(int t=0;t<i;t++){
                if(c[i].S!=0 && c[i].S==c[t].S){
                    erase.push_back(c[i].F);
                    erase.push_back(c[t].F);
                    /*
                    cout<<c[i].F.F<<" "<<c[i].F.S<<" "<<c[i].S<<endl;
                    cout<<c[t].F.F<<" "<<c[t].F.S<<" "<<c[t].S<<endl;
                    cout<<endl;
                     */
                    c[i].S=0;
                    c[t].S=0;
                    ans+=2;
                }
            }
        }
        if(erase.size()==1){continue;}
        for(auto &I:erase){
            YOKO[I.F].erase({I.S,A[I.F][I.S]});
            TATE[I.S].erase({I.F,A[I.F][I.S]});
            A[I.F][I.S]='.';
            for(int t=0;t<W;t++){
                if(A[I.F][t]=='.' && !cnt[I.F][t]){cnt[I.F][t]=true; Q.push({I.F,t});}
            }
            for(int t=0;t<h;t++){
                if(A[t][I.S]=='.' && !cnt[t][I.S]){cnt[t][I.S]=true; Q.push({t,I.S});}
            }
        }
    }
    cout<<ans<<endl;
    
    
    return 0;
}



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

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

using namespace std;

namespace mp = boost::multiprecision;
using Bint = mp::cpp_int;

using ll = long long;
ll mod = pow(10, 9) + 7;

template <typename T> void output(T, ll);
ll gcd(ll, ll);
ll lcm(ll, ll);
Bint comb(Bint, Bint);
void prime_map(map<ll, ll> &, ll);

int main() {
    // source
    string s;
    cin >> s;
    bool ans = true;
    rep(i, s.size()) {
        if (i % 2 == 0) {
            if (s[i] == 'R' | s[i] == 'U' | s[i] == 'D') {
                ans = true;
            } else {
                ans = false;
                break;
            }
        } else {
            if (s[i] == 'L' | s[i] == 'U' | s[i] == 'D') {
                ans = true;
            } else {
                ans = false;
                break;
            }
        }
    }

    if (ans) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}

Bint comb(Bint a, Bint b) {
    Bint ans = 1;

    if (a < b) {
        return 0;
    }

    rep(i, b) {
        ans *= a - i;
        ans /= i + 1;
    }

    return ans;
}

template <typename T> void output(T a, int precision) {
    if (precision > 0) {
        cout << setprecision(precision) << a << "\n";
    } else {
        cout << a << "\n";
    }
}

template <typename T> T min(T a, T b) {

    if (a < b) {
        return a;
    } else {
        return b;
    }
}

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

ll lcm(ll a, ll b) { return a * b / gcd(a, b); }

void prime_map(map<ll, ll> &m, ll num) {
    ll cache = num;
    repd(i, 2, sqrt(num) + 2) {
        if (num % i == 0) {
            if (m[i] == 0) {
                m[i] = 1;
            } else {
                m[i]++;
            }

            num /= i;
            break;
        }
    }

    if (cache == num) {
        if (m[num] == 0) {
            m[num] = 1;
        } else {
            m[num]++;
        }
        return;
    } else {
        prime_map(m, num);
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<iomanip>
#include <numeric>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define yesno(flg) if(flg){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define MAX_N 1002
#define i197 1000000007
#define KETA 40

using namespace std;

typedef long long  ll;
typedef pair<ll,ll> P1;
typedef pair<string,int> Pi;
typedef pair<double,Pi> Pdi;
typedef pair<ll,int>Pli;
typedef pair<Pi,int> P2;
const ll INF=1000000000000000001;
struct edge{int to,cost;};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
struct Road{double cost;int a,b;};

int t[100001]={};
int d[100001]={};
int main() {

	string s;

	cin>>s;

	rep(i,s.size()){
		if(s[i]=='R')t[i]++;
		if(s[i]=='R'&&s[i+1]=='R'){
			t[i+1]=t[i];
			t[i]=0;
		}
	}
	rrep(i,s.size()){
		if(s[i]=='L')d[i]++;
		if(s[i]=='L'&&s[i-1]=='L'){
			d[i-1]=d[i];
			d[i]=0;
		}
	}
	rep(i,s.size()-1){
		int y=0,x=0;
		if(s[i]=='R'&&s[i+1]=='L'){
			y=d[i+1];
			x=t[i];
			t[i]=y/2+x/2+x%2;
			d[i+1]=y/2+x/2+y%2;

		}
		cout<<max(t[i],d[i])<<" ";
	}
	cout<<max(t[s.size()-1],d[s.size()-1])<<endl;
	return 0;

}


Measured memory_bytes: 1408
N,M = map(int,input().split())
digit = 'zero padding: {:0=6}'
dic = [[] for _ in range(N+1)]

for i in range(M):
    p,y = map(int,input().split())
    dic[p].append((y,i))

for p in dic:
    p.sort()

ans = [None for _ in range(M)]
for k in range(1,N+1):
    p = dic[k]
    for j in range(len(p)):
        i = p[j][1]
        ID = str(k).zfill(6)+str(j+1).zfill(6)
        ans[i] = ID

for a in ans:
    print(a)


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

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

fn main() {
    let v = read_vec::<i64>();
    let (n, d) = (v[0], v[1]);
    let ans = (n + 2 * d) / (2 * d + 1);
    println!("{}", ans);
}

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

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


Measured memory_bytes: 2104
r,g,b,n=map(int,input().split())
count=0
for x in range(n+1):
    for y in range(n-x+1):
        z=(n-r*x-g*y)//b
        if 0<=z<=3000:
            if r*x+g*y+z*b==n:count+=1
print(count)

Measured memory_bytes: 40940
def solve():
    N = int(input())
    A = list(map(int, input().split()))

    for num in A:
        if num % 2 == 0:
            if num % 3 != 0 and num % 5 != 0:
                print('DENIED')
                break
    else:
        print('APPROVED')

if __name__ == '__main__':
    solve()

Measured memory_bytes: 38256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int[][] bingo = new int[3][3];
		for(int i = 0; i < 3; i++){
			for(int i2 = 0; i2 < 3; i2++){
				bingo[i][i2] = sc.nextInt();
			}
		}
		int n = sc.nextInt();
		boolean[][] bingo2 = new boolean[3][3];
		for(int i = 0; i < n; i++){
			int x = sc.nextInt();
			for(int k = 0; k < 3; k++){
				for(int k2 = 0; k2 < 3; k2++){
					if(bingo[k][k2] == x){
						bingo2[k][k2] = true;
					}
				}
			}
		}
		boolean isBingo =
				bingo2[0][0] && bingo2[0][1] && bingo2[0][2]
				|| bingo2[1][0] && bingo2[1][1] && bingo2[1][2]
						|| bingo2[2][0] && bingo2[2][1] && bingo2[2][2]
				|| bingo2[0][0] && bingo2[1][1] && bingo2[2][2]
						|| bingo2[0][0] && bingo2[1][0] && bingo2[2][0]
						|| bingo2[0][1] && bingo2[1][1] && bingo2[2][1]
						|| bingo2[0][2] && bingo2[1][2] && bingo2[2][2]
						|| bingo2[0][2] && bingo2[1][1] && bingo2[2][0];
		System.out.println(isBingo ? "Yes" : "No");
	}
}


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

using namespace std;

int main() {
	int n;
	int f = 0;
	cin >> n;
	while (n != 0) {
		if (n % 10 == 7) {
			cout << "Yes\n";
			f = 1;
			break;
		}
		n /= 10;
	}
	if (f == 0) {
		cout << "No\n";
	}
	
	
	return 0;
}

Measured memory_bytes: 3572
/*
    Stay motivated and keep working hard
*/
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll N, W, maxsum;
const ll INF = 1e15 + 7;
ll dp[107][100007]; // dp[N][V] - min wt for N items equal to value V
// if this min weight is <= W and V is as max as possible that is our answer
ll wt[107], val[107];
bool vis[107][100007];
// ll recur(ll n, ll v){
//     // base case
//     if(v <= 0){
//         return 0;
//     }
//     if(n == 0){
//         return INF;
//     }
//     if(vis[n][v]){
//         return dp[n][v];
//     }
//     vis[n][v] = 1;
//     return dp[n][v] = min(dp[n][v], min(recur(n-1, v), wt[n-1] + recur(n-1, v-val[n-1])));
//     // if(v >= val[n]){
//     //     return dp[n][v] = min(dp[n][v], min(recur(n+1, v), wt[n] + recur(n+1, v-val[n])));
//     // }
//     // else{
//     //     return dp[n][v] = min(dp[n][v], recur(n+1, v));
//     // }
// }
int main(){

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    cin >> N >> W;
    for(ll i=0;i<N;i++){
        cin >> wt[i] >> val[i];
        maxsum += val[i];
    }
    for(ll i=0;i<=N;i++){
        for(ll j=0;j<=maxsum;j++){
            dp[i][j] = INF;
        }
    }
    for(ll i=0;i<=maxsum;i++){
        dp[0][i] = INF;
    }
    for(ll i=0;i<=N;i++){
        dp[i][0] = 0;
    }
    for(ll i=1;i<=N;i++){
        for(ll j=1;j<=maxsum;j++){
            dp[i][j] = min(dp[i][j], min(dp[i-1][j], wt[i-1] + dp[i-1][j-val[i-1]]));
        }
    }
    bool flag = false;
    for(ll V = maxsum; V >= 0; V--){
        if(dp[N][V] <= W){
            flag = true;
            // cout << dp[N][V] << " ";
            cout << V << "\n";
            break;
        }
    }
    if(!flag){
        cout << "0\n";
    }
    // for(ll i=0;i<=N;i++){
    //     for(ll j=0;j<=maxsum;j++){
    //         cout << dp[i][j] << " ";
    //     }
    //     cout << "\n";
    // }
    
    // recur(0, maxsum);
    // bool flag = false;
    // for(ll V = maxsum; V >= 0; V--){
    //     if(recur(N, V) <= W){
    //         cout << V << "\n";
    //         flag = true;
    //         break;
    //     }
    // }
    // if(!flag){
    //     cout << "0\n";
    // }

  
    return 0;
}


Measured memory_bytes: 80128
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
using vi = vector<int>; // intの1次元の型に vi という別名をつける
using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける

int main() {
  int n;
  cin >> n;
  vector<tuple<string,int,int>> v;
  rep (i,n) {
    string s;
    int p;
    cin >> s >> p;
    v.push_back(make_tuple(s,100-p,i+1));
  }
  
  sort(v.begin(), v.end());
  
  rep (i,n) {
    int ord;
    tie(ignore, ignore, ord)=v.at(i);
    cout << ord << endl;
  }  
  return 0;
}

Measured memory_bytes: 256
#include <set>
#include <map>
#include <queue>
#include <ctime>
#include <cmath>
#include <cstdio>
#include <bitset>
#include <vector>
#include <cstring>
#include <cassert>
#include <iostream>
#include <algorithm>
using namespace std;
typedef double db;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pa;
typedef unsigned int uint;
typedef unsigned long long ull;
#define w1 first
#define ls (x<<1)
#define w2 second
#define ins insert
#define rs (x<<1|1) 
#define mp make_pair
#define pb push_back
#define mid ((l+r)>>1)
#define sqr(x) ((x)*(x))
#define cle(x) ((x).clear())
#define lowbit(x) ((x)&(-x))
#define SZ(x) (int((x).size()))
#define ms(x,y) memset(x,y,sizeof (x))
#define rep(i,a,b) for(int (i)=(a);(i)<=(b);(i)++)
#define rep2(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
#define per(i,a,b) for(int (i)=(a);(i)>=(b);(i)--)
#define Rep(p,x) for(int (p)=head[(x)];(p);(p)=nxt[(p)]) 
#define Rep2(p,x) for(int (p)=cur[(x)];(p);(p)=nxt[(p)])
#define debegin printf("debug\nbegin\n")
#define deend printf("debug\nend\n")
#define isfind printf("find\n")
template<class T>inline void rread(T&num){
	num=0;T f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9')num=num*10+ch-'0',ch=getchar();
	num*=f;
}
inline int getgcd(int x,int y){if(!x)return y;return getgcd(y%x,x);}
inline int power(int x,int k,int p){int res=1;for(;k;k>>=1,x=(ll)x*x%p)if(k&1)res=(ll)res*x%p;return res;}
const double pi=acos(-1);
inline void judge(){
	freopen("input.txt","r",stdin);
} 
//********************************head*************************************	
const int maxn=2e3+5;
int n,m,q;
int a[maxn][maxn],b[maxn][maxn],c[maxn][maxn];
char str[maxn];
inline int calc(int a[maxn][maxn],int x1,int x2,int y1,int y2){
	if(x1>x2||y1>y2)return 0;
	return a[x2][y2]-a[x2][y1-1]-a[x1-1][y2]+a[x1-1][y1-1];
}
int main(){
	rread(n);rread(m);rread(q);
	rep(i,1,n){
		scanf("%s",str+1);
		rep(j,1,m)if(str[j]=='1')a[i][j]=1;
	}
	rep(i,1,n-1)rep(j,1,m)if(a[i][j]&&a[i+1][j])b[i][j]=1;
	rep(i,1,n)rep(j,1,m-1)if(a[i][j]&&a[i][j+1])c[i][j]=1;
	rep(i,1,n)rep(j,1,m)a[i][j]=a[i-1][j]+a[i][j-1]-a[i-1][j-1]+a[i][j];
	rep(i,1,n)rep(j,1,m)b[i][j]=b[i-1][j]+b[i][j-1]-b[i-1][j-1]+b[i][j];
	rep(i,1,n)rep(j,1,m)c[i][j]=c[i-1][j]+c[i][j-1]-c[i-1][j-1]+c[i][j];
	while(q--){
		int x1,x2,y1,y2;rread(x1);rread(y1);rread(x2);rread(y2);
		printf("%d\n",calc(a,x1,x2,y1,y2)-calc(b,x1,x2-1,y1,y2)-calc(c,x1,x2,y1,y2-1));
	}
	return 0;
}

Measured memory_bytes: 48896
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<stack>
#include<vector>
#include<map>
#include<queue>
#include<cmath>
#include<set>
#include<cstdlib>
#include<cctype>
#include<ctime>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll maxn = 1e5 + 5;
const ll maxm = 1e3 + 5;
const ll MOD = 1e9 + 7;
template<class T>
inline T qread(T &IEE){
	register T x = 0, f = 1;
	register char ch = getchar();
	while(!isdigit(ch)){
		if(ch == '-'){
			f = -f;
		}
		ch = getchar();
	}
	while(isdigit(ch)){
		x = (x << 1) + (x << 3) + (ch ^ 48);
		ch = getchar();
	}
	return IEE = x * f;
}
template<class T>
inline void qwrite(T a){
	if(!a){
		putchar('0');
		return ;
	}
 	if(a < 0){
		putchar('-');
		a = -a;
	}
	if(a > 9) qwrite(a / 10);
	putchar(a % 10 + 48);
	return ;
}
template<class T>
inline T ab(T a){
	return (a > 0) ? a : -a;
}
template<class T>
inline void swa(T &a, T &b){
	a ^= b ^= a ^= b;
	return ;
}
ll cnt = 1, n;
int main(){
//	freopen("1.in", "r", stdin);
//	freopen("1.out", "w", stdout);
	cin >> n;
	for(int i = 1;i <= n;i++){
		cnt *= i;
		cnt %= MOD;
	}
	cout << cnt << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb(x) push_back(x)

int main()
{
    ll n,a,b,f=0;
    cin>>n>>a>>b;
    for(int i=a;i<=b;i++)
    {
        if(i%n==0)
        {
            cout<<"OK"<<endl;
            return 0;
        }
    }
    cout<<"NG"<<endl;
}


Measured memory_bytes: 3636
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <cstring>
#include <climits>
#include <cmath>
#include <cfloat>

using namespace std;

long int a[5000],ma,n;

int main()
{
	
	while(cin >> n, n)
	{
		ma = INT_MIN;
		
		for( int i = 0; i < n; i++)
		{
			cin >> a[i];
		}
		
		for( int j = 0; j < n; j++)
		{
			int sum = 0;
			
			for( int i = j; i < n; i++)
			{
				sum += a[i];
				
				if( sum > ma )
					ma = sum;
				
			}
		}
		
		cout << ma << endl;
	}
	
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define MAX_INF 0x7f
#define MAX_INF_VAL 0x7f7f7f7f
#define pi 3.141592653589
#define eps 1e-10
//#define p 2173412051LL
#define sz 2

using namespace std;

struct p {
	int u, m;
	ll t;
};
struct cmp {
	bool operator () ( const p &a, const p &b ) {
		if( a.t == b.t )
			return a.m < b.m;
		return a.t > b.t;
	}
};
priority_queue< p,vector< p >, cmp > q;
ll f[ 51 ][ 5050 ];
vector< int > e[ 51 ];
ll cst[ 51 ][ 51 ], mins[ 51 ][ 51 ];
ll c[ 51 ], d[ 51 ];
int ma;

void dijk( int, int, ll );
void update( int, int, ll );

int main() {
	int n, mm, s, x, y;
	ll a, b;
	ll u, m, t;
	ll ans;
	scanf( "%d%d%d", &n, &mm, &s );
	ma = mm * 50;
	s = min( s, ma );
	for( int i = 0; i < mm; ++i ) {
		scanf( "%d%d%lld%lld", &x, &y, &a, &b );
		e[ x ].push_back( y );
		e[ y ].push_back( x );
		cst[ x ][ y ] = cst[ y ][ x ] = a;
		mins[ x ][ y ] = mins[ y ][ x ] = b;
	}
	for( int i = 1; i <= n; ++i )
		scanf( "%lld%lld", &c[ i ], &d[ i ] );
	dijk( 1, s, 0 );
	for( int i = 2; i <= n; ++i ) {
		ans = 0x7f7f7f7f7f7f7f7f;
		for( int j = 0; j <= ma; ++j )
			ans = min( ans, f[ i ][ j ] );
		printf( "%lld\n", ans );
	}
	return 0;
}

void dijk( int x, int y, ll z ) {
	p pp;
	memset( f, MAX_INF, sizeof( f ) );
	q.push( { x, y, z } );
	f[ x ][ y ] = z;
	while( !q.empty() ) {
		pp = q.top();
		q.pop();
		if( pp.t == f[ pp.u ][ pp.m ] )
			update( pp.u, pp.m, pp.t );
	}
}

void update( int u, int m, ll t ) {
	int v = u, nm = m;
	ll nt = t;
	for( int i = 1; ; ++i ) {
		nm += c[ u ];
		nt += d[ u ];
		if( nm > ma )
			nm = ma;
		if( nt < f[ v ][ nm ] ) {
			f[ v ][ nm ] = nt;
			q.push( { v, nm, nt } );
		} else
			break;
		if( nm == ma )
			break;
	}
	for( int i = 0; i < e[ u ].size(); ++i ) {
		v = e[ u ][ i ];
		if( m < cst[ u ][ v ] )
			continue;
		nm = m - cst[ u ][ v ];
		nt = t + mins[ u ][ v ];
		if( nt < f[ v ][ nm ] ) {
			f[ v ][ nm ] = nt;
			q.push( { v, nm, nt } );
		}
	}
}

Measured memory_bytes: 21824
/* ＵＴＦ－８ */
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <array>
#include <queue>
#include <stack>
#include <algorithm>
#include <tuple>
#include <numeric>
#include <type_traits>
#include <limits>

#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>

#define USE_COLORED 1

#ifdef USE_COLORED
static const char stdout_pre[]  = "\033[1m"; // bold black
static const char stderr_pre[]  = "\033[31;1m"; // bold red
static const char stdxxx_post[] = "\033[m";

// 当然ながら GCC(g++)/libstdc++ 依存
#include <ext/stdio_filebuf.h>
using stdio_filebuf = __gnu_cxx::stdio_filebuf<char>;
class colored_stdio_filebuf : public stdio_filebuf {
private:
	const char* const pre_;
	const char* const post_;

public:
	colored_stdio_filebuf(FILE* fp, const char* pre, const char* post) : stdio_filebuf(fp, std::ios_base::out), pre_(pre), post_(post)
	{
	}

protected:
	std::streamsize xsputn(const char* s, std::streamsize count) override
	{
		stdio_filebuf::xsputn(pre_, strlen(pre_));
		auto ret = stdio_filebuf::xsputn(s, count);
		stdio_filebuf::xsputn(post_, strlen(post_));
		return ret;
	}
};
#endif

int main()
{
#ifdef USE_COLORED
	if (getenv("DEBUG")) {
		std::cout.rdbuf(new colored_stdio_filebuf(stdout, stdout_pre, stdxxx_post));
		std::cerr.rdbuf(new colored_stdio_filebuf(stderr, stderr_pre, stdxxx_post));
	} else
#endif
	{
		int fd = open("/dev/null", O_WRONLY);
		dup2(fd, 2);
		close(fd);
	}

	int N;
	long K;
	std::vector<int> A;
	std::cin >> N >> K;
	A.resize(N);
	for (auto& a : A) {
		std::cin >> a;
		--a;
	}
	

	std::vector<int> D;
	std::unordered_set<int> S;
	D.push_back(0);
	S.insert(0);
	int cur = 0;
	while (S.find(A[cur]) == S.end()) {
		cur = A[cur];
		D.push_back(cur);
		S.insert(cur);
	}

	cur = A[cur];
	long idx = find(D.begin(), D.end(), cur) - D.begin();
	long kidx = K  - idx;
	if (kidx >= 0)
		std::cout << D[kidx % (D.size() - idx) + idx] + 1<< "\n";
	else
		std::cout << D[K] + 1<< "\n";
}


Measured memory_bytes: 12672
import java.io.InputStream;
import java.io.PrintStream;
import java.util.*;

public class Main {

  public static void main(String[] args) {
    solve(System.in, System.out);
  }

  static void solve(InputStream is, PrintStream os) {
    Scanner sc = new Scanner(is);

    /* read */
    int n = sc.nextInt();
    int k = sc.nextInt();
    int r = sc.nextInt(); // pattern 0
    int s = sc.nextInt(); // pattern 1
    int p = sc.nextInt(); // pattern 2
    
    String t = sc.next();
    
    long ans = 0;
    for (int i = 0; i < k; i++) {
      char lastUsing = '*';
      for (int j = i; j < n; j += k) {
        char c = t.charAt(j);
        if (c == 'r') {
          if (lastUsing != 'p') {
            ans += p; // p wins against r
            lastUsing = 'p';
          } else {
            lastUsing = '*';
          }
        } else if (c == 's') {
          if (lastUsing != 'r') {
            ans += r; // r wins against s
            lastUsing = 'r';
          } else {
            lastUsing = '*';
          }
        } else if (c == 'p') {
          if (lastUsing != 's') {
            ans += s; // s wins against p
            lastUsing = 's';
          } else {
            lastUsing = '*';
          }
        }
      }
    }
    os.println(ans);
  }
}

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

int n;
int a[105];

int main() {
	ios::sync_with_stdio(0); cin.tie(0);
	cin >> n;
	for(int i = 0; i < n; i++)
		cin >> a[i];

	int ans = 1e9;
	for(int x = 1; x <= 100; x++) {
		int cur = 0;
		for(int i = 0; i < n; i++)
			cur += (a[i] - x) * (a[i] - x);
		ans = min(ans, cur);
	}

	cout << ans << '\n';

	return 0;
}

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

int n,m,k;

queue<pair<int,int> >q;

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

bool isValid(int x,int y)
{

    if(x<1 || x>n || y<1 || y>m)
        return false;

    return true;

}

int main()
{

    cin>>n>>m>>k;
    int x1,x2,y1,y2;
    cin>>x1>>y1>>x2>>y2;
    char a[n+5][m+5];
    int dis[n+5][m+5];

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

    q.push({x1,y1});
    dis[x1][y1]=0;
    while(!q.empty())
    {
        int currX=q.front().first;
        int currY=q.front().second;
        q.pop();
        for(int i=0; i<4; i++)
        {
            for(int j=1; j<=k; j++)
            {
                int newX=currX+dx[i]*j;
                int newY=currY+dy[i]*j;
                if(isValid(newX,newY) && a[newX][newY]!='@')
                {
                    if(dis[newX][newY]<=dis[currX][currY])
                        break;
                    if(dis[newX][newY]>dis[currX][currY]+1)
                    {
                        dis[newX][newY]=dis[currX][currY]+1;
                        q.push({newX,newY});
                    }
                }
                else
                    break;
            }
        }
    }

    int ans=dis[x2][y2];
    if(ans==INT_MAX)
        cout<<-1<<endl;
    else
        cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 9180
use std::io;
use std::io::*;
use std::str::FromStr;


fn abc(a:Vec<i32>) -> i32 {
    let max:i32 = *a.iter().max().unwrap();
    let min:i32 = *a.iter().min().unwrap();
    return max - min;
}

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char) 
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    /*
    assert_eq!(abc(), "Yes");
    assert_eq!(abc(101), "No");
    assert_eq!(abc(999999999), "Yes");
    */
    let mut a: Vec<i32> = (0..3).map(|_| read()).collect();
    
    let result = abc(a);
    
    println!("{}", result);
}



Measured memory_bytes: 4352
#include <iostream>  
#include <cstdio>  
#include <algorithm>
#define N 500001
using namespace std;
long long ti=0;
long long a[N];
long long li[N];
long long ri[N]; 
void m(long long a[],long long l,long long m,long long r){
	long long n=m-l;
	long long c=r-m;
	for(long long i=0;i<n;i++)li[i]=a[i+l];
	for(long long i=0;i<c;i++)ri[i]=a[i+m]; 
	li[n]=10000000001;
	ri[c]=10000000001;
	long long i=0,j=0;
	for(long long k=l;k<r;k++){
		ti++;
		if(li[i]<=ri[j]){
			a[k]=li[i];
			i++;
		}else{
			a[k]=ri[j];
			j++;
		}
		//cout<<a[k]<<li[i]<<ri[j]<<"\n";
 }
	return;
}
void msort(long long a[],long long l,long long r){
	if(l+1<r){
		long long mid=l+r;
		mid/=2;
		msort(a,l,mid);
		msort(a,mid,r);
		m(a,l,mid,r);
	} 
	return;
}
int main() { 
	long long n;
	cin>>n;
	for(long long i=0;i<n;i++){
		cin>>a[i];
	}
	msort(a,0,n);
	for(long long i=0;i<n-1;i++){
		printf("%d ",a[i]);
	}
	printf("%d\n",a[n-1]);
	cout<<ti<<endl;
    return 0;  
} 

Measured memory_bytes: 10932
import java.util.Scanner;


public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner s = new Scanner(System.in);
		int[][] c = new int[3][3];
		for(int i = 0;i < 3;i++){
			for(int j = 0;j < 3;j++){
				c[i][j] = s.nextInt();
			}
		}
		
		boolean can = true;
		can &= c[0][0] - c[1][0] == c[0][1] - c[1][1];
		can &= c[0][1] - c[1][1] == c[0][2] - c[1][2];
		can &= c[1][0] - c[2][0] == c[1][1] - c[2][1];
		can &= c[1][1] - c[2][1] == c[1][2] - c[2][2];/**/
		
		System.out.println(can ? "Yes" : "No");
	}

}


Measured memory_bytes: 22612
/**
 * ?????§?????????
 * FX????????§????????°?????????????????¨????????????????????¨??§????????????????????????????????¨?????§????????????????????°????????????100???????????? 1000???????????????????????????????????? 1?????? 108???????????£??????????£??????¨???(108??? ?????? 100???) ???? 1000?????? == 8000??????????????????????????¨?????§????????????
 * <p>
 * ???????????¨?????????????????????t?????????????????? Rt(t=0,1,2,,,n???1)?????\?????¨??????????????????????????§??????????????? Rj???Ri (?????????,j>i??¨??????) ????????§???????±??????????????????????
 * <p>
 * ??\???
 * ?????????????????´??°n?????????????????????????¶????n????????´??° Rt(t=0,1,2,,,n???1) ?????????????????????????????????
 * <p>
 * ??????
 * ?????§??????????????????????????????????????????
 * <p>
 * ??¶?´?
 * 2???n???200,000
 * 1???Rt???10e9
 */

import java.util.*;

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

		int N = stdIn.nextInt();
		int[] numbers = new int[N];

		for (int i = 0; i < N; i++) {
			numbers[i] = stdIn.nextInt();
		}

		int sortCounter = 0;

		for (int i = 0; i < N; i++) {
			for (int j = N - 1; j > i; j--) {
				if (numbers[j] < numbers[j - 1]) {
					int tmp = numbers[j - 1];
					numbers[j - 1] = numbers[j];
					numbers[j] = tmp;
					sortCounter++;
				}
			}
		}

		for (int i = 0; i < N - 1; i++) {
			System.out.print(numbers[i] + " ");
		}
		System.out.println(numbers[N - 1]);
		System.out.println(sortCounter);
	}
}

Measured memory_bytes: 26284
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int A, B;
    cin >> A >> B;
    if (A >= 13)
    {
        cout << B << endl;
    }
    else if (A < 13 & A >= 6)
    {
        cout << B / 2 << endl;
    }
    else
    {
        cout << 0 << endl;
    }
    return 0;
}

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

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

fn main() {
    let n: u32 = read();

    let l0 = 2;
    let l1 = 1;
    let mut l = l0+l1;

    let mut ans: u64 = 0;

    if n == 0 {
        ans = 2;
    } else if n == 1 {
        ans = 1;
    } else {
        let mut prev = l1;
        let mut prev2 = l0;
        for _ in 2..(n+1) {
            l = prev + prev2;
            prev2 = prev;
            prev = l;
        }
        ans = l;
    }

    println!("{}", ans);

}

Measured memory_bytes: 4352
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdint.h> // uint64_t

#define max(a,b) ((a) > (b) ? (a) : (b))
#define min(a,b) ((a) > (b) ? (b) : (a))

int get_int(void) {
  int num;
  scanf("%d", &num);
  return num;
}
#define UNIT_MAX 100
#define NUM_MAX 100000

int asc(const void *a1, const void *a2) {
    return *(int*)a1 - *(int*)a2;
}

int main(void) {
    int units[UNIT_MAX];
    int uidx = 0;
    int ulimit = get_int();

    int num = 6;
    while(ulimit >= num) {
        units[uidx++] = num;
        num *= 6;
    }
    num = 9;
    while(ulimit >= num) {
        units[uidx++] = num;
        num *= 9;
    }
    qsort(units, uidx, sizeof(int), asc);

    static int dp[NUM_MAX+1];
    int i;
    for(i = 0; i <= ulimit; i++) dp[i] = i;

    int k;
    for(k = 0; k < uidx; k++) {
        int unit = units[k];
        for(i = 0; i <= ulimit; i++) {
            if(i>=unit) dp[i] = min(dp[i], dp[i-unit]+1);
        }
    }
    printf("%d\n", dp[ulimit]);

    return 0;
}


Measured memory_bytes: 512
#include "bits/stdc++.h"

using namespace std;

void solve(void)
{
	int n;
	cin >> n;
	vector<int> hs(n);
	for (int i = 0; i < n; i++) cin >> hs[i];
	bool ok = 1;
	hs[0]--;
	for (int i = 1; i < n; i++)
	{
		if (hs[i-1] < hs[i])
		{
			hs[i]--;
		}
		else
		{
			if (hs[i] == hs[i-1]) continue;
			else ok = 0;
		}
	}
	cout << (ok ? "Yes" : "No") << endl;
}

int main()
{
	solve();
	//cout << "yui(*-v・)yui" << endl;
	return 0;
}


Measured memory_bytes: 640
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cassert>
#include <iostream>
#include <cctype>
#include <sstream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <utility>
#include <numeric>
#include <algorithm>
#include <iterator>
#include <bitset>
#include <complex>
#include <fstream>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T> T RoundOff(T a){ return int(a+.5-(a<0)); }
template<class T, class C> void chmax(T& a, C b){ if(a < b) a = b; }
template<class T, class C> void chmin(T& a, C b){ if(b < a) a = b; }
template<class T, class C> pair<T, C> mp(T a, C b){ return make_pair(a, b); }

#define SQR(x) ((x) * (x))
int main()
{
    for(int n; cin >> n && n != 0;)
	{
		int hn = (n - 1) / 2;
		vint num(hn, 0), v(n - 1);
		
		
		rep(i, n - 1) v[i] = SQR(i + 1) % n; 
		
		sort(ALL(v));
		v.erase(unique(ALL(v)), v.end());
		
		
		rep(i, v.size()) rep(j, v.size()) if(i != j)
		{
			int ab = v[i] - v[j];
			
			if(ab < 0) ab += n;
			if(hn < ab) ab = n - ab;
			
			num[ab - 1]++;
		}
		
		rep(i, hn)
			cout << num[i] << endl;
	}
}

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

int main(){
    string a, b, c;
    cin >> a >> b >> c;

    if(a.at(a.size()-1) == b.at(0) && b.at(b.size()-1) == c.at(0)){
        cout << "YES" << "\n";
    }else{
        cout << "NO" << "\n";
    }

  return 0;
}


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

using namespace std;

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

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const ll maxn  = 3e6;
const ll mod =1e9+7;
const ld PI = acos((ld)-1);

#define pb push_back
#define endl '\n'
#define dokme(x) return(cout << x , 0);
#define migmig ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ms(x , y) memset(x , y , sizeof x);
#define file_init freopen("input.txt", "r+", stdin); freopen("output.txt", "w+", stdout);
ll pw(ll a, ll b, ll md = mod){ll res = 1;while(b){if(b&1){res=(a*res)%md;}a=(a*a)%md;b>>=1;}return(res);}

string s;

int main(){
    migmig
    cin >> s;
    cout << s[0] << s[1] << s[2];
    
    
    
    
    return(0);
}

Measured memory_bytes: 3644
N=int(input())
S = []
for i in range(16):
  if   N%4==0: S.append('00'); N-=0
  elif N%4==1: S.append('01'); N-=1
  elif N%4==2: S.append('10'); N+=2
  else       : S.append('11'); N+=1
  N = N//4
  if N == 0: break
ans=''.join(reversed(S))
if ans[0]=='0': ans = ans[1:]
print(ans)


Measured memory_bytes: 3060
import java.util.*;
import java.io.*;
import java.text.*;
import java.math.*;
import static java.lang.Integer.*;
import static java.lang.Double.*;
import java.lang.Math.*;

public class Main {

	public static void main(String[] args) throws Exception {
		new Main().run();
	}

	public void run() throws Exception {
		FastIO file = new FastIO();
		int[] a = new int[3];
		a[0] = file.nextInt();
		a[1] = file.nextInt();
		a[2] = file.nextInt();
		Arrays.sort(a);
		System.out.println(a[0] * a[1] / 2);
	}

	public static class FastIO {
		BufferedReader br;
		StringTokenizer st;

		public FastIO() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}
	}

	public static long pow(long n, long p, long mod) {
		if (p == 0)
			return 1;
		if (p == 1)
			return n % mod;
		if (p % 2 == 0) {
			long temp = pow(n, p / 2, mod);
			return (temp * temp) % mod;
		} else {
			long temp = pow(n, p / 2, mod);
			temp = (temp * temp) % mod;
			return (temp * n) % mod;

		}
	}

	public static long pow(long n, long p) {
		if (p == 0)
			return 1;
		if (p == 1)
			return n;
		if (p % 2 == 0) {
			long temp = pow(n, p / 2);
			return (temp * temp);
		} else {
			long temp = pow(n, p / 2);
			temp = (temp * temp);
			return (temp * n);

		}
	}

	public static long gcd(long x, long y) {
		if (x == 0)
			return y;
		else
			return gcd(y % x, x);
	}

	public static boolean isPrime(int n) {
		if (n <= 1)
			return false;
		if (n <= 3)
			return true;

		if (n % 2 == 0 || n % 3 == 0)
			return false;

		for (int i = 5; i * i <= n; i = i + 6)
			if (n % i == 0 || n % (i + 2) == 0)
				return false;

		return true;
	}
}


Measured memory_bytes: 21204
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val a = sc.nextInt()
    val b = sc.nextInt()
    val c = sc.nextInt()
    val k = sc.nextInt()
    println(problem2020b(a, b, c, k))
}

fun problem2020b(a: Int, b: Int, c: Int, k: Int): String {
    var red = a
    var green = b
    var blue = c
    for (i in 0 until k) {
        if (red >= green) {
            green *= 2
        } else if (green >= blue) {
            blue *= 2
        }
        if (red < green && green < blue) return "Yes"
    }
    return "No"
}

Measured memory_bytes: 36392
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        if ((a < c && b >c ) || (a > c && b < c)) {

            System.out.println("Yes");
        } else {
            System.out.println("No");
        }

    }

}


Measured memory_bytes: 23124
N = int(input())
A = list(map(int, input().split()))

g = [{} for _ in range(N)]
for i, a in enumerate(A):
	g[i][a - 1] = True

count = 0
for n in range(N):
	for r in g[n]:
		if n in g[r]:
			count += 1
print(count // 2)


Measured memory_bytes: 40704
s = input()

if s=='SUN':
  print(7)
elif s=='MON':
  print(6)
elif s=='TUE':
  print(5)
elif s=='WED':
  print(4)
elif s=='THU':
  print(3)
elif s=='FRI':
  print(2)
elif s=='SAT':
  print(1)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#include<unordered_map>
using namespace std;
using Graph = vector<vector<int>>;
#define ll long long
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for(ll i = 0; i < n; i++)
const ll INF = 1LL << 60;


int main(){
    int A, B, C, tA, tB, tC;
    cin >> A >> B >> C;
    tA = A; tB = B; tC = C;
    int ans = 0;
    while(1){
        if(A%2 == 1 ||B%2 == 1 || C%2 == 1)break;
        if(ans > 40){
            cout << - 1 << endl;
            return 0;
        }
        A = (tB + tC) / 2;
        B = (tA + tC) / 2;
        C = (tA + tB) / 2;
        tA = A;
        tB = B;
        tC = C;
        ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
using ll = long long;
#define vl vector<long long>
#define vvl vector<vector<long long>>
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
using pll = pair<long long,long long>;
#define cY cout<<"Yes"<<endl
#define cN cout<<"No"<<endl
const long long INF = 1LL << 60;
const long long MOD = 1000000007;
const long double pi = (acos(-1));
#define pb push_back

//最大最小の入れ替え
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

//約数列挙
vector<long long> divisor(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);
        }
    }
    sort(ret.begin(), ret.end()); // 昇順に並べる
    return ret;
}
//コンビネーション
ll nCr(ll n, ll r) {
    ll ans = 1;
    for (ll i = n; i > n - r; --i) {
        ans = ans*i;
    }
    for (ll i = 1 ; i < r + 1; ++i) {
        ans = ans / i;
    }
    return ans;
}
//素因数分解
map< ll, ll > prime_factor(ll n) {
  map< ll, ll > ret;
  for(ll i = 2; i * i <= n; i++) {
    while(n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if(n != 1) ret[n] = 1;
  return ret;
}

//切り上げの割り算は(a + b - 1) / bでできる

//ここから
int main(){
    ll N;
    cin>>N;
    vl A(N);
    vl B(N);
    vl C(N);
    rep(i,N) cin>>A[i];
    rep(i,N) cin>>B[i];
    rep(i,N) cin>>C[i];
    sort(all(A));
    sort(all(B));
    sort(all(C));
    ll Ans=0;
    rep(i,N){
        ll x=lower_bound(all(A),B[i])-A.begin();
        ll y=C.end()-upper_bound(all(C),B[i]);
        Ans+=x*y;
    }
    cout<<Ans<<endl;
}

Measured memory_bytes: 2560
#include <stdio.h>
#include <stdlib.h>

#define NIL -1
#define INFTY (1<<21)

int **M;
int *key, *p;
int n;

void init() {
  int i, j;

  key = (int *)malloc(sizeof(int) * n);
  p = (int *)malloc(sizeof(int) * n);
  M = (int **)malloc(sizeof(int *) * n);

  for (i = 0; i < n; i++) {
    M[i] = (int *)malloc(sizeof(int) * n);
    key[i] = INFTY;
    p[i] = NIL;
    for (j = 0; j < n; j++) {
      M[i][j] = INFTY;
    }
  }

  key[0] = 0;
}

void input() {
  int i, j, u, k, v, c;

  scanf("%d", &n);
  init();

  for (i = 0; i < n; i++){
    scanf("%d %d", &u, &k);
    for (j = 0; j < k; j++){
      scanf("%d %d", &v, &c);
      M[u][v] = c;
    }
  }
}

int MSTPrim() {
  int i, u;

  while (1) {
    u = NIL;

    for (i = 0; i < n; i++) {
      if (p[i] == 1) continue;
      if (u == NIL || key[i] < key[u]) {
        u = i;
      }
    }

    if (u == NIL) break;
    p[u] = 1;
    for (i = 0; i < n; i++) {
      if (key[i] > M[u][i] + key[u] && p[i] == NIL) {
        key[i] = M[u][i] + key[u];
      }
    }
  }
}

void Free() {
  int i;

  for (i = 0; i < n; i++) {
    free(M[i]);
  }
  free(M);
  free(key);
  free(p);
}

main() {
  int i;

  input();
  MSTPrim();

  for ( i = 0; i < n; i++ ){
    if (key[i] == INFTY) key[i] = -1;
    printf("%d %d\n", i, key[i]);
  }

  Free();

  return 0;
}

Measured memory_bytes: 640
/*
ID: anonymo14
TASK: wormhole
LANG: C++                 
*/
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<pair<int,int>> vpii;

#define F first
#define S second
#define PU push
#define PUF push_front
#define PUB push_back
#define PO pop
#define POF pop_front
#define POB pop_back

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

#define MOD 1000000007

void solve(int test_case) {
	int n;
	cin>>n;
	ll f=2,s=1;
	if(n==0){
		cout<<f;
		return;
	}else if(n==1) {
		cout<<s;
		return;
	}
	n-=1;
	while(n--) {
		ll temp = s;
		s+=f;
		f=temp;
	}
	cout<<s;
}

int main() {
	
	////// FILE BASED IO////
	//freopen("wormhole.in", "r", stdin);
	//freopen("wormhole.out", "w", stdout);
	///////////////
	
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t=1;
	//cin>>t;
	REP(i,1,t) {
		solve(i);
	}
	return 0;
}	


Measured memory_bytes: 3640
#include<iostream>
using namespace std;
string a;
int n,i,s,gd;
int main()
{
	cin>>n>>a;
	for(i=0;i<n;i++)
	{
		if(a[i]=='I') gd++;
		else gd--;
		s=max(s,gd);
	}
	if(s<0) s=0;
	cout<<s<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){

  int i,n,f[44];

  scanf("%d",&n);

  f[0]=1;
  f[1]=1;

  for(i=2;i<n+2;i++){
    f[i]=f[i-2]+f[i-1];
  }


  printf("%d\n",f[n]);
   


  return 0;

}
  

    /*
makeFibonacci()
    F[0] = 1
    F[1] = 1
    for i が 2 から N まで
        F[i] = F[i-2] + F[i-1]
    */

Measured memory_bytes: 596
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"sort"
	"strconv"
	"strings"
)

func main() {

	N := oneInt()
	var vals []int

	for i := 0; i < N; i++ {
		vals = append(vals, oneInt())
	}

	index := 0
	count := 1
	for i := 0; i < len(vals); i++ {
		if vals[index] == 2 {
			fmt.Print(count)
			return
		} else {
			index = vals[index] - 1
		}
		count++
	}
	fmt.Print(-1)
}

func exp(val int) float64 {
	var temp float64
	for index := 1; index <= val; index++ {
		temp += float64(index)
	}
	return temp / float64(val)
}

func searchAbove(slice []int, target int, index int) int {
	for i := index + 1; i < len(slice); i++ {
		v := slice[i]
		if v >= target {
			return i
		}
	}
	return -1
}

var sc = bufio.NewScanner(os.Stdin)

func oneInt() int {
	var a int
	fmt.Scan(&a)
	return a
}
func oneStr() string {
	var a string
	fmt.Scan(&a)
	return a
}

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

func scanNums() (nums []int) {
	s := nextLine()
	numStr := strings.Split(s, " ")

	for _, n := range numStr {
		i, _ := strconv.Atoi(n)
		nums = append(nums, i)
	}
	return nums
}

func scanStrings() (strs []string) {
	s := nextLine()
	list := strings.Split(s, " ")
	strs = append(strs, list...)
	return strs
}

func abs(a int) int {
	return int(math.Abs(float64(a)))
}

func pow(p, q int) int {
	return int(math.Pow(float64(p), float64(q)))
}

func min(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton min() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Min(float64(res), float64(nums[i])))
	}
	return res
}

func max(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton max() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Max(float64(res), float64(nums[i])))
	}
	return res
}

func strSearch(a []string, b string) bool {
	for i := 0; i < len(a); i++ {
		if a[i] == b {
			return true
		}
	}
	return false
}

func sortAsc(a []int) []int {
	sort.Ints(a)
	return a
}

func sortDesc(a []int) []int {
	sort.Sort(sort.Reverse(sort.IntSlice(a)))
	return a
}

func gcd(a, b int) int {
	if b == 0 {
		return a
	}
	return gcd(b, a%b)
}

func lcm(a, b int) int {
	if a == 0 && b == 0 {
		return 0
	}
	return a * b / gcd(a, b)
}


Measured memory_bytes: 5504
var lines = [];
var readline = require('readline');

var rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout,
});

rl.on('line', function (x) {
    lines.push(x);
});

rl.on('close', function () {
    var N = Number(lines[0]);
    var M = Number(lines[N + 1])

    var s = [];
    var moji = {};
    for (var i = 1; i - 1 < N; i++) {
        moji[lines[i]] === undefined ? moji[lines[i]] = 1 : moji[lines[i]]++;
    }

    var t = [];
    for (var i = N + 2; i - (N + 2) < M; i++) {
        moji[lines[i]] === undefined ? moji[lines[i]] = -1 : moji[lines[i]]--;
    }

    var ans = 0;
    Object.keys(moji).forEach(value => {
        if (ans < moji[value]) { ans = moji[value] }
    });
    console.log(ans);
});

Measured memory_bytes: 7628
#include <cmath>
#include <deque>
#include <iostream>
#include <string>
#include <utility>

using namespace std;

int main()
{
    int N;
    int cnt[4] = {};
    int i;

    cin >>
        N;

    string S[N];

    for (i = 0; i < N; i++)
    {
        cin >> S[i];
        if (S[i] == "AC")
            cnt[0]++;
        if (S[i] == "WA")
            cnt[1]++;
        if (S[i] == "TLE")
            cnt[2]++;
        if (S[i] == "RE")
            cnt[3]++;
    }
    for (i = 0; i < 4; i++)
    {
        if (i == 0)
            printf("AC x ");
        if (i == 1)
            printf("WA x ");
        if (i == 2)
            printf("TLE x ");
        if (i == 3)
            printf("RE x ");
        cout << cnt[i] << endl;
    }

    return 0;
}


Measured memory_bytes: 6812