akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define ll long long int
#define pb push_back
#define endl '\n'
#define Endl '\n'
#define fi first
#define ii pair<ll,ll>
#define se second
#define ld long double
#define mod 1000000007
#define popcount __builtin_popcountll
#define PI acos(-1.0)
using namespace std;
ll a[200010];

vector<ll>v;
ll cum[200015];
ll get_sum(int l, int r){
    if(l==0)return cum[r];
    return cum[r]-cum[l-1];
}


ll get_ans(int l,int r,int mid){
    ll lf = get_sum(l,mid);
    ll rt = get_sum(mid+1,r);
    if(mid+1>r)return 1e18;
    return abs(lf-rt);
}

ii get(int st, int en){
    if (st == en) return {0,1e18};

    // cout<<"ST EN "<<st<<"  "<<en<<endl;
    ll l = st, r = en, lt, rt;
    for (int i=1;i<=169;i++){
        ll md = (l+r)/2;
        ll ansL = get_ans(st,en,md);
        ll ansR = get_ans(st,en,md+1);
        // cout<<st<<" "<<en<<" "<<md<<"       "<<md+1<<"          "<<endl;
        // cout<<ansL<<"  "<<ansR<<endl;;
        // int c; cin>>c;
        if (ansL < ansR) r = md+1;
        else l = md;
    }
    int idx = l;
    ll ans1 = abs(get_sum(st,idx)-get_sum(idx+1,en));
    idx++;
    ll ans2 = abs(get_sum(st,idx)-get_sum(idx+1,en));
    if(ans1>ans2)return {get_sum(st,idx), get_sum(idx+1,en)};
    idx--;
    return {get_sum(st,idx), get_sum(idx+1,en)};
}
int main(){
    int n;
    ll L;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a[i];
        v.pb(a[i]);
    }
    cum[0] = v[0];
    n = v.size();
    for(int i=1;i<n;i++)cum[i] = cum[i-1] + v[i];
    ll amid = 1e18;
    for (int i=0;i<n-1;i++){
        ii lf = get(0,i);
        ii rt = get(i+1,n-1);

        vector<ll> vv;
        vv.push_back(lf.fi);
        vv.push_back(lf.se);
        vv.push_back(rt.fi);
        vv.push_back(rt.se);
        // 3 1 1 3 2 2 3 3
        // cout<<"At "<<i<<": ";
        // for (auto nx:vv) cout<<nx<<" ";
        // cout<<endl;
        sort(vv.begin(),vv.end());
        amid = min(amid,vv[3]-vv[0]);
    }
    cout<<amid<<endl;
}


Measured memory_bytes: 5104
#include <stdio.h>

int main(void)
{
    int x, i = 1;
    while(i <= 10000) {
        scanf("%d", &x);
        if (x < 1 || x > 10000) break; 
        printf("Case %d: %d\n", i++, x);
    };
    
    return 0;
}

Measured memory_bytes: 596
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();
		int X = sc.nextInt();
		int Y = sc.nextInt();

		int price = 0;
		price += Math.min(2*C, A+B) * Math.min(X, Y);
		if(X>Y) {
			price += (X-Y)*A;
		}else {
			price += (Y-X)*B;
		}

		int AB = Math.max(X, Y)*2*C;

		System.out.println(Math.min(price, AB));

	}

}


Measured memory_bytes: 21972
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include <string.h>
#include <math.h>

using namespace std;

int c;
vector<char> s, t;

int main()
{
	bool ans = true;
	string tmp;
	cin >> tmp;

	for (int i = 0; i < tmp.size(); i++)s.push_back(tmp[i]);
	sort(s.begin(), s.end());

	cin >> tmp;
	for (int i = 0; i < tmp.size(); i++)t.push_back(tmp[i]);
	sort(t.begin(), t.end());

	c = min(s.size(), t.size());

	vector<char>::iterator _s, _t;

	_s = s.begin();
	_t = t.end();
	--_t;

	for (int i = 0; i < c; i++) {
		if (*_s < *_t) break;
		if (*_s > *_t) {
			ans = false;
			break;
		}
		if (_s == s.end()) {
			if (_t == t.begin())ans = false;
			break;
		}
		if (_t == t.begin()) {
			ans = false;
			break;
		}
		++_s;
		--_t;
	}

	if (ans) cout << "Yes" << endl;
	else cout << "No" << endl;




	return 0;
}


Measured memory_bytes: 256
using System;
using System.Linq;

namespace AizuOnlineJudge
{
    class Program
    {
        static void Main(string[] args)
        {
            var arr = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();

            Console.WriteLine($"{arr[0] * arr[1]} {(arr[0] + arr[1]) * 2}");
        }
    }
}



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

int main() {
    int n;
    cin >> n;
    vector<string> s(n),t(n);
    for (int i=0;i<n;i++) {
        cin >> s[i];
        t[i]=s[i];
    }
    sort(t.begin(),t.end());
    auto itr=unique(t.begin(),t.end());
    t.resize(distance(t.begin(),itr));
    int m=t.size();
    vector<pair<int,string>> p(m);
    for (int i=0;i<m;i++) {
        p[i].first=1000000;
        p[i].second=t[i];
    }
    for (int i=0;i<n;i++) {
        auto itr=lower_bound(t.begin(),t.end(),s[i]);
        p[itr-t.begin()].first--;
    }
    sort(p.begin(),p.end());
    for (int i=0;i<m;i++) {
        if (p[0].first==p[i].first) cout << p[i].second << endl;
    }
    
}

Measured memory_bytes: 18976
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
 
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll t,y=1;
    //cin>>t;
    t=1;
    while(t>0)
    {
        t--;
        ll n,i,j,k,flag=1,x=LLONG_MAX;
        cin>>n>>k;
        ll h[n+1],a[n+1];
        for(i=1;i<=n;i++)
        {
            cin>>h[i];
        }
        a[1]=0;
        for(i=2;i<=n;i++)
        {
            x=LLONG_MAX;
            for(j=i-1;j>=max(flag,i-k);j--)
            {
            	if(x>a[j]+abs(h[i]-h[j]))
            		x=a[j]+abs(h[i]-h[j]);
            }
            a[i]=x;
        }
        cout<<a[n]<<endl;
    }    
	return 0;
}

Measured memory_bytes: 1792
n=int(input())
ans=0
dic={}
for _ in range(n):
    s=input()
    s=sorted(s)
    s=''.join(s)
    if not s in dic.keys():
      dic[s]=1
    else: dic[s]+=1
for i in dic.values():
  ans+=i*(i-1)//2


print(ans)


Measured memory_bytes: 17852
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>

using namespace std;

typedef long long int ll;
typedef pair<ll, ll> P;
#define INF 10000000000000
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep1(i, n) for(ll i = 1; i < (ll)(n); i++)
#define repN_1(i, n) for(ll i = 0; i < (ll)(n - 1); i++)
#define repM(i, n) for(ll i = (ll)(n - 1); i >= 0; i--)
#define repM1(i, n) for(ll i = (ll)(n - 1); i > 0; i--)
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; }

int main()
{
	cout << fixed << setprecision(18);
	ll n;
	string ans;

	cin >> n;

	vector<ll> c;
	if (n == 0)
		ans = 'a';

	while (n > 0) {
		n--;
		c.push_back(n % 26);
		n = n / 26;
	}

	repM(i, c.size())
	{
		string tmp;
		tmp = 'a' + c[i];
		ans += tmp;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3636
import java.util.Scanner;

class Main{
  public static void main(String[] args){
    Scanner sc=new Scanner(System.in);
    
    String A=sc.next();
    String B=sc.next();
    String C=sc.next();
    
    if(Character.isUpperCase(B.charAt(0))){
      System.out.println(A.substring(0,1)+B.substring(0,1)+C.substring(0,1));
    }
  }
}

Measured memory_bytes: 23252
#include <iostream>

using namespace std;

int k;
string s;

void solve() {
  if (s.size() <= k) {
    cout << s << endl;
  } else {
    cout << s.substr(0, k) << "..." << endl;
  }
}

int main() {
  cin >> k;
  cin >> s;
  solve();
}


Measured memory_bytes: 3608
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>   
#include<limits.h>
using namespace std;
#define i64  long long
#define int  long long
 
#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807
#define MOD 1000000007



void solve()
{

    int M;
    int D = 0, S = 0;

    cin>>M;
    for (int i = 0; i < M; i++)
    {
      int A,B;
      cin>>A>>B;
      D += B;
      S += A*B;
    }
  
    cout<< D - 1 + (S - 1)/9<<endl;
    
}

int32_t main(int32_t argc, const char *argv[])
{
 
  solve();
 
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
  int h,w,i,j;
  char a[250][105];
  scanf("%d %d",&h,&w);
  getchar();
  
  for(i=1;i<=h;i++)
  {
  	for(j=1;j<=w;j++)
  	scanf("%c",&a[i][j]);
  	
  	getchar();
  }
 /* for(i=w+1;i<=2*w;i++)
  {
  	for(j=1;j<=h;j++)
  	a[i][j]=a[(i+1)/2][j];
  }*/
  
  for(i=1;i<=h;i++)
  {
  	for(j=1;j<=w;j++)
  	{
  		printf("%c",a[i][j]);
  	
  	
	  }
	  printf("\n");
	  for(j=1;j<=w;j++)
  	{
  		printf("%c",a[i][j]);
  	
  	
	  }
	  printf("\n");
  }
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#ifdef _DEBUG
#define _GLIBCXX_DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
// typedef __int128_t Int;
#define DBG 1
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define loop(n) rep(loop, (0), (n))
#define all(c) begin(c), end(c)
const int INF =
    sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
const double PI = acos(-1);
const double EPS = 1e-9;
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

struct Graph {
  int V;
  vector<vector<int>> g;
  vector<int> visited, recStack;
  vector<int> indeg;
  Graph(int V) : V(V), g(V), visited(V), indeg(V), recStack(V) {}
  void add_edge(int s, int t) { g[s].push_back(t); }
  bool is_cyclic() {
    fill(all(visited), 0);
    fill(all(recStack), 0);

    rep(i, 0, V) {
      if (isCyclicUtil(i))
        return true;
    }
    return false;
  }
  bool isCyclicUtil(int v) {
    if (!visited[v]) {
      visited[v] = recStack[v] = true;

      rep(i, 0, g[v].size()) {
        int x = g[v][i];
        if (!visited[x] and isCyclicUtil(x))
          return true;
        else if (recStack[x])
          return true;
      }
    }
    recStack[v] = false;
    return false;
  }
};
signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(12);

  int V, E;
  cin >> V >> E;
  Graph g(V);
  loop(E) {
    int s, t;
    cin >> s >> t;
    g.add_edge(s, t);
  }
  cout << g.is_cyclic() << endl;

  return 0;
}



Measured memory_bytes: 3204
#include<bits/stdc++.h>
using namespace std;
long N,K,A[1<<17],M=1e9+7,F[1<<17],I[1<<17],i,r;
long C(long n,long k){return F[n]*I[k]%M*I[n-k]%M;}
long P(long n,long r){return r?P(n*n%M,r/2)*(r%2?n:1)%M:1;}
int main(){
	cin>>N>>K;
	F[0]=1;
	for(i=1;i<=N;i++)F[i]=F[i-1]*i%M;
	I[N]=P(F[N],M-2);
	for(i=N;i--;)I[i]=I[i+1]*(i+1)%M;
	for(i=0;i<N;i++)cin>>A[i];
	sort(A,A+N);
	for(i=K-1;i<N;i++){
		(r+=A[i]*C(i,K-1))%=M;
		(r-=A[N-i-1]*C(i,K-1))%=M;
	}
	cout<<r%M<<endl;
}


Measured memory_bytes: 2560
#include <stdio.h>
int main(void)
{int A,B,C,D,N,x,y,K,S,Y,Z,k,l,i,tmp;
	long long int sum;
	scanf("%d",&N);
	sum=1;
	for(i=1;i<=N;i++){
		sum*=i;
		if(sum>=1000000007){
			sum%=1000000007;}
			
	}
	printf("%lld",sum);
	


	return 0;
}


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

#define int long long
#define ld long double

#define pb push_back
#define F first
#define S second
#define I insert
#define sz(a) (int)((a).size())
#define all(a) (a).begin(), (a).end()

#define debug1(a) cerr<<" "<<#a<<" : "<<a<<"\n"
#define debug2(a,b) cerr<<" "<<#a<<" : "<<a<<" "<<#b<<" : "<<b<<"\n"
#define debug3(a,b,c) cerr<<" "<<#a<<" : "<<a<<" "<<#b<<" : "<<b<<" "<<#c<<" : "<<c<<"\n"
#define debug4(a,b,c,d) cerr<<" "<<#a<<" : "<<a<<" "<<#b<<" : "<<b<<" "<<#c<<" : "<<c<<" "<<#d<<" : "<<d<<"\n"

#define INF (int)100000000000000000
#define PI (double)3.14159265358979
// #define M 421412341324321
#define MOD 998244353



signed main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

    int n;
    cin>>n;
    int a[n];

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


    int ans = 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 (a[i] + a[j] > a[k] && a[i] + a[k] > a[j] && a[k] + a[j] > a[i] && a[i]!=a[j] && a[j]!=a[k] && a[k]!=a[i])
                {
                    // debug3(i+1, j+1, k+1);
                    ans++;
                }
            }
        }
    }
    cout << ans << "\n";
    return 0;
}


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

int main() {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    if (a + b > c + d){
        cout << "Left" << endl;
    }else if (a + b == c + d){
        cout << "Balanced" << endl;
    }else{
        cout << "Right" << endl;
    }
}


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

int main(){
	int n,m;	cin>>n>>m;
	int a[n][m],b[m];
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			cin>>a[i][j];
		}
	}
	for(int i=0;i<m;i++){
		cin>>b[i];
	}
	for(int i=0;i<n;i++){
		a[i][0]*=b[0];
	}
	for(int i=1;i<m;i++){
		for(int j=0;j<n;j++){
			a[j][i]=(a[j][i]*b[i])+a[j][i-1];
		}
	}
	for(int i=0;i<n;i++){
		cout<<a[i][m-1]<<endl;
	}
	return 0;
}

Measured memory_bytes: 1200
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>

using namespace std;

const long MOD = 1000000007;
typedef pair<int, int> P;
typedef long long ll;

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

    const int MX = 55555;
    vector<int> p;
    bool isp[MX+1];
    fill(isp, isp+MX+1, true);
    for(int i=2; i<=MX; i++){
        if(!isp[i]) continue;
        p.push_back(i);
        int t = i+i;
        while(t <= MX){
            isp[t] = false;
            t += i;
        }
    }

    int cnt = 0;
    for(int q: p){
        if(q % 5 == 1){
            cout << q << " ";
            cnt++;
        }
        if(cnt == N) break;
    }

    cout << endl;

    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,s,n) for(int i=(s); i<(n); i++)
#define all(v) v.begin(),v.end()
#define outve(v) for(auto i : v) cout << i << " ";cout << endl
#define in(n,v) for(int i=0; i<(n); i++){cin >> v[i];}
#define out(n) cout << (n) << endl
#define fi first
#define se second
#define ve vector
#define pq priority_queue
#define vi vector<int>
#define vl vector<long long>
#define vii vector<vector<int>>
using namespace std;
using ll = long long;
using ld = long double;
const ll mod = 1000000007;



template <typename T> T gcd(T a, T b) {if(b == 0) return a;return gcd(b,a%b);}
template <typename T> T lcm(T a, T b) {return a*b/gcd(a,b);}
template <typename T> T extgcd(T a, T b, T& x, T& y){
    T d = a;
    if(b != 0){d = extgcd(b,a%b,y,x); y-=(a/b)*x;}
    else x=1,y=0;
    return d;
}
template <typename T> T modpow(T x, T n, T m) {
    if(n==0) return 1;
    T resp = modpow(x*x%m,n/2,mod);
    if(n&1) resp = resp*x%m;
    return resp;
}
template <typename T> T modinverse(T a, T m) {
    T x,y;
    extgcd(a,m,x,y);
    return (m+x%m)%m;
}
struct combination {
    ll M = mod;
    vector<ll> fact;vector<ll> ifact;
    combination(ll n):fact(n+1),ifact(n+1){
        fact[0]=1;ifact[0]=1;
        for (ll i = 0; i<n; i++) {fact[i+1] = fact[i]*(i+1) % M;ifact[i+1] = ifact[i]*modpow(i+1, M-2, M) % M;}
    }
    ll com(ll a, ll b){
        if(a == 0 && b == 0)return 1;if(a < b || a < 0)return 0;
        ll tmp = ifact[a-b]* ifact[b] % M;
        return tmp * fact[a] % M;
    }
};



int main()
{

    ll n,m;
    cin >> n >> m;
    ll ans = 1;
    
    combination C(200000);
    
    for (ll i = 2; i <= m; i++) {
        if(m%i!=0) continue;
        ll p = 0;
        while (m%i==0) {
            m/=i;
            p++;
        }
        if(p){
            //cout << p << " " << C.com(p+n-1,n-1) << endl;;
            ans *= C.com(p+n-1,n-1);
            ans %= mod;
        }
        if(m == 1) break;
    }
    out(ans%mod);

    

    return 0;
}


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

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define each(i,c) for(__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define all(v) v.begin(), v.end()
#define mset(a, n) memset(a, n, sizeof(a))

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;

const int INF = 1000000000;
const int MOD = 1000000007;
const double eps = 1e-9;

int main(int argc, char *argv[]) {
    // cin.tie(0);
    // ios::sync_with_stdio(false);
    string X; cin >> X;

    stack<char> S;
    rep(i, X.size()) {
        if (S.empty()) {
            S.push(X[i]);
            continue;
        }
        if (X[i] == 'S') S.push(X[i]);
        else {
            char s = S.top();
            if (s == 'S') S.pop();
            else S.push(X[i]);
        }
    }

    cout << S.size() << endl;
    return 0;
}

Measured memory_bytes: 644
#include <iostream>
#define llint long long
#define mod 1000000007

using namespace std;

llint n, k;
llint dp[2005][2005];

const int FACT_MAX = 4000005;
llint fact[FACT_MAX], fact_inv[FACT_MAX];

llint modpow(llint a, llint n)
{
	if(n == 0) return 1;
	if(n % 2){
		return ((a%mod) * (modpow(a, n-1)%mod)) % mod;
	}
	else{
		return modpow((a*a)%mod, n/2) % mod;
	}
}

void make_fact()
{
	llint val = 1;
	fact[0] = 1;
	for(int i = 1; i < FACT_MAX; i++){
		val *= i;
		val %= mod;
		fact[i] = val;
	}
	fact_inv[FACT_MAX-1] = modpow(fact[FACT_MAX-1], mod-2);
	for(int i = FACT_MAX-2; i >= 0; i--){
		fact_inv[i] = fact_inv[i+1] * (i+1) % mod;
	}
}

llint comb(llint n, llint k)
{
	llint ret = 1;
	ret *= fact[n];
	ret *= fact_inv[k], ret %= mod;
	ret *= fact_inv[n-k], ret %= mod;
	return ret;
}

int main(void)
{
	cin >> n >> k;
	make_fact();
	if(k == 1){
		cout << 1 << endl;
		return 0;
	}
	
	dp[1][1] = 1;
	for(int i = 1; i < n; i++){
		llint sum = 0;
		for(int j = i; j >= 0; j--){
			sum += dp[i][j], sum %= mod;
			dp[i+1][j+1] = sum * comb(i*k-j+k-2, k-2) % mod, dp[i+1][j+1] %= mod;
		}
	}
	
	llint ans = 0;
	for(int i = 1; i <= n; i++) ans += dp[n][i], ans %= mod;
	ans *= fact[n], ans %= mod;
	cout << ans << endl;

	
	return 0;
}

Measured memory_bytes: 94080
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b;
  cin>>a>>b;
  if(a==b)cout << "Draw" <<endl;
  else if(a==1)cout<< "Alice"<<endl;
  else if(b==1)cout<< "Bob" <<endl;
  else if(a>b)cout<<"Alice"<<endl;
  else cout<<"Bob"<<endl;
  
}

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

F=[0]*(M+1)

for i in range(N):
    a=A[i]
    b=a

    if F[b]<=1:
        while b<=M:
            F[b]+=1
            b+=a
    

T=0
for i in range(N):
    if F[A[i]]==1:
        T+=1

print(T)


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

int main(){
 int a=0,w=0,t=0,r=0;
 int n;
 cin >> n;
 for(int i=0;i<n;i++){
   string s;
   cin >> s;
   if(s=="AC") a++;
   if(s=="WA") w++;
   if(s=="TLE") t++;
   if(s=="RE") r++;
 }
 
 cout << "AC x " << a << endl;
 cout << "WA x " << w << endl;
  cout << "TLE x " << t << endl;
  cout << "RE x " << r << endl;
}

Measured memory_bytes: 3628
//In The Name of Allah
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

template < class T > using Tree = tree < T , null_type , less < T > , rb_tree_tag , tree_order_statistics_node_update >;

typedef long long            ll;
typedef long double          ld;
typedef string               str;
typedef pair < ll , ll >     pll;

#define X               first
#define Y               second
#define pb              push_back
#define all(x)			(x).begin(), (x).end()
#define SZ(x) 			(ll)(x.size())
#define sep             ' '
#define fast_io         ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define dbl_io(x)       cout << fixed << setprecision(x);

const int N = 1e5 + 10;
const ll mod = 1e9 + 7;
const ll inf = 1e18 + 10;

string s;
ll ans = 0, a[20];

void f(ll n){
	if (n == s.size()){
		ll res = 0;
		for (ll i = 0; i < s.size(); i ++){
			res = res * 10 + (s[i] - '0');
			if (a[i + 1])
				ans += res, res = 0;
		}
		ans += res;
		return ;
	}
	a[n] = 1;
	f(n + 1);
	a[n] = 0;
	f(n + 1);
}

int main(){
    fast_io
    //dbl_io(10);
    cin >> s;
    f(1);
    cout << ans;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
    ll n,p;
    cin>>n>>p;
    string s;
    cin>>s;
    if(p==2 || p==5)
    {
        ll ans=0;
        for(ll i=0;i<n;i++)
        {
            if((s[i]-'0')%p==0)
                ans+=(i+1);
        }
        cout<<ans;
        return 0;
    }
    ll ar[n+1];
    ar[0]=0;
    for(ll i=0;i<n;i++)
    {
        ar[i+1]=((ar[i]*10)+s[i]-'0')%p;
    }
    ll temp=1;
    for(ll i=n;i>0;i--)
    {
        ar[i]=(ar[i]*temp)%p;
        temp=(temp*10)%p;
    }
    map<ll,ll>m;
    for(ll i=0;i<=n;i++)
    {
        m[ar[i]]+=1;
    }
    ll ans=0;
    for(auto i=m.begin();i!=m.end();i++)
    {
        ans+=(i->second)*(i->second-1)/2;
    }
    cout<<ans;
	return 0;
}

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

using namespace std;

int gcd(int x, int y){
    if(x < y) swap(x, y);
    if(y == 0) return x;

    return gcd(x%y, y);
}

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

    int L[N], R[N], X[N];
    L[0] = A[0]; R[N-1] = A[N-1];
    for(int i = 1; i < N; i++) {
        L[i] = gcd(L[i-1], A[i]);
    }
    for(int i = N-2; i >= 0; i--) {
        R[i] = gcd(R[i+1], A[i]);
    }
    
    X[0] = R[1]; X[N-1] = L[N-2];
    for(int i = 1; i < N-1; i++) {
        X[i] = gcd(L[i-1], R[i+1]);
    }

    int ans = X[0];
    for(int i = 0; i < N; i++) {
        ans = max(ans, X[i]);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1792
#include <cstdio>
using namespace std;

inline int max (const int p, const int q) {return p > q ? p : q;}

const int N = 100003;
char s[N];
int n, fa[N], ans;

int Find (const int p) {return fa[p] == p ? p : fa[p] = Find (fa[p]);}

int main () {
	scanf ("%d", &n);
	scanf ("%s", s + 1);
	int i; for (i = 1; i <= n; ++i) fa[i] = i;
	for (i = 1; i < n; ++i) {
		if (s[i] == s[i + 1]) fa[Find (i)] = fa[Find (i + 1)];
	}
	for (i = 1; i <= n; ++i) {
		if (Find (i) == i) ++ans;
	}
	printf ("%d\n", ans);
	return 0;
}

Measured memory_bytes: 2176
#include<stdio.h>
int main()
{
	int n,m,i,j,k,l,f=1;
	char a[51][51],b[51][51];

	scanf("%d%d",&n,&m);
	for(i=0;i<n;i++)
		scanf("%s",a[i]);
	for(i=0;i<m;i++)
		scanf("%s",b[i]);

	for(i=0;i<=n-m;i++)
		for(j=0;j<=n-m;j++){
			for(k=i;k<i+m;k++)
				for(l=j;l<j+m;l++)
					if(a[k][l]!=b[k-i][l-j])
						f=0;
			if(f){
				puts("Yes");
				return 0;
			}
			f=1;
		}
	puts("No");
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <math.h> 
#include <string>
#include <iomanip>
using namespace std;
int main(){
  int y, m, d;
  char a, b;
  cin >> y >> a >> m >> b >> d;
  if(y >= 2019 && m > 4) cout << "TBD" << endl;
  else cout << "Heisei" << endl;
}
  

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

static const int MAX=10;

int n,m;
int d[MAX]={}; //チェックカウンタ
int R[MAX][MAX]={}; //隣接行列
bool all_visit;

int dfs(int x){
    all_visit=true;
    for(int i=0;i<n;i++){
        if(d[i]==0){
            all_visit=false;
        }
    }

    if(all_visit) return 1;

    int ans=0;

    for(int i=0;i<n;i++){
        if(d[i]==0&&R[x][i]!=0){
            d[i]=1;
            ans+=dfs(i);
            d[i]=0;
        }
    }
    return ans;
}

int main(){
    cin >> n >> m;
    for(int i=0;i<m;i++){
        int a,b;
        cin >> a >> b;
        a--;b--;
        R[a][b]++;
        R[b][a]++;
    }
    d[0]=1;
    cout << dfs(0) << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cmath>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <vector>

// Acknowledgement: Special thanks to kyomukyomupurin, who developed this
// template.
template <class T, class U>
std::ostream& operator<<(std::ostream& os, const std::pair<T, U>& p) {
  return os << '(' << p.first << ", " << p.second << ')';
}

template <class T>
std::ostream& operator<<(std::ostream& os, const std::vector<T>& vec) {
  int n = 0;
  for (auto e : vec) os << (n++ ? ", " : "{") << e;
  return os << (n ? "}" : "{}");
}

template <class T>
std::ostream& operator<<(std::ostream& os, const std::set<T>& st) {
  int n = 0;
  for (auto e : st) os << (n++ ? ", " : "{") << e;
  return os << (n ? "}" : "{}");
}

template <class T, class U>
std::ostream& operator<<(std::ostream& os, const std::map<T, U>& mp) {
  int n = 0;
  for (auto e : mp) os << (n++ ? ", " : "{") << e;
  return os << (n ? "}" : "{}");
}

template <class T>
std::istream& operator>>(std::istream& is, std::vector<T>& vec) {
  for (T& e : vec) is >> e;
  return is;
}

#ifdef LOCAL
#define debug(...) \
  std::cerr << "[" << #__VA_ARGS__ << "]: ", debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

void debug_out() { std::cerr << '\n'; }

template <class Head, class... Tail>
void debug_out(Head&& head, Tail&&... tail) {
  std::cerr << head;
  if (sizeof...(Tail) != 0) std::cerr << ", ";
  debug_out(std::forward<Tail>(tail)...);
}
using namespace std;
using int64 = long long;

constexpr int64 inf = 1e18;

int main() {
  int N;
  cin >> N;
  vector<int64> A(N);
  cin >> A;
  for (int i = 0; i < N; i++) {
    if (A[i] == 0) {
      cout << 0 << endl;
      return 0;
    }
  }
  int64 result = 1;
  int64 prev_result = 1;
  for (int i = 0; i < N; i++) {
    result *= A[i];
    if (prev_result > result || result > inf) {
      cout << -1 << endl;
      return 0;
    }
    prev_result = result;
  }
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 4052
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.stream.Stream;

public class Main {

  static int binarySearch(long x, int maxIdx){
    int left = 0; int right = maxIdx + 1;
    while(right - left > 1){
      int mid = (right + left) / 2;
      if(bsum[mid] <= x) left = mid;
      else right = mid;
    }
    return left;
  }

  static int n, m;
  static long k;
  static long[] a, b, asum, bsum;

  public static void main(String[] args) throws Exception {

    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    PrintWriter out = new PrintWriter(System.out);

    String[] in = br.readLine().split(" ");
    n = Integer.parseInt(in[0]);
    m = Integer.parseInt(in[1]);
    k = Long.parseLong(in[2]);

    in = br.readLine().split(" ");
    a = Stream.of(in).mapToLong(Long::parseLong).toArray();
    in = br.readLine().split(" ");
    b = Stream.of(in).mapToLong(Long::parseLong).toArray();

    asum = new long[n+1];
    bsum = new long[m+1];

    br.close();

    asum[0] = 0;
    for (int i = 0; i < n; i++) {
      asum[i+1] = asum[i] + a[i];
    }

    bsum[0] = 0;
    for (int i = 0; i < m; i++) {
      bsum[i+1] = bsum[i] + b[i];
    }

    long ans = 0;

    for (int i = 0; i <= n; i++) {
      if(asum[i] > k) {
        break;
      }

      ans = Math.max(ans, i + binarySearch(k - asum[i], m));
    }

    out.println(ans);

    out.flush();

  }
}

Measured memory_bytes: 83764
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
int INF = 1LL << 30;
int MOD = 1e9+7;
main(){
    string S,T;
    cin >> S >> T;
    vector<string> ans;
    for(int i = 0;i+T.size() <= S.size();i++){
        bool flag = 1;
        for(int j = 0;j < T.size();j++){
            if(S[i+j] == '?')continue;
            if(S[i+j] != T[j]){
                flag = 0;
                break;
            }
        }
        if(!flag)continue;
        string st = S;
        for(int j = 0;j < T.size();j++){
            st[i+j] = T[j];
        }
        for(int j = 0;j < st.size();j++)if(st[j]=='?')st[j]='a';
        ans.push_back(st);
        
    }
    sort(ans.begin(),ans.end());
    if(!ans.size())cout << "UNRESTORABLE" << endl;
    else cout << ans[0] << endl;
}

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;
 
/*******  All Required define Pre-Processors and typedef Constants *******/
#define mem(a, b) memset(a, (b), sizeof(a))
#define rep(i, k) for (int i = 0; i < k; i++)
#define repA(i, a, n) for (int i = a; i <= (n); ++i)
#define repD(i, a, n) for (int i = a; i >= (n); --i)
#define all(cont) cont.begin(), cont.end()
#define mp make_pair
#define pb push_back
#define INF 1e9
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
#define LLINF 1e14
#define sz(a) int(a.size())
#define ff first
#define ss second
 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef vector<ii> vp;
typedef vector<vp> vvp;
typedef long double ld;
ld a[55];
int main(int argc, char const *argv[])
{
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        int n; cin >> n;
        rep(i, n) cin >> a[i];
        sort(a, a + n);
        ld ans = (a[0] + a[1]) / 2;
        repA(i, 2, n - 1) ans = (ans + a[i]) / 2;
        cout << ans << '\n';
		return 0;    
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int i[11111111];
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int a,b,c,d=0;
  string s;
  cin >>s;
  for(int n=0;n<s.size();n++){
    if(s[n]=='+') d++;
    else d--;
  }
  cout <<d<<'\n';
  return (0);
}


Measured memory_bytes: 256
def inpl(): return list(map(int, input().split()))
N = int(input())
C = [int(input()) for _ in range(N)] + [0]
ans = 0
for k in range(N):
    c = C[k]
    ans += c//2
    if c%2 and C[k+1]:
        ans += 1
        C[k+1] -= 1
print(ans)

Measured memory_bytes: 7920
import java.util.Scanner;

public class Main {

    void solve() {
        Scanner sc = new Scanner(System.in);
        String S = sc.next();

        String part1 = S.substring(0, 2);
        String part2 = S.substring(2);

        int num1 = Integer.parseInt(part1);
        int num2 = Integer.parseInt(part2);

        if ((1 <= num1 && num1 <= 12) && (1 <= num2 && num2 <= 12)) {
            System.out.print("AMBIGUOUS");
        }
        else if (!(1 <= num1 && num1 <= 12) && (1 <= num2 && num2 <= 12)) {
            System.out.print("YYMM");
        }
        else if ((1 <= num1 && num1 <= 12) && !(1 <= num2 && num2 <= 12)) {
            System.out.print("MMYY");
        }
        else {
            System.out.print("NA");
        }
    }

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

Measured memory_bytes: 21844
fn main() {
    let n = read::<usize>();
    let a = read_vec::<i64>();
    let ans = (-100..101)
        .map(|x| a.iter().map(|&num| (num - x) * (num - x)).sum::<i64>())
        .min()
        .unwrap();
    println!("{}", ans);
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include <boost/multiprecision/cpp_int.hpp>
//typedef boost::multiprecision::cpp_int ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);



int main(){
    ll n,x;cin>>n>>x;
    if(x==1 || x==2*n-1){
        cout<<"No"<<endl;
    }else{
        cout<<"Yes"<<endl;
        ll a[2*n-1];rep(i,0,2*n-2)a[i]=0;
        bool b[2*n];rep(i,1,2*n-1)b[i]=true;
        a[n-1]=x;b[x]=false;
        if(n==2){
            a[0]=1;b[1]=false;a[2]=3;b[3]=false;
        }else{
            if(x==2){
                a[n-2]=1;b[1]=false;
                a[n-3]=x+1;b[x+1]=false;
                a[n]=x+2;b[x+2]=false;
            }else{
                a[n-2]=x+1;b[x+1]=false;
                a[n-3]=1;b[1]=false;
                a[n]=2;b[2]=false;
            }
        }
        ll j=1;
        rep(i,0,2*n-2){
            while(!b[j]){
                j++;
                if(j==2*n)break;
            }
            if(j==2*n)break;
            if(a[i]==0){
                a[i]=j;
                j++;
            }
        }
        rep(i,0,2*n-2){
            cout<<a[i]<<endl;
        }
        
    }
    
    
    return 0;
}



Measured memory_bytes: 3200
def main():
    # x in [1, 100]
    # n in [0, 100]
    # p_i in [1, 100] 
    x, n = (int(i) for i in input().split())
    if n > 0:
        p = set(int(i) for i in input().split())
    else:
        p = set() 

    b, e = x, x
    while b in p and e in p:
        b -= 1
        e += 1

    if b not in p:
        print(b)
    else:
        print(e)


main()


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

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int z = sc.nextInt();
        int[] num = new int[3];
        for(int i = 0; i < z; i++){
            for(int j = 0; j < num.length; j++){
                num[j] = sc.nextInt();
            }
            Arrays.sort(num);
            if(num[0]*num[0] + num[1]*num[1] == num[2]*num[2]){
                System.out.println("YES");
            }else{
                System.out.println("NO");
            }
        }
    }
}

Measured memory_bytes: 33856
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <functional>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <bitset>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> P;
#define rep(i,a,n) for(ll i = (a);i < (n);i++)
#define per(i,a,n) for(ll i = (a);i > (n);i--)
#define lep(i,a,n) for(ll i = (a);i <= (n);i++)
#define pel(i,a,n) for(ll i = (a);i >= (n);i--)
#define clr(a,b) memset((a),(b),sizeof(a))
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define sz size()
#define print(X) cout << (X) << endl
const ll INF = 1e+15+7;
ll n,m,l;
string s,t;
ll d[10001],dp[100][100];

int main(){
  vector<ll> vec;
  ll total = 0;
  cin >> n;
  rep(i,0,n){
    cin >> m;
    vec.pb(m);
    total += m;
  }
  ll ans = INF,sum = 0;
  rep(i,0,vec.sz){
    sum += vec[i];
    if(i+1 < n)ans = min(ans,abs(total-2*sum));
  }
  print(ans);
  return 0;
}

Measured memory_bytes: 2420
h, w, k = gets.split.map(&:to_i)
graph = []
h.times do
  graph << gets.chomp.split('')
end

black = graph.flatten.count('#')
minus = black - k

answer = 0

[0, 1].repeated_permutation(h + w) do |bits|
  tmp_graph = Marshal.load(Marshal.dump(graph))
  count = 0

  bits.each.with_index do |bit, i|
    next if bit == 0

    if i < h
      tmp_graph[i].each.with_index do |cell, num|
        if cell == '#'
          tmp_graph[i][num] = 'X'
          count += 1
        end
      end
    else
      tmp_graph.each.with_index do |row, num|
        if row[i - h] == '#'
          tmp_graph[num][i - h] = 'X'
          count += 1
        end
      end
    end

  end
  answer += 1 if count == minus
end

puts answer


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

int main(void){
   int n;cin >> n;
   
   int sum = 0;
   bool frag = true;
   int low = 1e9;
   rep{
     int a;
     cin >> a;
     sum += a;
     if(a % 10 != 0){
       frag = false;
     }
     if(a % 10 != 0){
      low= min(low,a);
     }
   }
   if(frag == true){
     cout << 0 << endl;
   }else if(sum % 10 == 0){
     cout << sum - low << endl;
   }else{
     cout << sum << endl;
   }
}

Measured memory_bytes: 256
using System;
using System.Linq;

namespace ITP1 {
	class Program {
		public static void Main() {
			int[] input = Console.ReadLine()
				.Split()
				.Select(int.Parse)
				.ToArray();
			int w = input[0],
				h = input[1],
				x = input[2],
				y = input[3],
				r = input[4];
			if (x - r >= 0 && x + r <= w
				&& y - r >= 0 && y + r <= h) Console.WriteLine("Yes");
			else Console.WriteLine("No");
		}
	}
}



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

int main() {
  long long a, b, k; cin >> a >> b >> k;
  
  if(k <= a) cout << a - k << ' ' << b <<endl;
  else if(k <= a+b) cout << 0 << ' ' << b - (k-a) <<endl;
  else cout << 0 << ' ' << 0 <<endl;
  
  return 0;
}

Measured memory_bytes: 256
/**
    color(i,j) != color(i+1,j)
    RBRBRB.../BRBRBR.. :  color(i,j) = color(i+1,j)
    f[i][j] = so cach to cot 1->i, dong h[j] -> max
    f[i][h[i]] = 2*.... (+ them x2 truong hop noi tren)
*/


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

using namespace std;

const int maxn = 110;
const int base = 1e9+7;

int n,a[maxn];
ll f[maxn][maxn];
map<int,int> cnt;
vector<int> h;

ll pw(int a,int n) {
    if (n==0) return 1ll;
    if (n==1) return a;
    ll tmp = pw(a,n/2);
    tmp = (tmp*tmp)%base;
    if (n%2==0) return tmp;
    return (tmp*a)%base;
}

int main() {
   // freopen("in.txt","r",stdin);
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin>>n;
    for (int i=1;i<=n;i++) {
        cin>>a[i];
        if (cnt[a[i]]!=0) continue;
        h.push_back(a[i]);
        cnt[a[i]]=1;
    }
    cnt.clear();
    h.push_back(0);
    sort(h.begin(),h.end());
    h.erase(unique(h.begin(),h.end()),h.end());
    for (int j=0;j<h.size();j++) cnt[h[j]]=j;
    for (int j=0;j<h.size();j++)
        if (h[j] == 0) f[1][j] = pw(2,a[1]);
        else if (h[j] <= a[1]) f[1][j] = pw(2,a[1] - h[j]+1);
    for (int i=2;i<=n;i++) {
        if (a[i] < a[i-1]) {
            int mi = cnt[a[i]];
            for (int j=0;j<h.size();j++)
                if (h[j] <= a[i])
                    f[i][j] = (f[i-1][j] + f[i-1][mi])%base;
        } else {
            int mi = cnt[a[i-1]];
            for (int j=0;j<h.size();j++) {
                if (h[j] <= a[i-1]) f[i][j] = ((f[i-1][j] + f[i-1][mi])%base * pw(2,a[i] - a[i-1])) % base;
                else if (h[j] <= a[i]) f[i][j] = (pw(2,a[i] - h[j]+1) * f[i-1][mi]) % base;
            }
        }
    }
    cout<<f[n][0]<<endl;

}


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

using namespace std;

int main() {
    string s; cin >> s;
    int n = s.size();
    for (int i = 0; i < n; i++) if (s[i] != s[n - i - 1]) return cout << "No\n", 0;
    n /= 2;
    for (int i = 0; i < n; i++) if (s[i] != s[n - i - 1]) return cout << "No\n", 0;
    cout << "Yes\n";

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

int gcd(int n, int m) {
    if (n < m) swap(n, m);
    while (m != 0) {
        int r = n % m;
        n = m;
        m = r;
    }
    return n;
}

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

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

    string s, t;
    cin >> s >> t;

    ll r = (ll)n * m;

    int b = 1;
    ll j = 0;
    for (ll i = 0; i < r; i += m) {
        while (j < i) j += n;
        if (i != j) continue;
        if (s[i / m] != t[j / n]) b = 0;
    }

    r /= gcd(n, m);
    if (!b) r = -1;

    cout << r << endl;

    return 0;
}

Measured memory_bytes: 640
import collections
import scipy.misc
import sys
import numpy as np
from operator import itemgetter

def prime_decomposition(n):
  i = 2
  table = []
  while i * i <= n:
    while n % i == 0:
      n /= i
      table.append(int(i))
    i += 1
  if n > 1:
    table.append(int(n))
  return table   

"""
N, X = map(int, input().split())

x = [0]*N
x[:] = map(int, input().split())
"""

N = int(input())
T, A = map(float, input().split())
H = [0.]*N
H[:] = map(float, input().split())


TH = [0.]*N
dTH = [0]*N
for i in range(N):
    TH[i] = T - H[i]*0.006
    dTH[i] = abs(A - TH[i])
print(dTH.index(min(dTH))+1)

Measured memory_bytes: 21780
#pragma region
#include <bits/stdc++.h>
using namespace std;
inline void ci(void){
  return;
}
template <typename First, typename... Rest>
void ci(First& first, Rest&... rest){
  cin >> first;
  ci(rest...);
  return;
}
inline void co(void){
  cout << endl;
  return;
}
template <typename First, typename... Rest>
void co(First first, Rest... rest){
  cout << first << "";
  co(rest...);
  return;
}
#define ll long long
#define ld long double
#define st string
#define wh while
#define ve vector
#define mp make_pair
#define tp tuple
#define mt make_tuple
#define pb push_back
#define pof pop_front
#define pob pop_back
#define pf push_front
#define fr front
#define ft first
#define sc second
#define tos to_string
#define len length
#define rt return
#define br break
#define con continue
#define lcm(n, m) (n * m / gcd(n, m))
#define np next_permutation
#define repi(i, m, n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i, n) repi(i, 0, n)
#define repill(i, m, n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define repll(i, n) repill(i, 0, n)
#define revi(i, m, n) for(int i=(int)(m);i>(int)(n);i--)
#define rev(i, m) revi(i, m, 0)
#define revill(i, m, n) for(ll i=(ll)(m);i>(ll)(n);i--)
#define revll(i, n) revill(i, 0, n)
#define sz(v) ((int)(v).size()) 
#define each(i, n) for(auto&& i: n)
#define all(n) (n.begin(), n.end())
#define allr(n) (n.rbegin(), n.rend())
#define sp(n) cout << fixed << setprecision(n)
#define inf pow(10, 9)
#pragma endregion
// sqrt ルート, int 2*10^9, gcd　最大公約数
// __builtin_popcount bitの個数

ve<int> dx = {0, 0, 1, -1}, dy = {1, -1, 0, 0};

int main() {
  int N;
  ci(N);
  ve<pair<int, int>> X(N);
  rep(i, N){
    int x, l;
    ci(x, l);
    X.at(i) = mp(l + x, x - l);
  }
  sort all(X);
  int c = - inf, a = 0;
  rep(i, N){
    if(c <= X.at(i).sc){
      c = X.at(i).ft;
      a++;
    }
  }
  co(a);
}

Measured memory_bytes: 1024
n_a, n_b, n_m=map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
total = min(a) + min(b)
for i in range(n_m):
    x, y, c = list(map(int,input().split()))
    _total = a[x - 1] + b[y - 1] - c
    if _total < total:
        total = _total
print(total)


Measured memory_bytes: 18740
#include<cstdio>
#include<cmath>
#include<climits>
#include<algorithm>
#include<sstream>
#include<iostream>
#include<string>
#include<queue>
#include<stack>
#include<set>
#include<list>
#include<map>
#include<vector>

using namespace std;


#define rep(i,n) for(int i=0; i<n; i++)
#define rept(i,a,b) for(int i=a; i<b; i++)
#define ll long long

#define IMIN INT_MIN;
#define IMAX INT_MAX;


int main(){
	ll N;
	cin >> N;
	ll num;
	ll mind=1000000000000001;
	ll mini=0;
	ll sum;
	ll dp[5];
	rep(i, 5) cin >> dp[i];
	rep(i, 5) {
		if (mind >= dp[i]){
			mind = dp[i];
			mini = i;
		}
	}
	sum = mini+1;
	if (N % mind != 0) sum += N / mind;
	else sum += N / mind - 1;
	sum += 5-mini-1;
	if (mind >= N) cout << 5 << endl;
	else cout << sum << endl;

	return 0;
}



Measured memory_bytes: 256
/*************************************************************************
  >         File: D.cc
  >       Author: lyyllyyl
  >         Mail: riho.yoshioka@yandex.com
  > Created Time: Sun 27 Nov 2016 12:20:21 AM JST
*************************************************************************/
#include <bits/stdc++.h>

const int N = 1e5 + 5;
std::map<int, int> cnt[N];

int main() {
  std::ios::sync_with_stdio(0);
  int n, m;
  std::cin >> n >> m;
  for (int i = 0; i < n; ++i) {
    int x;
    std::cin >> x;
    cnt[x % m][x]++;
  }
  int ans = 0;
  for (int i = 1, j = m - 1; i < j; i++, j--) {
    int a = 0, b = 0, c = 0, d = 0;
    for (auto &p: cnt[i]) {
      a += p.second - (p.second & 1);
      b += p.second & 1;
    }
    for (auto &p: cnt[j]) {
      c += p.second - (p.second & 1);
      d += p.second & 1;
    }
    if (b < d) {
      std::swap(b, d);
      std::swap(a, c);
    }
    ans += d;
    b -= d;
    ans += a / 2;
    if (b >= c) {
      ans += c;
    } else {
      ans += b;
      c -= b;
      ans += c / 2;
    }
  }
  int add = 0;
  for (auto &p: cnt[0]) {
    ans += p.second / 2;
    if (p.second & 1) add++;
  }
  ans += add / 2;
  if (!(m & 1)) {
    int add = 0;
    for (auto &p: cnt[m / 2]) {
      ans += p.second / 2;
      if (p.second & 1) add++;
    }
    ans += add / 2;
  }
  std::cout << ans << std::endl;
  return 0;
}


Measured memory_bytes: 9600
n, x = map(int, input().split())
a = list(map(int, input().split()))
ans = 0
if sum(a) == x:
  ans = n
elif x < min(a):
  ans = 0
else:
  if sum(a) < x:
    ans = n - 1
  else:
    a.sort()
    k = 0
    for e in a:
      k += e
      if k <= x:
        ans += 1
      else:
        break
print(ans)

Measured memory_bytes: 9128
#include <bits/stdc++.h>
#define FOR(I,X,Y) for(long int I=X;I<Y;I++)
#define REP(I,X) for(long int I=X;I>=0;I--)
#define INF 1e9+7
using namespace std;

int main(){
  string S,T,ans="UNRESTORABLE";
  cin >> S >> T;
  bool flag = 0;
  for(int i = S.size()-T.size();i >= 0;i--){
    flag = 1;
    FOR(j,0,T.size())if(S[i+j] != T[j] && S[i+j] != '?')flag = 0;
    if(flag){
      FOR(j,0,T.size())S[i+j] = T[j];
      ans = S;
      break;
    }
  }
  FOR(i,0,S.size())if(ans[i] == '?')ans[i] = 'a';
  cout << ans << endl;
}


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

int main() {
  
  int X=0;
  int Y=0;
  int N;
  cin>>N;
  
  vector<int> V(N);
for (int i = 0; i < N; i++) {
  cin >> V.at(i);
}
  
  vector<int> C(N);
for (int i = 0; i < N; i++) {
  cin >> C.at(i);
}
  
  for (int i = 0; i < N; i++) {
  if(V.at(i)>C.at(i)){
    X+=V.at(i);
    Y+=C.at(i);
  }
    
}
  
  cout<<X-Y<<endl;
    
 
}
  
  
  
  
  

  
  
  
  

Measured memory_bytes: 256
x, n = gets.split.map(&:to_i)
if n == 0
    p = gets
    puts x
    exit
end
p = gets.split.map(&:to_i)
min = 100
cand = 100
0.upto(200) do |pp|
    next if p.include?(pp)
    diff = (x - pp).abs
    if diff < min
        min = diff
        cand = pp
    end
end
puts cand

Measured memory_bytes: 14368