akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#define INFINITY 1000000
#define MAX_N 10

using namespace std;

int n,d[MAX_N][MAX_N] = {};

int main() {
  int city, mincity;
  int  temp1, temp2, temp3, alt,costtime, cost;
  while (1) {
    d[MAX_N][MAX_N] = {};
    cin >> n;
    if (n == 0) break;
    city = mincity = 0;
    for (int i = 0; i < MAX_N; ++i)
      for (int j = 0; j < MAX_N; ++j)
        if (i != j) d[i][j] = INFINITY;

    for (int i = 0; i < n; ++i) {
      cin >> temp1 >> temp2 >> temp3;

        d[temp1][temp2] = temp3;
        d[temp2][temp1] = temp3;
      if (city < temp1 || city < temp2) { city = (temp1 > temp2) ? temp1 : temp2; }
    }
    //cout << city <<endl;
    city++;




    for (int i = 0; i < city; ++i)
      for (int j = 0; j < city; ++j)
        for (int k = 0; k < city; ++k) {
          if (d[j][i] != INFINITY && d[i][k] != INFINITY) {
            alt = d[j][i] + d[i][k];
            if (alt < d[j][k]) d[j][k] = alt;
          }
        }


    for (int i = 0; i < city; ++i) {
      cost = 0;
      for (int j = 0; j < city; ++j) {
        if(d[i][j] != INFINITY)
        cost += d[i][j];
        //cout << d[i][j] << " ";
      }
      //cout << endl;
      if (i == 0) costtime = cost;
      if (costtime > cost) {
        costtime = cost;
        mincity = i;
      }
    }
    cout << mincity << " " << costtime << endl;

  }
  return 0;
}

Measured memory_bytes: 1160
a = list(input())
b = list(input())
c = list(input())

i = 1
j = 0
k = 0
last = a[0]

while i<=len(a) and j<=len(b) and k<=len(c):
    if last == 'a':
        if i < len(a):
            last = a[i]
        i += 1
    if last == 'b':
        if j < len(b):
            last = b[j]
        j += 1
    if last == 'c':
        if k < len(c):
            last = c[k]
        k += 1

if i == len(a)+1:
    print('A')
elif j == len(b)+1:
    print('B')
elif k == len(c)+1:
    print('C')

Measured memory_bytes: 9096
//============================
// ABC134a Dodecagon
//
// 2019/08/14
//============================

#include <iostream>
#include <string>
#include <cmath>
#include <vector>
#include <map>
#include <algorithm>
#include <functional>

using namespace std;

int main(int argc, char* argv[])
{
  int r;
  cin >> r;
  cout << 3*r*r << endl;

  return 0;
}

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

const ll MAXN = 200000;
const ll INF = 1001001001;
const ll MOD = 1000000007;

ll N, K, C, ans=0, tmp=0;
string S;
vector<ll> v1, v2, A;

signed main(){
    cin >> N >> K >> C >> S;
    v1.resize(N,0);
    v2.resize(N,0);
    tmp = 0;
    for(int i=0;i<N;i++) {
        if(S[i]=='o') {
            v1[i]=1;
            i+=C;
            tmp++;
            if(tmp==K) break;
        }
    }
    tmp = 0;
    for(int i=0;i<N;i++) {
        if(S[N-1-i]=='o') {
            v2[N-1-i]=1;
            i+=C;
            tmp++;
            if(tmp==K) break;
        }
    }
    /*
    for(int i=0;i<N;i++) {
        cout << v1[i];
    }
    cout << endl;
    for(int i=0;i<N;i++) {
        cout << v2[i];
    }
    cout << endl;
    */
    ll ct1=0, ct2=0;
    for(int i=0;i<N;i++) {
        if(v1[i]>0) {
            v1[i] += ct1;
            ct1++;
        }
    }
    for(int i=0;i<N;i++) {
        if(v2[i]>0) {
            v2[i] += ct2;
            ct2++;
        }
    }
    for(int i=0;i<N;i++) {
        if(v1[i]==v2[i]&&v1[i]!=0) A.push_back(i+1);
    }
    for(int i=0;i<A.size();i++) {
        cout << A[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 8492
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author NikuKyabe
 */

#include <iostream>
#include <fstream>

#include "bits/stdc++.h"

using namespace std;
#define int long long

class BAtCoderBeginnerContest111 {
public:
    void solve(std::istream &in, std::ostream &out) {
      int n;
      in >> n;
      int t = 111;
      int i = 1;
      while (n > t) {
        i++;
        t = 111 * i;
      }
      out << 111 * i << endl;
    }
};


signed main() {
  ios::sync_with_stdio(false);
  cout.tie(0);
  cout << fixed;
  BAtCoderBeginnerContest111 solver;
  std::istream &in(std::cin);
  std::ostream &out(std::cout);
  solver.solve(in, out);
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <math.h>
using namespace std;
 
int main(){
    string S;
    cin >> S;
    int out = 0;
    for(int i =0; i < S.size();i++){
      if(S[i] == '+') out++;
      if(S[i] == '-') out--;
    }
    cout << out << endl;
  return 0;
}

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

using namespace std;

using VI = vector<int>;
using VVI = vector<VI>;
using VB = vector<bool>;
using VVB = vector<VB>;
using VD = vector<double>;
using VVD = vector<VD>;
using VS = vector<string>;
using PII = pair<int, int>;
using VPII = vector<PII>;
using VL = vector<long long>;
using VVL = vector<VL>;

#define sz(var) (int)var.size()
#define REP(var, start, end) for(int var = start; var < (int)end; ++var)
#define REPC(var, start, end) for(int var = start; var <= (int)end; ++var)
#define CLEAR(var, with) memset(var, with, sizeof(var))
#define ALL(x) x.begin(), x.end()
#define LL long long
#define ULL unsigned long long
#define TIME cerr << "Time elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms" << endl;
#define DBG(x) cerr << x << endl;

/*
	http://abc072.contest.atcoder.jp/tasks/arc082_b
*/
int n;
VI A;
int solve()
{
	int ret = 0;
	for(int i = 1; i <= n; ++i)
	{
		if(A[i] == i)
		{
			++ret;
			int delta = i == n ? -1 : 1;
			swap(A[i], A[i + delta]);
		}
	}
	for(int i = 1; i <= n; ++i)
		if(A[i] == i) throw;
	return ret;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
//	freopen("tmp.in", "r", stdin);
	//freopen("tmp.out", "w", stderr);
#endif
	cin >> n;
	
	A.assign(n + 1, 0);
	REPC(i, 1, n) cin >> A[i];

	cout << solve() << endl;

	return 0;
}

Measured memory_bytes: 640
function Main(input) {
    var A1 = input.slice(0, 3).map(a => parseInt(a, 10));
    var A2 = input.slice(3, 6).map(a => parseInt(a, 10));
    var A3 = input.slice(6, 9).map(a => parseInt(a, 10));
    var N = parseInt(input[9], 10);
    var b = input.slice(10).map(a => parseInt(a, 10));

    for (var i = 0; i < N; i++) {
        for (var j = 0; j < 3; j++) {
            if (A1[j] === b[i]) {
                A1[j] = 0;
            }
        }
        for (var j = 0; j < 3; j++) {
            if (A2[j] === b[i]) {
                A2[j] = 0;
            }
        }
        for (var j = 0; j < 3; j++) {
            if (A3[j] === b[i]) {
                A3[j] = 0;
            }
        }
    }

    for (var i = 0; i < 3; i++) {
        if (A1[i] === 0 && A2[i] === 0 && A3[i] === 0) {
            return console.log('Yes');
        }
    }
    if (A1[0] === 0 && A1[1] === 0 && A1[2] === 0) {
        return console.log('Yes');
    }
    if (A2[0] === 0 && A2[1] === 0 && A2[2] === 0) {
        return console.log('Yes');
    }
    if (A3[0] === 0 && A3[1] === 0 && A3[2] === 0) {
        return console.log('Yes');
    }
    if (A1[0] === 0 && A2[1] === 0 && A3[2] === 0) {
        return console.log('Yes');
    }
    if (A1[2] === 0 && A2[1] === 0 && A3[0] === 0) {
        return console.log('Yes');
    }
    return console.log('No');
}

Main(require("fs").readFileSync("/dev/stdin", "utf8").trim().split(/\n|\s/));

Measured memory_bytes: 7372
use std::io::Read;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();

    let answer = solve(&buf);

    println!("{}", answer);
}

fn solve(input: &str) -> String {
    let mut iterator = input.split_whitespace();

    let a = iterator.next().unwrap();
    let b = iterator.next().unwrap();

    return if a == "H" {
        if b == "H" {
            "H".to_string()
        } else {
            "D".to_string()
        }
    } else {
        if b == "H" {
            "D".to_string()
        } else {
            "H".to_string()
        }
    };
}


Measured memory_bytes: 2092
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <stack>
#include <complex>
#include <stdlib.h>
#include <stdio.h>
#include <functional>
#include <cfloat>
#include <math.h>


#define fs first
#define sc second

using namespace std;


typedef long long ll;
typedef pair<ll, ll> P;


int main(){
    int n, d;
    cin >> n >> d;
    int x[21][21];
    for(int i = 0; i < n; i++){
        for(int j = 0; j < d; j++){
            cin >> x[i][j];
        }
    }

    int res = 0;
    for(int i = 0; i < n; i++){
        for(int j = i+1; j < n; j++){
            int dis = 0;
            for(int k = 0; k < d; k++){
                dis += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
            }
            for(int k = 1; k * k <= dis; k++){
                if(k * k == dis){
                    res++;
                }
            }
        }
    }

    cout << res << endl;


    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    // Your code here!
    int a,b ,c;
    scanf("%d %d %d",&a,&b,&c);
    if(a<b && b<c){
        printf("Yes\n");
    }
    else{
        printf("No\n");
    }

    return 0;
}


Measured memory_bytes: 2548
import java.util.*;
import java.awt.Point;
 
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int H = sc.nextInt();
		int W = sc.nextInt();
		int K = sc.nextInt();
		String[] map = new String[H];
		boolean[][] used = new boolean[H][W];
		int dist = Integer.MAX_VALUE;
		ArrayDeque<Point> deq = new ArrayDeque<Point>();
		for(int i=0; i<H; i++){
			map[i] = sc.next();
			for(int j=0; j<W; j++){
				if(map[i].charAt(j)=='S'){
					deq.add(new Point(i,j));
					used[i][j] = true;
					dist = distance(H,W,i,j);
				}
			}
		}
		
		Point[] dir = { new Point(1,0), new Point(-1,0), new Point(0,1), new Point(0,-1) };
		
		for(int i=0; i<K; i++){
			int size = deq.size();
			for(int j=0; j<size; j++){
				Point p = deq.poll();
				for(int k=0; k<4; k++){
					int newX = p.x + dir[k].x;
					int newY = p.y + dir[k].y;
					
					if(in_field(H,W,newX,newY)&&map[newX].charAt(newY)=='.'&&!used[newX][newY]){
						deq.add(new Point(newX,newY));
						used[newX][newY] = true;
						dist = Math.min(dist, distance(H,W,newX,newY));
					}
				}
			}
		}
		
		if(dist==0){
			System.out.println(1);
		}else{
			int ans = (int)Math.ceil((double)dist/(double)K) + 1;
			System.out.println(ans);
		}
		return;
	}
	
	public static boolean in_field(int h, int w, int x, int y){
		return (0 <= x && x < h)&&(0 <= y && y < w);
	}
	
	public static int distance(int h, int w, int x, int y){
		return Math.min(Math.min(x, h-x-1), Math.min(y, w-y-1));
	}
}

Measured memory_bytes: 42528
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e5+100;
const ll mod=1e9+7;


int main()
{
    ll n,k,s;
    cin>>n>>k>>s;
    for(int i=0;i<k;i++)
        printf("%lld ",s);
    if(s==1e9)
        for(int i=k;i<n;i++)
            printf("%lld ",1);
    else
    for(int i=k;i<n;i++)
        printf("%lld ",s+1);
    return 0;
}
/*

*/


Measured memory_bytes: 1280
n,t=map(int,input().split())
d = [list(map(int, input().split())) for i in range(n)]

ans = [d[i][0] for i in range(len(d)) if d[i][1] <= t]
if len(ans) == 0:
    print("TLE")
else:
    print(min(ans))

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

#define REP(i, x, n) for (int i = x; i < (int)(n); i++)
#define rep(i, n) REP (i, 0, n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x.size())
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define uniq(x) x.erase(unique(x.begin(), x.end()), x.end())
#define F first
#define S second
#define mp make_pair
#define eb emplace_back

using namespace std;

typedef long long ll;

const int INF = 1 << 29;

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

  ll ans = min(n, m / 2);
  ans += (m - ans * 2) / 4;

  cout << ans << endl;

  return 0;
}


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

using namespace std;

typedef long long LL;

const int N = 1010;

int a, b, c, x;

int main()
{
    cin >> a >> b >> c >> x;

    int res = 0;
    for(int i = 0; i <= a; i++)
        for(int j = 0; j <= b; j++)
            for(int k = 0; k <= c; k++)
                if(i * 500 + j * 100 + k * 50 == x)
                    res++;

    cout << res << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {

    private static int calc(int x) {
        int ret = 0;
        while(x % 100 == 0) {
            x /= 100;
            ++ret;
        }
        return ret;
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int d = sc.nextInt();
        int n = sc.nextInt();
        int count = 0;
        int value = 0;
        while(count < n) {
            ++value;
            if(calc(value) == d) ++count;
        }
        System.out.println(value);
        sc.close();
    }

}


Measured memory_bytes: 23124
#include <iostream>
#include <utility>
using namespace std;
typedef pair<int,int> pii;
pii mx(pii a, pii b){
	int i,ma1 = -1,ma2 = -1,c[4];
	c[0] = a.first,c[1] = a.second,c[2] = b.first,c[3] = b.second;
	for(i=0;i<4;i++){
		if(ma1<c[i]){
			ma2 = ma1; ma1 = c[i];
		}else if(ma2<c[i]){
			ma2 = c[i];
		}
	}
	return {ma1,ma2};
}
int a[1<<20];
pii dp[1<<20];
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int i,j,n;
	cin >> n;
	for(i=0;i<(1<<n);i++){
		cin >> a[i];
		dp[i] = {a[i],0};
	}
	for(i=0;i<n;i++){
		for(j=0;j<(1<<n);j++){
			if(j&(1<<i)){
				dp[j] = mx(dp[j],dp[j^(1<<i)]);
			}
		}
	}
	int ans = a[0] + a[1];
	for(i=1;i<(1<<n);i++){
		ans = max(ans,dp[i].first + dp[i].second);
		cout << ans << "\n";
	}
}

Measured memory_bytes: 9216
#include <iostream>
//#include <iomanip>
//#include <string>
#include <vector>
//#include <algorithm>
//#include <utility>
//#include <set>
//#include <map>
//#include <queue>
//#include <deque>
//#include <bitset>
//#include <math.h>
using namespace std ;
using ll = long long ;
//using ld = long double ;
using vll = vector<ll> ;
using vvll = vector<vll> ;
//using vc = vector<char> ;
//using vvc = vector<vc> ;
//using vb = vector<bool> ;
//using vvb = vector<vb> ;
//using pll = pair<ll,ll> ;
//#define all(v) v.begin(),v.end()
//ll mod = 1000000007 ;
//long double pie = acos(-1) ;
//ll INF = 1000000000000 ;

//void yorn(bool a){if(a) cout << "Yes" << endl ; else cout << "No" << endl ;}
//void YorN(bool a){if(a) cout << "YES" << endl ; else cout << "NO" << endl ;}
//ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
//ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
//ll sa(long long a,long long b){if(a>b) return a-b ; return b-a ;}
//void fix_cout(){cout << fixed << setprecision(20) ;}

int main(){
	ll h,w ;
	cin >> h >> w ;
	ll n ; cin >> n ;
	vll a(n) ;
	for(auto &i:a) cin >> i ;
	vvll ans(h,vll(w,-1)) ;
	ll x=0,y=0 ;
	for(int i=0;i<n;i++){
		for(int j=0;j<a.at(i);j++){
			ans.at(y).at(x) = i+1 ;
			if(y&1){
				x-- ;
				if(x==-1){
					y++ ;
					x++ ;
				}
			}else{
				x++ ;
				if(x==w){
					y++ ;
					x-- ;
				}
			}
		}
	}
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			cout << ans.at(i).at(j) << (j==w-1?'\n':' ') ;
		}
	}
}


Measured memory_bytes: 476
def value_and_count(x):
    d = {}
    for xi in x:
        if xi in d.keys():
            d[xi] += 1
        else:
            d[xi] = 1
    return d

def comb(n, k):
    k = min(n - k, k)
    denominator = 1 # 分母
    numerator = 1 # 分子
    for i in range(k):
        denominator *= i + 1
        numerator *= n - i
    return numerator // denominator

n, a, b = map(int, input().split())
v = list(map(int, input().split()))
d_v = value_and_count(v)
v.sort(reverse=True)
sum_v = sum(v[:a])
mean_v = sum_v / a
print(mean_v)

ans = 0
d_vk = None
for k in range(a, b + 1):
    vk = v[:k]
    sum_vk = sum(vk)
    if sum_vk / k < mean_v:
        break

    if d_vk is None:
        d_vk = value_and_count(vk)
    else:
        d_vk[vk[-1]] += 1

    ans_k = 1
    for vi, ci in d_vk.items():
        ans_k *= comb(d_v[vi], ci)
    ans += ans_k

print(ans)


Measured memory_bytes: 3188
import math

a,b,h,m = (int(x) for x in input().split())

m_deg = float((m/60) * 360)
h_deg = float(((h*60 +m) / (12*60) ) * 360)  


diff=m_deg-h_deg
#print(diff)
if abs(diff)>=180:
    diff=float(360-abs(diff))
#print(diff)
cos=math.cos(math.radians(diff))

#print(cos)

ans =math.sqrt( a**2 + b**2 -2*a*b*cos)
print(ans)

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

vector<ll> fact;
ll n, m, k, M = 998244353;

ll modpow(ll a, ll b, ll M) {
    ll ans = 1;
    while(b) {
        if(b & 1) {ans = (ans * a) % M;}
        a = (a * a) % M;
        b /= 2;
    }
    return ans;
}

ll modinv(ll a, ll M) {
    return modpow(a, M - 2, M);
}

ll comb(ll n, ll r, ll M) {
    return ((fact[n] * (modinv((fact[r] * fact[n - r]) % M, M))) % M);
}

void solve() {
    cin >> n >> m >> k;
    ll ans = 0;
    fact.resize(n + 1);
    fact[0] = 1;
    for(ll i = 1; i <= n; i++) {fact[i] = (i * fact[i - 1]) % M;}
    for(ll i = 0; i <= k; i++) {
        ll temp = comb(n - 1, i, M);
        temp = (temp * m) % M;
        temp = (temp * modpow(m - 1, n - 1 - i, M)) % M;
        ans = (ans + temp) % M;

    }
    cout << ans;
}

int main() {
    ios_base :: sync_with_stdio(false); 
    cin.tie(NULL);
    int t = 1;
    //cin >> t;
    while(t--) {
        solve();
    }
    return 0;
}

Measured memory_bytes: 4768
#!python3

import sys
iim = lambda: map(int, sys.stdin.readline().rstrip().split())
from functools import lru_cache

mod = 10 **9 + 7


@lru_cache(100)
def calc(n):
    ans = 0
    if n & 1:
        Y = [37033746750,-19102088250,-75258447165,+8922649446,+41082466425,+12030593120,-2592429840,-1880967088,-281252400,+27251510,+15690675,+2549638,+225225,+11620,+330,+4]
    else:
        Y = [0,         -98703360000,-108248279040,+4240221696,+40869628800,+12030593120,-2592429840,-1880967088,-281252400,+27251510,+15690675,+2549638,+225225,+11620,+330,+4]

    x = 1
    for i, y in enumerate(Y):
        ans = (ans + x*(y%mod) % mod) % mod
        x = x*n%mod
    ans = ans * pow(167382319104000, mod-2, mod) % mod
    return ans

def resolve():
    it = map(int, sys.stdin.read().split())
    N = next(it)

    ans = [0] * N
    for i in range(N):
        n = next(it)
        ans[i] = calc(n)

    print(*ans, sep="\n")

if __name__ == "__main__":
    resolve()


Measured memory_bytes: 70144
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <cmath>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <functional>

using namespace std;

typedef long long ll;

#define ITER( c ) __typeof( c ).begin()
#define REP( i, m, n ) for ( int i = m; i < n; i++ )
#define UREP( i, m, n ) for ( unsigned int i = m; i < n; i++ )
#define IREP( c, it ) for ( ITER(c) it = c.begin(); it != c.end(); ++it )
#define ALL( c ) c.begin(), c.end()
#define PB( n ) push_back( n );
#define MP( a, b ) make_pair( a, b )
#define fst first
#define snd second

string vtos( vector<int> v )
{
	string res;

	REP( i, 0, v.size() )
	{
		res += v[i] + '0';
		res += ' ';
	}

	res.erase( res.length() - 1 );

	return res;
}

int main()
{
	vector<int> viecle;
	viecle.PB( 1 );
	viecle.PB( 2 );
	viecle.PB( 1 );
	viecle.PB( 2 );
	viecle.PB( 1 );
	viecle.PB( 4 );
	viecle.PB( 1 );
	viecle.PB( 4 );

	while ( true )
	{
		string buffer;
		getline( cin, buffer );
		
		if ( buffer.length() == 0 )
		{
			break;
		}

		istringstream iss( buffer );
		vector<int> wait;

		REP( i, 0, 8 )
		{
			int in;
			iss >> in;
			wait.PB( in );
		}

		int curr;
		vector<int> v;
		vector< pair<int,string> > res;

		REP( i, 0, 8 )
		{
			curr = 0;
			v = viecle;

			REP( j, 0, i )
			{
				int tmp = v[0];
				v.erase( v.begin() );
				v.PB( tmp );
			}

			REP( j, 0, v.size() )
			{
				curr += abs( v[j] - wait[j] );
			}

			res.PB( MP( curr, vtos( v ) ) );
		}

		sort( ALL( res ) );

		cout << res[0].snd << endl;
	}

	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int n, X;

// GCD ユークリッドの互除法バージョン
long long GCD(long long a, long long b) {
    if(b == 0) return a;
    else return GCD(b, a%b);
}

int main() {
    cin >> n >> X;
    vector<int> x(n, 0);
    for(int i = 0; i < n; ++i) cin >> x.at(i);
    x.emplace_back(X);
    sort(x.begin(), x.end());

    int ans = x.at(1) - x.at(0);
    for(int i = 0; i < n; ++i) {
        ans = GCD(ans, (x.at(i+1) - x.at(i)));
    }

    cout << ans << endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#define MOD 1000000007
typedef long long ll;
using namespace std;

int N;
int a[51],b[51];

bool used[51];
vector<int> g[51];

bool dfs(int now,int target){
    used[now]=true;
    if(now==target) return true;
    for(int i=0;i<g[now].size();i++){
        int u=g[now][i];
        if(used[u]) continue;
        if(dfs(u,target)) return true;
    }
    return false;
}

bool judge(vector<int> &v){
    for(int i=0;i<=50;i++){
        used[i]=false;
        g[i].clear();
    }
    for(int i=1;i<=50;i++){
        for(int j=0;j<v.size();j++){
            g[i].push_back(i%v[j]);
        }
    }
    
    for(int i=0;i<N;i++){
        if(!dfs(a[i],b[i])) return false;
        for(int j=0;j<=50;j++) used[j]=false;
    }
    return true;
}

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

  bool flag=false;
  for(int i=0;i<N;i++){
    if((a[i]-1)/2<b[i]&&a[i]!=b[i]) flag=true;
  }
  if(flag){
    cout<<-1<<endl;
    return 0;
  }

  vector<int> se;
  for(int i=1;i<=50;i++) se.push_back(i);
  for(int i=50;i>=1;i--){
      se.erase(se.begin()+i-1);
      if(!judge(se)) se.push_back(i);
  }

  ll ans=0;
  for(int i=0;i<se.size();i++) ans+=pow(2,se[i]);
  cout<<ans<<endl;

  return 0;
}


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

int s[200009];
int t[200009];

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

    bool flag = false;
    for (int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        if (a == 1) {
            s[b]++;
        }
        if (b == n) {
            t[a]++;
        }
    }

    for (int i = 1; i <= 200000; i++) {
        if (s[i] && t[i]) {
            flag = true;
        }
    }

    if (flag) {
        puts("POSSIBLE");
    } else {
        puts("IMPOSSIBLE");
    }

    return 0;
}

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


def solve(S: str):
    c0 = 0
    c1 = 0
    for c in S:
        if c == "0":
            c0 += 1
        else:
            c1 += 1
    print(min(c0,c1) * 2)
    return


# Generated by 1.1.3 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  # type: int
    solve(S)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3316
#include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>

using namespace std;

int main() {
    int N, H;
    cin >> N >> H;

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

    sort(a.rbegin(), a.rend());
    sort(b.rbegin(), b.rend());

    long long cnt = 0;
    for (int i = 0; i < b.size(); i++) {
        // cout << "reminder H: " << H << endl;
        if (b[i] > a[0] && H > 0) {
            H -= b[i];
            cnt++;
        } else {
            break;
        }
    }
    // cout << "cnt: " << cnt << endl;
    if (H > 0) {
        cnt += ceil(double(H) / double(a[0]));
    }

    cout << cnt << endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <map>
#include <queue>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
using namespace std;
#pragma warning (disable: 4996)

int gcd(int a, int b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}

int main() {
	int X; cin >> X;
	int E = gcd(X, 360);
	cout << 360 / E << endl;
	return 0;
}

Measured memory_bytes: 3592
#include<bits/stdc++.h>
using namespace std;
int main() {
	int n,m;
	cin>>n>>m;
	vector<int> adj[n+2];
	for(int i=0;i<m;++i) {
		int x,y;
		cin>>x>>y;
		adj[x].push_back(y);
		adj[y].push_back(x);
	}
	int vis[n+5],ans[n+5];
	memset(vis, 0, sizeof vis);
	memset(ans, 0, sizeof ans);
	queue<int> q;
	q.push(1);
	while(!q.empty()) {
		int u = q.front();
		q.pop();
		vis[u] = 1;
		for(int i=0;i<adj[u].size();++i) {
			if(!vis[adj[u][i]]) {
				ans[adj[u][i]] = u;
				vis[adj[u][i]] = 1;
				q.push(adj[u][i]);
			}
		}
	}
	int flag = 0;
	for(int i=1;i<=n;++i) {
		if(!vis[i]) {
			flag = 1;
			break;
		}
	}
	if(flag) {
		cout<<"No";
	} else {
		cout<<"Yes\n";
		for(int i=2;i<=n;++i) {
			cout<<ans[i]<<"\n";
		}
	}
	return 0;
}

Measured memory_bytes: 10796
#include<iostream>
#include<cstdlib>
#include<string>
#include<vector>
#include<queue>
#include<algorithm>
using namespace std;
using ll = long long int;
const int mod = 1e9 + 7;
#define rep(i, a, b) for(int i = a;i < b; i++)

int main() {

	ll n;
	cin >> n;
	
	ll ans = n * (n - 1) / 2;

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
# -*- coding: utf-8-*-
if __name__ == '__main__':
    c = input()
    if c == "A":
        print("T")
    elif c == "T":
        print("A")
    elif c == "C":
        print("G")
    elif c == "G":
        print("C")


Measured memory_bytes: 2940
n,p=map(int,input().split())
if p==2:
    l=[int(c) for c in input()]
    res=0
    for i in range(n):
        if (l[i]%2)==0:
            res+=i+1
    print(res)
elif p==5:
    l=[int(c) for c in input()]
    res=0
    for i in range(n):
        if (l[i]==0)or(l[i]==5):
            res+=i+1
    print(res)
else:
    s=input()[::-1]
    l=[int(c) for c in s]
    ll=[0 for i in range(p)]
    now=0
    fac=1
    for i in l:
        now+=fac*i
        now%=p
        ll[now]+=1
        fac*=10
        fac%=p
    res=0
    for i in range(p):
        res+=ll[i]*(ll[i]-1)//2
    res+=ll[0]
    print(res)


Measured memory_bytes: 48172
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
using namespace std;
#define REP(i, j) for(int i = 0; i < (int)(j); ++i)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
typedef complex<double> P;

int solve(string s[3]){
  if(s[0][0] == s[0][1] && s[0][1] == s[0][2] && s[0][0] != '+') return (s[0][0] == 'w' ? 0 : 1);
  if(s[1][0] == s[1][1] && s[1][1] == s[1][2] && s[1][0] != '+') return (s[1][0] == 'w' ? 0 : 1);
  if(s[2][0] == s[2][1] && s[2][1] == s[2][2] && s[2][0] != '+') return (s[2][0] == 'w' ? 0 : 1);

  if(s[0][0] == s[1][0] && s[1][0] == s[2][0] && s[0][0] != '+') return (s[0][0] == 'w' ? 0 : 1);
  if(s[0][1] == s[1][1] && s[1][1] == s[2][1] && s[0][1] != '+') return (s[0][1] == 'w' ? 0 : 1);
  if(s[0][2] == s[1][2] && s[1][2] == s[2][2] && s[0][2] != '+') return (s[0][2] == 'w' ? 0 : 1);

  if(s[0][0] == s[1][1] && s[1][1] == s[2][2] && s[0][0] != '+') return (s[0][0] == 'w' ? 0 : 1);
  if(s[0][2] == s[1][1] && s[1][1] == s[2][0] && s[0][2] != '+') return (s[0][2] == 'w' ? 0 : 1);

  return -1;
}
 
int main() {
  string s[3];
  while(cin >>s[0] && s[0] != "0"){
    cin >>s[1] >>s[2];
    int ans = solve(s);
    if(ans == 0) cout <<"w" <<endl;
    else if(ans == 1) cout <<"b" <<endl;
    else cout <<"NA" <<endl;
  }
  return 0;
}

Measured memory_bytes: 1180
#include <iostream>
#include <string>
#include <algorithm>
#include <queue>
using namespace std;

int main(){

    int H, W = -1;

    queue<int> que_h;
    queue<int> que_w;

    while(1){
        if((H == 0) && (W == 0)){
            break;
        }
        cin >> H >> W;
        que_h.push(H);
        que_w.push(W);
    }

    while(1){
        
        H = que_h.front();
        W = que_w.front();

        if((H == 0) && (W == 0)){
            break;
        }

        
        for(int i=0; i<H; i++){
            for(int j=0; j<W; j++){
                
                if((i%2 == 0) && (j%2==0)){
                    cout << "#";
                }
                if((i%2 == 0) && (j%2==1)){
                    cout << ".";
                }

                if((i%2 == 1) && (j%2==1)){
                    cout << "#";
                }
                if((i%2 == 1) && (j%2==0)){
                    cout << ".";
                }
            }
            cout << endl;
        }
        cout << endl;

        que_h.pop();
        que_w.pop();
    }


    return  0;
}

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

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

  vector<int> a(n);
  rep(i,n) cin >> a[i];

  ll xor_sum = 0;
  for (int i = 0; i < n; i++) {
    xor_sum ^= a[i];
  }

  for (int i = 0; i < n; i++) {
    cout << (xor_sum ^ a[i]) << ' ';
  }
}


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

int main() {
  int n;
  cin>>n;
  vector<int> vec(200010);
  vector<int> veC(200010);

  
  
  for(int i = 0; i <n-1; i++)
    cin >> vec[i];
  
  for(int i = 0; i <n-1; i++)
      veC[vec[i]-1]++;
  
  for(int i = 0; i <n; i++)
    cout << veC[i] << endl;
}


Measured memory_bytes: 4848
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
static const int MAX = 10000;
static const int INFTY = (1<<20);
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;

int n;
vector<pair<int, int> > adj[MAX];

void dijkstra(void);

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

  cin >> n;
  for( int i = 0; i < n; i++)
    {
      cin >> u >> k;
      for( int j = 0; j < k; j++)
        {
          cin >> v >> c;
          adj[u].push_back(make_pair(v, c));
        }
    }

    dijkstra();

    return 0;
}

void dijkstra(void)
{
  priority_queue<pair<int, int> > PQ;
  int color[MAX];
  int d[MAX];
  for( int i = 0; i < n; i++)
    {
      d[i] = INFTY;
      color[i] = WHITE;
    }

  d[0] = 0;
  PQ.push(make_pair(0, 0));
  color[0] = GRAY;

  while( !PQ.empty() )
    {
      pair<int, int> f = PQ.top(); PQ.pop();
      int u = f.second;

      color[u] = BLACK;

      if( d[u] < f.first * (-1) ) continue;

      for( int j = 0; j < adj[u].size(); j++)
        {
          int v = adj[u][j].first;
          if( color[v] == BLACK ) continue;
          if( d[v] > d[u] + adj[u][j].second )
            {
              d[v] = d[u] + adj[u][j].second;
              PQ.push(make_pair(d[v] * (-1), v));
              color[v] = GRAY;
            }
        }
    }

  for( int i = 0; i < n; i++)
    {
      cout << i << " " << ( d[i] == INFTY ? -1 : d[i] ) << endl;
    }
}



Measured memory_bytes: 7984
n = int(input())
lst = []
for i in range(n):
    s, p = input().split()
    lst.append([s, int(p), i+1])

beta = sorted(lst, key=lambda x: x[1], reverse=True)
alpha = sorted(beta, key=lambda x: x[0])

for i in range(n):
    print(alpha[i][2])


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

int main() {
  int N,M;
  int Lmax = -1;
  int Rmin = 100000;
  int count = 0;
  cin >> N >> M;
  vector<int> L(M);
  vector<int> R(M);
  for (int i = 0; i < M; i++) {
    cin >> L.at(i);
    cin >> R.at(i);
  }
  for(int i = 0; i < M; i++){
    if(L.at(i) >= Lmax){
      Lmax = L.at(i);
    }
    if(R.at(i) <= Rmin){
      Rmin = R.at(i);
    }
  }
  for(int i = 1; i <= N; i++){
    if(Lmax <= i && i <= Rmin){
      count++;
    }
  }
  cout << count << endl;
}



Measured memory_bytes: 1024
from time import time
start = time()
import random
from sys import stdin
input = stdin.readline
D = int(input())
*c, = map(int, input().split())
S = []
for _ in [None] * D:
    *s, = map(int, input().split())
    S += s,
INF = float("inf")

def Tread(D):
    return [int(input()) for i in [None] * D]

def check(T):
    M = 0
    MM = []
    last = [-1] * 26
    for d, t in enumerate(T):
        M += S[d][t] - sum((d - last[i]) * c[i] for i in range(26) if i != t)
        last[t] = d
        # MM += M,
    return M # MM

def 貪欲():
    M = 0
    T = []
    last = [-1] * 26
    for d in range(D):
        m = -INF
        for j in range(26):
            Q = S[d][j] - sum((d - last[i]) * c[i] for i in range(26) if i != j)
            if m < Q:
                t, m = j, Q
        T += t,
        last[t] = d
        M += m
        # print(M)
    return T, M

def 局所探索():
    T, M = 貪欲()
    # print(T, M)
    while time() - start < 1.91:
        d, q = random.randrange(D), random.randrange(26)
        Check = T[:]
        Check[d] = q
        C = check(Check)
        if C > M:
            M, T = C, Check
    for s in T:print(s + 1)
    # print(M)

局所探索()

Measured memory_bytes: 89348
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		new Main().run();
	}

	void run() {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		String t = sc.next();
		s = s + s;
		while (s.length() < 2 * t.length()) {
			s = s + s;
		}
		int[] dp1 = Arrays.copyOfRange(zalgo(t + s), t.length(), t.length() + s.length());
		int n = s.length();
		int ans = 0;
		boolean exist = false;
		for (int i = 0; i < dp1.length; ++i)
			exist |= dp1[i] >= t.length();
		if (!exist) {
			System.out.println(0);
			return;
		}
		DJSet ds = new DJSet(n);
		for (int i = n / 2 - 1; i >= 0; --i) {
			int a = i;
			int b = (i + t.length()) % (n / 2);
			if (dp1[a] >= t.length() && dp1[b] >= t.length()) {
				if (ds.equiv(a, b)) {
					System.out.println(-1);
					return;
				} else {
					ds.setUnion(a, b);
				}
			}
			ans = Math.max(ans, ds.sz(i));
		}
		System.out.println(ans);
	}

	int[] zalgo(String s) {
		int n = s.length();
		int[] ret = new int[n];
		ret[0] = n;
		int i = 1, j = 0;
		while (i < n) {
			while (i + j < n && s.charAt(j) == s.charAt(i + j))
				++j;
			ret[i] = j;
			if (j == 0) {
				++i;
				continue;
			}
			int k = 1;
			while (i + k < n && k + ret[k] < j) {
				ret[i + k] = ret[k];
				++k;
			}
			i += k;
			j -= k;
		}
		return ret;
	}

	class DJSet {
		int n;
		int[] upper;

		public DJSet(int n_) {
			n = n_;
			upper = new int[n_];
			Arrays.fill(upper, -1);
		}

		int root(int x) {
			return upper[x] < 0 ? x : (upper[x] = root(upper[x]));
		}

		boolean equiv(int x, int y) {
			return root(x) == root(y);
		}

		void setUnion(int x, int y) {
			x = root(x);
			y = root(y);
			if (x == y)
				return;
			if (upper[x] < upper[y]) {
				x ^= y;
				y ^= x;
				x ^= y;
			}
			upper[y] += upper[x];
			upper[x] = y;
		}

		int sz(int x) {
			return -upper[root(x)];
		}
	}

	void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}

}

Measured memory_bytes: 75884
package main

import "fmt"

func primeFactor(n int, pf []int) {
	for i := 2; i*i <= n; i++ {
		for n%i == 0 {
			n /= i
			pf[i]++
		}
	}
	if n > 1 {
		pf[n]++
	}
}

func main() {
	var n int
	fmt.Scan(&n)
	pf := make([]int, 1010)
	mod := int(1e9 + 7)
	for i := 2; i <= n; i++ {
		primeFactor(i, pf)
	}
	// fmt.Println("n", n, "pf", pf)
	ans := 1
	for j := 1; j < len(pf); j++ {
		if pf[j] >= 1 {
			ans = (ans * (pf[j] + 1)) % mod
		}
	}
	fmt.Println(ans)
}


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

ll gcd(ll x, ll y) {
	return y ? gcd(y, x % y) : x;
}
ll lcm(ll x,ll y){
  ll g=gcd(x,y);
  return x/g*y;
}


int main(){
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  
  int a,b; cin>> a>> b;
  cout<<max(0,a-2*b)<<endl;
  
}

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

using namespace std;
using ll = long long;

int main() {
    ll x, k, d;
    cin >> x >> k >> d;

    x = abs(x);
    if (x / d >= k) {
        cout << x - d*k << endl;
    }
    /*else
    {
        long r1 = x % d;
        if ((k - (x - r1) / d) % 2 == 0)
        {
            cout << r1 << endl;
        }
        else
        {
            cout << (d - r1) << endl;
        }
    }*/
    else {
        ll r = x % d;
        if ((k - (x - r) / d) % 2 == 0) cout << r << endl;
        else cout << d - r << endl;
    }
}

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

ll N, i;
vector<ll> A, B, C;

void input(){
  int p;
  cin >> N;
  rep(i, N){
    cin >> p;
    A.push_back(p);
  }
  rep(i, N){
    cin >> p;
    B.push_back(p);
  }
  rep(i, N - 1){
    cin >> p;
    C.push_back(p);
  }
}

void solve(){
  input();
  
  ll score = 0;
  rep(i, N){
    score += B[A[i] - 1];
    if(A[i + 1] == A[i] + 1 && i != N - 1){
      score += C[A[i] - 1];
    }
  }
  cout << score << endl;
}

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

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

int n , m;
int a[1005] , b[1005] , c[1005][1005];
int inf = 1 << 30;
int dp[1 << 13];
int ret;

int main(){
  cin >> n >> m;
  for(int i = 1; i <= m; ++i){
    cin >> a[i] >> b[i];
    for(int j = 1; j <= b[i]; ++j){
      cin >> c[i][j];
    }
  }
  for(int j = 0; j < (1 << n); ++j){
    if(j == 0)dp[j] = 0;
    else dp[j] = inf;
  }
  ret = inf;
  for(int i = 1; i <= m; ++i){
    for(int j = (1 << n) - 1; j >= 0; --j){
      int next = j;
      for(int k = 1; k <= b[i]; ++k)next |= (1 << (c[i][k] - 1));
      dp[next] = min(dp[next] , dp[j] + a[i]);
      if(next == (1 << n) - 1)ret = min(ret , dp[next]);
    }
  }
  if(ret < inf)cout << ret << endl;
  else cout << -1 << endl;
  return 0;
}


Measured memory_bytes: 4224
#include "bits/stdc++.h"
using namespace std;
#define rep(i,n)for(int i=0;i<(int)(n);i++)
#define PI 3.141592653589793
//vector < vector<int>>a(0, vector<int>(0));二次元配列宣言


int main()
{
	int a, b, c;
	cin >> a >> b >> c;
	if (a + b == c || a + c == b || b + c == a)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
} 

Measured memory_bytes: 3580
import java.util.Scanner;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int num = sc.nextInt();
    int a = sc.nextInt();
    int b = sc.nextInt();
    int sum = 0;
    
    for(int i =1; i <= num; i++){
		int j = i;
      	int wa = 0;
      	while(j > 0){
        wa+= j%10;
          j = j/10;
        }
      if(wa >= a && wa <= b){
		sum += i;
      }
    }  
    System.out.println(sum);
  }
}

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

s = input()

while True:
    s = s[:-2]
    if s[0:len(s)//2] == s[len(s)//2:]:
        print(len(s))
        exit()






Measured memory_bytes: 9088
import std.stdio, std.conv, std.array, std.string, std.algorithm, std.container, std.range, core.stdc.stdlib, std.math, std.typecons;
T[][] combinations(T)(T[] s, in int m) {   if (!m) return [[]];   if (s.empty) return [];   return s[1 .. $].combinations(m - 1).map!(x => s[0] ~ x).array ~ s[1 .. $].combinations(m); }

alias Magic = Tuple!(long, "damage", long, "mp");

void main() {
  long H, N; readf("%d %d\n", &H, &N);
  auto Magics = N
    .iota
    .map!(i => readln.split.to!(long[]))
    .map!(m => Magic(m[0], m[1]))
    .array();

  long solve() {
    long[] dp = new long[](10000 * 10000 + 1);
    dp[] = 10000 * 10000 + 1;
    dp[0] = 0;

    foreach(i; 0..H+1) {
      foreach(magic; Magics) {
        dp[i + magic.damage] = min(dp[i + magic.damage], dp[i] + magic.mp);
      }
    }

    long answer = long.max;
    foreach(i; H..10000 * 10000 + 1) {
      answer = min(answer, dp[i]);
    }

    return answer;
  }

  solve().writeln;
}


Measured memory_bytes: 784764
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main() {
  string s,t;
  cin>>s;
  cin>>t;
  t.pop_back();
  if(s.compare(t)==0) cout<<"Yes"<<"\n";
  else cout<<"No"<<"\n";
    return 0;
}


Measured memory_bytes: 3600
#include<bits/stdc++.h>
#include<cmath>
#define SZ(x) ((int)x.size())
#include<vector>
#include<set>
#include<map>
#define ll long long
#define lli long long int
#define REP(i,a,b) for(ll i=a;i<b;i++)
#define pb push_back
#include<string>
#include<cctype>
#include<queue>
#define ii pair<int,int>
#include <sstream>
#define lli long long int
#define pairs pair<int,int>
#define mod 1000000007
const double PI = 3.141592653589793238460;
typedef std::complex<double> Complex;
typedef std::valarray<Complex> CArray;
using namespace std;
ll pows(ll a,ll n,ll m)
{
	ll res=1;
	while(n)
	{
	if(n%2!=0)
	{
		res=(res*a)%m;
		n--;
		}
		else
		{
			a=(a*a)%m;
			n=n/2;
			}	
	}
	return res%m;
}
ll  gcd(ll a,ll b)
{
	if(b==0)
	return a;
	else 
	return gcd(b,a%b);
}
bool isprime(ll n)
{
	if(n==1)
	{
		return false;
	}
	for(ll i=2;i*i<=n;i++)
	{
		if(n%i==0)
		{
			return false;
		}
	}
	return true;
}
bool istrue(string s)
{
	int i=0;
	int j=s.size()-1;
	while(i<j)
	{
	if(s[i]==s[j])
	{
		i++;
		j--;
		}
		else
		{
			return false;
			}	
	}
	return true;
}
int n;
int a[100001];
int dp[100001];
int getans(int i)
{
if(i>=n-1)
{
	return 0;
	}
	if(dp[i]!=-1)
	{
		return dp[i];
	}
	int ans=mod;
	if(i+1<=n-1)
	{
		ans=min(ans,getans(i+1)+abs(a[i]-a[i+1]));
	}
	if(i+2<=n-1)
	{
		ans=min(ans,getans(i+2)+abs(a[i]-a[i+2]));
	}
return dp[i]=ans;
}
int main()
{
ios::sync_with_stdio(false);
	 cin.tie(0);
    cout.tie(0);
cin>>n;
for(int i=0;i<n;i++)
{
	cin>>a[i];
}
memset(dp, mod, sizeof(dp));
if(n==1)
{
	cout<<a[0]<<endl;
	return 0;
}
dp[0]=0;
dp[1]=abs(a[1]-a[0]);
for(int i=2;i<n;i++)
{
	dp[i]=min(dp[i-1]+abs(a[i-1]-a[i]),dp[i-2]+abs(a[i-2]-a[i]));
}
cout<<dp[n-1]<<endl;
}




Measured memory_bytes: 4328
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<string>
#define rep(i,N) for(int i=0;i<N;i++)

long long  INF=1000000000000000000;
long long mod=1000000007;
using namespace std;
int sx,sy,tx,ty;
int main(){

cin>>sx>>sy>>tx>>ty;

int dx=abs(sx-tx);
int dy=abs(sy-ty);
char command[4]={'L','U','R','D'};
int direcrion[]={dy,dx};
int t=0;
cout<<command[0];
t++;
rep(i,dy+1)cout<<command[t];
t++;
rep(i,dx+1)cout<<command[t];
t++;
rep(i,dy+1)cout<<command[t];
t=0;
rep(i,dx)cout<<command[t];
//2週目
t++;
rep(i,dy)cout<<command[t];
t++;
rep(i,dx+1)cout<<command[t];
t++;
rep(i,dy+1)cout<<command[t];
t=0;
rep(i,dx+1)cout<<command[t];
cout<<"U"<<endl;

 return 0;
}
/*
0 0 1 2

UURDDLLUUURRDRDDDLLU

-2 -2 1 1

UURRURRDDDLLDLLULUUURRURRDDDLLDL
*/

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

int main(void){
    long long a, b, k;

    cin >> a >> b >> k;

    if(k >= a){
        k -= a;
        a = 0;
        if(k >= b){
            b = 0;
        } else {
            b -= k;
        }
    } else {
        a -= k;
    }

    cout << a << " " << b << endl;
    
    return 0;
}


Measured memory_bytes: 256
c11, c12, c13 = map(int, input().split())
c21, c22, c23 = map(int, input().split())
c31, c32, c33 = map(int, input().split())

ok = False
for i in range(101):
    for j in range(101):
        a1 = i
        a2 = c21 - c11 + a1
        a3 = c31 - c11 + a1
        b1 = j
        b2 = c12 - c11 + b1
        b3 = c13 - c11 + b1
        if((c11==a1+b1)and(c12==a1+b2)and(c13==a1+b3)and(c21==a2+b1)and(c22==a2+b2)and(c23==a2+b3)and(c31==a3+b1)and(c32==a3+b2)and(c33==a3+b3)):
            ok = True
            break
    if(ok):
        break
if ok:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3192
#include <cmath>
#include <iostream>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <bitset>
#include <algorithm>
#include <functional>
#include <utility>
#include <iomanip>

#define int long long int
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )

using namespace std;

typedef pair<int, int> P;

const int INF = 1e15;
const int MOD = 1e9+7;

template <typename T>
using vector2 = vector<vector<T>>;
template <typename T>
vector2<T> initVec2(size_t n0, size_t n1, T e = T()){
    return vector2<T>(n0, vector<T>(n1, e));
}

template <typename T>
using vector3 = vector<vector<vector<T>>>;
template <typename T>
vector3<T> initVec3(size_t n0, size_t n1, size_t n2, T e = T()){
    return vector3<T>(n0, vector2<T>(n1, vector<T>(n2, e)));
}

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

    int n, m;
    cin >> n >> m;

    vector<int> c(1 << n, INF);
    rep(i, m){
        int a, b;
        cin >> a >> b;

        int s = 0;
        rep(i, b){
            int x;
            cin >> x;
            x--;
            s ^= (1 << x);
        }
        c[s] = min(c[s], a);
    }

    vector<int> dp(1 << n, INF);
    dp[0] = 0;
    rep(s, 1 << n){
        rep(t, 1 << n){
            dp[s|t] = min(dp[s|t], dp[s] + c[t]);
        }
    }

    if(dp[(1<<n)-1] != INF){
        cout << dp[(1<<n)-1] << endl;
    }else{
        cout << -1 << endl;
    }

    return 0;
}


Measured memory_bytes: 888
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <string>
#include <deque>
#define pb push_back
#define mod 1000000007
using namespace std;
typedef pair<int,int> pii;
typedef long long ll;
 
 
vector<int> mati;
const ll INF=1LL<<50;
struct Edge {
  ll to, cost;
  Edge(ll a, ll b){to=a;cost=b;}
};
vector<vector<Edge> > graph;
vector<ll> dist;
 
/* num of vertex is 'n', start at 's' */
bool bellman_ford(ll n, ll s) {
  dist.clear();
  dist.resize(n, INF);
  dist[s] = 0;
  for (ll i = 0; i <= n; i++) {
    for (ll v = 0; v < n; v++) {
      for (ll k = 0; k < graph[v].size(); k++) {
	Edge e = graph[v][k];
	if(dist[v]==INF) continue;
	if (dist[e.to] > dist[v] + e.cost) {
	  dist[e.to] = dist[v] + e.cost;
	  if (i == n) return true; /* detect cycle */
	}
      }
    }
  }
  return false;
}
 
 
int main(void){
  int n,m,r;
  cin>>n>>m>>r;
  int x,a,b,c;
  for(int i=0;i<r;i++){
    cin>>x;
    mati.pb(x-1);
  }
  graph.resize(n);
  
  for(int i=0;i<m;i++){
    cin>>a>>b>>c;
    graph[a-1].pb(Edge(b-1,c));
    graph[b-1].pb(Edge(a-1,c));
  }
  
  vector<vector<ll> > waro(n);
  for(int i=0;i<n;i++){
    bellman_ford(n,i);
    waro[i]=dist;
  }
  /*
  cout<<endl;
  for(int i=0;i<n;i++){
    cout<<i<<":";
    for(int j=0;j<waro[i].size();j++){
      cout<<waro[i][j]<<" ";
    }
    cout<<endl;
  }
  */
  
  ll res=INF;
  sort(mati.begin(),mati.end());
  
  do{
    ll tmp=0;
    for(int i=1;i<mati.size();i++){
      tmp+=waro[mati[i-1]][mati[i]];
    }
    
    res=min(tmp,res);
  }while(next_permutation(mati.begin(),mati.end()));
  cout<<res<<endl;
  
  return 0;
}

Measured memory_bytes: 1408
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<cstring>
using namespace std;

string lcs_f;
string lcs_s;
int maxnum = 0;

void lcs() {
    maxnum = 0;
	int flen = lcs_f.size() + 1;
	int slen = lcs_s.size() + 1;
	int a[1001][1001] ={};
	for (int i = 0; i < flen; i++) {
		for (int j = 0; j < slen; j++) {
			if (i == 0 || j == 0) {
				a[i][j] = 0;
			}
			else if (lcs_f[i-1] == lcs_s[j-1]) {
				a[i][j] = a[i - 1][j - 1] + 1;
				if (a[i][j] > maxnum) {
				    maxnum = a[i][j];
				}
			}
			else {
				if (a[i][j - 1] < a[i - 1][j]) {
					a[i][j] = a[i - 1][j];
				}
				else {
					a[i][j] = a[i][j-1];
				}
				 
			}
		}
	}
	
	
}

int main() {
	int n;
	
	cin >> n;
	for (int i = 0; i < n; i++){
		cin >> lcs_f >> lcs_s;
		lcs();
		cout << maxnum << endl;
	}
}


Measured memory_bytes: 7052