akhauriyash/Code-Regression huggingface dataset:
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <queue>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <stdio.h>
#include <complex>
#include <cstdint>
#include <tuple>
#include <numeric>
#define M_PI       3.14159265358979323846

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define FILL(a, x) memset(a, x, sizeof(a))

//repetition
//------------------------------------------
#define FOR(i,s,n) for(int i=s;i<(int)n;++i)
#define REP(i,n) FOR(i,0,n)

const int N = 100;

struct edge {
	int to;
	int cap;
	int rev;
	edge(int _to, int _cap, int _rev) : to(_to), cap(_cap), rev(_rev) {};
};

int par[N], pare[N], possibleflow[N];
using node = vector<edge>;
using graph = vector<node>;


int aug(graph &g, int s, int t, int f) {
	memset(par, -1, sizeof(par));
	par[s] = s;
	possibleflow[s] = 1e9;
	deque<int> q;
	q.push_back(s);
	while (!q.empty()) {
		auto i = q.front();
		q.pop_front();
		for (auto &e : g[i]) {
			if (e.cap > 0 && par[e.to] == -1) {
				par[e.to] = i;
				pare[e.to] = e.rev;
				possibleflow[e.to] = min(possibleflow[i], e.cap);
				if (e.to == t) {
					auto df = possibleflow[t];
					while (par[t] != t) {
						g[t][pare[t]].cap += df;
						g[par[t]][g[t][pare[t]].rev].cap -= df;
						t = par[t];
					}
					return df;
				}
				q.push_back(e.to);
			}
		}
	}
	return 0;
}

int maximum_flow(graph &g, int s, int t) {
	int df;
	int flow = 0;
	do {
		df = aug(g, s, t, 1e9);
		flow += df;
	} while (df != 0);
	return flow;
}

void addedge(graph &g, int from, int to, int cap) {
	g[from].PB(edge(to, cap, g[to].size()));
	g[to].PB(edge(from, 0, g[from].size() - 1));
}

//http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=GRL_6_A
int main() {
	int v, e;
	scanf("%d%d", &v, &e);
	graph g(v);
	REP(i, e) {
		int x, y, z;
		scanf("%d%d%d", &x, &y, &z);
		addedge(g, x, y, z);
	}
	cout << maximum_flow(g, 0, v - 1) << endl;
	return 0;
}


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

using namespace std;
typedef long long ll;




int main()
{
    
    
    int N;
    cin>>N;
    
    if (N==1) {
        cout<<"Hello World"<<endl;
    }else{
        int A,B;
        cin >> A >>B;
        cout<<A+B<<endl;
    }
    
    return 0;
}




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

class Program
{
    public static void Main(string[] args)
    {
        int n = int.Parse(Console.ReadLine());
        int[] ns = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
        int q = int.Parse(Console.ReadLine());
        int[] qs = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();

        bool[,] res = new bool[n + 1, qs.Max() + 1];
        for (int i = 0; i <= n; i++) res[i, 0] = true;
        for (int i = 1; i <= qs.Max(); i++) res[n, i] = false;
        for (int i = n - 1; i >= 0; i--)
        {
            for (int j = 1; j < qs.Max() + 1; j++)
            {
                bool r = res[i + 1, j];
                r = (j - ns[i] >= 0)? (r || res[i + 1, j - ns[i]]): r;
                res[i, j] = r;
            }
        }
        for (int i = 0; i < q; i++) Console.WriteLine((res[0, qs[i]])? "yes": "no");
    }
}


Measured memory_bytes: 18340
#include <iostream>
#include <cstdio>
#include <vector>
#include <array>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <sstream>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <random>
#include <bitset>
#include <cassert>
#include <tuple>
#include <list>
#include <iterator>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <complex>

using namespace std;

typedef long long ll;
typedef long double ld;

template<class htpe, class cmp>
using heap = priority_queue<htpe, vector<htpe>, cmp>;

template<class htpe>
using min_heap = heap<htpe, greater<htpe> >;

template<class htpe>
using max_heap = heap<htpe, less<htpe> >;

#define mp make_pair
#define pb push_back
#define mt make_tuple
#define ff first
#define ss second

#define forn(i, n) for (int i = 0; i < ((int)(n)); ++i)
#define forrn(i, s, n) for (int i = (int)(s); i < ((int)(n)); ++i)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()

#define PYMOD(a, m) ((((a) % (m)) + (m)) % (m))

const int INF = 1791791791;
const ll INFLL = 1791791791791791791ll;
const int maxn = 112500179;
const int MOD = 1e9 + 7;

//int tpow[maxn];
unsigned char f[maxn];

int fpow(int a, int n) {
    int cur = a, ans = 1;
    while (n > 0) {
        if (n & 1)
            ans = (1ll * cur * ans) % MOD;
        cur = (1ll * cur * cur) % MOD;
        n >>= 1;
    }
    return ans;
}

int main() {
    /*
    tpow[0] = 1;
    forrn(i, 1, maxn) {
        tpow[i] = (10ll * tpow[i - 1]) % MOD;
    }*/
    forrn(i, 1, 10)
        f[i] = 1;
    forrn(i, 10, maxn) {
        f[i] = f[i / 10] + 1;
    }

    // Code here:

    int s;
    cin >> s;

    int ans = 0;

    vector<int> div;
    for (int x = 1; x * x <= s; x++) {
        if (s % x == 0) {
            div.pb(x);
            if (x * x != s)
                div.pb(s / x);
        }
    }
    sort(all(div));
    for (int d : div) {
        int n = PYMOD(fpow(10, d) - fpow(10, d - 1), MOD);
        if (d >= 9 || n >= s / d) {
            ans += n - s / d + 1;
            ans %= MOD;
        }
    }

    cerr << ans << endl;

    int l = 1, r = 1;
    int suml = 0, sumr = 0;
    /*while (sumr < s)
        sumr += f[r++];
    if (sumr == s && f[l] != f[r - 1])
        ans++;*/
    for (; r < maxn;) {
        sumr += f[r++];
        while (sumr - suml > s)
            suml += f[l++];
        if (sumr - suml == s && f[l] != f[r - 1])
            ans++;
    }

#ifdef LOCAL
    int realans = ans;
#endif

    cerr << ans << endl;

    for (int a = 9; a <= s; a++) {
        ans += ((s + a - 1) / a) - (s / (a + 1)) - 1;
    }
    ans %= MOD;
    cout << ans << endl;


#ifdef LOCAL
    for (int a = 9; a <= s; a++) {
        for (int x = 1; x * a < s; x++) {
            if ((s - a * x) % (a + 1) == 0) {
                realans++;
            }
        }
    }
    realans %= MOD;
    cout << "realans: " << realans << endl;
#endif

    return 0;
}


Measured memory_bytes: 110208
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <cmath>

using namespace std;

const int MAXN = 100 + 10;
const int MAXM = 6000 + 10;
const double eps = 1e-8;

int n, m, l, tot;
double org[MAXN];
double p[MAXN], t[MAXN], v[MAXN];
double b[MAXM], c[MAXM], tp1[MAXM], tp2[MAXM];
double C[MAXN][MAXN];

int Find(double x) {
        for (int i = 1; i <= tot; ++i)
		if (fabs(x - c[i]) < eps)
			return i;
}

double co[MAXN][MAXM];

inline int lowbit(int x) {
	return x & (-x);
}

inline void Add(int i, int x, double v) {
	if (x == 0)
		return;
	for (; x <= tot; x += lowbit(x))
		co[i][x] += v;
}

inline double Query(int i, int x) {
	double ret = 0;
	for (; x > 0; x -= lowbit(x))
		ret += co[i][x];
	return ret;
}
int main() {
	C[0][0] = 1;
	for (int i = 1; i <= 50; ++i) {
		C[i][0] = 1;
		for (int j = 1; j <= i; ++j)
			C[i][j] = C[i - 1][j - 1] + C[i - 1][j];
	}
	scanf("%d%d%d", &n, &m, &l);
	for (int i = 1; i <= n; ++i) {
		scanf("%lf%lf%lf", &p[i], &t[i], &v[i]);
		org[i] = 1.0 * l / v[i];
		p[i] = p[i] / 100;
	}
	for (int i = 1; i <= n; ++i)
		for (int j = 0; j <= m; ++j) {
			b[++tot] = -(org[i] + j * t[i]);
		}
	sort(b + 1, b + 1 + tot);
	int tmp = 0;
	for (int i = 1; i <= tot; ++i) {
		if (i == 1 || fabs(b[i] - b[i - 1]) > eps) {
			c[++tmp] = b[i];
		}
	}
	tot = tmp;
	for (int i = 1; i <= n; ++i) {
		for (int j = 0; j <= m; ++j) {
			double curs = -(org[i] + j * t[i]);
			double curp = C[m][j];
		        for (int k = 1; k <= j; ++k)
				curp *= p[i];
			for (int k = 1; k <= m - j; ++k)
				curp *= (1 - p[i]);
			int cur = Find(curs);
			Add(i, cur, curp);
		}
	}
	for (int i = 1; i <= n; ++i) {
		double ans = 0;
		for (int j = 0; j <= m; ++j) {
			double curs = -(org[i] + j * t[i]);
			double curp = C[m][j];
			for (int k = 1; k <= j; ++k)
				curp *= p[i];
			for (int k = 1; k <= m - j; ++k)
				curp *= (1 - p[i]);
			//	cout << i << ' ' << j << ' ' << curp << endl;
			int cur = Find(curs);
			for (int k = 1; k <= n; ++k) if (i != k) {
					curp *= Query(k, cur - 1);
			}
			ans += curp;
		}
		printf("%.8f\n", ans);
	}

	return 0;
}

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

int main(void){
    ll n;
    cin>>n;
    ll ans=0,m;
    cin>>m;
    for(ll i=1;i<n;++i){
        ll t;
        cin>>t;
        if(t>m){
            m=t;
        }else if(t<m){
            ans+=m-t;
        }
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 3620
//https://atcoder.jp/contests/abc046/tasks/arc062_b
#include <bits/stdc++.h>
using namespace std;
using ll=int64_t;
#define FOR(i,a,b) for(int64_t i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
int main() {
    string s; cin>>s;
    ll ans=0;
    ll g=0,p=0;
    REP(i,s.size()){
        //gのがおおくなるように
        if(s[i]=='g') {
            //p出せるなら出す
            if(p<g){
                ++p;
                ++ans;
            } else {
                ++g;
            }
        } else {
            //相手p
            //p出せるなら出す
            if(p<g){
                ++p;
            } else {
                ++g;
                --ans;
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int a[105];
int ans;
int main(void){
	string s; cin>>s;
	int ans1=0,ans2=0;
	for(int i=0;i<s.size();i++){
		if(i%2==0){
			if(s[i]=='0'){
				ans1++;
			}
		}else{
			if(s[i]=='1'){
				ans1++;
			}
		}
		if(i%2==0){
			if(s[i]=='1'){
				ans2++;
			}
		}else{
			if(s[i]=='0'){
				ans2++;
			}
		}
	}
	cout<<min(ans1,ans2)<<endl;
	
}


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

//typedef
//------------------------------------------
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<LL, LL> PLL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define PB push_back
#define MP make_pair
#define SORT(c) sort((c).begin(),(c).end())
#define COUT(x) cout<<x<<endl

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double PI = acos(-1.0);
const LL MOD = 1e9 + 7;
const ULL INF = 1e18;
const int dx[]{ 1,-1,0,0 }, dy[]{ 0,0,1,-1 };

//function
//--------------------------------------------
LL gcd(LL, LL);
bool isEven(LL);
void coutY();
void coutN();
LL ave(LL, LL);

int main() {
	int a, b; cin >> a >> b;
	cout << (a - 1) * (b - 1);
}

LL gcd(LL a, LL b) {
	if (a == 0 || b == 0)return 0;
	if (a < b)swap(a, b);
	if (a % b == 0)return b;
	else gcd(b, a % b);
}
bool isEven(LL a) {
	return !((bool)(a % 2));
}
void coutY() {
	cout << "Yes" << endl;
	return;
}
void coutN() {
	cout << "No" << endl;
	return;
}
LL ave(LL a, LL b) {
	return (a + b) / 2;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ctime>
#include <cstdlib>
#define rep(i, N) for (long i = 0; i < (N); i++)
#define swap(a, b) (a += b, b = a - b, a -= b)
using namespace std;
int main()
{
    int N;
    cin >> N;
    vector<int> a(N);

    rep(i, N)
    {
        cin >> a[i];
    }
    if (N == 1)
    {
        cout << "Yes" << endl;
    }
    else
    {
        reverse(a.begin(), a.end());
        rep(i, N - 1)
        {
            if (a[i] < a[i + 1])
            {
                a[i + 1]--;
            }
        }
        reverse(a.begin(), a.end());
        rep(i, N - 1)
        {
            if (a[i] > a[i + 1])
            {
                cout << "No" << endl;
                return 0;
            }
        }
        cout << "Yes" << endl;
    }
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
using ll = long long;
using namespace std;

string s;
int main()
{
    IOS
    cin >>s;
    cout << (s[0] == 'S' ? "Cloudy" : (s[0] == 'C' ? "Rainy" : "Sunny")) << endl;


    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define LL long long
#define REP(i,n) for(int i=0;i<(n);++i)
#define PER(i,n) for(int i=n-1;i>=0;--i)
#define REPA(i,n) for(int i=1;i<(n);++i)
#define foreach(i, n) for(auto &i:(n))
#define PII pair<int,int>
#define PLI pair<long long, int>
#define PLL pair<long long, long long>
#define MOD ((LL)1e9+7) 
#define INF ((LL)1e9+7)
#define INFLL ((LL)1e18)
#define ALL(x) (x).begin(),(x).end()
#define BIT(x) (1LL << (x))
using namespace std;
template<class t, class u> bool chmax(t &a, u b){if(a<b){a=b;return true;}return false;}
template<class t, class u> bool chmin(t &a, u b){if(a>b){a=b;return true;}return false;}

LL modpow(LL x, LL b){
	LL res = 1;
	while(b){
		if(b&1)res = res * x % MOD;
		x = x * x % MOD;
		b>>=1;
	}
	return res;
}

LL modinv(LL x){
	return modpow(x, MOD-2);
}

class union_find{
	public:
		int size;
		vector<int> parent;
		vector<int> union_size;
		union_find(int N){
			parent.resize(N);
			union_size.resize(N, 1);
			size = N;
			REP(i, N){
				parent[i] = i;
			}
		}

		int get_parent(int p){
			int d = parent[p];
			if(d == p)return p;
			return parent[p] = get_parent(d);
		}

		int get_union_size(int p){
			return union_size[get_parent(p)];
		}

		void merge(int a,int b){
			int ap = get_parent(a);
			int bp = get_parent(b);
			if(ap != bp){
				parent[bp] = ap;
				union_size[ap] += union_size[bp];
			}
		}

		int count(int lp = 0){
			vector<char> used(size, false);
			int res = 0;
			for(int i=lp;i<size;++i){
				if(!used[get_parent(parent[i])]){
					used[get_parent(parent[i])] = true;
					++res;
				}
			}
			return res;
		}

		bool is_brother(int a, int b){
			return get_parent(a) == get_parent(b);
		}
};


int main(){
	int N;
	int K, L;
	cin >> N;
	cin >> K >> L;
	union_find S(N), T(N);
	REP(i, K){
		int a, b;
		cin >> a >> b;
		--a;
		--b;
		S.merge(a, b);
	}
	REP(i, L){
		int a, b;
		cin >> a >> b;
		--a;
		--b;
		T.merge(a, b);
	}
	map<PII, int> m;
	REP(i, N){
		++m[PII(S.get_parent(i), T.get_parent(i))];
	}
	bool flag = false;
	REP(i, N){
		if(flag)cout << " ";
		flag = true;
		cout << m[PII(S.get_parent(i), T.get_parent(i))];
	}
	cout << endl;
}


Measured memory_bytes: 15104
#include <stdio.h>
#define abs(x) ((x)<0 ? -(x) : (x))
#define swap(type, x, y) do{ type t = x; x = y; y = t; }while(0)

int gojo(int a, int b){
  if(a % b == 0)
    return b;
  else
    gojo(b, a%b);
}

int main(){
  int n, x, xi;
  scanf("%d %d %d", &n, &x, &xi);
  int ans = abs(xi - x);
  for(int i=1; i<n; i++){
    scanf("%d", &xi);
    int a = ans, b = abs(xi-x);
    if(a < b)  swap(int, a, b);
    ans = gojo(a, b);
    if(ans == 1)  break;
  }

  printf("%d\n", ans);    
  return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define int long long
using namespace std;
signed main(){
    int n,k,ans=1;
    cin >> n >> k;
    REP(i,n){
        if(k < ans){
            ans += k;
        }
        else{
            ans *= 2;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import math
def py():
    print("Yes")
def pn():
    print("No")
def iin():
    x = int(input())
    return x

neko = 0
nya = 0
nuko = 0
s = input()
t = input()
if len(t)-len(s) == 1:
    if s == t[:-1]:
        py()
    else:
        pn()
else:
    pn()

Measured memory_bytes: 9048
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define vi vector<int>
#define vll vector<long long>
#define pb push_back
void solve(){
    string str;
    cin>>str;
    if(str[1]=='B')
    cout<<"ARC";
    else
    cout<<"ABC";
}
int  main(){
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t;
    //cin>>t;
	t=1;
	while(t--){
		solve();
	}
	return 0;
}

Measured memory_bytes: 3592
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <bitset>
#include <cstdio>
#include <limits>
#include <vector>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <fstream>
#include <numeric>
#include <sstream>
#include <cassert>
#include <iomanip>
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <fstream>
#define endl "\n"
#define c0 ios_base :: sync_with_stdio(0); cin.tie (0);
#define s second
#define f first
#define ll long long
#define ull unsigned ll
using namespace std;

const int MaxN = 4e5 + 17;
//const ll INF = 1e9 + 17;
//const int MOD = 1e9 + 7;
//const double eps = 1e-3;
//const double pi = 3.14159265359;



int main()
{
    #ifdef DEBUG
        freopen (".in", "r", stdin);
        freopen (".out", "w", stdout);
    #endif
    int a, b, c;
    cin >> a >> b >> c;
    a = a * 100 + b * 10 + c;
    if (a % 4 == 0)
        printf ("YES");
    else
        printf ("NO");
    return 0;
}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;
import static java.lang.System.*;
import static java.lang.Math.*;

public class Main
{
	public static void main(String []args)throws IOException
	{
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		String []s=br.readLine().split(" ");
		int a[]=new int[n];
		int min[]=new int[n];
		//boolean flag=true;
		int c=0,minval=Integer.MAX_VALUE;
		
		for(int i=0;i<n;i++)
			a[i]=Integer.parseInt(s[i]);
			
		min[0]=a[0];
		minval=a[0];
		for(int i=1;i<n;i++)
		{
			if(a[i]<minval)
			{
				minval=a[i];
				min[i]=minval;
			}	
		}
		
		for(int i=0;i<n;i++)
		{
			if(a[i]<=min[i])
				c++;
			
		}
		out.println(c);
	}
}




Measured memory_bytes: 49620
#include "bits/stdc++.h"
using namespace std;
typedef long long LL;
const LL INF = 1LL << 60;
struct edge {
	int to;
	LL cap;
	int rev;
	edge(int to, LL cap, LL rev) :to(to), cap(cap), rev(rev) {

	}
};
vector<edge> G[110];
int level[110];
int iter[110];
void add_edge(int from, int to, LL cap) {
	G[from].emplace_back(to, cap, G[to].size());
	G[to].emplace_back(from, 0, G[from].size() - 1);
}
void bfs(int s) {
	memset(level, -1, sizeof(level));
	queue<int> que;
	level[s] = 0;
	que.push(s);
	while (!que.empty()) {
		int v = que.front(); que.pop();
		for (int i = 0; i < G[v].size(); i++) {
			edge &e = G[v][i];
			if (e.cap > 0 && level[e.to] < 0) {
				level[e.to] = level[v] + 1;
				que.push(e.to);
			}
		}
	}
}
LL dfs(int v, int t, LL f) {
	if (v == t) return f;
	for (int &i = iter[v]; i < G[v].size(); i++) {
		edge &e = G[v][i];
		if (e.cap > 0 && level[v] < level[e.to]) {
			LL d = dfs(e.to, t, min(f, e.cap));
			if (d > 0) {
				e.cap -= d;
				G[e.to][e.rev].cap += d;
				return d;
			}
		}
	}
	return 0;
}
LL max_flow(int s, int t) {
	LL flow = 0;
	for (;;) {
		bfs(s);
		if (level[t] < 0) return flow;
		memset(iter, 0, sizeof(iter));
		LL f;
		while ((f = dfs(s, t, INF)) > 0) {
			flow += f;
		}
	}
}
int main() {
	int N;
	cin >> N;
	LL sum = 0;
	for (int i = 1; i <= N; i++) {
		LL a;
		cin >> a;
		if (a >= 0) {
			add_edge(i, N + 1, a);
			sum += a;
		}
		else {
			add_edge(0, i, -a);
		}
		for (int j = i * 2; j <= N; j += i) add_edge(i, j, INF);
	}
	cout << sum - max_flow(0, N + 1) << endl;
}

Measured memory_bytes: 256
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
N,K=MI()
A=[0]+LI()
c=1
turn=[-1]*(N+1)
for k in range(K):
  if turn[c]!=-1:
    T=k-turn[c]
    bias=turn[c]
    break
  turn[c]=k
  c=A[c]
else:
  print(c)
  exit()
K-=bias
K%=T
K+=bias
c=1
for k in range(K):
  c=A[c]
print(c)

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

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

  int cnt = 3;
  if(a == b) cnt--;
  if(b == c) cnt--;
  if(c == a) cnt--;

  if(cnt == 0) cnt++;

  cout << cnt << endl;

  return 0;

}



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

#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()

typedef long long ll;
typedef array<int, 3> tri;
typedef long double ld;

template <class T> istream& operator>>(istream& I, vector<T>& v) {for (T &e: v) I >> e; return I;}
template <class T> ostream& operator<<(ostream &O, const vector<T>& v) {for (const T &e: v) O << e << ' '; return O;}


unordered_map<int, int> pf(int x) {
        unordered_map<int, int> res;
        for (int d = 2; d * d <= x; d++) {
                while (x % d == 0) {
                        res[d]++;
                        x /= d;
                }
        }

        if(x > 1) res[x]++;

        return res;
}


void _main() {
        int n; cin >> n;
        unordered_map<int, int> primes;
        for (int i = 1; i <= n; i++) {
                auto p = pf(i);
                for (auto it: p) primes[it.first] += it.second;
        }

        ll ans = 1;

        for (auto it: primes) {
                (ans *= it.second + 1) %= 1000000007;
        }

        cout << ans;
}




signed main() {
        ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//        freopen("input.txt", "r", stdin);
        int _t = 1;
//        cin >> _t;
        while (_t--) _main();
        return 0;
}


Measured memory_bytes: 3656
def main():
    N = int(input())
    A = list(map(int, input().split()))
    cnt = 0
    for i in range(N):
        if A[i] < 0:
            cnt += 1
        A[i] = abs(A[i])

    A.sort()
    if cnt % 2 == 1:
        print(sum(A) - 2 * A[0])
    else:
        print(sum(A))

if __name__ == "__main__":
    main()

Measured memory_bytes: 64752
#include<bits/stdc++.h>
#define del(a,i) memset(a,i,sizeof(a))
#define ll long long
#define inl inline
#define il inl void
#define it inl int
#define ill inl ll
#define re register
#define ri re int
#define rl re ll
#define mid ((l+r)>>1)
#define lowbit(x) (x&(-x))
#define INF 0x3f3f3f3f
using namespace std;
template<class T>il read(T &x){
	int f=1;char k=getchar();x=0;
	for(;k>'9'||k<'0';k=getchar()) if(k=='-') f=-1;
	for(;k>='0'&&k<='9';k=getchar()) x=(x<<3)+(x<<1)+k-'0';
	x*=f;
}
template<class T>il _print(T x){
	if(x/10) _print(x/10);
	putchar(x%10+'0');
}
template<class T>il print(T x){
	if(x<0) putchar('-'),x=-x;
	_print(x);
}
ll mul(ll a,ll b,ll mod){long double c=1.;return (a*b-(ll)(c*a*b/mod)*mod)%mod;}
it qpow(int x,int m,int mod){
	int res=1,bas=x;
	while(m){
		if(m&1) res=(1ll*res*bas)%mod;
		bas=(1ll*bas*bas)%mod,m>>=1;
	}
	return res;
}
const int MAXN = 5e3+5,mod = 1e9+7;
int n,u,v,fac[MAXN],sz[MAXN],f[MAXN][MAXN],g[MAXN];
vector<int> G[MAXN];
il add_edge(int u,int v){
	G[u].push_back(v);
	G[v].push_back(u);
}
it add(int x,int y){return x+y>=mod?x+y-mod:x+y;}
it mul(int x,int y){return 1ll*x*y%mod;}
il inc(int &x,int y){x=add(x,y);}
il DFS(int u,int fa){
	sz[u]=1,f[u][1]=1;
	for(auto v:G[u]){
		if(v==fa) continue;
		DFS(v,u);
		for(ri i=0;i<=sz[u];++i)
			for(ri j=0;j<=sz[v];++j)
				inc(g[i+j],mul(f[u][i],f[v][j]));
		for(ri i=0;i<=sz[u]+sz[v];++i)
			f[u][i]=g[i],g[i]=0;
		sz[u]+=sz[v];
	}
	f[u][0]=0;
	for(ri i=1;i<=sz[u];++i)
		inc(f[u][0],mod-mul(f[u][i],fac[i]));
}
int main(){
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	read(n),fac[0]=1;
	for(ri i=1;i<n;++i)
		read(u),read(v),add_edge(u,v);
	for(ri i=2;i<=n;i+=2)
		fac[i]=mul(fac[i-2],i-1);
	DFS(1,0);
	print(mod-f[1][0]);
	return 0;
}

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

int convert(char c) {
    if (c == 'R') return 0;
    if (c == 'G') return 1;
    return 2;
}
int remain(char c1, char c2) {
    if ((c1 == 'R' && c2 == 'G') || (c1 == 'G' && c2 == 'R')) return 2;
    if ((c1 == 'R' && c2 == 'B') || (c1 == 'B' && c2 == 'R')) return 1;
    return 0;
}

int main() {
    int N; cin >> N;
    string S; cin >> S;
    long long cums[N][3] = {};
    long long ans = 0;

    cums[N-1][convert(S[N-1])] = 1;
    for (int i = N - 2; i >= 0; i--) {
        for (int j = 0; j < 3; j++) cums[i][j] = cums[i+1][j];
        cums[i][convert(S[i])]++;
    }

    for (int i = 0; i < N - 2; i++) {
        for (int j = i + 1; j < N - 1; j++) {
            if (S[i] == S[j]) continue;
            ans += cums[j+1][remain(S[i], S[j])];
            int k = 2 * j - i;
            if (k < N && convert(S[k]) == remain(S[i], S[j])) ans--;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3668
#include <bits/stdc++.h>
#define REP(i, e) for(int (i) = 0; (i) < (e); ++(i))
#define FOR(i, b, e) for(int (i) = (b); (i) < (e); ++(i))
#define ALL(c) (c).begin(), (c).end()
#define PRINT(x) cout << (x) << "\n"
using namespace std;
using ll = long long; using pint = pair<int, int>; using pll = pair<ll, ll>;
const long long MOD = 1000000007;

ll N, A, B, X[100010];

signed main(){
    cin >> N >> A >> B;
    REP(i, N) cin >> X[i];
    ll ans = 0;
    REP(i, N - 1){
        ans += min((X[i + 1] - X[i]) * A, B);
    }
    PRINT(ans);
    return 0;
}

Measured memory_bytes: 4408
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, core.bitop;

enum inf = 1L << 50;
enum mod = 10L^^9 + 7;

void main() {
    int n;
    scan(n);
    auto a = iota(n).map!(i => readln.split.to!(int[])).array;
    auto dp = new long[](1<<n);
    dp[0] = 1;

    foreach (s ; 1 .. 1<<n) {
        auto i = popcnt(s) - 1;
        foreach (j ; 0 .. n) {
            if (s & (1<<j) && a[i][j]) {
                dp[s] += dp[s ^ (1<<j)];
                if (dp[s] >= mod) dp[s] -= mod;
            }
        }
    }

    long ans = dp[(1<<n) - 1];
    writeln(ans);
}







void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}


void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

Measured memory_bytes: 18684
import java.util.*;

class Main {

	private static int ans[] = new int[1000];
	private static int pos;

	public static void main(String args[]){
		Scanner in = new Scanner(System.in);
		for(;;){
			int n = in.nextInt();
			if(n==0) return ;
			rec(n,n);
		}
	}
	
	private static void rec(int res, int ub){
		if(res ==0){
			for(int i=0; ; i++){
				System.out.print(ans[i] + ((ans[i+1]>0)?" ":"\n"));
				if(ans[i+1]==0) return ;
			}
		}
		for(int i=Math.min(res, ub); i>=1; i--){
			ans[pos] = i;
			pos++;
			rec(res-i, i);
			pos--;
			ans[pos] = 0;
		}
		return ;
	}
}

Measured memory_bytes: 12000
#include <iostream>
#include <vector>
#include <climits>
int main(){
	using namespace std;
	int N, i, j, k, c, tmp_cost;
	vector <vector <int> > cost;
	vector <int> dp;
	while(1){
		cin >> N;
		if (N==0) break;
		cost.resize(N);
		for (i=0;i<N;i++) cost[i].resize(N+1);
		dp.resize(1 << N);
		for(i=0;i<N;i++) for(j=0;j<=N;j++){cin >> c; cost[i][j] = c;}
		for(i=0;i<(1<<N);i++) dp[i] = INT_MAX;
		dp[0] = 0;
		for(i=0;i < (1<<N) - 1; i++){
			for (j=0;j<N;j++){
				if((i & (1<<j)) != 0) continue;
				tmp_cost = cost[j][0];
				for(k = 1; k <= N; k++){
					if ((i & 1<<(k-1)) == 0) continue;
					tmp_cost = min(tmp_cost, cost[j][k]);
				}
				k = i | (1 << j);
				dp[k] = min(dp[i] + tmp_cost, dp[k]);
			}
		}
		cout << dp[(1<<N) - 1] << endl;
	}
	return 0;
}

Measured memory_bytes: 1268
a = int(input())
b = int(input())
c = int(input())
x = int(input())
 
num = 0
for i in range(a+1):
  for j in range(b+1):
    for k in range(c+1):
      if 500 * i + 100 * j + 50 * k == x:
        num += 1
 
print(num)

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N,K,L;
template<int um> class UF {
	public:
	vector<int> par,rank,cnt;
	UF() {par=rank=vector<int>(um,0); cnt=vector<int>(um,1); for(int i=0;i<um;i++) par[i]=i;}
	void reinit() {int i; FOR(i,um) rank[i]=0,cnt[i]=1,par[i]=i;}
	int operator[](int x) {return (par[x]==x)?(x):(par[x] = operator[](par[x]));}
	int count(int x) { return cnt[operator[](x)];}
	int operator()(int x,int y) {
		if((x=operator[](x))==(y=operator[](y))) return x;
		cnt[y]=cnt[x]=cnt[x]+cnt[y];
		if(rank[x]>rank[y]) return par[x]=y;
		rank[x]+=rank[x]==rank[y]; return par[y]=x;
	}
};

UF<505050> uf1,uf2;
vector<int> V[505050];
map<pair<int,int>,int> M;

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>K>>L;
	FOR(i,K) {
		cin>>x>>y;
		uf1(x-1,y-1);
	}
	FOR(i,L) {
		cin>>x>>y;
		uf2(x-1,y-1);
	}
	FOR(i,N) M[{uf1[i],uf2[i]}]++;
	FOR(i,N) _P("%d%c",M[{uf1[i],uf2[i]}],(i==N-1)?'\n':' ');
	
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n';
	FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	solve(); return 0;
}


Measured memory_bytes: 35840
package main

import (
	"fmt"
	"sort"
)

func main() {
	var x, y, z, k int
	fmt.Scan(&x, &y, &z, &k)
	as := make([]int, x)
	for i := range as {
		fmt.Scan(&as[i])
	}
	sort.Sort(sort.Reverse(sort.IntSlice(as)))
	bs := make([]int, y)
	for i := range bs {
		fmt.Scan(&bs[i])
	}
	sort.Sort(sort.Reverse(sort.IntSlice(bs)))
	cs := make([]int, z)
	for i := range cs {
		fmt.Scan(&cs[i])
	}
	sort.Sort(sort.Reverse(sort.IntSlice(cs)))

	ans := make([]int, 0, x+y+z)
	for ia, a := range as {
		for ib, b := range bs {
			for ic, c := range cs {
				if (ia+1)*(ib+1)*(ic+1) > k {
					break
				}
				ans = append(ans, a+b+c)
			}
		}
	}
	sort.Sort(sort.Reverse(sort.IntSlice(ans)))
	for _, v := range ans[:k] {
		fmt.Println(v)
	}
}


Measured memory_bytes: 5376
// EbTech's Rust template. Thanks EbTech!
#![allow(unused_imports)]
use std::cmp::{max, min, Reverse};
use std::collections::{HashMap, HashSet};
use std::io::{self, prelude::*};
use std::str;

/*
5 2
5 -4 4 3 -5
4 3
3 -1

5 -4 4 3 -5 -> 8
5 -4 4 3 3  -> 11
5 -4 4 -1 3 -> 7
*/

struct Scanner<R> {
    reader: R,
    buf_str: Vec<u8>,
    buf_iter: str::SplitWhitespace<'static>,
}
impl<R: BufRead> Scanner<R> {
    fn new(reader: R) -> Self {
        Self {
            reader,
            buf_str: vec![],
            buf_iter: "".split_whitespace(),
        }
    }
    fn next<T: str::FromStr>(&mut self) -> T {
        loop {
            if let Some(token) = self.buf_iter.next() {
                return token.parse().ok().expect("Failed parse");
            }
            self.buf_str.clear();
            self.reader
                .read_until(b'\n', &mut self.buf_str)
                .expect("Failed read");
            self.buf_iter = unsafe {
                let slice = str::from_utf8_unchecked(&self.buf_str);
                std::mem::transmute(slice.split_whitespace())
            }
        }
    }
}

fn solve<R: BufRead, W: Write>(scan: &mut Scanner<R>, w: &mut W) {
    let n: usize = scan.next();
    let mut v = vec!(0;n);
    for i in 0..n {
        v[i] = scan.next::<u64>();
    }
    let mut cum = vec!(0;n);
    for i in 1..n {
        cum[i] = cum[i-1]+v[i];
    }
    let v = v;
    let cum = cum;

    let M = 1e9 as u64 + 7;
    let mut res = 0;
    for i in 0..n-1 {
        let f = v[i] % M;
        let sum = cum[n-1]-cum[i];
        let sum = sum%M;
        res += (sum*f)%M;
        res %= M;
    }
    writeln!(w, "{}", res);
}

fn main() {
    let (stdin, stdout) = (io::stdin(), io::stdout());
    let mut scan = Scanner::new(stdin.lock());
    let mut out = io::BufWriter::new(stdout.lock());
    // let t: u64 = scan.next();
    let t = 1;
    for _ in 0..t {
        solve(&mut scan, &mut out);
    }
}


Measured memory_bytes: 7432
n = int(input())
s = list(input())
count = 0
for i in  range(1,n):
    if s[i] =="E":
        count+=1
ans = count
for i in range(1,n):
    if s[i-1] == "W":
        count += 1
    if s[i] == "E":
        count -= 1
    if ans > count:
        ans = count
print(ans)




Measured memory_bytes: 5920
#include<bits/stdc++.h>
#define sd(a) scanf("%lld",&a)
#define int long long
using namespace std;
int n,q;
const int maxn=2e5+10;
bool vis[maxn];
int plz[maxn];
vector<int>ve[maxn];
void bfs(){
    queue<int>q;
    q.push(1);
    while(!q.empty()){
        int now=q.front();
        q.pop();
        if(vis[now])continue;
        vis[now]=true;
        for(auto i : ve[now]){
            if(!vis[i]){
                q.push(i);
                plz[i]+=plz[now];
            }

        }
    }
}
main(){
    sd(n);
    sd(q);
    memset(plz,0,sizeof(plz));
    memset(vis,false,sizeof(vis));
    for(int i=1;i<n;++i){
        int u,v;
        sd(u);
        sd(v);
        ve[u].emplace_back(v);
        ve[v].emplace_back(u);
    }
    for(int i=1;i<=q;++i){
        int p,x;
        sd(p);
        sd(x);
        plz[p]+=x;
    }
    bfs();
    for(int i=1;i<=n;++i)
        printf("%lld ",plz[i]);
    puts("");
}


Measured memory_bytes: 18032
#pragma warning(disable:4996)
//#define _CRT_NONSTDC_NO_WARNINGS
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <cstdio>
#include <cassert>
#include <cstdlib>
#include <ctype.h>
#include <limits.h>
#include <stdio.h>
#include <math.h>
#include <bitset>
#include <fstream>
#include <numeric>
#include <sstream>
#include <algorithm>
#include <string>
#include <cstring>
#include <iomanip>
#include <unordered_map>
#include <ctime>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <deque>
 
 
using namespace std;
typedef long long ll;
typedef long double ld;
                        
#define all(x)   (x).begin(), (x).end()           /*sorting STL */
#define fastio	 ios_base::sync_with_stdio(0);  cin.tie(nullptr);  cout.tie(nullptr)
 
#define TRIPmin(a, b, c) 	min(a, min(b, c))
#define TRIPmax(a, b, c)    max(a, max(b, c))
#define fillchar(a,x) 		memset(a, x, sizeof (a))
 
#define MOD		(ll)(1e9 + 7)
 
/***********************************************************************/

int main() {
    ll n; cin >> n;
    ll *a = new ll[n+10];
    for(ll i = 1; i <= n; i++) cin >> a[i];
    ll ans = 0;
    for(ll i = 2; i <= n; i++) {
        if(a[i-1] > a[i]) {
            ans += (a[i-1] - a[i]);
            a[i] = a[i-1];
        }
    }
    cout << ans;
    return 0;
}

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

int main()
{
    string T = "CODEFESTIVAL2016", S;
    cin >> S;
    int count = 0;
    rep(i, 16)
    {
        if (S[i] != T[i])
        {
            count++;
        }
    }
    cout << count << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
int a,b,i,c,d,y,z,x,e;
while(scanf("%d %d",&a,&b)!=EOF){
 if(a>=b) x=a,y=b;
 else x=b,y=a;
while(y!=0) {
 z=x%y; x=y; y=z;
 }
c=a/x;
d=b/x;
e=c*d*x;
printf("%d %d\n",x,e);
 }
return 0;}

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

#define REP(i, x, n) for (int i = x; i < (int)(n); i++)
#define rep(i, n) REP (i, 0, n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x.size())
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define uniq(x) x.erase(unique(x.begin(), x.end()), x.end())
#define F first
#define S second
#define mp make_pair
#define eb emplace_back

using namespace std;

typedef long long ll;

// const int INF = 1 << 30;
// const ll INF = 1LL << 60;
// const int MOD = 1000000007;

int main() {
  int H, W, N;
  cin >> H >> W >> N;

  map<pair<int, int>, int> cnt;

  rep (_, N) {
    int a, b;
    cin >> a >> b;
    a--; b--;

    for (int i = -1; i <= 1; i++) {
      for (int j = -1; j <= 1; j++) {
        int y = i + a;
        int x = j + b;
        if (0 < y && y < H - 1 && 0 < x && x < W - 1) {
          cnt[mp(y, x)]++;
        }
      }
    }
  }

  vector<ll> ans(10, 0);

  for (auto p : cnt) {
    ans[p.S]++;
  }

  ans[0] = 1LL * (H - 2) * (W - 2);
  REP (i, 1, 10) ans[0] -= ans[i];

  rep (i, 10) cout << ans[i] << endl;
}


Measured memory_bytes: 56448
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll ara[100005];
int main()
{
    int n;
    scanf("%d", &n);
    for(int i=0; i<n; i++)scanf("%d", &ara[i]);
    ll res= 0;
    for(int i=n-1; i>0; i--)
    {
        int p1= ara[i];
        int p2= ara[i-1];
        int x= min(ara[i-1], ara[i]);;
        res+= x;
        ara[i-1]-= x;
        ara[i]-= x;
        res+= (ara[i]/2);
        ara[i]-= ((ara[i]/2)*2);
        if(ara[i]==1 && ara[i]!=p1 && ara[i-1]!=p2)ara[i-1]++;
    }
    res+= (ara[0]/2);
    printf("%lld\n", res);
    return 0;
}


Measured memory_bytes: 1024
#include <algorithm>
#include <climits>
#include <iostream>
#include <vector>

typedef std::vector<int> vec;

inline bool power_of_2(int n) {
    return (n & (n - 1)) == 0;
}

inline int max_divisor(int n) {
    return n & -n;
}

int g(const vec& sequence) {
    int sum = 0;
    for (int i = 0; i < sequence.size(); i++) {
        sum += sequence[i];
    }

    vec table(sum + 1);
    std::fill(table.begin() + 1, table.end(), -1);
    table[0] = 0;

    sum = 0;
    for (int i = 0; i < sequence.size(); i++) {
        int x = sequence[i];
        for (int a = sum & -x; a >= 0; a -= x) {
            if (table[a] >= 0) {
                int b = a + x;
                table[b] = std::max(table[a] + 1, table[b]);
            }
        }
        sum += sequence[i];
    }

    int max = 0;
    for (int i = 1; i <= sum; i <<= 1) {
        max = std::max(max, table[i]);
    }
    return max;
}

vec extract(const vec& sequence, int k) {
    vec subsequence;
    int min = INT_MAX;
    for (int i = 0; i < sequence.size(); i++) {
        int x = sequence[i];
        if (x % k == 0 && power_of_2(x / k)) {
            subsequence.push_back(x);
            min = std::min(min, x);
        }
    }
    for (int i = 0; i < subsequence.size(); i++) {
        subsequence[i] /= min;
    }
    return subsequence;
}

void sort_and_uniq(vec& numbers) {
    std::sort(numbers.begin(), numbers.end());
    numbers.erase(std::unique(numbers.begin(), numbers.end()), numbers.end());
}

int f(const vec& sequence) {
    vec numbers;
    for (int i = 0; i < sequence.size(); i++) {
        int x = sequence[i];
        numbers.push_back(x / max_divisor(x));
    }
    sort_and_uniq(numbers);

    int max = 0;
    for (int i = 0; i < numbers.size(); i++) {
        int k = numbers[i];
        const vec& subsequence = extract(sequence, k);
        max = std::max(max, g(subsequence));
    }
    return max;
}

int main() {
    while (true) {
        int n;
        std::cin >> n;
        if (n == 0) {
            break;
        }
        vec sequence(n);
        for (int i = 0; i < n; i++) {
            std::cin >> sequence[i];
        }
        std::cout << f(sequence) << std::endl;
    }
    return 0;
}

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

int main() {
 int n;
 cin >> n;
 vector<int> p(n);
 for(int i = 0; i < n; i++) cin >> p[i];
  int ans = 0;
 for(int i = 1; i < n - 1; i++) {
  if((p[i - 1] < p[i]) && (p[i] < p[i + 1])) ans++;
  else if((p[i - 1] > p[i]) && (p[i] > p[i + 1])) ans++;
 }
 cout << ans << endl;
 return 0;
}


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

int main() {
  int N;
  cin >> N;
  vector<int> L(N);
  for (int &e : L) {
    cin >> e;
  }
  sort(L.begin(),L.end());
  
  int tri = 0;
  for (int i = 0; i < N-2; i++) {
    for (int j = i+1; j < N-1; j++) {
      auto itr = lower_bound(L.begin(), L.end(), L[i]+L[j]);
      itr--;
      tri += distance(L.begin()+j, itr);
    }
  }
  cout << tri << endl;
}

Measured memory_bytes: 256
N = int(input())
h = [int(x) for x in input().split()]
h.append(0)

dp = [float('inf')] * (N+1)
dp[0] = 0

for i in range(N-1):
    dp[i+1] = min(dp[i+1], dp[i]+abs(h[i]-h[i+1]))
    dp[i+2] = min(dp[i+2], dp[i]+abs(h[i]-h[i+2]))

print(dp[N-1])

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

#define times(n, i)      uptil(0, n, i)
#define upto(f, t, i)    for(decltype(t) _##i = (t), i = (f); i <= _##i; i++)
#define uptil(f, t, i)   for(decltype(t) _##i = (t), i = (f); i < _##i; i++)
#define downto(f, t, i)  for(decltype(t) _##i = (t), i = (f); i >= _##i; i--)
#define downtil(f, t, i) for(decltype(t) _##i = (t), i = (f); i > _##i; i--)
#define unless(c) if(!(c))
#define until(c) while(!(c))
#define loop while(true)

#define all(v) v.begin(), v.end()
#define ln << "\n"

struct line{};

template<class T> istream& operator>>(istream& in, vector<T>& v) {
    times(v.capacity(), i) in >> v[i];
    return in;
}

template<class T> const ostream& operator<<(ostream& out, const vector<T>& v) {
    times(v.size(), i) out << (i ? " " : "") << v[i];
    return out;
}

template<class T, class...U> typename enable_if<is_same<T, line>::value, string>::type next(istream& in, const U&... args) {
    string s;
    getline(in, s, args...);
    return move(s);
}

template<class T, class...U> typename enable_if<!is_same<T, line>::value, T>::type next(istream& in, const U&... args) {
    T t(args...);
    in >> t;
    return move(t);
}
template<class T, class...U> auto next(const U&... args) -> decltype(next<T>(cin)) {
    return next<T>(cin, args...);
}

template<class T> T sum(const vector<T>& v) {
    T ans = T();
    for(const T& t : v) ans += t;
    return ans;
}

template<class T> T sum(const typename vector<T>::iterator& begin, const typename vector<T>::iterator& end) {
    T ans = T();
    for(typename vector<T>::iterator t = begin; t != end; t++) ans += *t;
    return ans;
}

template<class T> T min(const vector<T>& v) {
    return *min_element(v.begin(), v.end());
}

template<class T> T min(const typename vector<T>::iterator& begin, const typename vector<T>::iterator& end) {
    return *min_element(begin, end);
}

template<class T> T max(const vector<T>& v) {
    return *max_element(v.begin(), v.end());
}

template<class T> T max(const typename vector<T>::iterator& begin, const typename vector<T>::iterator& end) {
    return *max_element(begin, end);
}

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

    int N = next<int>(), M = next<int>();

    vector<int> score(N, 0), A = next<vector<int>>(M);

    times(M, i) {
        times(N, j) {
            int B = next<int>();
            #ifdef debug
                cout << (B == A[i]);
            #endif
            if(B == A[i])
                score[j]++;
            else
                score[A[i] - 1]++;
        }
        #ifdef debug
            cout ln;
        #endif
    }

    times(N, j) cout << score[j] ln;

    return 0;
}

Measured memory_bytes: 1200
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
typedef long long ll;
#define ALL(v) v.begin(), v.end()
#define vmax(v) *max_element(ALL(v))
#define vmin(v) *min_element(ALL(v))
#define chmax(x, a) x = max(x, a)
#define chmin(x, a) x = min(x, a)

int main() {
    int H, W, A, B; cin >> H >> W >> A >> B;
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            if (j < A && i < B) cout << 1;
            else if (j >= A && i >= B) cout << 1;
            else cout << 0;
        }
        cout << endl;
    }
}


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

int main()
{
	ll n,m,l;
	cin>>n>>m>>l;
	vector<vector<ll> > g(n+1, vector<ll> (n+1, 1e16));
	vector<vector<ll> > dist(n+1, vector<ll> (n+1, 1e16));
	for(ll i=0;i<m;i++)
	{
		ll a,b,c;
		cin>>a>>b>>c;
		g[a][b]=c;
		g[b][a]=c;
		dist[a][b]=c;
		dist[b][a]=c;
	}
	for(int i=1;i<=n;i++)
	{
		g[i][i]=0;
		dist[i][i]=0;
	}
	for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++)
			for(int k=1;k<=n;k++)
				dist[j][k]=min(dist[j][k],dist[j][i]+dist[i][k]);
	// for(int i=1;i<=n;i++)
	// {
	// 	for(int j=1;j<=n;j++)
	// 		cout<<dist[i][j]<<" ";
	// 	cout<<endl;
	// }
	vector<vector<ll> > g2(n+1,vector<ll> (n+1,1e16));
	vector<vector<ll> > dist2(n+1,vector<ll> (n+1,1e16));
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=n;j++)
		{
			if(dist[i][j]<=l)
			{
				g2[i][j]=1;
				g2[j][i]=1;
				dist2[i][j]=1;
				dist2[j][i]=1;
			}
		}
	}
	for(int i=1;i<=n;i++)
	{
		g2[i][i]=0;
		dist2[i][i]=0;
	}
	for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++)
			for(int k=1;k<=n;k++)
				dist2[j][k]=min(dist2[j][k],dist2[j][i]+dist2[i][k]);
	// for(int i=1;i<=n;i++)
	// {
	// 	for(int j=1;j<=n;j++)
	// 		cout<<dist2[i][j]<<" ";
	// 	cout<<endl;
	// }
	ll q;
	cin>>q;
	while(q--)
	{
		ll s,t;
		cin>>s>>t;
		if(dist2[s][t]==1e16)
			cout<<-1<<endl;
		else
			cout<<dist2[s][t]-1<<endl;
	}
	return 0;
}

Measured memory_bytes: 3456
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int n = scan.nextInt();
        int m = scan.nextInt();
        System.out.println((n-1) * (m-1));
    }
}


Measured memory_bytes: 21844
import sys
input = sys.stdin.readline


def read():
    L, R, D = map(int, input().strip().split())
    return L, R, D


def solve(L, R, D):
    ans = 0
    for i in range(L, R+1):
        if i % D == 0:
            ans += 1
    return ans


if __name__ == '__main__':
    inputs = read()
    outputs = solve(*inputs)
    if outputs is not None:
        print("%s" % str(outputs))


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

int main() {
  int h1,m1,h2,m2,k;
  cin >> h1 >> m1>>h2>>m2>>k;
  int s1 = h1*60+m1,s2=h2*60+m2;
  int ans = s2-s1-k;
  cout << ans << endl;
  return 0;
}

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

vector<long long> G[200001];

int main(){
    long long N;
    cin >> N;
    long long A;
    for(long long i = 2; i<= N; i++){
        cin >> A;
        G[A].push_back(i);
    }
    for(long long i=1; i<=N; i++){
        cout << G[i].size() << endl;
    }
    system("pause");
    return 0;
}

Measured memory_bytes: 14600