akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = s; i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << '\n';
#define CFYN(n) cout << ( (n) ? "YES":"NO") << '\n';
#define OUT(n) cout << (n) << '\n';
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;

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

    int ans = 0;
    for (int i = 1; i <= n ; i+=2) {
        int y = 1;
        for (int j = 2; j <= i; j++) if (i % j == 0) y++;
        if (y == 8) ans++;
    }

    cout << ans << '\n';

    return 0;
}

Measured memory_bytes: 256
/* 
	Author: ankrypt
*/

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;
template<class T> using oset=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define MOD 1000000007
#define ll long long int
#define u64 unsigned long long int
#define ff first
#define ss second
#define all(x) x.begin(), x.end() 
#define ub upper_bound
#define lb lower_bound
#define MAX_INT 105
#define fi(a, b, c, d) for(int a = b; i < c; i += d)
#define fl(a, b, c, d) for(ll a = b; i < c; i += d)
#define quit exit(0)

ll N, K, A, B, C;
ll arr[MAX_INT], arr1[MAX_INT], data[MAX_INT];
vector<ll> V;

int main() {
	scanf("%lld %lld", &N, &K);
	for(int i = 0; i < N; i++) {
		scanf("%lld", &arr[i]);
	}
	ll ans = 0;
	for(int i = 0; i < N; i++) {
		ans += min(2 * abs(arr[i] - 0), 2 * abs(K - arr[i]));
	}
	printf("%lld\n", ans);
	return 0;
}
/*
	Powered by Buggy Plugin
*/




Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <limits>
#include <climits>
#include <utility>
#include <algorithm>
#include <numeric>
#include <bitset>

using namespace std;

using ll = long long;
using ull = unsigned long long;

int main()
{
    int A, B;
    cin >> A >> B;

    int k = (A + B) / 2;

    if (abs(A - k) == abs(B - k)) {
        cout << k << endl;
    } else {
        cout << "IMPOSSIBLE" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
a = [1,3,5,7,8,10,12]
b = [4,6,9,11]
c = [2]

x,y = map(int,input().split())
if (x in a and y in a)or (x in b and y in b)or(x in c and y in c):
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3060
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<functional>
#include<map>
#include<cstdlib>
#include<complex>
#include<numeric>

using namespace std;
using Int = long long;
Int INF = 1LL << 60;

Int gcd(Int a, Int b) { return b ? gcd(b, a % b) : a; }

int main() {

	Int a, b, c, d;
	cin >> a >> b >> c >> d;

	Int temp_c = 0;
	Int temp_d = 0;
	Int temp_cd = 0;
	Int cd = c*d/gcd(c, d);

	//1-B
	temp_c = b / c;
	temp_d = b / d;
	temp_cd = b / cd;

	//A-B
	temp_c -= (a - 1) / c;
	temp_d -= (a - 1) / d;
	temp_cd -= (a - 1) / cd;

	Int ans = (b - a + 1) - temp_c - temp_d + temp_cd;

	cout << ans << endl;
}

Measured memory_bytes: 256
// https://atcoder.jp/contests/atc001/tasks/unionfind_a

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define FORD(i,a,b) for(int i=a;i>=b;i--)
#define FORL(i,x) for(int i=head[x];i;i=nxt[i])
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define PB push_back
#define MP make_pair
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

// union by size + path having
class UnionFind {
public:
    vector <ll> par; // 各元の親を表す配列
    vector <ll> siz; // 素集合のサイズを表す配列(1 で初期化)

    // Constructor
    UnionFind(ll sz_): par(sz_), siz(sz_, 1LL) {
        for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
    }
    void init(ll sz_) {
        par.resize(sz_);
        siz.assign(sz_, 1LL);  // resize だとなぜか初期化されなかった
        for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
    }

    // Member Function
    // Find
    ll root(ll x) { // 根の検索
        while (par[x] != x) {
            x = par[x] = par[par[x]]; // x の親の親を x の親とする
        }
        return x;
    }

    // Union(Unite, Merge)
    bool merge(ll x, ll y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        // merge technique（データ構造をマージするテク．小を大にくっつける）
        if (siz[x] < siz[y]) swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }

    bool issame(ll x, ll y) { // 連結判定
        return root(x) == root(y);
    }

    ll size(ll x) { // 素集合のサイズ
        return siz[root(x)];
    }
};


int main() {
    // input(sunippets: inpv, inpn, inps)
    ll N, M, X, Y;
    cin >> N >> M;
    UnionFind uf(N);

    ll P[N];

    FOR(i,0,N-1) cin >> P[i];

    // calculation
    FOR(i, 0, M-1) {
        cin >> X >> Y;
        --X; --Y;
        uf.merge(X, Y);
    }

    int ans = 0;
    FOR(i,0,N-1){
      if(uf.issame(i,P[i]-1)){
        ++ans;
      }
    }

    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 2560
#include <algorithm>
#include <cassert>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

using namespace std;

typedef long long ll;

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;
}

vector<ll> A;

int main(void) {
    ll K, N;
    cin >> K >> N;

    A.resize(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }

    ll ans = A[N - 1] - A[0];
    for (int i = 1; i < N; i++) {
        chmin(ans, K - A[i] + A[i - 1]);
    }

    cout << ans << endl;

    return 0;
}


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

int M;
const int MOD = 10000;
string A, B;
int memo[512][2][2][10][512];

int dfs2(int i, bool low, bool tight, int pre, int rem);

int dfs1(int i=0, bool tight=true)
{
  int x = B[i] - '0';
  int r = (tight) ? (x) : 9;
  int ret = 0;
  
  if (B.size() - 1 == i){
    for (int j = 1; j <= r; j++){
      if (j % M) continue;
      ret++;
    }
    return ret;
  }

  ret += dfs1(i + 1, false);
  for (int j = 1; j <= r; ++j){
    ret += dfs2(i + 1, true, tight && x == j, j, j % M);
    ret += dfs2(i + 1, false, tight && x == j, j, j % M);
  }

  return ret % MOD;
}

int dfs2(int i, bool low, bool tight, int pre, int rem)
{
  if (i == B.size()){
    return rem == 0;
  }
  int &ret = memo[i][low][tight][pre][rem];

  if (ret != -1){
    return ret;
  }
  ret = 0;
  int x = B[i] - '0';
  int r = low ? pre - 1 : 9;
  int l = low ? 0 : (pre + 1);

  if (tight){
    r = min(r, x);
  }

  for (int j = l; j <= r; j++){
    ret += dfs2(i + 1, !low, tight && j == x, j, (rem * 10 + j) % M);
  }

  return ret %= MOD;
}

int main()
{
  cin >> A >> B >> M;

  for (int i = A.size() - 1; i >= 0; --i){
    if (A[i] - '0'){
      A[i]--;
      break;
    }
    A[i] = '9';
  }
  if (A[0] == '0' && A.size() != 1) A = A.substr(1);
  memset(memo, -1, sizeof(memo));
  int b = dfs1();
  swap(A, B);
  memset(memo, -1, sizeof(memo));
  int a = dfs1();

  cout << (b - a + MOD) % MOD << endl;
}

Measured memory_bytes: 42240
package main

import (
	"fmt"
)

func main() {
	var x int
	fmt.Scan(&x)

	var ps []int

	for i := 2; i < x; i++ {
		if isPrime(i, ps) {
			ps = append(ps, i)
		}
	}

	var ans int
	if x == 2 {
		ans = 2
	} else {
		for i := x; ; i++ {
			if isPrime(i, ps) {
				ans = i
				break
			}
		}
	}

	fmt.Print(ans)
}

func isPrime(x int, ps []int) bool {
	for _, p := range ps {
		if x % p == 0 {
			return false
		}
	}
	return true
}

Measured memory_bytes: 896
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
using namespace std;

int main() {
    int N,s;
    cin >> N;
    int M = N;
    while(N>0){
        s += N % 10;
        N /= 10;
    }

    if(M%s == 0) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll  long long int
#define MOD 1000000007
ll check(ll x,ll l,ll r)
{
	if(x>=l && x<=r)
	{
		return 1;
	}
	else
	return 0;
}
ll mod(ll x,ll h)
{
	return (x+h)%h;
}
int main()
{
ll l;
cin>>l;
double answer=0;
answer = l*l*l;
cout<<setprecision(100)<<(answer/27.0)<<endl;
}


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

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();
        int waNum = 0;
        int acNum = 0;
        int[] wa = new int[N];
        boolean[] ac = new boolean[N];
        for (int i = 0; i < M; i++) {
            int p = sc.nextInt()-1;
            String S = sc.next();
            if (S.equals("AC") && !ac[p]) {
                waNum += wa[p];
                acNum++;
                ac[p] = true;
            } else if (S.equals("WA") && !ac[p]) {
                wa[p]++;
            }
        }

        System.out.println(acNum + " " + waNum);
    }
}


Measured memory_bytes: 62672
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn = 22;
ll n, m, c;
ll b[maxn], a[maxn][maxn];

int main() {
    cin>>n>>m>>c;
    for(int i=1;i<=m;i++) {
        cin>>b[i];
    }

    ll result = 0LL;
    for(int i=1;i<=n;i++) {
        for(int j=1;j<=m;j++) {
            cin>>a[i][j];
        }

        ll temp = 0LL;
        for(int j=1;j<=m;j++) {
            temp += (a[i][j] * b[j]);
        }
        temp += c;
        if(temp > 0) result++;
    }
    cout<<result<<"\n";
    return 0;
}

Measured memory_bytes: 256
/**
 ____ ____ ____ ____ ____
||a |||t |||o |||d |||o ||
||__|||__|||__|||__|||__||
|/__\|/__\|/__\|/__\|/__\|

**/

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int N_MAX = 200002;
const int K_MAX = 12;

const int MOD = 998244353;

int n, k;

int l[K_MAX], r[K_MAX];

int dp[N_MAX];
int sdp[N_MAX];

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> k;
    for(int i = 1; i <= k; i++)
        cin >> l[i] >> r[i];
    dp[1] = sdp[1] = 1;
    for(int i = 2; i <= n; i++)
    {
        dp[i] = 0;
        for(int j = 1; j <= k; j++)
        {
            dp[i] += (sdp[max(0, i - l[j])] - sdp[max(0, i - r[j] - 1)] + MOD) % MOD;
            if(dp[i] >= MOD)
                dp[i] -= MOD;
        }
        sdp[i] = sdp[i - 1] + dp[i];
        if(sdp[i] >= MOD)
            sdp[i] -= MOD;
    }
    cout << dp[n] << "\n";
    return 0;
}


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

int n, res;
char s[100005];

int main() {
    scanf("%s", s);
    res = n = strlen(s);
    for (int i = 1; i < n; i++)
        if (s[i] != s[i - 1])
            res = min(res, max(i, n - i));
    printf("%d\n", res);
    return 0;
}


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

int main(void) {
  int a, b, c;
  double r, S, L, H;
  scanf("%d %d %d", &a, &b, &c);
  r = c * M_PI / 180.0;
  H = b * sin(r);
  S = a * H / 2;
  L = a + b + sqrt(H * H + (a - b * cos(r)) * (a - b * cos(r)));
  printf("%f\n%f\n%f\n", S, L, H);
  return 0;
}



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

vector<int> X,Y;
int main(){
	int x=1,y=0;
	while(1){
		scanf("%d,%d",&x,&y);
		if(!(x||y)) break;
		X.push_back(x);
		Y.push_back(y);
	}
	double nx=0,ny=0,na=0;
	for(int i=0;i<X.size();i++){
		nx+=(double)X[i]*sin(na*M_PI/180.0);ny+=(double)X[i]*cos(na*M_PI/180.0);
		na+=(double)Y[i];
	}
	cout<<(int)nx<<endl<<(int)ny<<endl;
	return 0;
}

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

#define all(v)			((v).begin()), ((v).end())
#define SIZE(v)			((int)((v).size()))
#define LOG(x)			log((double)x)
#define TOLOWER(x)          transform(all(x),x.begin(),::tolower)
#define TOUPPER(x)          transform(all(x),x.begin(),::toupper)
#define ROUND(x,m)			(round((double)x/m)*m)
#define DIGITS(x)			(floor(log10((double)x))+1)
#define READSTR(x)			getline(cin,x)
#define sort_g(a,b)              sort(a, b, greater<int>());
#define IOS() ios_base::sync_with_stdio(0);cin.tie(NULL);
#define REP(i, n) for (int i = 0; i < n; i++)
#define FILE_INPUT() 	freopen( "input.txt", "r", stdin)
#define FILE_OUTPUT()   freopen( "output.txt", "w", stdout)
#define PI 3.14159265


typedef long long ll;

bool myCmp(pair<int,int> &p1 , pair<int,int>&p2)
{
    return p1.first > p2.first;
}
unsigned long long
choose(unsigned long long n, unsigned long long k) {
    if (k > n) {
        return 0;
    }
    unsigned long long r = 1;
    for (unsigned long long d = 1; d <= k; ++d) {
        r *= n--;
        r /= d;
    }
    return r;
}
int toInt(string str)
{
    int num;
    std::istringstream iss(str); //put string in input stream
    iss >> num; return num; //read from stream as integer
}
ll  OO = 10e9;

const int MAXN = 2*10e3 + 1;
int X[MAXN];
ll cnt = 0;
int main() {
    IOS();
    int a,b,x;
    cin>>a>>b>>x;
    double vv = b*a;
    double hh = double(x)/vv;
    double angle = 0;
    if((a*a*0.5*b) >= double(x))
    {
        angle = atan(b/(2.0*hh));
    }
    else
    {
        double P = (double(x)/(a*a)) - 0.5*b;
        P = 2*P;
        P = double(b)-P;
        angle = atan(P/(a));
    }
    cout<<setprecision(10)<<(angle*180.0)/PI<<endl;
    return 0;
}



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

using namespace std;

bool is_integer(double x)
{
	return floor(x) == x;
}

int main()
{
	int N, D;
	cin >> N >> D;
	vector < vector < int >>X(N, vector < int >(D));
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < D; j++) {
			cin >> X[i][j];
		}
	}

	int ans = 0;
	for (int i = 0; i < N - 1; i++) {
		for (int j = i + 1; j < N; j++) {
			double sum = 0;
			for (int k = 0; k < D; k++) {
				sum += pow(X[i][k] - X[j][k], 2);
			}
			if (is_integer(sqrt(sum))) {
				ans++;
			}
		}
	}

  cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ALL(obj) (obj).begin(), (obj).end()
#define REP(i, n) for(int i = 0;i < (n);++i)

#define endl "\n"
#define pb push_back
#define MOD 1000000007LL
#define PI 3.1415926

const int dx[]={1,0,-1,0}, dy[]={0,-1,0,1};
const int dx_8[]={1,1,0,-1,-1,-1,0,1}, dy_8[]={0,-1,-1,-1,0,1,1,1};

typedef long long ll;

template <typename T> inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template <typename T> inline T LCM(T a,T b){T c=GCD(a,b);a/=c;return a*b;}
template <typename T> inline T nCr(T a,T b){T i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
template <typename T> inline T nHr(T a,T b){return nCr(a+b-1,b);}
template <typename T> inline T POW(T a,T b){int i,r=1;for(i=1;i<=b;i++){r*=a;}return r;}

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

	int n, a, b, c, l[8];
	cin >> n >> a >> b >> c;
	REP(i, n) cin >> l[i];
	int ans = INT_MAX;
	REP(i, pow(4, n)){
		int bit = i, aa = 0, bb = 0, cc = 0;
		bool ause = 0, buse = 0, cuse = 0;
		int score = 0;
		REP(j, n){
			if(bit % 4 == 1){ // aに使う
				if(ause) score += 10;
				ause = 1; aa += l[j];
			}
			if(bit % 4 == 2){ // bに使う
				if(buse) score += 10;
				buse = 1; bb += l[j];
			}
			if(bit % 4 == 3){ // cに使う
				if(cuse) score += 10;
				cuse = 1; cc += l[j];
			}
			bit /= 4;
		}
		if(!ause or !buse or !cuse) continue;
		score += abs(a-aa) + abs(b-bb) + abs(c-cc);
		ans = min(ans, score);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
//! ----------------------------------------------
//! Framework <https://github.com/vain0x/procon>
//!
//! See the bottom of file for solution.
//! ----------------------------------------------

#![allow(unused_imports)]
#![allow(non_snake_case)]

use std::cell::RefCell;
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::fmt::{Debug, Display, Formatter, Write as FmtWrite};
use std::io::{stderr, stdin, BufRead, Write};
use std::mem::{replace, swap};
use std::ops::*;
use std::rc::Rc;

/// Print values to standard error if debug mode.
#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), stderr());
            writeln!(err, "\x1B[33m{}\x1B[0m = {:?}", e, $e).unwrap()
        })*
    };
}

/// Read from standard input and parse each word.
/// - `read!(T, U, ..)` parses a line as a tuple of words.
/// - `read![[T]]` parses a line as an array of words.
/// - `read![..; N]` parses `N` lines, using `read!(..)` repeatedly.
#[allow(unused_macros)]
macro_rules! read {
    ([$t:ty] ; $n:expr) =>
        ((0..$n).map(|_| read!([$t])).collect::<Vec<_>>());
    ($($t:ty),+ ; $n:expr) =>
        ((0..$n).map(|_| read!($($t),+)).collect::<Vec<_>>());
    ([$t:ty]) =>
        (rl().split_whitespace().map(|w| w.parse().unwrap()).collect::<Vec<$t>>());
    ($($t:ty),*) => {{
        let buf = rl();
        let mut w = buf.split_whitespace();
        ($(w.next().unwrap().parse::<$t>().unwrap()),*)
    }};
}

/// Read a line from standard input.
#[allow(dead_code)]
fn rl() -> String {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();

    #[allow(deprecated)]
    buf.trim_right().to_owned()
}

// -----------------------------------------------
// Solution
// -----------------------------------------------

fn brute_force(N: i64) -> i64 {
    let mut sum = 0;
    for m in 1..N {
        if N / m == N % m {
            sum += m;
        }
    }
    sum
}

fn solve(N: i64) -> i64 {
    let mut sum = 0;

    let mut Q = 1;
    while Q * Q < N {
        if N / Q > 0 && N % Q == 0 {
            let m = N / Q - 1;
            if N / m == N % m {
                debug!(m);
                sum += m;
            }
        }
        Q += 1;
    }
    debug!(Q);

    let mut m = N / 2;
    while m >= 2 {
        let q = N / m;
        let r = N % m;

        if q <= Q {
            break;
        }
        if q > r {
            m -= 1;
            continue;
        }
        if q == r {
            sum += m;
            debug!(m);
        }
        debug_assert!(q <= r);
        // m を減らすごとに r は大きくなるので q が等しい範囲での探索は打ち切ってよい
        // 商が q+1 以上になる最小の m にジャンプ
        // debug!((m, q, r, N / q));
        m = min(m - 1, N / q);
    }

    sum
}

fn main() {
    // for N in 1..1000 {
    //     debug!(N);
    //     debug_assert_eq!(solve(N), brute_force(N), "N={}", N);
    // }

    let N = read!(i64);
    println!("{}", solve(N))
}


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

char s[3100],t[3100];
int lcs[3100][3100];
stack<char> st;

main()
{
    scanf("%s %s",s,t);
    for(int i=0;s[i];i++)
    {
    	for(int j=0;t[j];j++)
		{
			if(s[i]==t[j])
			{
				if(i&&j)
					lcs[i][j]=lcs[i-1][j-1]+1;//*
				else
					lcs[i][j]++;
				//*/
			}
			else
			{
				if(i&&j)
				{
					lcs[i][j]=max(lcs[i][j-1],lcs[i-1][j]);
				}
				else if(i)
				{
					lcs[i][j]=lcs[i-1][j];
				}
				else if(j)
				{
					lcs[i][j]=lcs[i][j-1];
				}
			}
		}
	}/*
	for(int i=0;s[i];i++)
	{
		for(int j=0;t[j];j++)
		{
			printf("%d ",lcs[i][j]);
		}
		printf("\n");
	}*/
	int x=strlen(s)-1,y=strlen(t)-1;
	while(1)
	{
		if(s[x]==t[y])
		{
			st.push(s[x]);
			x--;
			y--;
		}
		else
		{
			if(x&&y)
			{
				if(lcs[x][y-1]>lcs[x-1][y])
				{
					y--;
				}
				else
				{
					x--;
				}
			}
			else if(x)
			{
				x--;
			}
			else if(y)
			{
				y--;
			}
			else
			{
				break;
			}
		}
		if(x<0||y<0)
		{
			break;
		}
	}
	if(st.empty())
	{
		//printf("The answer is (an empty string).");
	}
	else
	while(!st.empty())
	{
		printf("%c",st.top());
		st.pop();
	}
}


Measured memory_bytes: 37120
import java.util.Scanner;

public class Main{
    static int[][][] caves = new int[2][1000][1000];
    static boolean[] primes = new boolean[1000000];
    static int[][] dp = new int[2][1000];
    static int[] vx = {1, 0, -1, 0};
    static int[] vy = {0, -1, 0, 1};

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        MakeCaves();
        while (true){
            int m = sc.nextInt();
            int n = sc.nextInt();
            if(m==0 && n==0) break;

            int x = -1, y = -1;
            for (int i = 0; i < 1000; i++) {
                for (int j = 0; j < 1000; j++) {
                    if(caves[0][i][j]==n){
                        x = j; y = i;
                        break;
                    }
                }
                if(x!=-1) break;
            }
            for (int i = 0; i <1000 ; i++) {
                dp[0][i] = dp[1][i] = 0;
            }

            int max = 0, dy = 0, mx = x, my = y;
            while (y+dy<1000){
                for (int i = (x-dy>=0)?x-dy:0; i <= ((x+dy<1000)?x+dy:999); i++) {
                    if(caves[0][y+dy][i]>m) continue;
                    dp[dy%2][i] = dp[(dy+1)%2][i] + caves[1][y+dy][i];
                    if(i>0&&dp[(dy+1)%2][i-1]!=0){
                        dp[dy%2][i] = Math.max(dp[dy%2][i], dp[(dy+1)%2][i-1] + caves[1][y+dy][i]);
                    }
                    if(i<999&&dp[(dy+1)%2][i+1]!=0){
                        dp[dy%2][i] = Math.max(dp[dy%2][i], dp[(dy+1)%2][i+1] + caves[1][y+dy][i]);
                    }
                    if(max<dp[dy%2][i]){
                        max = dp[dy%2][i];
                        mx = i; my = y + dy;
                    }else if(max==dp[dy%2][i] && caves[1][y+dy][i]==1){
                        if(caves[0][my][mx]<caves[0][y+dy][i]){
                            mx = i; my = y + dy;
                        }
                    }
                }
                dy++;
            }
            System.out.println(max+" "+((max!=0)?caves[0][my][mx]:0));
        }
    }

    static void FindPrimes() {
        primes[0] = true;
        for (int i = 1; i < 500000; i++) {
            if(primes[i]) continue;
            int j = (i+1)*2;
            while (j<1000000){
                primes[j-1] = true;
                j += i+1;
            }
        }
    }

    static void MakeCaves() {
        int n = 2, x = 499, y = 500;
        FindPrimes();
        caves[0][y][x] = 1;
        caves[1][y][x] = 0;

        for (int i = 0; i < 2000; i++) {
            for (int j = 0; j <= i/2; j++, n++) {
                if(n==1000001) break;
                x+=vx[i%4]; y+=vy[i%4];
                caves[0][y][x] = n;
                caves[1][y][x] = (primes[n-1])?0:1;
            }
        }
    }
}

Measured memory_bytes: 46848
// tested by Hightail: https://github.com/dj3500/hightail
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <cmath>
#include <algorithm>
#include <sstream>
#include <stack>
#include <cstring>
#include <iomanip>
#include <ctime>
#include <cassert>
using namespace std;
#define pb push_back
#define INF 1001001001
#define FOR(i,n) for(int (i)=0;(i)<(n);++(i))
#define FORI(i,n) for(int (i)=1;(i)<=(n);++(i))
#define mp make_pair
#define pii pair<int,int>
#define ll long long
#define vi vector<int>
#define SZ(x) ((int)((x).size()))
#define fi first
#define se second
#define wez(n) int (n); scanf("%d",&(n));
#define wez2(n,m) int (n),(m); scanf("%d %d",&(n),&(m));
#define wez3(n,m,k) int (n),(m),(k); scanf("%d %d %d",&(n),&(m),&(k));
inline void pisz(int n) { printf("%d\n",n); }
template<typename T,typename TT> ostream& operator<<(ostream &s,pair<T,TT> t) {return s<<"("<<t.first<<","<<t.second<<")";}
template<typename T> ostream& operator<<(ostream &s,vector<T> t){FOR(i,SZ(t))s<<t[i]<<" ";return s; }
#define DBG(vari) cout<<"["<<__LINE__<<"] "<<#vari<<" = "<<(vari)<<endl;
#define ALL(t) t.begin(),t.end()
#define FOREACH(i,t) for (__typeof(t.begin()) i=t.begin(); i!=t.end(); i++)
#define TESTS wez(testow)while(testow--)
#define REP(i,a,b) for(int (i)=(a);(i)<=(b);++i)
#define REPD(i,a,b) for(int (i)=(a); (i)>=(b);--i)
#define REMAX(a,b) (a)=max((a),(b));
#define REMIN(a,b) (a)=min((a),(b));
#define IOS ios_base::sync_with_stdio(0);

const int N = 100100;
int t[N];

int main () {
   wez(k);
   FORI(i,k) scanf("%d", t+i);
   ll a = 2, b = 2;
   REPD(i,k,1) {
      a = ((a + t[i] - 1) / t[i]) * t[i];
      b = b / t[i] * t[i];
      if (a > b) {
         pisz(-1);
         return 0;
      }
      b += t[i] - 1;
   }
   cout << a << ' ' << b;
}

Measured memory_bytes: 640
process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', function(chunk){


 var array = (chunk.trim()).split("\n")
 var hen = 3
 

for (var i = 1; i < array.length; i++) {
  var x = array[i].split(" ");
  x.sort(function(d, e){
    return e - d
  })
  if (Math.pow(x[0] , 2) == Math.pow(x[1] , 2) + Math.pow(x[2] , 2)) {
    console.log("YES");
  } else
    console.log("NO");
  
}



  })

Measured memory_bytes: 17732
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (long long i = j; i < (long long)(n); i++)
#define _GLIBCXX_DEBUG
#define MOD 1000000007
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
//name[i][j]-> vvl name(i,vl(j))
//map<int,int>mp
//余りを切り上げる =>  (a + b - 1) / b 

signed main(){
	int a,b,c;
	cin>>a>>b>>c;
	a-=b;
	a-=(a/c)*c;
	cout<<a;
	
	return 0;
}

Measured memory_bytes: 3600
var GET=(function(){function f(s){return new g(s);}function g(s){this._s=s.trim().split("\n");this._y=0;}g.prototype.a=function(f){var s=this._s, y=this._y, r;if(typeof s[y]==="string")s[y]=s[y].split(" ").reverse();r=s[y].pop();if(!s[y].length)this._y++;return f?r:+r;};g.prototype.l=function(f){var s=this._s[this._y++].split(" ");return f?s:s.map(a=>+a);};g.prototype.m=function(n,f){var r=this._s.slice(this._y,this._y+=n).map(a=>a.split(" "));return f?r:r.map(a=>a.map(a=>+a));};g.prototype.r=function(n,f){var r=this._s.slice(this._y,this._y+=n);return f?r:r.map(a=>+a);};return f;})();
var o=GET(require("fs").readFileSync("/dev/stdin","utf8"));
function xArray(v){var a=arguments,l=a.length,r="Array(a["+--l+"]).fill(0).map(x=>{return "+v+";})";while(--l)r="Array(a["+l+"]).fill(0).map(x=>"+r+")";return eval(r);}
function PriorityQueue(){
  this.heap = [];
}
PriorityQueue.prototype = {
  push : function(x){
    var h = this.heap, i = h.length++, j;
    while(i){
      j = i-1 >> 1;
      if(h[j] <= x)break;
      h[i] = h[j];
      i = j;
    }
    h[i] = x;
  },
  pop : function(){
    var h = this.heap, r = h[0], x = h.pop();
    var i = 0, k = h.length >> 1, j;
    while (i < k) {
      j = (i << 1) + 1;
      if(h[j+1] < h[j])++j;
      if(x <= h[j])break;
      h[i] = h[j];
      i = j;
    }
    if(h.length)h[i] = x;
    return r;
  },
  size : function(){return this.heap.length;},
  top : function(){return this.heap[0];},
};

console.log(main());
function main(){
  var n = o.a();
  var k = o.a();
  var p = o.l();
  var pqu = new PriorityQueue();
  var pqd = new PriorityQueue();
  var set = new Set();
  var ans = 1, id = 1, mx = p[0], f = 0;
  for(var i = 1; i < n; i++){
    if(mx < p[i])id++;
    else{
      if(id >= k){
        if(f)ans--;
        f = 1;
      }
      id = 1;
    }
    mx = p[i];
  }
  if(id >= k && f)ans--;
  for(var i = 0; i < k; i++){
    pqu.push(-p[i]);
    pqd.push(p[i]);
  }
  for(;i<n;i++){
    var t = 0;
    if(pqd.top() === p[i-k]){
      t++;
      pqd.pop();
    }
    if(pqu.top() === -p[i-k]){
      pqu.pop();
    }
    while(set.has(pqd.top()))pqd.pop();
    while(set.has(-pqu.top()))pqu.pop();
    if(pqu.top() > -p[i])t++;
    if(t < 2)ans++;
    pqd.push(p[i]);
    pqu.push(-p[i]);
    set.add(p[i-k]);
  }
  return ans;
}

Measured memory_bytes: 66528
#include "bits/stdc++.h"

#define debug(x) cout<<#x<<": "<<x<<endl
#define rep(i,n) for (int i=0;i<(n);i++)
#define FOR(i,a,b) for (int i=(a);i<=(b);i++)
#define all(a) (a).begin(),(a).end()
using namespace std;
typedef vector<int> VI;
typedef vector<vector<int>> VVI;
typedef long long ll;


void solve() {
#ifdef _WIN32
	istream &cin = ifstream("input.txt");
#endif

	VI v(3);
	rep(i, 3) cin >> v[i];
	sort(all(v));

	if (v[0] == 5 && v[1] == 5 && v[2] == 7) cout << "YES" << endl;
	else cout << "NO" << endl;

}


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


	solve();
	system("PAUSE");
	return 0;
}

Measured memory_bytes: 504
#include <cstdio>
#include <algorithm>
using namespace std;
int main() {
	int N;
	while (scanf("%d",&N)!=EOF) {
		int P[N];
		for (int i=0; i<N; i++) scanf("%d",&P[i]);
		sort(P, P+N);
		int res = 0, sum = 0;
		for (int i=0; i<N; i++) {
			sum += P[i];
			res += sum;
		}
		printf("%d\n", res);
	}
}

Measured memory_bytes: 0
#include <iostream>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#include <tuple>
#include <queue>
#include <set>
#include <math.h>
#include <array>
#include <list>
#include <set>
const int MOD=1000000007;
const int INF=1000000000;
using namespace std;
typedef long long ll;
typedef tuple<ll,ll,ll> tup;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> P;
vector<int> anscands;
int main(void)
{
  vector<pair<int,int> > ones;
  int N,K;
  bool seeone=false;
  string S;
  int ans=0;
  cin >> N >> K;
  cin >> S;
  int l=0,r=0;
  ones.push_back(make_pair(1,1));
  for(int i=0;i<N;i++)
    {
      if(S[i]=='1')
	{
	  if(!seeone)
	    {
	      l=i+1;
	      r=i+1;
	    }
	  seeone=true;
	  if(i==N-1)
	    {
	      r=i+1;
	      ones.push_back(make_pair(l,r));
	    }
	}
      else
	{
	  if(seeone)
	    {
	      r=i;
	      ones.push_back(make_pair(l,r));
	      l=0,r=0;
	      seeone=false;
	    }
	}
    }
  if(S[N-1]=='0')
    {
      ones.push_back(make_pair(N,N));
    }
  int osize=int(ones.size());
  /*for(int i=0;i<osize;i++)
    {
      cout << ones[i].first << ' ' << ones[i].second << endl;
      }*/
  for(int i=0;i<max(osize-K,1);i++)
    {
      for(int j=0;j<=K;j++)
	{
	  if(i+j>=osize) break;
	  ans=max(ans,ones[i+j].second-ones[i].first+1);
	}
    }
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 1020
#include<map>
#include<iostream>
#include<deque>
#include<algorithm>
#include<string>
#include<cctype>
#include<iomanip>
#include<vector>
#include<queue>
#include<tuple>
#include<stdio.h>
 
using namespace std;
#define REP(i,b,e) for(ll i=(ll)b;i<(ll)e;i++)
#define rep0(i,n) REP(i,0ll,n)
#define rep1(i,n) REP(i,1ll,n+1)
 
#define shosu setprecision(10)
 
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<P,ll> Q;
ll longinf=1ll<<60;
int inf=1<<29;
//mleしなければぜんぶllでかく。

int main(){
      int h,w,a,b;
      cin>>h>>w>>a>>b;
      int n=h/a;
      int m=w/b;
      int ans=h*w-(a*b)*(n*m);
      cout<<ans<<endl;
      

      return 0;
}


Measured memory_bytes: 3072
import java.util.Scanner

object Main extends App {
  val sc = new Scanner(System.in)

  val n = sc.nextInt
  val s = sc.next
  val t = sc.next

  val res = (s zip t).foldLeft(""){ case (str, (sCh, tCh)) =>
      str + sCh + tCh
  }

  println(res)

}

Measured memory_bytes: 27320
N=int(input())
A=list(map(int, input().split()))
A.sort()
ONE=0
TWO=0
THREE=0
Ne=0
ZERO=0
AA=A[0]
BB=A[N//3]
CC=A[(N*2)//3]
AAA=bin(AA)
BBB=bin(BB)
CCC=bin(CC)
X=bin(AA^BB)
Y=bin(BB^CC)
Z=bin(CC^AA)
i=0
if A[0]==0:
    for x in range(0,N):
        if A[x]==0:
            ZERO=ZERO+1
        if A[x]==BB:
            Ne=Ne+1
    if ZERO==N:
        i=1
    if N%3==0 and ZERO==N//3 and Ne==(N*2)//3:
        i=1

if X==CCC and Y==AAA and Z==BBB:
    if N%3==0:
        for x in range(0,N):
            if AA==A[x]:
                ONE=ONE+1
            if BB==A[x]:
                TWO=TWO+1
            if CC==A[x]:
                THREE=THREE+1
        if ONE==TWO and TWO==THREE and THREE==N//3:
            i=1
if i==0:
    print("No")
if i==1:
    print("Yes")



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

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,int> pli;
const ll INF = 10e16;
const int maxN = 200010;
const int maxD = 15;
const int maxH = 100; 
const int MOD = 1000000007;


vector<string> ans;
vector<int> p;


int main()
{
	double p = 3.1415926;
	int R;
	cin>>R;
	double ans = p * R * 2;
	printf("%f\n",ans); 
	return 0;
}

Measured memory_bytes: 3764
#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <list>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <algorithm>
#include <numeric>
#include <functional>

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define ALL(a) (a).begin(),(a).end()

using namespace std;
typedef long long ll;

class UnionFind {
  int *id, *sz;
  
  int root(int x) {
    if (id[x] != x)
      id[x] = root(id[x]);
    return id[x];
  }
  
 public:

  explicit UnionFind(int n) {
    id = new int[n];
    sz = new int[n];
    REP(i,n) {
      id[i] = i;
      sz[i] = 0;
    }
  }
  
  ~UnionFind() {
    delete[] id;
    delete[] sz;
  }

  bool same(int p, int q) {
    return root(p) == root(q);
  }

  void unite(int p, int q) {
    int i = root(p), j = root(q);
    if (sz[i] < sz[j]) {
      id[i] = j;
      sz[j] += sz[i];
    } else {
      id[j] = i;
      sz[i] += sz[j];
    }
  }
};



int main(int argc, char *argv[])
{
  cin.tie(0);
  ios::sync_with_stdio(false);
    
  int n, q, com, x, y;

  cin >> n >> q;
  UnionFind uf(n);
  REP(i,q) {
    cin >> com >> x >> y;
    if (com == 0) uf.unite(x, y);
    else if (uf.same(x, y)) cout << 1 << endl;
    else cout << 0 << endl;
  }

  return 0;
}

Measured memory_bytes: 1284
#include<bits/stdc++.h>
#include<iomanip>
using namespace std;
typedef long long ll;
typedef long  l;
typedef pair<ll,ll> P;
#define rep(i,n) for(int i=0;i<n;i++)
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
const double PI=3.141592653589;
const int INF=1000000007;
const ll LMAX=1000000000000001;
int gcd(int a,int b){if(a<b)swap(a,b);int c=a%b;while(c!=0){a=b;b=c;c=a%b;}return b;}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
int dx[]={-1,0,1,0};
int dy[]={0,1,0,-1};

int n, m, q;
int ans = -1;
vector<int> a(55);
vector<int> b(55);
vector<int> c(55);
vector<int> d(55);

void dfs(vector<int> k){
  if(k.size() == n){
    // rep(i, k.size()){
    //   cout << k[i] << (i == k.size() -1 ? "\n":" ");
    // }
    int sum = 0;
    rep(i, q){
      if(k[b[i] - 1] - k[a[i] - 1] == c[i]) sum += d[i];
    }
    ans = max(sum, ans);
    // cout << sum << endl;
  }else{
    int bc = k.back();
    rep(i, m - bc + 1){
      k.pb(bc + i);
      dfs(k);
      k.pop_back();
    }
  }
}

int main(){
  cin >> n >> m >> q;
  rep(i, q){
    cin >> a[i] >> b[i] >> c[i] >> d[i];
  }
  vector<int> A(1,1);
  rep(i, m){
    A[0] = i + 1;
    dfs(A);
  }

  cout << ans << endl;

  return 0;
}


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

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define RREP(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define RFOR(i, a, b) for (int i = (a); i >= (b); --i)
#define ALL(v) (v).begin(), (v).end()
#define RALL(a) (a).rbegin(), (a).rend()

#define uint8_t unsigned char
#define uint16_t unsigned short
#define uint32_t unsigned int
#define uint64_t unsigned long long

#define int8_t signed char
#define int16_t signed short
#define int32_t signed int
#define int64_t signed long long

using namespace std;

int main(int argc, char const* argv[])
{
    int x = 0;
    int y = 0;

    cin >> x >> y;
  	int b = (y-2*x)/2;
    int a = x-b;
  
  	if (a < 0 || b < 0) {
    	cout << "No" << endl;
    }
    else if (2*a + 4*b == y) {
    	cout << "Yes" << endl;
    }
    else {
    	cout << "No" << endl;
    } 
    return 0;
}




Measured memory_bytes: 3620
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <algorithm>
#include <cstdio>
#include <iomanip>
#include <queue>
#include <deque>
#include <stack>
#include <fstream>
#include <cmath>
#include <random>
#include <complex>
#include <functional>

#define ll int64_t
#define Rep(i, n) for (ll i = 0; i < n; i++)
using namespace std;
typedef vector<ll> vec;
typedef vector<vec> mat;

const ll inf = 1LL << 60;

template<class T> inline void chmin(T& a, T b) {
    if (a > b) {
        a = b;
    }
}
template<class T> inline void chmax(T& a, T b) {
    if (a < b) {
        a = b;
    }
}

const long double PI = 3.14159265358979323846;

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

    cout << fixed << setprecision(10);

    ll N;
    cin >> N;
    vector<complex<long double>> holes(N);
    Rep (i, N) {
        long double x, y;
        cin >> x >> y;
        complex<long double> hole(x, y);
        holes[i] = hole;
    }

    if (N == 2) {
        cout << "0.5\n0.5\n";
        return 0;
    }

    Rep (i, N) {
        deque<long double> a;
        Rep (j, N) {
            if (i == j) continue;
            a.push_back(arg(holes[j]-holes[i]));
        }

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

        // Rep (i, N-1) {
        //     cout << a[i] << " \n"[i==N-2];
        // }

        long double ans = 0;
        Rep (i, N-1) {
            long double tmp = a[N-2] - a[0] - PI;
            tmp *= -1;
            chmax(ans, tmp);
            a.push_back(a.front() + 2*PI);
            a.pop_front();
        }

        cout << ans / 2 / PI << "\n";
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,k;
    cin >> n >> k;
    int d;
    vector<bool>snuke(n,false);
    int a;
    for(int i=0;i<k;i++){
        cin >> d;
        for(int j=0;j<d;j++){
            cin >> a;
            a--;
            snuke[a] = true;
        }
    }
    int ans = 0;
    for(int i=0;i<n;i++){
        if(!snuke[i])ans++;
    }
    cout << ans << endl;
    
}

Measured memory_bytes: 3632
#define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f
#include <cstdio>
#include <iostream>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>
 
using namespace std;
 
typedef long long ll;
typedef pair <int,int> P;
typedef pair <int,P > PP;
 
const static int tx[] = {0,1,1,1,0,-1,-1,-1};
const static int ty[] = {-1,-1,0,1,1,1,0,-1};

struct Operation{
  string from;
  string to;
};

string modify(const string& src,const Operation& opr){
  string res="";
  int f_size = opr.from.size();
  string f_str = opr.from;
  string t_str = opr.to;
  
  for(int i=0;i<src.size();){
    if(src.substr(i,f_size) == f_str){
      res += t_str;
      i+=f_size;
      continue;
    }
    res.push_back(src[i]);
    i++;
  }
  return res;
}

void dfs(string src,int N,
	 Operation modify_operations[10],
	 map<string,int>& from_orig_cost,
	 const string& target){
  for(int i=0;i<N;i++){
    string dst = modify(src,modify_operations[i]);
    if(src==dst) continue;
    if(dst.size() > target.size()) continue;
    if(from_orig_cost.find(dst) == from_orig_cost.end()
       || from_orig_cost[dst] > from_orig_cost[src]+1){
      from_orig_cost[dst] = from_orig_cost[src]+1;
      dfs(dst,N,modify_operations,from_orig_cost,target);
    }
  }
}


int main(){
  int N;
  while(~scanf("%d",&N)){
    if(N==0) break;

    Operation modify_operations[10];
    for(int i=0;i<N;i++){
      string from,to;
      cin >> from >> to;
      Operation tmp = {from,to};
      modify_operations[i] = tmp;
    }

    map<string,int> from_orig_cost;

    string original;
    string target;
    cin >> original >> target;

    from_orig_cost[original] = 0;
    
    dfs(original,N,modify_operations,
	from_orig_cost,target);
    
    if(from_orig_cost.find(target) == from_orig_cost.end()){
      printf("-1\n");
    }
    else{
      printf("%d\n",from_orig_cost[target]);
    }
  }
}

Measured memory_bytes: 1484
#include <algorithm>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;
using ll = long long;

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

    vector<ll> A(N);
    ll sum = 0;
    for (int i = 0; i < N; i++) {
        cin >> A[i];
        sum += A[i];
    }
    sort(A.begin(), A.end(), greater<int>());
    ll output = 1;
    sum -= A[0];
    for (int i = 1; i < N; i++) {
        if (sum * 2 >= A[i - 1])
            output++;
        else
            break;
        sum -= A[i];
    }
    cout << output << endl;

    return 0;
}


Measured memory_bytes: 4044
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, x, n) for (int i = x; i < (n); i++)
#define all(n) begin(n), end(n)
struct cww
{
    cww()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
} star;
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
typedef vector<int> vint;
typedef vector<char> vchar;
typedef vector<vector<int>> vvint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef unsigned long long ull;
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;
}

ll Pow(ll x, ll n)
{
    ll ret = 1;
    while (n > 0)
    {
        if (n & 1)
            ret *= x;
        x *= x;
        n >>= 1;
    }
    return ret;
}

long long combination(long long N, long long R)
{
    if (R < 0 || R > N)
        return 0;
    if (R == 1)
        return N;
    else if (R == 2)
        return N * (N - 1) / 2;
    else
        return N * (N - 1) * (N - 2) / 6;
}

vector<vvll> memo;
string N;
int K, keta;
ll solve(int i, int k, bool smaller)
{
    if (memo[i][k][smaller] != -1)
    {
        return memo[i][k][smaller];
    }
    if (k == 0)
    {
        memo[i][k][smaller] = 1;
        return 1;
    }
    if (i == keta)
    {
        memo[i][k][smaller] = 0;
        return 0;
    }
    if (smaller)
    {
        memo[i][k][smaller] = combination(keta - i, k) * pow(9, k);
        return memo[i][k][smaller];
    }
    if (N[i] == '0')
    {
        memo[i][k][smaller] = solve(i + 1, k, smaller);
        return memo[i][k][smaller];
    }
    ll zero = solve(i + 1, k, true);
    ll mid = solve(i + 1, k - 1, true) * (N[i] - '1');
    ll girigiri = solve(i + 1, k - 1, false);
    memo[i][k][smaller] = zero + mid + girigiri;
    return memo[i][k][smaller];
}

int main()
{

    cin >> N;
    cin >> K;
    keta = N.size();
    memo.resize(keta + 1, vvll(K+1, vll(2, -1)));

    cout << solve(0, K, false);
    return 0;
}

Measured memory_bytes: 256
import math
from functools import reduce
def lcm_base(x, y):
    return (x * y) // math.gcd(x, y)
def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)
N = int(input())
T = [int(input()) for i in range(N)]
print(lcm_list(T))


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


int main(){
  int n;
  cin >> n;
  vector<int>d(n);
  for(int i=0;i<n;i++){
    cin >> d.at(i);
  }
  int ans =0;
  for(int i=0;i<n;i++){
    for(int j=i+1;j<n;j++){
      ans += d.at(i)*d.at(j);
    }
  }
  cout << ans << endl;
}
      


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
 
  int A,B,C;
  cin >> A >> B >> C;
  
  if ( (A==5 && B==5 && C==7) || (A==7 && B==5 && C==5) || (A==5 && B==7 && C==5) ) 
    cout << "YES" << endl;
  
  else cout << "NO" << endl;
}

Measured memory_bytes: 256
/*author: hyperion_1724
  date: 
*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace std;
using namespace __gnu_pbds;
#define READ(X) cin>>X;
#define READV(X) long long X; cin>>X;
#define READAR(A,N) long long A[N]; for(int i=0;i<N;i++) {cin>>A[i];}
#define rz(A,N) A.resize(N);
#define sz(X) (long long)(X.size())
#define fi first
#define se second
#define endl '\n'
#define trav(x,A) for(auto &x:A)
#define veci vector<int>
#define vecl vector<long long>
#define FORI(a,b,c) for(int a=b;a<c;a++)
#define FORD(a,b,c) for(int a=b;a>c;a--)
typedef tree<long long,null_type,less<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef tree<long long,null_type,greater<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set1;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<long,long> pll;
const long long inf=(long long)1e18;
const long long MOD=(long long)(1e9+7);
const long long INIT=(long long)(1e6+1);


ll power(ll x, ll y) 
{ 
    if (y == 0) 
        return 1; 
    ll p = power(x, y/2) % MOD; 
    p = (p * p) % MOD; 
  
    return (y%2 == 0)? p : (x * p) % MOD; 
} 
ll modInverse(ll a) 
{ 
    return power(a,MOD-2);
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	

	READV(N);
	READV(K);
	ll st=(N-K+1)%MOD;
	cout<<st<<endl;
	FORI(i,1,K)
	{
		ll ans=(((st*(K-i))%MOD)*(N-K-i+1))%MOD;
		ans=(ans*modInverse(i))%MOD;
		ans=(ans*modInverse(i+1))%MOD;
		cout<<ans<<endl;
		st=ans;
	}

	return 0;
}

Measured memory_bytes: 256
# coding: utf-8
N,M=map(int,input().split())
ansl=[None for i in range(N)]
flg=True

for i in range(M):
    s,c=map(int,input().split())
    if ansl[s-1]==None:
        ansl[s-1]=str(c)
    else:
        if ansl[s-1]!=str(c):
            flg=False

for i in range(N):
    if ansl[i]==None:
        if i==0 and N!=1:
            ansl[i]="1"
        else:
            ansl[i]="0"

if ansl[0]=="0" and N!=1:
    flg=False

ans=""

for i in range(N):
    ans+=ansl[i]
if flg:
    print(int(ans))
else:
    print(-1)


Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <list>
#include <utility>
#include <tuple>
#include <cstdio>
#include <set>
#include <queue>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <cmath>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<(n);++i)
using namespace std;
const long long INF = 1LL << 60;
typedef long long ll;
int main() {
    int N;
    cin >> N;
    //
    vector<int> A(N+1);
    for(int i=0;i<N+1;i++){
        cin >> A[i];
    }
    //
    vector<int> B(N);
    for(int j=0;j<N;j++){
        cin >> B[j];
    }
    //
    ll total=0;
    for(int i=0;i<N+1;i++){
        if(i==0){
            if(A[i]>=B[i]){
                total += B[i];
                B[0]=0;
            }
            else{
                total += A[i];
                B[0]-=A[0];
            }
        }
        else{
            if(A[i] <= B[i-1]){
                total+= A[i];
            }
            else{
                if(A[i] > B[i] + B[i-1]){
                    total += B[i] + B[i-1];
                    B[i-1]=0;
                    B[i]=0;
                }
                else{
                    total += A[i];
                    B[i] = B[i] - (A[i] - B[i-1]);
                }
            }
        }
    }
    cout << total << endl;
}

Measured memory_bytes: 4024
import java.util.*

fun main(args:Array<String>){
    val (n, z, w) = readLine()!!.split(" ").map{it.toInt()}
    val a = readLine()!!.split(" ").map{it.toInt()}
    val ans = if(n == 1) Math.abs(w - a.last()) else Math.max(Math.abs(w - a.last()), Math.abs(a[n - 2] - a[n - 1]))
    println(ans)
}


Measured memory_bytes: 37988