akhauriyash/Code-Regression huggingface dataset:
public class Main{
  public void run(java.io.InputStream in, java.io.PrintStream out){
    java.util.Scanner sc = new java.util.Scanner(in);
    int n, i, j, count;
    String s;
    char[] c;

    n = sc.nextInt();
    for(;n-- > 0;){
      s = sc.next();
      c = new char[s.length()];
      for(i = 0;i < s.length();i++)c[i] = s.charAt(i);
      for(i = 0;i < s.length();i = ++j){
        count = 0;
        for(j = i;j < s.length();j++){
          if(c[j] == '0'){
            if(count == 0)break;
            if(c[j - 1] == '1'){
              if(count % 5 == 1)out.print(".");
              else if(count % 5 == 2)out.print(",");
              else if(count % 5 == 3)out.print("!");
              else if(count % 5 == 4)out.print("?");
              else out.print(" ");
              break;
            }else if(c[j - 1] == '2'){
              out.print((char)('a' + (2 + count) % 3)); break;
            }else if(c[j - 1] == '3'){
              out.print((char)('d' + (2 + count) % 3)); break;
            }else if(c[j - 1] == '4'){
              out.print((char)('g' + (2 + count) % 3)); break;
            }else if(c[j - 1] == '5'){
              out.print((char)('j' + (2 + count) % 3)); break;
            }else if(c[j - 1] == '6'){
              out.print((char)('m' + (2 + count) % 3)); break;
            }else if(c[j - 1] == '7'){
              out.print((char)('p' + (3 + count) % 4)); break;
            }else if(c[j - 1] == '8'){
              out.print((char)('t' + (2 + count) % 3)); break;
            }else if(c[j - 1] == '9'){
              out.print((char)('w' + (3 + count) % 4)); break;
            }
          }else count++;
        }
      }
      out.println();
    }

    sc.close();
  }
  public static void main(String[] args){
    (new Main()).run(System.in, System.out);
  }
}

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

int main(){
  int n;
  cin >> n;
  vector<int> hai(n);
  for(int i=0;i<n;i++){
    cin >> hai.at(i);
  }
  sort(hai.begin(),hai.end());
  reverse(hai.begin(),hai.end());
  int a=0,b=0;
  for(int i=0;i<n;i++){
    if(i%2==0){
      a += hai.at(i);
    }else{
      b += hai.at(i);
    }
  }
  cout << a-b <<endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cmath>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<functional>
#include<algorithm>
#include<cstdio>
#include<math.h>
#include<unordered_map>
using namespace std;
typedef long long ll;
ll x[100000];
signed main() {
	ll n, a, b;
	cin >> n >> a >> b;
	for (ll i = 0; i < n; i++) {
		cin >> x[i];
	}
	ll sum = 0;
	for (ll i = 0; i < n - 1; i++) {
		if ((x[i + 1] - x[i])*a > b) {
			sum += b;
		}
		else {
			sum += ((x[i + 1] - x[i])*a);
		}
	}
	cout << sum << endl;
	cin >> n;
}

Measured memory_bytes: 1024
using System;
using System.Collections.Generic;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            var hw = Console.ReadLine().Split(' ');
            var H = int.Parse(hw[0]);
            var W = int.Parse(hw[1]);
            var hw1 = Console.ReadLine().Split(' ');
            var h = int.Parse(hw1[0]);
            var w = int.Parse(hw1[1]);

            var a = w * H;
            var b = h * W;
            var s = h * w;
            var z = H * W;

            Console.WriteLine(s-((a + b)-z));
        }
    }
}


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

using namespace std;

typedef long long          ll;
typedef unsigned long long ull;
typedef vector<int>	       vi;
typedef vector<bool>       vb;
typedef map<int, int>      mii;
typedef pair<int, int>     ii;

#define INF                0x3f3f3f3f
#define INFLL              0x3f3f3f3f3f3f3f3f
#define each(x, s)         for(auto& x : s)
#define loop(x)	           for(int i = 0;i < x;i++)
#define vloop(v, x)        for(int v = 0;v < x;v++)
#define avg(l, r)          l + (r - l) / 2
#define iter(a)            a.begin(), a.end()
#define riter(a)           a.rbegin(), a.rend()
#define endl               "\n"

const ll mod = 1000000007;

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

	int x, n;
	cin >> x >> n;
	vi a(n);
	loop(n) cin >> a[i];
	sort(iter(a));
	int p = lower_bound(iter(a), x) - a.begin();
	int b = x, c = x;
	if (n) for (int i = p;i >= 0 and a[i] == b;i--, b--); 
	for (int i = p;i < n and a[i] == c;i++, c++);
	cout << (abs(x - b) <= abs(x - c) ? b : c) << endl;
	return 0;
}



Measured memory_bytes: 3612
from heapq import heappushpop, heappush, heappop, heapify
N, M = map(int, input().split())
a = [-int(a) for a in input().split()]
heapify(a)
t = heappop(a) / 2
for _ in range(M - 1):
  t = heappushpop(a, t) / 2
heappush(a, t)
print(sum(int(-x) for x in a))


Measured memory_bytes: 14184
x, k, d = map(int, input().split())

x = abs(x)

wari = x//d
amari = k-wari
p = x - (d*wari)

if wari >= k:
    print(x-(d*k))
else:
    if amari%2 == 0:
        print(p)
    else:
        print(d-p)


Measured memory_bytes: 61844
#include <iostream>

using namespace std;

int main(int argc, char **argv)
{
	int n, max, min, s, t;
	
	while(1){
		cin >> n;
		if(n == 0){
			break;
		}
		min = 1001;
		max = s = 0;
		for(int i = 0; i < n; i++){
			cin >> t;
			if(t < min){
				min = t;
			}
			if(max < t){
				max = t;
			}
			s += t;
		}
		
		cout << (s-min-max)/(n-2) << endl;
	}
	
	return 0;
}

Measured memory_bytes: 0
import sys
import math
import bisect
import re

def solve(A):
    n = len(A)
    m = len(A[0])
    dp = []
    for i in range(n):
        dp.append([0] * m)
    for i in range(n):
        for j in range(m):
            dp[i][j] = A[i][j]
            if i:
                dp[i][j] = max(dp[i][j], dp[i-1][j] + A[i][j])
            if j:
                dp[i][j] = max(dp[i][j], dp[i][j-1] + A[i][j])
    '''
    for i in range(n):
        print('A[%d]: %s' % (i, str(A[i])))
    for i in range(n):
        print('dp[%d]: %s' % (i, str(dp[i])))
    '''
    return dp[n-1][m-1]

def main():
    n = 2
    m = int(input())
    A = []
    for i in range(n):
        A.append(list(map(int, input().split())))
    print(solve(A))

if __name__ == "__main__":
    main()


Measured memory_bytes: 38256
//
// author  : Abhishek
//
#include <bits/stdc++.h>

#define ll long long
#define db double
#define deb(x) cout<<#x<<": "<<x<<"\n"
#define all(x) x.begin(),x.end()
#define fo(i, n) for(i=0 ; i<n ; i++)
#define Fo(i, k, n) for(i=k ; i<n ; i++)

using namespace std;

const ll mod = 1000000007;
const ll N = 300005;  // array size
const ll inf = 10000000000000000;


void print(vector<ll> v) {
    ll i;
    fo(i, v.size())cout << v[i] << " ";
    cout << "\n";
}

vector<ll> read(ll n) {
    ll i;
    vector<ll> arr(n, 0);
    fo(i, n)cin >> arr[i];
    return arr;
}

vector<ll> read(ll n, ll k) {
    ll i;
    vector<ll> arr(n + k, 0);
    Fo(i, k, n + k)cin >> arr[i];
    return arr;
}

bool isEven(ll n) {
    return n % 2 == 0;
}

bool isOdd(ll n) {
    return n % 2 != 0;
}


void solve() {
    ll t;
    cin >> (t);
    while (t--) {

        ll i, j, k, n, m, p, q, x, y, a, b, l, r;


    }
}

int main() {

#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    ll i, j, k, n, m, p, q, x, y, a, b, l, r;


    cin >> n;
    vector<ll> arr(n);
    arr = read(n);

    ll ans = 0;

    i = 0;
    while (i < n) {
        j = i;
        ll ct= 0;
        while (j + 1 < n && arr[j] >= arr[j + 1]) {
            j++;
            ct++;
        }

        ans = max(ct,ans);

        i = j+1;

    }


    cout << ans;


    return 0;
}




Measured memory_bytes: 4748
#include <algorithm>
#include <bits/stdc++.h>
#include<iostream>
#include<string>
using namespace std;
#define rep(i, n) for (int i = 0; i <(int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define ll long long
const ll MOD=10000007;
int main(){
int n,m;cin >> n >> m;
int l[m],r[m];
int lmax=0;
int rmin=MOD;
rep(i,m){cin >> l[i] >> r[i];
lmax=max(lmax,l[i]);
rmin=min(rmin,r[i]);
}
if(rmin>=lmax)cout<<rmin-lmax+1<<endl;
else cout<<0<<endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <queue>
#include <set>
#include <vector>

using namespace std;

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

    vector<int> a(n + m - 1), b(n + m - 1);
    for (int i = 0; i < n + m - 1; i++) {
        cin >> a[i] >> b[i];
    }

    vector<set<int>> s(n, set<int>()), t(n, set<int>());
    for (int i = 0; i < n + m - 1; i++) {
        s[a[i] - 1].insert(b[i] - 1);
        t[b[i] - 1].insert(a[i] - 1);
    }

    queue<int> que;
    vector<int> res(n);
    for (int i = 0; i < n; i++) {
        if (t[i].size() == 0) {
            que.push(i);
            res[i] = -1;
        }
    }

    while (!que.empty()) {
        int q = que.front();
        que.pop();

        for (set<int>::iterator i = s[q].begin(); i != s[q].end(); i++) {
            t[*i].erase(q);
            if (t[*i].size() == 0) {
                que.push(*i);
                res[*i] = q;
            }
        }
    }

    for (int i = 0; i < n; i++) {
        cout << res[i] + 1 << endl;
    }
}


Measured memory_bytes: 21120
#include <bits/stdc++.h>
using namespace std;
#define mod 998244353
#define MOD 1000000007
#define inf 0x3f3f3f3f
#define linf 0x3f3f3f3f3f3f3f3fll
typedef long long ll;
typedef pair<int,int> pii;
typedef unsigned long long ull;
map<pair<ll,ll>,pii> cnt;
int n;
inline ll mygcd(ll x,ll y)
{
	if(!y)return x;
	return mygcd(y,x%y);
}
inline void add(ll &a,ll b)
{
	a+=b;
	if(a>=MOD)a-=MOD;
}
inline ll quickpow(ll base,ll ind)
{
	ll ans=1;
	while(ind>0)
	{
		if(ind&1)ans=ans*1ll*base%MOD;
		ind>>=1;
		base=base*1ll*base%MOD;
	}
	return ans;
}
int main()
{
	ll zero=0;
	scanf("%d",&n);
	for(int i=0;i<n;i++)
	{
		ll x,y;
		scanf("%lld%lld",&x,&y);
		if(x==0&&y==0)
		{
			zero++;
			continue;
		}
		ll gcd=mygcd(abs(x),abs(y));
		x/=gcd;
		y/=gcd;
		if(x<0)
		{
			x=-x,y=-y;
		}
		else if(x==0&&y<0)y=-y;
		if(y>0)cnt[make_pair(x,y)].first++;
		else cnt[make_pair(-y,x)].second++;
	//	cout<<x<<" "<<y<<endl;
	}
	ll ans=1ll;
	for(map<pair<ll,ll>,pii>::iterator it=cnt.begin();it!=cnt.end();it++)
	{
	//	cout<<(it->second).first<<" "<<(it->second).second<<endl;
		ll res=quickpow(2ll,(it->second).first);
		add(res,quickpow(2ll,(it->second).second));
		add(res,MOD-1);
	//	cout<<res<<endl;
		ans=ans*1ll*res%MOD;
	}
//	cout<<ans<<" "<<zero<<endl;
	add(ans,1ll*zero);
	add(ans,MOD-1);
//	cout<<ans<<endl;
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 16060
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    long n = sc.nextLong();
    long m = sc.nextLong();
    long ans = 0;
    for(long x = 1; x * x <= m; x++) {
      if((m % x) == 0) {
        if((m / x) >= n) {
          ans = Math.max(ans, x);
        }
        if(x >= n) {
          ans = Math.max(ans, m / x);
        }
      }
    }
    System.out.println(ans);
  }
}

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

using namespace std;

#define MOD 1000000007
#define ll long long int
#define ld long double
#define pb push_back
#define mkp make_pair
#define pii pair<int, int> 
#define pll pair<long long int, long long int>
#define sci(x) scanf("%d", &x)
#define scl(x) scanf("%lld", &x)
#define fi first
#define sc second
#define eps 1e-9

int BIT[200005];
int A[100005], B[100005];

void insert(int x, int v) 
{
	for (; x <= 200000; x += (x&-x)) {
		BIT[x] += v;
	}
}

int query(int x) {
	int ret = 0;
	for (; x > 0; x -= (x&-x)) ret += BIT[x];
	return ret;
}

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

	int n, m, i, j, k, x, y, z;
	cin >> n;
	for (i = 0; i < n; ++i) {
		cin >> A[i];
		B[i] = A[i];
	}
	sort(B, B+n);

	int start, mid, end, ans;
	start = 0;
	end = n-1;

	ll count, req;
	req = 1ll * n * (n + 1) / 2;
	while (start <= end) {
		mid = (start + end) >> 1;
		//memset(BIT, 0, sizeof(BIT));
		x = y = 0;
		for (i = 0; i < n; ++i) {
			x += (A[i] >= B[mid]);
			y += (A[i] < B[mid]);
			insert(100000 + x - y, 1);
		}
		count = 0;
		int cur = 100000;
		x = y = 0;
		for (i = 0; i < n; ++i) {
			count += (query(200000) -  query(cur-1));
			if (A[i] >= B[mid]) cur += 1;
			else cur -= 1;
			x += (A[i] >= B[mid]);
			y += (A[i] < B[mid]);
			insert(100000 + x - y, -1);
			//cout << "cur = " << cur << " count = " << count << endl;
		}
		ll left = req - count;
		//cout << "val = " << B[mid] << " right = " << count << " left = " << left << endl;
		if (count >= left) {
			ans = mid;
			start = mid + 1;
		} else {
			end = mid - 1;
		}
	}
	cout << B[ans] << endl;

	return 0;
}

Measured memory_bytes: 1408
# include <bits/stdc++.h>
# define ll long long
# define pb push_back
# define fi first
# define se second
# define mp make_pair
using namespace std;


ll dp[101][100001];
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    ll n,w;
    cin>>n>>w;
    vector <ll> weight(n+1),value(n+1);
    for(ll i=1;i<=n;i++)
    {
        cin>>weight[i]>>value[i];
    }
    // dp[i][j] -> maximum value that we can get if the weight is exactly j till the ith element
    // Base Case
    // dp[1][x] will be w1 if x=1 else infinity
    // dp[1][0]=0
    for(ll i=0;i<=w;i++)
    {
        if(i==weight[1]) dp[1][i]=value[1];
        else dp[1][i]=INT_MIN;
    }
    dp[1][0]=0;
    for(ll i=2;i<=n;i++)
    {
        for(ll j=0;j<=w;j++)
        {
            if(j-weight[i]>=0)
            dp[i][j] = max(dp[i-1][j],dp[i-1][j-weight[i]]+value[i]);
            else dp[i][j] = dp[i-1][j];
        }
    }
    ll ans = 0;
    for(ll i=0;i<=w;i++)
    {
        ans=max(ans,dp[n][i]);
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 81664
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>

using namespace std;

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

	int ans = 700 + 100 * count(s.begin(), s.end(), 'o');
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;


public class Main {
	public static void main(String args[]){
		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		int C = scan.nextInt();
		int K = scan.nextInt();
		int tempT = 0;
		int tempC = 0;
		int tempB = 0;
		int Ti = 0;
		ArrayList<Integer> array = new ArrayList<Integer>();
		while (scan.hasNext()){
			array.add(scan.nextInt());
		}
		Collections.sort(array);
		Ti = array.get(0);
		tempT = Ti + K;
		tempC = 1;
		tempB = 1;
		for (int i = 1; i < array.size(); i++) {
			Ti = array.get(i);
			if (tempC < C && Ti <= tempT){
				tempC++;
			} else {
				tempB++;
				tempC = 1;
				tempT = Ti + K;
			}
		}
		System.out.println(tempB);
	}
}


Measured memory_bytes: 64000
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
const int MX = 200005;
int n;
long long a[MX], ans = 1e17;

int main(){
	scanf("%d", &n);
	rep(i,n){
		scanf("%lld", a+i+1);
		a[i+1] += a[i];
	}
	rep(i,n+1) ans = min(ans, abs(a[n]-a[i]*2));
	printf("%lld\n", ans);
}

Measured memory_bytes: 1792
#define _USE_MATH_DEFINES

#include <iostream>
#include <iomanip>
#include <stdio.h>

#include <sstream>
#include <algorithm>
#include <iterator>
#include <cmath>
#include <complex>

#include <string>
#include <cstring>
#include <vector>
#include <bitset>

#include <queue>
#include <set>
#include <map>
#include <stack>
#include <list>

#include <ctime>
////
//#include <random>//
/////////

typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;

////定数
const int INF = (int)1e9 + 10;
const LL MOD = (LL)1e9 + 7;
const LL LINF = (LL)4e18 + 20;
const LD PI = acos(-1.0);
const double EPS = 1e-9; 
/////////
using namespace::std;
//////////////


void solve() {
	int N;
	cin >> N;
	LL ans = 0;
	for (int i = 1; i <= N; ++i) {
		if (i % 3 == 0 && i % 5 == 0) {
		}
		else if (i % 3 == 0) {}
		else if (i % 5 == 0) {}
		else { ans+=i; }
	}
	cout << ans << endl;
}

signed main(void) {
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	std::cout << std::fixed;//小数を10進数表示
	cout << setprecision(16);//小数点以下の桁数を指定//coutとcerrで別	

	solve();
}


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

int main() {
    int N; cin >> N;
    string S; cin >> S;
    if (N%2 == 1) {
        cout << "No" << endl;
    } else {
        rep(i, N/2) {
            int u = N/2 + i;
            if (S[i] != S[u]) {
                cout << "No" << endl;
                return 0;
            }
        }
        cout << "Yes" << endl;
    }
    return 0;
}

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

int main() {
    for(;;) {
        int x;
        std::cin >> x;
        if (x == 0) {
            break;
        }
        int res = 0;
        for(int i = 1; i < x; ++i) {
            int sum = i;
            int k = i+1;
            while (sum + k <= x) {
                sum += k;
                k += 1;
            }
            if (sum == x) {
                res += 1;
            }
        }
        printf("%d\n", res);
    }
}




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

int main(){
 	int n;
	cin >>n;
  	int min=1000;
  	int t;
  	int k;
  	for(int i=0;i<n;i++){
    	k=0;
      	cin >> t;      
     	while(t%2==0&&t>0) {
        	t/=2;
          	k++;
        }
      	if(min > k)
          	min = k;
    }
  	cout << min << endl;
	
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
    int n; cin >> n;
    string s; cin >> s;
    if(n > 0){
        for(int i = 0; i < s.size(); i++){
            if(s[i]+n > 90){
                s[i] = (s[i] + n)%90+64;
            }else{
                s[i] = s[i] + n;
            }
        }
    }
    cout << s << endl;
    return 0;
}

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

int main(){
	int n;
	while(cin >> n,n){
		int a[101];
		for(int i = 0;i < n + 1;i++) cin >> a[i];
		for(int i = 0;i < n + 1;i++){
			vector<int> vec;
			for(int j = 0;j < n + 1;j++){
				if(i != j) vec.push_back(a[j]);
			}
			int d = vec[1] - vec[0];
			bool flag = true;
			for(int j = 1;j < n - 1;j++){
				if(d != vec[j + 1] - vec[j]) flag = false;
			}
			if(flag){
				cout << a[i] << endl;
				break;
			}
		}
	}
	return 0;
}

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

using namespace std;

int main() {
  int n;
  cin >> n;
  
  vector<int> A(n);
  for (auto& item : A) {
    cin >> item;
  }

  int cnt = 0;
  for (int i = 0; i < n; ++i) {
    int minj = i;
    for (int j = i; j < n; ++j) {
      if (A[minj] > A[j]) minj = j;
    }
    if (i < minj) {
      swap(A[i], A[minj]);
      ++cnt;
    }
  }

  const char* sep = "";
  for (auto& item : A) {
    cout << sep << item;
    sep = " ";
  }
  cout << endl;
  cout << cnt << endl;
  return 0;
}



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

#define dump(...) do{print_vars(cout<<"# "<<#__VA_ARGS__<<'=',__VA_ARGS__);cout<<endl;}while(0)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define all(c) begin(c),end(c)
#define mp make_pair
#define mt make_tuple

using uint=unsigned;
using ll=long long;
using ull=unsigned long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using vd=vector<double>;
using vvd=vector<vd>;
using vs=vector<string>;

template<typename T,typename U>bool chmin(T& a,const U& b){return a>b?(a=b,1):0;}
template<typename T,typename U>bool chmax(T& a,const U& b){return a<b?(a=b,1):0;}

void print_vars(ostream&){}
template<typename Car,typename... Cdr>
void print_vars(ostream& os,const Car& car,const Cdr&... cdr){
	print_vars(os<<car<<(sizeof...(cdr)?",":""),cdr...);
}

template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& p){
	return os<<'('<<p.first<<','<<p.second<<')';
}

template<int I,typename Tuple>
void print_tuple(ostream&,const Tuple&){}
template<int I,typename Car,typename... Cdr,typename Tuple>
void print_tuple(ostream& os,const Tuple& t){
	os<<get<I>(t)<<(sizeof...(Cdr)?",":"");
	print_tuple<I+1,Cdr...>(os,t);
}
template<typename... Args>
ostream& operator<<(ostream& os,const tuple<Args...>& t){
	print_tuple<0,Args...>(os<<'(',t);
	return os<<')';
}

template<typename Ch,typename Tr,typename C>
basic_ostream<Ch,Tr>& operator<<(basic_ostream<Ch,Tr>& os,const C& c){
	os<<'[';
	for(auto i=begin(c);i!=end(c);++i)
		os<<(i==begin(c)?"":" ")<<*i;
	return os<<']';
}

constexpr int INF=1e9;
constexpr int MOD=1e9+7;
constexpr double EPS=1e-9;

int main()
{
	#ifndef _GLIBCXX_DEBUG
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	constexpr char endl='\n';
	#endif

	for(int n,h,w;cin>>n>>h>>w&&n|h|w;){
		cout<<(n-h+1)*(n-w+1)<<endl;
	}
}


Measured memory_bytes: 256
inpl = lambda: list(map(int,input().split()))
N, K = inpl()
V = inpl()
Nneg = len(list(filter(lambda x: x < 0, V)))
Vneg = sorted(list(enumerate(V)),key=lambda x: x[1])[:Nneg]

if K >= Nneg + N:
    print(sum(list(map(lambda x: x if x>0 else 0, V))))
    exit()

ans = 0
for i in range(Nneg+1):
    L = K - i
    if L > N:
        continue

    for j in range(L):
        S = sum(V[:L-j]) + sum(V[N-j:])
        k = 0
        for n, v in Vneg:
            if k >= i:
                break
            elif n < L-j or N-j <= n:
                S -= v
                k += 1
        if S > ans:
            ans = S

print(ans)

Measured memory_bytes: 40048
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
ll dp[100005][4];
#define mod 1000000009

ll helper(ll A[], ll B[], ll C[], ll n, ll i, ll x){
    
    if(i >= n){
        return 0;
    }
    
    if(dp[i][x] != -1){
        return dp[i][x];
    }
    
    ll ans = 0;
    if(x == 1){
        ans = max(ans, helper(A, B, C, n, i+1, 2) + B[i])%mod;
        ans = max(ans, helper(A, B, C, n, i+1, 3) + C[i])%mod;
    } else if(x == 2){
        
        ans = max(ans, helper(A, B, C, n, i+1, 1) + A[i])%mod;
        ans = max(ans, helper(A, B, C, n, i+1, 3) + C[i])%mod;
        
    } else if(x == 3){
        
        ans = max(ans, helper(A, B, C, n, i+1, 1) + A[i])%mod;
        ans = max(ans, helper(A, B, C, n, i+1, 2) + B[i])%mod;
        
    } else {
        ans = max(ans, helper(A, B, C, n, i+1, 1) + A[i])%mod;
        ans = max(ans, helper(A, B, C, n, i+1, 2) + B[i])%mod;
        ans = max(ans, helper(A, B, C, n, i+1, 3) + C[i])%mod;
    }
    return dp[i][x] = ans%mod;
}

int main(){
    ll n;
    cin >> n;
    ll A[n], B[n], C[n];
    for(ll i = 0; i < n; i++){
        cin >> A[i] >> B[i] >> C[i];
    }
    memset(dp, -1, sizeof(dp));
    cout << helper(A, B, C, n, 0, 0) << endl;
    
    
}


Measured memory_bytes: 18436
#include <bits/stdc++.h>
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define pi (double) acos(-1)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
using namespace std;

ll to_int(string n){
    ll ans = 0, mul = 1;
    reverse(all(n));
    for(int i = 0; i < n.size(); i++){
        string now; now = n[i];
        ans += atoi(now.c_str()) * mul;
        mul *= 10;
    }
    return ans;
}

int main(){
    string s;
    cin >> s;
    ll ans = 0, n = s.size()-1;
    for(ll bit = 0; bit < (1<<n); bit++){
        string now; now = s[0];
        ll num = 0;
        for(ll i = 0; i < n; i++){
            if(bit & (1<<i)){
                num += to_int(now);
                now = "";
            }
            now += s[i+1];
        }
        num += to_int(now);
        ans += num;
    }
    cout << ans << endl;
}   

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

using namespace std;

#define REP(i,n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef pair<int, int> pint;

bool f(int a, int b, int c) {
  return a==b && b==c;
}

int main() {
  int A, B, C;
  cin>>A>>B>>C;
  bool ans = f(A,B,C);
  cout << (ans ? "Yes" : "No") << endl;
  return 0;
}



Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main()
{
    char num[1005];
    int sum=0;
    while(1)
    {
        scanf("%s",num);
        sum=0;
        if (num[0]=='0') break;
        int i, sz=strlen(num);
        for(i=0;i<sz;i++)
 
        {
            sum+=num[i] - '0';
        }
 
    printf("%d\n",sum);
}
}


Measured memory_bytes: 2052
def isValid(num):
    s = str(num)
    cnt = {}
    for i in s:
        cnt[i] = 1
    return len(cnt) == 3
    

def dfs(num):
    if num > N:
        return 0
    a = dfs(num * 10 + 7)
    b = dfs(num * 10 + 5)
    c = dfs(num * 10 + 3)
    return a + b + c + isValid(num)

N = int(input())
ans = dfs(0)
print(ans)


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



int main() {
    int n;
    string s;
    cin >> n >> s;
    
    bool tf = true;
    if(n % 2 == 1)
        tf = false;
    else {
        rep(i,n/2) {
            if(s[i] != s[n/2 + i]) {
                tf = false;
                break;
            }
        }
    }
    
    if(tf)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    
    
    return 0;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
#include <cmath>
#include <numeric>
using namespace std;
#define rep(i,a,b) for(int64_t i=(a); i<(b); ++i) // a ≦ i < b 
#define Rrep(i,a,b) for(int64_t i=(a);i>=(b);--i) // reverse repeat. a から b まで減少．
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend() //逆イテレータ
#define RANGE(a,b,c) (a).begin()+b,(a).begin()+c // コンテナ a の 要素 b から c へのイテレータ
#define MOD 1000000007ll
#define INF 1000000000ll
typedef pair<int64_t, int64_t> PII;
typedef vector<int64_t> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<PII> VP;

// まずは全探索，次にDP
// 偶奇，逆から，ソート，出現回数，出現位置，DP
// 余事象，包除
// 問題の特徴量
// 存在判定：構成方法，入力の特徴
// 例外を十分に含む一般化．想像力の限界
// 始めは過剰に例示・場合分けしてもいい．各場合を確実に対処．
int main() {
cin.tie(0);
ios::sync_with_stdio(false);

int N;cin >> N;

if (N == 1) {cout << "1\n"; return 0;}

// 素因数の個数．
VI cntp(N+1, 0);
rep(i, 2, N + 1){
    int I = i;
    for (int j = 2; j * j <= i;){
        if (I % j) ++j;
        else {
            ++cntp[j];
            I /= j;
        }
    }
    if (I != 1) ++cntp[I];
}


int64_t ans = 1;
for (int i: cntp) {
    ans *= i + 1;
    ans %= MOD;
}

cout << ans % MOD << "\n";

}

// 境界，出力文字列 チェック



Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main (void)
{
	char S [3];
	cin >> S;
	int max = 0, record = 0;
	for (int i = 0; i < 3; i++)
	{
		if (S [i] == 'R')
		{
			max++;
			continue;
		}
		else
		{
			if (record < max)
				record = max;
			max = 0;
			continue;
		}
	}
	if (record < max)
		record = max;
	cout << record << endl;
	return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <assert.h>
#include <numeric>
#include <time.h>
#include <map>
#include <unordered_map>
#include <stack>
#include <queue>

using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < n; i++)
#define all(c) (c).begin(), (c).end()
#define P pair<int, int>

int main()
{
  ll n, k;
  cin >> n >> k;
  vector<ll> a(n);
  for (int i = 0; i < n; i++)
  {
    cin >> a[i];
  }

  sort(a.begin(), a.end());

  const ll INF = (ll)(1e18) + 1;
  ll left = -INF, right = INF;

  while (left + 1 < right)
  {
    ll x = (left + right) / 2;
    ll tot = 0; // x未満のpairの積の個数

    rep(i, n)
    {
      if (a[i] < 0)
      {
        int l = -1, r = n;
        while (l + 1 < r)
        {
          int c = (l + r) / 2;
          if (a[i] * a[c] < x)
          {
            r = c;
          }
          else
          {
            l = c;
          }
        }
        tot += n - r;
      }
      else
      {
        int l = -1, r = n;
        while (l + 1 < r)
        {
          int c = (l + r) / 2;
          if (a[i] * a[c] < x)
          {
            l = c;
          }
          else
          {
            r = c;
          }
        }
        tot += r;
      }
      if (a[i] * a[i] < x)
      {
        tot--;
      }
    }

    tot /= 2;

    if (tot < k)
    {
      left = x;
    }
    else
    {
      right = x;
    }
  }

  cout << left << endl;
}


Measured memory_bytes: 1792
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int X = sc.nextInt();
        sc.close();
        String ans = "No";
        if(X>=30){
            ans = "Yes";
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 35568
#include <iostream>

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

  int thousands = n / 1000;
  int hundreds = n / 100 % 10;
  int tens = n / 10 % 10;
  int ones = n % 10;
  std::string is_good_integer;
  if (thousands == hundreds && hundreds == tens ||
    hundreds == tens && tens == ones) {
    is_good_integer = "Yes";
  } else {
    is_good_integer = "No";
  }
  std::cout << is_good_integer << std::endl;
}


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



int main()
{
    int a,b,c,d,k;

    cin >> a >> b >> c >> d >> k;

    int ttl = (c*60) - (a*60);
    ttl -= b;
    ttl += d;
    cout << ttl-k << endl;

}


Measured memory_bytes: 3632
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = Integer.parseInt(sc.next());
    String A[] = new String[N];
    Map<String, Integer> map = new HashMap<String, Integer>();
    int max_cnt = 1;
    for(int i = 0; i < N;i++){
      A[i] = sc.next();
      if(map.containsKey(A[i])){
          map.put(A[i],map.get(A[i])+1);
          max_cnt = Math.max(max_cnt,map.get(A[i]));
      }else{
          map.put(A[i],1);
      }
    }
    ArrayList<String> ar = new ArrayList<String>();
    for(String key : map.keySet()){
        if(map.get(key) == max_cnt){
            ar.add(key);
        }
    }
    Collections.sort(ar);
    for(int i=0; i < ar.size(); i++){
        System.out.println(ar.get(i));
    }  
  }
}




Measured memory_bytes: 89472
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int inf=1e9;
const int MOD=1e9+7;
int ans[100005];
string s;
int main(void)
{
    memset(ans,0,sizeof(ans));
    vector<int> loops;
    cin >> s;
    int N=int(s.size());
    s='$'+s+'$';
    for(int i=1;i<=N;i++)
    {
        if(s[i]=='R' && s[i+1]=='L') loops.push_back(i);
    }
    for(int i=1;i<=N;i++)
    {
        if(s[i]=='R')
        {
            int point=*lower_bound(loops.begin(),loops.end(),i);
            int dis=point-i;
            //cout << point << ' ' << dis << endl;
            if(dis%2==0) ans[point]++;
            else ans[point+1]++;
        }
        else if(s[i]=='L')
        {
            int point=loops[lower_bound(loops.begin(),loops.end(),i)-loops.begin()-1];
            int dis=i-point;
            //cout << point << ' ' << dis << endl;
            if(dis%2==0) ans[point]++;
            else ans[point+1]++;
        }
    }
    for(int i=1;i<=N;i++)
    {
        if(i!=N) cout << ans[i] << ' ';
        else cout << ans[i] << endl;
    }

}

Measured memory_bytes: 1272
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll MOD=(ll)1e9+7;
const ll MOD2=(ll)998244353;
const ll INF=(ll)1e18+10;
const double PI=acos(-1);

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; }
int dy[]={-1,1,0,0};
int dx[]={0,0,-1,1};

void solve(int ca){
    int N,M; cin>>N>>M;
    vector<int> a(N);
    int total=0;
    for (int i = 0; i < N; ++i) {
        cin>>a[i];
        total+=a[i];
    }
    int pos=0;
    int cmp=ceil((double)total/4.0/M);
    for (int i = 0; i < N; ++i) {
        if(a[i]>=cmp)  pos++;
    }
    cout<<((pos>=M)?"Yes":"No")<<endl;
}

//#define MULTI
int main() {
#ifdef MULTI
    int N; cin>>N;
    for (int i = 0; i < N; ++i) {
        solve(i+1);
    }
#else
    solve(1);
#endif
    return 0;
}


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

#define ll long long

using namespace std;

const int N = 2e5 + 123;

ll n, k;

ll a[N], sum;

int main () {
    scanf ("%lld%lld", &n, &k);
    for (int i = 1;i <= n;i ++) {
        scanf ("%lld", a + i);
    }sort (a + 1, a + n + 1);
    for (int i = 1;i <= n - k;i ++) {
        sum += a[i];
    }
    printf ("%lld", sum);
}


Measured memory_bytes: 1792
from collections import Counter

n = int(input())
A = list(map(int, input().split()))
C = Counter(A)
ans = 1
MOD = 10**9+7
for k, v in C.items():
    if k == 0 and v != 1:
        print(0)
        exit()
    if k != 0 and v != 2:
        print(0)
        exit()
    ans *= v
print(ans % MOD)


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

int main() 
{
	int arr[32] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
	int k;
	cin>>k;
	cout<<arr[k-1];
	return 0;
}

Measured memory_bytes: 256
#include <iostream> 
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mk make_pair
#define MAX 1000001
ll prime[MAX];
#define FAST           ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
#define mod 1000000007

ll rec(vector<vector<ll> >& dp,vector<ll>& arr,int n,int i,int k,int w)
{
  ll ans=0;
  if(i>=n)
    return 0;

  if(dp[i][k]!=-1)
    return dp[i][k];


  if(k!=0)
  ans=max(rec(dp,arr,n,i+1,w,w),arr[i]+rec(dp,arr,n,i+1,k-1,w));
  else
  ans=max(rec(dp,arr,n,i+1,k,w),rec(dp,arr,n,i+1,w,w));

  return dp[i][k]=ans;

}

//ll t[400008];
// void build(vector<ll>& a, int v, int tl, int tr) {
//     if (tl == tr) {
//         t[v] = a[tl];
//     } else {
//         int tm = (tl + tr) / 2;
//         build(a, v*2, tl, tm);
//         build(a, v*2+1, tm+1, tr);
//         t[v] = max(t[v*2] ,t[v*2+1]);
//     }
// }

// ll maxi(int v, int tl, int tr, int l, int r) {
//     if (l > r) 
//         return 0;
//     if (l == tl && r == tr) {
//         return t[v];
//     }
//     int tm = (tl + tr) / 2;
//     return max(maxi(v*2, tl, tm, l, min(r, tm)) ,maxi(v*2+1, tm+1, tr, max(l, tm+1), r));
// }



// void update(int v, int tl, int tr, int pos, ll new_val) {
//     if (tl == tr) {
//         t[v] = new_val;
//     } else {
//         int tm = (tl + tr) / 2;
//         if (pos <= tm)
//             update(v*2, tl, tm, pos, new_val);
//         else
//             update(v*2+1, tm+1, tr, pos, new_val);
//         t[v] = max(t[v*2] ,t[v*2+1]);
//     }
// }


struct hash_pair {
   template <class T1, class T2>
   size_t operator()(const pair<T1, T2>& p) const{
      auto hash1 = hash<T1>{}(p.first);
      auto hash2 = hash<T2>{}(p.second);
      return hash1 ^ hash2;
   }
};

ll rec(ll a[],ll first,ll last,int n)
{
  if(first>last)
    return 0;

  ll temp=1000000000;
  ll ind=0;
  for(ll i=first;i<=last;i++)
   {
    if(temp>a[i])
    {
      temp=a[i];
      ind=i;
    }
   }
   for(ll i=first;i<=last;i++)
    a[i]-=temp;


return min(last-first+1,(rec(a,first,ind-1,n)+rec(a,ind+1,last,n)+temp));

}
int main() { 
int n;
cin>>n;
ll a[n];

ll sum=0;
for(int i=0;i<n;i++)
{
  cin>>a[i];
  sum=(sum+a[i])%mod;
}

ll ans=0;
for(int i=0;i<n-1;i++)
{
  ans=(ans+(((sum-a[i]+mod)%mod)*a[i])%mod)%mod;
  sum=(sum-a[i]+mod)%mod;
}


cout<<ans;
return 0;

}


Measured memory_bytes: 5200
#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main() {
    int N,M;
    cin >> N >> M;
    vector<int>A(N);
    priority_queue<int,vector<int>,less<int>> que;
    for(int i = 0; i < N; i++) {
        cin >> A[i];
        que.push(A[i]);
    }
    while(M != 0) {
        M--;
        int X = que.top();
        X/=2;
        que.pop();
        que.push(X);
    }
    int ans = 0;
    while(!que.empty()) {
        ans+=que.top();
        que.pop();
    }
    cout << ans << endl;
}


Measured memory_bytes: 2168
#include <stdio.h>

const int MAX_V = 1000000;
int prime[MAX_V+1];
int main() {
    int i, k, v;
    for(i = 2; i <= MAX_V; i++) {
        prime[i] = 1;
    }
        for(i = 2; i*i <= MAX_V; i++) {
            if(prime[i]){
             for(k = 2 * i; k <= MAX_V; k += i) {
        prime[k] = 0;
             }
            }
        }
    int max=0;
    while(scanf("%d", &v) != EOF) {
        for(i=2; i<=v; i++){
            if(prime[i]==1){
                if(prime[i-2]==1){
                    max=i;
                }
            }
        }
        if(v==0)break;
        printf("%d %d\n",max-2,max);
    }
    return 0;
}

Measured memory_bytes: 6484
#151_C
n, m = map(int, input().split())
ac = [False for _ in range(n)]
wa = [0 for _ in range(n)]

ans = 0
for _ in range(m):
    p, s = input().split()
    p = int(p) - 1
    if s == 'AC' and ac[p] == False:
        ans += wa[p]
        ac[p] = True
    else:
        wa[p] += 1
print(sum([ac[i] for i in range(n)]), ans)

Measured memory_bytes: 5528
/*
By Snickeen
*/
#include<bits/stdc++.h>
//#pragma comment(linker, "/STACK:102400000,102400000")
#include <stdio.h>
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string.h>
#include <stdlib.h>
#include <time.h>
#include <limits.h>
#include <math.h>
#include <algorithm>
#include <deque>
#include <queue>
#include <stack>
#include <list>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <string>
#include <vector>
#include <bitset>
#include <functional>
using namespace std;
typedef long long  LL;
typedef unsigned long long ULL;
typedef double db;
typedef long double ldb;
#define rep(i,a,b) for(i=a;i<b;i++)
#define repu(i,a,b) for(i=a;i<=b;i++)
#define repd(i,a,b) for(i=a;i>=b;i--)
#define repc(i,a,b,c) for(i=a;i<b;i+=c)
#define repcu(i,a,b,c) for(i=a;i<=b;i+=c)
#define repcd(i,a,b,c) for(i=a;i>=b;i-=c)
#define FIN freopen("input.in","r",stdin)
#define FOUT freopen("output.out","w",stdout)
#define CC(a) memset(a,0,sizeof(a))
#define MST(a,b) memset(a,b,sizeof(a))
#define PII pair<int,int>
#define PLL pair<LL,LL>
#define VI vector<int>
#define VL vector<LL>
#define VII vector<PII >
#define VLL vector<PLL >
#define all(x) x.begin(),x.end()
#define mp make_pair
#define pb push_back
#define pf push_front
#define FF first
#define SS second

template<typename T>inline void gn(T &x){
	x=0;T f=1;char ch=getchar();
	while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
	while(isdigit(ch)){x=x*10+ch-'0';ch=getchar();}
	x*=f;
}
template<typename T>inline void gt(T x){
	if(!x)return;
	gt(x/10);putchar(x%10+'0');
}
 
const LL MAXN=1e5+10;
LL t,n,m,ans,tot;
LL MOD=1e9+7,inf=0x1f1f1f1f;
db eps=1e-5;

LL a,b,c,d;

int main()
{
	//ios_base::sync_with_stdio(false);cin.tie(0);
	LL i,j,k,l,r,ca=0,u=0,v=0,w;
	cin>>n>>m>>t;
	b=n;d=m;
	rep(i,0,t){
		cin>>u>>v>>w;
		if(w==1)a=max(a,u);
		if(w==2)b=min(b,u);
		if(w==3)c=max(c,v);
		if(w==4)d=min(d,v);
	}
	if(a>=b||c>=d)ans=0;
	else ans=(b-a)*(d-c);
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
import java.util.*;
import static java.lang.Math.*;
public class Main {
	Scanner sc=new Scanner(System.in);
	public static void main(String[] args) {
		new Main().init();
	}
	void init(){
		final long STACK = 8*1024*1024;
		new Thread(null, new AOJ1318(), "RUN", STACK).start();
	}
	
	class AOJ1318 implements Runnable{
		AOJ1318(){}
		@Override public void run(){
			while(sc.hasNext()){
				N=sc.nextInt();
				M=sc.nextInt();
				CAP=sc.nextInt()*10;
				if((N|(CAP))==0)	break;
				solve();
			}
		}
		
		int N,M,CAP,Node;
		final int INF = 1<<29;
		HashMap<String,Integer> dic;
		ArrayList<ArrayList<Edge>> g;
		
		void solve(){
			String src=sc.next(),dest=sc.next();
			dic = new HashMap<String,Integer>();
			ArrayList<In> input = new ArrayList<In>();
			for(int i=0; i<N; ++i){
				String a=sc.next(),b=sc.next();
				int d=sc.nextInt();
				if(!dic.containsKey(a))	dic.put(a, dic.size());
				if(!dic.containsKey(b))	dic.put(b, dic.size());
				input.add(new In(a,b,d));
			}
			
			Node = dic.size();
			
			boolean[] chg = new boolean[Node];
			for(int i=0; i<M; ++i)	chg[dic.get(sc.next())]=true;
			
			g = new ArrayList<ArrayList<Edge>>();
			for(int i=0; i<Node; ++i)	g.add(new ArrayList<Edge>());
			for(In i:input){
				int a=dic.get(i.a),b=dic.get(i.b);
				g.get(a).add(new Edge(b, i.d, chg[b]));
				g.get(b).add(new Edge(a, i.d, chg[a]));
			}
			
			System.out.println( Dijkstra(dic.get(src), dic.get(dest)) );
			
		}
		
		int Dijkstra(int src,int to){
			
			PriorityQueue<State> open = new PriorityQueue<State>();
			open.add(new State(src, 0, CAP));
			
			int[][] closed = new int[Node][CAP+1];
			for(int i=0; i<Node; ++i)for(int j=0; j<=CAP; ++j)closed[i][j]=INF;
			for(int i=0; i<=CAP; ++i)closed[src][i]=0;
			
			while(!open.isEmpty()){
				State now=open.poll();
				if(now.p==to)	return now.d;
				
				ArrayList<Edge> cand = g.get(now.p);
				for(Edge e:cand){
					if(now.c < e.dis)	continue;
					
					int nextCap = e.ch? CAP : now.c-e.dis,
						nextDis = now.d + e.dis;
					
					if(closed[e.to][nextCap] <= nextDis)	continue;
					
					for(int i=nextCap; i>=0; --i){
						if(closed[e.to][i] <= nextDis)	break;
						closed[e.to][i] = nextDis;
					}
					open.add(new State(e.to, nextDis, nextCap));
					
				}
				
			}
			
			return -1;
		}
		
		class State implements Comparable<State>{
			int p,d,c;
			State(int p,int d,int c){
				this.p=p;
				this.d=d;
				this.c=c;
			}
			@Override public int compareTo(State o){
				return this.d-o.d;
			}
		}
		
		class In{
			String a,b;
			int d;
			In(String a,String b,int d){
				this.a=a;
				this.b=b;
				this.d=d;
			}
		}
		
		class Edge{
			int to,dis;
			boolean ch;
			Edge(int to,int dis,boolean ch){
				this.to=to;
				this.dis=dis;
				this.ch=ch;
			}
		}
		
	}

}

Measured memory_bytes: 87000
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

# nCr
def nCr(n,r):
  if n<r:
    return 0
  return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))

def main():
  n,p=LI()
  l=LI()

  la=[]
  lb=[]

  for x in l:
    if x%2==1:
      la.append(x)
    else:
      lb.append(x)

  # lbから偶数個選ぶ方法は何通り？
  bc=0
  for i in range(len(lb)+1):
    bc+=nCr(len(lb),i)
    # print(bc)

  ans=0
  for i in range(len(la)+1):
    if p==0:
      r=i*2
    else:
      r=i*2+1

    ans+=nCr(len(la),r)*bc

  return ans

print(main())


Measured memory_bytes: 6604
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

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

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

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

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

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

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int DX[] = {0, 1, 0, -1};
const int DY[] = {-1, 0, 1, 0};


//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

int main(int argc, char const *argv[])
{
	cin.tie(0);
	ios::sync_with_stdio(false);

	int A, B;
	while(!cin.eof() && cin >> A >> B){
		cout << A + B << endl;
	}

	
	return 0;
}

Measured memory_bytes: 1188
s=list(input())
a=0
for i in range(len(s)):
  if i % 2 == 0:
    if s[i]=="R" or s[i]=="U" or s[i]=="D":
      a+=1
  else:
    if s[i]=="L" or s[i]=="U" or s[i]=="D":
      a+=1
if a==len(s):
  print("Yes")
else:
  print("No")

Measured memory_bytes: 3064
#
# abc145 c
#

import sys
from io import StringIO
import unittest
import math
import itertools


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """3
0 0
1 0
0 1"""
        output = """2.2761423749"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """2
-879 981
-866 890"""
        output = """91.9238815543"""
        self.assertIO(input, output)

    def test_入力例_3(self):
        input = """8
-406 10
512 859
494 362
-955 -475
128 553
-986 -885
763 77
449 310"""
        output = """7641.9817824387"""
        self.assertIO(input, output)


def resolve():
    N = int(input())
    P = [list(map(int, input().split())) for _ in range(N)]

    R = itertools.permutations(range(N))

    all = 0
    for r in R:
        for pi in range(1, len(r)):
            all += math.sqrt((P[r[pi]][0]-P[r[pi-1]][0])**2 +
                             (P[r[pi]][1]-P[r[pi-1]][1])**2)

    n = 1
    for i in range(1, N+1):
        n *= i

    print(f"{all/n:.10f}")


if __name__ == "__main__":
    # unittest.main()
    resolve()


Measured memory_bytes: 16332
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
#define     FAST            ios_base::sync_with_stdio(false); cin.tie(0), cout.tie(0);
int main()
{
    FAST;
    ll n;
    cin>>n;

    vector<char>v;
    while(n!=0)
    {
        if(n%26==0)
        {
            v.push_back('z');
        }
        else
        {
            v.push_back((n%26)+96);
        }

        if(n%26==0)
        {
            n=(n/26)-1;
        }
        else
        {
            n=n/26;
        }
    }


    for(int i=v.size()-1;i>=0;i--)
    {
        cout<<v[i];
    }
    cout<<endl;






    return 0;

}


Measured memory_bytes: 3644
#include <vector>
#include <iostream>
using namespace std;
vector<int> par;
int root(int x) {
	if (x == par[x]) return x;
	return par[x] = root(par[x]);
}
int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	int N, M;
	while (cin >> N >> M, N) {
		vector<int> deg(N, 0);
		par.resize(N);
		for (int i = 0; i < N; ++i) par[i] = i;
		bool ans = true;
		for (int i = 0; i < M; ++i) {
			int a, b;
			cin >> a >> b; --a, --b;
			if (++deg[a] >= 3 || ++deg[b] >= 3 || root(a) == root(b)) ans = false;
			par[root(a)] = root(b);
		}
		cout << (ans ? "yes\n" : "no\n");
	}
	return 0;
}


Measured memory_bytes: 3868
def gcd(a, b) 
  if b === 0
    return a
    
  end
  return gcd(b, a % b)
end

def lcm(a, b)
  return a * b / gcd(a, b)
end

while line = gets
  array = line.chomp.split(' ').map(&:to_i)
  a = array[0]
  b = array[1]
  x = gcd(a, b)
  y = lcm(a, b)
  printf("%d %d\n", x, y)
end


Measured memory_bytes: 8884