akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<limits.h>

#define N 100
#define WHITE 0
#define GRAY 1
#define BLACK 2

int n, M[N][N];

void dijkstra(void);

int main()
{
  int i, j, k, c, u, v;

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

  
  for(i = 0; i < n; i++)
    {
      scanf("%d %d",&u,&k);
      for(j = 0; j < k; j++)
	{
	  scanf("%d %d",&v,&c);
	  M[u][v] = c;
	}
    }

  dijkstra();
  
  return 0;
}


void dijkstra(void)
{
  int i, u, v, mincost, d[N], p[N], color[N];

  for(u = 0; u < n; u++)
    {
      color[u] = WHITE;
      d[u] = INT_MAX;
      p[u] = -1;
    }
  
  d[0] = 0;

  while(1)
    {
      mincost = INT_MAX;
      for(i = 0; i < n; i++)
	{
	  if(color[i] != BLACK && d[i] < mincost)
	    {
	      mincost = d[i];
	      u = i;
	    }
	}
      if(mincost == INT_MAX)break;

      color[u] = BLACK;
      
      for(v = 0; v < n; v++)
	{
	  if(color[v] != BLACK && M[u][v] != INT_MAX)
	    {
	      if(d[u] + M[u][v] < d[v])
		{
		  d[v] = d[u] + M[u][v];
		  p[v] = u;
		  color[v] = GRAY;
		}
	    }
	}
    }
  for(i = 0; i < n; i++)
    {
      printf("%d %d\n",i,d[i]);
    }
  
}



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

typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))

int main(){
  int N, M;
  cin >> N >> M;
  vector<int> ans(N);
  rep(i, N) ans[i] = -1;
  bool flag = true;
  rep(i, M){
    int s, c;
    cin >> s >> c;
    if(ans[s-1] >= 0 && ans[s-1] != c){
      flag = false;
      break;
    }else{
      ans[s-1] = c;
    }
  }
  if(ans[0] == 0 && N !=1) flag = false;
  if(ans[0] == -1 && N != 1) ans[0] = 1;
  if(flag){
    rep(i, N) cout << max(ans[i], 0);
    cout <<endl;
  }else{
    cout << -1 <<endl;
  }
}
    

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint     = long long;
const lint inf = 1LL << 60;
const lint mod = 1000000007;

// Eratosthenes's sieve
// create list of prime numbers in O(N)
// check if the given number is prime in O(1)
struct Sieve {
    vector<bool> isPrime;
    Sieve(size_t max) : isPrime(max + 1, true) {
        isPrime[0] = false;
        isPrime[1] = false;

        for (size_t i = 2; i * i <= max; ++i)
            if (isPrime[i])
                for (size_t j = 2; i * j <= max; ++j)
                    isPrime[i * j] = false;
    }
    bool operator()(size_t n) { return isPrime[n]; }
};

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    lint q;
    cin >> q;
    vector<int> r(q), l(q);
    for (int i = 0; i < q; ++i) {
        cin >> l[i] >> r[i];
    }
    Sieve isp(100000);
    vector<int> cnt(100001, 0);
    for (int i = 1; i <= 100000; i += 2) {
        if (isp(i) && isp((i + 1) / 2))
            cnt[i]++;
    }
    for (int i = 1; i <= 100000; ++i) {
        cnt[i] += cnt[i - 1];
    }
    for (int i = 0; i < q; ++i) {
        cout << cnt[r[i]] - cnt[l[i] - 1] << "\n";
    }
    return 0;
}

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

// definition {{{ 1

// scaning {{{ 2
#define Scd(x) scanf("%d", &x)
#define Scd2(x,y) scanf("%d%d", &x, &y)
#define Scd3(x,y,z) scanf("%d%d%d", &x, &y, &z)

#define Scll(x) scanf("%llu", &x)
#define Scll2(x,y) scanf("%llu%llu", &x, &y)
#define Scll3(x,y,z) scanf("%llu%llu%llu", &x, &y, &z)

#define Scc(c) scanf("%c", &c);
#define Scs(s) scanf("%s", s);
#define Scstr(s) scanf("%s", &s);
// }}} 2

// constants {{{ 2
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
// }}} 2

// systems {{{ 2
#define Rep(x,y) for(int x = 0; x < y; x++)
#define Repe(x,y,z) for(int x = z; x < y; x++)
// }}} 2

// output {{{ 2
#define YesNo(a) (a)?printf("Yes\n"):printf("No\n");
// }}} 2

// }}} 1

int main() {

    char s[100003];
    Scs(s);

    int N = strlen(s);
    int l = (N-1)/2;
    int r = N/2;

    int ans = N/2;

    char td = s[r];
    while( l >= 0 ){
        if( s[l] == s[r] && s[r] == td ){
            ans++;
        }else{
            break;
        }
        l--; r++;
    }

    printf ("%d\n", ans );

    return 0;
}



Measured memory_bytes: 384
#include <iostream>
#define REP(i, n) for (int i = 0; i < (n); i++)
using namespace std;

void solve(std::string S){
    string s1 = S.substr(0, 2);
    string s2 = S.substr(2);
    int n1 = stoi(s1);
    int n2 = stoi(s2);
    if (n1 >= 1 && n1 <= 12) {
        if (n2 >= 1 && n2 <= 12) cout << "AMBIGUOUS" << '\n';
        else cout << "MMYY" << '\n';
    } else {
        if (n2 >= 1 && n2 <= 12) cout << "YYMM" << '\n';
        else cout << "NA" << '\n';
    }
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    std::string S;
    std::cin >> S;
    solve(S);
    return 0;
}


Measured memory_bytes: 256
n = input()
l = []
for i in range(n):
	a, b = map(int, raw_input().split())
	l.append((b, a))
curtime = 0
l.sort()
for i in l:
	if curtime + i[1] > i[0]:
		print "No"
		exit(0)
	else:
		curtime += i[1]
print "Yes"

Measured memory_bytes: 33284
#include<cstdio>
using namespace std;
typedef long long ll;
const int maxn = 3e6 + 10;
const ll mod = 998244353;



ll inv[maxn] ,fac[maxn];
/*void prec(int n){
	inv[1] = 1;fac[1] = 1;
	for(int i = 2;i <= n;i++) inv[i] = mod - inv[mod % i] * (mod / i) % mod;
	for(int i = 2;i <= n;i++) inv[i] = (inv[i] * inv[i - 1]) % mod,fac[i] = (fac[i - 1] * i) % mod;
}
ll C(ll n,ll m){ if(n < m) return 0;if(!m) return 1;return inv[m] * inv[n - m] % mod * fac[n] % mod;	}

*/

long long q_pow(long long x,long long n){    long long res = 1;    while(n > 0)    {        if(n & 1) res = res * x % mod;        x = x * x % mod;        n >>= 1;    }    return res;} 
void init(){    int i;    fac[0] = 1;    for(i = 1;i < maxn;i++)    {        fac[i] = (fac[i - 1] * i) % mod;    }    inv[maxn - 1] = q_pow(fac[maxn - 1],mod - 2);    for(i = maxn - 2;i >= 0;i--)    {        inv[i] = inv[i + 1] * (i + 1) % mod;    }} 
long long C(int n,int m){    if(n < m) return 0;    return fac[n] * inv[m] % mod * inv[n - m] % mod;}


int main(){
	ll n,A,B,k;
	scanf("%lld%lld%lld%lld",&n,&A,&B,&k);
	init();
	ll ans = 0;
	for(ll a = 0;a <= n;a++){
		ll x = k - a * A;
		if(x < 0) continue;
		if(x % B) continue;
		ll b = x / B;
		if(b > n || b < 0 ) continue; 
		ans = (ans + C(n,a) * C(n,b) % mod) % mod;
	}	
	printf("%lld\n",ans);
}

Measured memory_bytes: 46976
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <queue>
#include <bitset>		//UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>		//do setprecision
#include <ctime>
#include <complex>
using namespace std;
 
#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)
 
#define ST first
#define ND second
#define PB push_back
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double
 
const double pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342;
 
const int MR = 510;
 
char s[MR][MR];
 
bool isBlack[MR];
 
int main()
{
	int N;
	scanf("%d", &N);
	REP(i,N)
		scanf("%s", s[i]);
	// spr czy cala biala plansza
	bool white = 1;
	REP(i,N)REP(j,N)
		if(s[i][j] == '#')
			white = 0;
	
	if(white)
	{
		printf("-1\n");
		return 0;
	}

	// ile kolumn zlych
	int bad = 0;
	REP(i,N)REP(j,N)
		if(s[j][i] == '.')
		{
			bad++;
			break;
		}
	// na jakich pozycjach sa czarne wiersze
	// zauwaz, ze jesli na danej pozycji nie ma czarnego wiersza
	// mozna to zrobic w 1 ruchu, jesli plansza nie jest cala biala
	REP(i,N)REP(j,N)
		if(s[j][i] == '#')
		{
			isBlack[i] = 1;
			break;
		}
	int res = MR;
	REP(i,N)
	{
		int ile = 0;
		REP(j,N)
			if(s[i][j] == '.')
				ile++;
		// jesli na danej pozycji nie bylo czarnego wiersza, musisz wykonac 1 ruch, zeby go zrobic
		if(!isBlack[i])
			ile++;
		res = min(res, ile);
	}

	// dodaj liczbe zlych kolumn na poczatku
	res += bad;
 
	printf("%d\n", res);
 
	return 0;
}

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

int main(){
  int h,w;
  cin>>h>>w;
  char map[51][51];
  for(int i=0;i<h;++i){
    for(int j=0;j<w;++j){
        cin>>map[i][j];
    }
  }
  int x[4]={1,0,-1,0},y[4]={0,1,0,-1};
  bool ans=true;
  for(int i=0;i<h;++i){
    for(int j=0;j<w;++j){
        if(map[i][j]=='#'){
                ans=false;
            for(int k=0;k<4;++k){
                if(i+y[k]>=0&&i+y[k]<h&&j+x[k]>=0&&j+x[k]<w){
                    if(map[i+y[k]][j+x[k]]=='#')ans=true;
                }
            }
            if(!ans){
                cout << "No" << endl;
                return 0;
            }
        }
    }
  }
  cout << "Yes" << endl;
  return 0;
}


Measured memory_bytes: 256
N = int(input())
A = list(map(int,input().split()))

def insertionSort(A,N):
    for i in range(1,N):
        v = A[i]
        j = i -1
        while j >= 0 and A[j] > v:
            A[j+1] = A[j]
            j -= 1
        A[j+1] = v

        outputNum(A)

def outputNum(A):
    tmp = map(str,A)
    text = " ".join(tmp)
    print(text)

outputNum(A)
insertionSort(A,N)



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

void fnInput(vector<int>& rvnTrg, vector<int>& rvnSch)
{
  int nSchCnt;
  cin >> nSchCnt;

  rvnSch.resize(nSchCnt + 1);
  for (int i = 0; i < nSchCnt; i++)
    cin >> rvnSch[i];

  int nTrgCnt;
  cin >> nTrgCnt;

  rvnTrg.resize(nTrgCnt);
  for (int i = 0; i < nTrgCnt; i++)
    cin >> rvnTrg[i];
}

void fnLinSch(const vector<int>& cnrvnTrg, vector<int>& rvnSch, int& rnFnd)
{
  size_t nMaxSiz = rvnSch.size() - 1;
  for (size_t ni = 0; ni < cnrvnTrg.size(); ++ni)
  {
    rvnSch[nMaxSiz] = cnrvnTrg[ni];
    size_t nj = 0;
    while (cnrvnTrg[ni] !=rvnSch[nj])
      ++nj;
    if (nj != nMaxSiz)
      ++rnFnd;
  }
}

void fnResult(int nFnd)
{
  cout << nFnd << endl;
}

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

  vector<int> vnTrg, vnSch;
  int nFnd = 0;

  fnInput(vnTrg, vnSch);
  fnLinSch(vnTrg, vnSch, nFnd);
  fnResult(nFnd);

  return 0;
}

Measured memory_bytes: 3236
import java.util.*;
 
public class Main{
 
	public static void main(String[] args){
 
		Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        String[] row = new String[N];
        int[] count = new int[N];
      
        for(int i = 0; i < N; i++){
          row[i] =sc.next();
        }
      
        Arrays.sort(row);
        int Max = 0;
        for(int i = 0; i < N; i++){
          for(int j = i+1; j < N; j++){
            if(row[i].equals(row[j])){
              count[i] +=1;
            }else{
              break;
            }
          }
          
          if(Max < count[i]){
            Max = count[i];
          }
          i += count[i];
        }
    
      for(int i = 0; i < N; i++){
          if(Max == count[i]){
            System.out.println(row[i]);
          }
        }
      
	}
}

Measured memory_bytes: 73028
#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 rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1e9+7;
const ll MOD2 = 998244353;
const ll INF = 1e18;
const string alpha = "abcdefghijklmnopqrstuvwxyz";

ll gcd(ll a, ll b){
    if(b == 0) return a;
    else return gcd(b, a%b);
}
ll lcm(ll a, ll b){
    return a*b/gcd(a,b);
}

int main(){
    int N;
    ll M;
    cin >> N >> M;
    ll a[N];
    rep(i, N) cin >> a[i];
    ll e[41];
    e[0] = 1;
    rep2(i, 1, 40) e[i] = e[i-1]*2;
    int k = 0;
    while(a[0]%2 == 0){
        a[0] /= 2;
        k++;
    }
    rep2(i, 1, N-1){
        if(a[i]%e[k] == 0 && a[i]%e[k+1] != 0){
            a[i] /= e[k];
        }
        else{
            cout << 0 << endl;
            exit(0);
        }
    }
    ll l = a[0];
    rep2(i, 1, N-1){
        l = lcm(l, a[i]);
        if(l > M/e[k-1]){
            cout << 0 << endl;
            exit(0);
        }
    }
    l *= e[k-1];
    cout << (M/l+1)/2 << endl;
}

Measured memory_bytes: 1024
fn read_lines() -> Vec<String> {
    use std::io::Read;

    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();
    return buf.lines().map(|e| e.to_string()).collect::<Vec<_>>();
}

fn main() {
    let input = read_lines();
    let n: usize = input[0].parse().unwrap();
    let input_series: Vec<usize> = input[1].split_whitespace().map(|e| e.parse().unwrap()).collect::<Vec<usize>>();

    // カウンタ配列を生成
    let max_series_element = 10_000;
    let mut counting: Vec<usize> = vec![0; max_series_element];
    for e in &input_series {
        counting[*e] += 1;
    }
    for i in 1..max_series_element {
        counting[i] += counting[i-1];
    }

    // カウンタ配列をもとに出力配列を作成
    let mut output_series = vec![0; n];
    for j in (0..n).rev() {
        let target_elem = input_series[j];
        let output_position = counting[target_elem] - 1;
        output_series[output_position] = target_elem;
        counting[input_series[j]] -= 1;
    }

    println!("{}", output_series.into_iter().map(|u| format!("{}", u)).collect::<Vec<_>>().join(" "));
}



Measured memory_bytes: 109408
N=int(input())
F=[int(input().replace(" ",""),2) for i in range(N)]
P=[list(map(int,input().split())) for i in range(N)]
print(max(sum([p[bin(f&i).count("1")] for f,p in zip(F,P)]) for i in range(1,2**10)))

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using i64 = long long;

int main() {
    int n;
    std::cin >> n;
    std::set<std::pair<int, int>> s;
    std::vector<std::pair<int, int>> v;
    for (int i = 0; i < n; i++) {
        int x, y;
        std::cin >> x >> y;
        v.emplace_back(x, y);
    }
    for (int i = 0; i < n; i++) for (int j = i + 1; j < n; j++) {
        auto p = std::make_pair(v[i].first - v[j].first, v[i].second - v[j].second);
        s.insert(p);
    }

    int ret = n;
    for (const auto &p : s) {
        int cost = n;
        for (int i = 0; i < n; i++) {
            auto it = std::find(v.begin(), v.end(), std::make_pair(v[i].first + p.first, v[i].second + p.second));
            if (it != v.end()) cost--;
        }
        ret = std::min(ret, cost);
    }
    std::cout << ret << std::endl;

    return 0;
}


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

int main(){
    int a, b;
    cin >> a;
    cin >> b;
    for(int i = 0; i <= 1250; ++i){
        if((int) (i * 0.08) == a && (int) (i * 0.1) == b){
            cout << i << endl;
            exit(0);
        }
    }
    cout << -1 << endl;
}

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

int main(void){
    string S;
    cin >> S;
    int N = S.size();
    long long sum = 0;

    for (int i = 0; i < (1 << (N - 1)); i++){
        long long tmp = S[0] - '0';
        for (int j = 0; j < N - 1; j++){
            if (i & (1 << j)){
                sum += tmp;
                tmp = S[j+1] - '0';
            } else {
                tmp = tmp * 10 + S[j+1] - '0';
            }
        }
        sum += tmp;
    }

    cout << sum << endl;
}

Measured memory_bytes: 256
import math

num = int(input())
step = []
sqrt_num = int(math.sqrt(num))
count=0

while True:
  for i in range(2,sqrt_num+2):
    if num == 2:
      count=1
      break
      
    if num%i == 0:
      count = 0
      break
      
    count=1
    
  if count == 1:
    break
    
  num = num+1
  sqrt_num = int(math.sqrt(num))

print(num)

Measured memory_bytes: 3064
#include<stdio.h>
#define NN 36
void show(int *,char *,int);
int check(char*,char *,int);
int main(){
  
  int i,j,n,foo,N[NN],A[NN],minA,mini;

  
  char C[NN],B[NN],Che[NN],hoge;
  scanf("%d",&n);

  
  for(i=0;i<n;i++){
    scanf(" %c%d",&C[i],&N[i]);
  }

  
  for(i=0;i<n;i++){
    A[i]=N[i];
    B[i]=C[i];
  }
  
  for(i=0;i<n-1;i++){//BS
    for(j=n-1;j>i;j--){
      if(A[j]<A[j-1]){
	foo=A[j];
	A[j]=A[j-1];
	A[j-1]=foo;
	hoge=B[j];
	B[j]=B[j-1];
	B[j-1]=hoge;
    }
    }
  }
    show(A,B,n);//BS show
      printf("Stable\n");

  for(i=0;i<n;i++){
    Che[i]=B[i];
    A[i]=N[i];
    B[i]=C[i];
  }
    
    for(i=0;i<n-1;i++){//SS
    minA=A[i];
    mini=i;
    for(j=i+1;j<n;j++){
      if(minA>A[j]){
	minA=A[j];
	mini=j;
      }
    }
    if(i!=mini){
    A[mini]=A[i];
    A[i]=minA;
    hoge=B[mini];
    B[mini]=B[i];
    B[i]=hoge;
    }
  }
    show(A,B,n);//SS show
    if(check(B,Che,n)==1)
      printf("Stable\n");
    else
      printf("Not stable\n");
  return 0;
}
   void show(int A[],char B[],int n){
     int i;
for(i=0;i<n;i++){
      if(i!=0)
	printf(" ");
      printf("%c%d",B[i],A[i]);
    }
 printf("\n");
   }
int check(char B[],char Che[],int n){
  int i;
  for(i=0;i<n;i++){
    if(B[i]!=Che[i])
      return 0;
  }
  return 1;
    
}



Measured memory_bytes: 2084
#!/usr/bin/env python

string = input()

n = int(input())

for i in range(n):
    command = input().split()
    if "replace" in command:
        string = string[:int(command[1])] + command[3] + string[int(command[2]) + 1:]
    elif "reverse" in command:
        toReverse = string[int(command[1]):int(command[2]) + 1]
        theReverse = ""
        for i in range(len(toReverse)):
            theReverse += toReverse[-(i + 1)]
        string = string[:int(command[1])] + theReverse + string[int(command[2]) + 1:]
    else:
        print(string[int(command[1]):int(command[2]) + 1])

Measured memory_bytes: 7672
// Sat May  2 17:37:17 IST 2020         
#include <bits/stdc++.h>        
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#define forn(ii,a,b)        for(int ii = (int)a ; ii < (int)b  ; ii++ )
#define debug(x)           cerr << #x << " " << x << " -- \n"
#define I__O               ios::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define int64              long long    
#define MOD                998244353 
#define pb                 push_back
#define f1                 first 
#define s1                 second    
#define all(x)             (x).begin(),(x).end() 
#define precise(x)         cout << fixed << setprecision(12) << x << '\n'; 
#define tough_nut          numeric_limits<int64>::min()
const double pi=3.141592653589793238;
using namespace std ;     
using namespace __gnu_pbds;
 
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set ; 
const int N = 2e5; 
const int INF = 2e9;
int tests(){
    int n ;  
    int year = 0 ;
    int64 amt = 100 ;
    int64 x ;cin >> x ;
    int64 total = amt ; 
    while(total < x){
        year++ ;
        total = amt + (amt)/100;
        amt  = total;
    } 
    cout << year << '\n';
    return 0;
}   
int32_t main(){
    I__O ;    
    int cases = 1 ; 
    // cin >> cases ; 
    forn(iii,1,cases+1){   
        // cout << "Case #" << iii << ": ";
        tests(); 
    }
    return 0 ; 
}
 
// -Wall -Wextra -O2
// -pedantic -std=c++11
// -D_GLIBCXX_DEBUG -D_GLIBCXX_DEBUG_PEDANTIC


Measured memory_bytes: 3660
# -*- coding: utf-8 -*-

#整数値龍力　複数の入力
def input_multiple_number():
    return map(int, input().split())

n,a,b = input_multiple_number()

pattern = n //(a+b)
blue = pattern*a
red = pattern*b

rest = n%(a+b)

if rest <= a:
    blue += rest
else:
    blue += a
    red += (rest-a)

print(blue)


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

class edge:
   f, t, c = 0, 0, 0

inf = 10 ** 5 * (M + 1)
D = [inf] * N
D[0] = 0
E = [edge() for _ in range(M)]
for i in range(M):
  f, t, c = ABC[i]
  E[i].f = f - 1
  E[i].t = t - 1
  E[i].c = P - c
  
L = [False] * N
L[-1] = True
for i in range(N):
  for j in range(M):
    e = E[j]
    if L[e.t]:
      L[e.f] = True

cnt = N + 1
while True:
  flag = True
  for i in range(M):
    e = E[i]
    if D[e.f] != inf and D[e.t] > D[e.f] + e.c:
      D[e.t] = D[e.f] + e.c
      flag = False
      if cnt == 1:
        if L[e.t]:
          print(-1)
          exit()
  if flag:
    break
  cnt -= 1
  if cnt <= 0:
    break

print(max(0, -D[-1]))

Measured memory_bytes: 47704
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstring>
#include <math.h>
#include <numeric>
#define rep(i,s,n) for (int i = s; i < n; ++i)
#define drep(i,s,n) for (int i = n; i >= s; --i)
#define all(x) (x).begin(),(x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define print(x) cout<<(x)<<endl
using namespace std;
typedef long long ll;

int gcd(int a, int b)
{
   if (a%b == 0) return(b);
   else          return(gcd(b, a%b));
}
int lcm(int a, int b)
{
   return a * b / gcd(a, b);
}
void printvv(vector<vector<auto>> vv, int n)
{
  cout << '[' << endl;
  rep(q, 0, n)
  {
    cout << '[';
    rep(p, 0, n)
    {
      cout << vv.at(q).at(p) << ',';
    }
    cout << ']' << endl;
  }
  cout << ']' << endl;
}

void solve();
int main(){cin.tie(0);ios::sync_with_stdio(0);solve();}

//------------------------------------------------------------
void solve() {
  int a,b,c,d;
  cin >> a >> b>>c>>d;

  if (b<c || a>d) print(0);
  else print(min(b,d)-max(a,c));

  return;
}


Measured memory_bytes: 256
def main():
    N = int(input())
    A = list(map(int, input().split()))
    count = 0

    s = [0 for _ in range(N+1)]
    for i in range(N):
        s[i+1] = s[i] + A[i]
    s.sort()
    n = 1
    for i in range(N):
        if s[i+1] == s[i]:
            n+=1
        else:
            count += n*(n-1)//2
            n = 1
    count += n*(n-1)//2
    return count

if __name__ == '__main__':
    print(main())

    

Measured memory_bytes: 26136
#include "bits/stdc++.h"
using namespace std;

#define EACH(i,a) for (auto&& i : a)
#define FOR(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RFOR(i,a,b) for(int i=(int)b-1;i>=(int)a;--i)
#define REP(i,n) FOR(i,0,n)
#define REPS(i,n) FOR(i,1,n+1)
#define RREP(i,n) RFOR(i,0,n)
#define RREPS(i,n) RFOR(i,1,n+1)
#define ALL(x) (x).begin(),(x).end()
#define MEMSET(v, h) memset((v), h, sizeof(v))
#define debug(x) cout << #x << ": " << x << endl

#define pb push_back
#define mp make_pair
#define F first
#define S second

#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev
#define INF (1L << 30)
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-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 (b<a) { a=b; return 1; } return 0; }
using ll = long long;
#define int ll

bool grids[100][100];

int makeSQ(int x, int y){
    grids[x][y] = 1;
    grids[x+1][y] = 1;
    grids[x+2][y] = 1;
    grids[x][y+1] = 1;
    grids[x][y+2] = 1;
    grids[x+2][y+1] = 1;
    grids[x+2][y+2] = 1;
    grids[x+1][y+2] = 1;
    return 0;
}

//**********

signed main(void) {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int a,b;
    cin >> a >> b;
    REP(i,100){REP(j,100){grids[i][j]=0;}} //0: 多い方
    int h = 100;
    int w = 100;
    bool black_big = 0;
    if(a<b){black_big = 1; swap(a,b);}
    
    if(a==b){
        REP(i,b-1){
            makeSQ(1+(i/24)*4,(4*i+1)%96);
        }
        grids[0][0]=1;
    } else {
        int diff = a-b;
        REP(i,b-1){
            makeSQ(1+(i/24)*4,(4*i+1)%96);
        }
        REP(i,diff){
            makeSQ(97-(1+(i/32)*3),97-((3*i+1)%96));
        }
    }
    
    printf("%lld %lld\n",h,w);
    if(black_big==1){
        REP(i,h){
            REP(j,w){if(grids[i][j]==0){printf("#");}else{printf(".");}}
            printf("\n");
        }
    } else {
        REP(i,h){
            REP(j,w){if(grids[i][j]==0){printf(".");}else{printf("#");}}
            printf("\n");
        }
    }
    //    else printf("No\n");
    
    return 0;
    
}


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


int main(){
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  int n;
  cin>>n;
  int d=n/1000;
  int l=n%1000;
  if(l==0){
    cout<<0<<endl;
  }else{
    cout<<(d+1)*1000-n<<endl;
  }


       
  
}

Measured memory_bytes: 3640
#include<stdio.h>
int main(){
	double r;
    double s;
    double l;
    scanf("%lf", &r);
    s = r * r * 3.141592653589;
    l = 2 * r * 3.141592653589;
    printf("%lf %lf\n", s, l);
    return 0;
}



Measured memory_bytes: 2100
while True:
    try:
        N, X = map(int, input().split())
        L = list(map(int, input().split()))
        D = [0]
        for i in range(1, N+1):
            tmp = D[i-1] + L[i-1]
            D.append(tmp)
            if tmp > X:
                print(i)
                break
        else:
            print(N+1)
    except:
        break

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <map>
#include <string>
#include <algorithm>

using namespace std;

void solve()
{
	int N;
	cin >> N;
	int a;
	vector<int> odd;
	vector<int> even;
	vector<int> fourEven;
	for (int i = 0; i < N; ++i)
	{
		cin >> a;
		if (a % 4 == 0)
		{
			fourEven.push_back(a);
		}
		else if (a % 2 == 0)
		{
			even.push_back(a);
		}
		else
		{
			odd.push_back(a);
		}
	}
	int oddSize = odd.size();
	int evenSize = even.size();
	int fourEvenSize = fourEven.size();
	int current = 0;
	if (oddSize > 0)
	{
		current = 1;
		--oddSize;
	}
	else if (evenSize > 0)
	{
		current = 2;
		--evenSize;
	}
	else
	{
		current = 4;
		--fourEvenSize;
	}
	while (true)
	{
		if (oddSize == 0 && evenSize == 0 && fourEvenSize == 0)
		{
			break;
		}
		if (current == 1)
		{
			if (fourEvenSize > 0)
			{
				current = 4;
				--fourEvenSize;
				continue;
			}
			else
			{
				cout << "No" << endl;
				return;
			}
		}
		else if (current == 2)
		{
			if (evenSize > 0)
			{
				current = 2;
				--evenSize;
				continue;
			}
			else if (fourEvenSize > 0)
			{
				current = 4;
				--fourEvenSize;
				continue;
			}
			else
			{
				cout << "No" << endl;
				return;
			}
		}
		else if (current == 4)
		{
			if (oddSize > 0)
			{
				current = 1;
				--oddSize;
				continue;
			}
			else if (evenSize > 0)
			{
				current = 2;
				--evenSize;
				continue;
			}
			else
			{
				current = 4;
				--fourEvenSize;
				continue;
			}
		}
	}
	cout << "Yes" << endl;
}

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

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

using namespace std;

const int inf = (int) (2e9);

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n, w;
    cin >> n >> w;
    vector<int> we(n), va(n);
    int va_sum = 0;
    for (int i = 0; i < n; ++i) {
        cin >> we[i] >> va[i];
        va_sum += va[i];
    }
    vector<long long> dp(va_sum + 1, inf);
    dp[0] = 0;
    for (int i = 0; i < n; ++i) {
        for (int j = va_sum - va[i]; j >= 0; --j) {
            dp[j + va[i]] = min(dp[j + va[i]], dp[j] + we[i]);
        }
    }
    for (int i = va_sum; i >= 0; --i) {
        if (dp[i] <= w) {
            cout << i << '\n';
            break;
        }
    }
    return 0;
}

Measured memory_bytes: 4000
#include <iostream>
#define ll long long int
using namespace std;


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

	for (int i = 0; i < k; ++i) {
		if(i%2==0){
			if(a%2==1){
				a--;
			}
			b += a/2;
			a = a/2;
		}else{
			if(b%2==1){
				b--;
			}
			a += b/2;
			b = b/2;
		}
	}
	cout << a << " " << b << endl;

	return 0;
}


Measured memory_bytes: 256
n, a, b, c, d = map(int, input().split())
diff_ab = abs(b-a)
diff_cd = d - c
mod = c + d
mod_ab = diff_ab % mod
MAX = d * (n-1)
MAX_mod = MAX % mod
MIN_mod = (c * (n-1)) % mod
if MAX >= diff_ab:
    if diff_cd * (n-1) + 1 >= mod:
        print("YES")
    else:
        if MAX_mod >= MIN_mod:
            if mod_ab <= MAX_mod and mod_ab >= MIN_mod:
                print("YES")
            else:
                print("NO")
        else:
            if mod_ab >= MIN_mod or mod_ab <= MAX_mod:
                print("YES")
            else:
                print("NO")
        
else:
    print("NO")

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < (int)n; i++)
#define all(x) x.begin(), x.end()
#define MOD 1000000007//1e9+7
typedef long long ll;
using namespace std;
int main()
{
  string s;
  cin >> s;
  int ans = s[0] - '0' + s[1] - '0' + s[2] - '0';
  cout << ans << endl;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
    if(A > 9 || B > 9){
      System.out.println("-1");
    }else{
      System.out.printf("%d", A*B);
    }
	}
}

Measured memory_bytes: 23252
s1 = input()
n1 = len(s1)
s2 = input()
n2 = len(s2)

D = [[0 for j in range(n2)]for i in range(n1)]

if s1[0] == s2[0]: D[0][0] = 0
else: D[0][0] = 1
for j in range(1, n2):
    if s1[0] == s2[j]:
        delta = abs(j)
        D[0][j] = delta
    else:
        D[0][j] = D[0][j-1]+1
for i in range(1, n1):
    if s1[i] == s2[0]:
        delta = abs(i)
        D[i][0] = delta
    else:
        D[i][0] = D[i-1][0]+1
        
for i in range(1, n1):
    for j in range(1, n2):
        if s1[i] == s2[j]:
            D[i][j] = min(D[i-1][j-1], D[i-1][j]+1, D[i][j-1]+1)
        else:
            D[i][j] = min(D[i-1][j-1]+1, D[i-1][j]+1, D[i][j-1]+1)
            

print(D[n1-1][n2-1])



Measured memory_bytes: 42848
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0,i##_len=(n);i<i##_len;++i)
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define All(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;

int main(){
    string s;cin>>s;
    int ans=700;
    REP(i,s.size()) if(s[i]=='o') ans+=100;
    cout<<ans<<endl;
}


Measured memory_bytes: 256
import java.util.Scanner;
 


public class Main {
	static int a1[]= {0,-1,0,1};
	static int b1[]= {-1,0,1,0};
	private static Scanner sc = new Scanner(System.in);
	private static Scanner s = new Scanner(System.in);
	static void p(String ans) {System.out.println(ans);};
	static void p(int ans) {System.out.println(ans);};
	static void p(long ans) {System.out.println(ans);};
	static void p(double ans) {System.out.println(ans);};
	//result = Math.pow(num1, num3)
	//StringBuffer str = new StringBuffer(hoge1);
	//String hoge2 = str.reverse().toString();
	//map.containsKey(A)

	//Map<String, Integer> map = new HashMap<String, Integer>(n);
	/*for ( キーのデータ型 key : マップの名前.keySet() ) {
		データのデータ型 data = マップの名前.get( key );
		
		// keyやdataを使った処理;
	}*/
	//int i = Integer.parseInt(s);
	//Queue<String> qq=new ArrayDeque<>(); //add,poll,peek
	//Deque<String> qq=new ArrayDeque<>();//push,pop,peek
	//ArrayList<String> cc = new ArrayList<>(n);
	//Collections.sort(list);
	//Array.sort(list);
	//Arrays.asList(c).contains("a")
	//list.set(1,"walk");
	public static void main(String[] args) {
		int K=s.nextInt();			
		long ans=0;
		for(int a=1;a<=K;a++) {
			for(int b=1;b<=K;b++) {
				for(int c=1;c<=K;c++) {
					ans+=gcd(a,gcd(b,c));
				}
			}
		}
		p(ans);
		/*int N=sc.nextInt();
		for(int i=0;i<N;i++) {
			int x=sc.nextInt();
		}*/
		
		
		
				
		
	}
	public static int gcd(int num1,int num2) {
        if(num2==0) return num1;
        else return gcd(num2,num1%num2);
    }
}


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

int main() {
  int N;
  cin >> N;
  int A[110000];
  int count = 0;
  
  for (int i=0;i<N;i++) {
    cin >> A[i];
    if (A[i]%2 != 0) count++; 
  }
  
  if (count%2 == 0) cout << "YES" << endl;
  else cout << "NO" << endl;
}

Measured memory_bytes: 640
N = int(input())
A = list(map(int, input().split()))

def combi2(n):
    return n*(n-1)//2

cnt = {}
for a in A:
    if a not in cnt:
        cnt[a] = 1
    else:
        cnt[a] += 1
res = 0
for k, v in cnt.items():
    if v >= 2:
        res += combi2(v)

ans = []
for a in A:
    v = cnt[a]
    if v >= 2:
        ans.append(res-combi2(v)+combi2(v-1))
    else:
        ans.append(res)
for a in ans:
    print(a)



Measured memory_bytes: 26140
#include <iostream>
#include <math.h>
//#include <numeric>
#include <vector>
//#include <map>
#include <algorithm>
//#include <queue>

using namespace std;
#define n_max 10000
#define INF 10001000

#define rep(i, a, n) for(int i = a; i < n; i++)
#define rep2(i, a, n) for(int i = a; i <= n; i++)
#define rrep(i, a, n) for(int i = a; i > n; i--)
#define rrep2(i, a, n) for(int i = a; i >= n; i--)
#define lrep(i, a, n) for(long int i = a; i < n; i++)
#define in(a) cin >> a
#define out(a) cout << a << endl

int main()
{
    int ans = 0;
    int a, b;

    cin >> a >> b;
    
    cout << max(max(a*b, a+b), a-b) << endl;
    //cout << a << " " << b << endl;

    return 0;
}


Measured memory_bytes: 256
#[allow(unused_imports)]
use std::cmp::{Ordering};

#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};

#[allow(unused_imports)]
use std::io::{stdin, stdout, BufWriter, Write};

#[allow(unused_imports)]
use std::iter::FromIterator;

#[allow(unused_macros)]
macro_rules! min {
    ($x: expr) => ($x);
    ($x: expr, $($z: expr),+) => {{
        std::cmp::min($x, min!($($z),*))
    }}
}

#[allow(unused_macros)]
macro_rules! max {
    ($x: expr) => ($x);
    ($x: expr, $($z: expr),+) => {{
        std::cmp::max($x, max!($($z),*))
    }}
}

#[allow(unused_macros)]
macro_rules! get { 
    ([$t: ty]) => { 
        { 
            let mut line = String::new(); 
            stdin().read_line(&mut line).unwrap(); 
            line.split_whitespace().map(|t|t.parse::<$t>().unwrap()).collect::<Vec<_>>()
        }
    };
    ([$t: ty];$n: expr) => {
        (0..$n).map(|_|get!([$t])).collect::<Vec<_>>()
    };
    ($t: ty) => {
        {
            let mut line = String::new();
            stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t: ty),*) => {
        { 
            let mut line = String::new();
            stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            ($(iter.next().unwrap().parse::<$t>().unwrap(),)*)
        }
    };
    ($t: ty; $n: expr) => {
        (0..$n).map(|_|get!($t)).collect::<Vec<_>>()
    };
    ($($t: ty),*; $n: expr) => {
        (0..$n).map(|_|get!($($t),*)).collect::<Vec<_>>()
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*).unwrap();
    }
}

const BIG_STACK_SIZE: bool = true;

#[allow(dead_code)]
fn main() {
    use std::thread;
    if BIG_STACK_SIZE {
        thread::Builder::new()
            .stack_size(32 * 1024 * 1024)
            .name("solve".into())
            .spawn(solve)
            .unwrap()
            .join()
            .unwrap();
    } else {
        solve();
    }
}

fn solve() {
    let n = get!(usize);
    let a = get!(usize; 5);
    let mn = a.into_iter().min().unwrap();
    if n % mn == 0 {
        println!("{}", n/mn + 4);
    } else {
        println!("{}", n/mn + 5);
    }
}


Measured memory_bytes: 8572
/******************************************************/
/******************************************************/
/**                                                  **/
/**            BISMILLAHIR RAHMANIR RAHIM            **/
/**         REAZ AHAMMED CHOWDHURY - reaziii         **/
/**  Department of Computer Science and Engineering  **/
/*         INSTITUTE OF SCIENCE AND TECHNOLOGY       **/
/**                                                  **/
/******************************************************/
/******************************************************/
#include<bits/stdc++.h>
#define sc(x)        scanf("%lld",&x)
#define pcase(x)     printf("Case %d: ",x++)
#define pn           printf("\n")
#define fri(f)       for(int i=0;i<f;i++)
#define frj(f)       for(int j=0;j<f;j++)
#define reset(x,e)   memset(x,e,sizeof(x))
#define all(x)       x.begin(),x.end()
#define input        freopen("input.txt","r",stdin);
#define output       freopen("output.txt","w",stdout)
#define infi         INT_MAX
#define m_v          3000000
#define pii          pair<int,int>
#define pch          pair<char,char>
#define pll          pair<ll,ll>
#define mgraph       map<int,vector<int> >
#define mp           make_pair
#define pb           push_back
#define clr(x)       memset(x,0,sizeof(x))
#define frx(x,y)     for(int x=0;x<y;x++)
#define ff           first
#define ss           second
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
bool checkbitt(ll num, int pos);
ll setbitt(ll num, ll pos);
ll resetbitt(ll num, int pos);
void abcd() {
#ifndef ONLINE_JUDGE
	input;
	output;
#endif
#ifdef ONLINE_JUDGE
	ios_base::sync_with_stdio(false);
	cin.tie(0);
#endif
}

void read(int *aa, int sz) {fri(sz) scanf("%d", (aa + i));}
void read(ll *aa, int sz) {fri(sz) scanf("%lld", (aa + i));}
void read(ll *aa, int s, int e) {for (int i = s; i < s + e; i++)scanf("%lld", (aa + i));}
void read(int *aa, int s, int e) {for (int i = s; i < s + e; i++)scanf("%d", (aa + i));}
const ll mod =       1e9 + 7;
const ll N =     1e6 + 10;

//.................___Start from here___.................//
//.................._____________________................//


int arr[N];
int w[N];
int v[N];
int n, W;



int solve() {
	cin >> n >> W;
	vector<ll> dp(1e8, infi);
	for (int i = 1; i <= n; i++) {
		cin >> w[i] >> v[i];
	}
	dp[0] = 0;
	for (int i = n; i >= 1; i--) {
		for (int j = 1e7 + 10; j >= 0; j--) {

			if (j >= v[i]) dp[j] = min(dp[j], dp[j - v[i]] + w[i]);
		}
	}

	int res = 0;
	for (int i = 0; i < N; i++) if (W >= dp[i]) res = i;
	cout << res << endl;






	return 0;
}
int main() {
	abcd();
	int cs = 1;
	int cn = 1;
	//cin>>cs;
	while (cs--) {
		solve();

	}
}


bool checkbitt(ll num, int pos) {return (num >> pos) & 1;}
ll setbitt(ll num, ll pos) {return (1 << pos) | num;}
ll resetbitt(ll num, int pos) {if (!checkbitt(num, pos)) return num; else return (1 << pos)^num;}




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

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

int main(){
	int a[]={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; scanf("%d",&k); k--;
	printf("%d\n",a[k]);
	return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Math;
using static System.Console;

namespace C_ABC127
{
    class MainClass
    {

        static int[] s;

        public static void Main(string[] args)
        {
            s = Array.ConvertAll(ReadLine().Split().ToArray(), int.Parse);
            int l = -1;
            int r = int.MaxValue;
            for(int i=0;i<s[1];i++){
                int[] lr = Array.ConvertAll(ReadLine().Split().ToArray(), int.Parse);
                if(lr[0]>l){
                    l= lr[0];
                }
                if(lr[1]<r){
                    r=lr[1];
                }
            }
            int ans = Max(0,r-l+1);
            WriteLine(ans);
        }
        
    }
}


Measured memory_bytes: 17360
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, n) for(int i = 1, i##_len = (n); i < i##_len; ++i)
#define ALL(x) (x).begin(), (x).end()
#define PRINT(A) std::cout << (#A) << ":" << (A) << std::endl;
 
typedef long long int ll;
const int MOD = 1e9 + 7;
const int INF = 1e9;
 
using namespace std;
using Edge = pair<int, long long>;
using Graph = vector<vector<Edge>>;
 
void dfs(int n, ll dist, int p, vector<ll>& d, Graph& g) {
  for(auto e : g.at(n)) {
    if(e.first == p) continue;
    d.at(e.first) = dist + e.second;
    dfs(e.first, d.at(e.first), n, d, g);
  }
}
 
int main() {
  int N, Q, K;
  cin >> N;
 
  vector<ll> d = vector<ll>(100010);
  Graph g = Graph(100010);
  int a, b, c;
  REP(i, N - 1) {
    cin >> a >> b >> c;
    a--;
    b--;
    g.at(a).push_back({b, c});
    g.at(b).push_back({a, c});
  }
 
  cin >> Q >> K;
  K--;
  dfs(K, 0, -1, d, g);
 
  int x, y;
  REP(i, Q) {
    cin >> x >> y;
    x--;
    y--;
    ll ans = d.at(x) + d.at(y);
    cout << ans << endl;
  }
}

Measured memory_bytes: 17408
import java.util.*;
import java.lang.*;
import java.math.*;
import java.io.*;

import static java.lang.Math.*;
import static java.util.Arrays.*;

public class Main{

	Scanner sc=new Scanner(System.in);

	int INF=1<<28;
	double EPS=1e-9;

	void run(){
		for(;;){
			int m=sc.nextInt();
			if(m==0){
				break;
			}
			HashMap<String, String> map=new HashMap<String, String>();
			for(int i=0; i<m; i++){
				String s=sc.next();
				String t=sc.next();
				map.put(s, t);
			}
			int n=sc.nextInt();
			for(int i=0; i<n; i++){
				String s=sc.next();
				print(map.containsKey(s)?map.get(s):s);
			}
			println("");
		}
		System.out.flush();
	}

	void debug(Object... os){
		System.err.println(Arrays.deepToString(os));
	}

	void print(String s){
		System.out.print(s);
	}

	void println(String s){
		System.out.println(s);
	}

	public static void main(String[] args){
		System.setOut(new PrintStream(new BufferedOutputStream(System.out)));
		new Main().run();
	}
}

Measured memory_bytes: 13000
from heapq import *

n, k = map(int,input().split())
T = [[] for i in range(n)]
for i in range(n):
    t,d = map(int,input().split())
    T[t-1].append(d)
Top = []
for i in range(n):
    if T[i]:
        T[i].sort(reverse=True)
        Top.append((T[i][0],i))
Top.sort(reverse = True)

various = len(Top)


ans = 0
s = 0
sushi = []
heapify(sushi)
l = 0

for j,(t,i) in enumerate(Top[:k]):
    s += t
    if l + j + 1 > k:
        s -= heappop(sushi)
        l -= 1
    for new in T[i][1:]:
        if l + j + 1 >= k:
            s += new
            s -= heappushpop(sushi,new)
        else:
            s += new
            l += 1
            heappush(sushi, new)
    ans = max(ans, s + (j+1)**2)
print(ans)


Measured memory_bytes: 94156
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from sys import stdin
import math

# 標準入力をスペースで区切って、intに変換 listに収納
str_list  = stdin.readline().rstrip()


kisu = ['R','U','D']
gusu = ['L','U','D']


for i in range(len(str_list)):
    # 0から始まるので奇数なら偶数の配列を確かめる
    if i % 2 == 0:
        if str_list[i] in kisu:
            pass
        else:
            ans='No'
            break

    else:
        if str_list[i] in gusu:
            pass
        else:
            ans='No'
            break
else:
    ans='Yes'

print(ans)
            





Measured memory_bytes: 3060
package main

import (
	"bufio"
	"fmt"
	"math/big"
	"os"
	"strconv"
)

func main() {
	N := readInt()
	A := make([]*big.Int, N)
	for i := 0; i < N; i++ {
		A[i] = big.NewInt(int64(readInt()))
	}

	t := new(big.Int)

	lcm := big.NewInt(1)
	for i := 0; i < N; i++ {
		t.GCD(nil, nil, lcm, A[i])
		lcm.Mul(lcm, A[i])
		lcm.Div(lcm, t)
	}

	result := big.NewInt(0)
	for i := 0; i < N; i++ {
		result.Add(result, t.Div(lcm, A[i]))
	}
	result.Rem(result, big.NewInt(1000000007))

	fmt.Println(result)
}

const (
	ioBufferSize = 1 * 1024 * 1024 // 1 MB
)

var stdinScanner = func() *bufio.Scanner {
	result := bufio.NewScanner(os.Stdin)
	result.Buffer(make([]byte, ioBufferSize), ioBufferSize)
	result.Split(bufio.ScanWords)
	return result
}()

func readString() string {
	stdinScanner.Scan()
	return stdinScanner.Text()
}

func readInt() int {
	result, err := strconv.Atoi(readString())
	if err != nil {
		panic(err)
	}
	return result
}


Measured memory_bytes: 5760
N,M,*as=$<.read.split.map(&:to_i)

as = as.sort_by {|a|-a}
bs = []
m = M
while 0 < m
  if bs.empty? || as[0] > bs[0]
    a = as.shift
    bs << (a>>1)
  else
    b = bs.shift
    bs << (b>>1)
  end
  m -= 1
  if as.empty?
    as = bs
    bs = []
  end
end

ret = (as+bs).inject(&:+)
p ret



Measured memory_bytes: 12408
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Tue Feb 26 17:52:43 2019

@author: nakamuratakayuki
"""

R,G,B,N = tuple(map(int,input().split()))
L = [R,G,B]
L.sort(reverse=True)
c = 0
rmax = N//L[0]

for i in range(rmax+1):
    Nc = N
    Nc -= i*L[0]
    if Nc%L[2] == 0:
            c += 1
    while True:
        Nc -= L[1]
        if Nc < 0:
            break
        if Nc%L[2] == 0:
            c += 1

print(c)

Measured memory_bytes: 3064
#include<iostream>
using namespace std;
int main(){
    int r, c, T[101][101];
    cin >> r >> c;
    for(int i = 0; i < r; i++){
        for(int j = 0; j < c; j++){
            cin >> T[i][j];
            T[i][j+1] = 0;
        }
    }

    for(int i = 0; i <= r; i++){
        T[i][c] = 0;
    }

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

    for(int i = 0; i <= r; i++){
        for(int j = 0; j <= c; j++){
            if(j) cout << " ";
            cout << T[i][j];
        }
        cout << endl;
    }

    return 0;
}


Measured memory_bytes: 3096
#include <iostream>

using namespace std;

int main() {
	int N;
	cin >> N;
	int a;
	int b;
	int res = 0, count = 0;
	cin >> a;
	for (int i = 1; i < N; i++) {
		cin >> b;
		if (a >= b) count++;
		else count = 0;
		res = (res > count) ? res : count;
		a = b;
	}
	cout << res << endl;
	return 0;
}

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

int main() {
  vector<int> v;
  int n, k;
  REP(i, 3) {
    cin >> n;
    v.push_back(n);
  }
  cin >> k;
  sort(v.begin(), v.end());

  REP(i, k) {
    v[2] *= 2;
  }
  cout << v[0] + v[1] + v[2] << endl;
  return 0;
}

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

// definition {{{ 1

// scaning {{{ 2
#define Scd(x) scanf("%d", &x)
#define Scd2(x,y) scanf("%d%d", &x, &y)
#define Scd3(x,y,z) scanf("%d%d%d", &x, &y, &z)

#define Scll(x) scanf("%llu", &x)
#define Scll2(x,y) scanf("%llu%llu", &x, &y)
#define Scll3(x,y,z) scanf("%llu%llu%llu", &x, &y, &z)

#define Scc(c) scanf("%c", &c);
#define Scs(s) scanf("%s", s);
#define Scstr(s) scanf("%s", &s);
// }}} 2

// constants {{{ 2
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
// }}} 2

// systems {{{ 2
#define Rep(x,y) for(int x = 0; x < y; x++)
#define Repe(x,y,z) for(int x = z; x < y; x++)
// }}} 2

// output {{{ 2
#define YesNo(a) (a)?printf("Yes\n"):printf("No\n");
// }}} 2

// }}} 1


int main() {

    set<int> s;

    int n,a;
    Scd(n);
    Rep(i,n){
        Scd(a);
        if( s.find(a) != s.end() )
            s.erase(a);
        else
            s.insert(a);
    }

    printf ("%d\n", s.size());

    return 0;
}



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

char s[19];
int main(){

for(int i=0;i<19;i++){
	cin>>s[i];

}
for(int i=0;i<19;i++){
	if(s[i]==',')
	cout<<' ';
	else
	cout<<s[i];
}

	return 0;
} 


Measured memory_bytes: 256