akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define ll long long
#define dl double
using namespace std;

//***********************************************************************
int MAXNUM = 5e3+5;
vector <int>vis(MAXNUM);
vector<int> pr;
void sieve() {
	pr.push_back(2);
	for(ll i=3;i<MAXNUM;i+=2) if(!vis[i]) {
		pr.push_back(i);
		for(ll j=i*i;j<MAXNUM;j+=2*i) vis[j]=true;
	}
}
//************************************************************************

void solve()
{
    int n,k;
    cin >> n >> k;
    vector<int> v(n);
    for(int i=0;i<n;i++)
    {
        cin >> v[i];
    }
    vector <int> dp(k+1);
    dp[0]=0;
    for(int i=1;i<=k;i++)
    {
        for(int j=0;j<n;j++)
        {
            if(i-v[j]>=0 && dp[i-v[j]]==0)
            {
                dp[i]=1;
                break;
            }
            
        }
    } 
    if(dp[k]==1)
    cout << "First" << endl;
    else
    cout << "Second" << endl;
    
}


int main()
{ 
	ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
	ll t;
	//cin >> t;
	t=1;
	while(t--)
	{
		solve();
	}

	return 0;
}

Measured memory_bytes: 640
#include <stdio.h>
#include <string.h>
#include <limits.h>
#include <stdlib.h>
#include <math.h>


int main(void)
{
	long int i, j;
	long int a, b;
	long int sum;
	long int max;
	long int count;
	long int heit;
	char str[4];
	char t[4];
	
	scanf("%s%s", str, t);
	
	count = 0;
	
	for(i = 0; i < 3; i++) {
		if(str[i] == t[i]) {
			count++;
		}
	}
	
	printf("%ld\n", count);
	
	return 0;
}


Measured memory_bytes: 128
using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;
using System.Numerics;

namespace abc143
{
    class Program
    {
        static void Main(string[] args)
        {
            //Console.SetIn(new StreamReader("input.txt"));
            solve_abc143A();
        }

        public static void solve_abc143B()
        {

        }

        public static void solve_abc143A()
        {
            int[] ab = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
            int a = ab[0];
            int b = ab[1];

            Console.WriteLine(a > 2 * b ? a - 2 * b : 0);
        }
    }
}


Measured memory_bytes: 13140
N, M = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(M)]

ans = 0
ab.sort()
for i, (ai, bi) in enumerate(ab):
    if i == 0:
        l = ai
        r = bi - 1
        ans += 1
    else:
        l_tmp = max(l, ai)
        r_tmp = min(r, bi - 1)
        if l_tmp > r_tmp:
            l = ai
            r = bi - 1
            ans += 1
        else:
            l = l_tmp
            r = r_tmp

print(ans)

Measured memory_bytes: 27884
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define sz(a) a.size()
#define re return
#define all(a) a.begin(),a.end()
#define int long long
using namespace std;
const int dx[4]={-1,1,0,0};
const int dy[4]={0,0,-1,1};
int a[55],b[55],c[55],d[55];
int n,m,q;
int ans;
vector<int>into_array(int t){
	int a=1;
	vector<int>v;
	while (t){
		if (t%2)  v.pb(a);
		else  a++;
		t/=2;
	}
	re v;
}
int val(vector<int>v){
	int x=0;
	for (int i=0;i<q;i++){
		if (v[b[i]]-v[a[i]]==c[i]){
			x+=d[i];
		}
	}
	re x;
}
signed main()
{
	cin>>n>>m>>q;
	for (int i=0;i<q;i++){
		cin>>a[i]>>b[i]>>c[i]>>d[i];
		a[i]--, b[i]--;
	}
	for (int mask=0;mask<(1<<(n+m-1));mask++){
		vector<int>v=into_array(mask);
		if (sz(v)!=n)  continue;
		//for (int i=0;i<n;i++)  cout<<v[i]<<' ';cout<<'\n';
		ans=max(ans,val(v));
	}
	cout<<ans;
	re 0;
}
/*
3 4 3
1 3 3 100
1 2 2 10
2 3 2 10
*/
/*
4 6 10
2 4 1 86568
1 4 0 90629
2 3 0 90310
3 4 1 29211
3 4 3 78537
3 4 2 8580
1 2 1 96263
1 4 2 2156
1 2 0 94325
1 4 3 94328
*/

Measured memory_bytes: 3624
N, M = map(int, input().split())
AB = [list(map(int, input().split())) for i in range(M)]

class UnionFind:
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):  # 要素xが属するグループの根を返す
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):  # 要素xが属するグループと要素yが属するグループとを併合する
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.parents[x] > self.parents[y]:
            x, y = y, x
        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def same(self, x, y):  # 要素x, yが同じグループに属するかどうかを返す
        return self.find(x) == self.find(y)

    def size(self, x):  # 要素xが属するグループのサイズ（要素数）を返す
        return -self.parents[self.find(x)]

    def members(self, x):  # 要素xが属するグループに属する要素をリストで返す
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):  # すべての根の要素をリストで返す
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):  # グループの数を返す
        return len(self.roots())

    def all_group_members(self):  # {ルート要素: [そのグループに含まれる要素のリスト], ...}の辞書を返す
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):  # ルート要素: [そのグループに含まれる要素のリスト]を文字列で返す
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


uf = UnionFind(N)
for i in range(M):
    uf.union(AB[i][0] - 1, AB[i][1] - 1)
l = []
for i in range(N):
    l.append(uf.size(i))
print(max(l))


Measured memory_bytes: 124236
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
int n,m,X,Y;
int x[105],y[105];
int main(void){
    cin>>n>>m>>X>>Y;
    for(int i=0;i<n;i++){
        cin>>x[i];
    }
    for(int i=0;i<m;i++){
        cin>>y[i];
    }
    sort(x,x+n); sort(y,y+m);
    if(x[n-1]<y[0]&&x[n-1]<Y&&X<y[0]){
        cout<<"No War"<<endl;
    }else{
        cout<<"War"<<endl;
    }

}



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

int ab(int i);
int ab(int i){
  if(i>0) return i;
  else return -i;
}

int main(){
  int N,dis;
  bool fl = true;
  cin >> N;
  int t[N+1],x[N+1],y[N+1];
  t[0] = 0;
  x[0] = 0;
  y[0] = 0;
  for(int i=1;i<=N;i++){
    cin >> t[i] >> x[i] >> y[i];
    if((t[i]+x[i]+y[i])%2 == 1) fl = false;
  }
  for(int i=0;i<N;i++){
    if(fl == false) break;
    if(ab(x[i]-x[i+1]) + ab(y[i]-y[i+1])>t[i+1]-t[i]) fl = false;
  }
  if(fl == true) cout << "Yes";
  else cout << "No";
}

Measured memory_bytes: 1408
N, M = map(int, input().split())
INF = 10 ** 7
A = list()
B = list()
C = list()
d = [[INF] * N for i in range(N)]
for m in range(M):
    a, b, c = map(int, input().split())
    a -= 1
    b -= 1
    A.append(a)
    B.append(b)
    C.append(c)
    d[a][b] = c
    d[b][a] = c
for k in range(N):
    d[k][k] = 0

for k in range(N):
    for i in range(N):
        for j in range(N):
            d[i][j] = min(d[i][j], d[i][k] + d[k][j])

ans = 0
for m in range(M):
    if d[A[m]][B[m]] < C[m]:
        ans += 1

print(ans)



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

int h,w;
int done[1000][1000];
string s[1000];

bool ok(int x, int y)
{
    if (0<=x&&x<h)
        if (0<=y&&y<w)
            if (s[x][y]=='.')
                return 1;
    return 0;
}

vector<int> dx={0,0,-1,1};
vector<int> dy={-1,1,0,0};

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    int x1,y1,x2,y2,a,b,c;
    cin>>h>>w;
    cin>>x1>>y1;
    cin>>x2>>y2;
    --x1;
    --x2;
    --y1;
    --y2;
    for (int i=0;i<h;++i)
        cin>>s[i];
    deque<pair<int,pair<int,int>>> d;
    d.push_front({1,{x1,y1}});
    while (sz(d))
    {
        a=d.front().second.first;
        b=d.front().second.second;
        c=d.front().first;
        d.pop_front();
        if (done[a][b])
            continue;
        done[a][b]=c;
        //cout<<a<<" "<<b<<" "<<c<<"\n";
        for (int i=0;i<4;++i)
            if (ok(a+dx[i],b+dy[i]))
                if (!done[a+dx[i]][b+dy[i]])
                {
                    //cout<<a+dx[i]<<" "<<b+dy[i]<<", added by "<<a<<","<<b<<"\n";
                    d.push_front({done[a][b],{a+dx[i],b+dy[i]}});
                }
        for (int i=-2;i<3;++i)
            for (int j=-2;j<3;++j)
                if (abs(i)+abs(j)>1)
                    if (ok(a+i,b+j))
                        if (!done[a+i][b+j])
                        {
                            //cout<<"test "<<a+i<<" "<<b+j<<" added by "<<a<<","<<b<<"\n";
                            d.push_back({done[a][b]+1,{a+i,b+j}});
                        }
    }
    /**for (int i=0;i<h;++i)
    {
        for (int j=0;j<w;++j)
            cout<<done[i][j]<<" ";
        cout<<"\n";
    }**/
    if (done[x2][y2])
        cout<<done[x2][y2]-1;
    else
        cout<<-1;
    return 0;
}

Measured memory_bytes: 9008
#include <bits/stdc++.h>
#define mod 1000000000 + 7

using namespace std;

typedef long long ll;
typedef vector <int> vi;
typedef vector <ll> vl;
typedef pair <int, int> ii;
typedef pair <ll, ll> dl;
typedef vector <ii> vii;
typedef vector <dl> vil;
typedef vector <vi> graph;

int h, w;
char mat[1010][1010];
ll dp[1010][1010];

ll solve(int x, int y) {
  if (x == w - 1 && y == h - 1) {
    return 1;
  }
  if (dp[y][x] != -1) return dp[y][x];
  ll temp = 0;
  if (x < w - 1) {
    if (mat[y][x + 1] != '#') temp += solve(x + 1, y);
    temp %= mod;
  }
  if (y < h - 1) {
    if (mat[y + 1][x] != '#') temp += solve(x, y + 1);
    temp %= mod;
  }
  return dp[y][x] = temp;
}

int main() {
  cin >> h >> w;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      cin >> mat[i][j];
    }
  }
  for (int i = 0; i < 1010; i++) {
    for (int j = 0; j < 1010; j++) {
      dp[i][j] = -1;
    }
  }
  cout << solve(0, 0) << "\n";
  return 0;
}

Measured memory_bytes: 9344
#include <bits/stdc++.h>
#define PI 3.14159265358979323846
#define MAXINF (1e18L)
#define INF (1e9L)
#define EPS (1e-9)
#define MOD ((ll)(1e9+7))
#define REP(i, n) for(int i=0;i<int(n);++i)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define ALL(v) v.begin(),v.end()
#define FIND(v,x) (binary_search(ALL(v),(x)))
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v));reverse(ALL(v))
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define YES(n) cout<<((n)?"YES":"NO")<<endl
#define pb push_back
#define fi first
#define se second
using namespace std;
template<class A>void pr(A a){cout << (a) << endl;}
template<class A,class B>void pr(A a,B b){cout << a << " "  ;pr(b);}
template<class A,class B,class C>void pr(A a,B b,C c){cout << a << " " ;pr(b,c);}
template<class A,class B,class C,class D>void pr(A a,B b,C c,D d){cout << a << " " ;pr(b,c,d);}
template<class T> inline bool chmin(T& a, T b){return a>b ? a=b, true : false;}
template<class T> inline bool chmax(T& a, T b){return a<b ? a=b, true : false;}
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;

int lis(vector<int> &v){
    int n = v.size();
    vector<int> ans(n, INF);
    REP(i, n) *lower_bound(ALL(ans), v[i]) = v[i];
    return lower_bound(ALL(ans), INF) - ans.begin();
}

int main(void)
{
    int N;
    cin >> N;
    vector<int> P(N);
    for (int i = 0; i < N; i++) {
        cin >> P[i];
        P[i]--;
    }
    vector<int> Q(N);
    REP(i, N){
        Q[P[i]] = i;
    }

    int ans = 0;
    int s = 0;
    REP(i, N-1){
        if(Q[i] > Q[i+1]){
            s = i+1;
        }else{
            ans = max(ans, i-s+1);
        }
    }

    pr(N-ans-1);

}

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

#define LL long long
#define VI vector<int>
#define VB vector<bool>
#define VL vector<long long>
#define FOR(i,a,b) for(int i= (a); i<((int)b); ++i)
#define RFOR(i,a) for(int i=(a); i >= 0; --i)
#define FOE(i,a) for(auto i : a)
#define ALL(c) (c).begin(), (c).end()
#define RALL(c) (c).rbegin(), (c).rend()
#define DUMP(x)  cerr << #x << " = " << (x) << endl;
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v,x) (std::find(v.begin(), v.end(), x) != v.end())
#define BIT(n) (1LL<<(n))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
#define EPS 1e-14

const std::string YES = "YES";
const std::string Yes = "Yes";
const std::string NO = "NO";
const std::string No = "No";

bool inside(int y, int x, int H, int W) { return 0 <= y && y < H && 0 <= x && x < W; }

// 4近傍（右, 下, 左, 上）
const std::vector<int> dy = { 0, -1, 0, 1 };
const std::vector<int> dx = { 1, 0, -1, 0 };

using namespace std;

class CoordinateCompression {
public:
    unordered_map<long long, int> zip;    // 元の値 ->　圧縮した値
    unordered_map<int, long long> unzip;  // 圧縮した値 -> 元の値

    CoordinateCompression(const vector<long long> &v) {
        set<long long> s(v.begin(), v.end());

        int no = 0;
        for (long long x : s) {
            zip[x] = no;
//            zip[x] = x;
            unzip[no] = x;
            ++no;
        }
    }
};

class BinaryIndexedTree {
public:
    unsigned int n = 0; // (a.size() - 1)
    vector<long long> a;

    BinaryIndexedTree(unsigned int n) : n(n) {
        this->a = vector<long long>(n + 1, 0);
    }

    // sum[0, i)
    long long sum(int i) {
        assert(0 <= i && i <= this->n);

        long long s = 0;
        i -= 1;
        while (i >= 0) {
            s += this->a[i];
            i = (i & (i + 1)) - 1;
        }
        return s;
    }

    // sum[left, right)
    long long sum(int left, int right) {
        assert(left <= right);
        return this->sum(right) - this->sum(left);
    }

    // a[i] += x(0-origin)
    void add(int i, int x) {
        assert(0 <= i && i < this->n);

        while (i < this->n) {
            this->a[i] += x;
            i |= i + 1;
        }
    }
};


int solve(LL N, LL K, const vector<LL> &A) {

    vector<LL> cs(A.size() + 1, 0);
    FOR(i, 0, A.size()) {
        cs[i + 1] = cs[i] + (A[i] - K);
    }

    CoordinateCompression cc(cs);

    LL ans = 0;
    BinaryIndexedTree bit(N + 10);
    FOR(i, 0, cs.size()) {
        int x = cc.zip[cs[i]];
        ans += bit.sum(x + 1);
        bit.add(x, 1);
    }
    cout << ans << endl;
}


int main() {
    LL N, K;
    cin >> N >> K;
    vector<LL> A(N);
    FOR(i, 0, N) {
        cin >> A[i];
    }

    solve(N, K, A);
    return 0;
}

Measured memory_bytes: 29200
void main() {
	while(true) {
		auto S = rs.to!(dchar[]);
		if(S == "-") break;
		auto m = ri;
		foreach(i; 0..m) {
			auto h = ri;
			S = S[h..$] ~ S[0..h];
		}
		S.writeln;
	}
}

// ===================================

import std.stdio;
import std.string;
import std.functional;
import std.algorithm;
import std.range;
import std.traits;
import std.math;
import std.container;
import std.bigint;
import std.numeric;
import std.conv;
import std.typecons;
import std.uni;
import std.ascii;
import std.bitmanip;
import core.bitop;

T readAs(T)() if (isBasicType!T) {
	return readln.chomp.to!T;
}
T readAs(T)() if (isArray!T) {
	return readln.split.to!T;
}

T[][] readMatrix(T)(uint height, uint width) if (!isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		res[i] = readAs!(T[]);
	}
	return res;
}

T[][] readMatrix(T)(uint height, uint width) if (isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		auto s = rs;
		foreach(j; 0..width) res[i][j] = s[j].to!T;
	}
	return res;
}

int ri() {
	return readAs!int;
}

double rd() {
	return readAs!double;
}

string rs() {
	return readln.chomp;
}



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

typedef pair<int, int> P;
constexpr int IINF = INT_MAX;

vector<vector<int> > g, h;
vector<P> es;
vector<int> w, ww, deg, id;
vector<bool> in_cycle;

void dfs(int v){
    in_cycle[v] = false;
    for(auto u : g[v]){
        if(!in_cycle[u]) continue;
        deg[v]--;
        deg[u]--;
        if(deg[u]==1){
            dfs(u);
        }
    }
}

int rec(int v, int p){
    int res = 0;
    for(auto u : h[v]){
        if(u==p) continue;
        res = max(res, rec(u, v));
    }
    return res + ww[v];
}

int main() {
    int n, m;
    cin >> n >> m;
    g.resize(n);
    w.resize(n);
    deg.resize(n, 0);
    id.resize(n);
    in_cycle.resize(n, true);
    for(int i=0;i<n;i++){
        cin >> w[i];
    }
    for(int i=0;i<m;i++){
        int u, v;
        cin >> u >> v;
        u--; v--;
        g[u].push_back(v);
        g[v].push_back(u);
        deg[u]++;
        deg[v]++;
        es.push_back(P(u,v));
    }
    // 根は葉の頂点としない
    // 0 -> cycle -> 0 は必ず移動できる
    deg[0] = IINF;
    // 次数1の頂点から削る
    for(int i=1;i<n;i++){
        if(deg[i]==1){
            dfs(i);
        }
    }
    // 自由に行き来できる頂点を縮約したグラフを構築
    int num = 1;
    ww.push_back(0);
    for(int i=0;i<n;i++){
        if(in_cycle[i]){
            id[i] = 0;
            ww[0] += w[i];
        }
        else{
            id[i] = num++;
            ww.push_back(w[i]);
        }
    }
    h.resize(num);
    for(auto &e : es){
        int u = e.first, v = e.second;
        if(id[u]==id[v]) continue;
        h[id[u]].push_back(id[v]);
        h[id[v]].push_back(id[u]);
    }
    for(int i=0;i<num;i++){
        sort(h[i].begin(), h[i].end());
        h[i].erase(unique(h[i].begin(),h[i].end()),h[i].end());
    }
    // 構築したグラフは木になるので再帰で解ける
    cout << rec(id[0], -1) << endl;

    return 0;
}



Measured memory_bytes: 22476
// Last Change:                12/13/2018 23:34:35.
#include <algorithm>
#include <array>
#include <cmath>
#include <iostream>
#include <list>
#include <stack>
#include <string>
#include <vector>
using namespace std;
using ll = long long;

void LoopUntilZeroInpput() {
  int hogegegege = 0;
  while (cin >> hogegegege && hogegegege != 0) {
  }
}

int N;
ll a[50];

ll Cal(ll ans) {
  bool finish = true;
  for (int i = 0; i < N; i++) {
    if (a[i] >= N) {
      finish = false;
    }
  }
  if (finish) {
    return ans;
  }

  ll sum = 0;
  for (int i = 0; i < N; i++) {
    ll hoge = a[i] / N;
    a[i] -= hoge * N;
    sum += hoge;
    a[i] -= hoge;
  }
  for (int i = 0; i < N; i++) {
    a[i] += sum;
  }
  ans += sum;
  ans = Cal(ans);
  return ans;
}

int main() {
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> a[i];
  }
  sort(a, a + N);
  ll ans = Cal(0);
  cout << ans << endl;
}


Measured memory_bytes: 760
N = int(input())
A = [int(i) for i in input().split()]
A.insert(0,0)
A.append(0)
B = [0]*(N+1)

for i in range(1, N+2):
    B[i-1] = abs(A[i] - A[i-1])

c = sum(B)


for i in range(1, N+1):
    print(c - B[i-1]-B[i]+abs(A[i-1] -A[i+1]))

Measured memory_bytes: 14048
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b;
  cin>>a>>b;
  if(a<=b){
    cout<<"Impossible"<<endl;
    return 0;
  }
  int n=a+b;
  stack<int> y;
  for(int i=0;i<n;i++){
    if(y.empty()){
      y.push(i);
      continue;
    }
    cout<<"? "<<y.top()<<' '<<i<<endl;
    char r;
    cin>>r;
    if(r=='Y')
      y.push(i);
    else
      y.pop();
  }
  int h=y.top();
  string s;
  for(int i=0;i<n;i++){
    cout<<"? "<<h<<' '<<i<<endl;
    char r;
    cin>>r;
    s+=(r=='Y'?'1':'0');
  }
  cout<<"! "<<s<<endl;
}

Measured memory_bytes: 3764
#include <bits/stdc++.h>
using namespace std;
int main()
{
    vector<int> vec;
    int i;
    cin >> i;
    int ans;
    ans += i % 10;
    i /= 10;
    ans += i % 10;
    i /= 10;
    ans += i % 10;
    cout << ans << endl;
}

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

namespace AtCoder.Beginner093
{
    public class ABC093A
    {
        public static void Main(string[] args)
        {
            string S = Console.ReadLine();

            if(S.IndexOf("a") != -1 && S.IndexOf("b") != -1 && S.IndexOf("c") != -1)
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }
        }
    }
}

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

#define F first
#define S second
const long long mod = 1000000007;

int N;
string s;
vector<pair<int, int> > vp; // 0--F  1--T
vector<int> hor, ver;
int xf, yf, xin = 0, yin = 0, abx, aby;

const int U=6000, V = 10000;
int dp[U][V];
void initialize() {
    for(int i = 0;i < U;i++) {
        for(int j = 0;j < V;j++) {
            dp[i][j] = -1;
        }
    }
}

bool possible(int i, vector<int> &A, int sum) {
    if(i == -1 and sum == 0) {
        return true;
    }
    if(i == -1) {
        return false;
    }

    if(dp[i][sum+8000] != -1) {
        return dp[i][sum+8000];
    }

    bool ans = possible(i-1, A, sum+A[i]) || 
               possible(i-1, A, sum-A[i]);

    return dp[i][sum+8000] = ans;
}

int main() {
    cin >> s;
    N = s.size();
    cin >> xf >> yf;
    int i = 0, j = 0;
    while(j < N) {
        if(s[j] == s[i]) {j++;continue;}
        vp.push_back({s[i] == 'T', j-i});
        i = j;
    }
    vp.push_back({s[i] == 'T', j-i});

    if(vp[0].F == 0) {
        xin = vp[0].S;
        vp.erase(vp.begin());
    }
    abx = abs(xf-xin);
    aby = abs(yf-yin);

    if(vp.size() != 0 && vp[vp.size()-1].F) {
        vp.pop_back();
    }

    if(vp.size() == 0) {
        if(abx == 0 and aby == 0) {
            cout << "Yes" << endl;
        } else {
            cout << "No" << endl;
        }
        return 0;
    }

    bool hori = 1;
    for(int i = 0;i < vp.size();i += 2) {
        if(vp[i].S % 2 != 0) hori = !hori;
        if(hori) hor.push_back(vp[i+1].S);
        else ver.push_back(vp[i+1].S);
    }

    initialize();
    bool ans = possible(hor.size()-1, hor, abx);
    initialize();
    ans = ans && possible(ver.size()-1, ver, aby);

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


    return 0;
}


Measured memory_bytes: 234880
#include<iostream>
#include<stdio.h>
using namespace std;

int main(){
    int i,n;
    int a[10000];
    int max=-1000000,min=1000000;
    long sum=0;

    cin >> n;
    for (i = 0;i < n;i++) cin >> a[i];
    for (i = 0;i < n;i++){
        if(a[i]<min) min = a[i];
        if(a[i]>max) max = a[i];
        sum = sum + a[i];
    }
    cout << min << " " <<  max << " " <<  sum << endl;
    return 0;
}



Measured memory_bytes: 3124
#include<stdio.h>
int main(void)
{
	int day,A,B,C,D,amari=0,a=0,b=0;
	scanf("%d",&day);
	scanf("%d",&A);
	scanf("%d",&B);
	scanf("%d",&C);
	scanf("%d",&D);
	amari=A%C;
	if(amari!=0){
		a=A/C+1;
	}
	else 
		a=A/C;
	amari=B%D;
		if(amari!=0){
		b=B/D+1;
	}
	else 
		b=B/D;
	if(a>=b){
		printf("%d\n",day-a);
	}
	else 
		printf("%d\n",day-b);
	return 0;
}

Measured memory_bytes: 1024
# include <iostream>

using namespace std;
 
int main(){
  int N;
  cin >> N;
  int A[N-1];
  for (int i=0;i<N;i++){
  cin >> A[i];
  }
  
 int count=0;
 bool flag=true; 
 while(true){
 
    for (int i=0;i<N;i++){
      if(A[i] % 2 ==1){
        flag=false;
      }
    }
    if (! flag){
        break;
    }
    count++;
     for (int i=0;i<N;i++){
       A[i] /= 2;
     }
      
  }
  cout << count << endl;
  
}


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

int n;
double dp[310][310][310];

double rec(int i, int j, int k){
  if(dp[i][j][k]>=0)return dp[i][j][k];
  if(i==0 && j==0 && k==0)return 0.0;

  double res = 0.0;
  if(i>0)res += rec(i-1,j,k)*i;
  if(j>0)res += rec(i+1,j-1,k)*j;
  if(k>0)res += rec(i,j+1,k-1)*k;
  res += n;
  res *= 1.0/(i+j+k);

  return dp[i][j][k] = res;  
}


int main(){
  cin >> n;
  int a[n];
  int one=0,two=0,three=0;
  rep(i,n){
    cin >> a[i];
    if(a[i]==1) one++;
    else if(a[i]==2) two++;
    else three++;
  }
  //memset(dp,-1,sizeof(dp));
  rep(i,n+1)rep(j,n+1)rep(k,n+1)dp[i][j][k]=-1; // 
  cout << fixed << setprecision(10) << rec(one, two, three) << endl;

  return 0;
}

Measured memory_bytes: 227584
#include "bits/stdc++.h"
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using V = vector<int>;
using S = string;
using C = char;
//#define v(type, name, size, deff) vector<type> name(size, deff)

const double pi = 3.1415926535;

int digitsum(int n) {
	int sum = 0;
	while (n) {
		sum += n % 10;
		n /= 10;
	}
	return sum;
}

void Main()
{
    int n;
	cin >> n;
	int ans = 999999999;
	for (int i = 1; i < n; i++) {
		int a = i;
		int b = n - i;
		if (digitsum(a) + digitsum(b) < ans) {
			ans = digitsum(a) + digitsum(b);
		}
	}
	cout << ans << endl;
}

int main()
{
	std::cin.tie(nullptr);
	std::ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
	Main();
	return 0;
}

Measured memory_bytes: 3620
n,l,t = gets.split.map(&:to_i)
x = Array.new(n)
w = Array.new(n)
n.times do |i|
    x[i],w[i] = gets.split.map(&:to_i)
end
u = 0
a = 0
n.times do |i|
    next if w[i] == 2
    n.times do |j|
        next if w[j] == 1
        u += (2*t-(x[j]-x[i])%l+l-1)/l
    end
    a = i
    break
end
n.times do |i|
    x[i] += (w[i] == 1 ? t : -t)
    x[i] %= l
end
b = x[a]
x.sort!
m = x.bsearch_index{|num|num >= b}
n.times do |i|
    puts x[(m+i-u-a)%n]
end

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

using namespace std;

static const int INF = 1e9 + 7;

template<typename T>
using Vec = vector<T>;

template<typename T, typename T2>
using P = pair<T, T2>;

template<typename... Args>
using Tup = tuple<Args...>;

template<typename T>
using qp = priority_queue<T, Vec<T>, greater<T> >;

template<typename T>
using pq = priority_queue<T>;

using llong = long long;
using ullong = unsigned long long;
using uint = unsigned int;

int gcd(int x, int y)
{
	return y ? gcd(y, x % y) : x;
}

string str;

bool check(long long n) {
	return (n & (n - 1)) == 0;
}

void hawawa()
{
	int a, b;
	cin >> a >> b;
	cout << a - (b < a) << "\n";
}

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


Measured memory_bytes: 256
/*
Date: 2020/1/19.
Name: AtCoder ABC152 C "Low Elements".
*/
#include<iostream>
#include<vector>
#define REP(i,n) for(int i=0;i<(n);++i)
#define INF      (int)1e9
using namespace std;
typedef vector<int> vi;

int main(){
	int n;
	cin>>n;
	
	vi p(n);
	REP(i,n) cin>>p[i];
	
	int hoge=INF;//point.
	int cnt=0;
	REP(i,n){
		if(p[i]<hoge){
			cnt++;
			hoge=p[i];
		}
	}
	
	cout<<cnt<<endl;
}


Measured memory_bytes: 1024
package main

import (
	"fmt"
)

func main() {
	var N int
	fmt.Scan(&N)
	for n := 1; n <= N; n++ {
		res := 0

		for i := 1; i*i <= n; i++ {
			for j := 1; i*i+j*j+i*j <= n; j++ {
				for k := 1; i*i+j*j+k*k+i*j+i*k+k*j <= n; k++ {
					if i*i+j*j+k*k+i*j+i*k+k*j == n {
						res++
					}
				}
			}
		}
		fmt.Printf("%d\n", res)
	}
}


Measured memory_bytes: 1936
N=int(input())
A=list(map(int,input().split()))
gray=0
brown=0
green=0
light=0
blue=0
yellow=0
orange=0
red=0
god=0
for a in A:
  if 1<=a and a<=399 and gray==0:
    gray=1
  elif 400<=a and a<=799 and brown==0:
    brown=1
  elif 800<=a and a<=1199 and green==0:
    green=1
  elif 1200<=a and a<=1599 and light==0:
    light=1
  elif 1600<=a and a<=1999 and blue==0:
    blue=1
  elif 2000<=a and a<=2399 and yellow==0:
    yellow=1
  elif 2400<=a and a<=2799 and orange==0:
    orange=1
  elif 2800<=a and a<=3199 and red==0:
    red=1
  elif a>=3200:
    god+=1
mi=max(1,gray+brown+green+light+blue+yellow+orange+red)
ma=gray+brown+green+light+blue+yellow+orange+red+god
print(mi,ma)

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

int main() {
	string s = "MARCH";
	long long c[5] = {0};

	int n;
	cin >> n;
	rep(i, n) {
		string t;
		cin >> t;
		for (int j = 0; j < 5; j++) {
			if (t[0] == s[j]) {
				c[j]++;
			}
		}
	}

	long long ans = 0;
	for (int i = 0; i < 3; i++) {
		for (int j = i+1; j < 4; j++) {
			for (int k = j+1; k < 5; k++) {
				ans += c[i] * c[j] * c[k];
			}
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iomanip>
#include <limits>
using namespace std;
// 素因数分解
typedef pair<long long, long long> P;
vector<P> prime_factorize(long long n)
{
vector<P> res;
for (long long p = 2; p * p <= n; ++p)
{
if (n % p != 0)
continue;
int num = 0;
while (n % p == 0)
{
++num;
n /= p;
}
res.push_back(make_pair(p, num));
}
if (n != 1)
res.push_back(make_pair(n, 1));
return res;
}
// 因数分解
long long gcd(long long x, long long y)
{
  if (y == 0)
  {
    return x;
  }
  else
  {
    return gcd(y, x % y);
  }
}
const int MOD = 1000000007;
typedef long long int ll;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define rep(i, n) for (int i = 0; i < (n); i++)

int main()
{
    ll H, N;
    cin >> H >> N;
    ll sum = 0;
    rep(i,N){
        ll add;
        cin >> add;
        H -= add;
    }
    if(H<=0){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 3596
#include <stdio.h>
int gcd(int a, int b){
    while(1){
        if(a>b)a%=b;
        else b%=a;
        if(a==0)return b;
        if(b==0)return a;
    }
}
int main(void){
    int n,i,e=0,o=0,r,g=0;
    scanf("%d",&n);
    int a;
    for(i=0;i<n;i++){
        scanf("%d",&a);
        if(a==1){
            printf("1");
            return 0;
        }
        else{
            if(g)g=gcd(a,g);else g=a;
            if(a%2){
            if(a!=o&&o){o=-1;}
            else o=a;
            }
            else if(a!=e&&e){e=-1;}
            else e=a;
        }
    }
    if(g>1) r=g;
    else if(o&&e)r=1;
    else if(o==-1)r=1;
    else if(e==-1)r=2;
    else r=(e>o)?e:o;
    printf("%d",g);
}

Measured memory_bytes: 128
#include <bits/stdc++.h> 
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define size_of_array(array) (sizeof(array)/sizeof(array[0]))
#define MAX 100005
#define DEBUG 0 
#define LIMIT (LONG_MAX / 10)
#define POSITIVE_LAST_D (LONG_MAX % 10)
using ll =long long;
using namespace std;
using Graph=vector<vector<int>>;


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

    //check whether array include zero
    ll b[100000]={};
    rep(i,n){
        ll a;
        cin>>a;
        b[i]=a;
        if(a==0){
            cout<<0<<endl;
            return 0;
        }
    }
    //check the over 1e18
    ll ans=1;
    rep(i,n){
        if(b[i]<=1000000000000000000/ans){
            ans*=b[i];
        }else{
            cout<<-1<<endl;
            return 0;
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 4404
import java.io.*
import java.util.*
import java.lang.*
import java.lang.Math.*


fun solve() {
    val S = rd.readString()
    val N = S.length
    
    var ans = INF
    for (i in 0 until N) {
        val C = S[i]
        val T = S + C

        var dist = 0
        var len = 0
        for (j in 0 until N+1) {
            if (T[j] == C) {
                dist = max(dist, len)
                len = 0
            } else {
                len++
            }
        }

        ans = min(ans, dist)
    }

    println(ans)
}


//val rd = debug.Reader("agc", "016", "a", "sample-1")
val rd = Reader()


fun main(args: Array<String>) {
    try {
        var exception: Throwable? = null
        val sth = Thread(null, SolveThread(), "solveThread", 128 * 1024 * 1024)
        sth.setUncaughtExceptionHandler { _, e -> exception = e }
        sth.start(); sth.join()
        if (exception != null) throw exception!!
    } catch (e: Exception) { throw e }
}
const val MOD = 1_000_000_007L; const val INF = Int.MAX_VALUE/2; const val LINF = Long.MAX_VALUE/2
data class IntPair(val first: Int, val second: Int)
val errPrintln: (Any) -> Unit = { msg -> System.err.println(msg) }
fun rAssert(exp: Boolean, lazyMsg: () -> String = {""}) {
    if (!exp) { val msg = lazyMsg(); errPrintln("EAssert Error: $msg"); throw Error(msg) }
}
fun tAssert(exp: Boolean, lazyMsg: () -> String = {""}) {
    if (!exp) { val msg = lazyMsg(); errPrintln("TAssert Error: $msg"); Thread.sleep(3000) }
}
class SolveThread : Runnable {
    override fun run() { solve() }
}
class Reader {
    private val br = BufferedReader(InputStreamReader(System.`in`))
    val readString: () -> String = { br.readLine() }
    val readInt: () -> Int = { br.readLine().toInt() }
    val readLong: () -> Long = { br.readLine().toLong() }
    val readIntArray: () -> IntArray = { br.readLine().split(' ').map { it.toInt() }.toIntArray() }
    val readLongArray: () -> LongArray = { br.readLine().split(' ').map { it.toLong() }.toLongArray() }
    val readListInt: () -> List<Int> = { br.readLine().split(' ').map { it.toInt() } }
    val readListLong: () -> List<Long> = { br.readLine().split(' ').map { it.toLong() } }
}


Measured memory_bytes: 34600
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <iomanip>
#include <complex>
using namespace std;

//#define double long double
typedef complex<double> P;
#define rep(i, n) for (int i=0; i<(n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007
const int R = 100000;

int N;
P X[300];

int f(P x, int a, int b) {
  int ctr = 2;
  rep(i, N) {
    if (i == a || i == b) continue;
    P p = X[i];
    if (abs(x-p) <= 1.0) ctr++;
  }
  return ctr;
}

signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  while (cin >> N && N != 0) {
    rep(i, N) {
      double x, y;
      cin >> x >> y;
      X[i] = P(x, y);
    }
    int ans = 1;
    rep(i, N) {
      rep(j, i) {
        P a = X[i], b = X[j];
        P base = (a+b)/(double)2.0;
        P v = b-a;
        double d = abs(v) / 2.0;
        if (d > 1) continue;
        P h1 = ((v*P(0, +1)) / abs(v)) * sqrt(1.0-d*d);
        P h2 = ((v*P(0, -1)) / abs(v)) * sqrt(1.0-d*d);
        ans = max(ans, f(base+h1, i, j));
        ans = max(ans, f(base+h2, i, j));
      }
    }
    cout << ans << "\n";
  }
  return 0;
}

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

namespace A
{
    class Program
    {
        static void Main(string[] args)
        {
            var ABCXY = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            var A = ABCXY[0];
            var B = ABCXY[1];
            var C = ABCXY[2];
            var X = ABCXY[3];
            var Y = ABCXY[4];

            var output = double.PositiveInfinity;
            for (var numAB = 0; numAB <= Math.Max(X, Y); numAB++)
            {
                var numA = Math.Max(0, X - numAB);
                var numB = Math.Max(0, Y - numAB);

                output = Math.Min(output, numA * A + numB * B + numAB * 2 * C);
            }

            Console.WriteLine(output);
        }

        static int SumOfDigits(int x)
        {
            var sum = 0;
            while (x > 0)
            {
                sum += x % 10;
                x /= 10;
            }

            return sum;
        }
    }
}


Measured memory_bytes: 13396
#include <cmath>
#include <algorithm>
#include <cstring>
#include <cstdio>

using namespace std;

int dp[100][5000];
int const mod=100000;

int main(){
    int N,M,S;
    while(scanf("%d%d%d",&N,&M,&S)!=EOF && N|M|S){
        memset(dp,0,sizeof(dp));
        dp[0][0]=1;
        for(int i=1; i<=M; ++i){
            for(int j=N*N; j>0; --j){
                for(int k=i; k<=S; ++k){
                    dp[j][k]+=dp[j-1][k-i];
                    dp[j][k]%=mod;
                }
            }
        }

        printf("%d\n",dp[N*N][S]%mod);
    }
}

Measured memory_bytes: 2968
n = int(input())
a = [0] * n
for x in range(n):
    a[x] = list(map(int, input().split()))
# print(a)
dp = [[0 for _ in range(3)] for _ in range(n+1)]
# print(dp)
for i in range(n):
    for j in range(3):
        for k in range(3):
            if j == k:
                continue
            dp[i + 1][k] = max(dp[i + 1][k], dp[i][j] + a[i][k])
# print(dp)
print(max(dp[n]))

Measured memory_bytes: 47272
#[allow(dead_code)]
struct Utree {
    n: usize,
    par: Vec<usize>,
    rank: Vec<usize>,
    size: Vec<usize>
}

#[allow(dead_code)]
impl Utree {
    fn new(n: usize) -> Utree {
        let par: Vec<usize> = (0..n).collect();
        let rank: Vec<usize> = vec![0;n];
        let size: Vec<usize> = vec![1;n];
        Utree{n:n, par:par, rank:rank, size:size}
    }

    fn find(&mut self, x: usize) -> usize {
        if self.par[x] == x {
            x
        } else {
            let parent = {self.par[x]};
            let ret = self.find(parent);
            self.par[x] = ret;
            ret
        }
    }

    fn unite(&mut self, x: usize, y: usize) {
        let x_root = self.find(x);
        let y_root = self.find(y);
        if x_root == y_root {return;};

        if self.rank[x_root] < self.rank[y_root] {
            self.par[x_root] = y_root;
            self.size[y_root] += self.size[x_root];
        } else {
            self.par[y_root] = x_root;
            self.size[x_root] += self.size[y_root];
            if self.rank[x_root] == self.rank[y_root] {
                self.rank[x_root] += 1;
            }
        }
    }

    fn is_same(&mut self, x: usize, y: usize) -> bool {
        let x_root = self.find(x);
        let y_root = self.find(y);
        x_root == y_root
    }

    fn get_size(&mut self, x: usize) -> usize {
        let x_root = self.find(x);
        self.size[x_root]
    }
}

pub fn main() {
    use std::io::Read;
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();
    let mut iter = buf.split_whitespace();
    
    let n: usize = iter.next().unwrap().parse().unwrap();
    let m: usize = iter.next().unwrap().parse().unwrap();
    let mut a: Vec<usize> = vec![0;m];
    let mut b: Vec<usize> = vec![0;m];
    for i in 0..m {
        a[i] = iter.next().unwrap().parse::<usize>().unwrap() - 1;
        b[i] = iter.next().unwrap().parse::<usize>().unwrap() - 1;
    }

    a.reverse();
    b.reverse();

    let mut cost: u64 = n as u64 * (n as u64 - 1) / 2;
    let mut ret: Vec<u64> = vec![0;m];

    let mut utree = Utree::new(n);
    for i in 0..m {
        ret[i] = cost;
        let a_size = utree.get_size(a[i]) as u64;
        let b_size = utree.get_size(b[i]) as u64;
        if !utree.is_same(a[i], b[i]) && cost >= a_size * b_size {cost -= a_size * b_size;}
        utree.unite(a[i], b[i]);
    }
    ret.reverse();
    for i in 0..m {
        println!("{}", ret[i]);
    }
}


Measured memory_bytes: 13564
#include<stdio.h>
#include<string.h>
#include<iostream>
#include<math.h>
using namespace std;
int main()
{
    int a,b,c;
    cin>>a>>b>>c;
    int maxx=max(a,b);
    maxx=max(maxx,c);
    cout<<(a+b+c)-maxx<<endl;
    return 0;
}


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

using namespace std;

int N, M;
bool edge[700 + 10][700 + 10];
bool complementary_edge[700 + 10][700 + 100];
int color[700 + 100];
bool f = false;
bool dp[700 + 10][700 + 10];
int c1, c2;

void dfs(int pos, int bef) {
	if (color[pos] == 1)c1++;
	else c2++;
	for (int i = 0; i < N; i++) {
		if (complementary_edge[pos][i] && i != bef) {
			if (color[i] == 0) {
				color[i] = color[pos] == 1 ? 2 : 1;
				dfs(i, pos);
			}
			else {
				if ((color[pos] == 1 && color[i] == 2) || (color[pos] == 2 && color[i] == 1)) {
					//ok!
				}
				else f = true;//補グラフは二部グラフではない
			}
		}
	}
}

int main() {
	cin >> N >> M;
	for (int i = 0; i < N; i++)
		for (int j = 0; j < N; j++)
			if(i != j)
				complementary_edge[i][j] = true;

	for (int i = 0; i < M; i++) {
		int A, B;
		cin >> A >> B;
		A--, B--;
		edge[A][B] = true;
		edge[B][A] = true;
		complementary_edge[A][B] = false;
		complementary_edge[B][A] = false;
	}

	vector<pair<int, int>> connected_component;
	for (int i = 0; i < N; i++) {
		if (color[i] == 0) {
			color[i] = 1;
			dfs(i, -1);
			connected_component.push_back(make_pair(c1, c2));
			c1 = 0, c2 = 0;
		}
	}
	
	if (f) {
		cout << -1 << endl;
		return 0;
	}

	dp[0][0] = true;
	for (int i = 0; i < connected_component.size(); i++) {
		for (int j = 0; j <= N; j++) {
			if (dp[i][j]) {
				if (j + connected_component[i].first <= N)
					dp[i + 1][j + connected_component[i].first] = true;
				if (j + connected_component[i].second <= N)
					dp[i + 1][j + connected_component[i].second] = true;
			}
		}
	}
	int ans = 1145141919;
	for (int i = 0; i <= N; i++) {
		if(dp[connected_component.size()][i])
			ans = min(ans, i * (i - 1) / 2 + (N - i) * (N - i - 1) / 2);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1792
#include<stdio.h>

int main(void)
{
  int a;
  int b;
  int c;
  
  scanf("%d", &a);
  scanf("%d", &b);
  scanf("%d", &c);
  
  a = a - b;
  c = c - a;
  if(c >= 0){
  printf("%d", c);
  }
  else{
    printf("0");
  }
    
  
  return 0;
}
  
  
  

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

using namespace std;

int main()
{
  long long int n;
  cin>>n;
  long long int a[100000];
  for(long long int i=0;i<n;i++)
    cin>>a[i];
  int c=0;
  int m=0;
  for(long long int i=1;i<n;i++)
  {
   if(a[i]<=a[i-1])
      c++;
      else
      {
          if(m<c)
            m=c;
          c=0;

      }

 if(c>m)
    m=c;



  }
  cout<<m;


    return 0;
}






Measured memory_bytes: 1024
import sys
sys.setrecursionlimit(10 ** 6 + 100)
n, m = map(int, input().split())

memo = [-1] * (10 ** 6 + 100)

g = [[] for i in range(n + 1)]

for i in range(m):
    x, y = map(int, input().split())
    g[y].append(x)


def dfs(i):
    if memo[i] != -1:
        return memo[i]
    if not g[i]:
        return 0
    else:
        memo[i] = max(dfs(v) for v in g[i]) + 1
        return memo[i]


for i in range(1, n+1):
    dfs(i)

print(max(memo))


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

int main()
{
	int absolute_total=0;
  	int n,m;
  	cin>>n;
  	vector<int> times(n+4,0);
	for(int i=0 ; i<n ; ++i)
    {
    	cin>>times[i];
      	absolute_total+=times[i];
    }
  	cin>>m;
  	int index,time;	
  	for(int i=0 ; i<m ; ++i)
    {
    	cin>>index>>time;
    	--index;
      	cout<<(absolute_total-times[index]+time)<<endl;
    }
  	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    long a = sc.nextLong();
    double b = sc.nextDouble();
    long B = (long)(b * (double)100 + 0.01);
    System.out.println((a * B) / (long)100);
  }
}

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

typedef long long ll;
using namespace std;

template<typename T>
struct BinaryIndexedTree {
    vector<T> data;

    BinaryIndexedTree(int sz) {
        data.assign(++sz, 0);
    }

    T sum(int k) {
        T ret = 0;
        for (++k; k > 0; k -= k & -k) ret += data[k];
        return (ret);
    }

    void add(int k, T x) {
        for (++k; k < data.size(); k += k & -k) data[k] += x;
    }

    int search_small(int index) {
        int x = sum(index);

        int ok = -1;
        int ng = index;
        while (abs(ok - ng) > 1) {
            int mid = ok + (ng - ok) / 2;

            if (sum(mid) < x)ok = mid;
            else ng = mid;
        }

        return ok;
    }

    int search_big(int index) {
        int x = sum(index);

        int ok = data.size() - 1;
        int ng = index;
        while (abs(ok - ng) > 1) {
            int mid = ok + (ng - ok) / 2;
            int count = sum(mid);
            if (count > x)ok = mid;
            else ng = mid;
        }

        return ok;
    }

    void print() {
        for (int i = 0; i < data.size(); i++) {
            if (i > 0)cout << " ";
            cout << sum(i);
        }
        cout << endl;
    }
};

int main() {
    int n;
    cin >> n;
    vector<int> pos(n + 1);
    for (int i = 1; i <= n; i++) {
        int tmp;
        cin >> tmp;
        pos[tmp] = i;
    }

    BinaryIndexedTree<int> bit(n + 1);
    ll ret = 0;
    for (int i = 1; i <= n; i++) {
        int nowpos = pos[i];
        ll s1 = bit.search_small(nowpos);
        ll b1 = bit.search_big(nowpos);

        ret += i * (b1 - nowpos) * (nowpos - s1 - 1);
        bit.add(nowpos, 1);
    }

    cout << ret << endl;
    return 0;
}

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

using namespace std;

const int MX = 200000;

bool cmp(const pair<int, int>& A, const pair<int, int>& B) {
	return A.second * 1LL * B.first <= B.second * 1LL * A.first;
}

bool check(pair<int, int>& A, pair<int, int>& B) {
	return cmp(make_pair(A.first + B.first, A.second + B.second), A);
}

long long ans = 0;

vector<pair<int, int>> combine(vector<pair<int, int>>& A, vector<pair<int, int>>&& B) {
	vector<pair<int, int>> res;
	for (size_t i = 0, j = 0, onesA = 0, onesB = 0; i < A.size() || j < B.size();) {
		pair<int, int> cur;
		if (i == A.size() || (j < B.size() && cmp(B[j], A[i]))) {
			ans += onesA * (long long)(B[j].first);
			onesB += B[j].second;
			cur = B[j];
			j++;
		}
		else {
			ans += onesB * (long long)(A[i].first);
			onesA += A[i].second;
			cur = A[i];
			i++;
		}
		
		if (res.empty() == false && check(res.back(), cur)) {
			res.back().first += cur.first;
			res.back().second += cur.second;
		}
		else {
			res.push_back(cur);
		}
	}
	
	return res;
}

vector<int> G[MX];
int a[MX];

vector<pair<int, int>> dfs(int v) {
	vector<pair<int, int>> res;
	for (int u : G[v]) res = combine(res, dfs(u));
	if (a[v] == 1) {
		for (auto& x : res) ans += x.first;
		if (res.empty()) res.emplace_back(0, 0);
		res[0].second++;
	}
	else {
		vector<pair<int, int>> vec;
		vec.emplace_back(1, 0);
		move(res.begin(), res.end(), back_inserter(vec));
		swap(res, vec);
	}
	
	return combine(res, {});
}

int main() {
	int n;
	ignore = scanf("%d", &n);
	for (int i = 1, x; i < n; i++) {
		ignore = scanf("%d", &x);
		G[x - 1].push_back(i);
	}
	
	for (int i = 0; i < n; i++) ignore = scanf("%d", a + i);
	
	dfs(0);
	
	printf("%lld\n", ans);
	
	return 0;
}


Measured memory_bytes: 43264
#include <iostream>
#include <vector>
#include <numeric>
#include <string>

using namespace std;

int a, b;

void solve() {
	cin >> a >> b;
	if (a <= b) {
		for (int i = 0; i < b; i++) {
			cout << a;
		}
	}
	else {
		for (int i = 0; i < a; i++) {
			cout << b;
		}
	}
}

int main() {
	solve();
	return 0;
}

Measured memory_bytes: 256
/* ex3_3 melo */
#include <stdio.h>
int main(void){
    int N, K;
    int L=0;
    scanf("%d %d",&N,&K);
    while(N!=0){
        N=N/K;
        L=L+1;
    }
    printf("%d\n",L);
    return 0;
}

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

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

Node treeSearch(Node u, int k){
    if(u == NIL || k == u->key)return u;

    if(k < u->key)return treeSearch(u->left,k);

    else return treeSearch(u->right,k);
    
}

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x != NIL){
    y = x;
    if(z->key < x->key) x = x->left;
    else x = x->right;
  }

  z->parent = y;

  if(y == NIL)root = z;

  else if(z->key < y->key)y->left = z;

  else y->right = z;
}

void inorder(Node u){
  if(u != NIL){
    inorder(u->left);
    printf(" %d",u->key);
    inorder(u->right);
  }

}
void preorder(Node u){
  if(u==NULL) return;
    printf(" %d",u->key);
    preorder(u->left);
    preorder(u->right);
}


int main(){
  int n, i, x;
  char string[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", string);
    if ( string[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( string[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if ( string[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    }
  }

  return 0;
}



Measured memory_bytes: 20448