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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> ii;
typedef tuple<int, int, int> iii;

typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<ld> vd;
typedef vector<ll> vl;

typedef set<int> si;
typedef set<ii> sii;
typedef set<ld> sd;
typedef set<ll> sl;

typedef map<int, int> mii;
typedef priority_queue<int> pqi;
typedef queue<int> qi;
 
#define mp make_pair
#define pb push_back
#define f first
#define s second

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

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

    int r, g, b, n;
    cin >> r >> g >> b >> n;
    vi a = {r, g, b};
    vector<vl> dp(3, vl(n + 1, 0));
    dp[0][0] = 1;
    for (int i = 0; i < 3; i++) {
        for (int j = 0; j <= n; j++) {
            if (i > 0) dp[i][j] += dp[i - 1][j];
            if (j - a[i] < 0) continue;
            dp[i][j] += dp[i][j - a[i]];
        }
    }

    cout << dp[2][n] << endl;
}

/*
USE LONG LONG!!!!

:pray: :fishy15:
:pray: :summitosity:
:pray: :prodakcin:

          .=     ,        =.
  _  _   /'/    )\,/,/(_   \ \
   `//-.|  (  ,\\)\//\)\/_  ) |
   //___\   `\\\/\\/\/\\///'  /
,-"~`-._ `"--'_   `"""`  _ \`'"~-,_
\       `-.  '_`.      .'_` \ ,-"~`/
 `.__.-'`/   (-\        /-) |-.__,'
   ||   |     \O)  /^\ (O/  | .        <-  BESSIE THE COW
   `\\  |         /   `\    /
     \\  \       /      `\ /
      `\\ `-.  /' .---.--.\
        `\\/`~(, '()      ('
         /(O) \\   _,.-.,_)    
        //  \\ `\'`      /
       / |  ||   `""""~"`
     /'  |__||
           `o
*/

Measured memory_bytes: 384
from collections import *
n=int(input())
l=[]
for i in range(n):
    l.append(input())
f=0
c=Counter(l)
for i in c.values():
    if(i>1):
        f=1
        break
if(f==1):
    print("No")
else:
    d=0
    for i in range(1,n):
        if(l[i-1][-1]!=l[i][0]):
            d=1
            break
    if(d==1):
        print("No")
    else:
        print("Yes")


Measured memory_bytes: 65264
#include<bits/stdc++.h>
#define pi acos(-1)
#define ll long long
#define pii pair<ll,ll>
#define piii pair<ll,pii>
#define debug(a) cout<<a<<'\n'
#define maxn 59 /// Still trying to be normal
#define MOD 1000000007
#define F first
#define S second
#define rep(i, a, b) for(ll i = a; i < (b); ++i)
#define per(i, b, a) for(ll i = b-1; i>=a ; i--)
#define trav(a, x) for(auto& a : x)
#define allin(a , x) for(auto a : x)
#define all(x) begin(x), end(x)
#define sz(x) (ll)(x).size()
using namespace std;
const ll INF = 1e14 + 15;
vector<pair<ll,pii> > adj[maxn]; /// endpoint, money cost, time
pii ex[maxn]; // money gain, time
ll dis[maxn][2559];/// endpoint , money
ll n,m,s;
void addedge(ll a,ll b,ll c,ll d){
    adj[a].push_back({b,{c,d}});
    adj[b].push_back({a,{c,d}});
}
void INFINITAR(){
    for(ll i=0;i<=n;i++){
        rep(j,0,2559){
            dis[i][j]=INF;
        }
    }
}
void dijkstra(ll x){
    INFINITAR();
    dis[x][s]=0;
    priority_queue<piii, vector<piii>, greater<piii> > pq;/// time, endpoint, money have
    pq.push({0,{x,s}});
    while(!pq.empty()){
        // cout<<pq.size()<<endl;
        auto inicio=pq.top();
        // cout<<f.F<<" "<<f.S.F<<" "<<f.S.S<<'\n';
        pq.pop();
        if(dis[inicio.S.F][inicio.S.S] < inicio.F)continue;
        // cout<<"oi\n";
        ll moneyprox;
        if(inicio.S.S<2500){
            moneyprox = min(2509LL,inicio.S.S + ex[inicio.S.F].F);
            if(inicio.F + ex[inicio.S.F].S < dis[inicio.S.F][moneyprox]){
                    dis[inicio.S.F][moneyprox] = inicio.F + ex[inicio.S.F].S;
                    // cout<<e.F<<" "<<moneyprox<<" "<<dis[e.F][moneyprox]<<endl;
                    pq.push({dis[inicio.S.F][moneyprox],{inicio.S.F,moneyprox}});
            }
        }
        for(auto final: adj[inicio.S.F]){
                moneyprox = inicio.S.S - final.S.F;
                if(moneyprox<0) continue;
                if(inicio.F + final.S.S< dis[final.F][moneyprox]){
                    dis[final.F][moneyprox]=inicio.F + final.S.S;
                    // cout<<e.F<<" "<<moneyprox<<" "<<dis[e.F][moneyprox]<<endl;
                    pq.push({dis[final.F][moneyprox],{final.F,moneyprox}});
                }        
            }
        }
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>n>>m>>s;
    s=min(s,2509LL);
    rep(i,0,m){
        ll a,b,c,d;
        cin>>a>>b>>c>>d;
        addedge(a,b,c,d);
    }
    rep(i,1,n+1){
        ll a,b;
        cin>>a>>b;
        ex[i] = make_pair(a,b);
    }
    dijkstra(1);
    rep(i,2,n+1){
        ll ans=INF;
        rep(j,0,2559){
            ans=min(ans,dis[i][j]);
        }
        cout<<ans<<'\n';
    }
}


Measured memory_bytes: 7304
//設定言語check
#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <limits.h>
#include <algorithm>
#include <iomanip>
#include <math.h>
using namespace std;

int main(){
  long long int N, K, have = 0, money = 1000, kabu = 0, ans = 0 ;
  cin >> N ;
  long long int A[N], com[N] = {} ;
  for(int i=0;i<N;i++){
    cin >> A[i] ;
  }
  for(int i=0;i<(N-1);i++){
    if(have == 0){
      if(A[i] < A[i+1]){
        com[i] = 1 ; // buy
        have = 1 ;
      }
    }
    else{
      if(A[i] > A[i+1]){
        com[i] = 2 ; // sell
        have = 0 ;
      }
    }
  }
  for(int i=0;i<(N-1);i++){
    if(com[i] == 1){
      kabu = money / A[i] ;
      money = money % A[i] ;
    }
    else if(com[i] == 2){
      money += kabu * A[i] ;
      kabu = 0 ;
    }
  }
  if(kabu > 0){
    money += kabu * A[N-1] ;
  }
  cout << money << endl ;
  return 0 ;
}  

Measured memory_bytes: 3668
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
#include<queue>
using namespace std;
const int mod = 1000000007;
#define ll long long

ll A[200010], B[200010];
int main()
{
	int N; cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> A[i];
		B[i] = A[i] - i;
	}
	sort(B, B + N);
	ll b = B[N / 2];
	ll ans = 0;
	for (int i = 0; i < N; i++) {
		ans += abs(A[i] - (b + i));
	}
	cout << ans << endl;
}


Measured memory_bytes: 3328
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>

using namespace std;

vector<vector<int>> g;

using ll = long long;

const ll mod = 1000000007;

pair<ll, ll> dfs(int i, int p = -1) {
    pair<ll, ll> res(1, 1);
    
    for (int to : g[i]) {
        if (to == p) {
            continue;
        }

        auto x = dfs(to, i);

        res.first = res.first * x.second % mod;
        res.second = res.second * (x.first + x.second) % mod;
    }

    return res;
}

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

    g.resize(n);

    for (int i = 0; i < n - 1; i++) {
        int x, y;
        cin >> x >> y;

        x--;
        y--;

        g[x].push_back(y);
        g[y].push_back(x);
    }

    auto res = dfs(0);

    cout << (res.first + res.second) % mod << endl;
}


Measured memory_bytes: 11264
#include <cstdio>
#include <cmath>
using namespace std;

int main()
{
	int n, a, b;
	scanf("%d%d%d", &n, &a, &b);
	if ((a == 1 && b == 2) || (a == n && b == n-1) || (n == 2) || ((int)(abs(a-b)) % 2 == 1))
		printf("Borys");
	else printf("Alice");
	return 0;
}

Measured memory_bytes: 128
open System

[<EntryPoint>]
let main argv =
    let nk = Console.ReadLine().Split() |> Array.map int
    let n, k = nk.[0], nk.[1] - 1
    let s = Console.ReadLine().ToCharArray()
    Array.set s k (s.[k] |> Char.ToLower)
    s |> Console.WriteLine
    0

Measured memory_bytes: 11220
#include <bits/stdc++.h>
#define BIT(n) (1LL << (n))
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPB(i, n) for (int i = 0; i < BIT(n); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORA(i, n) for (auto &&i : n)
#define FORS(i, m, n) for (int i = m; i <= n; i++)
#define DEBUG(x) cerr << #x << ": " << x << "\n"
#define PRINTALL(V)                                                            \
  for (auto v : (V)) {                                                         \
    cout << v << " ";                                                          \
  }                                                                            \
  cout << "\n";
#define ALL(v) v.begin(), v.end()
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
#define epb emplace_back
#define int long long
using namespace std;
template < class T > bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template < class T > bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template < class T > using vec = std::vector< T >;
template < class T > void print(const T &x) { cout << x << "\n"; }
const int MOD = 1000000007, INF = 1061109567;
const double EPS = 1e-10, PI = acos(-1.0);
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
signed main() {
  cin.tie(0), ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  print(min(A, B) + min(C, D));
}

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

int main() {
	int w, h;
	char ch[110][110];

	cin >> w >> h;
	for (int i = 0; i < w; i++) {
		for (int j = 0; j < h; j++) {
			cin >> ch[i][j];
		}
	}
	for (int i = 0; i < w; i++) {
		for (int j = 0; j < h; j++) {
			cout << ch[i][j];
		}
		cout << endl;
		for (int j = 0; j < h; j++) {
			cout << ch[i][j];
		}
		cout << endl;
	}
	return 0;

}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<climits>
using namespace std;
static const int MAX_N = 100;

int N, M, D;
string s[MAX_N];

int main(){
	cin >> N >> M >> D;
	for(int i = 0; i < N; i++) cin >> s[i];
	int ans = 0;
	for(int i = 0; i < N; i++){
		for(int j = 0; j < M; j++){
			bool flag_x = true, flag_y = true;
			for(int k = 0; k < D; k++){
				if(i + k >= N || s[i + k][j] == '#') flag_x = false;
				if(j + k >= M || s[i][j + k] == '#') flag_y = false;
			}
			if(flag_x) ans++;
			if(flag_y) ans++;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3164
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pii  pair<int,int>
#define vpii vector<pii>
#define vll  vector<ll>
#define vi  vector<int>
#define pb push_back
#define f  first
#define s  second

int main() {

  int a,b;
    cin>>a>>b;
    if((a+b)%3==0||a%3==0||b%3==0)
       cout<<"Possible";
     else
        cout<<"Impossible";
    
    
    

	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<bits/stdc++.h>
#include<string>
using namespace std;
int main()
{
  int n, k ;
  cin >> n >> k ;
  
  if(n%k==0){
    cout << 0 << endl;
    return 0 ;
  }else{
   int r = n%k ;
   cout << n/k+1-n/k << endl;
    return 0 ;
  }
  
}


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

int main() {
  int N, A, B;
  cin >> N >> A;
  
  if (N >= 1 && N <= 10000 && A >= 0 && A <= 1000 && N >= 500) {
    B = N / 500;
    B = N - B * 500;
    if (A >= B) {
      cout << "Yes" << endl;
    }
    else {
      cout << "No" << endl;
    }
  }
  else if (N < A) { 
    cout << "Yes" << endl;
  }
}

Measured memory_bytes: 3544
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007;
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    ll n,a;
    cin>>n;
    vector<int> v;
    for(int i=0;i<n;i++){
    	cin>>a;
    	auto itr=lower_bound(be(v),a);
    	if(itr==v.end())v.pb(a);
    	else *itr=a;
    }
    cout << v.size() <<endl;
    return 0;
}



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

int get(int x){
	int t=x;
	int s=0;
	while(t){
		s+=t%10;
		t/=10;
	}
	return s;
}

int n;

int ans=0x3f3f3f3f;
int res;

int main(){
	cin>>n;
	for(int i=1;i<=n-1;i++){
		res=get(i)+get(n-i);
		if(res<ans)ans=res;
	}
	cout<<ans<<endl;
}

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

int main(void){
  int i, k = 100000;

  cin >> i;

  for(int j = 1;j<=i;j++){
    k = k + k * 0.05;
    if(k % 1000 != 0) k += 1000 - (k % 1000);
  }

  cout << k << endl;

  return 0;
}

Measured memory_bytes: 3080
#include<iostream>
using namespace std;
int k,s,cnt=0;
int main()
{
    cin>>k>>s;
    for(int x=0;x<=k;x++)
    {
        for(int y=0;y<=k;y++)
        {
            if(s-x-y>=0&&s-x-y<=k) cnt++;
        }
    }
    cout<<cnt<<endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] l = new int[n];

        for (int i=0; i<n; i++) l[i] = sc.nextInt();
        Arrays.sort(l);
        int ans = 0;
        for (int i=0; i<n-1; i++){
            for (int j=i+1; j<n; j++){
                int lower = j;
                int upper = n;
                while (lower+1<upper){
                    int mid = (lower+upper)/2;
                    if (l[mid]<l[i]+l[j]){
                        lower = mid;
                    }else {
                        upper = mid;
                    }
                }
                ans += (lower-j);
            }
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 27792
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <iomanip>
#include <algorithm>
using namespace std;

int main() {
	int a, b, c;
  	cin >> a >> b >> c;
  	cout << a * b / 2 << endl;
  	return 0;
}

Measured memory_bytes: 256
WV = $<.read.split.map(&:to_i).each_slice(2).to_a
N,W = WV.shift
WV.sort_by! {|w,v| [w,-v]}
I = {}
WV.each.with_index { |(w,*),i| break if w > W; I[w] ||= i}
I[0] = N
K = I.keys
A = Array.new W+1
A[0] = [0,0]
l = [-1]
A.each_with_index {|(c,b),n|
  (c||0) > l[0] ? l=A[n] : next
  K.each_cons(2) {|w,x|
    i,j = I[w],I[x]
    break  if W < w+=n
    m = 1 << j
    next  if WV[i][1]+c <= l[0] || m <= (b&(m-1))+(1<<i)
	i += 1  while b[i] > 0
    m = (A[w]||l)[0]
    v = WV[i][1] + c
    A[w] = [v,b+(1<<i)]  if m < v
  }
}
p l[0]

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

const int mod = 1000000007;
struct modint{
  ll x;
  modint(ll x = 0): x(((x%mod)+mod)%mod){}
  
  modint operator-() const{
    return modint(-x);
  }
  
  modint& operator+=(const modint a){
    x += a.x;
    if(x >= mod) x -= mod;
    return *this;
  }
  
  modint& operator-=(const modint a){
    x -= a.x;   
    if(x < 0) x += mod;
    return *this;
  }
  
  modint& operator*=(const modint a){
    (x *= a.x) %= mod;
    return *this;
  }
  
  modint operator+(const modint a) const{
    modint res(*this);
    return res += a;
  }
  
  modint operator-(const modint a) const{
    modint res(*this);
    return res -= a;
  }
  modint operator*(const modint a) const{
    modint res(*this);
    return res *= a;
  }
  
  modint pow(ll t) const{
    if(!t) return 1;
    modint a = pow(t>>1);
    a *= a;
    if(t&1) a *= *this;
    return a;
  }
  
  modint inv() const{
    return pow(mod-2);
  }
  modint& operator/=(const modint a){
    return *this *= a.inv();
  }
  modint operator/(const modint a) const{
    modint res(*this);
    return res /= a;
  }
};

modint choose(ll n, ll a){
  modint x = 1, y = 1;
  rep(i,a){
    x *= (n-i);
    y *= (i+1);
  }
  return x/y;
}

int main(){
  ll n, a, b;
  cin >> n >> a >> b;
  
  modint x = modint(2).pow(n);
  x -= 1;
  x -= choose(n,a);
  x -= choose(n,b);
  cout << x.x  << endl;
}

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

int main() {
	int H;
	cin >> H;
	int W;
	cin >> W;
	vector<string> a(H);
	for (int h = 0; h < H; h++) {
		cin >> a.at(h);
	}

	for (int w = 0; w < W+2; w++) {
		cout << "#";
	}
	cout << endl;

	for (int h = 0; h < H; h++) {
		cout << "#";
		cout << a.at(h);
		cout << "#";
		cout << endl;
	}

	for (int w = 0; w < W+2; w++) {
		cout << "#";
	}
	cout << endl;
}

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

#include <algorithm>
#include <iomanip>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>

int main() {

    long long int a, b, m;
    cin >> a >> b >> m;

    long long int mia = 114514;
    long long int mib = 114514;
    vector< long long int > p, q;
    for ( long long int i = 0; i < a; i++ ) {
        long long int in;
        cin >> in;
        p.push_back( in );
        mia = min( mia, in );
    }
    for ( long long int i = 0; i < b; i++ ) {
        long long int in;
        cin >> in;
        q.push_back( in );
        mib = min( mib, in );
    }
    long long int ans = mia + mib;

    for ( long long int i = 0; i < m; i++ ) {
        long long int x, y, c;
        cin >> x >> y >> c;
        ans = min( ans, p[x-1] + q[y-1] - c );
    }

    cout << ans << endl;

    return 0;

}


Measured memory_bytes: 2548
import heapq
n, m = map(int, input().split())
g = [[] for _ in range(n)]
for i in range(m):
    a, b, c = map(int, input().split())
    g[a-1].append((b-1,c))
    g[b-1].append((a-1,c))
vs = [[False]*n for _ in range(n)]
for i in range(n):
    ds = [-1]*n
    hq = [(0,i,None)]
    while hq:
        c,idx,v = heapq.heappop(hq)
        if ds[idx] != -1:
            if ds[idx] == c:
                vs[v[0]][v[1]] = True
            continue
        ds[idx] = c
        if v != None:
            vs[v[0]][v[1]] = True
        for j in g[idx]:
            if ds[j[0]] == -1:
                heapq.heappush(hq,(c+j[1],j[0],(idx,j[0])))
            elif ds[j[0]] == c+j[1]:
                vs[idx][j[0]] = True
res = 0
for i in range(n):
    for j in g[i]:
        if vs[i][j[0]] == False:
            res += 1
print(res//2)

Measured memory_bytes: 70164
#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll h;
ll cal(ll x) {
	if(x==1) return 1;
	return 2*cal(x/2)+1;
}
int main() {
	scanf("%lld",&h);
	printf("%lld\n",cal(h));
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cstdio>
#include <algorithm>
#include <map>
#include <queue>
#define rep(i,n) for(int i = 0; i < n; i++)
#define INF 1000000000
#define MOD 1000000007
#define ll long long
using namespace std;
ll n,a,b,ans;
ll x[100000];
int main(){
    cin>>n>>a>>b;
    rep(i,n) cin>>x[i];
    rep(i,n-1){
        ans+=min((x[i+1]-x[i])*a,b);
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i ++)
#define irep(i,n) for (int i = (int)(n) - 1;i >= 0;--i)
using namespace std;
using ll = long long;
using PL = pair<ll,ll>;
using P = pair<int,int>;
constexpr int INF = 1000000000;
constexpr long long HINF = 1000000000000000;
constexpr long long MOD = 1000000007;// = 998244353;
constexpr double EPS = 1e-4;
constexpr double PI = 3.14159265358979;

int main() {
    int N;cin >> N;
    vector<vector<P>> G(N);
    rep(i,N - 1) {
        int a,b,c; cin >> a >> b >> c;
        --a; --b;
        G[a].emplace_back(b,c);
        G[b].emplace_back(a,c);
    }
    vector<int> color(N,-1);
    color[0] = 0;
    stack<int> st;
    st.push(0);
    while (!st.empty()) {
        int v = st.top(); st.pop();
        for (P &p:G[v]) {
            if (color[p.first] >= 0) continue;
            color[p.first] = (color[v] + p.second)%2;
            st.push(p.first);
        }
    }
    rep(i,N) cout << color[i] << '\n';
    return 0;
}

Measured memory_bytes: 9612
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
int main(void)
{
  int n, m, s, c;
  int ans = 0;
  int f[3] = {-1, -1, -1};
  int i = 0, J = 0, bo = 0;
  scanf("%d%d", &n, &m);
  bo = pow(10, n - 1);
  if (n == 1)
    bo = 0;
  for (i = 0; i < m; i++)
  {

    scanf("%d%d", &s, &c);
    if ((f[s - 1] != -1) && (f[s - 1] != c))
    {
      printf("-1\n");
      return 0;
    }
    if (f[s - 1] != -1)
      continue;
    f[s - 1] = c;
    if (n == 3)
    {
      if (s == 1)
        ans += c * 100;
      else if (s == 2)
        ans += c * 10;
      else
        ans += c;
    }
    else if (n == 2)
    {
      if (s == 1)
        ans += c * 10;
      else
        ans += c;
    }
    else
      ans += c;
  }
  if (m == 0)
  {
    printf("%d\n", bo);
    return 0;
  }
  if (n == 3)
  {
    if ((f[0] == f[1]) && (f[0] == f[2]) && (f[0] == 0))
      printf("0\n");
    else if ((f[0] == 0) && ((f[1] != 0) || (f[2] != 0)))
      printf("-1\n");
    else if (f[0] == -1)
      printf("%d\n", ans + bo);
    else
      printf("%d\n", ans);
  }
  else if (n == 2)
  {
    if ((f[0] == f[1]) && (f[0] == 0))
      printf("0\n");
    else if (((f[0] == 0) && (f[1] != 0)))
      printf("-1\n");
    else if (f[0] == -1)
      printf("%d\n", ans + bo);
    else
      printf("%d\n", ans);
  }
  else
  {
    printf("%d\n", ans);
  }
  return 0;
}

Measured memory_bytes: 128
import java.util.Scanner;

public class Main {

	public static void main(String[] args){
		  Scanner sc = new Scanner(System.in);
		  int N = sc.nextInt();
		  String S = sc.next();
		  sc.close();
		  
		  int answer = N;
		  
		  int[] a = new int[N];
		  if(S.charAt(0) == 'W') a[0] = 1;
		  
		  for(int i = 1; i < N; i++) {
			  if(S.charAt(i) == 'W') a[i] = a[i - 1] + 1;
			  else a[i] = a[i - 1];
		  }
		  		  
		  for(int i = 0; i < N; i++) {
			  int count;
			  if(i == 0) {
				  count = (N - 1) - (a[N - 1] - a[0]);
			  }else if(i == N - 1) {
				  count = a[N - 2];
			  }else {
				  count = a[i - 1] + ((N - 1 - i)- (a[N - 1] - a[i]));
			  }
			  answer = Math.min(answer, count);
		  }
		  
		  System.out.println(answer);
	      System.exit(0);
	    }
}

Measured memory_bytes: 30048
//
//  main.cpp
//  CoderWork
//
//  Created by Minoru Hayashi on 2020/02/29.
//  Copyright © 2020 Minoru Hayashi. All rights reserved.
//

#include <bits/stdc++.h>
using namespace std;

#define REP(i,n) for (int i=0; i<(n); i++)
#define REP2(i,x,n) for (int i=x; i<(n); i++)
#define ALL(n) begin(n), end(n)



void solve(void){

  int a, b;
  
  cin >> a >> b;
  
  string P, Q;
  
  P = to_string(a);
  Q = to_string(b);
  
  P = string(b, P[0]);
  Q = string(a, Q[0]);

  if(P>Q){
    cout << Q << endl;
  }
  else
  {
    cout << P << endl;
  }

  return;
}

int main(int argc, const char * argv[]) {



    // cinを高速にするためのおまじない
    cin.tie(0);
    ios::sync_with_stdio(false);
  
    solve();
 
    return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
 
public class Main {
	public void exec() throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(System.out);
    	out.println(
    			new Dice(br.readLine().split(" "))
    			.rolling(br.readLine().toCharArray())
    			.get(Dice.LABEL_TOP));
        out.flush();
    }
	
    public static void main(String[] args) throws IOException {
        new Main().exec();
    }
}

class Dice {
	public static final int LABEL_TOP=0;
	public static final int LABEL_NEAR=1;
	public static final int LABEL_RIGHT=2;
	public static final int LABEL_LEFT=3;
	public static final int LABEL_FAR=4;
	public static final int LABEL_BOTTOM=5;
	public static final int LABEL_MAX=6;
	public static final int DIR_N=0;
	public static final int DIR_W=1;
	public static final int DIR_S=2;
	public static final int DIR_E=3;
	public static final int DIR_MAX=4;
	public static final int[][] NEXT = {
			//[LABEL_TOP][DIR_N,W,S,E]
			{LABEL_FAR,LABEL_LEFT,LABEL_NEAR,LABEL_RIGHT},
			//[LABEL_NEAR][DIR_N,W,S,E]
			{LABEL_TOP,LABEL_NEAR,LABEL_BOTTOM,LABEL_NEAR},
			//[LABEL_RIGHT][DIR_N,W,S,E]
			{LABEL_RIGHT,LABEL_TOP,LABEL_RIGHT,LABEL_BOTTOM},
			//[LABEL_LEFT][DIR_N,W,S,E]
			{LABEL_LEFT,LABEL_BOTTOM,LABEL_LEFT,LABEL_TOP},
			//[LABEL_FAR][DIR_N,W,S,E]
			{LABEL_BOTTOM,LABEL_FAR,LABEL_TOP,LABEL_FAR},
			//[LABEL_BOTTOM][DIR_N,W,S,E]
			{LABEL_NEAR,LABEL_RIGHT,LABEL_FAR,LABEL_LEFT},
	};
	String[][] labels = new String[2][LABEL_MAX];
	int main=0;
	int sub=1;
	public Dice(String[] strLabels){
		labels[0]=strLabels;
	}
	public String get(int label) {
		return labels[main][label];
	}
	private void switchMainSub() {
		main = sub;
		sub = (sub+1)%2;
	}
	public int getDir(char c) {
		switch(c){
		case 'N': return 0;
		case 'W': return 1;
		case 'S': return 2;
		case 'E': return 3;
		default: throw new IllegalArgumentException();
		}
	}
	public Dice rolling(char[] cArray) {
		for(char c: cArray){
			rolling(c);
		}
		return this;
	}
	public Dice rolling(char c) {
		int dir = getDir(c);
		for(int label=0; label<LABEL_MAX; label++) {
			labels[sub][NEXT[label][dir]]=labels[main][label];
		}
		switchMainSub();
		return this;
	}
	
}

Measured memory_bytes: 24496
from bisect import bisect_right

n = int(input())

six = [0] + [6**i for i in range(1,8)]
nine = [0] + [9**i for i in range(1,7)]

dp = [float("inf")] * (n+1)
dp[0] = 0
for i in range(1, n+1):
    dp[i] = dp[i-1] + 1
    j = bisect_right(six, i) - 1
    if j: dp[i] = min(dp[i], dp[i-six[j]] + 1)
    k = bisect_right(nine, i) - 1
    if k: dp[i] = min(dp[i], dp[i-nine[k]] + 1)

print(dp[-1])


Measured memory_bytes: 3828
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;
int main()
{
	int a[20][20];
	int n,d; 
	cin >> n >> d;
	for (int i=0;i<n;i++)
	{
		for(int j=0;j<d;j++)
		{
			cin >> a[i][j];
		}
	}
	int ans = 0;
	for(int i=0;i<n;i++)
	{
		for (int j=i+1;j<n;j++)
		{
			double sum1 = 0;
			double sum2;
			for (int k=0;k<d;k++)
			{
				sum1+=(a[j][k]-a[i][k])*(a[j][k]-a[i][k]);
			}
			sum2 = sqrt(sum1);
			if(sum2-floor(sum2)<0.0000000001)	//floor()向下取整
			{
				ans++;
			} 
		}
	}
	cout << ans << endl;
		
	return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bits/stdc++.h>
#include <cstdint>
#include <iostream>
#include <iterator>
#include <vector>

// lib/util.hpp
#ifndef UTIL_HPP
#define UTIL_HPP


typedef ::std::int_fast64_t i64;
typedef ::std::uint_fast64_t u64;
typedef ::std::int_fast32_t i32;
typedef ::std::uint_fast32_t u32;

namespace tools {
  template <typename T>
  void read(::std::istream& is, ::std::vector<T>& vector, const typename ::std::vector<T>::size_type size) {
    vector.reserve(size);
    ::std::copy_n(::std::istream_iterator<T>(is), size, ::std::back_inserter(vector));
  }
  template <typename T>
  void read(::std::vector<T>& vector, const typename ::std::vector<T>::size_type size) {
    ::tools::read(::std::cin, vector, size);
  }

  template <typename T, ::std::size_t N>
  void read(::std::istream& is, ::std::array<T, N>& array) {
    ::std::copy_n(std::istream_iterator<T>(is), N, array.begin());
  }
  template <typename T, ::std::size_t N>
  void read(::std::array<T, N>& array) {
    ::tools::read(::std::cin, array);
  }
}

#endif

// main.cpp

int main() {
  std::string S;
  std::cin >> S;
  std::cout << (S[2] == S[3] && S[4] == S[5] ? "Yes" : "No") << std::endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <string>
#include <vector>
#include <limits>
#include <algorithm>
#include <utility>
#include <sstream>
#include <numeric>
#include <iterator>

using namespace std;

#define repd(i,a,b) for (int i=(a);i<(b);++i)
#define rep(i,n) repd(i,0,n)
typedef long long ll;
typedef pair<int, int> P;

int main(int argc, const char * argv[]) {
  int a, b, c;
  cin >> a >> b >> c;
  cout << c << ' ' << a << ' ' << b << endl;;
  return 0;
}


Measured memory_bytes: 888
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define all(x) x.begin(),x.end()
#define cmin(a,b) (a>b?a=b:a)
#define cmax(a,b) (a<b?a=b:a)
#define mem(a,k) memset(a,k,sizeof(a))
#define lop(i,s,t) for(int i=s;i<(t);++i)
#define rep(i,s,t) for(int i=s;i<=(t);++i)
#define dec(i,s,t) for(int i=s;i>=(t);--i)
#define fore(i,v) for(int i=g[v],d=es[i].d;i;i=es[i].nxt,d=es[i].d)
using namespace std;

#define Pr(f,...) fprintf(stderr,f,##__VA_ARGS__),fflush(stderr)

typedef long long ll;

template<typename T>
void read(T &x){
	x=0; 
	char c;
	for(c=getchar();!isdigit(c);c=getchar()); 
	for(;isdigit(c);c=getchar())x=x*10+c-'0'; 
}

const int N=2e5+50,P=1e9+7; 

int mul(int a,int b){ return 1ll*a*b%P; }
int add(int a,int b){ a+=b; return a>=P?a-P:a; }
int sub(int a,int b){ a-=b; return a<0?a+P:a; }
int gcd(int a,int b){ return !b?a:gcd(b,a%b); }

int n,m,a[N],b[N],f[N],s[N];
int main(int argc,char *argv[]){
#ifdef CURIOUSCAT
#endif
	scanf("%d",&n); 
	rep(i,1,n)scanf("%d",a+i); 
	b[m=1]=a[1];
	rep(i,2,n)if(a[i]!=a[i-1])b[++m]=a[i];
	f[0]=1;
	rep(i,1,m){
		f[i]=add(f[i-1],s[b[i]]); 
		s[b[i]]=add(s[b[i]],f[i-1]);
	}
	printf("%d\n",f[m]);
	return 0; 
}


Measured memory_bytes: 3328
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int tap = 0;
        int num = 1;
        while (true) {
            if (num >= b) {
                System.out.println(tap);
                break;
            }
            tap++;
            num = tap * a - (tap - 1);
        }
    }

}


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

namespace ConsoleApp2
{
    class Program
    {
        static void Main(string[] args)
        {
            var solver = new Solver();
            solver.Calc();
        }
    }

    public class Solver
    {
        public void Calc()
        {

            var p = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();
            var N = p[0];
            var K = p[1];

            var member = new List<int>(Enumerable.Range(1, N));

            foreach (var j in Enumerable.Range(0, K))
            {
                var d = int.Parse(Console.ReadLine());
                var a = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();
                foreach (var cake in a)
                {
                    if (member.FirstOrDefault(x => x == cake) != 0)
                    {
                        member.Remove(cake);

                    }
                }
            }

            Console.WriteLine(member.Count);


        }


    }

}


Measured memory_bytes: 30232
#include <iostream>
#include <string>
#include <algorithm>
#include <numeric>
using namespace std;
int A[1005][1005]={};

int main() {
  int j,k;
  string a,b;
  cin >> a >> b;
  for(j=1;j<=a.size();j++) A[j][0] = j;
  for(k=1;k<=b.size();k++) A[0][k] = k;

  for(j=1;j<=a.size();j++) {
    for(k=1;k<=b.size();k++) {
      int m = min(A[j-1][k]+1, A[j][k-1]+1);
      if(a[j-1] == b[k-1]) {
        m = min(m,A[j-1][k-1]);
        A[j][k] = m;
      }else {
        m = min(m,A[j-1][k-1]+1);
        A[j][k] = m;
      }
    }
  }
  cout << A[a.size()][b.size()] << endl;
  return 0;
}


Measured memory_bytes: 7096
program abc20
 implicit none
 integer::A,B,C,K,ia,ib,ic
 read(*,*)A,B,C
 read(*,*)K
 do ia=0,K
  do ib=0,K-ia
   do ic=0,K-ia-ib
    if(A*2**ia<B*2**ib.and.B*2**ib<C*2**ic)then
     print'(a)',"Yes"
     stop
    end if
   end do
  end do
 end do
 print'(a)',"No"
end program abc20

Measured memory_bytes: 2944
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int main() {
  int n,t,x,y;
  int nt,nx,ny;
  scanf("%d\n",&n);
  nt=0;
  nx=0;
  ny=0;
  while (scanf("%d %d %d\n",&t,&x,&y )!=EOF) {

    if (abs(nx-x)+abs(ny-y)>t-nt) {
      printf("No\n");
      return 0;
    }
    if((t-nt-abs(nx-x)-abs(ny-y))%2==1){
      printf("No\n");
      return 0;
    }
    nx=x;
    ny=y;
    nt=t;
  }
  printf("Yes\n");
  return 0;
}


Measured memory_bytes: 256
<?php

class Edge {
    public $fromNode, $toNode, $cap, $rev;
    function __construct($fromNode, $toNode, $cap) {
        $this->fromNode = $fromNode;
        $this->toNode = $toNode;
        $this->cap = $cap;
        $this->rev = null;
    }
}

class MaxFlow {
    public $size, $edges, $level;

    function __construct($v) {
        $this->size = $v;
        $this->edges = array_fill(0, $v, []);
    }

    function addEdge($fromNode, $toNode, $cap) {
        $forEdge = new Edge($fromNode, $toNode, $cap);
        $backEdge = new Edge($toNode, $fromNode, 0);
        $forEdge->rev = $backEdge;
        $backEdge->rev = $forEdge;
        $this->edges[$fromNode][] = $forEdge;
        $this->edges[$toNode][] = $backEdge;
    }

    function bfs($source, $sink) {
        $this->level = array_fill(0, $this->size, null);
        $this->level[$source] = 0;
        $que = new SplQueue();
        $que->enqueue($source);
        while (!$que->isEmpty()) {
            $node = $que->dequeue();
            $newLevel = $this->level[$node] + 1;
            foreach ($this->edges[$node] as $edge) {
                if ($edge->cap and $this->level[$edge->toNode] === null) {
                    $this->level[$edge->toNode] = $newLevel;
                    $que->enqueue($edge->toNode);
                }
            }
        }
        return !is_null($this->level[$sink]);
    }

    function dfs($node, $sink, $f) {
        if ($node === $sink) return $f;

        foreach ($this->edges[$node] as $edge) {
            if ($edge->cap and $this->level[$edge->fromNode] < $this->level[$edge->toNode]) {
                $newFlow = $this->dfs($edge->toNode, $sink, min($f, $edge->cap));
                if ($newFlow) {
                    $edge->cap -= $newFlow;
                    $edge->rev->cap += $newFlow;
                    return $newFlow;
                }
            }
        }
        return 0;
    }

    function run($source, $sink) {
        $flow = 0;
        $INF = 100;
        while ($this->bfs($source, $sink)) {
            $addFlow = $INF;
            while ($addFlow) {
                $addFlow = $this->dfs($source, $sink, $INF);
                $flow += $addFlow;
            }
        }
        return $flow;
    }
}

list($V, $E) = explode(" ", trim(fgets(STDIN)));
$net = new MaxFlow((int)$V);
for ($i = 0; $i < (int)$E; $i++) {
    list($u, $v, $c) = explode(" ", trim(fgets(STDIN)));
    $net->addEdge((int)$u, (int)$v, (int)$c);
}
echo $net->run(0, $V - 1) . "\n";


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

int main() {
    string S;
    cin >> S;
    int zero = 0;
    int one = 0;
    rep(i, S.size()) {
        if (S[i] == '0') zero += 1;
        else one += 1;
    }
    cout << 2*min(zero, one) << endl;
    return 0;
}

Measured memory_bytes: 512
N = int(input())
A = list(map(int,input().split())) 
A.sort()
mx = A[-1]
E = [False]*(mx + 3)
ans = 0
A += [float("inf")]*2
for i in range(N):
    a = A[i]
    if not(E[a]) and A[i+ 1] != A[i]:
        ans += 1
    for j in range(1,(mx // a )+ 1):
        E[a*j] = True

print(ans)

Measured memory_bytes: 109392
#include <stdio.h>
#include <string>
#include <iostream>
#include <iomanip>
#include <map>
#include <algorithm>
#include <vector>
#include <math.h>
#define MOD 1000000007
using namespace std;

int main(void){
    int h,w,ans=0;
    cin >> h >> w;       
    if(h<w){
        int temp=h;
        h=w;w=temp;
    }
    ans=min(h,w);
    if(h%3==0||w%3==0){
        ans=0;
    }else if(h%2==0||w%2==0){
        if(h%2==0)ans=min(ans,h/2);
        if(w%2==0)ans=min(ans,w/2);
    }else {
        ans=min(ans,abs((h-1)*w/2-(w+1)/2*(h-1)/2));
        ans=min(ans,abs((w-1)*h/2-(h+1)/2*(w-1)/2));
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;

#define MAX 100

char data[MAX][MAX/2][MAX];
int plen, cnum, width, cspace, page;
int x, y;
string ss;

void init(){
  page = 0;
  for(int i = 0 ; i < MAX ; i++){
    for(int j = 0 ; j < MAX/2 ; j++){
      for(int k = 0 ; k < MAX ; k++){
        data[i][j][k] = '.';
      }
    }
  }
}

bool check(){
  bool ok = true;
  if(ss.empty()) return ok;

  for(int i = 0 ; i < plen ; i++){
    for(int j = 0 ; j < cnum*width+cspace*(cnum-1) ; j++){
      if(data[i][j][page] != '.') return ok;
    }
  }
  return !ok;
}

void change(){
  y++;
  if(y == plen){
    y = 0;
    x++;
    if(x == cnum){
      x = y = 0;
      page++;
    }
  }
}

void insert(string &str){
  int size = str.size(), start;
  int end, p = 0;
  bool flg = true;

  while(flg){
    start = x*(width+cspace);
    if(size - p <= width){
      end = start + size - p;
      flg = false;
    }else{
      flg = true;
      end = start + width;
    }
    for(int i = start ; i < end ; i++, p++){
      if(p == size){ 
        flg = false;
        break;
      }
      data[y][i][page] = str[p];
    }
    change(); 
  }
}

void print(){
  if(!check()) page--;
  for(int k = 0 ; k <= page ; k++){
    for(int i = 0 ; i < plen ; i++){
      for(int j = 0 ; j < cnum*width+cspace*(cnum-1) ; j++){
        cout << data[i][j][k];
      }
      cout << endl;
    }
    cout << '#' << endl;
  }
  cout << '?' << endl;
}

int main(){
  string str;
  while(cin >> plen && plen){
    init();
    cin >> cnum >> width >> cspace;

    cin.ignore();
    x = y = 0;
    while(getline(cin,str), str != "?"){
      ss = str;
      if(str.empty()){
        change();
      }else{
        insert(str);
      }
    }
    print();
  }

  return 0;
}

Measured memory_bytes: 1700
/*
Author: Racer5x
 ***************************************   UNAUTHORISED COPYING OF CODE PROHIBITED   **********************************
*/
 
/*#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")*/
 
#include<bits/stdc++.h>
#define int         long long
#define double      long double
#define pb          emplace_back
#define pf          emplace_front
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define rall(a)     (a).rbegin(),(a).rend()
#define x           first
#define y           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define hell        998244353 
#define PI          3.141592653589
#define tezz        ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define MAX         2000000000000000000
#define M           1000000007
using namespace std;
 
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
int power(int x,int n){
    int result=1;
    while(n>0)
    {
        if(n % 2 ==1)
            result=(result * x) % M;
        x=(x*x)% M;
        n=n/2;
    }
    return result % M;
}

int n;
vi adj[100005];
int dp[100005], ans[100005];
bool vis[100005] = {false};

void dfs(int v){
    if(vis[v]) return;
    vis[v] = true;

    for(int x:adj[v]){
        if(!vis[x]){
            dfs(x);
        }
    }

    if(adj[v].size() == 1){
        for(int x:adj[v]){
            if(dp[x]) goto label;
        }
        dp[v] = 1;
        ans[v] = 2;
    }

    label:
        int ans1=1, ans2=1;
        for(int x:adj[v]){
            if(dp[x]){
                ans2 = (ans2 * ans[x])%M;
                ans1 = (ans1 * dp[x])%M;
            }
        }
        dp[v] = ans2;
        ans[v] = (ans1 + ans2)%M;
}

signed main()
{
    tezz

    cin>>n;
    for(int i=0;i<n-1;i++){
        //cout<<'t';
        int a,b;
        cin>>a>>b;
        adj[a].pb(b);
        adj[b].pb(a);
    }
    dfs(1);
    cout<<ans[1];
}

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

using namespace std;
using ll = long long;
using ii = pair<ll, ll>;

const int MAX { 2010 };

int dist[MAX][MAX];

vector<int> solve(int N, int X, int Y)
{
    for (int u = 1; u <= N; ++u)
        for (int v = u + 1; v <= N; ++v)
            dist[u][v] = min(v - u, abs(u - X) + 1 + abs(v - Y));

    vector<int> ans(N);

    for (int u = 1; u <= N; ++u)
        for (int v = u + 1; v <= N; ++v)
            ans[dist[u][v]]++;

    return ans;
}

int main()
{
    ios::sync_with_stdio(false);

    int N, X, Y;
    cin >> N >> X >> Y;

    auto ans = solve(N, X, Y);

    for (int i = 1; i < N; ++i)
        cout << ans[i] << '\n';

    return 0;
}


Measured memory_bytes: 17280
N, M = map(int,input().split())
dist = [0] + [float('inf')] * (N - 1)

a = []
b = []
c = []

for i in range(M):
    i,j,k = map(int,input().split())
    a.append(i)
    b.append(j)
    c.append(-1*k)

INF = float('inf')

for i in range(N-1):
    for j in range(M):
        if dist[a[j] - 1] == INF: continue
        if dist[b[j] - 1] > dist[a[j] - 1] + c[j]:
            dist[b[j] - 1] = dist[a[j] - 1] + c[j]
        
ans = dist[N -1]

negative = [False] * N

for i in range(N):
    for j in range(M):
        if dist[a[j] - 1] == INF: continue
        if dist[b[j] - 1] > dist[a[j] - 1] + c[j]:
            dist[b[j] - 1] = dist[a[j] - 1] + c[j]
            negative[b[j] - 1] = True

        if negative[a[j] - 1] == True:
            negative[b[j] - 1] = True

if negative[N - 1]:
    print('inf')
else:
    print(-1 * ans)


Measured memory_bytes: 47704
#include <algorithm>
#include <iostream>
#include <vector>
#include <cstdio>
using namespace std;

long long dfs(const vector<vector<int>> &G, const vector<long long> &A, int v, int prev){
  if(G[v].size() == 1 and G[v][0] == prev) return A[v];
  long long s = 0, m = -1;
  for(auto v_ : G[v]){
    if(v_ == prev) continue;
    long long t = dfs(G,A,v_,v);
    if(t < 0) return -1;
    m = max(m,t);
    s += t;
  }
  long long d = s - A[v];
  if(d >= 0 and s - 2*d >= 0 and s - m >= d) return s - 2*d;
  return -1;
}

int main(){
  int N;
  cin >> N;
  vector<vector<int>> G(N);
  vector<long long> A(N);
  for(int i = 0; i < N; ++i) cin >> A[i];
  for(int i = 0; i < N-1; ++i){
    int a, b;
    cin >> a >> b;
    --a,--b;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  int v = 0;
  for(int i = 0; i < N; ++i){
    if(G[i].size() > 1) continue;
    v = i;
    break;
  }
  long long ans = dfs(G,A,v,-1);
  if(ans == A[v]) cout << "YES" << endl;
  else cout << "NO" << endl;
}


Measured memory_bytes: 15872
def checkACGT(s):
    for i in range(len(s)):
        if s[i] == "A" or s[i] == "G" or s[i] == "C" or s[i] == "T":
            continue
        else:
            return False
    return True

s=input()
n = len(s)
check = []
check.append(s)
while True:
    if not check:
        print(0)
        break
    if checkACGT(check[0]):
        print(len(check[0]))
        break
    else:
        if len(check[0]) == 1:
            check.pop(0)
            continue
        check.append(check[0][1:])
        check.append(check[0][:len(check[0])-1])
        check.pop(0)

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

int main() {
  int A,B,C,D; cin >>A >>B >>C >>D;
  int ans=min(A,B)+min(C,D);
  cout <<ans <<endl;
  return 0;
}


Measured memory_bytes: 256
Q=int(input())
LR=[list(map(int,input().split())) for i in range(Q)]

x=10**5+1
import math 
L=math.floor(math.sqrt(x))#平方根を求める

Primelist=[i for i in range(x+1)]
Primelist[1]=0#1は素数でないので0にする.
 
for i in Primelist:
    if i>L:
        break
    if i==0:
        continue
    for j in range(2*i,x+1,i):
        Primelist[j]=0

ANSLIST=[0]*(10**5+1)

for i in range(1,10**5+1,2):
    if Primelist[i]!=0 and Primelist[(i+1)//2]!=0:
        ANSLIST[i]=1

for i in range(1,10**5+1):
    ANSLIST[i]=ANSLIST[i-1]+ANSLIST[i]

for l,r in LR:
    print(ANSLIST[r]-ANSLIST[l-1])


Measured memory_bytes: 33072
# import numpy as np
# import math
# import copy
# from collections import deque
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10000)


def f(x):
    if x == 1:
        return 1
    return 2 * f(x//2) + 1


def main():
    H = int(input())

    res = f(H)

    print(res)



main()


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

int main() {
    int K, S; cin >> K >> S;
    long long ans = 0;
    for (int k = 0; k <= K; k++) {
        ans += max(0, min(S - k, K) - max(0, S - k - K) + 1);
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <sstream>
#include <math.h>
#include <queue>
#include <map>
#include <set>
#include <ios>     // std::left, std::right
#include <iomanip> // std::setw(int), std::setfill(char)
using namespace std;


int main(){
long long N,M;
cin>>N>>M;
long long p;
std::string str;
int AC[N]={};
long long WA[N]={};
for(int i=0;i<M;++i){
  cin>>p>>str;
  p--;
  //ACだった場合
  if(str=="AC"){
    AC[p]=1;
  }
  //WAだった場合
  else if(str=="WA"){
    if(AC[p]!=1){
      WA[p]+=1;
    }
  }
}
long long ans=0;
long long pena=0;
for(int i=0;i<N;++i){
  if(AC[i]==1){
    ans+=1;
    pena+=WA[i];
  }
}
cout<<ans<<" "<<pena<<"\n";
return 0;
}

Measured memory_bytes: 1536
import itertools
import math
n=int(input())
l=list(map(int,input().split()))
if len(l)<=2:
    print('0')
else:
    c = list(itertools.combinations(l, 3))
    count=0
    r=math.factorial(len(l)) // (math.factorial(len(l) - 3) * 6)
    for i in range(r):
        if c[i][0]==c[i][1] or c[i][1]==c[i][2] or c[i][2]==c[i][0]:
            pass
        else:
            if c[i][0]+c[i][1]>c[i][2] and c[i][1]+c[i][2]>c[i][0] and c[i][2]+c[i][0]>c[i][1]:
                count+=1
            else:
                pass
    print(count)

Measured memory_bytes: 20540
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include <bitset>
#include<math.h>
using namespace std;
#define INF 110000000000
#define MOD 1000000007
typedef long long ll;
typedef pair<ll,int> P;

ll d[210][210]; //d[u][v]は辺e=(u,v)のコスト(存在しない場合はINF，d[i][i]=0)
int v; //頂点数

//(V^3)
void warshall_floyd(){
  for(int k=0;k<v;k++){
    for(int i=0;i<v;i++){
      for(int j=0;j<v;j++) d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
    }
  }
}

vector<int> V[110000];
int color[110000];

//二部グラフならtrueを返す
bool dfs(int x,int c){
  color[x]=c;
  for(int i=0;i<V[x].size();i++){
    //隣接している頂点が同じ色ならfalse
    if(color[V[x][i]]==c) return false;
    //隣接している頂点がまだ塗られていないなら-cで塗る
    if(color[V[x][i]]==0 && !dfs(V[x][i],-c)) return false;
  }
  return true;
}


void init(){
  for(int i=0;i<210;i++){
    for(int j=0;j<210;j++){
      if(i==j) d[i][j]=0;
      else d[i][j]=INF;
    }
  }
}

int main(){
    cin>>v;
    char temp;
    init();
    for(int i=0;i<v;i++){
        for(int j=0;j<v;j++){
            cin>>temp;
            if(temp=='1'){
                V[i].push_back(j);
            d[i][j]=1;
            }
            
        }
    }
    if(dfs(1,1)){
        warshall_floyd();
        ll ans=0;
        for(int i=0;i<v;i++){
            for(int j=0;j<v;j++){
                ans=max(ans,d[i][j]);
                //cout<<i<<" "<<j<<" "<<d[i][j]<<endl;
            } 
        }
                    cout<<ans+1<<endl;

    }else cout<<-1<<endl;
}


Measured memory_bytes: 3328
class Array
  def med
    if size.odd?
      self[size/2]
    else
      Rational( self[size/2] + self[size/2-1], 2 )
    end
  end
end

n = gets.to_s.to_i
a, b = Array.new(n){ gets.to_s.split.map{|e| e.to_i } }.transpose

a.sort!
b.sort!

ans = 0
if n.odd?
  ans = [0, b.med - a.med + 1].max
else
  ans = [0, ( b.med - a.med ) / (1/2r) + 1].max.to_i
end

puts ans

Measured memory_bytes: 32968
#!/usr/bin/perl
my ($n,$p) = map { $_ - 0 } split(/\s+/,<STDIN>);
my @f=(2);
my @d=();
$#d=1000000;
for(my $i=3;$i<=$#d;$i+=2){
  next if $d[$i];
  push(@f,$i);
  for(my $j=3*$i;$j<=$#d;$j+=2*$i){
    $d[$j] = 1 if $j<=$#d;
  }
}
my %fa = ();
for(my $i=0;$i<=$#f;$i++){
  last if $p == 1;
  while( $p % $f[$i] == 0 ){
    $p /= $f[$i];
    $fa{$f[$i]}++;
  }
}
$fa{$p}++ if $p>1;
my $res = 1;
foreach my $k (keys %fa){
  if( $fa{$k}>=$n ){
    $res *= ($k - 0) ** int($fa{$k} / $n);
  }
}
print "$res\n";


Measured memory_bytes: 20864