akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using ld = long double;

//#define int long long
//signed main(){
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,m;
    cin >> n >> m;
    vector<int> a;
    for(int i = 0; i < n; i++) {
        int ta;
        cin >> ta;
        a.emplace_back(ta);
    }
    sort(a.begin(),a.end());
    vector<pair<int,int>> cb(m);
    for(int i = 0; i < m; i++) {
        cin >> cb[i].second >> cb[i].first;
    }
    sort(cb.rbegin(),cb.rend());

    int idx=0;
    bool cont=false;
    for(int i = 0; i < m; i++) {
        for(int j = 0; j < cb[i].second; j++) {
            a.emplace_back(cb[i].first);
            idx++;
            if(idx>n){
                cont=true;
                break;
            }
        }
        if(cont) break;
    }

    sort(a.rbegin(),a.rend());
    ll count=0;
    for(int i = 0; i < n; i++) {
        count+=a[i];
    }
    cout << count << "\n";

    return 0;
}

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

/*BigInteger
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/rational.hpp>
namespace xxx = boost::multiprecision;
using Bint = xxx::cpp_int;
using Real = xxx::number<xxx::cpp_dec_float<1024>>;
*/

#define int long long
#define pb(x) push_back(x)
#define m0(x) memset((x), 0LL, sizeof(x))
#define mm(x) memset((x), -1LL, sizeof(x))

//container
#define ALL(x) (x).begin(), (x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define EACH(i, c) for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define UNIQUE(v) (v).erase(unique((v).begin(), (v).end()), (v).end());
#define PERM(c) \
  sort(ALL(c)); \
  for (bool c##p = 1; c##p; c##p = next_permutation(ALL(c)))

// debug
#define GET_VAR_NAME(variable) #variable
#define test(x) cout << GET_VAR_NAME(x) << " = " << x << endl;

// bit_macro
#define Bit(n) (1LL << (n))
#define Bitset(a, b) (a) |= (1LL << (b))
#define Bitunset(a, b) (a) &= ~(1LL << (b))
#define Bitcheck(a, b) ((((a) >> (b)) & 1LL) == 1LL)
#define Bitcount(a) __builtin_popcountll((a))

//typedef
typedef long long lint;
typedef unsigned long long ull;
typedef complex<long double> Complex;
typedef pair<int, int> P;
typedef tuple<int, int, int> TP;
typedef vector<int> vec;
typedef vector<vec> mat;

//constant
constexpr int INF = (int)1e18;
constexpr int MOD = (int)1e9 + 7;
constexpr double PI = (double)acos(-1);
constexpr double EPS = (double)1e-10;
constexpr int dx[] = {-1, 0, 0, 1, 0, -1, -1, 1, 1};
constexpr int dy[] = {0, -1, 1, 0, 0, 1, -1, 1, -1};

//
template <typename T>
void chmax(T &a, T b) { a = max(a, b); }
template <typename T>
void chmin(T &a, T b) { a = min(a, b); }
//
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T>
inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}

//
struct Accelerate_Cin {
  Accelerate_Cin() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(20);
  };
};

signed main() {
  int N, W;
  cin >> N >> W;
  int w[110], v[110];
  for (int i = 0; i < N; i++) {
    cin >> w[i] >> v[i];
  }

  static int dp[110][101011];
  for (int i = 0; i < N; i++) {
    for (int j = 0; j <= 101010; j++) {
      dp[i][j] = INF;
    }
  }
  dp[0][0] = 0;

  for (int i = 0; i < N; i++) {
    for (int j = 0; j <= 101010; j++) {
      dp[i + 1][j] = dp[i][j];
      if (j >= v[i]) {
        dp[i + 1][j] = min(dp[i + 1][j], dp[i][j - v[i]] + w[i]);
      }
    }
  }

  for (int j = 101010; j >= 0; j--) {
    if (dp[N][j] <= W) {
      cout << j << endl;
      return 0;
    }
  }
  return 0;
}


Measured memory_bytes: 80128
import math
n,k = map(int, input().split())
m = n
ans = 0
if n >= k:
  ans += (n-k+1)/n
  m = k-1

p=2
while m > 0:
  if m * p >= k:
    a = m - math.ceil(k/p) + 1
    ans += a/n/p
    m -= a
  p *= 2

print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n;
  cin>>n;
  int ar[n+1];
  for(int i=1;i<=n;i++) cin>>ar[i];
  map<int,int> mp;
  long long int sum=0;
  for(int i=1;i<n+1;i++)
  {
    if(mp.find(i-ar[i])!=mp.end())
      sum+=(long long int)mp[i-ar[i]];
    if(mp.find(ar[i]+i)!=mp.end())
       mp[ar[i]+i]++;
    else mp[ar[i]+i]=1;
  } 
  cout<<sum<<endl;
  return 0;
}  


Measured memory_bytes: 13592
url = "https://atcoder.jp//contests/abc142/tasks/abc142_d"

import math

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

def main():
    a, b = list(map(int, input().split()))
    abgcd = math.gcd(a, b)
    s = set(prime_factorize(abgcd))
    print(len(s)+1)

if __name__ == '__main__':
    main()


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

int main() {

	int a = 0, b = 0, c = 0, d = 0;
	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";
	}

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define N 100005
#define ll long long
#define ull unsigned long long
#define loop1(i, j, k, step) for (int i = j; i < k; i += step)
#define loop(i, j, k) for (int i = j; i < k; i++)
#define rloop1(i, j, k, step) for (int i = j; i >= k; i -= step)
#define rloop(i, j, k) for (int i = j; i >= k; i--)
#define rep(i, k) for (int i = (0); i < (k); i++)
#define rrep(i, k) for (int i = k - 1; i >= 0; i--)
#define forall(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define mp make_pair
#define pb push_back
#define pop pop_back
#define F first
#define S second
#define sz(x) (int)(x).size()
#define lin "\n"
#define Max (int)INT_MAX
#define Min (int)INT_MIN
#define MEM(a, b) memset(a, (b), sizeof(a))
#define fast_io ios_base::sync_with_stdio(0), cin.tie(NULL), cout.tie(0)
#define PI 2 * acos(0.0)
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef vector<ll> vl;
typedef pair<ll, ll> pll;

// vector<pair<int, int>> v;
// bool sortinrev(const pair<int, int> &a,
//                const pair<int, int> &b)
// {
//     return (a.second > b.second);
// }
// bool spOrder(const pair<int, int> &a,
//              const pair<int, int> &b)
// {
//     if (a.second == b.first)
//         return true;
//     return a.first < b.first;
// }
// void gen(int x,int y)
// {

// }
void solve()
{
    ll a, b;
    cin >> a >> b;
    cout << a * b << lin;
}

int main()
{
    auto start = clock();
    fast_io;
    // freopen("test.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    int t;
    t = 1;
    // cin >> t;
    while (t--)
    {
        solve();
    }
    auto stop = clock();
    cerr << "time taken:" << double(stop - start) / double(CLOCKS_PER_SEC) << " s" << endl;
    return 0;
}


Measured memory_bytes: 3792
/*
title:

url:
*/

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <functional>
#include <queue>
#include <limits>
#include <string>
#include <utility>
#include <cstring>
#include <map>
#include <cmath>
#include <iterator>

using namespace std;

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

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

#define int ll

//get vector of prime numbers which is lower than or equal n
vector<int> get_primes(int n)
{
    vector<bool> is_prime(n + 1, true);
    vector<int> res;
    is_prime[0] = is_prime[1] = false;
    for (int i = 2; i <= n; i++)
    {
        if (is_prime[i])
        {
            res.push_back(i);
            for (int j = 2 * i; j < is_prime.size(); j = j + i)
            {
                is_prime[j] = false;
            }
        }
    }
    return res;
}

vector<pair<int, int>> factorize(int n)
{
    vector<pair<int, int>> res;
    for (int i = 2; i * i <= n; i++)
    {
        int tmp = 0;
        while (n % i == 0)
        {
            tmp++;
            n /= i;
        }
        res.push_back(make_pair(i, tmp));
    }
    if (n != 1)
    {
        res.push_back(make_pair(n, 1));
    }
    return res;
}

int mpow(int x, int n)
{
    int res = 1;
    while (n != 0)
    {
        if (n & 1)
            res = res * x % INF;
        x = x * x % INF;
        n = n >> 1;
    }
    return res;
}

//mod frac
vector<int> mfrac;
void set_mfrac(int n)
{
    if (mfrac.size() == 0)
    {
        mfrac.push_back(1);
    }
    for (int i = mfrac.size(); i <= n; i++)
    {
        mfrac.push_back((i * mfrac[i - 1]) % INF);
    }
}

//get nCm mod INF
int mcomb(int n, int m)
{
    if (mfrac.size() <= n)
    {
        set_mfrac(n);
    }
    int res = mfrac[n];
    res = res * mpow(mfrac[m], INF - 2) % INF;
    res = res * mpow(mfrac[n - m], INF - 2) % INF;
    return res;
}

vector<int> get_gcd(int n)
{
    vector<int> res;
    for (int i = 1; i * i <= n; i++)
    {
        if (n % i == 0)
        {
            if (i * i == n)
            {
                res.push_back(i);
            }
            else
            {
                res.push_back(i);
                res.push_back(n / i);
            }
        }
    }
    return res;
}

#define double long double

signed main()
{
    double a, b, x;
    cin >> a >> b >> x;
    double ans;
    double PI = acos(-1);
    if ((int)a * (int)b * (int)a < 2 * (int)x)
    {
        // a*a*b-x = 1/2 * a * a * tan(theta) * a
        //tan(theta) = 2/a(b-x/a/a)
        ans = atan((a * a * b - x) * 2. / a / a / a);
    }
    else if ((int)a * (int)b * (int)a == 2 * (int)x)
    {
        ans = atan(b / a);
    }
    else
    {
        // x/a = 1/2 * b * btan(pi/2-theta)
        ans = atan(2. * x / a / b / b);
        ans = PI / 2. - ans;
    }

    printf("%2.10Lf\n", ans * 180. / PI);
    return 0;
}

Measured memory_bytes: 256
S = input()
c = ''
L = []
i = 0
j = 3
min = 10**9
while j<=len(S):
    c = S[i:j]
    L.append(int(c))
    i += 1
    j += 1
for element in L:
    if abs(753-element) < min:
        min = abs(753-element)
print(min)

Measured memory_bytes: 3060
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef long long ll;
map<ll,pair<ll,int>> s;
set<pair<ll,int>> t;
ll inf = 10000000000;
ll solve(ll x){
    auto it = s.upper_bound(x);
    it--;
    auto p = *it;
    return p.second.first + p.second.second*(x - p.first);
}

int curve(int x){
    auto it = s.upper_bound(x);
    it--;
    auto p = *it;
    return p.second.second;
}

int main(){
    int i,h,w; cin >> h >> w;
    s[0] = {inf,0}; t.insert({inf,0});
    s[1] = {0LL,0}; t.insert({0LL,1});
    s[w + 1] = {inf,0}; 
    for(i=1;i<=h;i++){
        int a,b; cin >> a >> b;
        ll hi1 = solve(a - 1),hi2 = solve(b + 1),k = curve(b + 1);
        //cout << hi1 << " c " << hi2 << endl;
        t.erase({solve(a),a}); s[a] = {hi1 + 1,1},t.insert({hi1 + 1,a});
        t.erase({solve(b + 1),b + 1}); s[b + 1] = {hi2,k},t.insert({hi2,b + 1});
        auto it = s.upper_bound(a);
        while(true){
            auto q = *it;
            //cout << q.first << " a " << q.second.first << " b " << q.second.second << endl;
            if(q.first>b) break;
            t.erase({q.second.first,q.first}); s.erase(it++);
        }
        /*for(auto x:s){
            cout << x.first << " " << x.second.first << " " << x.second.second << endl;
        }*/
        auto q = *t.begin();
        if(q.first + i<inf) cout << q.first + i << endl;
        else cout << -1 << endl;
        /*cout << q.first << " " << q.second << endl;
        for(int j=1;j<=w;j++){
            cout << solve(j) << " ";
        }
        cout << endl;*/
    }
}

Measured memory_bytes: 28560
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <stdio.h>
#include <iomanip>
#include <limits>
#include <list>
#include <string>
#include <queue>
#include <deque>
#include <tuple>
#include <map>
#include <sstream>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define FOR(i,a,b) for(int i=a; i<(int)(b); i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort(ALL(x))
#define CLR(a) memset((a), 0 ,sizeof(a))
#define PB push_back
#define MP make_pair
#define SP << " " <<
const int INF = 1001001001;
const ll LINF = 100100100100100100;
const double EPS = 1e-10;
const long double PI  = acos(-1.0L);
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
#define chmax(a,b) a = (((a)<(b))?(b):(a))
#define chmin(a,b) a = (((a)>(b))?(b):(a))

__attribute__((constructor))
void initial(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

signed main(){
	int n,m; cin>>n>>m;
	ll dp[m+5][n+5][n+5]; CLR(dp);
	dp[0][1][1] = 1;
	rep(i,m+1){
		rep(j,n+1){
			rep(k,n+1){
				dp[i+1][j+1][k] += dp[i][j][k]*(n-j)%MOD; // 新しい街に行く
				dp[i+1][j+1][k] %= MOD;
				dp[i+1][j][k] += dp[i][j][k]*(j-k)%MOD; // 強連結要素につなげない
				dp[i+1][j][k] %= MOD;
				dp[i+1][j][j] += dp[i][j][k]*k%MOD; // 強連結化
				dp[i+1][j][j] %= MOD;
			}
		}
	}
	cout << dp[m][n][n] << endl;

  return 0;
}


Measured memory_bytes: 221952
#include<iostream>
#include<iomanip>
#include<cstdlib>
#include<algorithm>
#include<vector>
#include<map>
#include<cmath>
#include<string>

#define rep(i,p) for(long long int i=0;i<p;i++)
#define reep(i,p) for(long long int i=1;i<=p;i++)
#define ll long long

using namespace std;

int main(){

string S;
cin >> S;

ll int n;
n=S.size();

if (S[n-1]=='s'){
	cout << S << "es";
}
else{
	cout << S << 's';
}










	return 0;

}



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

int main() {
    int a,b;
    cin>>a>>b;

    if(a+b>=10){
        cout<<"error"<<endl;
    }
    else {
        cout<<a+b <<endl;
    }
}


Measured memory_bytes: 256
/*
数学的にすべての場合を計算で求めようとして失敗した（うまく考えられなかった）
よくよく考えると組み合わせは１０通りしかないから、すべての組み合わせを試すと良かった.
*/

#include <bits/stdc++.h>
using namespace std;

string s;
int n;
long long m, a, r, c, h;
long long D[5];
vector<int> p = {0,0,0,0,0,0,1,1,1,2};
vector<int> q = {1,1,1,2,2,3,2,2,3,3};
vector<int> R = {2,3,4,3,4,4,3,4,4,4};

int main(){
    cin >> n;
    
    for (int i = 0; i < n; i++){
        cin >> s;
        
        if (s[0] == 'M') m++;
        else if (s[0] == 'A') a++;
        else if (s[0] == 'R') r++;
        else if (s[0] == 'C') c++;
        else if (s[0] == 'H') h++;
    }
    
    D[0] = m, D[1] = a, D[2] = r, D[3] = c, D[4] = h;
    long long res = 0;
    for (int d = 0; d < 10; d++) res += D[p[d]] * D[q[d]] * D[R[d]];
    
    cout << res << endl;
}

Measured memory_bytes: 256
#define M(x,y)(x>y?x:y)
#define m(x,y)(x<y?x:y)
I;int parse(char *p){switch(*p){
	case'0':return 0;
	case'1':return 1;
	case'2':return 2;
	case'P':return I%3;
	case'Q':return I/3%3;
	case'R':return I/9%3;
	case'-':return 2-parse(p+1);
	case'(':{
		int x=0;
		char*q=++p;
		for(;;p++){
			if(*p=='(')x++;
			if(*p==')')x--;
			if(x==0&&*p!='-')break;
		}
		return(*(++p)=='*')?m(parse(q),parse(p+1)):M(parse(q),parse(p+1));
	}
}}
char p[81];main(s){for(;scanf("%s",p),*p-'.';printf("%d\n",s))for(s=I=0;I<27;I++)s+=parse(p)==2;exit(0);}

Measured memory_bytes: 536
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int a = scan.nextInt();
        int b = scan.nextInt();
        int c = scan.nextInt();
        while(!(a<=b) || !(b<=c)){
        if (a>b){
            int d = b;
            b = a;
            a = d;
        }
        if (b>c){
            int d = c;
            c = b;
            b = d;
        }
        }
        System.out.printf("%d %d %d\n", a, b, c);
        scan.close();
    }
}


Measured memory_bytes: 26332
n, m, l = map(int, input().split())
A = list()
[A.append(list(map(int, input().split()))) for i in range(n)]
B = list()
[B.append(list(map(int, input().split()))) for i in range(m)]
C = [[0 for i in range(l)] for j in range(n)]
for i in range(n):
    for j in range(l):
        _ = 0
        for k in range(m):
            _ += A[i][k]*B[k][j]
        C[i][j] = _
    print(" ".join(map(str, C[i])))


Measured memory_bytes: 6916
#include<bits/stdc++.h>
using namespace std;
const int N=200005;
long long ans;
int n;
char s[N];
int main(){
	scanf("%s",s+1);
	int n=strlen(s+1),cnt=0;
	for (int i=1;i<=n;i++){
		if (s[i]=='A')cnt++;
		if (s[i]=='C')cnt=0;
		if (s[i]=='B'){
			if (s[i+1]=='C')ans+=cnt,i++;
			else cnt=0;
		}
	}
	printf("%lld\n",ans);
}

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

#define _GLIBCXX_DEBUG
#define all(v) (v).begin(),(v).end()

using namespace std;

using ll=long long;
using pii=pair<int, int>;
using vi=vector<int>;
using vii=vector<vector<int>>;

const ll LINF=1LL<<60;
const int INF=1<<29;
const int MOD=1e9+7;

template<typename T> bool chmax(T &a,const T b){if(a < b){a=b; return true;} return false;}
template<typename T> bool chmin(T &a,const T b){if(a > b){a=b; return true;} return false;}



int main(){
    int k, x; cin >> k >> x;
    int pos=max(x-k+1, -1000000);
    while(pos <= 1000000 && pos <= x+k-1){
        cout << pos << " ";
        pos++;
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 3628
n = input()
l = len(n)-1
for i in range(2**l):
    op = ["-"]*l
    for j in range(l):
        if (i>>j)&1:
            op[l-j-1]="+" #lからjだけシフトさせて+に変える

    formula = ""
    for op_num,op_l in zip(n,op+[""]):
        formula += op_num + op_l
    if eval(formula)==7:
        print(formula+"=7")
        break

Measured memory_bytes: 9024
import sys
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def YesNo(x): return 'Yes' if x else 'No'
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()
from collections import defaultdict

def main():
    N = II()
    xy = []
    for _ in range(N):
        xy.append(LI())
    xy2g = defaultdict(int)
    g2xy = defaultdict(set)
    for x, y in xy:
        y = -y
        gx = xy2g[x]
        gy = xy2g[y]
        if gx != 0 and gy != 0 and gx != gy:  # merge
            if len(g2xy[gx]) < len(g2xy[gy]):
                gx, gy = gy, gx
            for xy in g2xy[gy]:
                xy2g[xy] = gx
            g2xy[gx] |= g2xy[gy]
            g2xy[gy].clear()
        else:
            g = gx or gy or x
            xy2g[x] = xy2g[y] = g
            g2xy[g] |= {x, y}
    ans = -N
    for xys in g2xy.values():
        nx = sum(1 for xy in xys if xy > 0)
        ny = len(xys) - nx
        ans += nx * ny
    return ans

print(main())

Measured memory_bytes: 114396
#include <stdio.h>
#include <iostream>

using namespace std;

int min(int x, int y)
{
    return x < y ? x : y;
}

int main()
{
    int A, B, C, D;

    scanf("%d\n%d\n%d\n%d", &A, &B, &C, &D);

    printf("%d\n", min(A, B) + min(C, D));

    return 0;
}


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

int main() {
  int N;
  cin >> N;
  int mx = 1;
  for (int i = 2; i * i <= N; i++) {
    for (int j = 0; pow(i, j) <= N; j++) {
      mx = max(mx, (int) pow(i, j));
    }
  }
  cout << mx << "\n";
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <queue>
using namespace std;

int A[55];
vector<pair<int,int>> v;
int main(){
	int N; scanf("%d",&N);
	for(int i=1;i<=N;i++){
		scanf("%d",A+i);
	}
	int *mx = max_element(A+1,A+N+1);
	int *mn = min_element(A+1,A+N+1);
	if(*mx > 0 && *mn < 0){
		if(abs(*mx) > abs(*mn)){
			for(int i=1;i<=N;i++) v.push_back({mx-A,i});
			for(int i=1;i<N;i++) v.push_back({i,i+1});
		}
		else{
			for(int i=1;i<=N;i++) v.push_back({mn-A,i});
			for(int i=N;i>1;i--) v.push_back({i,i-1});
		}
	}
	else if(*mn >= 0){
		for(int i=1;i<N;i++) v.push_back({i,i+1});		
	}
	else {
		for(int i=N;i>1;i--) v.push_back({i,i-1});
	}
	printf("%d\n",v.size());
	for(auto it : v){
		printf("%d %d\n",it.first,it.second);
	}
}

Measured memory_bytes: 256
#include <atcoder/all>
#include <bits/stdc++.h>
using namespace std;
using namespace atcoder;
using mint = modint998244353;

int main() {
  long n,m;
  cin >> n >> m;
  vector<long> a(n),b(m);
  for(long i=0;i<n;i++) cin >> a[i];
  for(long i=0;i<m;i++) cin >> b[i];
  vector<long> ans=convolution(a,b);
  for(long i=0;i<n+m-1;i++) cout << ans[i] << " ";
  cout << endl;
}

Measured memory_bytes: 27288
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cctype>
#include<cmath>
#include<cstdio>
#include<set>
#include<stack>
#include<string>
#include<sstream>
#include<map>
#include<queue>
#include<vector>
using namespace std;

int main() {
	stack<int> a;
	for (int b; cin >> b;) {
		if (b)a.push(b);
		else { cout << a.top() << endl; a.pop(); }
	}
	return 0;
}

Measured memory_bytes: 1200
s = input()
if s == "MON":
  print(6)
elif s == "TUE":
  print(5)
elif s == "WED":
  print(4)
elif s == "THU":
  print(3)
elif s == "FRI":
  print(2)
elif s == "SAT":
  print(1)
else:
  print(7)


Measured memory_bytes: 38256
#include <bits/stdc++.h>
#include <fstream>
#include <cstdio>
using namespace std;
// vector<pair<int,int> > v;
// cin.ignore();//twice getline(cin,s);
// g++ iterator.cpp -std=c++17
// cout<<(A + B == C ? "YES" : "NO")<<endl;
// __gcd(a,b)
// string s=to_string(n);
// string p=s.substr(0,len);
// string q=s.insert(0,str);
// sort(arr, arr+n, greater<int>());
// cout<<fixed<<setprecision(9)<<pi<<endl
// const  double pi = acos(-1.0);
#define ff first
#define ss second
#define pb push_back
#define mk make_pair
#define vll vector<ll>
#define mll map<ll,ll >
#define mlli map<ll,ll>::iterator
#define size size()
#define endl "\n"
#define ll long long int
#define ld long double
void fast(){ios_base::sync_with_stdio(false);
cin.tie(NULL);cout.tie(NULL);}


int main(void)
{
	fast();
	string s;
	cin>>s;
	string p=s.substr(0,3);
	cout<<p<<endl;	
}

Measured memory_bytes: 3644
use proconio::{input, fastout};

#[fastout]
fn main() {
    input!{ n: usize, mut a: [usize; n] };
    a.sort_by(|l, r| r.cmp(l));
    let mut ans = 0;
    let mut t = n - 1;
    for i in 0 .. n {
        let c = if i == 0 { 1 } else { 2 };
        for _ in 0 .. c {
            if t > 0 {
                ans += a[i];
                t -= 1;
            }
        }
    }
    println!("{}", ans)
}


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



int main() {
  string s;
  cin >> s;
  int l = 0;
  int ans = 0;
  while(1){
    int n = s.length()-1;
    if(l>=n) break;

    if(s[l]==s[n]){
      ++l;
      s.pop_back();
    }
    else if(s[l]=='x'){
      s.push_back('x');
      ++ans;
    }
    else if(s[n]=='x'){
      if(l==0){
        s.insert(s.begin(),'x');
        ++ans;
      }
      else{
        --l;
        s[l] = 'x';
        ++ans;
      }
    }
    else{
      cout << -1 << endl;
      return 0;
    }

    // cout << l << " " << s << endl;
  }

  cout << ans << endl;

}



Measured memory_bytes: 512
import sys, os

f = lambda:list(map(int,input().split()))
if 'local' in os.environ :
    sys.stdin = open('./input.txt', 'r')

dp = {}
g = []

def get_dp(x, y):
    global g
    if (x,y) in dp:
        return dp[(x,y)]

    if x<0 or y<0:
        return 0

    dp[(x,y)] = max(get_dp(x-1,y), get_dp(x, y-1)) + g[x][y]

    return dp[(x,y)]




def solve():
    global g
    n = f()[0]
    g = [ f() for i in range(2)]

    print(get_dp(1,n-1))



solve()


Measured memory_bytes: 3064
#include <stdio.h>
#include <memory.h>

void create_new_table(r, c) {
	int i, j, tmp, csum;
	int list[c+1];
	memset((char*)list, 0x00, sizeof(list));
	
	for(i=0;i<r+1;i++) {
		for(j=0,csum=0;j<c;j++) {
			if(i==r) {
				tmp = list[j];
			} else if(j<c-1) {
				scanf("%d ", &tmp);
				list[j] += tmp;
			} else {
				scanf("%d\n", &tmp);
				list[j] += tmp;
			}
			csum += tmp;
			printf("%d ", tmp);
		}
		printf("%d\n", csum);
	}
}

int main(void) {
	int r, c;
	scanf("%d %d\n", &r, &c);
	create_new_table(r, c);
	return 0;
}

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

using namespace std;

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

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)
typedef complex<Real> P;

int main(){
  int h,w;
  int cnt[26] = {};
  cin>>h>>w;
  REP(i,h){
    string s;
    cin>>s;
    REP(j,w){
      cnt[s[j]-'a']++;
    }
  }
  int n1=0, n2=0, n4=0;
  if(h%2==1 && w%2==1){
    n1=1;
    n2=(h-1)/2+(w-1)/2;
    n4=(h-1)/2*(w-1)/2;
  }else if(h%2==1){
    n1=0;
    n2=w/2;
    n4=w/2*(h-1)/2;
  }else if(w%2==1){
    n1=0;
    n2=h/2;
    n4=h/2*(w-1)/2;
  }else{
    n1=0;
    n2=0;
    n4=h*w/4;
  }
  assert(n1+2*n2+4*n4==h*w);
  // n1
  REP(i,26)if(cnt[i]%2==1){
    cnt[i]--;
    n1--;
    break;
  }
  // n2
  REP(i,26)if(n2&&cnt[i]%4==2){
    cnt[i]-=2;
    n2--;
  }
  REP(i,26)while(n2&&cnt[i]>=2){
    cnt[i]-=2;
    n2--;
    if(n2&&cnt[i]>=2){
      cnt[i]-=2;
      n2--;
    }
  }
  // n4
  REP(i,26)if(cnt[i]%4==0){
    n4 -= cnt[i]/4;
  }
  puts(n1||n2||n4?"No":"Yes");
  return 0;
}


Measured memory_bytes: 256
// https://atcoder.jp/contests/abc128/tasks/abc128_e

#include "algorithm"
#include "iostream"
#include "queue"
#include "set"
#include "vector"
#define rep(i, to) for (ll i = 0; i < (to); ++i)
#define repf(i, from, to) for (ll i = from; i < (to); ++i)
using namespace std;
typedef long long ll;
template <typename T>
using V = vector<T>;
using VL = V<ll>;
using VVL = V<VL>;
template <typename T, typename U>
using P = pair<T, U>;
using PL = P<ll, ll>;
using VPL = V<PL>;
template <typename T>
inline bool chmax(T& a, T b);
template <typename T>
inline bool chmin(T& a, T b);
void print_ints(vector<ll> v);
template <typename T>
void drop(T a);

// type: 0: delete, 1: insert, 2: query
// f: (f: time, s: type), s: x
using event = P<PL, ll>;

void solve() {
  ll N, Q;
  cin >> N >> Q;

  V<event> es;

  rep(i, N) {
    ll s, t, x;
    cin >> s >> t >> x;
    es.emplace_back(PL(s - x, 1), x);
    es.emplace_back(PL(t - x, 0), x);
  }

  rep(i, Q) {
    ll d;
    cin >> d;
    es.emplace_back(PL(d, 2), 0);  // second は使わない
  }

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

  VL res;
  multiset<ll> se;

  for (auto p : es) {
    ll tx = p.first.first;
    ll type = p.first.second;
    ll x = p.second;

    if (type == 0)
      se.erase(x);
    else if (type == 1)
      se.insert(x);
    else
      res.push_back(se.empty() ? -1 : *(se.begin()));
  }

  for (auto r : res) cout << r << endl;
}

struct exit_exception : public std::exception {
  const char* what() const throw() { return "Exited"; }
};

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

  try {
    solve();
  } catch (exit_exception& e) {
  }

  return 0;
}
#endif

template <typename T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}

template <typename T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

void print_ints(vector<ll> v) {
  rep(i, v.size()) {
    if (i > 0) {
      cout << " ";
    }

    cout << v[i];
  }

  cout << endl;
}

template <typename T>
void drop(T res) {
  cout << res << endl;
  throw exit_exception();
}


Measured memory_bytes: 29796
//
// Created by yamunaku on 2020/03/28.
//

#include <bits/stdc++.h>

using namespace std;

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repl(i, l, r) for(int i = (l); i < (r); i++)
#define per(i, n) for(int i = ((n)-1); i >= 0; i--)
#define perl(i, l, r) for(int i = ((r)-1); i >= (l); i--)
#define all(x) (x).begin(),(x).end()
#define MOD9 998244353
#define MOD1 1000000007
#define IINF 1000000000
#define LINF 1000000000000000000
#define SP <<" "<<
#define CYES cout<<"Yes"<<endl
#define CNO cout<<"No"<<endl
#define CFS cin.tie(0);ios::sync_with_stdio(false)
#define CST(x) cout<<fixed<<setprecision(x)

using ll = long long;
using ld = long double;
using vi = vector<int>;
using mti = vector<vector<int>>;
using vl = vector<ll>;
using mtl = vector<vector<ll>>;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
template<typename T>
using heap = priority_queue<T, vector<T>, function<bool(const T, const T)>>;

int main(){
    //CFS;
    string s;
    cin >> s;
    if(s[2] == s[3] && s[4] == s[5]) CYES;
    else
        CNO;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<cstdio>
#include<queue>
#include<algorithm>
#include<numeric>
#include<vector>
#include<string>


typedef long long ll;
#define REP(i,n) for(long long int (i)=0;(i) < (n);(i)++)
using namespace std;



int main(){
  int n,tmp;
  cin >> n;
  vector<int> v;
  REP(i,n){
    cin >> tmp;
    v.push_back(tmp);
  }
  sort(v.begin(),v.end());
  priority_queue<int,vector<int>,greater<int>> ans;
  REP(i,min(n,10)){
    REP(j,min(n,10)){
      if(j==i)continue;
      ans.push(stoi(to_string(v[i]) + to_string(v[j])));
    }
  }
  ans.pop();
  ans.pop();
  cout << ans.top() << endl;

    return 0;

}


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

int main(void){
	int l[4],r[4];
	memset(l,0,sizeof(l));
	memset(r,0,sizeof(r));
	double a,b;
	while(~scanf("%lf%lf",&a,&b)){
		if(a>=1.1)l[0]++;
		else if(a>=0.6)l[1]++;
		else if(a>=0.2)l[2]++;
		else l[3]++;
		if(b>=1.1)r[0]++;
		else if(b>=0.6)r[1]++;
		else if(b>=0.2)r[2]++;
		else r[3]++;
	}
	for(int i=0;i<=3;i++){
		printf("%d %d\n",l[i],r[i]);
	}
    return 0;
}

Measured memory_bytes: 0
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
	int N;
	cin >> N;
	vector<int> A(N);
	for (int i = 0; i < N; ++i) cin >> A[i];
	sort(A.begin(), A.end());
	long long sum = 0;
	for (int i = 0; i < N - 1; ++i) {
		sum += 2 * (long long)(min(i + 1, N - i - 1)) * (A[i + 1] - A[i]);
	}
	if (N % 2 == 0) {
		sum -= A[N / 2] - A[N / 2 - 1];
	}
	else {
		sum -= min(A[N / 2] - A[N / 2 - 1], A[N / 2 + 1] - A[N / 2]);
	}
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define fi first
#define se second
#define mp make_pair
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,K,Q,A,B,L,R;
string S,T;
const ll MOD = (1e+9) + 7;
const ll INF = 1LL << 60;
typedef pair<ll,ll> P;

typedef vector<P> vp;
typedef vector<vp> matP;

int main(){
    cin>>N;
    ll sn = 0;
    M = N;
    while(M > 0){
        sn += M%10;
        M /= 10;
    }
    cout<<(N%sn == 0 ? "Yes" : "No")<<endl;
}


Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var a,b,c,x int
	fmt.Scan(&a,&b,&c,&x)
	count := 0
	for i := 0; i <= a; i++ {
		for j := 0; j <= b;j++ {
			k := (x - (500 * i + 100 * j)) / 50
			if 0 <= k && k <= c {
				count++
			}
		}
	}
	fmt.Println(count)
}

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

const int64_t INF = 1e18;

int main() {
    int N, K; cin >> N >> K;
    vector<int64_t> A(N);
    K--;
    for(auto &a : A) cin >> a;
    int64_t ans = INF;
    for(int bit = 0; bit < (1 << (N - 1)); ++bit) {
        if(__builtin_popcount(bit) != K) continue;
        int64_t now = A[0], cost = 0;
        for(int i = 1; i < N; ++i) {
            if(bit & (1 << (i - 1))) {
                int64_t dif = A[i] - now;
                if(dif > 0) {
                    now = A[i];
                } else {
                    cost += -dif + 1;
                    now = A[i] - dif + 1;
                }
            } else {
                now = max(now, A[i]);
            }
        }
        ans = min(ans, cost);
    }
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 256
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, x) \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;

ll dx[9] = {-1, 1, 0, 0, -1, -1, 1, 1, 0};
ll dy[9] = {0, 0, -1, 1, -1, 1, -1, 1, 0};

const ll INF = 1LL << 50;

struct UnionFind {
  vector<ll> par;  // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2
  ll num;

  UnionFind(ll N) : par(N) {  //最初は全てが根であるとして初期化
    for (ll i = 0; i < N; i++) par[i] = i;
    num = N;
  }

  ll root(ll x) {  // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
    if (par[x] == x) return x;
    return par[x] = root(par[x]);
  }

  void unite(ll x, ll y) {  // xとyの木を併合
    ll rx = root(x);         // xの根をrx
    ll ry = root(y);         // yの根をry
    if (rx == ry) return;  // xとyの根が同じ(=同じ木にある)時はそのまま
    par[rx] =
        ry;  // xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    num--;
  }

  bool same(ll x, ll y) {  // 2つのデータx, yが属する木が同じならtrueを返す
    ll rx = root(x);
    ll ry = root(y);
    return rx == ry;
  }
};

int main() {
  ll n, m;
  cin >> n >> m;

  UnionFind uf(n);

  rep(i, m) { ll x, y, z;
    cin >> x >> y >> z;
    x--;
    y--;
    uf.unite(x, y);
  }

  cout << uf.num << endl;

  return 0;
}


Measured memory_bytes: 1024
def resolve():
    N, x = list(map(int, input().split()))
    A = list(map(int, input().split()))
    cnt = 0
    for i in range(N-1):
        if A[i] + A[i+1] > x:
            diff = (A[i] + A[i+1]) - x
            cnt += diff
            if A[i+1] < diff:
                A[i] = diff - A[i+1]
                A[i+1] = 0
            else:
                A[i+1] -= diff
    print(cnt)


if '__main__' == __name__:
    resolve()



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

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

    long long ans = 0;
    for (int i = 1; i < N; i++) {
        if (A[i - 1] > A[i]) {
            int sa = A[i - 1] - A[i];
            ans += sa;
            A[i] += sa;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4396
#include <bits/stdc++.h>
using namespace std;
#define all(c) c.begin(),c.end()
#define init(c) memset(c,0,sizeof c)
#define S second
#define F first
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
const int N=20000005;
int n,k,x,t,a,b,m;
string s;
vi v;

void solve(){
	char c;
	cin >>c;
	if(c>='a'){
		cout << 'a';
	}else{
		cout << 'A';
	}
}

int main(){

	int t= 1;
	while(t--){
		solve();
	}
	
	return 0;
}

Measured memory_bytes: 3604
import java.util.*;

public class Main {
	int N;
	List<Integer> a, b, c;
	long[][] happies;
	int nextPlay;

	Main() {
		Scanner in = new Scanner(System.in);
		N = Integer.parseInt(in.nextLine());
		a = new ArrayList<>(N);
		b = new ArrayList<>(N);
		c = new ArrayList<>(N);
		for (int i = 0; i < N; ++i) {
			String[] tokens = in.nextLine().split(" ");
			a.add(Integer.parseInt(tokens[0]));
			b.add(Integer.parseInt(tokens[1]));
			c.add(Integer.parseInt(tokens[2]));
		}
		in.close();
		happies = new long[N][3];
		happies[0][0] = a.get(0);
		happies[0][1] = b.get(0);
		happies[0][2] = c.get(0);
	}

	long getResult() {
		return Math.max(happies[N - 1][0], Math.max(happies[N - 1][1], happies[N - 1][2]));
	}

	void calc() {
		for (int i = 1; i < N; ++i) {
			happies[i][0] = Math.max(happies[i - 1][1], happies[i - 1][2]) + a.get(i);
			happies[i][1] = Math.max(happies[i - 1][0], happies[i - 1][2]) + b.get(i);
			happies[i][2] = Math.max(happies[i - 1][0], happies[i - 1][1]) + c.get(i);
		}
	}

	public static void main(String[] args) {
		Main ins0 = new Main();
		ins0.calc();
		System.out.println(ins0.getResult());
	}

}

Measured memory_bytes: 132084
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rrep(i,n) for(ll i = 1; i <= (n); ++i)
#define drep(i,n) for(ll i = (n)-1; i >= 0; --i)
#define all(v) v.begin(),v.end()
#define len(x) (ll)(x).length()
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define pb push_back
#define sz(x) (ll)(x).size()
#define v(T) vector<T>
#define vv(T) vector<vector<T>>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
ll gcd(ll a,ll b){if(a%b==0){return b;}else{return(gcd(b,a%b));}}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
const int INF=1e9;
const ll MX = 1e18;
const ll MOD=INF+7;
const int di[] = {-1,0,1,0};
const int dj[] = {0,-1,0,1};
const double PI=acos(-1);
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
const int MAX = 1000001;
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {fac[0] = fac[1] = 1;finv[0] = finv[1] = 1;inv[1] = 1;for (int i = 2; i < MAX; i++){fac[i] = fac[i - 1] * i % MOD;inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;finv[i] = finv[i - 1] * inv[i] % MOD;}}
long long COM(int n, int k){if (n < k) return 0;if (n < 0 || k < 0) return 0;return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;}

int main() {
  int n;
  string s;
  cin>>n>>s;
  if(n%2!=0){
    cout<<"No"<<endl;
    return 0;
  }
  string t=s.substr(0,n/2);
  string u=s.substr(n/2,n/2);
  if(t==u) yn;
}

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

struct item {
    int v;
    int w;
};

item I[101];
int C[101][10001];

int main() {
    int N, W; cin >> N >> W;
    for (int i = 0; i < 101; i++){
        C[i][0] = 0;
    }
    for (int i = 0; i < 10001; i++){
        C[0][i] = 0;
    }
    rep(i, N){
        cin >> I[i].v >> I[i].w;
    }
    for (int i = 0; i < N; i++){
        for (int j = 1; j <= W; j++){
            if(I[i].w <= j){
                C[i+1][j] = max(C[i][j], C[i][j-I[i].w] + I[i].v);
            } else {
                C[i+1][j] = C[i][j];
            }
        }
    }

    cout << C[N][W] << endl;

    return 0;
}


Measured memory_bytes: 7060
#include <bits/stdc++.h>
#define N 100
#define INF 1e9 + 5
#define LINF 1e18 + 5

using namespace std;
using ll = long long;
string a, b;
vector<vector<int>> memo;
int solve(int y, int x)
{

    if (x == 0 || y == 0)
        return memo[y][x] = 0;
    int &best = memo[y][x];
    if (best != -1)
        return best;
    best = max(solve(y - 1, x), solve(y, x - 1));
    if (a[y] == b[x])
        best = max(best, solve(y - 1, x - 1) + 1);
    return best;
}
/*
 abyxb
a10000 
x11122
y11222
b12223
*/
int main()
{
    cin >> a >> b;
    a = "$" + a;
    b = "$" + b;
    memo.resize(a.length() + 1, vector<int>(b.length() + 1, -1));
    int maxlenth = solve(a.length() - 1, b.length() - 1);
    int x = b.length() - 1, y = a.length() - 1;
    string t = "";
    while (x > 0 && y > 0)
    {
        if (memo[y][x] == memo[y - 1][x])
            y--;
        else if (memo[y][x] == memo[y][x - 1])
            x--;
        else
        {
            t = a[y--] + t;
            x--;
        }
    }
    cout << t;
    return 0;
}

Measured memory_bytes: 35968
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <functional>
#include <map>
#include <queue>

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

using namespace std;
using ll = long long;
using P = pair<int, int>;
using TP = tuple<ll, ll, ll>;
ll MOD = 1e9+7;
ll INF = 1LL<<40;


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

    ll N, M;
    cin >> N >> M;
    ll ans = 0;
    for(ll i = M/N; i >= 1; i--){
        if(M%i == 0){
            if(M/i >= N){
                ans = i;
                break;
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<cmath>
#include<sstream>
#include<string>
using namespace std;
typedef long long ll;
ll mod = 1e9+7;
#define rep(i,n) for(int i = 0; i < (n); ++i)
bool used[27];
int main(){
    string s;
    cin >> s;
    rep(i, (int)s.length()) {
        used[s[i]-'a'] = 1;
    }
    if ( (int)s.length() < 26 ) {
        rep(i, 26) {
            if ( !used[i] ) {
                s += char('a'+i);
                break;
            }
        }
        cout << s << endl;
    }
    else {
        int id = -1;
        for ( int i = (int)s.length()-2; i >= 0; --i ) {
            if ( s[i] < s[i+1] ) {
                id = i;
                break;
            }
        }
        if ( id == -1 ) {
            cout << -1 << endl;
        }
        else {
            string t = s.substr(0, id);
            int idx2 = id + 1;
            for ( int i = id + 1; i < (int)s.length(); ++i ) {
                if ( s[i] < s[idx2]  && s[i] > s[id] ) {
                    idx2 = i;
                }
            }
            t += s[idx2];
            cout << t << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 256
def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a
a, b = map(int, input().split())
apri = set(prime_factorize(a))
bpri = set(prime_factorize(b))
print(len(apri & bpri)+1)


Measured memory_bytes: 3060
#include <stdio.h>
#include <stdlib.h>

#define HASH 1000003

typedef struct List {
	struct List *next;
	char *s;
	int l;
} list;

long long div_mod(long long x, long long y, long long z)
{
	if (x % y == 0) return x / y;
	else return (div_mod((1 + x / y) * y - x, (z % y), y) * z + x) / y;
}

int hash_string(char* s)
{
	int i, x = 0;
	for (i = 0; s[i] != 0; i++) x = ((x << 5) + s[i] - 'a') % HASH;
	return x;
}

int lex_smaller(char* s1, char* s2)
{
	int i;
	for (i = 0; s1[i] != 0 && s2[i] != 0; i++) {
		if (s1[i] < s2[i]) return 1;
		else if (s1[i] > s2[i]) return -1;
	}
	if (s1[i] == s2[i]) return 0;
	else if (s1[i] == 0) return 1;
	else return -1;
}

int main()
{
	int i, j, l[200001], N;
	char *S[200001], T[1000001];
	scanf("%d", &N);
	for (i = 1; i <= N; i++) {
		scanf("%s", T);
		for (l[i] = 0; T[l[i]] != 0; l[i]++);
		S[i] = (char*)malloc(sizeof(char) * (l[i] + 1));
		for (j = 0; j <= l[i]; j++) S[i][j] = T[j];
	}
	
	int h[200001];
	list *p, *hash[HASH], d[200001];
	for (i = 1; i <= N; i++) {
		h[i] = hash_string(S[i]);
		d[i].s = S[i];
		d[i].l = l[i];
		d[i].next = hash[h[i]];
		hash[h[i]] = &(d[i]);
	}
	
	int k, dp[26];
	long long ans = 0, tmp, pow[32];
	const long long inv = div_mod(1, 32, HASH);
	for (k = 1, pow[0] = 32; k < 32; k++) pow[k] = pow[k-1] * pow[k-1] % HASH;
	for (i = 1; i <= N; i++) {
		if (l[i] <= 1) continue;
		for (j = 0; j <= l[i]; j++) T[j] = S[i][j];
		for (j = l[i] - 1, k = 0, tmp = 1; j > 0; j >>= 1, k++) if ((j & 1) == 1) tmp = tmp * pow[k] % HASH;
		h[i] = (h[i] - tmp * (T[0] - 'a') % HASH + HASH) % HASH;
		tmp = tmp * inv % HASH;
		h[i] = (h[i] - tmp * (T[1] - 'a') % HASH + HASH) % HASH;
		for (j = 0; j < 26; j++) dp[j] = 0;
		dp[S[i][0] - 'a'] = 1;
		for (j = 1; j < l[i]; j++) {
			dp[S[i][j] - 'a'] = 1;
			for (k = 0; k < 26; k++) {
				if (dp[k] == 0) continue;
				T[j] = 'a' + k;
				h[0] = (tmp * k + h[i]) % HASH;
				for (p = hash[h[0]]; p != NULL; p = p->next) if (p->l == l[i] - j && p->s[0] == T[j] && p->s[p->l - 1] == T[l[i] - 1] && lex_smaller(p->s, &(T[j])) == 0) break;
				if (p != NULL) ans++;
			}
			tmp = tmp * inv % HASH;
			h[i] = (h[i] - tmp * (S[i][j+1] - 'a') % HASH + HASH) % HASH;
		}
	}
	
	printf("%lld\n", ans);
	fflush(stdout);
	return 0;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define REP(i, n) for(int i=0; i<n; i++)
#define REPi(i, a, b) for(int i=int(a); i<int(b); 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; }
const ll MOD = 998244353;

const int MAX_N = 300000;

ll fact[MAX_N+100];
ll frev[MAX_N+100];

ll rev(ll a, ll p){
    if(p == 0) return 1;
    ll tmp = rev(a, p/2);
    tmp = tmp * tmp % MOD;
    if(p % 2 == 1) tmp = tmp * a % MOD;
    return tmp;
}


void calc_fact(){
    fact[0] = frev[0] = 1;
    for(int i = 1; i <= MAX_N; i++){
        fact[i] = (fact[i-1] * i) % MOD;
        frev[i] = rev(fact[i], MOD-2);
    }
}


ll comb(int n, int k){
    if(n < 0 || k < 0 || n < k) return 0;
    if(n == 0 || k == 0) return 1;
    return fact[n] * frev[k] % MOD * frev[n-k] % MOD;
}


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

    fact[0] = frev[0] = 1;
    for(int i = 1; i <= MAX_N; i++){
        fact[i] = (fact[i-1] * i) % MOD;
        frev[i] = rev(fact[i], MOD-2);
    }

    ll ans = 0;
    for(ll x = 0; x <= N; x++){
        ll rhs = K - A*x;
        if(rhs < 0) continue;
        if(rhs % B != 0) continue;
        ll y = rhs / B;
        ans += (comb(N, x) * comb(N, y)) % MOD;
        ans %= MOD;
    }

    cout << ans << endl;

    return 0;
}


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

vector<int>adj[100001];
int dp[100001];
int solve(int u)
{
    if(dp[u]!= -1)
       return dp[u];

    bool leaf = 1;
    for(auto child : adj[u])
    {
        leaf = 0;
        dp[u] = max(dp[u],(1+solve(child)));
    }
    if(leaf)
     dp[u] = 0;

   return dp[u];
}
int main(void)
{
    int n,m,x,y;
    cin>>n>>m;
    for(int  i = 0;i<m;i++)
    {
         cin>>x>>y;
         adj[x].push_back(y);
    }
    memset(dp, -1 ,sizeof dp);
     int ans = 0;
    for(int  i = 1;i<=n;i++)
    {
       ans = max(ans,solve(i));
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 7424