akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <assert.h>
using namespace std;
using i64 = long long;

int main()
{
    i64 n, a;
    cin >> n >> a;
    if (n % 500 <= a)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
using namespace std;

//ループマクロ
#define FOR(i , a , b)  for(int i = (a) ; i < (b) ; i++)
#define REP(i , n)      for(int i = 0 ; i < n ; i++)
#define REPR(i , n)     for(int i = n ; 0 <= i ; i--)

//入出力
#define SCOUT(x) cout << (x) << " "
#define VECCIN(x) for(auto& ele : (x) ) cin >> ele
#define VECOUT(x) for(auto& ele : (x) ) cout << ele << " "; cout << endl;

//その他
#define ALL(obj) (obj).begin() , (obj).end() 
#define P pair<int , int>
#define V vector<int>
#define PQ priority_queue<int>
#define PQG priority_queue<int , V , greater<int>>
int main(void) {

	ios::sync_with_stdio(false);	cin.tie(0);
	ll N, A, B;  cin >> N >> A >> B;
	ll ans = 0;
	ll pre, now;  cin >> pre;
	for(ll i = 1 ; i < N ; i++){
	 cin >> now;
	 ans += min((now - pre) * A, B);
	 pre = now;
	}

	cout << ans << endl;

	return 0;
}

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


int main() {
	int N;
	cin >> N;
	vector<int> vec(N);

	for (int i = 0; i < N; i++) {
		cin >> vec[i];
	}
	vector<int> dep = vec;

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

	

	for (int i = 0; i < N; i++) {
		if (vec.at(i) > dep.at(N / 2)) {
			cout << dep.at(N / 2-1) << endl;
		}
		 else if(vec.at(i) == dep.at(N / 2)) {
			cout << dep.at(N / 2-1) << endl;
		}
		 else if (vec.at(i) < dep.at(N / 2)&& vec.at(i) > dep.at(N / 2-1)) {
			 cout << dep.at(N / 2-1) << endl;
		 }
		 else if (vec.at(i) ==dep.at(N / 2-1)) {
			 cout << dep.at(N / 2) << endl;
		 }
		 else if (vec.at(i) < dep.at(N / 2-1)) {
			 cout << dep.at(N / 2) << endl;
		 }

	}
		


		
	return 0;
}






Measured memory_bytes: 3712
from functools import reduce
def reduce_wrapper(func, *args):
    if len(args) == 1:
        return reduce(func, args[0])
    return reduce(func, args)

from fractions import gcd
def lcm(*args):
    return reduce_wrapper(lambda x, y: x*y // gcd(x, y), *args)

def xgcd(a, b):
    ''' return (g, x, y) such that a*x + b*y = g = gcd(a, b) '''
    x0, x1, y0, y1 = 0, 1, 1, 0
    while a != 0:
        (q, a), b = divmod(b, a), a
        y0, y1 = y1, y0 - q * y1
        x0, x1 = x1, x0 - q * x1
    return b, x0, y0

def modinv(n):
    g, x, _ = xgcd(n, mod)
    if g != 1:
        raise ValueError('Modinv is not exist! arg={}'.format(n))
    return x % mod

mod = 10**9 + 7
n, *A = map(int, open(0).read().split())

l = lcm(A) % mod
s = 0
for a in A:
    s += l * modinv(a)
    s %= mod
print(s)

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

int main(){
    int A, B, C, N, M ,K;
    int sum = 0;
    int t = 0;
    string s, s1;

    vector<int> X(5);
    for(int i = 4; i >=0 ; i--){
        cin >> X.at(i);
    }
    cin >> K;

    for(int i = 0; i < 5; i++){
        for(int j = i+1; j < 5; j++){
            if(X.at(i) - X.at(j) > K) {
                cout << ":(" << endl;
                return 0;
            }
        }
    }

    cout << "Yay!" << endl;
//    for(int i = 0; i < ; i++){}
//    for(int j = 0; j < ; j++){}

//    cout <<  << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;

#ifdef MUTABLE
int mod;
#else
template<int mod>
#endif
struct ModInt {
  int val;
  ModInt inv() const{
    int tmp,a=val,b=mod,x=1,y=0;
    while(b)tmp=a/b,a-=tmp*b,swap(a,b),x-=tmp*y,swap(x,y);
    return ModInt(x);
  }
  ModInt():val(0){}
  ModInt(ll x){if((val=x%mod)<0)val+=mod;}
  ModInt pow(ll t){ModInt res=1,b=*this; while(t){if(t&1)res*=b;b*=b;t>>=1;}return res;}
  ModInt& operator+=(const ModInt& x){if((val+=x.val)>=mod)val-=mod;return *this;}
  ModInt& operator-=(const ModInt& x){if((val+=mod-x.val)>=mod)val-=mod; return *this;}
  ModInt& operator*=(const ModInt& x){val=(ll)val*x.val%mod; return *this;}
  ModInt& operator/=(const ModInt& x){return *this*=x.inv();}
  bool operator==(const ModInt& x) const{return val==x.val;}
  bool operator!=(const ModInt& x) const{return val!=x.val;}
  bool operator<(const ModInt& x) const{return val<x.val;}
  bool operator<=(const ModInt& x) const{return val<=x.val;}
  bool operator>(const ModInt& x) const{return val>x.val;}
  bool operator>=(const ModInt& x) const{return val>=x.val;}
  ModInt operator+(const ModInt& x) const{return ModInt(*this)+=x;}
  ModInt operator-(const ModInt& x) const{return ModInt(*this)-=x;}
  ModInt operator*(const ModInt& x) const{return ModInt(*this)*=x;}
  ModInt operator/(const ModInt& x) const{return ModInt(*this)/=x;}
  static int get_mod() { return mod; }
};

#ifndef MUTABLE
using modint = ModInt<1000000007>;
#endif

modint dp[51][51][2501];

int main() {
  int n, K; cin >> n >> K;
  dp[0][0][0] = 1;
  for (int i = 0; i < n; ++i) {  // 見ている要素の位置
    for (int j = 0; j < i+1; ++j) {  // 保留の数
      for (int k = 0; k < K+1; ++k) { 
        { // 解説動画のア (横につなぐ)
          int nj = j;
          dp[i+1][nj][k+nj*2] += dp[i][j][k];
        }
        { // 解説動画のイ (両方保留)
          int nj = j+1;
          dp[i+1][nj][k+nj*2] += dp[i][j][k];
        }
        { // 解説動画のウ (片方つなぐ)
          int nj = j;
          modint x = 2*j;
          dp[i+1][nj][k+nj*2] += x*dp[i][j][k];
        }
        { // 解説動画のエ (両方つなぐ)
          int nj = j-1;
          modint x = j*j;
          dp[i+1][nj][k+nj*2] += x*dp[i][j][k];
        }
      }
    }
  }
  cout << dp[n][0][K].val << endl;
}



Measured memory_bytes: 25600
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <sstream>
#include <cstring>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <numeric>
#include <functional>
#include <cmath>
#include <array>

#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll; typedef vector<int> VI;
typedef pair<int,int> pii;
const int mod = (int)1e9+7;


int main()
{
	
	//cin.tie(0); ios_base::sync_with_stdio(false);
	string s;
	cin >> s;
	int dr[4]={};
	rep(i,sz(s)){
		if(s[i]=='N') dr[0]++;
		if(s[i]=='S') dr[1]++;
		if(s[i]=='E') dr[2]++;
		if(s[i]=='W') dr[3]++;
	}
	if(dr[0] == 0 && dr[1]>0) puts("No");
	else if(dr[1] == 0 && dr[0]>0) puts("No");
	else if(dr[2] == 0 && dr[3]>0) puts("No");
	else if(dr[3] == 0 && dr[2]>0) puts("No");
	else puts("Yes");
	
	return 0;
}


Measured memory_bytes: 256
INF = 1 << 28
N, q = gets.split.map(&:to_i)
S = "<#{gets.chomp}>"
Q = q.times.map{gets.chomp.intern}.reverse

def move(pos, op)
  S[pos] != op[0] ? pos : (op[2] == 'L' ? pos - 1 : pos + 1)
end

l,r = 1, N
Q.each do |op|
  l = (l - 1 .. l + 1).min_by{|pos| move(pos, op) >= l ? pos :  INF}
  r = (r - 1 .. r + 1).max_by{|pos| move(pos, op) <= r ? pos : -INF}
  break if r < l
end
puts r < l ? 0 : r - l + 1


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

using ll = long long;
#define ALL(c) (c).begin(), (c).end()
const int MOD = 1000000007;

int main() {
    int n;
    cin >> n;
    vector<vector<int>> f(n, vector<int>(10));
    vector<vector<int>> p(n, vector<int>(11));
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < 10; j++) {
            cin >> f[i][j];
        }
    }
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < 11; j++) {
            cin >> p[i][j];
        }
    }

    int mx = -1000000100;
    for (int i = 1; i < 1 << 10; i++) {
        vector<int> c(n, 0);
        for (int j = 0; j < 10; j++) {
            if ((1 & i >> j) == 1) {
                for (int k = 0; k < n; k++) {
                    if (f[k][j] == 1) {
                        c[k]++;
                    }
                }
            }
        }
        int sum = 0;
        for (int j = 0; j < n; j++) {
            sum += p[j][c[j]];
        }
        mx = max(mx, sum);
    }

    cout << mx << endl;
}


Measured memory_bytes: 256
//Mohamed Galal
#define _CRT_SECURE_NO_WARNINGS
#include <cstring>
#include <map>
#include <deque>
#include <queue>
#include <stack>
#include <sstream>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <fstream>
#include <string>
#include <cstdlib>
#include <functional>
#include <algorithm>
#include <vector>
#include <set>
#include <complex>
#include <list>
#include <climits>
#include <cctype>
#include <bitset>
#define PI 3.14159265359
#define all(v)  ((v).begin()), ((v).end())
#define all(s)  ((s).begin()), ((s).end())
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
using namespace std;
void file()
{
	freopen("in.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
}
void Mohamed_Galal()
{
	ios_base::sync_with_stdio(0);
	cin.tie(NULL), cout.tie(NULL);
}
int main()
{
	Mohamed_Galal();
	ll n;
	cin >> n;
	ll *arr = new ll[n];
	arr[0] = 2, arr[1] = 1; 
	for (size_t i = 2; i <= n; i++)
		arr[i] = (arr[i - 1] + arr[i - 2]);
	cout << arr[n] << endl;
	return 0;
}

Measured memory_bytes: 256
n,k=map(int,input().split())
a=list(map(int,input().split()))

x=[0 for _ in range(n)]
for i in range(1,n):
	for j in range(i):
		if a[j]>a[i]:
			x[i]+=1

y=[0 for _ in range(n)]
for i in range(1,n):
	for j in range(i):
		if a[j]<a[i]:
			y[i]+=1


print((sum(x)*k*(k+1)//2+sum(y)*k*(k-1)//2)%(10**9+7))

Measured memory_bytes: 41564
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		//n次元ベクトル
		int n = sc.nextInt();

		double M = 0;
		double U = 0;
		double ppp = 0;
		double c = 0;

		//ベクトルx,y
		int[] x = new int[n];
		for (int i = 0; i < x.length; i++) {
			x[i] = sc.nextInt();

		}

		int[] y = new int[n];
		for (int i = 0; i < y.length; i++) {
			y[i] = sc.nextInt();

		}

		double pow = 0;
		for (int i = 0; i < n; i++) {
			//p=1 マンハッタン距離
			pow = Math.abs(x[i] - y[i]);
			M += pow;
		}

		double pow2 = 0;
		for (int i = 0; i < n; i++) {
			//p=2 ユークリッド距離
			int num = Math.abs(x[i] - y[i]);
			num *= num;
			pow2 += num;

		}
		U = Math.sqrt(pow2);

		double pow3 = 0;
		for (int i = 0; i < n; i++) {
			//p=3
			int num = (Math.abs(x[i] - y[i]));
			num *= num * num;
			pow3 += num;
		}

		ppp = Math.cbrt(pow3);

		double pow4 = 0;

		for (int i = 0; i < n; i++) {
			//p=∞ チェビシェフ距離
			pow4 = Math.abs(x[i] - y[i]);
			c = Math.max(pow4, c);

		}

		System.out.println(M);
		System.out.println(U);
		System.out.println(ppp);
		System.out.println(c);

		sc.close();

	}
}



Measured memory_bytes: 26568
package main

import "fmt"

func main() {
	var w string
	fmt.Scan(&w)

	xm := make(map[rune]int)
	for _, r := range w {
		xm[r]++
	}

	for _, v := range xm {
		if v%2 != 0 {
			fmt.Println("No")
			return
		}
	}
	fmt.Println("Yes")
}


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

#define int long long
#define ll long long
#define f1(i,a,b) for(i=a;i<b;i++)
#define f2(i,a,b) for(i=a;i>=b;i--)
#define endl '\n'
#define pb push_back
#define gp " "
#define ff first
#define ss second
#define mp make_pair

const int mod=1000000007;
int i,j;
ll temp;

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    // #ifndef ONLINE_JUDGE
    // 	freopen("/home/akmittal/Desktop/Competitive Programming/in.txt","r",stdin);
    // 	freopen("/home/akmittal/Desktop/Competitive Programming/out.txt","w",stdout);
    // #endif
    int n,m;
    cin>>n>>m;
    int a[n+1];
    f1(i,0,n+1)
    a[i]=-1;
    f1(i,0,m)
    {
    	cin>>temp;
    	a[temp]=0;
    }
    if(a[0]==0)
    {
    	cout<<0;
    	return 0;
    }
    a[0]=1;
    int s0=0;
    f1(i,0,n+1)
    {
    	if(a[i]==-1)
    	{
    		if(i==1)
    		{
    			a[i]=a[0]+s0;
    		}
    		else
    		{
    			a[i]=a[i-1]+a[i-2];
    			a[i]%=mod;
    		}
    	}
    }
    cout<<a[n];
    return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
 
using namespace std;
 
int main(){
    while( true ){
        int n;
        int ma = 0;
        int mi = 1000;
        int s = 0;
        cin >> n;

        if(n == 0){
            break;
        }

        int a[n];

        for(int i=0;i<n;i++){
            cin >> a[i];
            if(ma < a[i]){
                ma = a[i];
            }
            if(mi > a[i]){
                mi = a[i];
            }
            s += a[i];
        }

        cout << (s - ma - mi)/(n - 2) << endl;
    }   
 
}

Measured memory_bytes: 1160
///////////////////////////////////////////
//                                       //
//      Gagan_Sharma : DTU               // 
//                                       //                   
///////////////////////////////////////////
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
#define int        long long
// #define mp      make_pair
#define eb         emplace_back
#define pb         push_back
#define ss         second
#define ff         first
#define IOS        ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define mod        998244353
#define MOD        (1000*1000*1000+7)
#define MN         LLONG_MIN
#define MX         LLONG_MAX
#define v1d        vector<int>
#define v2d        vector<vector<int>>
#define vip        vector<pair<int,int> >
#define v1s        vector<string>
#define pa         pair<int,int>
#define mxpq(T)    priority_queue <T>
#define mnpq(T)    priority_queue<T,vector<T>,greater<T>>
#define print(v)   for(auto i:v)cout<<i<<" ";cout<<"\n";
#define p2d(v)     for(auto a:v){for(auto b:a)cout<<b<<" ";cout<<endl;}
#define p1d(v)     for(auto a:v)cout<<a<<" ";cout<<endl;
#define ppd(v)     for(auto a:v)cout<<a.ff<<" "<<a.ss<<endl;
#define endl       '\n'
#define input(b,n) for(int i=0;i<n;i++)cin>>b[i+1];
#define Sort(v)    sort(v.begin(),v.end())
#define RSort(v)   sort(v.rbegin(),v.rend())
#define all(v)     v.begin(),v.end()
int gcd(int a,int b){return b?gcd(b,a%b):a;}
//string s = bitset<64>(a).to_string();
 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
#define fbo find_by_order // iterator to the kth element
#define ook order_of_key  //number of items that are strictly smaller than our item k
// #define T pair<int, int>
// #define ordered_set tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>
 
void read(int n=12){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cout<<setprecision(n)<<fixed;
}
 
//____________________________________________________________________________________
 
 
void solve(){
    int n;cin>>n;
    v1d h(n+5);input(h,n);
    v1d dp(n+5);
    dp[1] = 0;
    dp[2] = abs(h[2]-h[1]);
    for(int i=3;i<=n;i++)dp[i] = min(dp[i-1]+abs(h[i]-h[i-1]), dp[i-2]+abs(h[i]-h[i-2]));
    cout<<dp[n];
 
}
 
int32_t main(){
    read();
    int t = 1;
    // cin>>t;
    while(t--){
        solve();
    }
    
 
 
    return 0;
}  


Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <stdio.h>
#include <math.h>
#include <queue>
using namespace std;


int main(int argc, char* argv[])
{
	int K;
	scanf("%d", &K);

	queue<long long> A;

	for(long long i=0; i<9; i++){
		A.push(i+1);
	}

	for(int i=0; i<K-1; i++){
		long long x = A.front();
		if(x%10 == 0){
			A.push(x * 10 + 0);
			A.push(x * 10 + 1);
		}else if(x%10 == 9){
			A.push(x * 10 + 8);
			A.push(x * 10 + 9);
		}else{
			A.push(x * 10 + x%10 - 1);
			A.push(x * 10 + x%10 + 0);
			A.push(x * 10 + x%10 + 1);
		}
		A.pop();
	}

	long long y = A.front();


	printf("%lld\n",y);


	return 0;
}





Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
long long dp[5010];
long long dp2[25000010];
int main() {
    int n; cin >> n;
    long long g[3][2]; 
    dp[n] = n;
    for (int i = 0; i < 2; i++) {
        for (int j = 0; j < 3; j++) {
            cin >> g[j][i];
        }
    }
    for (int t = 0; t < 3; t++) {
        if (g[t][0] < g[t][1]) {
            for (int i = n; i >= 0; i--) {
                if (i >= g[t][0]) {
                    dp[i-g[t][0]] = max(dp[i-g[t][0]], dp[i] + g[t][1] - g[t][0]);
                }
            }
        }
    }
    long long maxn = 0;
    for (int i = 0; i <= n; i++) {
        maxn = max(maxn, dp[i]);
    }
    dp2[maxn] = maxn;
    for (int t = 0; t < 3; t++) {
        if (g[t][1] < g[t][0]) {
            for (int i = maxn; i >= 0; i--) {
                if (i >= g[t][1]) {
                    dp2[i-g[t][1]] = max(dp2[i-g[t][1]], dp2[i] + g[t][0] - g[t][1]);
                }
            }
        }
    }
    long long ans = 0;
    for (int i = 0; i <= maxn; i++) {
        ans = max(ans, dp2[i]);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 195584
#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)

int main() {
	int d, n;
	cin >> d >> n;
	if (d == 0) {
		if (n == 100) {
			cout << 101 << endl;
			return 0;
		}
		cout << n << endl;
	} 
	else if (d == 1) {
		if (n == 100) {
			cout << 10100 << endl;
			return 0;
		}
		cout << n * 100 << endl;
	}
	else {
		if (n == 100) {
			cout << 1010000 << endl;
			return 0;
		}
		cout << n * 10000 << endl;
	}


	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define mod 1000000007
#define db(a) cout << a << endl
#define db2(a,b) cout << a << " " << b << endl
#define dbp(a) cout << a.first << " " << a.second << endl
#define adb(a) for(auto i:a) cout << i << " "; cout << endl
#define adb2(a) for(auto i:a) cout << i.first << " " << i.second << endl;
#define fastIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define N 100010
using namespace std;

int main()
{
    fastIO;
    string s;
    cin >> s;

    if(s == "AAA" || s == "BBB") cout << "No" << endl;
    else cout << "Yes" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <map>
#define snd second
using namespace std;
int n,tp;
map<int,int> mp;
int main()
{
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin>>n;
	for (int i=0;i<n;i++)
	{
		cin>>tp;
		mp[tp]++;
	}
	if (mp.size()==1)
	{
		if (mp[0]) {cout<<"Yes\n";}
		else {cout<<"No\n";}
	}
	else if (n%3==0)
	{
		if (mp.size()==3)
		{
			int to = 0,xx = 0;
			for (auto x:mp) {to += (x.snd==n/3);xx^=x.first;}
			if (to==3 && xx==0) {cout<<"Yes\n";}
			else {cout<<"No\n";}
		}
		else if (mp.size()==2)
		{
			if (mp[0]==n/3) {cout<<"Yes\n";}
			else {cout<<"No\n";}
		}
		else {cout<<"No\n";}
	}
	else {cout<<"No\n";}
	return 0;
}

Measured memory_bytes: 3840
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
vector<int> a(14);
bool solve(int x, int y);
int main(){
  string s;
  while(cin >>s){
    vector<int> ans;
    for(int i=1; i<10; i++){
      int n[10]={};
      bool f = true;
      for(int j=0; j<s.size(); j++) a[j] = s[j]-'0';
      a[13] = i;
      sort(a.begin(),a.end());
      for(int j=0; j<a.size(); j++) n[a[j]]++;
      for(int j=1; j<10; j++) if(n[j]>4) f = false;
      if(f) if(solve(1,4)) ans.push_back(i);
    }
    if(ans.size() == 0) cout <<"0"<<endl;
    else{
      for(int i=0; i<ans.size(); i++){
	if(i != 0) cout <<" ";
	cout <<ans[i];
      }
      cout <<endl;
    }
  }
}
bool solve(int x, int y){
  int ans = false;
  if(x == 0 && y == 0) return true;
  if(x == 1){
    for(int i=0; i<13; i++){
      if(a[i] == -1) continue;
      if(a[i] == a[i+1]){
	int sc = a[i];
	a[i] = a[i+1] = -1;
	ans = ans|solve(0,y);
	a[i] = a[i+1] = sc;
      }
    }
  }
  if(y != 0){
    for(int i=0; i<12; i++){
      if(a[i] == -1) continue;
      if(a[i] == a[i+1] && a[i+1] == a[i+2]){
	int sc = a[i];
	a[i] = a[i+1] = a[i+2] = -1;
	ans = ans|solve(x,y-1);
	a[i] = a[i+1] = a[i+2] = sc;
      }
      for(int j=i+1; j<13; j++){
	if(a[j]!=a[i]+1) continue;
	for(int k=j+1; k<14; k++){
	  if(a[k]!=a[j]+1) continue;
	  int sc = a[i];
	  a[i] = a[j] = a[k] = -1;
	  ans = ans|solve(x,y-1);
	  a[i] = sc; a[j] = sc+1; a[k] = sc+2;
	}
      }
    }
  }
  return ans;
}

Measured memory_bytes: 1204
# DPL 1 D

import bisect

def solve():
    n = int(input())
    a = [int(input()) for _ in range(n)]
    dp = []
    dp.append(a[0])
    for i in range(1, n):
        if a[i] > dp[-1]:
            dp.append(a[i])
        else:
            j = bisect.bisect_left(dp, a[i])
            dp[j] = a[i]

    print(len(dp))


if __name__ == "__main__":
    solve()



Measured memory_bytes: 10356
from collections import defaultdict


def resolve():
    n = int(input())
    a = list(map(int, input().split()))
    d = defaultdict(int)
    for ai in a:
        d[ai] += 1
    f = sorted([k for k, v in d.items() if v >= 2], reverse=True)
    if len(f) < 2:
        ans = 0
    else:
        if d[f[0]] >= 4:
            ans = max(f[0] ** 2, f[0] * f[1])
        else:
            ans = f[0] * f[1]
    print(ans)


if __name__ == "__main__":
    resolve()


Measured memory_bytes: 18600
#include <iostream>
#include <cmath>

using namespace std;

int main() {
    long long N;
  	scanf("%lld",&N);
	long long ans = N - 1;

    for (long long i = 2; i * i <= N; ++i) {
        if (N % i == 0){
            ans = min(ans, i + N / i - 2);
        }
    }

    printf("%lld\n", ans);

    return 0;
}


Measured memory_bytes: 256
import sys
from io import StringIO
import unittest

def resolve():
    N, W = map(int, input().split())

    wv = [list(map(int, input().split())) for _ in range(N)]

    # 荷物の個数 * 価値上限 -> 重さ最小化
    # これだとcase2が10**9なので解けない
    inf = 10 ** 10
    max_v = sum([v for w, v in wv])+ 10
    sum_w = sum([w for w, v in wv])

    dp = [[inf for _ in range(max_v + 2)] for __ in range(N + 1)]

    # for i in range(max_v + 2):
    #     dp[0][i] = 0

    for i in range(N + 1):
        dp[i][0] = 0

    # ２つ目の添字を超えないように価値を選んだときの、最小の重み
    # 送るモード
    for i in range(N):
        w = wv[i][0]
        v = wv[i][1]
        for j in range(max_v + 2):
            if j - v >= 0:
                dp[i + 1][j] = min(dp[i][j], dp[i][j - v] + w)
            else:
                dp[i + 1][j] = dp[i][j]
            # if j - v >= 0:
            #     dp[i + 1][j] = min(dp[i][j], dp[i][j - v] + w)
            # elif j <= v:
            #     dp[i + 1][j] = min(dp[i][j], w)
            # else:
            #     dp[i + 1][j] = dp[i][j]

    # for d in dp:
    #     print(d)
    # print(W)
    # print([i for d in dp for i, w in enumerate(d) if w <= W])
    print(max([i for d in dp for i, w in enumerate(d) if w <= W]))


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)
    def test_入力例_1(self):
        input = """3 8
3 30
4 50
5 60"""
        output = """90"""
        self.assertIO(input, output)
    def test_入力例_2(self):
        input = """1 1000000000
1000000000 10"""
        output = """10"""
        self.assertIO(input, output)
    def test_入力例_3(self):
        input = """6 15
6 5
5 6
6 4
6 6
3 5
7 2"""
        output = """17"""
        self.assertIO(input, output)

if __name__ == "__main__":
    # unittest.main()
    resolve()

Measured memory_bytes: 224884
from collections import deque
import sys

sys.setrecursionlimit(10 ** 5 + 10)


def resolve():
    N = int(input())
    H = list(map(int, input().split()))

    cluster = deque([H])
    cnt = 0
    while cluster:
        i = cluster.popleft()
        if len(i) != 0:
            mini = min(i)
            cnt += mini
            for j in range(len(i)):
                i[j] -= mini

            j = 0

            for k in range(len(i)):
                if i[k] == 0:
                    cluster.append(i[j:k])

                    j = k + 1
                elif k == len(i) - 1:
                    cluster.append(i[j:len(i)])

    print(cnt)


resolve()


Measured memory_bytes: 38640
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef pair<int, int> P;
int main() {
  int N;
  cin >> N;
  vector<ll> A(N);
  REP(i, N) cin >> A[i];
  unordered_map<ll, ll> lum{}, rum{};
  REP(i, N) {
    lum[A[i] + i + 1]++;
    rum[-A[i] + i + 1]++;
  }
  ll ans = 0;
  for (auto s : lum) {
    ans += s.second*rum[s.first];
  }
  cout << ans << endl;
}

Measured memory_bytes: 27928
#include<algorithm>
#include<climits>
#include<cmath>
#include<cstring>
#include<deque>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;

using lint = long long;
using P = pair<int, int>;
using LLP = pair<long long, long long>;

#define REP(i, x, n) for(int i = (x), i##_len = int(n) ; i < i##_len ; ++i)
#define rep(i, n) for(int i = 0, i##_len = int(n) ; i < i##_len ; ++i)
#define reps(i, n) for(int i = 1, i##_len = int(n) ; i <= i##_len ; ++i)
#define rrep(i, n) for(int i = int(n) - 1 ; i >= 0 ; --i)
#define rreps(i, n) for(int i = int(n) ; i > 0 ; --i)
#define SORT(x) sort((x).begin(), (x).end())
#define SORT_INV(x) sort((x).rbegin(), (x).rend())
#define TWINS(x) cout << ((x) ? "Yay!" : ":(") << endl

const int IINF = (1 << 30) - 1;
const long long LLINF = 1LL << 61;
const int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1};
const int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};
const double EPS = 1e-8;

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

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

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

    int n;
    while(cin >> n, n){
        lint ascore = 0, bscore = 0;
        rep(i, n){
            lint a, b;
            cin >> a >> b;
            if(a == b){
                ascore += a;
                bscore += b;
            }else if(a < b){
                bscore += a + b;
            }else{
                ascore += a + b;
            }
        }

        cout << ascore << " " << bscore << endl;
    }

    return 0;
}


Measured memory_bytes: 3072
using System;
using System.Text;
using System.Collections.Generic;
using static System.Math;
using System.Linq;
using static System.Array;

namespace Vertial
{
    class Program
    {
        static int[][] D;
        static int[][] map;
        static int N;
        static int[,] dist;
        static int C;
        static void Main(string[] args)
        {
            var NC = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
            N = NC[0];
            C = NC[1];

            D = new int[C][];
            for (int i = 0; i < C; i++)
            {
                D[i] = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
            }

            map = new int[N][];
            for (int i = 0; i < N; i++)
            {
                map[i] = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
            }
            dist = new int[3,C+1];
            for (int i = 1; i <= N; i++)
            {
                for (int j = 1; j <= N; j++)
                {
                    if ((i + j) % 3 == 0)
                    {
                        dist[0, map[i - 1][j - 1]]++;
                    }
                    else if ((i + j) % 3 == 1)
                    {
                        dist[1, map[i - 1][j - 1]]++;
                    }
                    else
                    {
                        dist[2, map[i - 1][j - 1]]++;
                    }
                }
            }
            var min = long.MaxValue;
            
            for (int i = 1; i <= C; i++)
            {
                for (int j = 1; j <= C; j++)
                {
                    for (int k = 1; k <= C; k++)
                    {
                        if(!(i == j || j == k || i== k))
                        {
                            //3割って0余るものをi,1あまるものをj,2余るものをに変換する
                            min = Min(min, Calculation(i, j, k));
                        }
                    }
                }
            }
            Console.WriteLine(min);
        }

        static long Calculation(int a,int b,int c)
        {
            long ans = 0;
            for (int i = 0; i < 3; i++)
            {
                for (int j = 1; j <= C; j++)
                {
                    if(i == 0)
                    {
                        ans += dist[i, j] * D[j - 1][a-1];
                    }else if(i == 1)
                    {
                        ans += dist[i, j] * D[j - 1][b-1];
                    }
                    else
                    {
                        ans += dist[i, j] * D[j - 1][c-1];
                    }
                    
                }
            }
            
            return ans;
        }


    }
}


Measured memory_bytes: 18756
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
#include<map>
#include<stack>
#include<vector>
#include<queue>
#include<set>
#include<algorithm>
const int N = 1e9;
using namespace std;
#define INF 0x3f3f3f3f
#define mod 1000000009
#define e  2.718281828459045
#define PI acos(-1)
#define lowbit(x) (x&(-x))
#define read(x) scanf("%d",&x)
#define put(x) printf("%d\n",x)
#define memset(x,y) memset(x,y,sizeof(x))
#define ll long long

int main(){

	int a,b;
	cin>>a>>b;
	cout<<6-a-b<<endl; 
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cmath>

using namespace std;

void show_vertex(double x, double y) {
	cout << fixed;
	cout << setprecision(8) << x << " " << y << endl;
}
	// 線分を3等分する関数
void koch(double x0, double y0, double x1, double y1, int n) {
	//3等分する点をだす
	double x2 = (2 * x0 + x1) / 3;
	double y2 = (2 * y0 + y1) / 3;
	double x3 = (x0 + 2 * x1) / 3;
	double y3 = (y0 + 2 * y1) / 3;
	//正三角形の残りの頂点を出す(これ面倒...)
	double dx = x3 - x2;
	double dy = y3 - y2;
	double x4 = (x0 + x1) / 2 - dy * sqrt(3) / 2;
	double y4 = (y0 + y1) / 2 + dx * sqrt(3) / 2;
	//座標の描画
	if (n == 0) {
		//cout << x0 << " " << y0 << endl;
		show_vertex(x0, y0);
	} else {
		koch(x0, y0, x2, y2, n-1);
		koch(x2, y2, x4, y4, n-1);
		koch(x4, y4, x3, y3, n-1);
		koch(x3, y3, x1, y1, n-1);
	}
//	if (n == 1) {
//		//座標のプリント
//		cout << "(" << x0 << "," << y0 << ")" << endl;
//		cout << "(" << x2 << "," << y2 << ")" << endl;
//		cout << "(" << x4 << "," << y4 << ")" << endl;
//		cout << "(" << x3 << "," << y3 << ")" << endl;
//	}

}

int main(void) {
	int n;
	cin >> n;
	koch(0, 0, 100, 0, n);
	show_vertex(100, 0);
}

// 複素数使ってもやりたい



Measured memory_bytes: 3244
#include<bits/stdc++.h>
using namespace std;
#define pi acos(-1)
#define mod 1000000007
#define ll long long
#define ull unsigned long long
#define mem(a) memset(a,0,sizeof(a))
#define cio ios::sync_with_stdio(false);
ll c[20];
ll s[20][20];
ll q[20];
ll minn = 1e18;
int n, m, x;
void dfs(int p, ll sum)
{
	int flag = 1;
	for(int i = 1; i <= m; i++){
		if(q[i]<x){
			flag = 0;
			break;
		}
	}
	if(flag) minn = min(minn,sum);
	if(p>n) return;
	dfs(p+1,sum);
	for(int i = 1; i <= m; i++){
		q[i] += s[p][i];
	}
	dfs(p+1,sum+c[p]);
	for(int i = 1; i <= m; i++){
		q[i] -= s[p][i];
	}
}
int main()
{
	cio;
	cin >> n >> m >> x;
	for(int i = 1; i <= n; i++){
		for(int j = 1; j <= m; j++){
			if(j==1){
				cin >> c[i];
				cin >> s[i][j];
			}else{
				cin >> s[i][j];
			}
		}
	}
	int flag = 1;
	for(int i = 1; i <= m; i++){
		ll sum = 0;
		for(int j = 1; j <= n; j++){
			sum += s[j][i];
			if(sum>=x){
				break;
			}
		}
		if(sum<x){
			flag = 0;
			break;
		}
	}
	if(flag==0){
		cout << -1 << endl;
		return 0;
	}
	dfs(1,0);
	cout << minn << endl;
    return 0;
}



Measured memory_bytes: 3652
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <iostream>
using namespace std;

int main() {
  int H1, M1, H2, M2, K;
  cin >> H1 >> M1 >> H2 >> M2 >> K;
  cout << 60*(H2-H1)+(M2-M1)-K << endl;
}

Measured memory_bytes: 3580
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
typedef long long ll;
 
int main()
{
    ll n,x;
    cin>>n>>x;
    vector<ll> a(n);
    for(int i=0;i<n;i++){
        cin>>a.at(i);
    }
    sort(all(a));
    ll ans=0;
    for(int i=0;i<n;i++){
        if(x>=a[i]){
            x-=a[i];
            ans++;
        }
        else if(i==n-1&&x>0){
            ans++;
        }
    }
    if(x>0){
        ans--;
    }
    if(ans<0){
        ans=0;
    }
    cout<<ans<<endl;
    
}
 

Measured memory_bytes: 256
#include <bits/stdc++.h>
//#pragma GCC optimize("O3")
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("unroll-loops")
#define pb push_back
#define IOS                                                                    \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(0);                                                                  \
  cout.tie(0);cout<<fixed<<setprecision(16);
#define ll long long int
#define ld long double
#define el '\n'
#define El '\n'
#define PI (ld)3.141592653589793238462643383279502884197169399375105820974944
#define inf (ll)1000000000
#define mod (ll)1000000007
#define mod1 (ll)998244353
#define fo(i, n) for (long long i = 0; i < n; i++)
#define pll pair<ll, ll>
#define ml map<ll,ll>
#define vpl vector<pll>
#define vvl vector<vector<ll> >
#define vvpl vector< vector<pll> >
#define ff first
#define ss second
#define pqueue priority_queue< ll >
#define pdqueue priority_queue< ll,vl ,greater< ll > >
#define mem(a,b) memset(a,b,sizeof(a));
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define sz(a) (ll)a.size()
#define f(i,a,b) for(ll i=a;i<b;i++)
#define fd(i,a,b) for(ll i=a;i>=b;i--)
#define all(a) a.begin(),a.end()
#define vl vector<ll>
//#define x ff
//#define y ss
#define pt(a) for(auto it:a)cout<<it<<" ";cout<<endl;
unsigned seed = std::chrono::system_clock::now().time_since_epoch().count();
using namespace std;

// vector
template<class T> istream& operator >> (istream &is , vector<T> &v) { for(T &a : v) is >> a; return is; }
template<class T> ostream& operator << (ostream &os , const vector<T> &v) { for(const T &t : v) os << t<<" "; return os << endl; }
// pair
template<class T, class U> ostream& operator << (ostream &os , const pair<T, U> &v) { return os << v.first << " " << v.second ; }

double gcd(double a, double b) { return a < 0.01 ? b : gcd(fmod(b, a), a); }

long long bpow(long long a, long long b, long long m) {
  a %= m;
  long long res = 1;
  while (b > 0) {
    if (b & 1)

      res = res * a % m;
      a = a * a % m;
      b >>= 1;
  }
  return res;
}


ll kv;
ll t,n,x,y,h,k,z,p,q,w;
string s[1000],s1,s2;
//vvl v;
//vl vis,d;

ll dp[1000][1000];

ll sg(ll x, ll y){
    if(dp[x][y]!=-1)return dp[x][y];
    ll p=0;
    if(x>0&&s[x-1][y]!='#')p+=sg(x-1,y);
    if(y>0&&s[x][y-1]!='#')p+=sg(x,y-1);
    return dp[x][y]=p%mod;
}

int main() {
    IOS;
    cin>>n>>k;
    fo(i,1000)fo(j,1000)dp[i][j]=-1;
    fo(i,n)cin>>s[i];
    dp[0][0]=1;
    cout<<sg(n-1,k-1);
    return 0;
}


Measured memory_bytes: 9216
#include <iostream>
#include <vector>
#include <algorithm>
	

unsigned isPrime(unsigned x) {
	static std::vector<unsigned> primes{2};
	if (x < 2) {
		return 0;
	}
	if (x == 2) {
		return 1;
	}
	if (primes.back() < x) {
		for (unsigned i = primes.back() + 1; i*i <= x; i++) {
			bool isPrime = std::none_of(primes.begin(), primes.end(), [i](auto d){ return i % d == 0; });
			if (isPrime) {
				primes.push_back(i);
			}
		}
	}
	bool isPrime{true};
	for (auto&& var : primes) {
		if (var >= x) break;
		if (x % var == 0) {
			isPrime = false;
			break;
		}
	}
	return (isPrime) ? 1 : 0;
}

unsigned numOfPrime(const unsigned& x) {
	unsigned sum{};
	static unsigned ntable[999999]{};
	static unsigned maxX{1};
	if (x < 2) {
		return 0;
	}
	if (x == 2) {
		return 1;
	}
	unsigned count_from = std::min(maxX, x);
	sum += ntable[count_from];
	for (unsigned i = count_from + 1; i <= x; i++) {
		sum += isPrime(i);
		ntable[i] = sum;
	}
	maxX = std::max(x,maxX);
	return sum;
}

int main(int argc, char const* argv[])
{
	unsigned d{};
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	while (std::cin >> d) {
		std::cout << numOfPrime(d) << std::endl;
	}
	return 0;
}

Measured memory_bytes: 7064
import std.stdio, std.string, std.conv;
import std.array, std.algorithm, std.range;

void main()
{
    foreach(a;stdin.byLine().map!(s=>s.split().map!(to!int).array()).array().until([-1,-1,-1]))
    {
        auto r = new int[3];
        foreach(i,v;[2,0,0]) r[i]=v-a[i];
        foreach_reverse(i;1..3) if(r[i]<0) --r[i-1],r[i]+=60;
        r.map!(n=>format("%02d",n)).join(":").writeln();
        foreach(ref v;r) v*=3;
        foreach_reverse(i;1..3) r[i-1]+=r[i]/60,r[i]%=60;
        r.map!(n=>format("%02d",n)).join(":").writeln();
    }
}

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

int main(){
    string s; cin >> s;
    reverse(ALL(s));
    bool flag = true;
    while(s.size()){
        if(s.substr(0,5) == "maerd") s = s.substr(5);
        else if(s.substr(0,7) == "remaerd") s = s.substr(7);
        else if(s.substr(0,5) == "esare") s = s.substr(5);
        else if(s.substr(0,6) == "resare") s = s.substr(6);
        else {
            flag = false;
            break;
        }
    }
    if(flag) cout << "YES" << endl;
    else cout << "NO" << endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define PI 3.1415926535

int main() {
    string s;
    cin >> s;
    vector<ll> num(s.length());
    ll rstart = 0, rmid = 0, lmid = 0, lgoal = 0;
    ll now = 0;
    bool Rsearch = true, Lsearch = false;
    while(1){
        if(now >= s.length()) break;
        if(Rsearch && s[now] == 'R' && s[now + 1] == 'L'){
            rmid = now;
            lmid = now + 1;
            Rsearch = !Rsearch;
            Lsearch = !Lsearch;
        }

        if((Lsearch && s[now] == 'L' && s[now + 1] == 'R') || now == s.length() - 1){
            lgoal = now;
            num[rmid] = (rmid - rstart + 2) / 2 + (lgoal - lmid + 1) / 2;
            num[lmid] = (lgoal - rstart + 1) - num[rmid];
            rstart = now + 1;
            Rsearch = !Rsearch;
            Lsearch = !Lsearch;
        }
        now++;
    }

    for(ll i = 0; i < s.length(); i++){
        cout << num[i] << endl;
    }

    

}


Measured memory_bytes: 1536
//#include "stdafx.h"
#include "iostream"
#include "fstream"
#include "algorithm"
#include "iomanip"
#include "stack"
#include "queue"
#include "string"
#include "vector"
#include "map"
#include "set"
#include "list"
#include "deque"
#include "complex"
#include "bitset"
#include "cmath"
#include "unordered_set"
#include "unordered_map"
#include "iterator"
#include <ctime>
#include <cassert>
#include "numeric"
#include <cstdio>
#include "random"
#include "chrono"
#include "cstring"

//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast")
//#pragma GCC target_ans("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

using namespace std;

//#define f(i,n) for(int i=0; i<n;i++)
//#define rf(i, n) for(int i=n-1;i>=0;i--)
//#define forn(i, j, n) for(int i=j; i<n; i++)
//#define ff(i, j, n) f(i, n)f(j, n)
#define pb push_back
#define maxi(a,b) a = max(a, b);
#define mini(a,b) a = min(a, b);
//#define endl '\n'

#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define sqr(x) ((x) * (x))
#define SZ(a) ((int)(a.size()))
#define watch(x) cout << (#x) << " = " << x << endl;
//typedef long long ll;
typedef long double ld;

#define int long long
//#define int unsigned int
#define double ld
typedef map<int, int> mii;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<pii> vpii;
typedef vector<char> vc;
typedef vector<vi> vvi;

template<class T>
void show(const vector<T> &a)
{
	for (T x : a)
		cout << x << " ";
	cout << endl;
}

vi xx = { 1, 0, -1, 0 };
vi yy = { 0, 1, 0, -1 };
string dir = "LRUD";

const int N = 2e5 + 50, oo = 3e18 + 500;
//const int mod = 998244353;
const int mod = 1e9 + 7;
//const int mod = 1e9 + 9;
const double eps = 1e-12, PI = 2 * acos(0.0);
int n, m, k;
long long cnt = 0;
int lg = 18;
set<int> g[N];
vi rg[N];
vi visit(N, 0);

int bin_pow(int a, int b)
{
	int res = 1;
	while (b)
	{
		if (b & 1)
		{
			res = res * a % mod;
		}

		a = a * a % mod;
		b >>= 1;
	}

	return res;
}

signed main()
{
	ios::sync_with_stdio(0);
	cout.tie(0); cin.tie(0);
	/*freopen("abbreviation.in", "r", stdin);
	freopen("abbreviation.out", "w", stdout);*/

	cin >> k;
	string s;
	cin >> s;
	int n = SZ(s);

	vi fact(n + k + 1, 1);
	vi pow(n + k + 1, 1);
	cnt = 1;
	for (int i = 1; i <= n + k; i++)
	{
		fact[i] = fact[i-1] * i % mod;
		pow[i] = pow[i - 1] * 25 % mod;
		cnt = cnt * 26 % mod;
	}

	for (int m = 0; m < n; m++)
	{
		int val = fact[n + k] * bin_pow(fact[n + k - m], mod - 2) % mod *
			bin_pow(fact[m], mod - 2) % mod * pow[n+k-m] % mod;
		cnt = (cnt - val + mod) % mod;
	}

	cout << cnt;
}



Measured memory_bytes: 46072
a = input()
flag = 0
first = []
last = []
for i in range(int(input())):
    query = [j for j in input().split()]
    t = int(query[0])
    if t == 1:
        flag = 1 - flag
    else:
        x = int(query[1])
        if x == 1:
            if flag == 0:
                first.append(query[2])
            else:
                last.append(query[2])
        else:
            if flag == 0:
                last.append(query[2])
            else:
                first.append(query[2])

if flag == 0:
    print("".join(first)[::-1] + a + "".join(last))
else:
    print("".join(last)[::-1] + a[::-1] + ''.join(first))



Measured memory_bytes: 5704
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  int64_t k;
  cin>>n>>k;
  vector<int> b;
  while(k>1){
    b.push_back(k%2);
    k/=2;
  }
  reverse(b.begin(),b.end());
  vector<vector<int>> a(n,vector<int>(n));
  for(int i=0;i<n;i++)
    for(int j=0;j<n;j++)
      cin>>a.at(i).at(j);
  int p=1000000007;
  vector<vector<int64_t>> dp(n,vector<int64_t>(n));
  for(int i=0;i<n;i++)
    for(int j=0;j<n;j++)
      dp[i][j]=a.at(i).at(j);
  for(int d:b){
    vector<vector<int64_t>> c=dp;
    for(int i=0;i<n;i++){
      for(int j=0;j<n;j++){
        dp[i][j]=0;
        for(int x=0;x<n;x++)
          dp[i][j]=(dp[i][j]+c.at(i).at(x)*c.at(x).at(j))%p;
      }
    }
    if(d==1){
      c=dp;
      for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
          dp[i][j]=0;
          for(int x=0;x<n;x++)
            dp[i][j]=(dp[i][j]+c.at(i).at(x)*a.at(x).at(j))%p;
        }
      }
    }
  }
  int64_t s=0;
  for(int i=0;i<n;i++)
    for(int j=0;j<n;j++)
      s=(s+dp[i][j])%p;
  cout<<s<<endl;
}

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

class Main {
	double[][] p = new double[2][6];

	void run() {
		Scanner sc = new Scanner(System.in);
		int Na = sc.nextInt();
		int Nb = sc.nextInt();
		long[] xa = new long[Na];
		long[] ya = new long[Na];
		long[] xb = new long[Nb];
		long[] yb = new long[Nb];
		for (int i = 0; i < Na; ++i) {
			xa[i] = sc.nextLong();
			ya[i] = sc.nextLong();
		}
		for (int i = 0; i < Nb; ++i) {
			xb[i] = sc.nextLong();
			yb[i] = sc.nextLong();
		}

		double ans = Double.MAX_VALUE / 3;
		for (int t = 0; t < 2; ++t) {
			for (int i = 0; i < Na; ++i) {
				for (int j = 0; j < Na; ++j) {
					if (cross(xa[0], ya[0], xa[i], ya[i], xb[0], yb[0], xb[1], yb[1])) {
						continue;
					}
					if (cross(xa[i], ya[i], xa[j], ya[j], xb[0], yb[0], xb[1], yb[1])) {
						continue;
					}
					if (cross(xa[j], ya[j], xa[1], ya[1], xb[0], yb[0], xb[1], yb[1])) {
						continue;
					}
					ans = Math.min(ans, dist(xa[0], ya[0], xa[i], ya[i]) + dist(xa[i], ya[i], xa[j], ya[j])
							+ dist(xa[j], ya[j], xa[1], ya[1]) + dist(xb[0], yb[0], xb[1], yb[1]));
				}
			}
			Na ^= Nb;
			Nb ^= Na;
			Na ^= Nb;
			long[] tmp = new long[Na];
			tmp = Arrays.copyOf(xa, xa.length);
			xa = Arrays.copyOf(xb, xb.length);
			xb = Arrays.copyOf(tmp, tmp.length);
			tmp = Arrays.copyOf(ya, ya.length);
			ya = Arrays.copyOf(yb, yb.length);
			yb = Arrays.copyOf(tmp, tmp.length);
		}
		System.out.println(ans >= Double.MAX_VALUE / 4 ? "-1" : ans);
	}

	double dist(long xa, long ya, long xb, long yb) {
		long dx = xa - xb;
		long dy = ya - yb;
		return Math.sqrt(dx * dx + dy * dy);
	}

	boolean cross(long xa1, long ya1, long xb1, long yb1, long xa2, long ya2, long xb2, long yb2) {
		long v = f(xa1, ya1, xb1, yb1, xa2, ya2) * f(xa1, ya1, xb1, yb1, xb2, yb2);
		long u = f(xa2, ya2, xb2, yb2, xa1, ya1) * f(xa2, ya2, xb2, yb2, xb1, yb1);
		return v <= 0 && u <= 0;
	}

	long f(long xa, long ya, long xb, long yb, long x, long y) {
		return (ya - yb) * (x - xa) - (y - ya) * (xa - xb);
	}

	void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}

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


Measured memory_bytes: 37364
# セイウチ

def main():
    from heapq import heappush, heappop

    INF = 1 << 60
    MX_AG = 2500

    N, M, S = map(int, input().split())
    S = min(S, MX_AG)  # それ以上のAgは不要

    g = tuple(set() for _ in range(N))
    for _ in range(M):
        u, v, a, b = map(int, input().split())
        u -= 1
        v -= 1
        g[u].add((v, a, b))
        g[v].add((u, a, b))

    exchange = []
    for _ in range(N):
        c, d = map(int, input().split())
        exchange.append((c, d))

    h = [(0, S, 0)]

    time = [[INF] * (MX_AG + 1) for _ in range(N)]
    time[0][S] = 0
    # time[location][r_Ag]:=minimum_time_to_reach

    while h:
        t, ag, loc = heappop(h)
        for to, fare, dt in g[loc]:
            if (n_Ag := ag - fare) < 0: continue
            if time[to][n_Ag] <= (n_time := t + dt): continue
            time[to][n_Ag] = n_time
            heappush(h, (n_time, n_Ag, to))

        if (e_Ag := ag + exchange[loc][0]) > MX_AG: continue
        if time[loc][e_Ag] <= (e_time := t + exchange[loc][1]): continue
        time[loc][e_Ag] = e_time
        heappush(h, (e_time, e_Ag, loc))

    ans = (min(time[to]) for to in range(1, N))

    print(*ans, sep='\n')


if __name__ == '__main__':
    main()


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

using namespace std;

#define INF (long long)1e12+7

long long i,j,k,l,n,m,maxi,res;

long long a[10];

int main()
{
    cin>>a[1]>>a[2]>>a[3];
    sort(a+1,a+4);
    if(a[2]!=a[3])res=a[3]-a[2];
    else{
        if((a[3]-a[1])%2==0)cout<<(a[3]-a[1])/2<<endl;
        else{
            cout<<(a[3]-a[1])/2+2<<endl;
        }
        return 0;
    }
    if(a[1]!=a[3])a[1]+=res;
    if(a[2]!=a[3])a[2]+=res;
    if((a[3]-a[1])%2==0)cout<<res+(a[3]-a[1])/2<<endl;
    else{
        cout<<res+(a[3]-a[1])/2+2<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
 
int main(){
  int A,B,C,K;
  cin >> A >> B >> C >> K;
  int a,b,c;
  a=max(max(A,B),C);
  b=min(min(A,B),C);
  c=A+B+C-a-b;
  for(int i=0;i<K;i++){
    a=a*2;}
  cout << a+b+c << endl;
}

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

using namespace std;
int main(){
    long N,A,B;
    cin>>N>>A>>B;
    cout<<(N/(A+B))*A+min(N%(A+B),A)<<endl;
    
    return 0;
}



Measured memory_bytes: 384
n,m = map(int,input().split())
ab = [list(map(int,input().split())) for x in [0]*n]
cd = [list(map(int,input().split())) for x in [0]*m]
for a,b in ab:
    l = [abs(a-c)+abs(b-d) for c,d in cd]
    print(l.index(min(l))+1)

Measured memory_bytes: 3060