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

int gcd(int a,int b){
  if(a < b) swap(a,b);
  if(b == 0) return a;
  return gcd(b,a%b);
}

signed main(){

  int n,m; cin >> n >> m;
  string s,t; cin >> s >> t;

  bool f = 1;
  for(int i = 0; i < gcd(n,m); i++){
    //if(i*(n/gcd(n,m)) >= s.size() || i*(m/gcd(n,m)) >= t.size()) break;
    if(s[i*(n/gcd(n,m))] != t[i*(m/gcd(n,m))]) f = 0;
    //cout << s[i*(n/gcd(n,m))] << " " << t[i*(m/gcd(n,m))] << endl;
  }
  cout << (f == 1 ? n/gcd(n,m)*m : -1) << endl;

  return 0;
}


Measured memory_bytes: 512
import java.math.BigInteger;
import java.util.Scanner;

public class Main {

	static Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		BigInteger m = sc.nextBigInteger();
		BigInteger n = sc.nextBigInteger();

		System.out.println(m.modPow(n, BigInteger.valueOf(1000000007)));
	}
}


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

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define MOD 1000000007
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)

lli bitCount(lli num){
    lli cnt=0;
    lli tmp = num;
    while(num>0){
        if(num%2)cnt++;
        num/=2;
    }
    if(DEBUG)cout<<"num="<<tmp<<" bitCount="<<cnt<<endl;
    return cnt;
}

int main(){

    lli n;
    cin>>n;

    vector<vector<pair<lli,lli>>> v(n);

    REP(i,0,n){
        lli a;
        cin>>a;
        REP(j,0,a){
            lli x,y;
            cin>>x>>y;
            x--;
            v[i].push_back(mp(x,y));
        }
    }

    lli ans = 0;
    for(lli bit=0;bit<(1LL<<n);bit++){
        bool ok = true;
        REP(i,0,n){
            if(bit&(1LL<<i)){
                REP(j,0,v[i].size()){
                    if( (lli)(!!(bit&(1LL<<v[i][j].first))) != v[i][j].second){
                        ok=false;
                        break;
                    }
                }
            }
        }
        if(ok){
            ans = max(ans,bitCount(bit));
        }
    }
    cout<<ans<<endl;


    return 0;
}


Measured memory_bytes: 384
def distance(x, y, p):
    length = len(x)
    if p == -1:
        return max(abs(x[i] - y[i]) for i in range(length))
    return sum([abs(i - j)**p for i, j in zip(x, y)])**(1/p)

n = int(input())
x = [*map(int, input().split())]
y = [*map(int, input().split())]
P = (1, 2, 3, -1)
for p in P:
    print('%f' % distance(x, y, p))


Measured memory_bytes: 5648
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996) 

typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
//const long long MOD = 1000000007;
const long long MOD = 998244353;
using namespace std;

ll mpow(ll x, ll n){ //x^n(mod M)
    ll ans = 1;
    while(n != 0){
        if(n&1) ans = ans*x % MOD;
        x = x*x % MOD;
        n = n >> 1;
    }
    return ans;
}


ll dp0[305][90005];
ll dp[305][90005];

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

    vector<int> a(n);
    int i,j;
    int sum=0;
    for(i=0; i<n; i++) {
        scanf("%d", &a[i]);
        sum+=a[i];
    }

    dp0[0][0]=1;
    dp[0][0]=1;
    for(i=1; i<=n; i++) {
        for(j=0; j<=sum; j++) {
            dp0[i][j]=(dp0[i][j]+dp0[i-1][j])%MOD;
            dp[i][j]=(dp[i][j]+dp[i-1][j]*2)%MOD;
            if(j>=a[i-1]) {
                dp0[i][j]=(dp0[i][j]+dp0[i-1][j-a[i-1]])%MOD;
                dp[i][j]=(dp[i][j]+dp[i-1][j-a[i-1]])%MOD;
            }
        }
    }

    ll ans0=0;
    for(i=(sum+1)/2; i<=sum; i++) {
        ans0 = (ans0 + dp[n][i] - 2*dp0[n][i] + 2*MOD)%MOD;
    }

    ll ans1 = ((ans0+1) * 3)%MOD;
    ll ans2 = (mpow(3, n) - 3*mpow(2,n) + 3*MOD + 3)%MOD;
    ll ans = (ans2 - ans1 + MOD)%MOD;
    printf("%lld\n", ans);

    return 0;
}


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

#define deb(x) cerr<<"["#x<<" : "<<x<<" ]\n";

int power_100(int d)
{
	int res = 1;
	for(int i = 0; i < d; i++) res *= 100;
	return res;
}

int main()
{
	int d, n;
	cin >> d >> n;
	cout << ((n == 100) ? power_100(d)*(n+1) : power_100(d)*n);
}


Measured memory_bytes: 3600
import sys
from math import log2,floor,ceil,sqrt
# import bisect
# from collections import deque

# from types import GeneratorType
# def bootstrap(func, stack=[]):
#     def wrapped_function(*args, **kwargs):
#         if stack:
#             return func(*args, **kwargs)
#         else:
#             call = func(*args, **kwargs)
#             while True:
#                 if type(call) is GeneratorType:
#                     stack.append(call)
#                     call = next(call)
#                 else:
#                     stack.pop()
#                     if not stack:
#                         break
#                     call = stack[-1].send(call)
#             return call
#     return wrapped_function

Ri = lambda : [int(x) for x in sys.stdin.readline().split()]
ri = lambda : sys.stdin.readline().strip()
 
def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
INF = 10 ** 18
MOD = 10**9+7

a,b = ri().split()
a = int(a)
b = b.split('.')
b[0] = int(b[0])
b[1] = b[1].rstrip('0')
l = len(b[1])



# print(a,b[0],b[1])
if l == 0:
    print(a*b[0])
else:
    b[1] = int(b[1])
    ans = a*b[0] + a*b[1]//10**l
    print(ans)



Measured memory_bytes: 62424
#include <stdio.h>

int main(){
int n,a,b,max,min;
scanf("%d%d%d",&n,&a,&b);
if(a > b)
	max = b;
else
	max = a;
if(a + b > n)
	min = a + b - n;
else
min = 0;
printf("%d %d",max,min);
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define Pair pair<int,int>
#define x first
#define y second
using namespace std;

Pair a[148],b[148];
int n,t;

int head[100048],to[100048],nxt[100048],f[100048],tot=1;
inline void addedge(int s,int t,int cap)
{
	to[++tot]=t;nxt[tot]=head[s];head[s]=tot;f[tot]=cap;
	to[++tot]=s;nxt[tot]=head[t];head[t]=tot;f[tot]=0;
}

queue<int> q;int depth[100048];
bool bfs()
{
	int i,x,y;
	for (i=0;i<=t;i++) depth[i]=-1;
	depth[0]=0;q.push(0);
	while (!q.empty())
	{
		x=q.front();q.pop();
		for (i=head[x];i;i=nxt[i])
		{
			y=to[i];
			if (depth[y]==-1 && f[i])
			{
				depth[y]=depth[x]+1;
				q.push(y);
			}
		}
	}
	if (depth[t]==-1) return false; else return true;
}

int dfs(int x,int maxf)
{
	if (x==t) return maxf;
	int i,y,minf,now,ans=0;
	for (i=head[x];i;i=nxt[i])
	{
		y=to[i];
		if (depth[y]==depth[x]+1 && f[i])
		{
			minf=min(maxf-ans,f[i]);
			now=dfs(y,minf);
			f[i]-=now;f[i^1]+=now;ans+=now;
			if (ans>=maxf) return ans;
		}
	}
	return ans;
}

int main ()
{
	int i,j;
	cin>>n;
	for (i=1;i<=n;i++) cin>>a[i].x>>a[i].y;
	for (i=1;i<=n;i++) cin>>b[i].x>>b[i].y;
	t=n*2+1;
	for (i=1;i<=n;i++) addedge(0,i,1);
	for (i=1;i<=n;i++) addedge(n+i,t,1);
	for (i=1;i<=n;i++)
		for (j=1;j<=n;j++)
			if (a[i].x<b[j].x && a[i].y<b[j].y) addedge(i,n+j,1);
	int ans=0;
	while (bfs()) ans+=dfs(0,2e9);
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;

ll N;

struct acgt {
	ll ct[4][4][4];
};

acgt n0;

const ll MOD = 1000000007;

const int A = 0;
const int C = 1;
const int G = 2;
const int T = 3;


int main(){
	cin >> N;
	
	acgt c;
	for ( int i = 0; i < 4; i++ ){
		for ( int j = 0; j < 4; j++ ){
			for ( int k = 0; k < 4; k++ ){
				c.ct[i][j][k] = 
					(i==A&&j==G&&k==C) ||
					(i==G&&j==A&&k==C) ||
					(i==A&&j==C&&k==G) ? 0 : 1;
			}
		}
	}
	
	N -= 3;
	
	while ( N ){
		N--;
		/*
			以下のパターンを除く
			*AGC
			*GAC
			*ACG
			A*GC
			AG*C
		*/
		acgt n = n0;
		
		for ( int i = 0; i < 4; i++ ){
			for ( int j = 0; j < 4; j++ ){
				for ( int k = 0; k < 4; k++ ){
					for ( int l = 0; l < 4; l++ ){
						if (         j==A && k==G && l==C 
						  ||         j==G && k==A && l==C 
						  ||         j==A && k==C && l==G 
						  || i==A &&         k==G && l==C 
						  || i==A && j==G && l==C 
						)
							;
						else
							n.ct[j][k][l] = (n.ct[j][k][l] + c.ct[i][j][k])%MOD;
					}
				}
			}
		}
		
		c = n;
	}
	
	ll result = 0;
	for ( int i = 0; i < 4; i++ )
		for ( int j = 0; j < 4; j++ )
			for ( int k = 0; k < 4; k++ )
				result += c.ct[i][j][k];
	cout << result%MOD << endl;
	
	return 0;
}



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

// region template
#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define trav(a, x) for (auto &a : x)
#define all(x) begin(x), end(x)
#define sz(x) (ll)(x).size()
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;

ll gcd(ll a, ll b) { return __gcd(a, b); }

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

typedef unsigned long long ull;
typedef long double ld;
ull mod_mul(ull a, ull b, ull M) {
    ll ret = a * b - M * ull(ld(a) * ld(b) / ld(M));
    return ret + M * (ret < 0) - M * (ret >= (ll)M);
}
ull mod_pow(ull b, ull e, ull mod) {
    ull ans = 1;
    for (; e; b = mod_mul(b, b, mod), e /= 2)
        if (e & 1)
            ans = mod_mul(ans, b, mod);
    return ans;
}

const ll mod = 1000000007;
struct Mod {
    ll x;
    Mod(ll xx) : x(xx) {}
    Mod operator+(Mod b) { return Mod((x + b.x) % mod); }
    Mod operator-(Mod b) { return Mod((x - b.x) % mod); }
    Mod operator*(Mod b) { return Mod((x * b.x) % mod); }
    Mod operator/(Mod b) { return *this * invert(b); }
    Mod invert(Mod a) {
        ll x, y, g = euclid(a.x, mod, x, y);
        assert(g == 1);
        return Mod((x + mod) % mod);
    }
    Mod operator^(ll e) {
        if (!e)
            return Mod(1);
        Mod r = *this ^ (e / 2);
        r = r * r;
        return e & 1 ? *this * r : r;
    }
};
// endregion

int main() {
    cin.sync_with_stdio(0);
    cin.tie(0);
    cin.exceptions(cin.failbit);

    for (;;) {
        int n, l, r;
        cin >> n >> l >> r;
        if (!n)
            break;

        vector<int> v(n);
        rep(i, 0, n) cin >> v[i];

        int ans = 0;
        for (int i = l; i <= r; i++) {
            for (int j = 0; j < n; j++) {
                if (i % v[j] == 0) {
                    if (~j & 1) ans++;
                    goto nxt;
                }
            }
            if (~n & 1) ans++;
            nxt: void(0);
        }
        cout << ans << endl;
    }
}



Measured memory_bytes: 3148
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#include <string>
#include <queue>
#include <map>
#include <cmath>
#include <iomanip> 
#include <bits/stdc++.h>
using namespace std;
double pi=3.14159265358979323846264338;
const int MOD=1000000007;
string arr[27]={"z","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"};
string ans;
int cnt;
void dfs(int k){
	if(k<=26){cnt--;ans=arr[k]+ans;return;}
	int re=k%26;
	if(re==0){
		ans="z"+ans;
		cnt--;
		dfs(k/26);
		return;
	}
	ans=arr[re]+ans;
	cnt--;
	dfs((k-re)/26+1);
	return;
}
int main() {
	
	int n;
	cin>>n;
	n--;
	//cout<<n<<endl;
	n=n%1000;
	//cout<<n<<endl;
	n++;
	//cout<<n<<endl;
	cout<<1000-n<<endl;
	return 0;
}

Measured memory_bytes: 3628
#include <iostream>

using namespace std;



int main()
{

	int month[12];

	month[0] = 0, month[1] = 1, month[2] = 0, month[3] = 2, month[4] = 0, month[5] = 2, month[6] = 0, month[7] = 0, month[8] = 2, month[9] = 0, month[10] = 2, month[11] = 0;
	int x,y;
	cin >> x>>y;

	if (month[x - 1] == month[y - 1])cout << "Yes"<<endl;
	else cout << "No" << endl;
	return 0;
}


Measured memory_bytes: 256
// 22
/****************************************************
https://searleser97.gitlab.io/algorithms/template.cpp
****************************************************/

#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define fors(_, x, n, s) for (int _ = x; _ < n; _ += s)
#define forn(_, x, n) fors(_, x, n, 1)
#define rep(_, n) forn(_, 0, n)
#define forrs(_, x, n, s) for (int _ = x; _ > n; _ -= s)
#define forrn(_, x, n) forrs(_, x, n, 1)
#define rrep(_, n) forrn(_, n - 1, -1)
#define fi first
#define se second
#define pb push_back
#define pairii pair<int, int>
#define all(x) x.begin(), x.end()
#define cerr(s) cerr << "\033[48;5;196m\033[38;5;15m" << s << "\033[0m"
// typedef __int128_t lli;
typedef long long int li;
typedef long double ld;
const li inf = 1e14;
// 12
void _main(int tc) {
  int n, W, sumV = 0;
  cin >> n >> W;
  vector<int> w(n), v(n);
  rep(i, n) {
    cin >> w[i] >> v[i];
    sumV += v[i];
  }

  vector<vector<li>> mem(n + 1, vector<li>(sumV + 1, inf));

  rep(i, n + 1) mem[i][0] = 0;

  rrep(i, n) {
    rrep(V, sumV + 1) {
      if (V - v[i] >= 0)
        mem[i][V] = min(w[i] + mem[i + 1][V - v[i]], mem[i + 1][V]);
      else
        mem[i][V] = mem[i + 1][V];
    }
  }

  rrep(i, sumV + 1) {
    if (mem[0][i] <= W) {
      cout << i << endl;
      break;
    }
  }
}

int main() {
  ios_base::sync_with_stdio(0), cin.tie(0);
  _main(0);
  return 0;
  int tc;
  cin >> tc;
  rep(i, tc) _main(i + 1);
}

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

#define INF 1000000001

#define MOD 1000000007

typedef long long ll;

void chmin(ll *a,ll b){ //第二引数のほうが第一引数より小さければ、第一引数に代入
  if(*a > b){
    *a = b;
  }
}

void chmax(ll *a,ll b){ //第二引数のほうが第一引数より大きければ、第一引数に代入
  if(*a < b){
    *a = b;
  }
}

int main(void){
  int N,W;
  std::cin >> N >> W;

  ll dp[N+1][W+1];
  for(int i=0; i<=N; i++){
    for(int j=0; j<=W; j++){
      dp[i][j] = 0;
    }
  }

  ll weight[N],value[N];
  for(int i=0; i<N; i++){
    std::cin >> weight[i] >> value[i];
  }

  for(int i=0; i<N; i++){
    for(int sum_w=0; sum_w<=W; sum_w++){
      if(sum_w - weight[i] >= 0){
        chmax(&dp[i+1][sum_w],dp[i][sum_w - weight[i]] + value[i]);
      }
      chmax(&dp[i+1][sum_w],dp[i][sum_w]);
    }
  }

  std::cout << dp[N][W] << std::endl;
  return 0;
}


Measured memory_bytes: 79104
#include <iostream>
#include <vector>
#include <set>
#include <cmath>
#include <algorithm>
#include <climits>
#include <map>

using namespace std;

int main() {
	int k;
	cin >> k;
	int currt = 0;
	int currx = 0;
	int curry = 0;
	bool fail = false;
	for(int i = 0; i < k; i++) {
		int t, x, y;
		cin >> t >> x >> y;
		int xdif = abs(currx - x);
		int ydif = abs(curry - y);
		int tdif = t - currt;
		int dif = tdif - xdif - ydif;
		if(dif < 0 || dif % 2 != 0) {
			fail = true;
		}
	}
	if(!fail) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}

Measured memory_bytes: 384
import java.util.*;

class Main{
	
	public static void main(String args[]){

		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int arr[] = new int[N];
		for(int n=0;n<N;n++){
			arr[n] = sc.nextInt();
		}

		int p=-1;

		int cnt = 0;
		for(int n=0;n<N;n++){
			if(p == arr[n]){
				cnt++;
				p = -1;
			}
			else{
				p = arr[n];
			}
		}
		System.out.println(cnt);
	}
}

Measured memory_bytes: 22356
let n, m = Scanf.scanf "%d %d" (fun n m -> n, m)

let d = Array.init (n + m) (fun i ->
  if i < n then Scanf.scanf " %d" (fun i -> 1, i)
  else Scanf.scanf " %d %d" (fun b c -> b, c))

let rec f i j ans =
  if i = n + m || j = 0 then ans
  else
    let b, c = d.(i) in
    let b = min b j in
    f (i + 1) (j - b) (ans + b * c)

let () =
  Array.sort (fun (_, c1) (_, c2) -> c2 - c1) d;
  Printf.printf "%d\n"  (f 0 n 0)


Measured memory_bytes: 12676
#include <bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  if(abs(a-c)<=d){
    cout<<"Yes";
  }
  else if(abs(a-b)<=d&&abs(b-c)<=d)
    cout<<"Yes";
  else cout<<"No";
  return 0;
}

Measured memory_bytes: 256
#pragma comment(linker, "/stack:20000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")

#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>

#define se second
#define fi first
#define ss size()
#define pb push_back
#define mp make_pair
#define ins insert
#define ll long long
#define y1 y12313312312
#define endl '\n'
#define gcd __gcd
//#define int ll

using namespace std;
//using namespace __gnu_pbds;

//template <typename T> using ordered_set = tree<T, null_type, std::less<T>, rb_tree_tag, tree_order_statistics_node_update>;

const int N = 2e5 + 40, T = 4 * N, inf = 1e9 + 7;

int n, m, f, r, l, e, w, o, z, test, id;
ll a[N], d[N][3], b[N], c[N];

void freop()
{
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
}

void boos()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}

main()
{
    //freop();
    boos();
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        cin >> a[i] >> b[i] >> c[i];
    }
    d[0][0] = a[0];
    d[0][1] = b[0];
    d[0][2] = c[0];
    for (int i = 1; i < n; i++)
    {
        d[i][0] = max(d[i - 1][1], d[i - 1][2]) + a[i];
        d[i][1] = max(d[i - 1][0], d[i - 1][2]) + b[i];
        d[i][2] = max(d[i - 1][1], d[i - 1][0]) + c[i];
    }
    cout << max(d[n - 1][1], max(d[n - 1][2], d[n - 1][0]));
}


Measured memory_bytes: 8064
S = input()
for i in range(len(S)//2):
	if S[i] != S[-i-1]:
		print("No")
		exit()
S_front = S[:(len(S)//2)]
for i in range(len(S_front)//2):
	if S_front[i] != S_front[-i-1]:
		print("No")
		exit()
S_back = S[(len(S)+1)//2:]
for i in range(len(S_back)//2):
	if S_back[i] != S_back[-i-1]:
		print("No")
		exit()
print("Yes")

Measured memory_bytes: 3064
#include <iostream>

bool isPrime[100001];
int cusumLike[100001];

int main() {
	for (int i = 2; i <= 100000; ++i)
		isPrime[i] = true;
	for (int i = 2; i <= 100000; ++i) {
		if (!isPrime[i])
			continue;

		for (int j = i * 2; j <= 100000; j += i)
			isPrime[j] = false;
	}

	for (int i = 1; i <= 100000; i += 2)
		cusumLike[i] = (isPrime[i] && isPrime[(i + 1) / 2] ? 1 : 0);
	for (int i = 1; i <= 100000; ++i)
		cusumLike[i] += cusumLike[i - 1];

	int q;
	std::cin >> q;

	for (int i = 0; i < q; ++i) {
		int l, r;
		std::cin >> l >> r;

		std::cout << cusumLike[r] - cusumLike[l - 1] << std::endl;
	}
}

Measured memory_bytes: 1152
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cfloat>
#include<climits>
#include<cmath>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<string>
#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 REVERSE(x) reverse((x).begin(), (x).end())
#define TWINS(x) cout << ((x) ? "Yay!" : ":(") << '\n'
#define endl '\n'

constexpr int IINF = (1 << 30) - 1;
constexpr long long LLINF = 1LL << 61;
constexpr double EPS = 1e-10;

constexpr int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1};
constexpr int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};

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);
    cout << fixed << setprecision(10);

    lint k, x;
    cin >> k >> x;

    if(k * 500 < x){
        cout << "No" << endl;
    }else{
        cout << "Yes" << endl;
    }

    cout << flush;

    return 0;
}

Measured memory_bytes: 768
import sys
input = sys.stdin.readline

from bisect import bisect

n = int(input())
x = list(map(int, input().split()))
l = int(input())

m = 20
par = [[-1]*n for i in range(m)]

for i in range(n):
    j = bisect(x, x[i]+l)-1
    par[0][i] = j

for i in range(m-1):
    for j in range(n):
        par[i+1][j]=par[i][par[i][j]]

def hoge(x, y):
    k = 0
    for i in range(m)[::-1]:
        if par[i][x] < y:
            k += 1<<i
            x = par[i][x]
    return k+1

q = int(input())
ans = []
for i in range(q):
    a,b = map(int, input().split())
    a,b = a-1,b-1
    if a > b:
        a,b = b,a
    print(hoge(a,b))

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

int main(){
  bool c=true;
  string s;
  cin >> s;
  rep(i,s.size()){
    if(i % 2==0){
      if(s[i]=='L') c=false;
    }else{
      if(s[i]=='R') c=false;
    }
  }
  if(c==true) cout << "Yes" << endl;
  else cout << "No" << endl;
}

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

int gcd(int a, int b){
    while (a && b){
        (a < b) ? b %= a : a %= b;
    }
    return a + b;
}

int main(){
    int N;
    cin >> N;
    vector<int> A(N);
    for(auto& a : A){
        cin >> a;
    }

    vector<int> gcd_front(N);
    vector<int> gcd_back(N);

    gcd_front[0] = A[0];
    for(int ii=1; ii<N; ii++){
        gcd_front[ii] = gcd(gcd_front[ii-1], A[ii]);
    }

    gcd_back[N-1] = A[N-1];
    for(int ii=N-2; ii>=0; ii--){
        gcd_back[ii] = gcd(gcd_back[ii+1], A[ii]);
    }

    int gcd_max = max(gcd_back[1], gcd_front[N-2]);
    for(int ii=1; ii<N-1; ii++){
        gcd_max = max(gcd_max, gcd(gcd_front[ii-1], gcd_back[ii+1]));
    }
    cout << gcd_max << endl;
    return 0;
}


Measured memory_bytes: 1408
import bisect

N = int(input())
A = sorted(list(map(int, input().split())))
B = sorted(list(map(int, input().split())))
C = sorted(list(map(int, input().split())))

res = 0
for b in B:
    a = bisect.bisect_left(A, b)
    c = N - bisect.bisect_right(C, b)
    res += a * c

print(res)

Measured memory_bytes: 107108
#include<bits/stdc++.h>
using namespace std;
int a[20000005];
int main()
{
	int n,A,b,c,d;
	cin>>n>>A>>b>>c>>d;
	char x;
	for(int i=1;i<=n;i++)
	{
		cin>>x;
		if(x=='.')
			a[i]=0;
		if(x=='#')
			a[i]=1;
	}
	for(int i=min(A,b);i<=max(c,d)-1;i++)
	{
		if(a[i]==a[i+1]&&a[i]==1)
		{
			cout<<"No"<<endl;
			return 0;
		}
	}
	if(A>b)
	{
		swap(A,b);
		swap(c,d);
	}
	int i=A,j=b,flag=0;
	while(i<c)
	{
		if(a[i+2]==1)
			i+=1;
		else
			i+=2;
		if(i==j)
		{
			if(j==d&&i==c)
			{
				cout<<"Yes"<<endl;
				return 0;
			}
			if(j==d)
			{
				cout<<"No"<<endl;
				return 0;
			}
			else
			{
				if(a[j+1]!=1)
					j+=1;
				else
					j+=2;
			}
		}
//		cout<<i<<" "<<j<<endl;
	}
	for(int k=j;k<=d;k++)
	{
		if((a[k+1]==1&&k+2==c)||(a[k+2]==1&&k+1==c))
		{
			cout<<"No"<<endl;
			return 0;
		}
	}
	cout<<"Yes"<<endl;
	return 0;
}

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

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

  int a, ans = 0;
  rep(i,0,N-1) {
    cin >> a;
    ans += a - 1;
  }

  cout << ans << endl;
  return 0;
}


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

#define int long long 

void read(int &x) {
    x=0;int f=1;char ch=getchar();
    for(;!isdigit(ch);ch=getchar()) if(ch=='-') f=-f;
    for(;isdigit(ch);ch=getchar()) x=x*10+ch-'0';x*=f;
}
 
void print(int x) {
    if(x<0) putchar('-'),x=-x;
    if(!x) return ;print(x/10),putchar(x%10+48);
}
void write(int x) {if(!x) putchar('0');else print(x);putchar('\n');}

#define lf double
#define ll long long 

const int maxn = 1e5+10;
const int inf = 1e9;
const lf eps = 1e-8;

int p[maxn],d[maxn],n,m,k,fa[maxn][61],a[maxn],b[maxn];

signed main() {
	read(n);for(int i=1;i<=n;i++) read(p[i]),d[i]=p[i]-p[i-1],a[i]=i;
	for(int i=1;i<=n;i++) b[i]=i;
	read(m),read(k);
	for(int i=1,x;i<=m;i++) read(x),swap(a[x],a[x+1]);
	for(int i=1;i<=n;i++) fa[i][0]=a[i];
	for(int i=1;i<=60;i++)
		for(int x=1;x<=n;x++)
			fa[x][i]=fa[fa[x][i-1]][i-1];
	for(int t=k,x=1;x<=n;x++,t=k)
		for(int i=60;~i;i--)
			if(t>=(1ll<<i)) t-=(1ll<<i),b[x]=fa[b[x]][i];
	for(int i=1;i<=n;i++) a[i]=d[b[i]];
	for(int i=1;i<=n;i++) a[i]+=a[i-1],printf("%lld.0\n",a[i]);
	return 0;
}


Measured memory_bytes: 52224
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define ll unsigned long long
using namespace std;
int main(){
    int A,B;
    cin>>A>>B;
    vector<int> ans = {1,2,3};
    REP(i,3){
        if(ans[i]!=A&&ans[i]!=B){
            cout<<ans[i]<<endl;
            return 0;
        }
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <list>
#include <queue>
#include <stack>
#include <map>
#include <set>
#define mod 1000000007
#define MAX 20000000009
using namespace std;

vector<long long> arr(200005,0);

int main(){
    int n, k;
    cin >> n >> k;
    arr[k] = 1;
    for(int i = k+1; i <= n+1; i++){
        arr[i] = (arr[i-1] + i-1) % mod;
    }
    long long tot = 0;
    for(int i = k; i <= n+1; i++) {
        tot = (tot + arr[i]) % mod;
    }
    cout << tot << endl;
}



Measured memory_bytes: 4696
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

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 I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
     
def main():
    N = I()
    maxA = -1
    max2A = -1
    max_i = -1
    for i in range(N):
        a = I()
        if a > maxA:
            max2A = maxA
            maxA = a
            max_i = i
        else:
            max2A = max(max2A, a)
    for i in range(N):
        if i != max_i:
            print(maxA)
        else:
            print(max2A)

main()



Measured memory_bytes: 6996
S=list(input())
ans1 = 0 #0から
ans2 = 0 #1から
for i in range(len(S)):
    if i%2 == 0:
        if S[i] == '1':
            ans1 += 1
        else:
            ans2 += 1
    else:
        if S[i] == '0':
            ans1 += 1
        else:
            ans2 += 1

print(min(ans1,ans2))

Measured memory_bytes: 3956
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop
from itertools import permutations, accumulate
from math import sqrt, ceil, floor
from bisect import bisect_left, bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
import sys
def I(): return int(input())  # '123' -> 123
def Is(): return map(int, input().split())  # '123 456' -> 123, 456
def LI(): return list(map(int, input().split()))  # '123 456' -> [123, 456]
def TI(): return tuple(map(int, input().split()))  # '123 456' -> (123, 456)
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def TIR(n): return [TI() for _ in range(n)]
def S(): return input()
def Ss(): return input().split()  # 'aa bb' -> 'aa','bb' or ['aa','bb']
def LS(): return list(input())  # 'abc123' -> ['a','b','c','1','2','3']
def SR(n): return [S() for _ in range(n)]
def SsR(n): return [Ss() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
sys.setrecursionlimit(1000000)
MOD = 1000000007
INF = float('inf')

n, m = Is()
print(int(n*(n-1)/2+m*(m-1)/2))

Measured memory_bytes: 63468
#include "bits/stdc++.h"
using namespace std;

int main() {
	string S, T, U;
	int A, B;

	cin >> S >> T;
	cin >> A >> B;
	cin >> U;

	if (S == U) {
		A--;
	}if (U == T) {
		B--;
	}
	cout << A <<' ' << B << endl;
}

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

int main()
{
	int a, b, c;
	cin >> a >> b >> c;
	map<tuple<int, int, int>, int> m;
	int count = 0, na = a, nb = b, nc = c;
	int ta, tb, tc;
	while(1)
	{
		if(m[make_tuple(na, nb, nc)])
		{
			cout << -1 << endl;
			break;
		}
		if(na % 2 == 1 || nb % 2 == 1 || nc % 2 == 1)
		{
			cout << count << endl;
			return 0;
		}
		m[make_tuple(na, nb, nc)] = 1;
		int ta = na;
		int tb = nb;
		int tc = nc;
		ta = nc / 2 + nb / 2;
		tb = na / 2 + nc / 2;
		tc = na / 2 + nb / 2;
		na = ta;
		nb = tb;
		nc = tc;
		++count;
	}
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
char str[1001],com[9],cp[1001],p[1001];

void reset(void);
void reset2(void);


main()
{
	
	int q,a,b,c,c2,FLAG;
	
	scanf("%s",str);
	
	scanf("%d",&q);
	
	while(q){
		FLAG=3;
		reset();
		
		scanf("%s",com);
		
		if(strcmp(com,"print")==0  ) {FLAG=0;}
		if(strcmp(com,"reverse")==0) {FLAG=1;}
		if(strcmp(com,"replace")==0) {FLAG=2;}
		
		
		switch(FLAG){
			case 0: //print
				scanf("%d %d",&a,&b);
				for(c=a;c<=b;c++){
					printf("%c",str[c]);
				}
				printf("\n");
				break;
			
			case 1: //reverse
				scanf("%d %d",&a,&b);
				reset2();
				strcpy(cp,str);
				for(c=a,c2=b;c<=b;c++,c2--){
					str[c]=cp[c2];
				}
				break;
			
			case 2: //replace
				scanf("%d %d",&a,&b);
				scanf("%s",p);
				
				for(c=a,c2=0;c<=b;c++,c2++){
					str[c]=p[c2];
				}
				break;
			
			default:q++;break;
		}
		q--;
	}
	return 0;
}

void reset(){
	int a;
	
	for(a=0;a<9;a++){
		com[a]=0;
	}
}

void reset2(){
	int a;
	
	for(a=0;a<1001;a++){
		cp[a]=0;
		p[a]=0;
	}
}

Measured memory_bytes: 584
#include <math.h>

#include <algorithm>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
using ll = long long;
using P = pair<int, int>;

int main() {
  int n, q;
  cin >> n;
  vector<int> a(n);

  ll sum = 0;
  map<int, int> mp;
  rep(i, n) {
    cin >> a[i];
    sum += a[i];  //合計を計算
    mp[a[i]]++;   //数をカウント
  }
  cin >> q;
  vector<P> bc(q);
  rep(i, q) {
    int b, c;
    cin >> b >> c;
    // bc[i].first = b;       //入れ替えるもの
    // bc[i].second = c - b;

    sum += (mp[b]) * (c - b);
    cout << sum << endl;
    mp[c] += mp[b];
    mp[b] = 0;  //入れ替え
  }
  return 0;
}


Measured memory_bytes: 8800
#include <bits/stdc++.h>
using namespace std;
using i64 = int64_t;
using vi = vector<i64>;
using vvi = vector<vi>;

#include <bits/stdc++.h>
using namespace std;
using i64 = int64_t;
using vi = vector<i64>;
using vvi = vector<vi>;

i64 largest_rectangle(vi hist) {
    hist.push_back(0);
    using ii = pair<i64, int>;
    stack<ii> st;
    i64 ret = 0;
    for (int i = 0; i < hist.size(); i++) {
        if (st.empty() || st.top().first < hist[i]) {
            st.push(ii(hist[i], i));
        } else {
            int s;
            while (st.size() && st.top().first >= hist[i]) {
                ret = max(ret, st.top().first * (i - st.top().second));
                s = st.top().second;
                st.pop();
            }
            st.push(ii(hist[i], s));
        }
    }
    
    return ret;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    cout.setf(ios::fixed);
    cout.precision(10);
    int h, w;
    cin >> h >> w;
    vvi b(h, vi(w));
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            int c;
            cin >> c;
            if (c == 0) {
                if (i == 0) {
                    b[i][j] = 1;
                } else {
                    b[i][j] = b[i - 1][j] + 1;
                }
            } else {
                b[i][j] = 0;
            }
        }
    }

    i64 ret = 0;
    for (int i = 0; i < h; i++) {
        ret = max(ret, largest_rectangle(b[i]));
    }
    cout << ret << endl;
}


Measured memory_bytes: 18220
import java.util.Scanner;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String str = sc.next();
        int n = sc.nextInt();
        String ch ="";
        int t,f;


        for(int i=0;i<n;i++){
            String test = sc.next();

            if(test.equals("replace")){
            	t=sc.nextInt();
            	f=sc.nextInt();
            	ch = sc.next();
            	String str1 = str.substring(0,t);
            	String str2 = str.substring(f+1);
            	str =str1+ch+str2;

            }
            else if(test.equals("reverse")){
            	t=sc.nextInt();
            	f=sc.nextInt();
            	char rev[]= str.substring(t,f+1).toCharArray();
            	char rev2[] = new char[rev.length];
            	for(int j=0;j<rev.length;j++){
            		rev2[j]=rev[rev.length-1-j];
            	}
            	str=str.replaceFirst(str.substring(t,f+1),String.valueOf(rev2));


            }else if(test.equals("print")){
            	t=sc.nextInt();
            	f=sc.nextInt();
            	System.out.println(str.substring(t,f+1));

            }else{
            	System.out.println("EEE");
            }



        }
        sc.close();
    }

}



Measured memory_bytes: 30708
#include<bits/stdc++.h>
using namespace std;
long long a[410][410];
int x;
int main()
{
	cin>>x;
	for(long long i=-200;i<=200;i++)
		for(long long j=-200;j<=200;j++)
			a[i+201][j+201]=pow(i,5)-pow(j,5);
	for(int i=1;i<=401;i++)
	{
		for(int j=1;j<=401;j++)
			if(a[i][j]==x)
			{
				cout<<i-201<<" "<<j-201;
				exit(0);
			}
	}
}

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

int main(){
  int n;
  cin >> n;
  vector<int> h(n);
  for (int i=0;i<n;++i) cin >> h[i];
  
  int pre=-999;
  for (int i=0;i<n;++i){
    if (pre<=h[i]-1){
      pre=h[i]-1;
    }
    else if (pre<=h[i]){
      pre=h[i];
    }
    else {
      puts("No");
      return 0;
    }
  }
  puts("Yes");
  return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
const int INF = 1 << 29;
int main()
{
    int N, K;
    int dp[15][2005];
    vector < int > product[15];
    cin >> N >> K;
    for(int i = 0; i < N; i++) {
        int a, b;
        cin >> a >> b;
        product[b - 1].push_back(a);
    }
    for(int i = 0; i < 10; i++) {
        sort(product[i].begin(), product[i].end(), greater < int > ());
    }
    fill_n(*dp, 15 * 2005, -INF);
    dp[0][0] = 0;
    for(int i = 0; i < 10; i++) {
        for(int j = 0; j <= N; j++) {
            if(dp[i][j] == -INF) continue;
            int sum = 0;
            dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]);
            for(int k = 0; k < product[i].size(); k++) {
                if(j + k + 1 > K) break;
                sum += product[i][k];
                dp[i + 1][j + k + 1] = max(dp[i + 1][j + k + 1], dp[i][j] + sum + k * (k + 1));
            }
        }
    }
    cout << dp[10][K] << endl;
    return (0);
}


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

int sum(int a){
	string b = to_string(a);
	int c = 0;
	for(int i = 0;i < b.size();i++)
		c += b[i] - '0';
	return c;
}

int main(){
	int n, a, b;
	cin >> n >> a >> b;
	int result = 0;
	for(int i = 0;i <= n;i++){
		int quer = sum(i);
		if(quer >= a && quer <= b)
			result += i;
	}
	cout << result;
}

Measured memory_bytes: 256
import qualified Data.ByteString.Char8 as BS
import Data.Maybe (fromJust)
import Data.List

isEvenStr :: String -> Bool
isEvenStr s =
    s1 == s2
    where 
        c = (length s) `div` 2
        s1 = take c s
        s2 = drop c s

solve :: String -> Int 
solve s 
    | isEvenStr s = length s
    | otherwise = solve $ init s

main :: IO()
main = do
    s <- getLine
    print $ solve (init s)


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

int main(){
  int n;
  cin>>n;
  vector<int> numbers(n);
  for(int i=0;i<n;i++){
    cin>>numbers.at(i);
    if(numbers.at(i)%2==0&&(numbers.at(i)%3!=0&&numbers.at(i)%5!=0)){
      cout<<"DENIED"<<endl;
      return 0;
    
    }
  }
  cout<<"APPROVED"<<endl;
}



Measured memory_bytes: 256
// B - 文字列大好きいろはちゃんイージー / Iroha Loves Strings (ABC Edition) https://atcoder.jp/contests/abc042/tasks/abc042_b

  import io.Source

  object Main extends App {
    val xs = Source.stdin.getLines()
    xs.next() // N, Lをスキップ

    println(solve(xs))

    def solve(xs: Iterator[String]): String = {
      xs.toSeq.sorted.foldLeft("")((acc, s) => acc + s)
    }
  }


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

using namespace std;
typedef long long ll;
typedef pair<int,int> pa;

#define fst first
#define snd second
#define pb push_back

const int maxn=1000005,maxm=55;
const double pi=acos(-1.0);
const ll mod=1000000007;
const double eps=1e-6;

int k,n;
int a[maxn];

int main()
{
	int i,j,k;
	scanf("%d %d",&k,&n);
	for(i=0;i<n;i++) scanf("%d",a+i);
	int r=k-(k-a[n-1]+a[0]);
	for(i=0;i<n-1;i++)
    {
        r=min(r,k-a[i+1]+a[i]);
    }
    printf("%d\n",r);
    return 0;
}


Measured memory_bytes: 1024
#include<cmath>
#include<cstdio>
#include<algorithm>
using namespace std;
const int MAXN=505;
const int L=100000;
int N,K,A[MAXN],B[MAXN];
int Sum[MAXN],P[L+5],Len,Ans;
int gcd(int x,int y){
	if(x==0)return y;
	return gcd(y%x,x);
}
int Check(int d){
	for(int i=1;i<=N;i++)
		B[i]=A[i]%d;
	sort(B+1,B+N+1);
	for(int i=1;i<=N;i++)
		Sum[i]=Sum[i-1]+B[i];
	int t=Sum[N]/d;
	if(Sum[N-t]<=K)return 1;
	return 0;
}
int main(){
	scanf("%d%d",&N,&K);
	for(int i=1;i<=N;i++){
		scanf("%d",&A[i]);
		Sum[i]=Sum[i-1]+A[i];
	}
	sort(A+1,A+N+1);
	if(Sum[N]-A[N]<=K){
		printf("%d\n",Sum[N]);
		return 0;
	}
	int siz=sqrt(Sum[N]);
	for(int i=1;i<siz;i++)
		if(Sum[N]%i==0){
			P[++Len]=i;
			P[++Len]=Sum[N]/i;
		}
	if(siz*siz==Sum[N])P[++Len]=siz;
	else if(Sum[N]%siz==0)P[++Len]=siz,P[++Len]=Sum[N]/siz;
	sort(P+1,P+Len+1);
	for(int i=1;i<=Len;i++)
		if(Check(P[i]))
			Ans=P[i];
	printf("%d\n",Ans);
}

Measured memory_bytes: 128
P = 2019
S = input()
N = len(S)
list_a = [0] * P
list_a[0] += 1
counter = 0
temp = 0
power = 1
for i in range(N):
    temp += pow(10, i, P) * int(S[N-i-1])
    temp %= P
    counter += list_a[temp]
    list_a[temp] += 1
print(counter)


Measured memory_bytes: 68344
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1000000009LL;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define fo(i,j,n) for (int i=(j); i < (n); i++)
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() {
    int n; cin >> n;
    vector<ll> A(n); rep(i, n) cin >> A[i];

    sort(all(A));
    ll ans[2] = {A[n-1], -1};
    ll half = ans[0]/ 2;
    rep(i, n){
        ll num = A[i];
        if(num <= half)
            chmax(ans[1], num);
        else{
            ll tmp = ans[0] - num;
            if(ans[1] < tmp) ans[1] = num;  
            break;
        }
    }

    cout << ans[0] << " " << ans[1] << ln;
}

    

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define ALL(c) (c).begin(),(c).end()
#define EACH(i,c) for(auto i=(c).begin();i!=(c).end();++i)
using namespace std;
#define int long long

signed main(){
	int N;
	cin >> N;
	vector<int> a(N), res(N);
	priority_queue<pair<int,int>> Q;
	Q.push(make_pair(0,0));
	for(int i = 0; i < N; ++i) {
		cin >> a[i];
		Q.push(make_pair(a[i], N - i));
	}
	int idx = Q.top().second, t = Q.top().first, cnt = 1;
	Q.pop();
	while(!Q.empty()) {
		//cout << idx << "," << cnt << "," << t << endl;
				//cout << ">" << Q.top().first << "," << Q.top().second << endl;
		if(idx >= Q.top().second) {
			if (Q.top().first >= t) {
				res[N - idx] += Q.top().first - t;
				++cnt;
				Q.pop();
			} else {
				// cout << ">" << Q.top().first << "," << Q.top().second << endl;
				res[N - idx] += (t - Q.top().first) * cnt;
				t = Q.top().first;
				++cnt;
				Q.pop();
			}
		} else {
			// cout << "|" << Q.top().first << "," << Q.top().second << endl;
			res[N - idx] += (t - Q.top().first) * cnt;
			t = Q.top().first;
			++cnt;
			idx = Q.top().second;
			Q.pop();
		}
	}
	for(int i = 0; i < N; ++i) {
		cout << res[i] << endl;
	}
	return 0;
}


Measured memory_bytes: 4336
#include<stdio.h>

int main(){
  int n;
  double s;
  int k;
  int ca;
  int cb;
  scanf("%d",&n);
  s = n /1.08;
  k = (int)s;
  ca = (int)(k*1.08);
  cb = (int)((k+1)*1.08);
  if(ca == n){
    printf("%d",k);
  }else if(cb == n){
    printf("%d",k+1);
  }else{
    printf(":(");
  }
  return 0;
}

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

using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using vint = vector<int>;
template<typename T> using uset = unordered_set<T>;
template<typename T1, typename T2> using umap = unordered_map<T1, T2>;

constexpr int INF = (1 << 30) - 1;
constexpr ll LLINF = 1LL << 60;
constexpr int dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dx[] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr char el = '\n';
constexpr int mod = 1000000007;

template<typename T> T lcm(T a, T b) { return (a / gcd(a, b) * b); }

ll dp[305][305][305] = {};
int main() {
    int N, M;
    cin >> N >> M;

    dp[0][1][1] = 1;
    for (int i = 0; i < M; i++) {
        for (int j = 1; j <= N; j++) {
            for (int k = 1; k <= N; k++) {
                if (dp[i][j][k] == 0) continue;
                (dp[i + 1][j + 1][k] += (N - j) * dp[i][j][k]) %= mod;
                (dp[i + 1][j][j] += k * dp[i][j][k]) %= mod;
                (dp[i + 1][j][k] += (j - k) * dp[i][j][k]) %= mod;
            }
        }
    }

    cout << dp[M][N][N] << endl;

    return (0);
}

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

int main()
{
    int a, b;
    char c;

    cin >> a >> b >> c;

    char m[b][a];
    for( int i = 0; i < b; i++ )
        for( int j = 0; j < a; j++ )
            m[i][j] = '.';
    
    m[(b-1)/2][(a-1)/2] = c;
    m[0][0] = '+';
    m[0][a-1] = '+';
    m[b-1][0] = '+';
    m[b-1][a-1] = '+';

    for( int i = 1; i < a - 1; i++ )
        m[0][i] = '-';
    for( int i = 1; i < a - 1; i++ )
        m[b-1][i] = '-';
    for( int i = 1; i < b - 1; i++ )
        m[i][0] = '|';
    for( int i = 1; i < b - 1; i++ )
        m[i][a-1] = '|';

    for( int i = 0; i < b; i++ )
    {
        for( int j = 0; j < a; j++ )
            cout << m[i][j];
        cout << endl;
    }

    return 0;
}


Measured memory_bytes: 3124
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int maxn=1e5+10;
int n,q;
struct Node
{
   int  s,t;
    int pos;
}s[maxn*2];
bool cmp(Node a,Node b)
{
        if(a.s==b.s)
            return a.t<b.t;
        return a.s<b.s;
}
int main()
{
   cin>>n>>q;
   int x,t,s1;
   for(int i=1;i<=n;i++)
   {
     cin>>s1>>t>>x;
     s[i].s=(s1-x);
     s[i].t=(t-x);
      s[i].pos=x;
   }
   sort(s+1,s+n+1,cmp);
  /* for(int i=1;i<=n;i++)
   {
       cout<<s[i].s<<' '<<s[i].t<<endl;
   }*/
   int d;
   int index=1;
   priority_queue<P,vector<P>,greater<P> >que;
   for(int i=0;i<q;i++)
   {
       cin>>d;
       while(index<=n&&s[index].s<=d)
       {
        que.push({s[index].pos,s[index].t});
            index++;
       }
       while(!que.empty()&&que.top().second<=d)
                que.pop();
       if(!que.empty())
        cout<<que.top().first<<endl;
       else
        cout<<-1<<endl;

   }


    return 0;
}


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

int main() {
  int N, K, X, Y;
  cin >> N >> K >> X >> Y;
  
  if(N>K){
  cout << K*X + Y*(N-K);
  }
  
  else
  {
    cout << N*X;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
 
int main() {
    int n,m,a,b;
    cin >> n >> m;
    int h[n] = {0};
    int f[n] = {0};
    for(int i=0;i<n;++i){
        cin >> h[i];
    }
    for(int i=0;i<m;++i){
        cin >> a >> b;
        if(h[a-1] > h[b-1]){
            f[b-1]=1;
        }else if(h[a-1] < h[b-1]){
            f[a-1]=1;
        }else{
            f[a-1]=1;
            f[b-1]=1;
        }
    }
    int c=0;
    for(int i=0;i<n;++i){
        if(f[i] == 0){
            c++;
        }
    }
    cout << c << endl;
}

Measured memory_bytes: 4416
N, K = map(int, input().split())
ans_list = []

for i in range(2*K):
  if(i%2==0):
    tmp = input()
    pass
  else:
    list_tmp = list(map(int, input().split()))
    for item in list_tmp:
      ans_list.append(item)

print(N - len(set(ans_list)))


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

#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = (n)-1; i >= 0; i--)
#define rep1(i,n) for(int i = 1; i <= (n); i++)
#define rrep1(i,n) for(int i = (n); i > 0; i--)

#define ll long long
#define pi pair<int, int>
#define pll pair<ll, ll>

#define MOD 1000000007
#define INF 1000000000000000LL

using namespace std;

#define MAXN 220000

vector<vector<pll>>is(MAXN);

struct Seg{
  vector<ll>mx;
  vector<ll>sum;

  Seg(){
    mx.resize(1<<19);
    sum.resize(1<<19);
  }

  void add_val(ll l, ll r, ll score, ll pos=1, ll bottom=0, ll top=1<<18){
    if(r <= bottom || l >= top)return;
    if(l <= bottom && top <= r){
      sum[pos] += score;
      return;
    }

    ll mid = (bottom+top)/2;
    add_val(l, r, score, pos*2, bottom, mid);
    add_val(l, r, score, pos*2+1, mid, top);
    mx[pos] = max<ll>(
      sum[pos*2] + mx[pos*2],
      sum[pos*2+1] + mx[pos*2+1]
    );
  }

  ll max_val(ll l, ll r, ll pos=1, ll bottom=0, ll top=1<<18){
    if(r <= bottom || l >= top)return -INF;
    if(l <= bottom && top <= r)return mx[pos] + sum[pos];

    ll mid = (bottom+top)/2;
    return max<ll>(
      max_val(l, r, pos*2, bottom, mid),
      max_val(l, r, pos*2+1, mid, top)
    )+sum[pos];

  }

};

int main(){
  int n,m;cin>>n>>m;
  rep(i, m){
    int l,r,a;cin>>l>>r>>a;
    is[r].push_back({l,a});
  }

  Seg seg;

  rep1(r, n){
    ll mx = seg.max_val(0, r);
    seg.add_val(r, r+1, mx);
    for(auto p: is[r]){
      ll l = p.first;
      ll a = p.second;
      seg.add_val(l, r+1, a);
    }
  }

  cout<<seg.max_val(0, n+1)<<endl;

//  rep(i, n)cout<<seg.max_val(0, i+1)<<' ';cout<<endl;

  return 0;
}

Measured memory_bytes: 22740