akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
const long long int INF = 1e18;

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

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

    // cumulative sum
    for(int i=1; i<n; i++){
        a[i] += a[i-1];
    }

    int c, l, r;
    vector<int> left(n-2), right(n-2);// arg c = center-cut position (1 ~ n-3)
    left[1] = 0;// o|o|oooo...
    right[n-3] = n-2;// n >= 4

    // left
    c = 2;
    l = 0;
    while(1){
        // for fixed c, move l
        while(abs( (a[c] - a[l])   - a[l]   ) 
           >  abs( (a[c] - a[l+1]) - a[l+1] )
           && l < c - 1
        ){
            l += 1;
        }
        
        // left[c] deterined, move on to next c
        left[c] = l;
        if(c < n - 3) c += 1;
        else break;
    }

    // right
    c = 1;
    r = 2;
    while(1){
        // for fixed c, move r
        while(abs( (a[n-1] - a[r]  ) - (a[r]   - a[c]))
           >  abs( (a[n-1] - a[r+1]) - (a[r+1] - a[c]))
           && r < n - 2
        ){
            r += 1;
        }
        
        // right[c] determined, move on to next c
        right[c] = r;
        //cout << c << " " << r << endl;
        if(c < r - 1) c += 1;
        else if(r < n - 2){
            c += 1;
            r += 1;
        }
        else break;
    }

    long long int ans = INF;
    for(int ci=1; ci<=n-3; ci++){// center

        //cout << a[left[ci]] << " " 
        //     << a[ci] - a[left[ci]] << " "
        //     << a[right[ci]]- a[ci] << " "
        //     << a[n-1]- a[right[ci]] << endl;

        long long int diff
        = abs(
          max({ a[left[ci]], a[ci] - a[left[ci]], a[right[ci]]- a[ci], a[n-1]- a[right[ci]] })
        - min({ a[left[ci]], a[ci] - a[left[ci]], a[right[ci]]- a[ci], a[n-1]- a[right[ci]] })
        );
        if(diff < ans) ans = diff;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3328
// abc138_a
#include <bits/stdc++.h>
#ifdef LOCAL
#include "../cxx-prettyprint/prettyprint.hpp"
#endif
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;

#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))
#define ALL(x) x.begin(), x.end()

#define INF ((1 << 29)-1)
#define MOD (1000000007)

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
template<class T> void print(const T& x){cout << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }
struct PreMain {PreMain(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} premain;

int main() {
#ifdef LOCAL
    ifstream in("../arg.txt"); cin.rdbuf(in.rdbuf());
#endif

    string S, T;
    cin >> S >> T;

    int ans = 0;
    REP(i, 3){
        if (S[i] == T[i]) ans++;
    }

    print(ans);

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1000000007;
#define INF 1LL<<30
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()


int main(){
    int n;
    cin>>n;
    vector<int> h(n);
    rep(i,n) cin>>h[i];
    vector<int> g(n,0);

    int ans=0;
    while(1){
        bool ok=true;
        rep(i,n){
            if(g[i]!=h[i]) ok=false;
        }
        if(ok){
            cout<<ans<<endl;
            return 0;
        }

        ok=true;
        rep(i,n){
            if(g[i]!=h[i] && ok){
                g[i]++;
                ans++;
                ok=false;
            }
            else if(g[i]!=h[i]) g[i]++;
            else ok=true;
        }
    }
}



Measured memory_bytes: 3596
S = [input() for _ in range(3)]

dic = {"a": 0, "b": 1, "c": 2}
arr = ["A", "B", "C"]

old = "a"
while True:
  i = dic[old]
  if len(S[i]) == 0:
    print(arr[i])
    break
  old = S[i][0]
  S[i] = S[i][1:]


Measured memory_bytes: 3064
l = input().split()
N = int(l[0])
A = []

for i in range(N):
    l = input().split()
    A.append(int(l[0]))

# print(N, A)

B = {}
for a in A:
    if a not in B:
        B[a] = 1
    else:
        B[a] += 1

sum = 0
for b in B:
    sum += B[b] % 2

print(sum)


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

int main(){
    int A, B, ans = 0;
    cin >> A >> B;
    for(int i = A; i <= B ; i++){
        int a, b, c, d, e;
        //1の位から順にa,b,c,d,e
        a = i % 10;
        b = i % 100 / 10;
        c = i % 1000 / 100;
        d = i % 10000 / 1000;
        e = i / 10000;
        if(a == e && b == d){
            ans ++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	int a, b, c;
	scanf("%d %d %d", &a, &b, &c);
	double sum = (double)(a + b + c);
	sum /= 2;
	if(sum == a || sum == b || sum == c) printf("Yes\n");
	else printf("No\n");
	return 0;
}


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

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> VI;
typedef vector<VI> VVI;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = numeric_limits<int>::max() / 2;
const int NEG_INF = numeric_limits<int>::min() / 2;

/*bool is_prime(int n){
  bool res=true;
  if(n==1) return false;
  for(int i=2;i*i<=n;i++){
    if(n%i==0) res=false;
  }
  return res;
}*/

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

  bool prime[2000000];
  prime[1]=false;
  for(int i=2;i<=1000000;i++){
    prime[i]=true;
  }
  for(int i=2;i*i<1000001;i++){
    if(prime[i]){
      for(int j=2;i*j<1000001;j++){
        prime[i*j] = false;
      }
    }
  }

  while(true){
    int a,d,n;
    cin >> a >> d >> n;
    if(n==0) break;
    int count=0,idx=0;
    while(count<n){
      if(prime[a+d*idx]) count++;
      idx++;
    }
    cout << a+d*(idx-1) << endl;
  }
}

Measured memory_bytes: 4056
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <set>
using namespace std;

long long n,a,x[60],dp[60][2510][60];

long long solve(long long i,long long sum,long long card){
    
    if(dp[i][sum][card]>=0)return dp[i][sum][card];
    
    if(i==n){
        if(card!=0&&sum/card==a&&sum%card==0)return 1;
        else return 0;
    }
    
    else{
        dp[i][sum][card]=solve(i+1,sum,card)+solve(i+1,sum+x[i],card+1);
        return dp[i][sum][card];
    }
    
}

int main(void){
    cin>>n>>a;
    for(int i=0;i<n;i++){
        cin>>x[i];
    }
    for(int i=0;i<=50;i++){
        for(int j=0;j<=2500;j++){
            for(int k=0;k<=50;k++){
                dp[i][j][k]=-1;
            }
        }
    }
    cout<<solve(0,0,0)<<endl;
    return 0;
}


Measured memory_bytes: 61696
#include<bits/stdc++.h>
#define ll long long

const int MAX = 1 << 18;
const int N = 200010;

ll seg[2][2][MAX << 1];
int n, q, a, b;
int x[N];

void add(int type1, int type2, int sit, ll value){
	sit += MAX;
	seg[type1][type2][sit] = std::min(seg[type1][type2][sit], value);
	for (sit >>= 1 ; sit; sit >>= 1){
		seg[type1][type2][sit] = std::min(seg[type1][type2][sit << 1], seg[type1][type2][(sit << 1) + 1]);
	}
}

ll query(int type1, int type2, int left, int right){
	ll ret = LLONG_MAX;
	for (int l = left + MAX, r = right + MAX + 1; l < r; l >>= 1, r >>= 1){
		if (l & 1){
			ret = std::min(ret, seg[type1][type2][l ++]);
		}
		if (r & 1){
			ret = std::min(ret, seg[type1][type2][-- r]);
		}
	}
	return ret;
}

int main(){
	int x0;
	scanf("%d%d%d%d", &n, &q, &a, &b);
	for (int i = 0; i < q; ++ i){
		scanf("%d", &x[i]);
	}
	memset(seg, 0x3f, sizeof(seg));
	add(0, 0, b, b + std::abs(a - x[0]));
	add(0, 1, b, n - b + std::abs(a - x[0]));
	add(1, 0, a, a + std::abs(b - x[0]));
	add(1, 1, a, n - a + std::abs(b - x[0]));
	ll now = 0;
	for (int i = 1; i < q; ++ i){
		ll x1 = query(0, 0, x[i], n), x2 = query(0, 1, 1, x[i]);
		x1 -= x[i], x2 -= n - x[i];
		ll y1 = std::min(x1, x2) + now;
		x1 = query(1, 0, x[i], n), x2 = query(1, 1, 1, x[i]);
		x1 -= x[i], x2 -= n - x[i];
		ll y2 = std::min(x1, x2) + now;
		now += std::abs(x[i] - x[i - 1]);
		add(1, 0, x[i - 1], y1 - now + x[i - 1]);
		add(1, 1, x[i - 1], y1 - now + n - x[i - 1]);
		add(0, 0, x[i - 1], y2 - now + x[i - 1]);
		add(0, 1, x[i - 1], y2 - now + n - x[i - 1]);
	}
	ll ans = LLONG_MAX;
	for (int i = 1; i <= n; ++ i){
		ans = std::min(ans, seg[0][0][i + MAX] - i + now);
		ans = std::min(ans, seg[1][0][i + MAX] - i + now);
	}
	return printf("%lld\n", ans), 0;
}

Measured memory_bytes: 17408
# coding: utf-8
# Your code here!

def iter_subset(_a): #aの部分集合を走る
    _bit = _a
    yield _bit
    while 1:
        _bit = (_bit-1) & _a 
        yield _bit
        if not _bit: break



n=int(input())
A= [[int(i) for i in input().split()] for j in range(n)]

total = 1<<n
gscore = [0]*total
dp = [0]*(total)

for i in range(n):
    for k in range(1<<(i)):
        gscore[k^(1<<i)] += gscore[k]
        for j,c in enumerate(A[i]):
            if (1<<j)&k:
                gscore[k^(1<<i)] += c  

        c = -(1<<50)
        for l in iter_subset(k):
            c = max(c, gscore[l^(1<<i)] + dp[k^l])
        dp[k^(1<<i)] = c
        
#print(gscore)        
#print(dp)        
print(dp[-1])        
        

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

int findSumOfDigits(int n){
  int sum = 0;
  while(n>0){
    sum += n % 10;
    n /=10;
  }
  return sum;
}

int main(){
  int N;
  cin >> N;
  int total = 0;
  if (N% findSumOfDigits(N) == 0) cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <utility>
#define maxn 100005
using namespace std;
typedef long long ll;
int n,k;
char s[maxn];
int main(){
  scanf("%d%d",&n,&k);
  scanf("%s",s + 1);
  s[0] = '1';
  int cnt = 0,j = 0,ans = 0;
  for(int i = 1;i <= n;i++){
    while(j <= n && cnt <= k){
      if(s[j] == '1' && s[j + 1] == '0') cnt++;
      j++;
    }
    j--;
    if(s[j] == '1' && s[j + 1] == '0') cnt--;
    ans = max(ans,j - i + 1);
    if(s[i] == '0' && s[i + 1] == '1') cnt--;
  }
  printf("%d\n",ans);
  return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    ll n,m,sum=0,mul=1,i,j,k,flag =0,maxi=LONG_LONG_MIN,mini =LONG_LONG_MAX;
    double x,y;
    cin>>x;
    y=x/3;
    cout<<fixed<<setprecision(8)<<y*y*y<<endl;

}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repe(i, n) for (int i = 0; i <= (n); ++i)
#define repe1(i, n) for (int i = 0; i <= (n); ++i)
#define all(x) (x).begin(),(x).end()
#define pb(x) push_back(x)
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
typedef long long ll;
const int INF = 1e9;
const ll mod = 1000000007;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a * b / gcd(a, b);}

int main() {
  vector<int> n(4);
  rep(i,4) cin >> n.at(i);
  vector<int> v = {1,4,7,9};
  sort(n.begin(),n.end());
  if (n == v) {
    cout << "YES" <<"\n";
  } else {
    cout << "NO" << "\n";
  }
}


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

int main() {
	string s;
	cin >> s;
	if (s[0]==s[1]){
		cout << "No" << endl;
	}
	else if (s[0]==s[2]){
		cout << "No" << endl;
	}
	else if (s[1]==s[2]){
		cout << "No" << endl;
	}
	else {
		cout << "Yes" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int

using namespace std;

const ll MOD = (ll)1e9 + 7 ;
const int N = (int)1e5 + 10;

ll fast_power(ll a, ll b){
    ll res = 1;
    a %= MOD;
    while( b){
        if( b & 1) res = (res * a) % MOD;
        a *= a; a %= MOD;
        b >>= 1;
    }
    return res;
}

vector<ll> F(N), D(N);
 
void init(){
    F[0] = 1;
    for(ll i = 1; i < N; ++i){
        F[i] = (i * F[i - 1] )% MOD; 
    }
    D[N - 1] = fast_power(F[N - 1], MOD - 2); 
    for(ll i = N - 2; i >= 0; --i){
        D[i] = D[i + 1] * (i + 1) % MOD;
    }
}

ll NcR(ll N, ll R){
    if( N < 0 or R < 0 or N < R) return 0;
    return F[N] * D[R] % MOD * D[N - R] % MOD;
}


void solve(){
    ll n, k; cin >> n >> k;
    init();
    vector<int> a(n);
    for(int i = 0; i < n; ++i){
        cin >> a[i];
    }
    sort(a.begin(), a.end());
    ll ans = 0;
    for(ll i = 0; i < n; ++i){
        if( i >= k - 1){
            //to just add
            //add i c k - 1
            ans +=  ( NcR(i, k - 1) * a[i]%MOD ); ans %= MOD;
        }
        if ( i <= n - k ){
            //to subtract its contribution
            //subrtact n-1-i C k - 1
            ll tmp = NcR(n - 1- i, k - 1);
          	tmp *= a[i]; tmp %= MOD;
            ans += MOD; ans -= tmp; ans %= MOD;
        }
    }
    cout << ans << '\n';
    
}

int main(){
    ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr); 
    //int t; cin >> t;
    //while(t--)
        solve();
}

Measured memory_bytes: 2176
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using Graph = vector<vector<int>>;
const int INF = 1e9 + 1;
const ll LLINF = 1e18;
const int MOD = 1e9 + 7;

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

int main() {
    int N;
    cin >> N;
    int two = 0, four = 0;
    for(int i = 0; i < N; ++i) {
        int a;
        cin >> a;
        if(!(a % 4))
            four += 2;
        else if(!(a % 2))
            two++;
    }
    two = max(two - 1, 0);
    cout << (two + four >= N - 1 ? "Yes" : "No") << endl;
    return 0;
}


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

using vi = vector<int>;
using vll = vector<long long>;

constexpr long long mod = 1000000007;

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

bool _is_prime(long long int a) {
    if (a < 2)
        return false;
    else if (a == 2)
        return true;
    if (a % 2 == 0)
        return false;
    for (long long int i = 3; i * i <= a; i += 2) {
        if (a % i == 0)
            return false;
    }
    return true;
}

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

    int n;
    cin >> n;

    vi a(n), b(n);
    rep(i, n) cin >> a[i] >> b[i];

    int m = 1000000;
    vi cnt(m + 1, 0);
    for (int i = 3; i <= m; i += 2) {
        if (_is_prime(i) && _is_prime((i + 1) / 2)) {
            cnt[i] = cnt[i - 2] + 1;
        } else {
            cnt[i] = cnt[i - 2];
        }
    }

    rep(i, n) {
        int t = _is_prime(a[i]) && _is_prime((a[i] + 1) / 2) ? 1 : 0;

        if (a[i] == b[i]) {
            cout << t << endl;
        } else {
            cout << cnt[b[i]] - cnt[a[i]] + t << endl;
        }
    }
}


Measured memory_bytes: 5376
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <fstream>
#include <string>
#include <math.h>
#include <cstdlib>
#include <istream>
#include <sstream>
#include <cctype>
#define fore(i,x,y) for(long long i=x;i<y;i++)
typedef long long ll;
using namespace std;
int main()
{
	int x,y,xg=0,yg=0;
	cin >> x >> y;
	if(x==1||x==3||x==5||x==7||x==8||x==10||x==12)xg=1;
	if(x==4||x==6||x==9||x==11)xg=2;
	if(x==2)xg=3;
	if(y==1||y==3||y==5||y==7||y==8||y==10||y==12)yg=1;
	if(y==4||y==6||y==9||y==11)yg=2;
	if(y==2)yg=3;
	if(xg==yg){
		cout << "Yes" << endl;
	}
	else{
		cout << "No" << 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();//1行目入力
		int topping[] = new int[N];
		int BP = sc.nextInt();//2行目入力
		int OP = sc.nextInt();//2行目入力
		int BC = sc.nextInt();//3行目入力
		int price=0,calorie=0;
		int cpd=0;// calorie/dollar
		int great=0;//最高のcpd
		for(int i=0;i<N;i++){//トッピングカロリーを入力
			topping[i] = sc.nextInt();
		}
		Arrays.sort(topping);//カロリーを昇順に並び替える。
		price = BP;// 生地のみの値段を入れてしておく
		calorie = BC;//生地のみのカロリーを入れておく
		great= BP/BC;//生地のみを最高のピザと仮定。
		
		for(int i=N-1;i>=0;i--){//トッピングをカロリーの高い方から足す。
			price += OP;//全体の値段 
			calorie += topping[i];//全体のカロリー
			cpd = calorie/price;
			if(great<cpd){
				great = cpd;
			}
		}
		System.out.println(great);
	}
}

Measured memory_bytes: 18124
import java.util.Scanner;

class Main
{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		
		int n = scan.nextInt();
		
		int[][] a = new int[4][14];
		
		for(int i=0; i<4; i++){
			for(int j=0; j<=13; j++){
				a[i][j] = 0;}}
		
		for(int i=0; i<n; i++){
			String str = scan.next();
			int b = scan.nextInt();
			if(str.equals("S")){
				a[0][b] = 1;}
			else if(str.equals("H")){
				a[1][b] = 1;}
			else if(str.equals("C")){
				a[2][b] = 1;}
			else if(str.equals("D")){
				a[3][b] = 1;}}
			
		for(int i=0; i<4; i++){
			for(int j=1; j<=13; j++){
				if(a[i][j]==0){
					if(i==0){
						System.out.println("S "+j);}
					else if(i==1){
						System.out.println("H "+j);}
					else if(i==2){
						System.out.println("C "+j);}
					else if(i==3){
						System.out.println("D "+j);}}}}
	}
}


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

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    if (b < a) {
        int tmp = a;
        a = b;
        b = tmp;
    }
    if (c < b) {
        int tmp = b;
        b = c;
        c = tmp;
    }
    if (b < a) {
        int tmp = a;
        a = b;
        b = tmp;
    }
    cout << a << " " << b << " " << c << endl;
    return 0;
}



Measured memory_bytes: 3092
import sys

file_input = sys.stdin

t = int(file_input.readline())

for i in range(t):
    n, k = map(int, file_input.readline().split())
    if n <= k:
        file_input.readline()
        print(0)
    else:
        x_list = list(map(int, file_input.readline().split()))            
        distance = [d2 - d1 for d1, d2 in zip(x_list, x_list[1:])]
        if k == 1:
            print(sum(distance))
        else:
            distance.sort()
            print(sum(distance[:1-k]))

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

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

int main() {

int n;
cin >> n;
int d[n];
int sum = 0;

for(int i = 0; i < n; i++) cin >> d[i];

for(int i = 0; i < n; i++){
  for(int j = 1 + i; j < n; j++){
    sum += d[i] * d[j];
  }
}
cout << sum;
}

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

class Program
{
    #region Reader
    static string ReadStr => Console.ReadLine();
    static string[] ReadStrs => Console.ReadLine().Split(' ');
    static int ReadInt => Convert.ToInt32(Console.ReadLine().Trim());
    static int[] ReadInts => Console.ReadLine().Trim().Split(' ').Select(s => Convert.ToInt32(s)).ToArray();
    static long ReadLong => Convert.ToInt64(Console.ReadLine().Trim());
    static long[] ReadLongs => Console.ReadLine().Trim().Split(' ').Select(s => Convert.ToInt64(s)).ToArray();
    #endregion
    #region Method
    const int mod = 1000000007;
    public static int Mod(int a,int mod) { return a % mod >= 0 ? a % mod : a % mod + mod; }
    public static long Mod(long a, long mod = mod) { return a % mod >= 0 ? a % mod : a % mod + mod; }
    #endregion

    static void Main()
    {

        int N = ReadInt;
        int[] As = ReadInts;
        Array.Sort(As);

        int c = 0;
        for (int i = 0; i < N; i++)
        {
            for (int j = i+1; j < N; j++)
            {
                for (int k = j+1; k < N; k++)
                {
                    if (As[k] < As[i] + As[j])
                    {

                        if (As[k] != As[i] && As[i] != As[j]&&As[j]!=As[k])
                        {
                            c++;
                        }
                    }
                }
            }
        }
        WriteLine(c);
    }
}


Measured memory_bytes: 28368
#include<bits/stdc++.h>
#define INF 1e12

using namespace std;
typedef long long int ll;

int main()
{
   int N,M; cin >> N >> M;
   vector<vector<bool>>G(N,vector<bool>(N,false));
   for(int i = 0; i < M; i++)
   {
       int a,b; cin >> a >> b;
       G[a-1][b-1] = true;
       G[b-1][a-1] = true;
   }
   vector<int>V(N);
   for(int i = 0; i < N; i++) V[i] = i;
   int ans = 0;
   do
   {
       bool f = true;
       for(int i = 0; i < N-1; i++)
       {
           if(G[V[i]][V[i+1]] == false) f = false;
       }
       if(f) ans++;
   }while(next_permutation(V.begin()+1,V.end()));
   cout << ans << endl;
}

Measured memory_bytes: 3572
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0;i<(n);i++)
using namespace std;
typedef long long ll; //long longをllとして簡略

int main(){
    int a,b,sum;
    cin >> a >> b;
    if(!(1<=a && a<=100)){return -1;}
    if(!(1<=a && a<=100000)){return -1;}
    sum = a*500;
    if(b<=sum){printf("Yes");}
    else {printf("No");}
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cctype>
#include <cstdlib>
#include <string>
#include <memory.h>
#include <cmath>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
typedef long long ll;
typedef pair<int, int> P;
typedef pair<int,P> PP;
const int INF = 1 << 29;

int w, h;
int memo[110][110];
int field[110][110];

int main(){
  while(cin >> w >> h && (w || h)){
    int sx, sy, gx, gy;
    fill(&memo[0][0], &memo[109][109] + 1, INF);
    memset(field, -1, sizeof(field));
    int l = 0;
    rep(i, h){
      rep(j, w){
	char ch;
	cin >> ch;
	if(ch == 'S'){
	  sx = j;
	  sy = i;
	}else if(ch == 'G'){
	  gx = j;
	  gy = i;
	}else if( ch == '.'){
	  field[i][j] = -1;
	}else{
	  cin.putback(ch);
	  cin >> field[i][j];
	  l = max(field[i][j], l);
	}
      }
    }

    
    field[sy][sx] = 0;
    field[gy][gx] = l + 1;
    
    priority_queue<PP, vector<PP>, greater<PP> > que;
    que.push(PP(0, P(sy, sx)));
    memo[sy][sx] = 0;

    while(!que.empty()){
      PP pp = que.top();
      que.pop();
      int x = pp.second.second;
      int y = pp.second.first;
      int cost = pp.first;
      int nxt = field[y][x] + 1;
      
      rep(i, h)rep(j, w){
	if(field[i][j] == nxt){
	  int dis = abs(i - y) + abs(j - x);
	  if(memo[i][j] > cost + dis){
	    memo[i][j] = cost + dis;
	    que.push(PP(memo[i][j], P(i, j)));
	  }
	}
      }
    }
    cout << memo[gy][gx] << endl; 
  }
  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vl;
#define rep(i, n) for(ll i = 0;i < n;i++)
#define all(i) i.begin(), i.end()
template<class T, class U> void cmax(T& a, U b) { if (a<b) a = b; }
template<class T, class U> void cmin(T& a, U b) { if (a>b) a = b; }

vector<int> r(3);
ll ans = 0;

void a(int cnt, int n) {
  if (cnt == 2) {
    if (n % r[cnt] == 0) ans++;
  } else {
    for (int i = n/r[cnt]; i >= 0; i--) {
      a(cnt+1, n-r[cnt]*i);
    }
  }
}

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

  int n;
  cin >> r[0] >> r[1] >> r[2] >> n;

  a(0, n);

  cout << ans << endl;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil
from operator import itemgetter
from copy import deepcopy
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
inf = 10**17
mod = 10**9 + 7

s=input().rstrip()
dif=[]
for i in range(len(s)-2):
    nm=int(s[i:i+3])
    dif.append(abs(nm-753))
dif.sort()
print(dif[0])
    

Measured memory_bytes: 3436
// AOJ 0648 Art Exhibition
// 2018.3.29 bal4u

#include <stdio.h>
#include <stdlib.h>

//#define getchar_unlocked()  getchar()
int in()	/* 整数値の入力 */
{
	int n = 0, c = getchar_unlocked();
	do n = 10*n + (c & 0xf), c = getchar_unlocked(); while (c >= '0');
	return n;
}

long long big()		/* long long 整数値の入力 */
{
	long long n = 0, c = getchar_unlocked();
	do n = 10*n + (c & 0xf), c = getchar_unlocked(); while (c >= '0');
	return n;
}

#define INF 0x1010101010101010LL
typedef struct { long long a; int b; } T;
T tbl[500002];

int cmp(T *a, T *b) {
	if (a->a == b->a) return a->b - b->b;
	if (a->a < b->a) return -1;
	return 1;
}

int main()
{
	int N, i;
	long long sp, sn, t, min, max;

	N = in();
	for (i = 1; i <= N; i++) tbl[i].a = big(), tbl[i].b = in();
	qsort(tbl+1, N, sizeof(T), cmp);

	min = INF, max = -INF, sp = 0;
	for (i = 1; i <= N; i++) {
		t = sp - tbl[i].a; if (t < min) min = t;
		sn = sp + tbl[i].b;
		t = sn - tbl[i].a - min; if (t > max) max = t;
		sp = sn;
	}
	printf("%lld\n", max);
	return 0;
}



Measured memory_bytes: 17176
#include <iostream>
#include <stdio.h>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <map>
#include <set>
#include <math.h>
#include <queue>
#define rep(i,n) for (int i = 0; i < (n); ++i)
typedef long long ll;
using namespace std;

vector<pair<ll, ll> > prime_factorize(ll N) {
    vector<pair<ll, ll> > res;
    for (ll a = 2; a * a <= N; ++a) {
        if (N % a != 0) continue;
        ll ex = 0; // 指数

        // 割れる限り割り続ける
        while (N % a == 0) {
            ++ex;
            N /= a;
        }

        // その結果を push
        res.push_back(make_pair(a, ex));
    }

    // 最後に残った数について
    if (N != 1) res.push_back(make_pair(N, 1));
    return res;
}

int main() {
    ll N;
    cin >> N;
    const auto &res = prime_factorize(N);
    //cout << N << ":";
    /*for (auto p : res) {
        for (int i = 0; i < p.second; ++i) cout << " " << p.first;
    }*/
    int ans=0;
    for (auto p : res) {
        int x = p.second;
        int b = 1;
        while (b <= x) {
            x -= b;
            b++;
            ++ans;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3200
from fractions import gcd

A, B, C, D = map(int, input().split())

c = (B // C) - ((A-1) // C)
d = (B // D) - ((A-1) // D)

CD = C * D // gcd(C, D)
cd = (B // (CD)) - ((A-1) // (CD))

print((B - A + 1) - (c + d - cd))

Measured memory_bytes: 5048
#include <iostream>
#include <vector>
#include <algorithm>
#define rep(i, n) for(i = 0; i < n; i++)
using namespace std;

////drkenさんの記事より
inline long long mod(long long a, long long m) {
    return (a % m + m) % m;
}

long long extGcd(long long a, long long b, long long &p, long long &q) {  
    if (b == 0) { p = 1; q = 0; return a; }  
    long long d = extGcd(b, a%b, q, p);  
    q -= a/b * p;  
    return d;  
}

// 中国剰余定理
// リターン値を (r, m) とすると解は x ≡ r (mod. m)
// 解なしの場合は (0, -1) をリターン
pair<long long, long long> ChineseRem(const vector<long long> &b, const vector<long long> &m) {
  long long r = 0, M = 1;
  for (int i = 0; i < (int)b.size(); ++i) {
    long long p, q;
    long long d = extGcd(M, m[i], p, q); // p is inv of M/d (mod. m[i]/d)
    if ((b[i] - r) % d != 0) return make_pair(0, -1);
    long long tmp = (b[i] - r) / d * p % (m[i]/d);
    r += M * tmp;
    M *= m[i]/d;
  }
  return make_pair(mod(r, M), M);
}

//
int n;
int p[200];
int q[200];

signed main() {
	int i, j;
	
	cin >> n;
	rep(i, n) cin >> p[i];
	rep(i, n) cin >> q[i];
	
	vector<long long> b;
	vector<long long> m;
	
	rep(i, n) {
		int x = p[i];
		rep(j, n + 1) {
			if (x == i + 1) break;
			x = q[x - 1];
		}
		if (j == n + 1) { cout << -1 << endl; return 0; }
		
		b.push_back(j);
		
		x = p[i];
		rep(j, n + 1) {
			x = q[x - 1];
			if (x == p[i]) break;
		}
		m.push_back(j + 1);
	}
	
	//rep(i, n) cout << b[i] << ", " << m[i] << endl;
	
	pair<long long, long long> ans = ChineseRem(b, m);
	if (ans.second == -1) { cout << -1 << endl; }
	else { cout << ans.first << endl; }
	return 0;
}


Measured memory_bytes: 3164
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        int M = sc.nextInt();

        long[][] list = new long[N][2];


        for (int i=0; i<N; i++) {
            list[i][0] = sc.nextInt();
            list[i][1] = sc.nextInt();
        }

        Arrays.sort(list, (a, b) -> Long.compare(a[0], b[0]));

        long result = 0;
        for (int i=0; i<N; i++) {
            if (M>list[i][1]) {
                result += list[i][0] * list[i][1];
                M -= list[i][1];
            } else {
                result += list[i][0] * M;
                break;
            }
        }

        System.out.println(result);
    }
}

Measured memory_bytes: 95048
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
#define mp make_pair

template<class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }

const int LIM=10010;
int sosu[LIM];
	
int main() {
	int i,j;
	sosu[0]=1;
	sosu[1]=1;
	for(i=0;i<LIM;i++){
		if(sosu[i])continue;
		for(j=i*2;j<LIM;j+=i){
			sosu[j]=1;
		}
	}
	int n;
	while(cin>>n){
		int k,res=0;
		for(k=1;k<=n;k++){
			if(sosu[k]+sosu[n-k+1]==0)res++;
		}
		cout<<res<<endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include <iostream>

using namespace std;

int main(void)
{
    long long A, B;
    cin >> A >> B;
    long long ans = 0;
    if (A % 2)
    {
        if (B % 2)
        {
            ans = A ^ (((B - A) / 2) % 2);
        }
        else
        {
            if (B - A >= 3) ans = (A ^ B) ^ (((B - A - 1) / 2) % 2);
            else ans = A ^ B;
        }
    }
    else
    {
        if (B % 2)
        {
            ans = ((B - A + 1)  / 2) % 2;
        }
        else
        {
            ans = B ^ ((B - A) / 2 )% 2;
        }
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;

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

#define EPS (1e-8)
#define EQ(a,b) (abs((a)-(b)) < EPS)
#define EQV(a,b) ( EQ(a.real(), b.real()) && EQ(a.imag(), b.imag()) )

typedef complex<double> p;

double cross(p a, p b) {
	return (a.real() * b.imag() - a.imag() * b.real());
}

int main() {
	while (true) {
		double x[4], y[4];
		if (scanf("%lf %lf %lf %lf %lf %lf %lf %lf",
			&x[0], &y[0], &x[1], &y[1], &x[2], &y[2], &x[3], &y[3]) == EOF) break;
		p point[4];
		REP(i, 4) point[i] = p(x[i], y[i]);
		
		int cnt[2] = {};
		REP(i, 3) {
			int now = (i + 1) % 3;
			p v[2];
			v[0] = point[now] - point[i];
			v[1] = point[3] - point[i];
			
			if (cross(v[0], v[1]) < -EPS) cnt[0]++;
			else cnt[1]++;
		}
		
		if (cnt[0] == 3 || cnt[1] == 3) puts("YES");
		else puts("NO");
	}
	return 0;
}

Measured memory_bytes: 1196
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func getNextUint64(scanner *bufio.Scanner) uint64 {
	i, _ := strconv.ParseUint(getNextString(scanner), 10, 64)
	return i
}

func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}

func main() {
	fp := os.Stdin
	wfp := os.Stdout

	if os.Getenv("MASPY") == "ますピ" {
		fp, _ = os.Open(os.Getenv("BEET_THE_HARMONY_OF_PERFECT"))
	}
	if os.Getenv("MASPYPY") == "ますピッピ" {
		wfp, _ = os.Create(os.Getenv("NGTKANA_IS_GENIUS10"))
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(wfp)

	n := getNextInt(scanner)
	s := getNextString(scanner)

	counter := make([][10]int, n+1)
	ll := make([]int, 10)
	rr := make([]int, 10)
	for i := 0; i < 10; i++ {
		ll[i] = n
	}
	for i := 0; i < n; i++ {
		for j := 0; j < 10; j++ {
			counter[i+1][j] = counter[i][j]
		}
		counter[i+1][s[i]-'0']++
		rr[s[i]-'0'] = i
	}
	for i := n - 1; i >= 0; i-- {
		ll[s[i]-'0'] = i
	}

	ans := 0
	for l := 0; l < 10; l++ {
		for r := 0; r < 10; r++ {
			for i := 0; i < 10 && rr[r] > 1 && ll[l] < n-2 && ll[l] < rr[r]; i++ {
				if counter[rr[r]][i] > counter[ll[l]+1][i] {
					ans++
				}
			}
		}
	}

	fmt.Println(ans)
	writer.Flush()
}


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

int main(){
  /*
  int n, i, j;
  cin >> n;
  vector<int> A(n);
  rep(i, n) cin >> A[i];
  */
 int64_t a, b, c, g, d, e;
 cin >> a >> b >> c;
 d = c-a-b;
 e = d*d;
 g = 4*a*b;

 if(d<=0) cout << "No" << endl;
 else if(g < e) cout << "Yes" << endl;
 else cout << "No" << endl;



}

Measured memory_bytes: 256
// JAI SHREE RAM
typedef long long int ll;
typedef unsigned long long int ull;
#define fast  ios_base::sync_with_stdio(false); cin.tie(NULL);
#define FOR(i,n) for(int i=0;i<n;i++)
#define MOD 1000000007
#define sz(a) int((a).size())
#define forn(i, n) for (int i = 0; i < (n); ++i)
#define fore(i, l, r) for (int i = int(l); i < int(r); ++i)
#define loop for(int i=0;i<n;i++)
#define max3(a,b,c) max(a,max(b,c))
#define max4(a,b,c,d) max3(a,max(b,c),d)
#define max5(a,b,c,d,e) max4(a,max(b,c),d,e)
#define min3(a,b,c) min(a,min(b,c))
#define min4(a,b,c,d) min3(a,min(b,c),d)
#define min5(a,b,c,d,e) min4(a,min(b,c),d,e)
#define sec second
#define fir first
// #define all(a) (a).begin(),(a).end()
#define vec vector<int>
#define M_PI           3.14159265358979323846  /* pi */
#define pb push_back
#define pii pair<int,int>
#include<bits/stdc++.h>
#include<cmath>
using namespace std;
int main()
{


	ll n, k; cin >> n >> k;
	ll v[n];
	FOR(i, n)
	{
		cin >> v[i];
	}
	ll dp[n];
	memset(dp, 10, sizeof(dp));
	//cout<<v[1]<<" "<<v[0]<<endl;
	dp[0] = 0;
	// for (int i = 1; i < k; ++i)
	// 	dp[i] = abs(v[i] - v[0]);
	dp[1] = abs(v[0] - v[1]);

	//cout << dp[0] << endl << dp[1] << endl;
	//dp[1]=abs(v[1]-v[0]);
	//cout<<dp[1]<<endl;
	//dp[2]=min(abs(v[2]-v[1])+dp[1],abs(v[2]-v[0]));
	ll m = k;
	for (ll i = 2 ; i < n; ++i)
	{
		for (ll j = i - 1; j >= 0 && (i - j) <= k; --j)
		{
			dp[i] = min(dp[i], abs(v[i] - v[j]) + dp[j]);
		}
	//	cout << dp[i] << endl;

	}
	cout << dp[n - 1] << endl;

}

Measured memory_bytes: 1792
from collections import deque
k = int(input())
q = deque()
def main():
    for i in range(1, 10):
        q.append(i)
    for _ in range(k):
        x = q.popleft()
        if x % 10 != 0:
            q.append(x * 10 + x%10 - 1)
        q.append(x * 10 + x%10)
        if x % 10 != 9:
            q.append(x * 10 + x%10 + 1)
    print(x)

        
if __name__ == '__main__':
    main()

Measured memory_bytes: 18800
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<string.h>
#include<math.h>
#include<iomanip>
using namespace std;
 
int main(){
	double R;
	cin >> R;
	cout << 2*R*M_PI << endl;
	return 0;
}

Measured memory_bytes: 3780
#include<iostream>
#include<algorithm>
#include<cstring>
#include<iomanip>
#include<cstdio>
using namespace std;
typedef long long ll;
const ll inf=0x3f3f3f3f;
int main()
{
	int n,t;
	cin>>n;
	t=n%10;
	if(t==2||t==4||t==5||t==7||t==9)
	cout<<"hon";
	else if(t==0||t==1||t==6||t==8)
	cout<<"pon";
	else
	cout<<"bon";
	return 0;
}

Measured memory_bytes: 3612
/**************erik****************/
#include<bits/stdc++.h>
#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long  int ll;
typedef unsigned long long int ull;
//map<ll,ll> mp1;
//set<int> s1;
//set<int>::iterator it;
#define maxm(a,b,c)  max(a,max(c,b))
#define minm(a,b,c)  min(a,min(c,b))
#define f(i,n)  for(ll i=0;i<n;i++)
#define rf(i,n) for(ll i=n-1;i>=0;i--)

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(); cout.tie();
    ll a=0,b=0,i,j,x;
    cin>>x ;
    for(i=1;i<=1000;++i){
        for(j=-1000;j<i;++j){
            if(pow(i,5)-pow(j,5)==x) a = i , b = j ;
        }
    }    
    cout << a << " " << b << "\n" ;
    return 0 ;

}

Measured memory_bytes: 4080
#include <iostream>

int main() {
    int h, n;
    std::cin >> h >> n;
    int a[n];
    for(int i = 0; i < n; i++) {
        std::cin >> a[i];
    }

    int sum = 0;
    for(int i = 0; i < n; i++) {
        sum += a[i];
    }
    if(sum >= h) {
        std::cout << "Yes" << std::endl;
    } else {
        std::cout << "No" << std::endl;
    }
}


Measured memory_bytes: 640
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<string>
#include<vector>
#include<stack>
#include<bitset>
#include<cstdlib>
#include<cmath>
#include<set>
#include<list>
#include<deque>
#include<map>
#include<queue>
using namespace std;
typedef long long ll;
const double PI = acos(-1.0);
const double eps = 1e-6;
const int INF = 1000000000;
const int mod = 1e9+7;
const int maxn = 2e5+5;
ll c[maxn];
long long quickpow(long long a, long long b) {
    if (b < 0) return 0;
    long long ret = 1;
    a %= mod;
    while(b) {
        if (b & 1) ret = (ret * a) % mod;
        b >>= 1;
        a = (a * a) % mod;
    }
    return ret;
}
long long inv(long long a) {
    return quickpow(a, mod - 2);
}
int main() {
	ll n,a,b;
	cin>>n>>a>>b;
	c[1] = n;
	//cout<<1111<<endl;
	for(ll i=2;i<=max(a,b);i++){
		c[i] = (c[i-1]*(n-i+1)%mod)*inv(i);
		c[i]%=mod;
	}
	ll sum = quickpow(2,n)-1;
//	cout<<sum<<endl;
	
	cout<<(sum-c[a]-c[b]+mod+mod)%mod<<endl;
    return 0;
}



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

	public static void main(String[] args) {		
		Scanner scanner=new Scanner(System.in);
		String first=scanner.nextLine();
		String middle=String.valueOf(first.length()-2);
		System.out.println(first.charAt(0)+middle+first.charAt(first.length()-1));
	}

}

Measured memory_bytes: 23380
#include <bits/stdc++.h>
#define ll long long

using namespace std;
ll n;

int main()
{
    cin >> n;
    for(ll i = -2000;i<=2000;i++){
        for(ll j = -2000;j<=2000;j++){
            ll a = i * i * i * i * i;
            ll b = j * j * j * j * j;
            if(a - b == n){
                cout << i << " " << j << '\n';
                exit(0);
            }
        }
    }
    return 0;
}


Measured memory_bytes: 3600
#include <stdio.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <queue>

using namespace std;

#define rep(i,x) for(int i=0;i<x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define pb(x) push_back(x)
#define int long long

signed main(void) {
  int A, B, T;
  cin >> A >> B >> T;

  int ans;
  ans = (T/A) * B;

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
// Problem : B - Thin
// Contest : AtCoder - AtCoder Beginner Contest 049
// URL : https://atcoder.jp/contests/abc049/tasks/abc049_b
// Memory Limit : 256 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>

#define spc ' '
#define endl '\n'

using namespace std;


int main(){
	ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int h, w;
	cin >> h >> w;
	vector<vector<char>> a(h, vector<char> (w)), b(2*h,vector<char> (w));
	for(auto &it:a){
	    for(auto &it2:it){
	        cin >> it2;
	    }
	}
	for(int i = 0; i <2*h; i++){
	    for(int j=0; j<w; j++){
	        b[i][j] = a[(i+2)/2 -1][j];
	    }
	}
	for(vector<char> s:b){
	    for(char c:s){
	        cout << c;
	    }
	    cout << endl;
	}
	return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<string>
#include<algorithm>
#include<math.h>
#include<queue>
#include<set>
#include<map>
#include<random>
#include<functional>
#include<utility>

typedef long long ll;

#define rep(i,n) for(int i=0; i<n; i++)
#define pb push_back
#define P pair<int, int>
#define PLI pair<ll, int>
#define PLL pair<ll, ll>
#define VI vector<int>
#define VII vector<VI>

using namespace std;


const ll INF = 1e18;

struct edge {
	int to;
	ll co;
	edge(int t, ll c):to(t), co(c){}
	bool operator<(const edge e) const {
		return co > e.co;
	}
};
int N, M;
vector<edge> G[100005];
ll cost[100005];
int main() {
	cin >> N >> M;
	rep(i, M) {
		int l, r, c;
		cin >> l >> r >> c;
		l--; r--;
		G[l].emplace_back(r, c);
	}
	rep(i, N - 1) {
		G[i + 1].emplace_back(i, 0);
	}

	rep(i, N) cost[i] = INF;
	cost[0] = 0;
	priority_queue<edge> pq;
	pq.emplace(0, 0);
	while (!pq.empty())
	{
		edge now = pq.top(); pq.pop();
		if (cost[now.to] < now.co) continue;
		for (auto e : G[now.to]) {
			if (cost[e.to] > cost[now.to] + e.co) {
				cost[e.to] = cost[now.to] + e.co;
				pq.emplace(e.to, cost[e.to]);
			}
		}
	}
	if (cost[N - 1] == INF) cout << -1 << endl;
	else cout << cost[N - 1] << endl;

	return 0;
}

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

#define ll long long

ll int dp[105][100005];
int val[105];
int wgt[105];


ll int kil(int idx, int weight)
{
  if(weight < 0)
    return -1e17;

  if(idx == 0)
    return 0;

  if(dp[idx][weight] != -1)
    return dp[idx][weight];

  dp[idx][weight] = max(dp[idx][weight], kil(idx-1, weight));
  dp[idx][weight] = max(dp[idx][weight], kil(idx-1, weight - wgt[idx]) + val[idx]);

  return dp[idx][weight];
}

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

  for(int i=1;i<=n;i++)
    cin>>wgt[i]>>val[i];

  // for(int i=1;i<=n;i++)
  // {
  //     dp[i][wgt[i]] = val[i];
  //     for(int j=1;j<=w;j++)
  //     {
  //       dp[i][j] = max(dp[i][j], dp[i-1][j]);
  //       if(j - wgt[i] > 0 && dp[i-1][j-wgt[i]] > 0)
  //         dp[i][j] = max(dp[i][j], dp[i-1][j-wgt[i]] + val[i]);
  //
  //       dp[i][j] = max(dp[i][j], dp[i][j-1]);
  //     }
  // }
  //
  // cout<<dp[n][w]<<endl;

  memset(dp, -1, sizeof dp);
  cout<<kil(n, w)<<endl;

  return 0;
}


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

using ll = long long;
#define rep(i, j) for(int i=0; i < (int)(j); i++)
#define repeat(i, j, k) for(int i = (j); i < (int)(k); i++)

template<class T> bool set_min(T &a, const T &b) { return a > b  ? a = b, true : false; }

const int INF = 1 << 30;

class Solver {
  public:
    bool solve() {
        ll N; cin >> N;
        int ans = INF;
        repeat(i, 1, sqrt(N) + 1) {
            if(N % i == 0) {
                set_min(ans, (int)log10(N / i) + 1);
            }
        }
        cout << ans << endl;
        return 0;
    }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    Solver s;
    s.solve();
    return 0;
}


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

int main()
{
  int A, B;
  cin >> A >> B;
  int count = 0;
  for (int i = A; i <= B; i++)
  {
    int o = i % 10, p = i / 10000 % 10;
    int s = i / 10 % 10, t = i / 1000 % 10;
    if (o == p && s == t)
      count++;
  }
  cout << count << endl;
}
      

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define range(a) (a).begin(),(a).end()
#define print(A,n) rep(i,0,n){cout<<(i ? " ":"")<<A[i];}cout<<endl;
#define pprint(A,m,n) rep(j,0,m){print(A[j],n);}
const long mod=1e9+7;
const int size=1e5;
const int INF=1e9;
int main(){
	int n,m;cin>>n>>m;
	long X[n],Y[m];
	rep(i,0,n) cin>>X[i];
	rep(i,0,m) cin>>Y[i];
	long a=0,b=0;
	rep(i,0,n){ a+=(n-1-2*i)*X[i];a%=mod; }
	rep(i,0,m){ b+=(m-1-2*i)*Y[i];b%=mod; }
	long ans=(a*b)%mod;
	cout<<(ans+mod)%mod<<endl;
}

Measured memory_bytes: 1792
//verma_ankit484

#include<bits/stdc++.h>
typedef long long ll;

using namespace std;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	#ifdef AV
	freopen("int.txt", "r", stdin);
	#endif
	ll n, k;
	cin >> n >> k;
	vector<ll> vc(n+1, 0);
	for(ll i = 1; i <= n; i++) {
		cin >> vc[i];
	}
	ll sum = 0;
	ll dp[n+1] ;
	for(ll i = 0; i < n+1; i++) {
		dp[i] = INT_MAX;
	}
	dp[1] = 0;
	dp[2] = abs(vc[1]-vc[2]);
	for(ll i = 3; i <= n; i++) {
		for(ll j = 1; j <= min(k, i); j++) {
			dp[i] = min(dp[i], abs(vc[i]-vc[i-j])+dp[i-j]);
		}
	}
	cout << dp[n] << '\n';
	return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define all(x) x.begin(),x.end()
#define pll pair<ll,ll>
#define mp make_pair
#define bp __builtin_popcountll
#define MOD  998244353
const int N = 200005;
#define FAST ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);srand(time(NULL));
vector<ll> v[N];
ll ans[N],a[N];
vector<int> tail(N,0);
ll length = 1;
int CeilIndex(int l, int r, int key) 
{ 
    while (r - l > 1) { 
        int m = l + (r - l) / 2; 
        if (tail[m] >= key) 
            r = m; 
        else
            l = m; 
    } 
  
    return r; 
} 
void dfs(ll id,ll p)
{
     ll which,data[3],oo;
     if(id==1)
     {
          tail[0] = a[1];
          ans[1] = length;
     }
     else
     {
          if(a[id]<tail[0])   data[0] = tail[0],tail[0] = a[id],which=0;
          else if(a[id]>tail[length-1])
          {
               which = 1;
               data[1] = tail[length+1];
               tail[length++] = a[id];
          }
          else
          {
               ll id1 = CeilIndex(-1,length-1,a[id]);
               oo = id1;
               data[2] = tail[id1];
               tail[id1] = a[id];
               which = 2;
          }
          ans[id] = length;
     }
     for(auto X:v[id])
     {
          if(X!=p)
          {
               dfs(X,id);
          }
     }
     if(id==1)    return;
     else
     {
          if(which==0)
          {
               tail[0] = data[0];
          }
          else if(which==1)
          {
               tail[length] = data[1];
               length--;
          }
          else
          {
               tail[oo] = data[2];
          }
     }

}
void solve()
{
     ll n;
     cin >> n;
     for(ll i=1;i<=n;i++)    cin >> a[i];
     for(ll i=0,x,y;i<n-1;i++)
     {
          cin >> x >> y;
          v[x].pb(y);
          v[y].pb(x);
     }
     dfs(1,0);
     for(ll i=1;i<=n;i++)    cout<<ans[i]<<"\n";  
}

int main()
{
     FAST;
     ll t = 1;
   //  cin >> t; 
     for(ll i=1;i<=t;i++)
     {
         // cout<<"Case #"<<i<<": ";
          solve();
     }
}

Measured memory_bytes: 35268
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

#define SIZE 1000

int stack[SIZE];
int pos = 0;

int empty()
{
	return pos == SIZE;
}

void push(int x)
{
	if (empty())
		printf("ERROR\n");
	else
		stack[pos++] = x;
}

int pop()
{
	int x;

	if (pos == 0)
	{
		printf("ERROR\n");
		exit(1);
	}
	else
		x = stack[--pos];

	return x;
}

void swap(int *a, int *b)
{
	int tmp = *a;
	*a = *b;
	*b = tmp;
}

void print(int A[], int N)
{
	int i;
	for (i = 0; i < N; i++)
	{
		if (i == N - 1)
			printf("%d\n", A[i]);
		else
			printf("%d ", A[i]);
	}
}

int binary_search(int A[], int N, int key)
{
	int left, right, middle;

	left = 0, right = N - 1;

	while (left <= right)
	{
		middle = (left + right) / 2;

		if (A[middle] == key)
			return 1;
		else if (A[middle] < key)
			left = middle + 1;
		else
			right = middle - 1;
	}

	return 0;
}

int dfs(int A[], int n, int k, int num, int sum)
{
	if (k == n)
	{
		if (num == sum)
			return 1;
		else 
			return 0;
	}
	else
	{
		if (dfs(A, n, k + 1, num + A[k], sum))
			return 1;
		if (dfs(A, n, k + 1, num, sum))
			return 1;
	}
	return 0;
}

int fibo(n)
{
	double a = (1 + sqrt(5)) / 2;
	double b = (1 - sqrt(5)) / 2;
	return (int)((pow(a, n) - pow(b, n))/sqrt(5));
}

int main()
{
	char T[2000], P[2000];

	scanf("%s%s", T, P);
	
	int i, j;
	int shift = 0;
	int flag = 0;

	for (i = 0; i < strlen(T); i++)
	{
		for (j = 0; j < strlen(P); j++)
		{
			if (T[i + shift] == P[j])
				shift++;
			else
			{
				flag = 1;
				break;
			}
		}
		if (flag == 1)
			flag = 0;
		else
			printf("%d\n", i);
		shift = 0;
	}

	return 0;
}


Measured memory_bytes: 2104