akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef pair<int, int> P;
vector<int> v[700], w[700];
int c[700];

P f(int x, int y){
    c[x]=y;
    int a=0, b=0;
    if(y==1)a++;
    if(y==2)b++;
    for(int i=0;i<w[x].size();i++){
        if(c[w[x][i]]==y){
            return P(-1, -1);
        }else if(c[w[x][i]]==0){
            P p=f(w[x][i], 3-y);
            if(p.first==-1)return P(-1, -1);
            a+=p.first;
            b+=p.second;
        }
    }
    return P(a, b);
}

int main(void){
    int n,m;
    vector<int> u;
    bool d[700][2000];
    cin>>n>>m;
    for(int i=0;i<m;i++){
        int a,b;
        cin>>a>>b;
        a--;
        b--;
        v[a].push_back(b);
        v[b].push_back(a);
    }
    for(int i=0;i<n;i++){
        v[i].push_back(i);
        v[i].push_back(n);
        sort(v[i].begin(), v[i].end());
        int p=0;
        for(int j=0;j<v[i].size();j++){
            while(p<v[i][j]){
                w[i].push_back(p);
                p++;
            }
            p=v[i][j]+1;
        }
        c[i]=0;
    }
    for(int i=0;i<n;i++){
        if(c[i]==0){
            P p=f(i, 1);
            int a=p.first, b=p.second;
            if(a==-1){
                cout<<-1<<endl;
                return 0;
            }
            u.push_back(max(a, b)-min(a, b));
        }
    }
    int r=u.size();
    for(int i=0;i<r;i++){
        for(int j=0;j<2000;j++){
            d[i][j]=false;
        }
        if(i==0){
            d[0][1000+u[0]]=d[0][1000-u[0]]=true;
        }else{
            for(int j=u[i];j<2000-u[i];j++){
                if(d[i-1][j-u[i]]||d[i-1][j+u[i]])d[i][j]=true;
            }
        }
    }
    int k=1e8;
    for(int j=0;j<2000;j++){
        if(d[r-1][j]){
            k=min(k, abs(1000-j));
        }
    }
    cout<<(n*n-2*n+k*k)/4<<endl;
}


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

class UnionFind {
	vector<int>par, sz;
public:
	UnionFind() {}
	UnionFind(int n) {
		par = sz = vector<int>(n);
		for (int i = 0; i < n; i++) {
			par[i] = i;
			sz[i] = 1;
		}
	}
	int find(int x) {
		if (par[x] == x)return x;
		return par[x] = find(par[x]);
	}
	void unite(int x, int y) {
		x = find(x); y = find(y);
		if (x == y)return;
		if (sz[x] > sz[y]) {
			par[y] = x;
			sz[x] += sz[y];
		}
		else {
			par[x] = y;
			sz[y] += sz[x];
		}
	}
	bool same(int x, int y) {
		return find(x) == find(y);
	}
	int size(int x) {
		return sz[find(x)];
	}
};

int n;ll d;
ll a[300000];
UnionFind uf;
ll mp[300000];

vector<P>loop(bool b){
	vector<P>res(n);
	rep(i,n)res[i]=P(INFL,-1),mp[i]=INFL;
	set<P>se;//コスト、連結成分
	rep(i,n){
		int id=(b?n-i-1:i);
		int p=uf.find(id);
		if(!se.empty()){
			auto it=se.begin();
			while(it!=se.end()&&it->second==p)it++;
			if(it!=se.end()){
				res[p]=min(res[p],P(d*i+it->first+a[i],it->second));
			}
		}
		ll cost=-i*d+a[i];
		if(cost<mp[p]){
			if(mp[p]!=INFL)se.erase(P(mp[p],p));
			mp[p]=cost;
			se.insert(P(cost,p));
		}
	}
	return res;
}
int main(){
	cin>>n>>d;
	rep(i,n)scanf("%lld",&a[i]);
	uf=UnionFind(n);
	ll ans=0;
	while(uf.size(0)!=n){
		auto res=loop(0);
		rep(i,n/2)swap(a[i],a[n-i-1]);
		auto res2=loop(1);
		rep(i,n/2)swap(a[i],a[n-i-1]);
		rep(i,n){
			res[i]=min(res[i],res2[i]);
			if(res[i].second==-1)continue;
			if(!uf.same(i,res[i].second)){
				uf.unite(i,res[i].second);
				ans+=res[i].first;
			}
		}
	}
	cout<<ans<<endl;
}

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

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

    Scanner cin;

    int mod = 1000000007;

    public void Do()
    {
        cin = new Scanner();
        int N = cin.nextInt();
        int W = cin.nextInt();
        int[] w = new int[N];
        int[] v = new int[N];

        for(int i=0; i<N; i++) {
            w[i] = cin.nextInt();
            v[i] = cin.nextInt();
        }

        long[] DP = new long[W+1];
        long ans = 0;

        for (int i=0; i<N; i++) {
            for (int j=W; j>=0; j--) {
                if (j + w[i] <= W) {
                    DP[j+w[i]] = Math.Max(DP[j] + v[i], DP[j+w[i]]);
                    ans = Math.Max(ans, DP[j+w[i]]);
                }
            }
        }

        Console.WriteLine(ans);
    }
}

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

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

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

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


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

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

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

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

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

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


Measured memory_bytes: 11744
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ll long long int
#define FIO ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define all(in) in.begin(), in.end()

int main(){
    FIO;
    ll n;   cin >> n;
    ll arr[n-1];
    for(ll i = 0 ; i < n-1 ; i++){
        cin >> arr[i];
    }
    ll ans = arr[n-2];
    for(ll i = n-2 ; i >= 1 ; i--){
        ans += min(arr[i], arr[i-1]);
    }
    ans += arr[0];
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
import sys


def solve(N: int, s: "List[str]", t: "List[int]", X: str):

    ans = 0
    f = 0
    for i in range(N):

        if f == 1:
            ans += t[i]
        if s[i] == X:
            f = 1
    print(ans)

    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    s = [str()] * (N)  # type: "List[str]"
    t = [int()] * (N)  # type: "List[int]"
    for i in range(N):
        s[i] = next(tokens)
        t[i] = int(next(tokens))
    X = next(tokens)  # type: str
    solve(N, s, t, X)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3316
#include <iostream>

using namespace std;

using ll =  long long;

constexpr int N_MAX = 1000;
constexpr int K_MAX = 1000;
constexpr ll MOD = 1000000007;

ll fact[N_MAX+K_MAX+1], rfact[N_MAX+K_MAX+1];

ll perm(ll n, ll k) {
    if(n-k < 0LL) return 0LL;
    return (fact[n] * rfact[n-k]) % MOD;
}

ll comb(ll n, ll k) {
    if(n-k < 0LL) return 0LL;
    return (perm(n, k) * rfact[k]) % MOD;
}

ll modpow(ll a, ll p) {
    ll ret = 1LL;
    while(p) {
        if(p & 1) {
            ret = (ret * a) % MOD;
        }
        a = (a * a) % MOD;
        p >>= 1;
    }
    return ret;
}

void init_fact(ll n) {
    fact[0] = fact[1] = 1;
    rfact[0] = rfact[1] = 1;
    for(ll i=2;i<=n;++i) {
        fact[i] = (fact[i-1] * i) % MOD;
        rfact[i] = modpow(fact[i], MOD-2);
    }
}

int main() {
    ll n, k;
    cin >> n >> k;
    init_fact(N_MAX+K_MAX);
    cout << comb(n+k-1, n) << endl;
}



Measured memory_bytes: 3136
#include <bits/stdc++.h>
#define repl(i, l, r) for (ll i = l; i < r; i++)
#define rep(i, n) repl(i, 0, n)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;

int main()
{
    ll x;
    cin >> x;
    ll k = x / 11;
    if(x % 11 == 0) {
        cout << 2 * k << endl;
    } 
    else if(x % 11 <= 6) {
        cout << 2 * k + 1 << endl;
    }
    else cout << 2 * k + 2 << endl;
    return 0;
}


Measured memory_bytes: 3636
public class Main {
    public static void main(String[] args)  {
        java.util.Scanner sc = new java.util.Scanner(System.in);
        int N = Integer.parseInt(sc.next()), H = Integer.parseInt(sc.next()), W = Integer.parseInt(sc.next());
        System.out.println((N-H+1) * (N-W+1));
    }
}

Measured memory_bytes: 23508
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue> 
#include <stack>

using namespace std;
typedef long long ll;
#define rep(i, s, e) for (int(i) = (s); (i) <= (e); ++(i))
#define all(x) x.begin(),x.end()


int main()
{
	int n; cin >> n;
	
    int o[100010] = {0};
    int e[100010] = {0};
    // vector<int> o(100010, 0), e(100010, 0);
    // vector<int> o(1e5 + 1, 0), e(1e5 + 1, 0);

	// when changing input process -> result doesn't change
    int a, b;
    for(int i=0;i<n/2;i++){
        cin>>a>>b;o[a]++;e[b]++;
    }
    /*
    rep(i, 1, n)
	{
		int x; cin >> x;
		if (i % 2 == 1) ++o[x];
		else ++e[x];
	}
    */
	int mxO, mxOId, secO, mxE, mxEId, secE;
	mxO = secO = mxE = secE = 0;
    // mxO = secO = mxE = secE = mxOId = mxEId = 0;

    // this code is ok
    // rep(i, 0, 100000){
    //     if(o[i]>mxO){
    //         secO=mxO;mxO=o[i];mxOId=i;
    //     }
    //     else if(o[i]>secO)
    //     secO=o[i];
    //     if(e[i]>mxE){
    //         secE=mxE;mxE=e[i];mxEId=i;
    //     }
    //     else if(e[i]>secE)
    //     secE=e[i];
    // }

    // bags included
    rep(i, 0, 100000){
        if(o[i]>mxO){
            secO=mxO;mxO=o[i];mxOId=i;
        }
        else if(o[i]>secO)
        secO=o[i];        
		// if (mxO < o[i])
		// {
		// 	secO = mxO;
		// 	mxO = o[i];
		// 	mxOId = i;
		// }
		// else if (secO < o[i]);
		// {
		// 	secO = o[i];
		// }
        if (mxE < e[i])
		{
			secE = mxE;
			mxE = e[i];
			mxEId = i;
		}
		else if (secE < e[i])
		{
			secE = e[i];
		}
	}

    // output process changed -> result doesn't change
    int ans;
    if(mxEId==mxOId)
    ans=max(secE,secO)+mxE;
    else
    ans=mxE+mxO;
    cout<<n-ans<<endl;
    return 0;
    /*
    if (mxOId != mxEId) cout << n - mxO - mxE << endl;
	else
	{
		int res = max(mxO + secE, secO + mxE);
		cout << n - res << endl;
	}
    */
}


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

using namespace std;

typedef pair<int, int> P;

int dp[3030];

int main() {
  int n, t, a, b;
  cin >> n >> t;
  vector<P> ab;
  for (int i = 0; i < n; i++) {
    cin >> a >> b;
    ab.emplace_back(a, b);
  }
  sort(ab.begin(), ab.end());

  for (int i = 0; i < n; i++) {
    for (int j = t - 1; 0 <= j; j--) {
      dp[min(t, j + ab[i].first)] =
          max(dp[min(t, j + ab[i].first)], dp[j] + ab[i].second);
    }
  }

  cout << dp[t] << endl;

  return 0;
}

Measured memory_bytes: 256
// This file is a "Hello, world!" in C# language by Mono for wandbox.
using System;

using System.Linq;

using System.Collections.Generic;

class Program
{
    static void Main(string[] args)
    {
            var a = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
            var b = 0;
            for (int i = a[0]; i <= a[1]; i++)
            {
                if (a[2] % i == 0) b++;
            }
            Console.WriteLine(b);
        
    }
}



Measured memory_bytes: 9640
import java.util.ArrayList;
import java.util.List;
import java.util.PriorityQueue;
import java.util.Scanner;

class Edge {
    int to;
    int cost;

    Edge(int to, int cost) {
        this.to = to;
        this.cost = cost;
    }
}

class Pair implements Comparable<Pair> {
    int dist;
    int index;

    Pair(int dist, int index) {
        this.dist = dist;
        this.index = index;
    }

    public int compareTo(Pair p2) {
        return dist - p2.dist;
    }
}
 
public class Main {
    static final int INF = 2000000000;

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

        for(int i = 0; i <= t.length() - p.length(); i++) {
            if(t.substring(i, i + p.length()).equals(p)) {
                System.out.println(i);
            }
        }
 
        sc.close();
    }
}


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

using namespace std;
using ll = long long;

#pragma region Macros
#define FOR(i, m, n) for (ll i = (ll)(m); i < (ll)(n); i++)
#define rep(i, n) FOR(i, 0, n)

template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template <class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }

template <class T> string join(const T &v, const string delim = ",")
{
    if (v.empty())
        return "";

    ostringstream res;
    res << v[0];
    for (int i = 1; i < v.size(); i++)
    {
        res << delim << v[i];
    }
    return res.str();
}

#pragma endregion Macros

// a以下の整数のうちxで割り切れるものの個数
ll f(ll a, ll x){
    if (a < 0) return 0;
    return a / x + 1;
}

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

    cout << f(b,x) - f(a-1,x) << endl;
}


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

int main(){
    int N ,M; //N スイッチ M 電球
    cin >> N >> M;
    vector<int> k(M),p(M);
    vector<vector<int>> s(M, vector<int>());
    for(int i = 0; i < M; ++i){
        cin >> k[i];
        for(int j = 0; j < k[i]; ++j){
            int tmp;
            cin >> tmp;
            s[i].push_back(tmp);
        }
    }
    for(int i = 0; i < M; ++i) cin >> p[i];

    int ans = 0;
    for(int bit = 0; bit < ( 1 << N ); ++bit){
        bool flag = true;
        bitset<10> bs(bit);
        for(int i = 0; i < M; ++i){
            int tmp=0;
            for(int j = 0; j < k[i]; ++j) tmp += bs[ s[i][j] - 1];
            if(tmp % 2== p[i]) continue;
            else {
                flag = false;
                break;
            }
        }
        if(flag) ans++;
    }

    cout << ans << endl;
}

Measured memory_bytes: 384
import sys
import numpy as np

input = sys.stdin.readline

# N 店の数
n = int(input())

# F 店の営業計画
f = [input().replace(" ", "") for i in range(n)]

# P 営業利益
p = [list(map(int, input().split())) for i in range(n)]

# 全ての時間帯で店を開けるか閉めるの組合せを考える。
# 2 ** 10 の組合せで最大の利益となるものを求める
p_max = -999999999999999
# 1日は開ける必要があるので 1から
for i in range(1, 1024):
    # 2進数にして 1：店を開ける 0：店を開けない
    f_b = format(i, '010b')
    # 10個の時間帯１パターンでの最大利益
    p_10 = 0
    for f_1, p_1 in zip(f, p):
        # 店１つ分の処理
        # お姉ちゃんの店と同時に開いている回数
        p_cnt = 0
        for j in range(10):
            # 10個の時間帯ごとの処理
            if f_1[j] == '1' and f_b[j] == '1':
                # 両方の店が開いている
                p_cnt += 1
        # 両方で営業している回数での利益
        p_10 += p_1[p_cnt]
    if p_10 > p_max:
        # 利益が大きいので入れ替え
        p_max = p_10

print(p_max)

Measured memory_bytes: 12440
#k = int(input())
#s = input()
#a, b = map(int, input().split())
#s, t = map(str, input().split())
#l = list(map(int, input().split()))
#l = [list(map(int,input().split())) for i in range(n)]
#a = [list(input()) for _ in range(n)]


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

if c >= a and c <= b:
    print("Yes")
else:
    print("No")


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

int main()
{
 int n;
  cin >> n;
  vector<int> v;
  for (int i = 0;i < n;i++)
  {
    int tmp;
    cin >> tmp;
    v.push_back(tmp);
  }
  
  int sum = 0;
  for (int i = 0;i < n; i++)
  {
   for (int j = 0; j < i; j++) 
   {
     sum += (v[i]*v[j]);
   }
  }
  cout << sum << endl;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(int(2e6))

def dfs(u, p = 0):
  vis[u] = True
  for v in g[u]:
    if not vis[v]:
      dfs(v, u)

n, m = map(int, input().split())
assert 2 <= n <= int(1e5)
assert 1 <= m <= int(1e5)
g = [list() for i in range(n + 1)]
for i in range(m):
  u, v = map(int, input().split())
  assert 1 <= u <= int(1e5)
  assert 1 <= v <= int(1e5)
  assert u < v
  g[u].append(v)
  g[v].append(u)
c = 0
vis = [False] * (n + 1)
for i in range(1, n + 1):
  if not vis[i]:
    c += 1
    dfs(i)
print(c - 1)


Measured memory_bytes: 54984
#include<iostream>
#include<iomanip>
//#include<cstdio>
#include<vector>
#include<map>
#include<queue>
#include<algorithm>
#include<cmath>
#include<cassert>
using namespace std;
typedef long long ll;
const ll P = 1e9+7;
const int COMB_MAX = 300000;
ll fact[COMB_MAX];

ll ext_gcd(ll a, ll b, ll &x, ll &y){
	if(b == 0){
		x = 1;
		y = 0;
		return a;
	}
	ll nx, ny;
	ll g = ext_gcd(b, a%b, nx, ny);
	x = ny;
	y = nx - a/b *ny;
	return g;
}

ll inv_mod(ll x, ll p){
	ll y,z;
	ext_gcd(x, p, y, z);
	return y>=0 ? y : p+(y%p);
}

ll fact_mod(ll n, ll p, ll &e){
	// n! = a * p^e
	// return = a % p
	if(n == 0){
		e = 0;
		return 1;
	}

	ll na = fact_mod(n/p, p, e);

	e += n/p;
	ll a = na * fact[n%p] % p;

	if((n/p)%2) a = a * (p-1)%p;
	return a;
}

ll comb_mod(ll n, ll m, ll p){
	ll e1,e2,e3;
	ll a1 = fact_mod(n, p, e1);
	ll a2 = fact_mod(m, p, e2);
	ll a3 = fact_mod(n-m, p, e3);

	if(e1 > e2+e3) return 0;
	else return a1*inv_mod(a2*a3%p, p)%p;
}

int main(){
	fact[0] = fact[1] = 1;
	for(int i=2; i<COMB_MAX; i++) fact[i] = fact[i-1]*i%P;

	int H, W, A, B;
	cin >> H >> W >> A >> B;

	ll all = comb_mod(W+H-2, W-1, P);
	for(int i=0; i<B; i++){
		ll x = comb_mod(i+H-A-1, i, P) * comb_mod(W-i-1+A-1, A-1, P) % P;
		all = (all + P - x) % P;
	}

	cout << all << endl;


	return 0;
}


Measured memory_bytes: 2560
n,m = map(int,input().split())
a = [0 for _ in range(m)]
b = [0 for _ in range(m)]

for i in range(m):
    a[i],b[i] = map(int,input().split())
    a[i] -= 1
    b[i] -= 1

ans = [-1 for _ in range(n-1)]
looked = [1 for _ in range(n)]
queue = [0]
looked[0] = 0
can = [[] for _ in range(n)]

for i in range(m):
    can[a[i]].append(b[i])
    can[b[i]].append(a[i])

while(len(queue)):
    now = queue.pop(0)
    for i in can[now]:
        if looked[i]:
            queue.append(i)
            looked[i] = 0
            ans[i-1] = now+1
for i in ans:
    if ans == -1:
        print("No")
        exit
print("Yes")
for i in ans:
    print(i)

Measured memory_bytes: 40544
#include <stdio.h>

int main()
{
    int x, a, b;
    scanf("%d %d %d", &x, &a, &b);
    a = x - a;
    b = x - b;

    a = a*a;
    b = b*b;


    if(a<b)
    {
        printf("A");
    }
    else
    {
        printf("B");
    }

    return 0;
}


Measured memory_bytes: 1660
#include <cstdio>
#include <vector>
#include <algorithm>
#include <queue>
#include <utility>

using namespace std;

template <class T>
using lp_queue=priority_queue<T, deque<T>, greater<T>>;

using Weight=int;
using DArray=vector<Weight>;
using DMatrix=vector<DArray>;

static const Weight INF=1<<30;

struct Edge {
    size_t src, dst;
    Weight weight;
    Edge() {}
    Edge(size_t src, size_t dst, Weight weight=1):
        src(src), dst(dst), weight(weight)
    {}
};

bool operator<(const Edge &e, const Edge &f) {
    if (e.weight != f.weight) {
        return e.weight > f.weight;
    } else {
        return e.src!=f.src? e.src<f.src : e.dst<f.dst;
    }
}

using Edges=vector<Edge>;
using Vertex=vector<Edge>;
using Graph=vector<Vertex>;

void join(Graph &g, size_t s, size_t d, Weight w=1) {
    // non-directed
    g[s].push_back(Edge(s, d, w));
    g[d].push_back(Edge(d, s, w));
}

void connect(Graph &g, size_t s, size_t d, Weight w=1) {
    // directed
    g[s].push_back(Edge(s, d, w));
}

vector<Weight> shortest_distance(const Graph &g, size_t s) {
    /* Dijkstra */
    size_t V=g.size();
    vector<Weight> d(V, INF); d[s]=0;

    lp_queue<pair<Weight, size_t>> q; q.push(make_pair(0, s));
    while (!q.empty()) {
        pair<Weight, size_t> p=q.top(); q.pop();
        size_t v=p.second;
        if (d[v] < p.first) continue;

        for (const Edge &e: g[v])
            if (d[e.dst] > d[v] + e.weight) {
                d[e.dst] = d[v] + e.weight;
                q.push(make_pair(d[e.dst], e.dst));
            }
    }
    return d;
}

int main() {
    size_t V, E, r;
    scanf("%zu %zu %zu", &V, &E, &r);

    Graph g(V);
    for (size_t i=0; i<E; ++i) {
        size_t s, t;
        Weight d;
        scanf("%zu %zu %d", &s, &t, &d);

        connect(g, s, t, d);
    }

    vector<Weight> d=shortest_distance(g, r);
    for (Weight w: d)
        if (w < INF) {
            printf("%d\n", w);
        } else {
            printf("INF\n");
        }

    return 0;
}

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

int main(){
    int a,b,t; cin >> a >> b >> t;
    int time = 0;
    int ans = 0;
    while(time <= t){
        time += a;
        ans += b;
    }
    cout << ans-b << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,x) for(int i=0; i<x;i++)
#define mod 1000000007
#define INF 10000000000
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int N;
double dp[310][310][310];
               
double res(int one,int two,int three){
  	if(dp[one][two][three] >=0) return dp[one][two][three];
	if(one==0 && two==0 && three==0) return 0.0;
  
  double ans=0.0;
  if(one>0) ans+=res(one-1,two,three)*one;
  if(two>0) ans+=res(one+1,two-1,three)*two;
  if(three>0) ans+=res(one,two+1,three-1)*three;
  ans+=N;
  ans*=1.0/(one+two+three);
  
  return dp[one][two][three] = ans;
}



int main(){
  ios::sync_with_stdio(false);
  
  cin>>N;
  
  int a[N];
  int one=0,two=0,three=0;
  
  rep(i,N){
    cin>>a[i];
    if(a[i]==1) one++;
    if(a[i]==2) two++;
    if(a[i]==3) three++;
  }
  memset(dp,-1,sizeof(dp));
  
  cout<<fixed<<setprecision(10)<<res(one,two,three);
  
}

Measured memory_bytes: 233088
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define printVec(v) printf("{"); for (const auto& i : v) { std::cout << i << ", "; } printf("}\n");
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
//Get the highest value and key from a map.
template<typename KeyType, typename ValueType>
std::pair<KeyType,ValueType> get_max( const std::map<KeyType,ValueType>& x ) {
  using pairtype=std::pair<KeyType,ValueType>;
  return *std::max_element(x.begin(), x.end(), [] (const pairtype & p1, const pairtype & p2) {
        return p1.second < p2.second;
  });
}
using namespace std;
using P = pair<int,int>;
using ll = long long;
const ll INF = 1LL<<60;

int main() {
  int h1, h2, m1, m2, k;
  cin >> h1 >> m1 >> h2 >> m2 >> k;

  int limitm = (h2 - h1) * 60 + (m2 - m1);
  cout << limitm - k << endl;
  return 0;
}


Measured memory_bytes: 3604
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        
        Scanner sc = new Scanner(System.in);
        int cityNum = sc.nextInt();
        int roadNum = sc.nextInt();
        
        int[] ownNum = new int[cityNum];
        
        for(int i=0 ; i< (roadNum*2); i++){
            int cityName = sc.nextInt();
            ownNum[cityName-1]++;
        }
        
        for(int i=0; i< cityNum ; i++){
            System.out.println(ownNum[i]);
        }
    }
}

Measured memory_bytes: 21844
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<queue>

using namespace std;
using ll = long long;

#define INF 100000

bool is_in_field(int y, int x, int h, int w){
  return (y >= 0 && y < h && x >= 0 && x < w);
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int ti = clock();
  // start-----------------------------------------------
  int h, w;
  cin >> h >> w;
  vector<vector<char>> s(h, vector<char>(w));
  vector<vector<int>> f(h, vector<int>(w, INF));
  for(int i = 0; i < h; i++){
    for(int j = 0; j < w; j++){
      cin >> s[i][j];
    }
  }
  f[0][0] = (s[0][0] == '#') ? 1 : 0;
  for(int i = 0; i < h; i++){
    for(int j = 0; j < w; j++){
      int a = INF, b = INF;
      if(is_in_field(i-1, j, h, w)){
        a = f[i-1][j];
        if(s[i][j] == '#' && s[i][j] != s[i-1][j]) a++;
      }
      if(is_in_field(i, j-1, h, w)){
        b = f[i][j-1];
        if(s[i][j] == '#' && s[i][j] != s[i][j-1]) b++;
      }
      f[i][j] = min({f[i][j], a, b});
    }
  }

  cout << f[h-1][w-1] << endl;

  // end-----------------------------------------------
  // cerr << 1.0 * (clock() - ti) / CLOCKS_PER_SEC << endl;
}


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

using namespace std;
#define ll long long
#define cinf(n,x) for(int i=0;i<(n);i++) cin >> x[i];
#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)
const ll mod = 1e9 + 7;

int main (){
    
    ll a,b,x;
    cin >> a >> b >> x;
    ll count = 0;
    if(a % x == 0){
        count++;
    }
    count += b/x - a/x;
    cout << count << endl;



    

    return 0;
}

Measured memory_bytes: 256
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;
import std.bigint;


void main()
{
  auto n = readln.chomp.to!int;
  auto w = readln.chomp.split.to!(int[]);
  int s1, s2;
  auto d = int.max;
  s2 = w.sum;
  foreach (i; 0..n) {
    s1 += w[i];
    s2 -= w[i];
    d = min(d, abs(s1 - s2));
  }
  d.writeln;
}


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

using namespace std;

const int p = 1e9 + 7;

int h, l;
int P[maxn];
int ans;
int a[maxn][2];
int sk[maxn], top;

void dfs1(int i, int sum){
	sum = 1ll * sum * i % p;
	if(i >= l){
		sk[++top] = i = l + P[i - l + 1] - 1;
		sum = 1ll * sum * i % p;
		int x = i & 1;
		i >>= 1;
		while(i){
			sum = 1ll * sum * i % p;
			a[i][x] = (a[i][x] + sum) % p;
			x = i & 1, i >>= 1;
		}
		return;
	}else{
		dfs1(i << 1, sum), dfs1(i << 1 | 1, sum);
	}
}

void dfs2(int i, int sum){
	sum = 1ll * sum * i % p;
	if(i >= l){
		i = l + P[i - l + 1] - 1;
		sum = 1ll * sum * i % p;
		int x = i & 1;
		i >>= 1;
		while(i){
			ans = (ans + 1ll * a[i][x ^ 1] * sum) % p;
			//printf("%d %d--\n", i, 1ll * a[i] * sum % p);
			sum = 1ll * sum * i % p;
			x = i & 1, i >>= 1;
		}
		return;
	}else{
		dfs2(i << 1, sum), dfs2(i << 1 | 1, sum);
	}
}

int main(){
	scanf("%d", &h), l = 1 << (h - 1);
	for(int i = 1;i <= l;i++) scanf("%d", &P[i]);
	for(int i = 1;i < l;i++){
		dfs1(i << 1, i), dfs2(i << 1 | 1, 1);
		while(top){
			int x = sk[top--];
			while(x) a[x >> 1][x & 1] = 0, x >>= 1;
		}
	}
	printf("%d", ans);
}

Measured memory_bytes: 5540
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc=new Scanner(System.in);
    int n=sc.nextInt();
    long a[]=new long[n];
    for(int i=0;i<n;i++)
    a[i]=sc.nextLong();
    Arrays.sort(a);
    int ans=0;
    for(int i=0;i<n-2;i++)
    {
      for(int j=i+1;j<n-1;j++)
      {
        if(a[i]==a[j])
        continue;
        int k=j+1;
        while(k<n)
        {
          if(a[k]==a[j])
          {
            k++;
            continue;
          }
          if(a[i]+a[j]>a[k])
          {
          //System.out.println(i+" "+j+" "+k);
          ans++;
          }
          else
          {
          break;
          }
          k++;
        }
      }
    }
    System.out.println(ans);
  }
}
    

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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

#define ld long double
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

/* Some Libraries */

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

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int t[3][3];
    rep(i,3)rep(j,3){
        cin>>t[i][j];
    }
    bool ng=false;
    rep(i,2){
        int d1=t[i+1][0]-t[i][0];
        int d2=t[i+1][1]-t[i][1];
        int d3=t[i+1][2]-t[i][2];
        if (!(d1==d2&&d2==d3)) ng=true;
    }
    rep(j,2){
        int d1=t[0][j+1]-t[0][j];
        int d2=t[1][j+1]-t[1][j];
        int d3=t[2][j+1]-t[2][j];
        if (!(d1==d2&&d2==d3)) ng=true;
    }
    if (ng){
        cout<<"No\n";
    }else{
        cout<<"Yes\n";
    }
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<vector>
#include<functional>
#include<iomanip>
#include<cmath>
#include<queue>
#include<limits>
#include<cassert>
#include<set>
#include<tuple>
#include<map>
#include<list>

#define PB push_back
#define ALL(a)  (a).begin(),(a).end()
#define DWN(a)  (a).begin(),(a).end(), greater<int>()
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

using namespace std;
typedef long long ll;

int main() {
	int N;
	cin >> N;
	vector<ll> a(N);
	REP(i, N) {
		cin >> a[i];
	}
	ll sum = 0;
	ll ans1 = 0;
	//偶：正、奇：負のとき
	REP(i, N) {
		sum += a[i];
		if (i % 2 == 0) {
			if (sum < 1) { //偶が正でないなら
				ans1 += 1 - sum;
				sum = 1;
			}
		}
		else {
			if (sum > -1) { //奇が負でないなら
				ans1 += 1 + sum;
				sum = -1;
			}
		}
	}
	sum = 0;
	ll ans2 = 0;
	//偶：負、奇：正のとき
	REP(i, N) {
		sum += a[i];
		if (i % 2 == 0) {
			if (sum > -1) { //偶が負でないなら
				ans2 += 1 + sum;
				sum = -1;
			}
		}
		else {
			if (sum < 1) { //奇が正でないなら
				ans2 += 1 - sum;
				sum = 1;
			}
		}
	}
	cout << min(ans1, ans2) << endl;
	return 0;
}

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

int main(void){
    int n;
    cin>>n;
    long long a_sum[n+1] = {};
    for(int i=0;i<n;i++){
        int a;
        cin>>a;
        a_sum[i+1] = a_sum[i] + a;
    }

    long long ans = abs(a_sum[n]-a_sum[1]*2);
    for(int i=2;i<n;i++){
        long long tmp = abs(a_sum[n]-a_sum[i]*2);
        ans = min(ans,tmp);
    }
    cout<<ans<<endl;

}

Measured memory_bytes: 1792
#include<stdio.h>
     
    int main(){
      char a;
      scanf("%c", &a);
     
      if((a >= 'a') && (a <= 'z')) {
        printf("a");
      }else if((a >= 'A') && (a <= 'Z')) {
        printf("A");
      }
     
      return 0;
    }




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

using namespace std;

#define scnaf scanf
#define sacnf scanf
#define sancf scanf

#define ln '\n'
#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define PERM(v) next_permutation(all(v))
#define UNIQUE(v) sort(all(v));(v).erase(unique(all(v)), v.end())
#define CIN(type, x) type x;cin >> x
#define MP(a,b) make_pair((a),(b))
#define PB(a) push_back((a))
#define P(p) cout << (p) << endl;
#define S(s) cin >> (s);
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)
#define tmax(x,y,z) max(x,max(y,z))
#define tmin(x,y,z) min(x,min(y,z))
#define fastIO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)

#define reps(i,a,b) for(int (i)=(a); (i)<(b); ++(i))
#define rep(i,n) reps(i,0,(n))
#define rreps(i,a,b) for(int (i)=(a); (i)>=(b); --(i))
#define rrep(i,n) reprt(i,n,0)

typedef long double ld;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vst;
typedef vector<bool> vb;
typedef vector<ld> vld;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vector<int> > mat;

const int MOD = 1e9 + 7;
const int INF = 1e9;
const ll INFF = 1e18;
const double EPS = 1e-9;
const double PI  = acos(-1.0);

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

void Yes(bool f) {if(f){P("Yes");}else{P("No")}}
void yES(bool f) {if(f){P("yES");}else{P("nO")}}
void Yay(bool f) {if(f){P("Yay!");}else{P(":(")}}

void ll2str(const ll &n,string &s) { stringstream stream; stream << n; stream >> s; }
void int2str(const int &n,string &s) { stringstream stream; stream << n; stream >> s; }
void str2ll(ll &n,const string &s) { stringstream stream(s); stream >> n; }
void str2int(int &n,const string &s) { stringstream stream(s); stream >> n; }

/*********TEMPLATE**********/

string N;

void str2int(ll &n,const string &s) {
  stringstream stream(s);
  stream >> n;
}

signed main() {

  S(N);

  ll num, ans;
  str2ll(num,N);

  if (1 <= num && num <= 9) {
    ans = num;
  } else {
    string tmp;
    ll2str(num+1,tmp);
    // 最上位の数が1の場合とそれ以外で分類
    if (N[0]=='1') {
      if (tmp[0]=='2') {
        ans = 1 + 9 * (N.size()-1);
      } else {
        ans = 9 * (N.size()-1);
      }
    } else {
      if (tmp[0]!=N[0]) {
        ans = N[0] - '0' + 9 * (N.size()-1);
      } else {
        ans = N[0] - '0' - 1 + 9 * (N.size()-1);
      }
    }
  }

  P(ans);

}


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

int dist[25][25];
int bfs(vector<string>& maze, int h, int w, int s_row, int s_col) {
  if (maze[s_row][s_col] == '#') return 0; 
  fill(&dist[0][0], &dist[25][0], -1);

  int ans = 0;
  dist[s_row][s_col] = 0;
  queue<pair<int, int>> que;
  que.push(make_pair(s_row, s_col));
  while (!que.empty()) {
    pair<int, int> v = que.front();
    que.pop();
    pair<int, int> dest[4] = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};
    for (auto e : dest) {
      pair<int, int> n{v.first + e.first, v.second + e.second};
      if (n.first < 0 || n.first >= h || n.second < 0 || n.second >= w) continue;
      if (maze[n.first][n.second] == '#') continue;
      if (dist[n.first][n.second] != -1) continue;
      dist[n.first][n.second] = dist[v.first][v.second] + 1;
      ans = max(ans, dist[n.first][n.second]);
      que.push(n);
    }
  }
  return ans;
}

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << setprecision(20);

  int h, w;
  cin >> h >> w;
  vector<string> maze(h);
  rep(i, h) cin >> maze[i];
  int ans = 0;
  rep(i, h) {
    rep(j, w) {
      ans = max(ans, bfs(maze, h, w, i, j));
    }
  }
  cout << ans << endl;
  return 0;
}


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

ll f(ll x) {
    ll ret = ((x + 1) / 2) % 2;
    if (x % 2 == 0) return ret^x;
    else return ret;
}

int main() {
    ll A, B; cin >> A >> B;
    if (A > 0) cout << (ll)(f(B) ^ f(A-1)) << endl;
    else cout << f(B) << endl;
    return 0;
}


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

int main(){
    int a, b, c, t;
    
    cin >> a >> b >> c;
    
    if(b < a){
        t = b;
        b = a;
        a = t;
    }
    if(c < b){
        t = b;
        b = c;
        c = t;
    }
   if(b < a){
        t = b;
        b = a;
        a = t;
    }
    
    cout << a << " " << b  << " " << c << endl;
    
    return 0;
}


Measured memory_bytes: 3068
#include<bits/stdc++.h>
 
using namespace std;
 
// Competetive Template:
typedef long long int lli;
typedef unsigned long long int ulli;
typedef long double ldb;
 
// Debugging :
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
 
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
 
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define ba  back
#define si size()
#define be begin()
#define en end()
#define le length()
#define mp make_pair 
#define mt make_tuple
#define fi first
#define se second
#define gcd __gcd
#define maxe *max_element
#define mine *min_element
#define deb debug
 
#define forz(i,n) for(long long int i=0;i<n;i++)
#define rep(i,k,n) for (lli i = k; i <= n; i++)
#define deci(n)  fixed<<setprecision(n)
#define high(n) __builtin_popcount(n)
#define parity(n) __builtin_parity(n)
#define ctz(n)  __builtin_ctz(n)
#define mod 1000000007
#define mod2 998244353
#define kira ios::sync_with_stdio(0), cin.tie(0),cout.tie(0)
 
typedef pair <lli,lli> pll;
 
 
lli countGreater(lli arr[], lli n, lli k) 
{ 
    lli l = 0; 
    lli r = n - 1; 
  
    // Stores the index of the left most element 
    // from the array which is greater than k 
    lli leftGreater = n; 
  
    // Finds number of elements greater than k 
    while (l <= r) { 
        lli m = l + (r - l) / 2; 
  
        // If mid element is greater than 
        // k update leftGreater and r 
        if (arr[m] > k) { 
            leftGreater = m; 
            r = m - 1; 
        } 
  
        // If mid element is less than 
        // or equal to k update l 
        else
            l = m + 1; 
    } 
  
    // Return the count of elements greater than k 
    return (n - leftGreater); 
} 
void solve()
{
    lli n,m;
    cin>>n>>m;
    lli ans = (n*(n-1)+m*(m-1))/2;
    cout<<ans;

}
 
int main()
{
    kira; 
 
    lli t=1; //cin>>t;
    while(t--)
    {
        solve();
    }
    
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
char encode[96][9];
char decode[32];
int main(void){
	strcpy(encode[' '],"101");
	strcpy(encode['\n'],"");
	strcpy(encode['\''],"000000");
	strcpy(encode[','],"000011");
	strcpy(encode['-'],"10010001");
	strcpy(encode['.'],"010001");
	strcpy(encode['?'],"000001");
	strcpy(encode['A'],"100101");
	strcpy(encode['B'],"10011010");
	strcpy(encode['C'],"0101");
	strcpy(encode['D'],"0001");
	strcpy(encode['E'],"110");
	strcpy(encode['F'],"01001");
	strcpy(encode['G'],"10011011");
	strcpy(encode['H'],"010000");
	strcpy(encode['I'],"0111");
	strcpy(encode['J'],"10011000");
	strcpy(encode['K'],"0110");
	strcpy(encode['L'],"00100");
	strcpy(encode['M'],"10011001");
	strcpy(encode['N'],"10011110");
	strcpy(encode['O'],"00101");
	strcpy(encode['P'],"111");
	strcpy(encode['Q'],"10011111");
	strcpy(encode['R'],"1000");
	strcpy(encode['S'],"00110");
	strcpy(encode['T'],"00111");
	strcpy(encode['U'],"10011100");
	strcpy(encode['V'],"10011101");
	strcpy(encode['W'],"000010");
	strcpy(encode['X'],"10010010");
	strcpy(encode['Y'],"10010011");
	strcpy(encode['Z'],"10010000");
	int n,i,k;
	char type[200],code[10000];
	for(i=0;i<26;i++){decode[i]='A'+i;}
	decode[26]=' ';
	decode[27]='.';
	decode[28]=',';
	decode[29]='-';
	decode[30]='\'';
	decode[31]='?';
	while(fgets(type,200,stdin)!=NULL){
		code[0]='\0';
		n=strlen(type);
		for(i=0;i<n;i++){strcat(code,encode[type[i]]);}
		n=strlen(code);
		for(i=0;i<n;i+=5){
			k=0;
			if(code[i]=='1')k+=16;
			if(code[i+1]=='1' && i+1<n)k+=8;
			if(code[i+2]=='1' && i+2<n)k+=4;
			if(code[i+3]=='1' && i+3<n)k+=2;
			if(code[i+4]=='1' && i+4<n)k+=1;
			printf("%c",decode[k]);
		}
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 524
//----------BHAVIK DIWANI(PICT_COMP)---------------
#include<bits/stdc++.h>
#define test ll t; cin>>t; while(t--)
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define mod 1000000007
#define ll long long
#define int long long
#define ull unsigned long long
#define MAX 1000005
#define pb push_back
#define mkp make_pair
#define vi vector<int>
#define pii pair<int,int>
#define endl '\n'
#define vs vector<string>
#define mii map<int,int>
#define msi map<string,int>
#define vpii vector< pair<int, int > >
#define vpsi vector< pair< string ,int > >
#define forci(p,q) for(int i=p;i<q;i++)
ll gcd(ll a,ll b){ if(b==0) return a;    return gcd(b,a%b);}
ll lcm(ll a,ll b) { return (a/gcd(a,b)*b);}
ull power(ull a, ull b) {a %= mod;  ull res = 1;  while (b > 0) { if (b & 1) res = res * a % mod;  a = a * a % mod;  b >>= 1; }  return res%mod; }
ll modmul(ll x, ll y){return (x*y)%mod;}
ll modadd(ll x, ll y){return (x+y)%mod;}
ll modsub(ll x, ll y){return (x-y+mod)%mod;}
ll fact[1000007]={0};
void facto() {fact[0]=1;fact[1]=1;for(int i=2;i<1000007;i++)fact[i]=(fact[i-1]*i)%mod;}
ll ncr(ll n,ll r) {ll res=1; res=fact[n]; res=(res*(power(fact[r],mod-2)))%mod; res=(res*(power(fact[n-r],mod-2)))%mod; return res;}
ll npr(ll n,ll r) {ll res=1; res=fact[n]; res=(res*(power(fact[n-r],mod-2)))%mod; return res;}
inline long long toint(const std::string &s) {std::stringstream ss; ss << s; long long x; ss >> x; return x;}
inline std::string tostring(long long number) {std::stringstream ss; ss << number; return ss.str();}
inline std::string tobin(long long x) {return std::bitset<63>(x).to_string();}
/*bool prime[MAX];
ull sieve(){memset(prime,true,sizeof(prime));for(ull p=2;p*p<MAX;p++){if(prime[p]==true){for(ull i=2*p;i<MAX;i+=p){prime[i]=false;}}}prime[0]=0;prime[1]=0;
}*/
/*int inv[1000001]={0};
void findinverse(){inv[1] = 1;for(int i = 2; i <=1e6 ; ++i)	inv[i] = (mod - (mod/i) * inv[mod%i] % mod) % mod;}
*/
using namespace std;
int solve()
{
	int n;
	cin>>n;
	int a[n+1];
	for(int i=1;i<=n;i++)	cin>>a[i];
	int money=1000;
	int stock=0;
	int profit=0;
	for(int i=2;i<=n;i++){
		if(a[i]>a[i-1]){
			stock=money/a[i-1];
			profit=(a[i]-a[i-1])*stock;
			money+=profit;
		}
	}
	cout<<money<<endl;
	return 0;
}
signed main()
{
	fastio;
//	test
		solve();
}







Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define all(a) 			a.begin(),a.end()
#define pb 				push_back
#define vi				vector<int>
#define vl 				vector<long long>
#define MOD 			1000000007
#define FOR(i,a,b) 		for(int i = a; i < b ; i++)
#define forn(i,n) 		for(int i = 0 ; i < n; i++)
#define br 				cout<<endl;
#define testc()			int t;cin>>t;while(t--)
#define ll				long long
#define printv(v)		FOR(i,0,v.size())cout<<v[i]<<' ';br;
#define f				first
#define s 				second
#define fast 			ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define vb 				vector<bool>

using namespace std;




int main()
{
	int n;
	cin>>n;
	cout<<(n - 2) * 180<<endl;	

	
}

Measured memory_bytes: 256
fun main(args: Array<String>) {
    val (n, m, d) = readInputLine().split(" ").map { it.toInt() }
    
    if (d == 0) {
        println((m - 1).toDouble() / n.toDouble())
    } else {
        println((m - 1).toDouble() * 2.0 * (n - d).toDouble() / n.toDouble() / n.toDouble())
    }
}

fun readInputLine(): String {
    return readLine()!!
}


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

using namespace std;

int main() {
  string S;
  cin >> S;

  int y = 700;

  if (S[0] == 'o') {
    y += 100;
  }
  if (S[1] == 'o') {
    y += 100;
  }
  if (S[2] == 'o') {
    y += 100;
  }

  cout << y << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
//#include <stack>
//#include <queue>
//#include <map>
#include <cmath>
#include <string>
//#include <sstream>
#include <iomanip>
//#include <complex>
using namespace std;

#define ll long long
#define vvi vector< vector<int> >
#define All(X) X.begin(),X.end()
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back


int map_j[1010][1010];
int map_o[1010][1010];
int map_i[1010][1010];

int main(){
	int h,w;
	ll int kk;
	cin >> h >> w >> kk;
	string st;
	char joi[1001][1001];
	REP(i,h){
		char tmp[1010];
		scanf("%s",tmp);
		REP(j,w){
			joi[i][j] = tmp[j];
		}
	}

	char hit[4] = "JOI";

	int tmp = 0;
	
		FOR(j,1,w+2){
			if(joi[0][j-1]==hit[0]) tmp++;
			map_j[1][j] = tmp;
		}
		FOR(j,2,h+2){
			tmp = 0;
			FOR(k,1,w+2){
				if(joi[j-1][k-1]==hit[0]) tmp++;
				map_j[j][k] = map_j[j-1][k]+tmp;
			}
		}
		FOR(j,1,w+2){
			if(joi[0][j-1]==hit[1]) tmp++;
			map_o[1][j] = tmp;
		}
		FOR(j,2,h+2){
			tmp = 0;
			FOR(k,1,w+1){
				if(joi[j-1][k-1]==hit[1]) tmp++;
				map_o[j][k] = map_o[j-1][k]+tmp;
			}
		}
		FOR(j,1,w+2){
			if(joi[0][j-1]==hit[2]) tmp++;
			map_i[1][j] = tmp;
		}
		FOR(j,2,h+2){
			tmp = 0;
			FOR(k,1,w+2){
				if(joi[j-1][k-1]==hit[2]) tmp++;
				map_i[j][k] = map_i[j-1][k]+tmp;
			}
		}	

	REP(i,kk){
		int x1,y1,x2,y2;
		cin >> x1 >> y1 >> x2 >> y2;
		int t[3];
		t[0] = map_j[x2][y2]+map_j[x1-1][y1-1]-map_j[x1-1][y2]-map_j[x2][y1-1];
		t[1] = map_o[x2][y2]+map_o[x1-1][y1-1]-map_o[x1-1][y2]-map_o[x2][y1-1];
		t[2] = map_i[x2][y2]+map_i[x1-1][y1-1]-map_i[x1-1][y2]-map_i[x2][y1-1];	
		cout << t[0] << " " << t[1] << " " << t[2]<<endl;
 	}
 	return 0;


}

Measured memory_bytes: 14056
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <bitset>
#include <utility>
#include <numeric>
#include <queue>
#include <stack>

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9) + 7;

int main(void) {
	int n;
	cin >> n;
	
	vector<int> a(n);
	for(int i = 0; i < n; ++i) {
		cin >> a[i];
	}
	
	bool flag = true;
	int cnt = 0;
	while( flag ) {
		flag = false;
		
		for(int i = n - 1; i >= 1; i--) {
			if( a[i] < a[i - 1] ) {
				swap(a[i], a[i - 1]);
				flag = true;
				cnt++;
			}
		}
	}
	
	for(int i = 0; i < n; ++i) {
		if( i != 0 ) cout << " ";
		cout << a[i];
	}
	
	cout << endl;
	cout << cnt << endl;
	
	return 0;
}



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

using ll=long long;
#define int ll

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

int read(){
	int i;
	scanf("%lld",&i);
	return i;
}

signed main(){
	int a,b;
	cin >> a >> b;
	if(a+b == 15) cout << "+";
	else if(a*b == 15) cout << "*";
	else cout << "x";
}

Measured memory_bytes: 256