akhauriyash/Code-Regression huggingface dataset:
A, B = [int(num) for num in input().split()]

count = 0
for num in range(A, B+1):
  target = str(num)
  target_list = list(target)
  target_list_reversed = reversed(target_list)
  target_list_reversed = list(target_list_reversed)
  
  if target_list == target_list_reversed:
    count = count + 1
print(count)

Measured memory_bytes: 3060
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
typedef  unsigned long long int ull;
typedef pair<ll,ll> P;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
//const ll mod=998244353;
const ll mod=1000000007;
//ios_base::sync_with_stdio(false);
//cin.tie(NULL);
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
int main(){
int n,m;
cin>>n>>m;
if(n==m)cout<<"Yes"<<endl;
else cout<<"No"<<endl;
}


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

const int MOD=1000000007;
const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;
ll gcd(ll x, ll y){
  if(y==0) return x;
  else return gcd(y, x%y);
}
ll lcm(ll x,ll y){
  ll g=gcd(x,y);
  return x/g*y;
}
 
int main() {
  int n ; 
  cin>>n;
  
  int m=0;
  int z=0;
  ll ans=0;
  vector<ll>vec;
  rep(i,n){
    ll a; cin>>a;
    if(a<0){
      m++;
    }
    if(a==0)z++;
    ans+=abs(a);
    vec.push_back(abs(a));
  }
  if(m%2==0 ||z>0) cout<<ans<<endl;
  else{
    sort(vec.begin(),vec.end());
    ans-=2*vec[0];
    cout<<ans<<endl;
  }
  
  
}
  



Measured memory_bytes: 1400
#include<cmath>
#include<bits/stdc++.h>
#define ABS(a) ((a)>0? (a):(-(a)))
#define MAX(a,b) (a>b? a:b)
#define MIN(a,b) (a>b? b:a)
#define rep(i,n) for(lint i=0;i<(lint)(n);i++)
#define repr(i,n) for(lint i=(lint)(n);i>0;--i)
#define reps(i,a,b) for(lint i=a;i<=(lint)(b);i++)
typedef long long lint;
typedef long double ld;
using namespace std;
const ld PI = acos(-1.0);

int main(){
    lint A, B, Q;
    cin >> A >> B >> Q;
    vector<lint> s(A+2), t(B+2), x(Q);
    rep(i,A) cin >> s[i+1]; // 神社
    rep(i,B) cin >> t[i+1]; // 寺
    rep(i,Q) cin >> x[i]; // 初期条件
    s[0] = 0; t[0] = 0; // 左端
    s[A+1] = numeric_limits<lint>::infinity();
    t[B+1] = numeric_limits<lint>::infinity(); // 右端
    lint left, right, mid;
    lint sl, sr, tl, tr;
    lint dis;
    rep(i,Q) {
        left = 0;
        right = A+1;
        while(1){
            mid = left + (right-left)/2;
            if(left==right) break;
            if(x[i]>s[mid]) left = mid;
            if(x[i]<s[mid]) right = mid;
            if(right-left==1) break;
        }
        sl = left;
        sr = right;
        left = 0;
        right = B+1;
        while(1){
            mid = left + (right-left)/2;
            if(left==right) break;
            if(x[i]>t[mid]) left = mid;
            if(x[i]<t[mid]) right = mid;
            if(right-left==1) break;
        }
        tl = left;
        tr = right;
        //
        dis = ABS(s[sr]-x[i])+ABS(t[tr]-s[sr]);
        // cout << "1:"<< ABS(s[sr]-x[i])+ABS(t[tr]-s[sr]) << endl;
        if(tl!=0) {
            dis = MIN(dis, ABS(s[sr]-x[i])+ABS(t[tl]-s[sr]));
            // cout << "2:" << MIN(dis, ABS(s[sr]-x[i])+ABS(t[tl]-s[sr])) << endl;
        }
        if(sl!=0) {
            dis = MIN(dis, ABS(s[sl]-x[i])+ABS(t[tr]-s[sl]));
            // cout << "3:" << ABS(s[sl]-x[i])+ABS(t[tr]-s[sl]) << endl;
        }
        if(sl!=0&&tl!=0) {
            dis = MIN(dis, ABS(s[sl]-x[i])+ABS(t[tl]-s[sl]));
            // cout << "4:" << ABS(s[sl]-x[i])+ABS(t[tl]-s[sl]) << endl;
        }
        //
        dis = MIN(dis, ABS(s[sr]-t[tr])+ABS(x[i]-t[tr]));
        // cout << "5:"<<  ABS(s[sr]-t[tr])+ABS(x[i]-t[tr]) << endl;
        if(tl!=0) {
            dis = MIN(dis, ABS(s[sr]-t[tl])+ABS(x[i]-t[tl]));
            // cout << "6:"<<  ABS(s[sr]-t[tl])+ABS(x[i]-t[tl]) << endl;
        }
        if(sl!=0) {
            dis = MIN(dis, ABS(s[sl]-t[tr])+ABS(x[i]-t[tr]));
            // cout << "7:"<<  ABS(s[sl]-t[tr])+ABS(x[i]-t[tr]) << endl;
        }
        if(sl!=0&&tl!=0) {
            dis = MIN(dis, ABS(s[sl]-t[tl])+ABS(x[i]-t[tl]));
            // cout << "8:"<<  ABS(s[sl]-t[tl])+ABS(x[i]-t[tl]) << endl;
        }
        // cout << "i=" << i;
        // cout << " dis=" << dis;
        // cout <<  " sl:" << sl << " sr:" << sr;
        // cout <<  " tl:" << tl << " tr:" << tr << endl;
        cout << dis << endl;
    }
	return 0;
}

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

int main () {
    int n;
    cin >> n;
    set<string> st;
    rep(i,n) {
        string s;
        cin >> s;
        st.insert(s);
    }
    cout << st.size() << endl;
}

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

using namespace std;

int main(){
	bool sosuu[1000011];
	bool dp[1000011];
	
	while(1){
		for(int i=0;i<=1000000;i++){
			sosuu[i]=0;
			dp[i]=0;
		}
		for(int i=2;i<=500000;i++){
			if(sosuu[i]==0){
				for(int j=i;j<=1000000;j+=i){
					sosuu[j]=1;
				}
				sosuu[i]=0;
			}
		}
		sosuu[0]=1;
		sosuu[1]=1;
		
		int item[30];
		
		int n,m;
		scanf("%d%d",&n,&m);
		
		if(n==0 && m==0){
			break;
		}
		for(int i=0;i<n;i++){
			scanf("%d",&item[i]);
		}
		dp[0]=1;
		for(int i=0;i<=m;i++){
			for(int j=0;j<n;j++){
				if(i<item[j]){
					continue;
				}
				if(dp[i-item[j]]==1){
					dp[i]=1;
				}
			}
		}
		int num=0;
		for(int i=m;i>=0;i--){
			if(dp[i]==1&&sosuu[i]==0){
				num=i;
				break;
			}
		}
		if(num==0){
			puts("NA");
		}else{
			printf("%d\n",num);
		}
	}
}

Measured memory_bytes: 2832
#include <iostream>
#include <fstream>
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iomanip>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <sstream>
#include <string>
#include <vector>
using namespace std;

#define EPS 1e-9
#define INF MOD
#define MOD 1000000007LL
#define fir first
#define iss istringstream
#define sst stringstream
#define ite iterator
#define ll long long
#define mp make_pair
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<n;i++)
#define pi pair<int,int>
#define pb push_back
#define sec second
#define sh(i) (1LL<<i)
#define sz size()
#define vi vector<int>
#define vc vector
#define vl vector<ll>
#define vs vector<string>

#define FOR(t,i,c) for(t::const_iterator i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(),(c).end()

struct E{
	int to,w;
	E(int a,int b):to(a),w(b){}
};

typedef vc<E> Es;
typedef vc<Es> Gr;

bool visit(const Gr& g,int v,vi& order,vi& color){
	color[v]=1;
	FOR(Es,e,g[v]){
		if(color[e->to]==2)continue;
		if(color[e->to]==1)return 0;
		if(!visit(g,e->to,order,color))return 0;
	}
	order.pb(v);color[v]=2;
	return 1;
}

bool topo(const Gr& g,vi& order){
	int n=g.sz;
	vi color(n);
	rep(u,n)if(!color[u]&&!visit(g,u,order,color))return 0;
	reverse(ALL(order));
	return 1;
}

int n,xs,ys,xt,yt,X,Y,R,ax[1010],ay[1010],ar[1010],bx[1010],by[1010],br[1010],dpa[1010],dpb[1010];
Gr ga,gb;

int sq(int x){return x*x;}

int d2(int x,int y,int xx,int yy){
	return sq(x-xx)+sq(y-yy);
}

int main(){
	while(cin>>n,n){
		cin>>xs>>ys>>xt>>yt;
		int A=0,B=0;
		rep(i,n){
			cin>>X>>Y>>R;
			int a=d2(xs,ys,X,Y),b=d2(xt,yt,X,Y);
			if(a<R*R&&b>R*R)ax[A]=X,ay[A]=Y,ar[A++]=R;
			if(a>R*R&&b<R*R)bx[B]=X,by[B]=Y,br[B++]=R;
		}
		ga.clear(),ga.resize(A),gb.clear(),gb.resize(B);
		rep(i,A)rep(j,A)if(ar[i]<ar[j]&&d2(ax[i],ay[i],ax[j],ay[j])<sq(ar[i]-ar[j]))ga[i].pb(E(j,0));
		rep(i,B)rep(j,B)if(br[i]<br[j]&&d2(bx[i],by[i],bx[j],by[j])<sq(br[i]-br[j]))gb[i].pb(E(j,0));
		vi va,vb;
		topo(ga,va),topo(gb,vb);
		fill(dpa,dpa+1010,A>0),fill(dpb,dpb+1010,B>0);
		rep(i,A)rep(j,ga[va[i]].sz)dpa[ga[va[i]][j].to]=max(dpa[ga[va[i]][j].to],dpa[va[i]]+1);
		rep(i,B)rep(j,gb[vb[i]].sz)dpb[gb[vb[i]][j].to]=max(dpb[gb[vb[i]][j].to],dpb[vb[i]]+1);
		int a=max(*max_element(dpa,dpa+A),*max_element(dpb,dpb+B));
		rep(i,A)rep(j,B)if(d2(ax[i],ay[i],bx[j],by[j])>sq(ar[i]+br[j]))a=max(a,dpa[i]+dpb[j]);
		cout<<a<<endl;
	}
}

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

using namespace std;

typedef long long int ll;

const ll N=1e6+1;

int main(){
    ll n,weight;
    cin>>n>>weight;
    ll w[n+1],v[n+1],ans=0,dp[n+1][weight+1];
    for(ll i=1;i<=n;i++)
        cin>>w[i]>>v[i];
    
    for(int i=0;i<=n;i++){
        for(int j=0;j<=weight;j++)
            dp[i][j]=0;
    }
    
   for(int i=1;i<=n;i++){
        for(int j=0;j<=weight;j++){
            if(w[i]>j) dp[i][j]=dp[i-1][j];
            else dp[i][j]=max(dp[i-1][j-w[i]]+v[i],dp[i-1][j]);
        }
    }
    
    cout<<dp[n][weight]<<"\n";
    return 0;
}


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

int main() {
  string S,T;cin>>S>>T;
  int n=S.size();
  int count=0;
  for(int i=0;i<n;i++){
    if(S.at(i)!=T.at(i)){
      count++;
    }
  }
  cout<<count<<endl;
    
}


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

int main(int argc, char* argv[]) {
  int n;
  cin >> n;

    int i = 1;
   CHECK_NUM:
    int x = i;
    if ( x % 3 == 0 ){
      cout << " " << i;
      goto END_CHECK_NUM;
    }
   INCLUDE3:
    if ( x % 10 == 3 ){
      cout << " " << i;
      goto END_CHECK_NUM;
    }
    x /= 10;
    if ( x ) goto INCLUDE3;
   END_CHECK_NUM:
    if ( ++i <= n ) goto CHECK_NUM;

    cout << endl;

  return 0;
}

Measured memory_bytes: 1164
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,m,i,j,a,b;
    scanf("%d %d",&n,&m);
    a=min(n,m);
    b=max(n,m);
    for(i=0;i<b;i++)
        printf("%d",a);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define forn(x, n)              for (int x = 0; x < n; x++)
#define forr(x, n)              for (int x = n; x >= 0; x--)
#define fore(x, a, b, c)        for (int x = a; x <= b; x += c)
#define forre(x, a, b, c)       for (int x = a; x >= b; x -= c)
#define clr                     cin.ignore(numeric_limits<streamsize>::max(), '\n')
#define all(container)          (container).begin(), (container).end()
#define rall(container)         (container).rbegin(), (container).rend()
#define devugv(v)               for (auto& x: v) cerr << x << " "; cerr << '\n';
#define debugvp(v)              for (auto& x: v) cerr << x.fi << " - " << x.se << '\n';
#define FILL(x, val)            memset(x, val, sizeof(x))
#define pb                      push_back
#define eb                      emplace_back
#define fi                      first
#define se                      second
#define mod                     (int)1000000007
#define INF                     (int)0x3f3f3f3f

using namespace std;

#define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}

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

typedef long long i64; 
typedef vector< int > vi;
typedef vector< i64 > vi64;
typedef pair< int, int > pi;
typedef vector< pair< int, int > > vpi;
typedef vector< vector < int > > vvi;

int main(void) {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
    cout.precision(10);
    cout << fixed;
#ifdef LOCAL_DEFINE
    freopen("in.txt", "r", stdin);
#endif

    string A, B, U;
    cin >> A >> B;
    int a, b;
    cin >> a >> b;
    cin >> U;
    if (U == A) a--;
    else b--;
    cout << a << " " << b << '\n';

#ifdef LOCAL_DEFINE
    cout << "time elapsed : " << 1.0 * clock() / CLOCKS_PER_SEC << "s\n";
#endif
    return 0;
}

Measured memory_bytes: 256
n = int(input().strip())
listP = list(map(int, input().split()))
count = 0


for i in range(n-2):
    if (listP[i] < listP[i+1]) and (listP[i+1] < listP[i+2]):
      	count += 1
    elif (listP[i] > listP[i+1]) and (listP[i+1] > listP[i+2]):
        count += 1
    else:
        count += 0

print(count)




Measured memory_bytes: 3060
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		StringBuilder sb = new StringBuilder();

		String[] s = sc.next().split("");

		for(int i = 0; i < s.length; i++) {
			sb.append(s[i].equals("1") ? "9" : "1");
		}

		System.out.println(sb);
	}
}

Measured memory_bytes: 35576
#include <stdio.h>

int main(void)
{
	int n, a, v, wa, wv;
	int i;

	scanf("%d", &n);
	scanf("%d%d", &wa, &wv);
	for (i = 1; i < n; i++) {
		scanf("%d%d", &a, &v);
		if (v > wv) {
			wv = v; wa = a;
		} else if (v == wv && a < wa) {
			wv = v; wa = a;
		}
	}
	printf("%d %d\n", wa, wv);

	return 0;
}

Measured memory_bytes: 600
#include<bits/stdc++.h>
using namespace std;
vector<vector<long long int> > ve;
long long int recurse(long long int *arr,int i,int j){
	if(i>j){
		return 0;
	}
	else if(i==j){
		ve[i][j]=arr[i];
		//cout<<i<<" "<<j<<" "<<ve[i][j]<<endl;
		return arr[i];
	}
	else if((i+1)==j){
		long long int maximum=max(arr[i],arr[j]);
		ve[i][j]=maximum;
		return maximum;
	}
	else if(ve[i][j]!=0){
		return ve[i][j];
	}
	else{
		long long int max1=recurse(arr,i+1,j-1)+arr[i];
		long long int max2=recurse(arr,i+2,j)+arr[i];
		long long int max3=recurse(arr,i+1,j-1)+arr[j];
		long long int max4=recurse(arr,i,j-2)+arr[j];
		ve[i][j]=min(max1,max2);
		long long int fake=min(max3,max4);
		ve[i][j]=max(ve[i][j],fake);
		return ve[i][j];
	}
}
int main(void){
	int n;
	cin>>n;
	ve.resize(n);
	for(int i=0;i<n;i++){
		ve[i].resize(n);
	}
	long long int arr[n];
	for(int i=0;i<n;i++)
	cin>>arr[i];
	long long int ans=recurse(arr,0,n-1);
	long long int sum=0;
	for(int i=0;i<n;i++)
	sum+=arr[i];
	long long int fake=sum-ans;
	cout<<(ans-fake)<<endl;
}

Measured memory_bytes: 74184
#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <iostream>
using namespace std;

int cnt = 0;

void merge(int a[], int left, int mid, int right);
void mergeSort(int a[], int left, int right);

int main(void)
{
	int n;
	cin >> n;
	int *s = new int[n];
	for (int i = 0; i < n; i++) cin >> s[i];

	mergeSort(s, 0, n - 1);

	cout << s[0];
	for (int i = 1; i < n; i++) cout << " " << s[i];
	cout << endl << cnt << endl;
	
	delete[] s;
	return 0;
}

void merge(int a[], int left, int mid, int right)
{	
	int n1 = mid - left + 1;
	int n2 = right - (mid + 1) + 1;
	int *l = new int[n1 + 1];
	int *r = new int[n2 + 1];
	for (int i = 0; i <= n1; i++) l[i] = a[left + i];
	for (int i = 0; i <= n2; i++) r[i] = a[(mid + 1) + i];
	l[n1] = 1000000000;
	r[n2] = 1000000000;
	
	int i = 0, j = 0;
	for (int k = left; k <= right; k++) {
		if (l[i] <= r[j]) {
			a[k] = l[i];
			i++;
		}
		else {
			a[k] = r[j];
			j++;
		}
		cnt++;
	}
	delete[] l, r;
}

void mergeSort(int a[], int left, int right) {
	if (left < right) {
		int mid = (left + right) / 2;
		mergeSort(a, left, mid);
		mergeSort(a, mid + 1, right);
		merge(a, left, mid, right);
	}
}

Measured memory_bytes: 37268
"use strict";
function Main(input) {
    let lines = input.split("\n");
    const nums = lines.shift().split(/\s/).map((v) => v - 0);
    const N = nums[0], Q = nums[1];
    let S = lines.shift().split(/\s/)[0];
    let T = new Array(N).fill(0);
    for (let m = 0; m < S.length-1; m++) {
        T[m + 1] = T[m] + ((S.substr(m, 2) == 'AC') ? 1 : 0);
    }
    for (let n = 0; n < Q; n++) {
        let lr = lines.shift().split(/\s/).map((v) => v - 0 - 1);
        console.log(T[lr[1]] - T[lr[0]]);
    }
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


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

int gcd(int a, int b) {
	int c;
	for (int i = 1; i < 10000000; i++) {
		if (a%i == 0 && b%i == 0) {
			c = i;
		}
	}
	return c;
}

int a, b;
int main() {
	while (cin >> a >> b) {
		cout << gcd(a, b) << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#include<stdio.h>
int main()
{
    int x, y, z, temp;
    scanf("%d %d %d", &x, &y, &z);

    temp = y;
    y = x;
    x = temp;  //

    temp = z;
    z = x;
    x = temp;

    printf("%d %d %d", x, y, z);

    return 0;
}


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

int main() {
    int N,A;
    set<int> s;
    cin >> N;

    rep(i,N) {
        cin >> A;
        if(!s.count(A))
            s.insert(A);
        else
            s.erase(A);
    }

    cout << s.size() << endl;
}

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

using namespace std;
int main(){
    int n{0},k{0};
    scanf("%d %d",&n,&k);
    if(n<10){
        n=10-n;
        n*=100;
        k+=n;
    }
    printf("%d\n",k);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vint = vector<int>;
using vvint = vector<vint>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vchar = vector<char>;
using vvchar = vector<vchar>;
using vp = vector<P>;
using vpp = vector<pair<P, P>>;
using vvp = vector<vp>;

#define rep(i, n) for (int i = 0; i < n; ++i)
#pragma region Debug
istream &operator>>(istream &is, P &a)
{
    return is >> a.first >> a.second;
}
ostream &operator<<(ostream &os, const P &a) { return os << "(" << a.first << "," << a.second << ")"; }

template <typename T>
void view(const std::vector<T> &v)
{
    for (const auto &e : v)
    {
        std::cout << e << " ";
    }
    std::cout << std::endl;
}
template <typename T>
void view(const std::vector<std::vector<T>> &vv)
{
    for (const auto &v : vv)
    {
        view(v);
    }
}
#pragma endregion

int n, m, q;
int x[55][4];

int rec(int k, vint &a)
{

    if (a.size() == n)
    {
        int score = 0;
        rep(i, q)
        {
            auto now = x[i];

            if (a[now[1]] - a[now[0]] == now[2])
            {
                score += now[3];
            }
        }

        return score;
    }

    int ret = 0;
    for (int i = k; i <= m; i++)
    {
        vint newA = a;
        newA.emplace_back(i);
        ret = max(ret, rec(i, newA));
    }

    return ret;
}

int main()
{

    cin >> n >> m >> q;

    rep(i, q)
    {
        int a, b, c, d;
        cin >> a >> b >> c >> d;
        a--;
        b--;
        x[i][0] = a;
        x[i][1] = b;
        x[i][2] = c;
        x[i][3] = d;
    }

    vint A = vint(1, 1);
    int ans = rec(1, A);

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3632
#include<iostream>
#include<algorithm>
#include<stdbool.h>
#include<math.h>
#include<vector>
#include<string>
#include<map>
using namespace std;
typedef long long ll;

int main(void) {
	string s, t;
	int ans = 0;
	cin >> s;
	vector<string>st;
	for (int i = 0;i < s.length()-1;i++){
		for (int j = 1;j <= s.length()-i;j++) {
			if (i == 0 && j == s.length())continue;
			t = s.substr(i, j );
			int num = t.length();
			if (num % 2 == 0) {
				string x, y;
				x = t.substr(0, t.length() / 2);
				y = t.substr(t.length() / 2 , t.length()/2);
				if (x == y)ans = max(ans, num);
			}
	}
}
	cout << ans << endl;

	//データ構造をpairについて勉強する
	/*
	ABC041
	keyとvalueを考え、身長の高さについて管理しソート後リバース
	これにより前をイテレータで管理し、前から順番の値を出力
	*/
	return 0;
}

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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ll long long
#define PINT pair<int,int>
#define f1 first
#define s2 second
const int INF = 1e9 + 7;

using namespace std;

#define MAX_V 202
struct edge{int to, cap, rev;}; //辺（行き先，容量，逆辺）

vector<edge> G[MAX_V];  //隣接リスト
int level[MAX_V];   //ｓからの距離
int iter[MAX_V];    //どこまで調べ終わったか

//sからの最短距離をBFSで計算する
void bfs(int s){
    memset(level, -1, sizeof(level));
    queue<int> que;
    level[s] = 0;
    que.push(s);
    while(!que.empty()){
        int v = que.front(); que.pop();
        REP(i,G[v].size()){
            edge &e = G[v][i];
            if(e.cap > 0 && level[e.to] < 0){
                level[e.to] = level[v] + 1;
                que.push(e.to);
            }
        }
    }
}

//増加パスをDFSで探す
int dfs(int v, int t, int f){
    if(v == t) return f;
    for(int &i = iter[v]; i < G[v].size(); i++){
        edge &e = G[v][i];
        if(e.cap > 0 && level[v] < level[e.to]){
            int d = dfs(e.to, t, min(f, e.cap));
            if(d > 0){
                e.cap -= d;
                G[e.to][e.rev].cap += d;
                return d;
            }
        }
    }
    return 0;
}

//sからtへの最大流を求める
int max_flow(int s, int t){
    int flow = 0;
    for(;;){
        bfs(s);
        if(level[t] < 0) return flow;
        memset(iter, 0, sizeof(iter));
        int f;
        while((f = dfs(s, t, INF)) > 0){
            flow += f;
        }
    }
}

//fromからtoへ向かう容量capの辺をグラフに追加する
void add_edge(int from, int to, int cap){
    G[from].push_back((edge){to, cap, G[to].size()});
    G[to].push_back((edge){from, 0, G[from].size() - 1});
}

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

    int n;
    cin >> n;
    vector<PINT> red(n),blue(n);
    REP(i,n) cin >> red[i].f1 >> red[i].s2;
    REP(i,n) cin >> blue[i].f1 >> blue[i].s2;

    //sort(red.begin(),red.end());
    //sort(blue.begin(),blue.end());

    FOR(i,1,n+1) add_edge(0,i,1);
    FOR(i,101,101+n+1) add_edge(i,201,1);
    REP(i,n){
        REP(j,n){
            //if(red[j].f1>=blue[i].f1) break;
            if(red[j].f1<blue[i].f1 && red[j].s2<blue[i].s2){
                add_edge(1+i,101+j,1);
                //cout << i << ":" << j << endl;
            }
        }
    }

    cout << max_flow(0,201) << endl;
    return 0;
}


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

"""


input:
5 12
0 1 4
0 2 3
1 1 2
1 3 4
1 1 4
1 3 2
0 1 3
1 2 4
1 3 0
0 0 4
1 0 2
1 3 0

output:
0
0
1
1
1
0
1
1

"""

import sys


class UnionFind(object):
    __slots__ = ('size', 'tree_height_rank_list', 'ancestor_list')

    def __init__(self, size):
        self.size = int(size)
        self.tree_height_rank_list = [0] * self.size
        self.ancestor_list = [i for i in range(self.size)]

    def _find(self, x):
        if x != self.ancestor_list[x]:
            self.ancestor_list[x] = self._find(self.ancestor_list[x])
        return self.ancestor_list[x]

    def same(self, x, y):
        return self._find(x) == self._find(y)

    def link(self, x, y):
        if self.tree_height_rank_list[x] > self.tree_height_rank_list[y]:
            self.ancestor_list[y] = x
        else:
            self.ancestor_list[x] = y
            if self.tree_height_rank_list[x] == self.tree_height_rank_list[y]:
                self.tree_height_rank_list[y] += 1

    def union(self, x, y):
        self.link(self._find(x), self._find(y))


def action(_cmd_list):
    for _, each in enumerate(_cmd_list):
        cmd, ele_1, ele_2 = map(int, each)
        if cmd == 0:
            case.union(ele_1, ele_2)
        elif cmd == 1:
            if case.same(ele_1, ele_2):
                print('1')
            else:
                print('0')
    return case


if __name__ == '__main__':
    _input = sys.stdin.readlines()
    ele_num, cmd_num = map(int, _input[0].split())
    cmd_list = map(lambda x: x.split(), _input[1:])

    case = UnionFind(size=ele_num)

    ans = action(cmd_list)

Measured memory_bytes: 16664
package main

import (
	"fmt"
)

func main() {
	var h, w int
	fmt.Scan(&h, &w)
	as := make([]string, h)
	for i := range as {
		fmt.Scan(&as[i])
	}

	row := make([]bool, h)
	col := make([]bool, w)

	for i := 0; i < h; i++ {
		for j := 0; j < w; j++ {
			if as[i][j] == '#' {
				row[i] = true
				col[j] = true
			}
		}
	}

	for i := 0; i < h; i++ {
		if row[i] {
			for j := 0; j < w; j++ {
				if col[j] {
					fmt.Printf(string(as[i][j]))
				}
			}
			fmt.Println()
		}
	}
}


Measured memory_bytes: 1896
# import sys
# sys.setrecursionlimit(10 ** 6)
# import bisect
# from collections import deque
# from decorator import stop_watch
# 
# 
# @stop_watch
def solve(N, M, ABCi):
    inf = 10 ** 5 * 12 * 2
    for i in range(M):
        C = ABCi[i][2]
        ABCi[i][2] = sum([2 ** (c - 1) for c in C])
    # dp[i番目までのカギだけ購入したときに][bin(j)の宝箱が開けられる最小金額]
    dp = [[inf] * (2 ** N) for _ in range(M + 1)]
    dp[0][0] = 0
    for i in range(1, M + 1):
        for j in range(2 ** N):
            a, b, c = ABCi[i - 1]
            dp[i][j] = min(dp[i - 1][(c & j) ^ j] + a, dp[i - 1][j])
    ans = min([x[2 ** N - 1] for x in dp])
    if ans == inf:
        ans = -1
    print(ans)


if __name__ == '__main__':
    N, M = map(int, input().split())
    ABCi = [
        [int(i) for i in input().split()] + [[int(i) for i in input().split()]]
        for _ in range(M)]
    solve(N, M, ABCi)

    # # test
    # from random import randint, sample
    # from func import random_str
    # N, M = 12, 10 ** 3
    # tmp = [i for i in range(1, N + 1)]
    # ABCi = [[randint(1, 10 ** 5), randint(1, N)] for _ in range(M)]
    # print(ABCi)
    # for i in range(M):
    #     ABCi[i].append(sample(tmp, ABCi[i][1]))
    # solve(N, M, ABCi)


Measured memory_bytes: 171144
#pragma GCC optimize("Ofast")
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define PI 3.141592
#define all(a) (a).begin(), (a).end()


int main(){
    int x, y;
    cin >> x >> y;
    cout << x * y << endl;
}


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

int main(){
  int N,M;
  cin >> N >> M;
  vector< vector<int> > ab(N+1);
  queue<int> q;
  for(int i=0;i<M;i++){
    int a,b;
    cin >> a >> b;
    ab.at(a).push_back(b);
    if(a==1){
      q.push(b);
    }
  }
  while(!q.empty()){
    for(int i=0;i<ab.at(q.front()).size();i++){
      if(ab.at(q.front()).at(i)==N){
        cout << "POSSIBLE" << endl;
        return 0;
      }
    }
    q.pop();
  }
  cout << "IMPOSSIBLE" << endl;
  return 0;
}


Measured memory_bytes: 8824
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <climits>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <fstream>

using namespace std;
#define TOSTRING(x) #x
#define SZ(x) (int)(x).size()
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REPR(i,n) for(int i=(n)-1;i>=0;i--)
#define ALL(s) (s).begin(), (s).end()
#define so(V) sort(ALL(V))
#define rev(V) reverse(ALL(V))
#define uni(v) v.erase( unique(ALL(v)) , v.end());
#define PAU system("pause")

typedef long long unsigned int llu;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef vector<vb> vvb;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;
const int INF = (1 << 28);
const ll LINF = 1e18;
const double PI = acos(-1);

vi n753;
void dfs(int cnt,string s) {
	int c7 = 0, c5 = 0, c3 = 0;
	REP(i, SZ(s)) {
		if (s[i] == '7')c7++;
		if (s[i] == '5')c5++;
		if (s[i] == '3')c3++;
	}
	if (c7 * c5 * c3 != 0) {
		stringstream ss;
		ss << s;
		int n;
		ss >> n;
		if(find(ALL(n753),n) == n753.end())n753.push_back(n);
	}
	if (cnt == 0) {
		return;
	}
	dfs(cnt - 1, s + '7');
	dfs(cnt - 1, s + '5');
	dfs(cnt - 1, s + '3');
	return;
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	string N;
	cin >> N;
	dfs(SZ(N),"");
	so(n753);
	stringstream ss;
	ss << N;
	int iN;
	ss >> iN;
	int ans = distance(n753.begin(), upper_bound(ALL(n753), iN));
	cout << ans << endl;
	PAU;
	return 0;
}


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

inline ll gcd(ll a,ll b){ return b?gcd(b,a%b):a; }
inline ll lcm(ll a,ll b){ return a/gcd(a,b)*b; }

int n,q,l,r;
int p[100100];
int sum[100100], len[100100];
bool use[100100];
const ll mod = 1e9+7;
int par_sum[50][100100];

ll n_, c[1<<20];

void init(int n){
  n_ = 1;
  while(n_<n)n_*=2;

  for(int i=n_-1;i<2*n_-1;i++){
    if(i-n_+2<=n)c[i] = len[i-n_+2];
    else c[i] = 1;
  }

  for(int i=n_-2;i>=0;i--){
    c[i] = lcm(c[2*i+1],c[2*i+2]);
  }
}

ll query(int a,int b,int k,int l,int r){
  if(r<=a || b<=l)return 1;
  if(a<=l && r<=b)return c[k];
  ll vl = query(a,b,k*2+1,l,(l+r)/2);
  ll vr = query(a,b,k*2+2,(l+r)/2,r);
  return lcm(vl,vr);
}

int main(){
  scanf("%d%d",&n,&q);
  for(int i=1;i<=n;i++)scanf("%d",p+i);

  memset(use,0,sizeof(use));

  for(int i=1;i<=n;i++){
    if(!use[i]){
      int now = p[i];
      int tmplen = 1, tmpsum = i;
     
      while(now!=i){
	tmplen++; (tmpsum += now) %= mod;
	now = p[now];
      }

      now = i;
      while(!use[now]){
	use[now] = true;
	len[now] = tmplen;
	sum[now] = tmpsum;
      }
    }
  }

  for(int i=1;i<=40;i++){
    par_sum[i][0] = 0;
    for(int j=1;j<=n;j++){
      if(len[j]==i)par_sum[i][j] = (par_sum[i][j-1] + sum[j]) % mod;
      else par_sum[i][j] = par_sum[i][j-1];
    }
  }

  init(n);

  for(int i=0;i<q;i++){
    scanf("%d%d",&l,&r);
    ll cycle = query(l-1,r,0,0,n_);

    ll res = 0;
    for(int i=1;i<=40;i++){
      res += (((cycle/i)%mod)*(((par_sum[i][r]-par_sum[i][l-1])%mod+mod)%mod))%mod;
      res %= mod;
    }

    cout << res << endl;
  }
}

Measured memory_bytes: 24084
n = int(input())
info = [list(map(int, input().split())) for i in range(n - 1)]

tree = [[] for i in range(n)]
for a, b in info:
    a -= 1
    b -= 1
    tree[a].append(b)
    tree[b].append(a)

ans = 0
for v in range(n):
    ans += (v + 1) * (n - v)

    
for a, b in info:
    a, b = min(a, b), max(a, b)
    a -= 1
    b -= 1
    ans -= (a + 1) * (n - b)
print(ans)

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

#define PI 3.14159265358979323846
#define int long long int
#define ff first
#define ss second
#define pb push_back

#define N 100010
#define MOD 1000000007

int32_t main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.precision(10);

    int n;
    cin >> n;
    int a[n];
    for (int i = 0; i < n; ++i)
     {
         cin >> a[i];
     } 
    int no = 1;
    int ans = n;
    for (int i = 0; i < n; ++i)
    {
        if(a[i] == no)
        {
            no++;
            ans--;
        }
    }

    if(ans == n)
        cout << -1;
    else
        cout << ans;
   	return 0;	
}

Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;



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

	int a, b, k, i;
	set<int> s;
	cin >> a >> b >> k;
	for (i = 0; i < k; i++) {
		if (a + i <= b) s.insert(a + i);
		if (b - i >= a) s.insert(b - i);
	}

	for (auto p : s) cout << p << "\n";


	return 0;
}


Measured memory_bytes: 256
#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;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key

typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<int> vi;
typedef long double ld; 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
typedef vector<int>::iterator vit;

int h,w;
string a[27][27];

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	cin>>h>>w;
	int x=-1; int y=-1;
	for(int i=0;i<h;i++)
	{
		for(int j=0;j<w;j++)
		{
			cin>>a[i][j];
			if(a[i][j]=="snuke")
			{
				x=i+1; y=j+1;
			}
		}
	}
	cout<<char(y+'A'-1)<<x<<'\n';
}


Measured memory_bytes: 384
# -*- coding: utf-8 -*-
n = int(input())
a = []
for i in range(n):
    a.append(str(input()))

alph = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
count = [[0 for _ in range(len(alph))] for _ in range(n)]
for i in range(n):
    for j in range(len(alph)):
        count[i][j] = a[i].count(alph[j])
#print(count)
tmp = [100 for _ in range(len(alph))]
for i in range(len(alph)):
    for j in range(n):
        if count[j][i] < tmp[i]:
            tmp[i] = count[j][i]
ans = ''
for i in range(len(alph)):
    ans += alph[i] * tmp[i]
print(ans)


Measured memory_bytes: 3192
#include <iostream>
#include <vector>
#include <cmath>
#include <string>
#include <climits>
#include <iomanip>
#include <algorithm>
#include <queue>
#include <map>
#include <tuple>
#include <iostream>
#include <deque>
#include <array>
#include <set>
#include <functional>
#include <memory>
#include <stack>

constexpr long long int mod = 1000000007;
struct Factorial {
	std::vector<long long int> factorial;
	std::vector<long long int> factorial_inverse;
	Factorial(const int size) : factorial(size + 1, 1), factorial_inverse(size + 1, 1) {
		std::vector<long long int> inv(size + 1, 1);
		for (auto i = 2; i < size + 1; ++i) {
			factorial[i] = i * factorial[i - 1] % mod;
			inv[i] = (mod - mod / i) * inv[mod % i] % mod;
			factorial_inverse[i] = inv[i] * factorial_inverse[i - 1] % mod;
		}
	}
	long long int combination(const int n, const int r) const {
		return factorial[n] * factorial_inverse[n - r] % mod * factorial_inverse[r] % mod;
	}
	long long int fact(const int n) const {
		return factorial[n];
	}
	long long int fact_inv(const int n) const {
		return factorial_inverse[n];
	}
};
int main() {
	int n, k; std::cin >> n >> k;
	std::vector<std::vector<int>> nodes(n);
	for (auto i = 1; i < n; ++i) {
		int a, b; std::cin >> a >> b;
		nodes[a - 1].push_back(b - 1);
		nodes[b - 1].push_back(a - 1);
	}
	if (std::any_of(nodes.begin(), nodes.end(), [k](const std::vector<int>& vec) {return vec.size() + 1 > k; })) {
		std::cout << 0 << std::endl;
		return 0;
	}
	Factorial fact(k);
	if (k <= 2) {
		if (n == 1) {
			std::cout << k << std::endl;
		}
		else if (n == 2 && k == 2) {
			std::cout << 2 << std::endl;
		}
		else {
			std::cout << 0 << std::endl;
		}
		return 0;
	}
	std::stack<std::pair<int, int>> stack;
	std::stack<std::pair<int, int>> accumulate;
	stack.push(std::make_pair(-1, 0));
	std::vector<long long int> memo(n, 1);
	while (!stack.empty()) {
		auto top = stack.top(); stack.pop();
		auto count = std::count_if(nodes[top.second].begin(), nodes[top.second].end(), [top](const int v) {return v != top.first; });
		if (count != 0) {
			if (top.first != -1) memo[top.second] = fact.fact(k - 2) * fact.fact_inv(k - 2 - count) % mod;
			else memo[top.second] = fact.fact(k - 1) * fact.fact_inv(k - 1 - count) % mod;
			for (const auto next : nodes[top.second]) if (next != top.first) {
				accumulate.push(std::make_pair(top.second, next));
				stack.push(std::make_pair(top.second, next));
			}
		}
		else {
			memo[top.second] = 1;
		}
	}
	while (!accumulate.empty()) {
		auto top = accumulate.top(); accumulate.pop();
		memo[top.first] *= memo[top.second];
		memo[top.first] %= mod;
	}
	std::cout << memo[0] * k % mod << std::endl;
}

Measured memory_bytes: 10088
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;
const ll mod=998244353;
const int MAXN=1e5+5;
int n;
ll cnt[MAXN],ans=1;
ll mod_pow(ll x,ll n){
	ll ret=1;
	if (x==0) ret=0;
	while (n){
		if (n&1) ret=ret*x%mod;
		x=x*x%mod;
		n>>=1;
	}
	return ret;
}
int main(){
	scanf("%d",&n);
	ll mx=0;
	scanf("%lld",&mx);
	if (mx!=0) ans=0;
	cnt[mx]++;
	for (int i=1;i<n;i++){
		ll x; scanf("%lld",&x);
		cnt[x]++; mx=max(mx,x);
	}
	for (int i=1;i<=mx;i++){
		ans=ans*mod_pow(cnt[i-1],cnt[i])%mod;
	}
	if (cnt[0]>1) ans=0;
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 1024
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {

	static int[] S ;
	public static void main(String[] args) throws Exception {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		String W = in.readLine();
		String[] Ws = W.split(" ");
		int N = Integer.parseInt(Ws[0]);
		int M = Integer.parseInt(Ws[1]);

		String[] S = new String[(int)Math.pow(10, N)];
		for(int i=0;i<S.length;i++){
			S[i] = String.valueOf(i);
		}

		String[][] Q = new String[M][];
		for(int i=0;i<M;i++){
			W = in.readLine();
			Q[i] = W.split(" ");
		}

		int i = (int)Math.pow(10, N-1);
		int end = i*10;
		if(i==1){
			i=0;
		}
		for(;i<end;i++){
			boolean flg = true;
			for(int k = 0;k<Q.length;k++){
				if(S[i].charAt(Integer.parseInt(Q[k][0])-1) != Q[k][1].charAt(0)){
					flg= false;
					break;
				}
			}
			if(flg){
				break;
			}
		}
		if(i==end){
			System.out.println(-1);
		}else{
			System.out.println(S[i]);
		}
	}


}


Measured memory_bytes: 22484
#include<stdio.h>
int main()
{
    int K, A, B, i, count=0;
    scanf("%d", &K);
    scanf("%d %d", &A, &B);

    for(i=A; i<=B; i++)
    {
        if(i%K==0)
        {
            count=1;
            break;
        }
    }
    if(count==1)
    {
        printf("OK\n");
    }
    else
    {
        printf("NG\n");
    }
    return 0;
}


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

typedef long long ll;
typedef unsigned long long ull;
#define endl "\n";
#define FASTER ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define POSITIVE_INFINITY 9223372036854775807
#define NEGATIVE_INFINITY -9223372036854775807
#define MOD 1000000007

int main()
{
    FASTER;
    int a, b, c;
    cin >> a >> b >> c;
    int left = c - (a + b)- 1;
    cout << b + c - max(0, left) << endl;
    return 0;
}


Measured memory_bytes: 256
//1.read question_2.read I/O_3.read test cases_4.read constraints(to decide TC of solution)_5.decide method_6.dry run_
//7.code_8.test_9.submit
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
#define mod 1000000007
#define F first
#define S second
#define _READ freopen("input.txt","r", stdin);
#define pb push_back
#define MP make_pair
#define _FAST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
int main()
{
    
    _FAST
    lli n,t,i,j,k,ans=0,flag=0,a,b,m;
    cin>>n>>k;vector<lli> ar(n);
    for(auto &i:ar)
        cin>>i;
    vector<lli> dp(k+1,0);
    dp[0]=0;
    for(i=0;i<=k;i++)
    {
        for(j=0;j<n;j++)
        {
            if(i+ar[j]<=k && dp[i+ar[j]]==0)
            dp[i+ar[j]]=1-dp[i];
        }
    }
    //for(auto i:dp)
    //    cout<<i<<" ";cout<<"\n";
    if(dp[k]==1)
        cout<<"First";
    else
        cout<<"Second";
    return 0;
}


Measured memory_bytes: 1024
<?php

$i = 1;

    $input = trim(fgets(STDIN));
    if($input == 0){
        exit;
    }else{
        echo "Case $i: $input";
        $i++;
    }

while(true){
    $input = trim(fgets(STDIN));
    if($input == 0){
        break;
    }else{
        echo "\nCase $i: $input";
        $i++;
    }
}
?>

Measured memory_bytes: 15232
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		// ??°?????\??????????????????
		Scanner scanner = new Scanner(System.in);
		Integer inputValue = scanner.nextInt();

		// if??§0??\??????86400???????????\??????????????¶??¨??????
		if ( (inputValue>=0)&&(inputValue<86400) ) {

			// h????¨????
			Double h = Math.floor(inputValue/3600);

			// m????¨????
			Double m = Math.floor((inputValue - h*3600)/60);

			// s????¨????
			Double s = Math.floor( (inputValue - (h*3600 + m*60) ) );

			// ?¨???????????????´??¢????????????
			System.out.println(Math.round(h) + ":" + Math.round(m) + ":" + Math.round(s));


		}



	}

}

Measured memory_bytes: 26340
def main():
    N = int(input())
    jobs = [list(map(int, input().split())) for _ in range(N)]
    time = 0
    jobs = sorted(jobs, key=lambda x: x[1])
    for j in jobs:
        time += j[0]
        if time > j[1]:
            print("No")
            return
        
    else:
        print("Yes")


if __name__ == '__main__':
    main()

Measured memory_bytes: 55180
D, G = map(int,input().split())
p = []
c = []
for i in range(D):
    s, t = map(int,input().split())
    p.append(s)
    c.append(t)

cs = []
for i in range(D):
    cs.append(100 * (i + 1) * p[i] + c[i])

ans = []
for i in range(2**D):
    score = 0
    n = 0
    han = []
    for j in range(D):
        if i >> j & 1:
            score += cs[j]
            n += p[j]
        else:
            han.append(j)
    if score >= G:
        ans.append(n)
    else:
        for np in reversed(han):
            for j in range(p[np]-1):
                score += 100 * (np + 1)
                n += 1
                if score >= G:
                    ans.append(n)
                    break
            if score >= G:
                break

print(min(ans))


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define EPS 0.0000000001
#define INF 1000000000
#define MOD 1000000007
typedef long long ll;

int main()
{
    int n;
    cin >> n;
    vector<int> c(n - 1);
    vector<int> s(n - 1);
    vector<int> f(n - 1);
    for (int i = 0; i < n - 1; i++)
    {
        cin >> c[i] >> s[i] >> f[i];
    }
    vector<int> ans(n);

    for (int j = 0; j < n - 1; j++)
    {

        ll nowtime = 0;
        for (int i = j; i < n - 1; i++)
        {
            if (nowtime <= s[i])
            {
                nowtime = s[i];
            }
            else
            {
                int di = nowtime - s[i];
                if (di % f[i] != 0)
                {
                    nowtime = s[i] + f[i] * (di / f[i] + 1);
                }
            }
            //nowtime  発車時刻

            nowtime += c[i];
            //nowtime　到着時刻
            //cout<<nowtime<<endl;
        }
        cout << nowtime << endl;
    }
    cout<<0<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>          // printf(), scanf()

int
main(int argc, char **argv)
{
	int a, b, n;
	int i;

	while (scanf("%d %d %d", &a, &b, &n) != EOF)
	{
		int sum = 0;
		a %= b;
		for (i = 0; a != 0 && i < n; ++i)
		{
			a *= 10;
			sum += a / b;
			a %= b;
		}

		printf("%d\n", sum);
	}

	return 0;
}

Measured memory_bytes: 596
#include<iostream>
#include<vector>
#include<string>
#include<map>

using namespace std;

map<char,int> a;
int main(){
  int a,b;
  cin >> a >> b;
  if(a == b) cout << 2*a <<endl;
  else if(a > b) cout << 2*a-1<<endl;
  else cout << 2*b-1 <<endl;
}


Measured memory_bytes: 256
N = int(input())
T, A  = map(int, input().split())
hight_list = list(map(int, input().split()))
 
ans = 10000
ans_ind = 0
 
for i in range(N):
  temp = T - 0.006 * hight_list[i]
  diff = abs(temp - A)
  if  diff < ans:
    ans = diff
    ans_ind = i
    
print(ans_ind+1)
    

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

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

int main()
{
	int n;
	cin >> n;
		vector<int> a(n+1);
	for(int i = 0;i<n+1;i++)
	{
		cin >> a[i];
	}
	int now = a[0]-a[1];
	sort(a.begin(),a.end());
	for(int i = 0;i<n;i++)
	{
		now = gcd(now,a[i+1]-a[i]);
	}
	cout<<now<<endl;
	return 0;
}


Measured memory_bytes: 640
import java.util.Scanner;

class Main
{
    public static void main(String args[])
    {
        Scanner scan = new Scanner(System.in);
        
        int S = scan.nextInt();
        int h = S/3600;
        int m = (S%3600)/60;
        int s = S%60;
        System.out.println(h+":"+m+":"+s);
    }
}


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

int main()
{
    long long X, n = 0;
    long long yen = 100;
    cin >> X;

    while (++n)
    {
        yen = yen + yen * 0.01;
        if (yen >= X)
            break;
    }
    cout << n << endl;
    // cout << round(log((double) X/100) / log(1.01)) << endl;


}


Measured memory_bytes: 3592
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <cmath>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <iostream>
#include <random>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include <fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;

using ll = long long;
using vll = vector<long long>;
using pll = pair<long long, long long>;
#define rep(i,n) for(long long i(0);(i)<(n);(i)++)
ll INF = 1LL << 60;

const long long MOD = 1000000007;
//* prime factorization in O(sqrt(n))
map<ll, ll> prime_factor(ll n){
    map<ll, ll> res;
    for(ll i=2; i*i <= n; i++){ //* n shrinks during the for-loop!
        while(n % i == 0){
            ++res[i];
            n /= i;
        }
    }
    if(n != 1) {
        ++res[n];
    }
    return res;
}

ll extgcd(ll a, ll b, ll &x, ll &y){
    if(b == 0){
        x = 1; y = 0;
        return a;
    }
    ll d = extgcd(b, a % b, y, x);
    y -= (a / b) * x;
    return d;
}

ll mod_inverse(ll a, ll m){
    ll x, y;
    extgcd(a, m, x, y);
    return(m + x%m) % m;
}

ll mod_fact_simple(ll n, ll p){
    ll res = 1;
    if(n == 0) return res;
    for(ll i=1; i<= n; i++){
        res *= i;
        res = res % p;
    }
    return res;
}

ll mod_comb(ll n, ll k, ll p){
    if(n < 0 || k < 0 || n < k) return 0;
    ll a1 = mod_fact_simple(n, p);
    ll a2 = mod_fact_simple(k, p);
    ll a3 = mod_fact_simple(n-k, p);
    return (a1 * mod_inverse(a2 * a3 % p, p)) % p;
}

void solve(long long N, long long M){
    map<ll, ll> pf = prime_factor(M);
    ll ans = 1;
    for(auto it = pf.begin(); it != pf.end(); ++it){
        ll b = it->second;
        ans *= mod_comb(b+N-1, b, MOD);
        ans = ans % MOD;
    }
    cout << ans << endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    long long M;
    scanf("%lld",&M);
    solve(N, M);
    return 0;
}


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

int main() {
  int N;
  cin >> N;
  int64_t power = 1,p;
  p = pow(10,9) + 7;
  for(int i = 1; i <= N; i++){
    power = power * i;
    power = power % p;
  }
  cout << power <<endl;
}

Measured memory_bytes: 256
/*
 * main.c
 *
 *  Created on: 2019/07/07
 *      Author: family
 */

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

typedef unsigned long long int uint64_t;
typedef long long int int64my_t;

//qsort(a, 3, sizeof(int), sort_inc);
int sort_inc(const void *a, const void *b)
{
    return (*(int*)a - *(int*)b);
}
int sort_dec(const void* a, const void* b)
{
    return (*(int*)b - *(int*)a);
}

int main()
{
	int r = 0;
	scanf("%d", &r);
	printf("%d\n", 3*r*r);
    return 0;
}


Measured memory_bytes: 128
(N, M) = gets.split.map(&:to_i)

bridge = []

M.times do
  bridge << gets.split.map(&:to_i)
end

class UnionFind
  attr_reader :count

  def initialize(n)
    @root = Array.new(n + 1)
    @root[0] = nil
    @root_count = Hash.new(1)
    @count = n * (n - 1) / 2
  end

  def union(a, b)
    unite(find(a), find(b))
  end

  def find(a)
    @root[a] == nil ? a : @root[a] = find(@root[a])
  end

  def unite(a, b)
    return 0 if a == b
    a, b = b, a if b < a
    @count -= @root_count[a] * @root_count[b]
    @root[b] = a
    @root_count[a] += @root_count[b]
    @root_count.delete(b)
  end
end

uf = UnionFind.new(N)

ans = bridge.reverse_each.map do |a, b|
  c = uf.count
  uf.union(a, b)
  c
end

puts ans.reverse

Measured memory_bytes: 14588