akhauriyash/Code-Regression huggingface dataset:
/*
    Written by Nitrogens
    Desire for getting accepted!!
*/
#include <cstdio>
#include <ctime>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <queue>
#include <map>
#include <bitset>
#include <stack>
#include <set>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;

const int maxn = 1e5+5;
const int Mod = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const double e = exp(1);
const db PI = acos(-1);
const db ERR = 1e-10;

#define Se second
#define Fi first
#define pb push_back
#define dbg(x) cout<<#x<<" = "<< (x)<< endl
#define dbg2(x1,x2) cout<<#x1<<" = "<<x1<<" "<<#x2<<" = "<<x2<<endl
#define dbg3(x1,x2,x3) cout<<#x1<<" = "<<x1<<" "<<#x2<<" = "<<x2<<" "<<#x3<<" = "<<x3<<endl

int main()
{
    //ios::sync_with_stdio(false);
    //freopen("a.txt","r",stdin);
    //freopen("b.txt","w",stdout);

    int x;
    scanf("%d", &x);
    int delta = 1, ans = 0;
    while (x > 0) {
        x -= delta;
        delta++;
        ans++;
    }
    printf("%d\n", ans);

    //cout << "time: " << (long long)clock() * 1000 / CLOCKS_PER_SEC << " ms" << endl;
    return 0;
}


Measured memory_bytes: 384
h, w, k = map(int, input().split())
cake_map = []
for i in range(h):
    cake_map.append(list(input()))
pop_num = 0
while True:
    s_flg = 0
    for j in range(w):
        if cake_map[0][j] == '#':
            s_flg += 1
    if s_flg != 0:
        break
    cake_map.pop(0)
    pop_num += 1
s_id = 1
s_cnt = 0
h = len(cake_map)
for i in range(h):
    s_flg = 0
    for j in range(w):
        if cake_map[i][j] == '#':
            s_flg += 1
    if s_flg == 0:
        for j in range(w):
            cake_map[i][j] = cake_map[i - 1][j]
    else:
        for j in range(w):
            if cake_map[i][j] == '#':
                s_cnt += 1
                if s_cnt >= 2:
                    s_cnt = 1
                    s_id += 1
            cake_map[i][j] = s_id
        s_id += 1
    s_cnt = 0
for i in range(h):
    while pop_num > 0:
        for j in range(w):
            if j == w - 1:
                print(cake_map[0][j])
            else:
                print(cake_map[0][j], end = " ")
        pop_num -= 1
    for j in range(w):
        if j == w - 1:
            print(cake_map[i][j])
        else:
            print(cake_map[i][j], end = " ")

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

typedef long long ll;

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

int main() {
    int N;
    cin >> N;
    vector<int> L(N);
    rep(i, N) cin >> L[i];
    sort(L.begin(), L.end());
    int ans = 0;
    for (auto itr1 = L.begin(); itr1 != L.end()-2; itr1++){
        for (auto itr2 = itr1 + 1; itr2 != L.end()-1; itr2++) {
            auto right = lower_bound(itr2, L.end(), *itr2 + *itr1);
            ans += distance(itr2+1, right);
        }
    }
    cout << ans << endl;
}


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

int main(){
    ll d,g,ans=1001;
    cin >> d >> g;
    vector<ll> p(d),c(d),all(d);
    for(int i = 0;i < d;i ++){
        cin >> p[i] >> c[i];
        all[i]=100*(i+1)*p[i]+c[i];
    }
    // {0, 1, ..., d-1} の部分集合の全探索
    for (int bit = 0; bit < (1<<d); ++bit){
        ll s=0,cnt=0;
        for(int i = 0;i < d;i ++){
            if(bit&(1<<i)){
                s += all[i];
                cnt += p[i];
            }
        }
        if(s>=g) {ans = min(ans,cnt);continue;}
        else{
            int j;
            for(int i = d-1;i >= 0;i --){
                if(!(bit&(1<<i))){j=i;break;}
            }
            if(s+100*(j+1)*(p[j]-1)<
            g) continue;
            else{
                cnt += (g-s)/(100*(j+1))+((g-s)%(100*(j+1))!=0);
            }
            ans = min(ans,cnt);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 1000000;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

///////////////////////////





int main() {

	int N;

	cin >> N;

	ll x[200], y[200];
	repn(i, N) cin >> x[i] >> y[i];

	ll ans = 0;

	repn(i, N) {
		ll testx = y[i];
		ll testy = -x[i];

		ll nowx = 0;
		ll nowy = 0;
		repn(j, N) {
			if (x[j] * testx + y[j] * testy >= 0) {
				nowx += x[j];
				nowy += y[j];
				//cout << j<<" ";
			}
		}
		//cout << nowx << nowy << endl;

		ans = max(ans, nowx*nowx + nowy * nowy);

		//////////////////////////////////////

		repn(j, N) {
			if (x[i]*y[j]==x[j]*y[i]&&(x[i]*x[j]>0||y[i]*y[j]>0)) {
				nowx -= x[j];
				nowy -= y[j];
				//cout << j << " ";
			}
		}
		//cout << nowx << nowy << endl;

		ans = max(ans, nowx*nowx + nowy * nowy);

		//////////////////////////////////

		testx = -y[i];
		testy = x[i];

		nowx = 0;
		nowy = 0;
		repn(j, N) {
			if (x[j] * testx + y[j] * testy >= 0) {
				nowx += x[j];
				nowy += y[j];
				//cout << j<<" ";
			}
		}
		//cout << nowx << nowy << endl;

		ans = max(ans, nowx*nowx + nowy * nowy);

		///////////////////////////////////
		nowx = 0;
		nowy = 0;
		repn(j, N) {
			if (x[i] * y[j] == x[j] * y[i] && (x[i] * x[j] > 0 || y[i] * y[j] > 0)) {
				nowx -= x[j];
				nowy -= y[j];
				//cout << j << " ";
			}
		}
		//cout << nowx << nowy << endl;

		ans = max(ans, nowx*nowx + nowy * nowy);
	}

	cout << fixed << setprecision(13);

	cout << sqrt((double)ans);

	system("PAUSE");
}


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
using llint = long long;
using vint = vector<int>;

int main () {
    int n; cin >> n;
    string s; cin >> s;
    if (n % 2 != 0) {
        cout << "No\n";
        return 0;
    }
    int x = n / 2;
    int count = 0;
    bool ans = false;
    for (int i = 0; i < x; i++) {
        if (s[i] == s[x + i]) {
            count++;
            if (count == x) ans = true;
        }
    }

    if (ans == true) cout << "Yes\n";
    else cout << "No\n";
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <bits/c++io.h>
#include <algorithm>
#include <iomanip>
#include <math.h>
using namespace std;

int main()
{
 int x,y,z;
 cin>>x>>y>>z;
 if(abs(x-y)>abs(x-z))
    cout<<"B"<<endl;
    else
        cout<<"A"<<endl;
}






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

using namespace std;


int main()
{
	ll n,m;
	cin>>n>>m;
	ll arr[m];
	ll sum=0;
	for(int i=0;i<m;i++)
	{
		cin>>arr[i];
		sum+=arr[i];
	}
	
	if(sum > n)
	cout<<-1<<endl;
	else if(sum == n)
	cout<<0<<endl;
	else
	cout<<(n-sum)<<endl;
	
	

	
	return 0;
}
	
	


Measured memory_bytes: 3648
#include<bits/stdc++.h>
//#include<iostream>
//#include<cstdio>
//#include<stdlib.h>
//#include<string.h>
//#include<algorithm>
using namespace std;
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define READ freopen("in.txt","r",stdin)
#define WRITE freopen("out.txt","w",stdout);
#define pb push_back
#define mem(arr,val) memset(arr,val,sizeof(arr))
#define sf(x) scanf("%d",&x)
#define sf2(x,y) scanf("%d %d",&x,&y)
#define sf3(x,y,z) scanf("%d %d %d",&x,&y,&z)
#define sl(x) scanf("%lld",&x)
#define sl2(x,y) scanf("%lld %lld",&x,&y)

#define sl3(x,y,z) scanf("%lld %lld %lld",&x,&y,&z)
#define sd(x) scanf("%lf",&x);
#define pLL pair<long long,long long>
#define pDB pair<double,double>
#define ff first
#define sn second
#define PRINT_CASE  printf("Case %d: ",tc++)
#define PRINT_CASENL  printf("Case %d:\n",tc++)
//#define mx 100005
#define lnd tree[ind<<1]
#define rnd tree[(ind<<1)+1]
#define cnd tree[ind]
#define lndp b,(b+e)>>1,(ind<<1)
#define rndp ((b+e)>>1)+1,e,(ind<<1)+1
#define IN(a,x,y) (a>=x && a<=y)
#define popcountL __builtin_popcountll
#define popcount __builtin_popcount
/// int other=mask^((1<<n)-1);
typedef long long ll;
typedef long long int lln;
typedef pair<int,int> pii;
ll INF=1<<28;
//typedef long long lld;
const double PI=acos(-1.0);
//int fx[]={1,-1,0,0}; //direction array
//int fy[]={0,0,1,-1};
int dir[4][2]={1,0,-1,0,0,-1,0,1};
int knight[8][2]={1,2,1,-2,2,1,2,-1,-1,2,-1,-2,-2,1,-2,-1};
const long double EPS=1e-7;
//#define INF 10000

struct compare
{
  bool operator()(const pair<int,pii>& l, const pair<int,pii>& r)
  {
      if(l.ff==r.ff)
      {
          return l.sn.ff>r.sn.ff;
      }
      return l.ff<r.ff;
  }
};
// bool operator<(pair<int,pii> l, pair<int,pii> r)
//  {
//      if(l.ff==r.ff)
//      {
//          cout<<"ok "<<endl;
//          return l.sn.ff<r.sn.ff;
//      }
//      return l.ff>r.ff;
//  }

/////////////////////////////////////template sesh/////////////////////////////////////////////////////

///code goes from here
const int mx=300150;
///
int mod=1000000007;
double arr[mx];
ll n,k;
bool checkk(double x)
{
    ll lagbe=0;
//    cout<<x<<endl;
    for(int i=0;i<n;i++)
    {
        ll y=ceil(arr[i]/x);
        y-=1;

        lagbe+=y;
//        cout<<arr[i]/x<<endl;
    }
//    cout<<lagbe<<endl;
    if(lagbe<=k)
        return true;
    return false;
}
int main()
{
//    SPEED;
//    mem(dp,-1);
    int t,tc=1;
//    sf(t);
    t=1;

    while(t--)
    {
        sl2(n,k);
        double l=1,r=0;
        for(int i=0;i<n;i++)
        {
            cin>>arr[i];
            r=max(r,arr[i]);
        }
        double ans=r;
        int c=1000;
//        cout<<l<<" "<<r<<endl;
        while(c--)
        {
            double mid=(l+r)/2;
            if(checkk(mid))
            {
                ans=mid;
                r=mid;
            }
            else
                l=mid;
        }
        ll ok=ceil(ans);
        cout<<ok<<endl;

    }


    return 0;
}



Measured memory_bytes: 5420
#include <cstdio>
#include <cmath>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>

#ifdef _DEBUG
#define DMP(x) cerr << #x << ": " << x << "\n"
#else
#define DMP(x) ((void)0)
#endif

const int MOD = 1000000007, INF = 1111111111; 
using namespace std;
using lint = long long;

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	int N;
	cin >> N;

	cout << N / 3 << "\n";

	return 0;
}

Measured memory_bytes: 256
def pff(m):
    pf = {}
    for i in range(2, int(m ** 0.5) + 1):
        while m % i == 0:
            pf[i] = pf.get(i, 0) + 1
            m //= i
    if m > 1: pf[m] = 1
    return pf
def examB():
    X = I()
    ans = 0
    for i in range(X,0,-1):
        cur = pff(i)
        flag = True
        now = 0
        for j in cur.values():
            if j==1:
                flag = False
            if now==0:
                now = j
            else:
                if now!=j:
                    flag = False
        if flag:
            ans = i
            break
    print(ans)

import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

examB()

Measured memory_bytes: 3668
#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define ull unsigned long long
#define vi vector<ll>
#define vvi vector<vi>
#define BITLE(n) (1LL<<(n))
#define BITCNT(n) (__builtin_popcountll(n))
#define SUBS(s,f,t) (s.substr(f-1,t-f+1))
#define ALL(a) (a).begin(),(a).end()
using namespace std;
struct Grid{ll x,y,t;};
struct Edge{ll to,cost;};
struct Graph{vector<vector<Edge>>E;int V;
  const ll Inf = llINF;const int MAX_V=201010;vector<ll>d;
  Graph(int n):E(n){d.resize(MAX_V);E.resize(n);V=n;}
  void init(){for(int i=0;i<MAX_V;i++)d[i]=Inf;}
  void add_edge(ll from,ll to,ll cost){E[from].pb({to,cost});}
};
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll a,b,c,d,e;
  cin>>a>>b;
  if(b%a==0)cout<<b+a<<endl;
  else cout<<b-a<<endl;
  return 0;
}


Measured memory_bytes: 256
N, L = map(int, input().split())
ans = 0
if L >= 0:
    for i in range(1, N):
        ans += i + L
    print(ans)
else:
    if N-1 + L > 0:
        for i in range(N):
            if i + L != 0:
                ans += i + L
        print(ans)
    else:
        for i in range(N-1):
            if i + L != 0:
                ans += i + L
        print(ans)


Measured memory_bytes: 38384
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 3007;
const int MOD = 998244353;

int sum(int a, int b) {
    return a + b >= MOD ? a + b - MOD : a + b;
}
int sub(int a, int b) {
    return a - b < 0 ? a - b + MOD : a - b;
}
int mul(int a, int b) {
    return (1LL*a*b)%MOD;
}
int pw(int a, int b) {
	if (!b) return 1;
	int r = pw(a, b/2);
	r = mul(r, r);
	if (b%2) r = mul(r, a);
	return r;
}

int A, B, C, D;
int suffix(int col, int hori);

int dp[MAXN][MAXN];
int solve(int col, int hori) {
    assert(hori <= C);
    if (dp[col][hori]!=-1) return dp[col][hori];
    if (col > D) return dp[col][hori] = pw(D, C-hori);
    int ans = mul(hori, solve(col+1, hori));
    ans = sum(ans, suffix(col, hori+1));
    return dp[col][hori] = ans;
}

int fp[MAXN][MAXN];
int suffix(int col, int hori) {
    if (hori > C) return 0;
    if (fp[col][hori]!=-1) return fp[col][hori];
    int ans = sum(solve(col+1, hori), suffix(col, hori+1));
    ans = mul(ans, col-1);
    return fp[col][hori] = ans;
}

int main() {
    memset(dp, -1, sizeof dp);
    memset(fp, -1, sizeof fp);

    cin >> A >> B >> C >> D;
    cout << solve(B+1, A) << endl;

    return 0;
}


Measured memory_bytes: 74512
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
#include<complex>
using namespace std;

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = mod * mod;
typedef pair<int, int>P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-6;
const ld pi = acos(-1.0);
typedef vector<vector<ll>> mat;
typedef vector<ll> vec;

void debug(vec &v) {
	int n = v.size();
	rep(i, n) {
		if (i > 0)cout << " ";
		cout << v[i];
	}
	cout << endl;
}


void solve() {
	ll n, m, v, p; cin >> n >> m >> v >> p;
	vector<ll> a(n);
	rep(i, n)cin >> a[i];
	sort(a.begin(), a.end());
	//debug(a);
	int ans = 0;
	vector<ll> ra(n + 1);
	rep(i, n) {
		ra[i + 1] = ra[i] + a[i];
	}
	rep(i, n) {
		int le = i;
		while (i + 1 < n&&a[i] == a[i + 1])i++;
		int num = i - le + 1;
		int up = i + 1;
		if (i >= n - p) {
			ans += num; continue;
		}
		if (up + p - 1 >= v) {
			if (a[i]+m >= a[n - p]) {
				ans += num;
			}
			continue;
		}
		ll need = m * (v - up - (p - 1));

		ll las = m + a[i];
		if (las < a[n-p]) {
			continue;
		}
		int ri = n - p + 1;
		ll sum = (ll)las*(ri-up)-(ra[ri] - ra[up]);
		//ll need = (ll)(v - up)*m;
		//cout << i << " " << ri << endl;
		//cout << i << " " << need << " " << sum << endl;
		if (need <= sum)ans+=num;
	}
	cout << ans << endl;
}


signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(12);
	//init();
	//int t; cin >> t; rep(i, t)solve();
	solve();
	stop
	return 0;
}

Measured memory_bytes: 1792
using System;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Linq;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using System.Security.Cryptography;

class Program
{
    const string Yes = "Yes";
    const string No = "No";
    const char White = '.';
    const char Black = '#';
    const long Mod = 1000000007;

    static void Main(string[] args) {
#if DEBUG
        MyDebugger.Test(process, "../TextFile1.txt");
#else
        object ret = process(new StreamReader(Console.OpenStandardInput()));
        Console.WriteLine(ret);
#endif
    }

    static object process(TextReader input) {
        var s = input.ReadLine();
        var ss = new int[s.Length];
        for(int i=0; i<s.Length; i++) {
            ss[i] = s[i] - '0';
        }

        long sum = 0;

        var bs = new BitSearch(ss.Length - 1);
        do {
            long y = 0;
            long x = ss[0];
            for(int i=1; i<ss.Length; i++) {
                if (bs[i - 1]) {
                    y += x;
                    x = ss[i];
                } else {
                    x = x * 10 + ss[i];
                }
            }
            y += x;
            sum += y;
        }while(bs.Next());

        return sum;
    }

    class BitSearch
    {
        private int max;
        private int x;
        public int Length { get; }

        //0~n-1
        public bool this[int i] {
            get {
                var si = Length - i - 1;
                return ((x >> si) & 0x01) == 1;
            }
        }

        public BitSearch(int n) {
            this.Length = n;
            this.max = (int)Math.Pow(2, n) - 1;
            this.x = 0;
        }
        public bool Next() {
            if (x >= max) {
                return false;
            }
            x += 1;
            return true;
        }
        public void Reset() {
            x = 0;
        }
    }

    static long[] ToIntArray(string strs, int n) {
        var ret = new long[n];
        var spl = strs.Split(' ');
        for (int i = 0; i < n; i++)
            ret[i] = long.Parse(spl[i]);
        return ret;
    }
}

Measured memory_bytes: 11092
#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/STACK:256000000")
#define _USE_MATH_DEFINES
#include<iostream>
#include<vector>
#include<string>
#include<stack>
#include<algorithm>
#include<cmath>
#include<set>
#include<queue>
#include<sstream>
#include<utility>
#include<map>
#include<ctime>
#include<cstdio>
#include<cassert>
#include<functional>
#include<unordered_map>
#include<deque>
#include<cmath>





using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef pair<char, char> pcc;
typedef pair<double, double> pdd;

#define show(x) cerr << x
#define debug(x) show(#x << ": " << (x) << endl)

const long double PI = 3.14159265358979323846;
const long double eps = 1e-5;
const ll INF = numeric_limits<int>::max();
const ll LINF = numeric_limits<ll>::max();
//const ll mod = 1000 * 1000 * 1000 + 7;




void solve() {
    ll n, k;
    cin >> n >> k;
    ll res = k;
    for (int i = 1; i < n; ++i)
        res *= k - 1;
    cout << res << endl;

}


//#define LOCAL

int main() {
    ios_base::sync_with_stdio(0);cin.tie(nullptr);cout.tie(nullptr);
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    solve();



#ifdef LOCAL
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif	
    return 0;
}


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

using namespace std;
const int N = 1e5+5;
bool dp[N][2];
int v[N];
int main()
{
    int n;
    cin >> n;
    for (int i = 1; i<=n; i++)
        cin >> v[i];
    dp[1][0] = dp[1][1] = 1;
    for (int i = 2; i<=n; i++)
    {
        if (v[i]>=v[i-1])
            dp[i][0]|=dp[i-1][0];
        if (v[i]>=v[i-1]-1)
            dp[i][0]|=dp[i-1][1];
        if (v[i]-1>=v[i-1])
            dp[i][1]|=dp[i-1][0];
        if (v[i]-1>=v[i-1]-1)
            dp[i][1]|=dp[i-1][1];
    }
    if (dp[n][0] || dp[n][1])
        cout << "Yes";
    else
        cout << "No";
}


Measured memory_bytes: 768
import sys
input = sys.stdin.readline
N, M = map(int, input().split())
A = [0]*M
B = [0]*M
C = [0]*M
for i in range(M):
    A[i], B[i] = map(int, input().split())
    for c in [int(i) for i in input().split()]:
        C[i] |= 1 << (c - 1)

dp = [[float("inf")] * 2 ** N for _ in range(2)]
dp[0][0] = 0
for i, c in enumerate(C):
    for bit in range(2 ** N):
        dp[1][bit] = min(dp[1][bit], dp[0][bit])
        dp[1][c | bit] = min(dp[0][bit] + A[i], dp[1][c | bit])
    dp[0], dp[1] = dp[1], dp[0]
print(dp[0][-1] if dp[0][-1] < float("inf") else - 1)

Measured memory_bytes: 48732
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <random>
#include <chrono>
#include <queue>
#include <math.h>
#include <string>
#include <sstream>

using namespace std;

int main(){
    int n,m;
    cin >> n >> m;
    int d[n+10];
    for (int i=1;i<=n;i++){
        d[i]=1000;
    }
    int ans=0;
    for(int i=1;i<=m;i++){
        int s,c;
        cin >> s >> c;
        if(d[s]!=1000 && d[s]!=c){
            ans=-1;
            break;
        }
        else{
            d[s]=c;
        }
    }
    if(ans!=-1){
    for(int i=1;i<=n;i++){
        if(n!=1 && d[1]==0){
            ans=-1;
            break;
        }
       if(d[i]!=1000) ans+=d[i]*pow(10,n-i);
      
       if(i==1 && d[1]==1000) ans+=pow(10,n-i);
     
    }
    }
    if(n==1 && m==0) cout << 0 << endl;
    else cout << ans << endl;
}



Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <set>
#include <string>
#include <vector>

#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

using namespace std;

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

	vector<int> vec(N);
	rep(i, N) cin >> vec.at(i);
	sort(vec.begin(), vec.end());

	int ret = 0;
	rep(i, K) ret += vec.at(i);

	cout << ret << endl;
	return 0;
}

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

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

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcountll

#define INF 1e16
#define mod 998244353

ll mod_pow(ll a,ll n){
  ll res=1;
  a%=mod;
  while(n>0){
    if(n&1)res=res*a%mod;
    a=a*a%mod;
    n>>=1;
  }
  return res;
}

ll comb(ll n,ll r){
  if(n<0||r<0||n<r)return 0;
  ll res=1;
  rep(i,r){
    (res*=(n-i)%mod)%=mod;
    (res*=mod_pow(i+1,mod-2))%=mod;
  }
  return res;
}

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

  ll M,N,K;
  cin>>M>>N>>K;
  vector<ll> dp(K+1,0);
  dp[0]=0;
  repl(i,1,K){
    dp[i]=mod_pow(i,N)*comb(M,i)%mod;
    ll c=comb(M,i);
    rep(j,i){
      //ll sub=comb(M-j,i-j)%mod;
      ll sub=c;
      sub*=dp[j];
      sub%=mod;
      dp[i]=(dp[i]-sub+mod)%mod;

      
      (c*=mod_pow(M-j,mod-2))%=mod;
      c*=(i-j);
      c%=mod;
    }
  }
  ll res=mod_pow(M,N);
  rep(i,K){
    res=(res-dp[i]+mod)%mod;
  }
  cout<<res<<endl;

  return 0;
}



Measured memory_bytes: 3220
import java.io.IOException;
import java.util.NoSuchElementException;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;

import java.util.Arrays;

public class Main {
    public static void main(String[] args) throws IOException {
        try (
            BufferedReader reader = new BufferedReader(
                new InputStreamReader(System.in))) {
            FastScanner fs = new FastScanner();

            final int N = fs.nextInt();
            fs.nextInt();

            String[] a = new String[N];

            for (int i = 0; i < N; i++) a[i] = fs.next();

            Arrays.sort(a);

            for (int i = 0; i < N; i++) System.out.print(a[i]);

            System.out.println();
        }
    }
}

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        } else {
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() {
        if (hasNextByte()) return buffer[ptr++];
        else return -1;
    }
    private static boolean isPrintableChar(int c) {
        return 33 <= c && c <= 126;
    }
    public boolean hasNext() {
        while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;
        return hasNextByte();
    }
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true) {
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            } else if(b == -1 || !isPrintableChar(b)) {
                return minus ? -n : n;
            } else {
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
            throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() {
        return Double.parseDouble(next());
    }
}


Measured memory_bytes: 22612
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>

using namespace std;

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

#define fi first
#define se second
#define mp make_pair
#define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

const int N = 505;

char A[N][N];
char B[N][N];

int main(){
    fastIO;
    int n, m;
    cin >> n >> m;
    for(int i = 1; i <= n; i ++ )
        for(int j = 1; j <= m ;j ++ )
            A[i][j] = '.', B[i][j] = '.';
    for(int i = 1; i <= n; i ++ ){
        if(i % 2 == 1){
            for(int j = 1; j < m ; j ++ ){
                A[i][j] = '#';
            }
        }
        else{
            A[i][1] = '#';
        }
    }
    for(int i = 1; i <= n; i ++ ){
        if(i % 2 == 1){
            B[i][m] = '#';
        }
        else{
            for(int j = 2; j <= m ; j ++ ){
                B[i][j] = '#';
            }
        }
    }
    char f;
    for(int i = 1; i <= n; i ++ ){
        for(int j = 1; j <= m ; j ++ ){
            cin >> f;
            if(f == '#') A[i][j] = '#', B[i][j] = '#';
        }
    }
    for(int i = 1; i <= n; i ++ ){
        for(int j = 1; j <= m ; j ++ ){
            cout << A[i][j];
        }
        cout << "\n";
    }
    cout << "\n";
    for(int i = 1; i <= n; i ++ ){
        for(int j = 1; j <= m ; j ++ ){
            cout << B[i][j];
        }
        cout << "\n";
    }
    return 0;
}


Measured memory_bytes: 1280
import itertools
import sys
from scipy.sparse.csgraph import csgraph_from_dense
from scipy.sparse.csgraph import dijkstra
input = sys.stdin.readline


n, m, r = map(int, input().split())
visiting_town = list(map(int, input().split()))
edges = [[float('INF')]*n for _ in range(n)]

for i in range(m):
    a, b, c = map(int, input().split())
    edges[a-1][b-1] = c

G = csgraph_from_dense(edges, null_value=float('INF'))
comp_dist = {}
for node in visiting_town:
    dist_list = dijkstra(G, directed=False, indices=node-1)
    comp_dist[node-1] = dist_list

candidates = []
for route in itertools.permutations(visiting_town):
    result = 0
    for _from, to in zip(route[:-1], route[1:]):
        dist = comp_dist[_from-1][to-1]
        result += dist
    candidates.append(result)

print(int(min(candidates)))


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

using namespace std;

vector < int > solve (int N, int A, int pA, int B, int pB)
{
    if (N == 1)
        return {A, B};
    int bitA = (A >> (N - 1)) & 1, bitB = (B >> (N - 1) & 1);
    if (bitA != bitB)
    {
        int mid = 0, pMid = 0;
        if (!(pA ^ bitA))
            mid ++, pMid ^= 1;
        vector < int > firstHalf, secondHalf, ans;
        firstHalf = solve (N - 1, A & ((1 << N) - 1), pA ^ bitA, mid, pMid);
        secondHalf = solve (N - 1, mid, pMid, B & ((1 << N) - 1), pB ^ bitB);
        for (auto it : firstHalf)
            if (bitA) ans.push_back (it | (1 << (N - 1)));
            else ans.push_back (it);
        for (auto it : secondHalf)
            if (bitB) ans.push_back (it | (1 << (N - 1)));
            else ans.push_back (it);
        return ans;
    }
    else
    {
        vector < int > onlyHalf, ans;
        onlyHalf = solve (N - 1, A & ((1 << N) - 1), pA ^ bitA, B & ((1 << N) - 1), pB ^ bitB);
        int currBg = bitA;
        for (auto it : onlyHalf)
        {
            if (currBg) ans.push_back (it | (1 << (N - 1)));
            else ans.push_back (it);
            currBg ^= 1;
            if (currBg) ans.push_back (it | (1 << (N - 1)));
            else ans.push_back (it);
        }
        return ans;
    }
}

int main ()
{
//freopen ("input", "r", stdin);
//freopen ("output", "w", stdout);

int N, pA = 0, A, B, pB = 0;
scanf ("%d %d %d", &N, &A, &B);
for (int i=0; i<N; i++)
    pA ^= (A >> i) & 1,
    pB ^= (B >> i) & 1;
if (pA == pB)
{
    printf ("NO\n");
    return 0;
}
printf ("YES\n");
vector < int > ans = solve (N, A, pA, B, pB);
for (auto it : ans)
    printf ("%d ", it);
printf ("\n");
/*for (int i=1; i<ans.size (); i++)
{
    int curr = ans[i] ^ ans[i - 1];
    assert ((curr & (curr - 1)) == 0);
}*/
return 0;
}


Measured memory_bytes: 1716
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;


public class Main {
	private	static	BufferedReader	br    = null;

	static {
		br  = new BufferedReader(new InputStreamReader(System.in));
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		int[]	aParam  = null;
		int		nSquare = 0;
		int		nDia    = 0;

		while((aParam = parseParam()) != null) {
			if (aParam[0] != 0 && aParam[1] != 0 && aParam[2] != 0) {
				if (aParam[0] == aParam[1]) {
					nDia++;
				}

				if ((aParam[0] * aParam[0] + aParam[1] * aParam[1]) == aParam[2] * aParam[2]) {
					nSquare++;
				}
			}
		}

		System.out.println(nSquare);
		System.out.println(nDia);
	}

	private static int[] parseParam() {
		int[]	aParam = null;
		String	strIn  = null;

		if ((strIn = parseStdin()) != null) {
			String[]	aN = strIn.split(",");
			aParam = new int[3];
			aParam[0] = Integer.parseInt(aN[0]);
			aParam[1] = Integer.parseInt(aN[1]);
			aParam[2] = Integer.parseInt(aN[2]);
		}
		
		return aParam;
	}

	private static String parseStdin() {
		String	strNum = null;

		try {
			String line = br.readLine();
			if (line != null) {
				if (!line.isEmpty()) {
					strNum = line;
				}
			}
		}
		catch (IOException e) {}

		return strNum;
	}
}

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

#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;

int main()
{
    string s, t;
    cin >> s >> t;
    if (s[0] == t[2] && s[1] == t[1] && s[2] == t[0])
        OP("YES");
    else
        OP("NO");

    return 0;
}

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

int V;
std::vector< std::tuple<int, int> > graph[112345];
int dist[112345];
const int INF = (1 << 30);

void dfs(int id) {
  for(std::tuple<int, int> I : graph[id]) {
    int next, cost;
    std::tie(next, cost) = I;
    if( dist[next] != INF ) continue;
    dist[next] = dist[id] + cost;
    dfs(next);
  }
}

int main() {
  scanf("%d", &V);
  for(int i = 1; i < V; ++i) {
    int s, t, w;
    scanf("%d %d %d", &s, &t, &w);
    graph[s].push_back(std::tuple<int, int>(t, w));
    graph[t].push_back(std::tuple<int, int>(s, w));
  }

  for(int i = 0; i < V; ++i) dist[i] = INF;
  dist[0] = 0;
  dfs(0);
  int p = 0;
  for(int i = 1; i < V; ++i) {
    if( dist[p] < dist[i] ) {
      p = i;
    }
  }
  for(int i = 0; i < V; ++i) dist[i] = INF;
  dist[p] = 0;
  dfs(p);
  int q = 0;
  for(int i = 1; i < V; ++i) {
    if( dist[q] < dist[i] ) {
      q = i;
    }
  }
  printf("%d\n", dist[q]);
  
  return 0;
}

Measured memory_bytes: 12492
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define r(i,s,l) for(int i=s;i<l;i++)
#define mod 1000000007
#define INT_BITS 32
#define ld long double
#define pp pair<long long,long long>
#define ss second
#define ff first
#define N 2000005
#define all(a) a.begin(),a.end()
#define pb push_back
using namespace std;
void fast()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
}
 
int main(){
    fast();
    int n;
    cin>>n;
    string s;
    unordered_map<string,int> mp;
    r(i,0,n)
    {
        string s;
        cin>>s;
        sort(all(s));
        mp[s]++;
    }
    ll ct=0;
    for(auto i=mp.begin();i!=mp.end();i++)
    {
        ll x=i->second;
        ct+= (x*(x-1))/2;
    }
    cout<<ct;
	return 0;
}

Measured memory_bytes: 10660
import java.util.*;

class Main {
  public static void main (String[] args) {
    Scanner scanner = new Scanner(System.in);
    while (scanner.hasNext()) {
      int n = scanner.nextInt();
      if (n == 0) {
        break;
      }
      List<Integer> nos = new ArrayList<Integer>();
      List<Double> prs = new ArrayList<Double>();
      for (int ii = 0; ii < n; ii++) {
        Integer no = scanner.nextInt();
        Double at = scanner.nextDouble();
        Double cn = scanner.nextDouble();
        int pos = nos.indexOf(no);
        if (pos != -1) {
          prs.set(pos, prs.get(pos) + at * cn);
        } else {
          nos.add(no);
          prs.add(at * cn);
        }
      }

boolean flag = true;
for (int ii = 0; ii < nos.size(); ii++) {
  if (prs.get(ii) >= 1000000) {
    System.out.println(nos.get(ii));
    flag = false;
  }
}
if (flag) {
  System.out.println("NA");
}
    }
  }
}

Measured memory_bytes: 28132
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ll;
typedef pair<int,int> int_pair;
typedef pair<ll,ll> ll_pair;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
int h,w,c[10][10],a[201][201],cost[10],done[10]={0};

int minthisnum(int x){
  int ans;
  ans=c[x][1];
  FOR(i,0,10){
    if(done[i]){
      ans=min(ans,cost[i]+c[x][i]);
    }
  }
  return ans;
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
  cin>>h>>w;
  cost[1]=0;
  done[1]=1;
  FOR(i,0,10){
    FOR(j,0,10){
      cin>>c[i][j];
    }
  }
  FOR(i,1,h+1){
    FOR(j,1,w+1){
      cin>>a[i][j];
    }
  }
  FOR(j,0,9){
    int a=1001,b,c;
    FOR(i,0,10){
     if(!done[i]){
       c=a;
       a=min(minthisnum(i),a);
       if(c!=a)b=i;
     }
    }
    done[b]=1;
    cost[b]=a;
  }
  int ans=0;
  FOR(i,1,h+1){
    FOR(j,1,w+1){
      if(a[i][j]==(-1))continue;
      ans+=cost[a[i][j]];
    }
  }
  cout<<ans<<endl;
	return 0;
}


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

int n;
int x;
int asum[105];
int b[105];
int bsum[105];
int maxv;

int main(){
	cin>>n;
	
	for(int i=1;i<=n;i++){
		cin>>x;
		asum[i]=asum[i-1]+x;
	}
	
	for(int i=1;i<=n;i++) cin>>b[i];
	
	for(int i=n;i>=1;i--) bsum[i]=bsum[i+1]+b[i];
	
	for(int i=1;i<=n;i++){
		int sum=asum[i]+bsum[i];
		maxv=max(maxv,sum);
	}
	
	cout<<maxv<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <ctime>
#include <iterator>
#include <bitset>
#include <numeric>
#include <list>
#include <iomanip>
#include <cassert>

#if __cplusplus >= 201103L
#include <array>
#include <tuple>
#include <initializer_list>
#include <unordered_set>
#include <unordered_map>
#include <forward_list>

#define cauto const auto&
#define ALL(v) begin(v),end(v)
#else
#define ALL(v) (v).begin(),(v).end()
#endif

using namespace std;


namespace{
typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
	v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
	stringstream ss;
	ss << f;
	ss >> t;
}


#define REP(i,n) for(int i=0;i<int(n);++i)
#define RALL(v) (v).rbegin(),(v).rend()


#define MOD 1000000007LL
#define EPS 1e-8


void mainmain(){
	int n, m;
	cin >> n >> m;
	VV(int) ds;
	initvv(ds, n, n, 1010101010);
	for(int i = 0; i < n; ++i){ ds[i][i] = 0; }
	vector<int> as(m), bs(m), cs(m);
	for(int i = 0; i < m; ++i){
		cin >> as[i] >> bs[i] >> cs[i];
		--as[i];
		--bs[i];
		ds[as[i]][bs[i]] = ds[bs[i]][as[i]] = cs[i];
	}
	for(int k = 0; k < n; ++k)
	for(int i = 0; i < n; ++i)
	for(int j = 0; j < n; ++j){
		ds[i][j] = min(ds[i][j], ds[i][k] + ds[k][j]);
	}
	int ans = 0;
	for(int i = 0; i < m; ++i){
		ans += ds[as[i]][bs[i]] != cs[i];
	}
	cout << ans << endl;
}



}
int main() try{
//	ios::sync_with_stdio(false);
	cout << fixed << setprecision(10);
	cerr << fixed << setprecision(4);
	mainmain();
}
catch(...){}


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

int ltoR[100005];
int ans[100005];

int main () {
  string S;
  cin >> S;
  memset(ans, 0, sizeof(ans));
  memset(ltoR, 0, sizeof(ltoR));
  int lrCounter=0;
  
  // 移動する距離をメモ
  // 右からなめる
  for (int i=S.size()-1; i>= 0; i--) {
    if (S[i]=='R') {
      lrCounter++;
      ltoR[i]=lrCounter;
    } else {
      lrCounter=0;
    }
  }
  
  // 左からなめる
  for (int i=0; i< S.size(); i++) {
    if (S[i]=='L') {
      lrCounter--;
      ltoR[i]=lrCounter;
    } else {
      lrCounter=0;
    }
  } 
  
  // 計算
  for (int i=0; i< S.size(); i++) {
    if (ltoR[i]%2==0) {
      ans[i+ltoR[i]]+=1;
    } else if (ltoR[i] <0) {
      ans[i+ltoR[i]+1]+=1;
    } else {
      ans[i+ltoR[i]-1]+=1;
    }
  }
  
  // 出力
  for (int i=0; i< S.size(); i++) {
    cout << ans[i] << " ";
  }
  cout << endl;
  return 0;
  
}

Measured memory_bytes: 1408
/*

結果:
*/
#define _USE_MATH_DEFINES
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <limits.h>  
#include <stdbool.h>   
#define inf (INT_MAX-1)
#define INF 9223372036854775807
#define PI 3.14159265358979323846;
#define EPS 1e-10
#define sq(n) ((n)*(n))
#define rep(i,n) for(i=0;i<n;i++)
#define rev(i,n) for(i=n-1;i>=0;i--)
/*
#define sort(a,n) qsort(a,n,sizeof(TYPE),cmp)
#define sort_r(a,n) qsort(a,n,sizeof(TYPE),cmp_r)
*/
#define chsort(s,n) qsort(s,n,sizeof(char),cmp)
#define chsort_r(s,n) qsort(s,n,sizeof(char),char_cmp_r)
#define TYPE long long
#define ll long long
#define MEMSET(a) memset(a,0,sizeof(a))
#define MEMSET_U(a) memset(a,-1,sizeof(a))
const int mod = (int)1e09 + 7;

//#define DEBUG1
//#define DEBUG2
//#define DEBUGF
#define DUMMY

int in(void) { int i; scanf("%d", &i); return i; }
long long llin(void) { long long i; scanf("%lld", &i); return i; }
double din(void) { double i; scanf("%lf", &i); return i; }
void chin(char s[]) { scanf("%s", s); }

void print(int a) { printf("%d\n", a); }
void llprint(long long a) { printf("%lld\n", a); }
void dprint(double a) { printf("%.10f\n", a); }
void print2(int a, int b) { printf("%d %d\n", a, b); }
int Max(int a, int b) { if (a > b) { return a; }return b; }
int Min(int a, int b) { if (a < b) { return a; }return b; }
long long llmax(long long a, long long b) { return a > b ? a : b; }
long long llmin(long long a, long long b) { return a < b ? a : b; }
double dmax(double a, double b) { return a > b ? a : b; }
double dmin(double a, double b) { return a < b ? a : b; }
//long long llmax(long long a, long long b) { return a > b ? a : b; }
//long long llmin(long long a, long long b) { return a < b ? a : b; }
//double dmax(double a, double b) { return a > b ? a : b; }
int cmp(const void *a, const void *b) { return *(TYPE *)a - *(TYPE *)b; }
int cmp_r(const void *a, const void *b) { return *(TYPE *)b - *(TYPE *)a; }
int char_cmp(const void *a, const void *b) { return strcmp((char *)a, (char *)b); }
int char_cmp_r(const void *a, const void *b) { return strcmp((char *)b, (char *)a); }
void swap(int *a, int *b) { int t = *a; *a = *b; *b = t; }


int N;
char S[101], T[101];
int ans;

int same(int d) {
	for (int i = 0; i < N-d; i++) {
		if (S[i + d] != T[i]) {
			return 0;
		}
	}
	return 1;
}

int main() {
	scanf("%d", &N);
	scanf("%s%s", S, T);

	int d = 0;
	for (d = 0; d < N; d++) {
		if (same(d)) {
			break;
		}
	}

	ans = N + d;
	printf("%d\n", ans);

#ifdef DEBUGF
	getch();
#endif
	return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<string>
#include<algorithm>
#include<math.h>
#include<queue>
#include<vector>
#include<map>
#include<iomanip>
#include<tuple>
#include<bitset>


using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define printfloat(x) cout << fixed << setprecision(7) << (x) << endl;
#define printbit(x) cout << bitset<15>(x) << endl;
using ll = long long int;



long double pi = 3.14159265359;

int a,b;
int unuse,cnt;
int main(){
    cin >> a >> b;
    unuse = a;
    cnt ++;
    if(b==1){
        cout << 0 << endl;
        return 0;
    }
    while(b > unuse){
        unuse += a - 1;
        cnt ++;
    }
    cout << cnt << endl;


return 0;
}

Measured memory_bytes: 3528
n,m = list(map(int,input().split(" ")))
ac_count = 0
wa_list = [0]*n
ac_list = [0]*n

for i in range(m):
    x = list(map(str,input().split(" ")))
    x0 = int(x[0])
    x1 = str(x[1])
    if ac_list[x0-1] == 1:
        pass
    else:
        if x1 == "AC":
            ac_count += 1
            ac_list[x0-1] = 1
        else:
            wa_list[x0-1] += 1

acnone =[i for i, x in enumerate(ac_list) if x == 0]
if not acnone:
    pass
else:
    for i in acnone:
        wa_list[i] = 0
wa_count = sum(wa_list)
print(ac_count,wa_count)

Measured memory_bytes: 8728
#include <bits/stdc++.h>
#include <assert.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define PB push_back
#define MP make_pair
#define MOD 1000000007LL
#define endl "\n"
#define fst first
#define snd second
const ll UNDEF = -1;
const ll INF=1e18;
template<typename T> inline bool chkmax(T &aa, T bb) { return aa < bb ? aa = bb, true : false; }
template<typename T> inline bool chkmin(T &aa, T bb) { return aa > bb ? aa = bb, true : false; }
typedef pair<ll,ll> pll;
typedef vector<ll> vll;

void solve(long long N, vector<long long> a){
	int n=N;
	int x=1;
	int ans=0;
	for (int i=1;i<n;i++) {
		if (a[i]==a[i-1]) {
			x++;
		}
		else {ans+=x/2;x=1;}
	}
	ans+=x/2;
	printf("%d\n",ans);
}

int main(){	
	ios_base::sync_with_stdio(false); cin.tie(0);
	long long N;
	scanf("%lld",&N);
	vector<long long> a(N-1+1);
	for(int i = 0 ; i <= N-1 ; i++){
		scanf("%lld",&a[i]);
	}
	solve(N, a);
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
struct point{int x;int y;};
int i,j,k,count1=0,count2=0;

int main(){
    string s;
    cin>>s;
    int ans=0;
    for(i=0;i<s.length();){
        cerr<<"i:"<<i<<endl;
        if((s[i]=='0'&&s[i+1]=='1')||(s[i]=='1'&&s[i+1]=='0')){
            s.erase(s.begin()+i);
            s.erase(s.begin()+i);
            if(i!=0)i--;
            ans+=2;
        }else{
            i++;
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 640
L,R = map(int,input().split(' '))
if R - L >= 2019:
  print(0)
  exit()
else:
  MIN = float('inf')
  for i in range(L,R):
    for j in range(i+1,R+1):
      MIN = min(MIN,(j*i) % 2019)
  print(MIN)

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

int main(void){
    int n, m;
    cin>>n>>m;
    if(m==0){
        if(n==3) cout<<100<<endl;
        else if(n==2) cout<<10<<endl;
        else cout<<0<<endl;
        return 0;
    }
    vector<pair<int, int> > v(m);
    rep(i, m){
        int a, b;
        cin>>a>>b;
        --a;
        v[i].first=a; v[i].second=b;
    }
    vector<int> ans(n);
    sort(v.begin(), v.end());
    //rep(i, m) cout<<v[i].first<<", "<<v[i].second<<endl;
    if(v[0].first==0&&v[0].second==0&&n!=1){
        cout<<-1<<endl;
        return 0;
    }
    rep(i, m-1){
        if(v[i].first==v[i+1].first && v[i].second!=v[i+1].second){
            cout<<-1<<endl;
            return 0;
        }
    }
    rep(i, m){
        if(v[i].first>=n){
            cout<<-1<<endl;
            return 0;
        }
    }
    rep(i, m){
        ans[v[i].first]=v[i].second;
    }

    //rep(i, n) cout<<ans[i]<<endl;

    if(n>=2) ans[0]=max(1, ans[0]);
    int answer=0;
    rep(i, n){
        answer+=ans[i]*pow(10, (n-i-1));
    }
    cout<<answer<<endl;
    return 0;

}

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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(a)     (a).begin(),(a).end()
#define RALL(a)     (a).rbegin(),(a).rend()
#define PRINT(a)   cout << (a) << endl

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define Fi first
#define Se second

#define debug(x) cerr << x << " " << "(L:" << __LINE__ << ")" << '\n';

using ll = long long int;
using P = pair<int,int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using pii = pair<int, int>;

template <typename T> using PQ = priority_queue<T>;
template <typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

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

const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7;

int main(){
  string S;
  cin >> S;
  // 1〜2文字目を数値に変換
  int x = (S[0]-'0')*10+(S[1]-'0');
  // 3〜4文字目を数値に変換
  int y = (S[2]-'0')*10+(S[3]-'0');

  if(1<=x && x<=12 && 1<=y && y<=12){
    cout << "AMBIGUOUS" << endl;
  }else if(1<=x && x<=12){
    cout << "MMYY" << endl;
  }else if(1<=y && y<=12){
    cout << "YYMM" << endl;
  }else{
    cout << "NA" << endl;
  }
}



Measured memory_bytes: 3612