akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
 
int main(){
    int n,m,l;
    scanf("%d%d%d",&n,&m,&l);
    int a[n][m],b[m][l];
    long c[n][l];

    for(int i = 0; i < n; i++){
        for(int j = 0; j < l; j++){
            c[i][j] = 0;
        }
    }

    for(int i = 0; i < n; i++){
        for(int j = 0; j < m; j++){
            scanf("%d",&a[i][j]);
        }
    }

    for(int i = 0; i < m; i++){
        for(int j = 0; j < l; j++){
            scanf("%d",&b[i][j]);
        }
    }

    for(int i = 0; i < n; i++){
        for(int j = 0; j < l; j ++){
            c[i][j] = 0;
            for(int k = 0; k < m; k++){
                c[i][j] = c[i][j] + a[i][k] * b[k][j];
            }
        }
    }

    for(int i = 0; i < n; i++){
        for(int j =0; j < l; j++){
            printf("%ld",c[i][j]);
            if(j == l - 1){
            printf("\n");
            }
            else{
            printf(" ");
            }
        }
    }

    return 0;
}


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

using namespace std;

uint64_t powmod(uint64_t a, uint64_t e, uint64_t MOD) {
  uint64_t ret = 1;
  while (true) {
    if (e & 1ULL) {
      ret = ret * a % MOD;
    }
    e >>= 1;
    if (e == 0) return ret;
    a = a * a % MOD;
  }
}

uint64_t solve(const int N, vector<int>& D, const uint64_t MOD) {
  if (D[0] != 0) return 0;
  if (N == 1) return 1;

  // Now N >= 2.
  sort(D.begin(), D.end());
  auto start = D.begin() + 1;
  if (*start != 1) return 0;

  uint64_t ret = 1;
  uint64_t prev_count = 1;
  for (int depth = 1; start != D.end(); ++depth) {
    uint64_t count = 0;
    auto i = start;
    for (; i != D.end() && *i == depth; ++i) {
      ++count;
    }
    start = i;
    if (count == 0) {
      return 0;
    }
    ret = ret * powmod(prev_count, count, MOD) % MOD;
    prev_count = count;
  }
  return ret;
}

int main() {
  int N;
  cin >> N;
  vector<int> D(N);
  for (int i = 0; i < N; ++i) {
    cin >> D[i];
  }
  cout << solve(N, D, 998244353ULL) << endl;
  return 0;
}


Measured memory_bytes: 768
//sppsfver - 20.08.2020
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using pll = pair <ll, ll>;
const int MAX = 1e5+5;

ll n;

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

	cin >> n;
	cout << (n < 30 ? "No" : "Yes") << endl;
	return 0;
}


Measured memory_bytes: 3604
#include <stdio.h>
#include <math.h>

int main(int argc, const char * argv[]) {
    int N;
    double v,vv,y,t;
    while(scanf("%lf",&v)!=EOF){
        for(N=1;;N++){
            y=5*N-5;
            t=sqrt(y/4.9);
            vv=9.8*t;
            if(vv>v)
                break;
        }
        printf("%d\n",N);
    }
    return 0;
}

Measured memory_bytes: 628
#include <stdio.h>
#include <strings.h>
int main()
{
    int num,j;
    char i[3];
    scanf("%c%c%c%c",&i[0],&i[1],&i[2],&i[3]);
    num = 0;
    for(j=0;j<4;j++){
    if(i[j] == '+'){
        num = num + 1;
    }else{
        num = num - 1;
    }    
    }
    printf("%d",num);
return 0;
}


Measured memory_bytes: 128
N = int(input())

def display(x):
  if(x==3):
    print("bon")
  elif(x==0 or x==1 or x==6 or x==8):
    print("pon")
  else:
    print("hon")

if(N<10):
  display(N)
elif(N<100):
  display(N%10)
else:
  display((N%100)%10)
  

Measured memory_bytes: 9180
#include<bits/stdc++.h>
using namespace std;
#define int             long long int
#define pb              push_back
#define se              second
#define mp              make_pair
#define fi              first
#define del(a,vec)      vec.erase(std::remove(vec.begin(), vec.end(), a), vec.end());
#define search(f,l,v)   binary_search(f,l,v)
#define iter(a,b)       vector<int>::iterator a,b
#define lower(v,num)    lower_bound (v.begin(), v.end(), num);
#define upper(v,num)    upper_bound (v.begin(), v.end(), num); 
#define removecopy(a)   unique(a.begin(), a.end()); 
#define vi              vector<int> 
#define pi              pair<int,int>    
#define vpi             vector<pi>      
#define mlbb            ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)    
int mod =1000000007;
namespace Rahul{
    bool isPrime(int n) 
    {if (n <= 1)  return false; if (n <= 3)  return true; 
    if (n%2 == 0 || n%3 == 0) return false; 
    for (int i=5; i*i<=n; i=i+6) 
        if (n%i == 0 || n%(i+2) == 0) 
           return false; 
    return true; }
    int pow (int x, int n,int mod) {//calculate x^n
    if (n == 0) return 1;

    int res = pow (x, n / 2,mod);

    res = (res * res) % mod;
    if (n % 2) res = (res * x ) % mod;

    return res;
    }
    int _gcd(int a,int b)
    {
        if(a==0)
            return b;
        else    
            return _gcd(b%a,a);
    }
    //s.erase(s.find(2)) where s={1,2,3,3,2}; 
};
using namespace Rahul;
int32_t main()
{
    mlbb;
   int n,k;
    cin>>n>>k;
   
   vector<int>v;
   for(int i = 0; i<n;i++){
       int x;
       cin>>x;
       v.pb(x);
   }
   sort(v.begin(),v.end());
   int ans = 0;
   if(k>=v.size())  {
       cout<<0<<endl;
       return 0;
   }
    for(int i= 0 ; i<v.size() - k  ; i++){
        ans = ans + v[i];
    }
    cout<<ans<<endl;
    
}


Measured memory_bytes: 2548
#include<bits/stdc++.h>
#define int long long
#define loop(i, a, b) for(int i = a; i < b; i++)
#define rep(i, a) loop(i, 0, a)
#define all(a) (a).begin(),(a).end()
using namespace std;
const int MOD = 1e9 + 7, INF = 1e9;
using vi = vector <int>;
using vvi = vector <vi>;
//g++ -std==c++14

struct edge {int to, cost; };
using P = pair<int , int>;
int V;
//頂点数をＶで受け取ること！！！！！！！！！！！！
vector <edge> G[100010];
int d[100010];

void dijkstrra(int s){
    priority_queue <P, vector<P>, greater<P> > que;
    fill(d, d + V, 1e18);
    d[s] = 0;
    que.push(P(0 , s));
    
    while(!que.empty()){
        P p = que.top(); que.pop();
        int v = p.second;
        if(d[v] < p.first)  continue;
        for(int i = 0; i < G[v].size(); i++){
            edge e = G[v][i];
            if(d[e.to] > d[v] + e.cost){
                d[e.to] = d[v] + e.cost;
                que.push(P(d[e.to], e.to));
            }
        }
    }
}

signed main(){
    cin >> V;
    int a, b, c;
    rep(i, V - 1){
        cin >> a >> b >> c;
        a--; b--;
        G[a].push_back({b, c});
        G[b].push_back({a, c});
    }

    int q, k;   cin >> q >> k;
    k--;
    dijkstrra(k);
    int x, y;
    rep(i, q){
        cin >> x >> y;
        x--; y--;
        cout << d[x] + d[y] << endl;
    }
}

Measured memory_bytes: 11120
// A.

#include <iostream>
#include <sstream>
#include <algorithm>
#include <vector>
#include <numeric>

using namespace std;

typedef long long LL;

int main(int argc, char* argv[]) {
	const LL INF = 1LL << 60;
#ifdef _MSC_VER
	while (true)
#endif
	{
		string s;
		cin >> s;
		int n = s.length() + 1;
		if (n <= 1) return 0;
		vector<int> v(n, -1);
		char prev = -1;
		int m = 0;
		for (int i = 1; i < n; ++i) {
			char c = s[i - 1];
			if (c == '<') {
				v[i] = ++m;
				if (prev != '<') {
					v[i - 1] = 0;
				}
			} else {
				m = 0;
			}
			prev = c;
		}
		prev = -1;
		for (int i = n - 2; i >= 0; --i) {
			char c = s[i];
			if (c == '>') {
				++m;
				v[i] = max(v[i], m);
				if (prev != '>') {
					v[i + 1] = 0;
				}
			} else {
				m = 0;
			}
			prev = c;
		}
		//for (int i = 0; i < n; ++i) {
		//	cout << " " << v[i];
		//}
		//cout << endl;
		long long ans = accumulate(v.begin(), v.end(), 0LL);
		cout << ans << endl;
	}
	return 0;
}


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

int main(){
    int n ;
    cin >> n ;
    vector<int> v(n) ;
    int MAX = -1e9 ;
    int MIN = 1e9 ;
    for(int i=0;i<n;i++){
        cin >> v[i] ;
        MAX = max(MAX,v[i]);
        MIN = min(MIN,v[i]);
    }
    vector<pair<int,int> > ans ;
    if ( abs(MAX) >= abs(MIN) ){
        int maxIndex = max_element(v.begin(),v.end()) - v.begin();
        maxIndex++;
        for(int i=0;i<n;i++){
            if ( i+1 == maxIndex ) continue ;
            ans.push_back({maxIndex,i+1});
        }
        ans.push_back({maxIndex,maxIndex});
        for(int i=1;i<n;i++){
            ans.push_back({i,i+1});
        }
    }
    else{
        int minIndex = min_element(v.begin(),v.end()) - v.begin();
        minIndex++;
        for(int i=0;i<n;i++){
            if ( i+1 == minIndex ) continue ;
            ans.push_back({minIndex,i+1});
        }
        ans.push_back({minIndex,minIndex});
        for(int i=n;i>1;i--){
            ans.push_back({i,i-1});
        }
    }
    cout << ans.size() << endl;
    for(auto &p : ans){
        cout << p.first << " " << p.second << endl;
    }
    return 0 ;
}


Measured memory_bytes: 256
N = int(input())
n = len(str(N))
nine = int("9" * n)

def f(n):
  return sum(map(int, str(n)))

if nine == N:
  print(f(N))
elif N < nine:
  l = str(N)
  x = l[0] + "9"*(len(l)-1)
  if l == x:
    print(f(x))
  else:
    print(f((int(l[0] + "0"*(len(l)-1)))-1))
elif N > nine:
  print(f(nine))

Measured memory_bytes: 3064
#include <stdio.h>

int	main(void)
{
  	int	a;
  	int	b;
  	int num;
  
  	num = scanf("%d", &a);
  	if (num != 1)
      	return (0);
  
  	num = scanf("%d", &b);
  	if (num != 1)
      	return (0);
	
  	printf("%d", 6 - a - b);
  	return (0);
}

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

const int MAX_N = 1 << 18;
const int def = 0;

//セグメント木を持つグローバル配列
ll n, dat[2 * MAX_N - 1];

//初期化
void init(ll n_){
    //簡単のため、要素数を2のべき乗に
    n = 1;
    while ( n < n_ ) n *= 2;

    //全ての値をINT_MAXに
    for(int i = 0; i < 2 * n - 1; i++) dat[i] = def;
}

//k番目の値(0-indexed)をaに変更
void update(ll k, ll a){
    //葉の節点
    k += n - 1;
    dat[k] = a;
    //登りながら更新
    while(k > 0){
        k = (k-1)/2;
        dat[k] = max(dat[k*2+1], dat[k*2+2]);
    }
}

// [a,b)の最小値を求める
// 後ろの方の引数は、計算の簡単のための引数
// kは節点の番号、1,rはその接点が[1,r)に対応づいていることを表す
// したがって、外からはquery(a, b, 0, 0, n)として呼ぶ
ll query(ll a, ll b, ll k = 0, ll l = 0, ll r = n){
    //[a,b)と[l,r)が交差しなければ、INT_MAX
    if( r <= a || b <= l) return def;

    //[a,b)が[l,r)を完全に含んでいれば、この節点の値
    if(a <= l && r <= b) return dat[k];
    else{
        //そうでなければ、２つの子が必要
        ll vl = query(a, b, k * 2 + 1, l, (l+r)/2);
        ll vr = query(a, b, k * 2 + 2, (l+r)/2, r);
        return max(vl,vr);
    }
}

int main(){
    ll N; cin >> N;
    vector<ll> h(N), a(N);
    rep(i, 0, N) cin >> h[i];
    rep(i, 0, N) cin >> a[i];

    init(N);
    rep(i, 0, N){
        update(h[i]-1, query(0, h[i]-1) + a[i]);
    }
    cout << query(0, N) << endl;
}

Measured memory_bytes: 7552
n = int(input())
a = list(map(int, input().split()))

count = 0
i = 0
val = 1
while i < n:
    while(i < n and a[i] != val):
        i = i + 1
        count = count + 1
    
    if(i < n):
        i = i + 1
        val = val + 1

if(val == 1):
    print(-1)
else:
    print(count)


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

using namespace std;

int main() {

    long a, b, c, d;
    cin >> a >> b >> c >> d;
    long tmp_1 = a *c;
    long tmp_2 = a *d;
    long tmp_3 = b * c;
    long tmp_4 = b * d;
    long ans = max(max(max(tmp_1,tmp_2),tmp_3),tmp_4);
    cout << ans <<endl;

    return 0;
}


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

using namespace std;

typedef long long ll;

#define optimize() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define fraction() cout.unsetf(ios::floatfield); cout.precision(10); cout.setf(ios::fixed, ios::floatfield);
#define file() freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);

const int mxN = 1e5 + 123;
const ll MOD = 1e9 + 7;

inline void normal(ll &a) { a %= MOD; (a < 0) && (a += MOD); }
inline ll modMul(ll a, ll b) { a %= MOD; b %= MOD; normal(a); normal(b); return (a * b) % MOD; }
inline ll modAdd(ll a, ll b) { a %= MOD; b %= MOD; normal(a); normal(b); return (a + b) % MOD; }
inline ll modSub(ll a, ll b) { a %= MOD; b %= MOD; normal(a); normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1LL; while (p) { if (p & 1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline ll modInverse(ll a) { return modPow(a, MOD - 2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }

int n;
vector<int> adj[mxN];
ll dp1[mxN], dp2[mxN];

void dfs(int u, int p) {
    for (int v : adj[u]) {
        if (v != p) {
            dfs(v, u);
            dp1[u] = modMul(dp1[u], dp2[v]);
            dp2[u] = modMul(dp2[u], modAdd(dp1[v], dp2[v]));
        }
    }
}

int main() {
    optimize();
    cin >> n;
    for (int i = 0; i < mxN; ++i) {
        dp1[i] = dp2[i] = 1LL;
    }
    for (int i = 1; i < n; ++i) {
        int u, v;
        cin >> u >> v;
        adj[u].push_back(v), adj[v].push_back(u);
    }
    dfs(1, -1);
    cout << modAdd(dp1[1], dp2[1]) << endl;
    return 0;
}


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

A,B=1,1

for at in AT:
  n=max(-(-A//at[0]//1),-(-B//at[1]//1))
  #print("n,a,b",n,-(-A//at[0]//1),-(-B//at[1]//1))
  #print("a,b", at[0],at[1])
  A=n*at[0]
  B=n*at[1]
  #print(A,B)
print(A+B)

Measured memory_bytes: 3188
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
#define mp make_pair

template<class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }

int cost[110][110];
bool used[110];

int main() {
	int n,m;
	int a,b,c;
	while(n=in(),m=in()){
		int i,j;
		for(i=0;i<110;i++){
			for(j=0;j<100;j++){
				cost[i][j]=1000;
			}
			used[i]=false;
		}
		for(i=0;i<m;i++){
			cin>>a>>b>>c;
			if(cost[a][b]>c){
				cost[a][b]=c;
				cost[b][a]=c;
			}
		}
		priority_queue<pint,vector<pint>,greater<pint> > que;
		que.push(pint(0,0));
		int res=0;
		while(!que.empty()){
			pint p=que.top();
			que.pop();
			if(used[p.second])continue;
			used[p.second]=true;
			res+=p.first;
//cout<<p.first<<" "<<p.second<<endl;
			for(i=0;i<n;i++){
				if(used[i])continue;
				if(cost[p.second][i]==1000)continue;
				que.push(pint(cost[p.second][i],i));
			}
		}
		cout<<res<<endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
int a[110],flag,n,x,m;
int main(){
	scanf("%d%d",&m,&n);
	for(int i=1;i<=n;++i)
		scanf("%d",&a[i]),x+=a[i]%2;
	if(n==1&&a[1]==1)return printf("1\n1\n1"),0;
	if(n==1)return printf("%d\n2\n%d %d",a[1],a[1]-1,1),0;
	if(x>2)return puts("Impossible"),0;
	if(x)for(int i=1;i<=n;++i)if(a[i]%2)swap(a[i],a[flag?n:1]),flag=1;
	for(int i=1;i<=n;++i)printf("%d ",a[i]);
	a[1]--,a[n]++;
	if(!a[1])printf("\n%d\n",n-1);
	else printf("\n%d\n",n);
	for(int i=1;i<=n;++i)if(a[i])printf("%d ",a[i]);
}

Measured memory_bytes: 256
import java.util.*;

class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int r = Integer.parseInt(sc.next());
        int g = Integer.parseInt(sc.next());
        int b = Integer.parseInt(sc.next());
        sc.close();
        if ((g*10+b)%4 == 0) System.out.println("YES");
        else System.out.println("NO");
    }
}

Measured memory_bytes: 35456
using System;
    using System.Linq;
    using System.Collections.Generic;
    using System.Text.RegularExpressions;
    using System.Text;
    using System.Net;

     
    public class Program
    {

        public void Proc() {
            int[] inpt = Reader.ReadLine().Split(' ').Select(a=>int.Parse(a)).ToArray();
            String ans = "Odd";
            if(inpt.Any(a=>a%2==0)) {
                ans = "Even";
            }
            Console.WriteLine(ans);
        }



        public class Reader {
            public static bool IsDebug = false;
            private static System.IO.StringReader SReader;
            private static string InitText = @"









";
            public static string ReadLine() {
                if(IsDebug) {
                    if(SReader == null) {
                        SReader = new System.IO.StringReader(InitText.Trim());
                    }
                    return SReader.ReadLine();
                } else {
                    return Console.ReadLine();
                }
            }
        }
        public static void Main(string[] args)
        {
            #if DEBUG
            Reader.IsDebug = true;
            #endif
            Program prg = new Program();
            prg.Proc();
        }
    }

Measured memory_bytes: 13396
#include<stdio.h>
int main(void){
int c,a,b,x,y,z;

scanf("%d",&a);
scanf("%d",&b);
scanf("%d",&c);
x = a + b;
y = a + c;
z = b + c;

if (x<=y&&x<=z) {
printf("%d\n",x);
} else if (y<=x&&y<=z) {
printf("%d\n", y);
}  else if (z<=x&&z<=y) {
printf("%d\n", z);
}
return 0;
}

Measured memory_bytes: 128
s = input()

lis = []
l = len(s)
judge = True
i = 0
while (i < l):
    if judge:
        if (s[i] == 'A'):
            lis.append(0)
            i += 1
        elif (s[i:i+2] == 'BC'):
            lis.append(1)
            i += 2
        else:
            judge = False
            lis.append(2)
            i += 1
    else:
        if (s[i] == 'A'):
            judge = True
            lis.append(0)
        i += 1

sum1 = 0    
cnt = 0
for i in lis:
        if i == 0:
            cnt += 1
        elif i == 1:
            sum1 += cnt
        else:
            cnt = 0

print(sum1)


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

#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define REP(i, n)  for(int i=0;i<(n);++i)
#define REPr(i, n) for(int i=(n)-1;i>=0; --i)
#define FORq(i, m, n) for(int i = (m);i <= (n);++i)
#define FORqr(i, m, n) for(int i = (n);i >=(m);--i)
#define PB push_back
#define MP make_pair
#define DEBUG printf("%s\n","debug")
#define fst first
#define snd second
#define SIN(x, S) (S.count(x) != 0)
#define M0(x) memset(x,0,sizeof(x))
#define FILL(x, y) memset(x,y,sizeof(x))
#define MM(x) memset(x,-1,sizeof(x))
#define ALL(x) (x).begin(),(x).end()
#define SCD(n) scanf("%d",&n)
#define SCD2(m,n) scanf("%d%d",&m,&n)
#define SCD3(m,n,k) scanf("%d%d%d",&m,&n,&k)
#define SCLLD(n) scanf("%lld",&n)
#define SCLLD2(m,n) scanf("%lld%lld",&m,&n)
#define SCLLD3(m,n,k) scanf("%lld%lld%lld",&m,&n,&k)
using namespace std;
typedef pair<int, int> PII;
typedef pair<long long, long long> PLL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef long long ll;
typedef long long integer;
///////////////////////////////////////////////
const ll MOD = 1e9+7;

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

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

template<class T>
inline bool chmax(T &a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
///////////////////////////////////////////////
/*🍈( '-'  🍈*/

int main(){
	vector<char> S;
	REP(i,4){
	    char s;
	    cin >> s;
	    S.PB(s);
	}

	sort(ALL(S));

	bool ans = true;
	if (S[0] != S[1]) ans = false;
	if (S[2] != S[3]) ans = false;
	if (S[1] == S[2]) ans = false;

	if (ans) puts("Yes");
	else puts("No");


	return 0;
}


Measured memory_bytes: 256
/*
        ####   ####
     ###    ###    ###
   ###    Bravery    ###
  ###  Determination  ###
   ##  Perseverance   ##
    ##   Integrity   ##
     ##  Patience   ##
      ## Kindness  ##
        ##Justice##
         ##     ##
           ## ##
             #
*/
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
typedef long long ll;
using namespace std;
int n,a[20],b[20],c[20],ans;
int main(){
	cin>>n;
	for (int i=0;i<n;i++) cin>>a[i];
	for (int i=0;i<n;i++){
		cin>>b[i];
		ans+=b[i];
	}
	for (int i=1;i<n;i++){
		cin>>c[i];
	}
	for (int i=0;i<n;i++){
		if (a[i+1]-a[i]==1){
			ans+=c[a[i]];
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void){
int  n;
  scanf("%d",&n);
  double a[n],sum=0;
  for(int i=0;i<n;i++){
	scanf("%lf",&a[i]);
   
    
  }
  
  for(int i=0;i<n;i++){
	sum+=1/a[i];
    
  }
   // printf("%lf\n",sum);
/*double ans=1;
  for(int i=0;i<n;i++){
	ans*=a[i];
  }
 // printf("%lf\n",ans);*/
  printf("%.10lf",1/sum);
  return 0;
}

Measured memory_bytes: 128
from math import factorial
N, P = map(int, input().split())
A = list(map(int, input().split()))

odd, even = 0,0
for a in A:
    if a%2==0:
        even += 1
    else:
        odd += 1

ans = 0

def combination(n, r):
    return factorial(n)//(factorial(r)*factorial(n-r))

if P==0:
    for i in range(0,odd+1):
        if i%2==0:
            ans += combination(odd,i)*(2**even)
else:
    for i in range(1,odd+1):
        if i%2==1:
            ans += combination(odd,i)*(2**even)
print(ans)

Measured memory_bytes: 3064
/*
 * atcoder/abc091_2nd/c.cpp
 */

// C++ 14
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstring> // memset
#include <cassert>
using namespace std;
#define ll long long
#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)
template <class T> bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false; }
template <class T> bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false; }
struct Point {
  int x, y;
};
ostream & operator << (ostream & out, Point const & v) {
  out << "Point(" << v.x << ", " << v.y << ')';
  return out;
}
bool yAsc(const Point& lh, const Point& rh) {
     return lh.y < rh.y;
}
bool xDesc(const Point& lh, const Point& rh) {
     return lh.x > rh.x;
}

int N;
vector<Point> red, blue;
bool done[300] = {0};

void solve() {
  cin >> N;
  int x, y;
  loop(n,0,N) {
    cin >> x >> y; red.push_back({ x, y });
  }
  loop(n,0,N) {
    cin >> x >> y; blue.push_back({ x, y });
  }
  sort(blue.begin(), blue.end(), yAsc);
  sort(red.begin(), red.end(), xDesc);
  int count = 0;
  loop(b,0,N) {
    loop(r,0,N) {
      if (done[r]) continue;
      if (red[r].x < blue[b].x and red[r].y < blue[b].y) {
        count++;
        done[r] = true;
        break;
      }
    }
  }
  cout << count << endl;
}
int main() {
  // cout.precision(15); cout << fixed;

  solve();

  return 0;
}


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

int main () {
  long long int A, B, C;
  cin >> A >> B >> C;
  long long int cnt = 0;
  if ((A%2==1) || (B%2==1) || (C%2==1)) {
    cout << "0" << endl;
    return 0;
  }
  if ((A==B) && (B==C)) {
    cout << "-1" << endl;
    return 0;
  }
  while ((A%2==0) && (B%2==0) && (C%2==0)) {
    cnt++;
    int a = A / 2, b = B / 2, c = C / 2;
    A = b + c;
    B = c + a;
    C = a + b;
  }
  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 256
import bisect
import heapq
import itertools
import math
import os
import re
import string
import sys
from collections import Counter, deque, defaultdict
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7

N, S = list(map(int, sys.stdin.readline().split()))
X = list(map(int, sys.stdin.readline().split()))

X = np.array(X + [S])
X -= X.min()

print(reduce(gcd, X))


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

int main()
{
    int n;
    cin >> n;
    long long mx = 0, mn = 1e10;
    for(int i = 0; i < n; i++){
        long long a;
        cin >> a;
        mx = max(mx, a);
        mn = min(mn, a);
    }
    cout<<mx-mn<<endl;
    return 0;
}


Measured memory_bytes: 256
# Graph I - Connected Components
import array
from collections import deque
def groupify(length, adj_list):
    group = array.array('l', (-1 for _ in range(length)))
    g_id = 0
    dq = deque()
    for idx in range(length):
        if group[idx] == -1:
            group[idx] = g_id
            dq.append(idx)
            while len(dq):
                v = dq.popleft()
                for t in adj_list[v]:
                    if group[t] == -1:
                        group[t] = g_id
                        dq.append(t)
            g_id += 1
    return group

n,m = map(int, input().split())
adj_list = [set() for _ in range(n)]
for _ in range(m):
    i,j = map(int, input().split())
    adj_list[i].add(j)
    adj_list[j].add(i)
group = groupify(n, adj_list)

q = int(input())
for _ in range(q):
    s,t = map(int, input().split())
    if group[s] == group[t]: print('yes')
    else: print('no')


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

#define INF (INT64_MAX)
#define MOD (1000000000+7)
#define MAX 200000

int N;
int h[MAX];
int a[MAX];

typedef enum { MINIMUM, MAXIMUM } MinMax;
 
template <typename T>
class SegmentTree {
public:
    int bit_, N;
    vector<T> buf_;
    T invalid;
    MinMax mode;
 
    SegmentTree(int size, MinMax mode=MINIMUM) : mode(mode) {
        N = 1;
        bit_ = 0;
        while (N < size) {
            N *= 2;
            ++bit_;
        }
 
        switch (mode) {
            case MINIMUM:
                if (sizeof(T) == 4) {
                    invalid = INT_MAX;
                } else if (sizeof(T) == 8) {
                    invalid = LLONG_MAX;
                }
                break;
            case MAXIMUM:
                if (sizeof(T) == 4) {
                    invalid = INT_MIN;
                } else if (sizeof(T) == 8) {
                    invalid = LLONG_MIN;
                }
                break;
        }
        buf_.assign(N*2, invalid);
    }
 
    T merge(T l, T r) {
        switch (mode) {
            case MINIMUM:
                return min(l, r);
            case MAXIMUM:
                return max(l, r);
			default:
                return min(l, r);
        }
    }
 
    void update(int i, T x) {
        i = N + i - 1;
 
        if (merge(buf_[i], x) != x) return;
 
        buf_[i] = x;
        while (i > 0) {
			i = (i - 1) / 2;
			buf_[i] = merge(buf_[i*2+1], buf_[i*2+2]);
        }
    }
 
    T query(int lo, int hi) {
        return query(lo, hi, 0, 0, N);
    }
    T query(int a, int b, int k, int l, int r) {
        if (r <= a || b <= l) return invalid;
 
        if (a <= l && r <= b) {
            return buf_[k];
        } else {
			T lv = query(a, b, 2*k+1, l, (l+r)/2);
			T rb = query(a, b, 2*k+2, (l+r)/2, r);
			return merge(lv, rb);
        }
    }
 
    void dump() {
    }
};

int main() {
	cin >> N;
	for( int i = 0; i < N; i++ ) {
		cin >> h[i];
	}
	for( int i = 0; i < N; i++ ) {
		cin >> a[i];
	}

	int hmax = *max_element( h, h + N );
	SegmentTree<long long> st( hmax + 1, MAXIMUM );
	for( int i = 0; i < N; i++ ) {
		long long maxval = max( 0LL, st.query( 0, h[i] ) );
		long long newval = maxval + a[i];
		st.update( h[i], newval );
	}
	long long ans = st.query( 0, hmax + 1 );

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 5888
//jinhaonan
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
template<class T>inline void read(T &x){
	x=0;char c=getchar();bool f=0;
	for(;c>'9'||c<'0';f=c=='-',c=getchar());
	for(;c>='0'&&c<='9';x=(x<<1)+(x<<3)+c-'0',c=getchar());
	x=f?-x:x;
}
template<class T>inline void write(T x){
	if(x<0)putchar('-'),x=-x;
	if(x>=10)write(x/10);
	putchar(x%10+48);
}
template<class T>inline bool chkmax(T &a,T const &b){
	return a<b?a=b,1:0;
}
template<class T>inline bool chkmin(T &a,T const &b){
	return a>b?a=b,1:0;
}
const int N=1000+10;
long long x[N],y[N];
long long d[40];
void Main(){
	int n;read(n);
	bool flag[2]={false,false};
	for(int i=1;i<=n;++i){
		read(x[i]),read(y[i]);
		// cout<<((x[i]+y[i])&1)<<'\n';
		flag[(x[i]+y[i])&1]=1;
	}
	if(flag[0]&&flag[1]){
		puts("-1");
		return;
	}
	int m=31;
	for(int i=0;i<m;++i){
		d[i]=1ll<<i;
	}
	reverse(d,d+m);
	if(flag[0]){
		d[m]=1;
		write(m+1),putchar('\n');
		for(int i=0;i<=m;++i){
			write(d[i]),putchar(i==m?'\n':' ');
		}
	}else{
		write(m),putchar('\n');
		for(int i=0;i<m;++i){
			write(d[i]),putchar(i==m-1?'\n':' ');
		}
	}
	for(int i=1;i<=n;++i){
		if(flag[0]){
			--x[i];
		}
		for(int j=0;j<m;++j){
			bool u=y[i]+x[i]>0,v=y[i]-x[i]>0;
			if(u&&v){
				putchar('U');
				y[i]-=d[j];
			}else if(!u&&!v){
				putchar('D');
				y[i]+=d[j];
			}else if(u&&!v){
				putchar('R');
				x[i]-=d[j];
			}else if(!u&&v){
				putchar('L');
				x[i]+=d[j];
			}
		}
		// assert(x[i]==0&&y[i]==0);
		if(flag[0]){
			putchar('R');
		}
		putchar('\n');
	}
}
int main(){
    // freopen("in.txt","r",stdin);
    // int test;read(test);
    // while(test--){
        Main();
    // }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<string.h>
using namespace std;
#define pb push_back
#define all(v) v. begin(),v. end()
#define  rep(i,n,v) for(i=n;i<v;i++)
#define per(i,n,v) for(i=n;i>v;i--)
#define ff first 
#define ss second 
#define pp pair<ll,ll>
#define ll  long long
#define endl '\n'
void solve()
{
  ll n, a,m=0,b=1, c,k=0, i, j,l=1e9+7;
  string s, r, y;
  cin>>s;
//  cout<<s[0];
sort(s.begin(),s. end());
char e='a';
rep(j,0,26) {
  k=0;
   rep(i,0,s.length())
   {
     if(s[i]==e) {k=1;break;}
   }
   if(!k) {
   cout<<e;return;}
   e++;
   }
   cout<<"None";
}
int main()
{
 ios_base::sync_with_stdio(false);
  cin. tie(0);cout. tie(0);
    ll t=1;
   //cin>>t;
    while(t--)
    {
      solve();
    }
    return 0;
}

Measured memory_bytes: 3740
#include <iostream>
#include <vector>
using namespace std;
int main(){
    int n,m,d;
    char map[100][100];
    bool x=true;
    cin>>n>>m>>d;
    for (int i=0; i<n; i++) {
        for(int j=0;j<m;j++){
            cin>>map[i][j];
        }
    }
    
    int ans=0;
    for (int i=0; i<n; i++) {
        for(int j=0;j<m;j++){
            if(map[i][j]=='#')continue;
            if(m>=j+d){
                x=true;
                for (int k=j; k<j+d; k++) {
                    if(map[i][k]=='#'){
                        x=false;
                        break;
                    }
                }
                if(x)ans++;
            }
            if(n>=i+d){
                x=true;
                for(int k=i;k<i+d;k++){
                    if(map[k][j]=='#'){
                        x=false;
                        break;
                    }
                }
                if(x)ans++;
            }
            map[i][j]='#';
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3088
#include <iostream>
#include<vector>
#include<algorithm>
#include<cstring>
#include<string>
#include <set>
#include <cassert>
#include"math.h"
using namespace std;
#define MOD 1000000007
class UnionFind {
	vector<int> data;
public:
	UnionFind(int size) : data(size, -1) { }
	bool unionSet(int x, int y) {
		x = root(x); y = root(y);
		if (x != y) {
			if (data[y] < data[x]) swap(x, y);
			data[x] += data[y]; data[y] = x;
		}
		return x != y;
	}
	bool findSet(int x, int y) {
		return root(x) == root(y);
	}
	int root(int x) {
		return data[x] < 0 ? x : data[x] = root(data[x]);
	}
	int size(int x) {
		return -data[root(x)];
	}
};

int find(vector<long long> &arr, long long obj) {
	if (arr[arr.size() - 1] < obj)return arr.size()-1;
	if (arr[0] > obj)return -1;

	int min = 0; int max = arr.size() - 1;
	for (int i = 0; i < arr.size(); i++) {
		if (arr[min+(max-min) / 2] > obj) {
			max = min + (max - min) / 2;
		}
		else {
			min = min + (max - min) / 2;
		}
		if (max - min == 1) {
			return min;
		}
	}


}

int main() {
	double t, x;
	cin >> t >> x;
	cout << t / x;


	return 0;
}

Measured memory_bytes: 256
h, w = map(int, input().split())

dp = [0] * w
max_d = 0
for _ in range(h):
    dp_prev = dp[:]
    tiles = list(map(int, input().split()))
    dp[0] = 0 if tiles[0] else 1
    for i in range(1, w):
        dp[i] = 0 if tiles[i] else min(dp[i-1], dp_prev[i], dp_prev[i-1]) + 1
    max_d = max(max_d, max(dp))

print(max_d**2)


Measured memory_bytes: 5720
local n = io.read("*n")
a = {}
local sum = 0
for i = 1, n do
    local k = io.read("*n")
    a[i] = k
    sum = sum + k
end
table.sort(a, function(x, y) return x > y end)
local alice = 0
for i = 1, n, 2 do
    alice = alice + a[i]
end
print(alice * 2 - sum)

Measured memory_bytes: 256
import math

N = int(input())
A = list(map(int,input().split()))
MAX_INT = 10**6
f1 = [0] * (MAX_INT+1)
for a in A:
  f1[a] += 1

flg = True
for i in range(2, MAX_INT+1):
  cnt = 0
  for j in range(i, MAX_INT+1, i):
    cnt += f1[j]
  if cnt > 1:
    flg = False
    break

if flg:
  print("pairwise coprime")
  exit()

g = A[0]
for i in range(1, N):
  g = math.gcd(g, A[i])

if g == 1:
  print("setwise coprime")
else:
  print("not coprime")

Measured memory_bytes: 194948
states = list(map(int,input().strip().split(' ')))
sortedlist = sorted(states)

diff0 = (sortedlist[2]-sortedlist[0])//2
diff1 = (sortedlist[2]-sortedlist[1])//2

newlist = [sortedlist[0]+2*diff0, sortedlist[1]+2*diff1, sortedlist[2]]

def patternMatch(s):
    if 1==2*s[2]-s[1]-s[0]:
        return 2
    elif 2==2*s[2]-s[1]-s[0]:
        return 1
    elif 0==2*s[2]-s[1]-s[0]:
        return 0

print(patternMatch(newlist)+diff0+diff1)

Measured memory_bytes: 3064
#include<iostream>
#include<map>
#include<algorithm>
using namespace std;
long long n,m,ans=0;
#define ll long long
const int maxn=1e5+5; 
long long x[maxn],pre[maxn];
int main()
{
	map<ll,ll>mp;
	cin>>n>>m;
	pre[0]=0;
	for(int i=1; i<=n; i++)
	{
		cin>>x[i];
		pre[i]=(pre[i-1]+x[i])%m;
		ans+=mp[pre[i]];
		mp[pre[i]]++;
	}
	cout<<ans+mp[0]<<endl;
/*	while(cin>>n>>m)
	{
		long long x;
		pre[0]=0;
		for(long long i=1; i<=n; i++)
		{
			cin>>x;
			//pre[i]=((pre[i-1]+x)%m+m)%m;
			pre[i]=(pre[i-1]+x)%m;
		}
		sort(pre,pre+n+1);
		long long s=1;
		long long ans=0;
		for(long long i=1; i<=n; i++)
		{
			if(pre[i]==pre[i-1]) s++;
			else
			{
				ans+=s*(s-1)/2;
				s=1;
			}
		}
		ans+=s*(s-1)/2;
		cout<<ans;
	}*/
	return 0;
}


Measured memory_bytes: 5760
import math
A, B, H, M = map(int, input().split())


if H == 0:
    H = 12
elif M == 0:
    M = 60
L = M / 5



N = min(abs(L - H), abs(H - L))

if L >= H:
    if M == 60:
        M = 0
    S = 360 * N / 12 - (0.5 * M)
else:
    S = 360 * N / 12 + (0.5 * M)


ANS = A**2 + B**2 - (2*A*B*math.cos(math.radians(S)))
ANS = math.sqrt(ANS)
print(ANS)


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

using P= pair<int, int>;
const int MAX_T = 1e5 + 9;

int main() {
    int N, C;  cin >> N >> C;
    vector<vector<P>> v(C);
    for (int i = 0; i < N; ++i) {
        int s, t, c;
        cin >> s >> t >> c;  --c;
        v[c].push_back(P(s, t));
    }
    for (int c = 0; c < C; ++c) sort(v[c].begin(), v[c].end());
    // DUMP(v);

    vector<int> imos(MAX_T * 2);
    for (int c = 0; c < C; ++c) {
        int i = 0;
        if (i >= v[c].size()) continue;
        ++imos[v[c][i].first * 2 - 1];
        while (i < v[c].size()) {
            if (i + 1 < v[c].size() && v[c][i].second != v[c][i + 1].first) {
                --imos[v[c][i].second * 2 + 1];
                ++imos[v[c][i + 1].first * 2 - 1];
            }
            else if (i + 1 == v[c].size()) {
                --imos[v[c][i].second * 2 + 1];
            }
            ++i;
        }
    }

    int ans = 0;
    for (int i = 0; i < MAX_T * 2 - 1; ++i) {
        imos[i + 1] += imos[i];
        ans = max(ans, imos[i]);
    }
    cout << ans << endl;
}


Measured memory_bytes: 5340
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>

using namespace std;

int main() {
    int N; cin >> N;
    vector<int> A(N);
    map<int, int> M;
    int mx = 0;

    for(int i=-1; i<=100001; i++){
        M[i] = 0;
    }
    
    for(int& a:A){
        cin >> a;
        mx = max(mx, a);
        M[a]++;
    }
    
    map<int, int> cnt;
    for(int i=0; i<=mx; i++){
        cnt[i] = M[i] + M[i-1] + M[i+1];
    }
    
    int ans = 0;
    for(auto c:cnt){
        ans = max(ans, c.second);
    }
    
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 9984
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstring>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <sstream>
#include <stdio.h>
#include <string>
#include <tuple>
#include <vector>
#define FORi(N) for(int i = 0; i < N; ++i)
#define FORj(N) for(int j = 0; j < N; ++j)
#define FORk(N) for(int k = 0; k < N; ++k)
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
ll gcd(ll m, ll n) {
    if(n == 0)
        return abs(m);
    return (gcd(n, m % n));
}
void putYN(bool b) {
    if(b) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}
void swap(ll &a, ll &b) {
    ll tmp = a;
    a = b;
    b = tmp;
}
int main() {
    ll N;
    cin >> N;
    vector<ll> d(N);
    FORi(N) { cin >> d[i]; }
    sort(d.begin(), d.end());
    ll num = d[N / 2 ] - d[N / 2-1];
    cout << num << endl;
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
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; }

vector<pair<int64_t,int64_t>>prime_factorize(int64_t x){
  vector<pair<int64_t,int64_t>>p;
  for(int64_t i=2;i*i<=x;i++){
    int cnt=0;
    if(x%i==0){
    while(x%i==0){cnt++;x/=i;}
    p.push_back(make_pair(i,cnt));
    }
  }
  if(x!=1){p.push_back(make_pair(x,1));}
  return p; 
}

int main() {
  string s;
  cin>>s;
  int n=s.size();
  string r;
  for(int i=0;i<n;i++){
    if(s[i]=='B'){
      if(!r.empty()){r.pop_back();}
    }
    else{r.push_back(s[i]);}
  }
  cout<<r<<endl;
  return 0;
}

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

using namespace std;

const int MXN = 1e5 + 5;
const long long MOD = 1e9 + 7;

vector<int> v[MXN];
long long black[MXN] , white[MXN];

void dfs(int now , int prev){
    long long b = 1 , w = 1;
    for(auto i : v[now]){
        if(i != prev){
            dfs(i , now);
            b *= white[i];
            b %= MOD;
            w *= (white[i] + black[i]) % MOD;
            w %= MOD;
        }
    }
    black[now] = b;
    white[now] = w;
    return;
}

int main(){
    int n;
    scanf("%d" ,&n);
    for(int i = 0 ; i < n - 1 ; i++){
        int a , b;
        scanf("%d %d" ,&a ,&b);
        v[a].push_back(b);
        v[b].push_back(a);
    }
    dfs(1 , -1);
    printf("%lld" ,(white[1] + black[1]) % MOD);
}

Measured memory_bytes: 14208
#include <iostream>
#include <stdio.h>
#include <vector>
#include <functional>
#include <unordered_set>
#include <algorithm>
#include <set>
#include <map>
#include <cmath>
#include <string>
#include <cstring>
#include <ctime>
#include <cassert>
#include <queue>
#include <stack>
#include <bitset>

using namespace std;

const int N = 410;
const int MOD = 1e9 + 7;

int a[N];
long long dp[N][N];

int sub(int a, int b) {
	a -= b;
	if (a < 0)
		return a + MOD;
	return a;
}

void add(int& a, int b) {
	a += b;
	if (a >= MOD)
		a -= MOD;
}

int plus(int a, int b) {
	add(a, b);
	return a;
}

long long sum[N];

long long getsum(int l, int r) {
	if (l == 0)
		return sum[r];
	return sum[r] - sum[l - 1];
}

template <class T>
void relax(T& a, T b) {
	a = min(a, b);
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int n, k;
	cin >> n;
	for (int i = 0; i < n; ++i) {
		cin >> a[i];
		sum[i] = a[i];
		if (i > 0)
			sum[i] += sum[i - 1];
		dp[i][i] = 0;
	}
	for (int len = 2; len <= n; ++len) {
		for (int l = 0; l + len <= n; ++l) {
			int r = l + len - 1;
			dp[l][r] = 1LL << 60;
			const long long addition = getsum(l, r);
			for (int mid = l + 1; mid <= r; ++mid) {
				relax(dp[l][r], dp[l][mid - 1] + dp[mid][r]);
			}
			dp[l][r] += addition;
		}
	}
	cout << dp[0][n - 1] << "\n";

	return 0;
}

Measured memory_bytes: 1536
//04
#include<iostream>
#include<queue>
#include<vector>
#include<algorithm>

using namespace std;

struct S{
  int v,c,d;
  bool operator<(S a)const{
    if(c!=a.c){
      return c>a.c;
    }else{
      return d>a.d;
    }
  }
};

struct E{
  int t,c;
};

int main(){
  for(int n,m,c;cin>>n>>m>>c,n|m|c;){
    vector<E> e[101];
    while(m--){
      int f,t,c;
      cin>>f>>t>>c;
      E ce={t,c};
      e[f].push_back(ce);
    }
    priority_queue<S> que;
    S is={1,0,0};
    que.push(is);
    int p[101];
    fill(p,p+101,-1);
    for(;;){
      S cs=que.top();
      if(cs.v==n&&cs.d<=c)break;
      que.pop();
      if(cs.d>c||p[cs.v]==cs.c)continue;
      p[cs.v]=cs.c;
      for(int i=0;i<e[cs.v].size();i++){
	S ns[2]={{e[cs.v][i].t,cs.c,cs.d+e[cs.v][i].c},{e[cs.v][i].t,cs.c+1,cs.d}};
	que.push(ns[0]);
	que.push(ns[1]);
      }
    }
    cout<<que.top().c<<endl;
  }
  return 0;
}
      

Measured memory_bytes: 1284
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;
import java.util.function.Consumer;
import java.util.stream.IntStream;

import static java.util.stream.Collectors.toList;

public class Main {
    private static final Scanner scanner = new Scanner(System.in);
    private static final Consumer<List<String>> consumer = solve();

    public static void main(String[] args) {
        consumer.accept(readInput());
    }

    private static List<String> readInput() {
        final List<String> lineList = new ArrayList<>();
        while (scanner.hasNextLine()) {
            lineList.add(scanner.nextLine());
        }
        return lineList;
    }

    private static Consumer<List<String>> solve() {
        return args -> {
            final List<Integer> firstRow = Arrays.stream(args.get(1).split(" ")).map(Integer::valueOf).collect(toList());
            final List<Integer> secondRow = Arrays.stream(args.get(2).split(" ")).map(Integer::valueOf).collect(toList());
            final Integer ans = IntStream.range(0, firstRow.size())
                    .map(index ->
                            firstRow.subList(0, index + 1).stream().mapToInt(Integer::intValue).sum()
                                    + secondRow.subList(index, secondRow.size()).stream().mapToInt(Integer::intValue).sum())
                    .max()
                    .orElse(-1);
            System.out.println(ans);
        };
    }

}


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

int main() {
  int h, w;
  while (true) {
    cin >> h >> w;
    if (h == 0 && w == 0) {
      break;
    }
    int i, j;
    for (i = 0; i < h; i++) {
      if (i == 0 || i == h - 1) {
        for (j = 0; j < w; j++) {
          cout << "#";
        }
      } else {
        for (j = 0; j < w; j++) {
          if (j == 0 || j == w - 1) {
            cout << "#";
          } else {
            cout << ".";
          }
        }
      }
      cout << endl;
    }
    cout << endl;
  }
  return 0;
}



Measured memory_bytes: 3092
#include <stdio.h>
#include <iostream>
#include <cmath>

using namespace std;

int main()
{
    long x;
    cin >> x;

    long x500 = x / 500;
    long x5 = (x - x500*500) / 5;

    long uresisa = x500 * 1000 + x5 * 5;

    cout << uresisa << endl;

    return 0;
}

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

public class ABC164B {
	private static void Main(string[] args) {
		var input = ReadIntsAsArray();
		var a = input[0];
		var b = input[1];
		var c = input[2];
		var d = input[3];

		var takahashi = (c % b == 0) ? c / b : c / b + 1;
		var aoki = (a % d == 0) ? a / d : a / d + 1;

		var answer = (aoki >= takahashi) ? "Yes" : "No";
		Console.WriteLine(answer);
	}

	private static int[] ReadIntsAsArray() => Console.ReadLine().Trim().Split().Select(x => int.Parse(x)).ToArray();
}

Measured memory_bytes: 28312
import sys
from itertools import combinations
def input(): return sys.stdin.readline().strip()


def main():
    N = int(input())
    A = list(map(int, input().split()))
    """
    まず２分して左右をさらにそれぞれ２分するときこれらはなるべく差が小さい方がよさそう
    """
    # m = 1で切った時で初期化
    s = sum(A[2:])
    partial_s = 0
    init_r = N - 2
    for r in range(2, N - 1):
        partial_s += A[r]
        if partial_s * 2 > s:
            init_r = r
            break
    l = 0
    r = init_r
    sums = [A[0], A[1], partial_s, s - partial_s]
    ans = max(sums) - min(sums)
    temp = [sums[0], sums[1], sums[2] - A[r], sums[3] + A[r]]
    ans = min(ans, max(temp) - min(temp))
    #print("l={}, m=1, r={}, sums={}, ans={}".format(l, r, sums, ans))


    # m >= 2で動かしたとき
    for m in range(2, N - 2):
        # lの移動
        sums[1] += A[m]
        while sums[0] <= sums[1] and l < m - 1:
            l += 1
            sums[0] += A[l]
            sums[1] -= A[l]
        # rの移動
        sums[2] -= A[m]
        while sums[2] <= sums[3] and r < N - 2:
            r += 1
            sums[2] += A[r]
            sums[3] -= A[r]
        # ansの更新
        ans = min(ans, max(sums) - min(sums))
        temp = [sums[0] - A[l], sums[1] + A[l], sums[2], sums[3]]
        ans = min(ans, max(temp) - min(temp))
        temp = [sums[0], sums[1], sums[2] - A[r], sums[3] + A[r]]
        ans = min(ans, max(temp) - min(temp))
        temp = [sums[0] - A[l], sums[1] + A[l], sums[2] - A[r], sums[3] + A[r]]
        ans = min(ans, max(temp) - min(temp))
        #print("l={}, m={}, r={}, sums={}, ans={}".format(l, m, r, sums, ans))
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 91968
def bubbleSort(A, N):
    '''list of int, int -> list of int(sorted)
    N = len(A)
    return list(bubble sorted)
    '''
    assert(len(A) == N)
    outA = A.copy()
    flag = True
    numofcng = 0
    while flag:
        flag = False
        for j in range(N - 1, 0, -1):
            if outA[j] < outA[j - 1]:
                outA[j], outA[j - 1] = outA[j - 1], outA[j]
                numofcng += 1
                flag = True
    return outA, numofcng

def printlist(L):
    for itm in L[:-1]:
        print(itm, end = ' ')
    print(L[-1])

n = int(input())
A = list(map(int, input().split()))
outA, num = bubbleSort(A, n)
printlist(outA)
print(num)



Measured memory_bytes: 5616
import java.util.Scanner;
import java.util.Arrays;

public class Main {
  public static final long MOD = 1000000007;
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int K = sc.nextInt();
    int[] array = new int[N];
    Arrays.setAll(array, i -> sc.nextInt());
    int count1 = 0;
    int count2 = 0;
    for (int i = 0; i < N; i++)
      for (int j = 0; j < N; j++)
        if (array[i] > array[j]) {
          count1++;
          if (i < j)
            count2++;
        }
    long tmp = K % 1000000007;
    System.out.println(((tmp * (tmp - 1) / 2) % MOD * count1 + tmp * count2) % MOD);
  }
}

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

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

    vector<long long int> a(n);
    for(int i=0; i<n; i++){
        cin >> a[i];
    }
    sort(a.begin(),a.end());
    reverse(a.begin(),a.end());

    long long int ans = 0;
    multiset<long long int> f = {a[0]};
    for(int i=1; i<n; i++){
        ans += *prev(f.end());
        f.erase(prev(f.end()));
        f.insert(a[i]);
        f.insert(a[i]);
    }
    cout << ans << endl;
    return 0;
}

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

using ll = long long;
using vi = vector<int>;
using vi2 = vector<vector<int>>;
#define MP(a,b) make_pair((a),(b))
#define MT(...) make_tuple(__VA_ARGS__)

#define FOR(i,a,b) for(int i=(a);i<(b);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--)

#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl;
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl;

#define DCOUT(x,n) cout << fixed << setprecision(n) << (x) << endl;

#define sz(x) (int)(x).size()

template<typename T>inline istream& operator>>(istream&i,vector<T>&v)
{REP(j,sz(v))i>>v[j];return i;}

int main() {
    string S;
    int K;
    cin >> K >> S;
    int s = S.size();
    string answer;

    if(s<=K){
        cout << S << endl;
    }
    else{
        REP(i,K){
            answer.push_back(S[i]);
        }

        cout << answer << "..." << endl;
    }
}


Measured memory_bytes: 3632