akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
#include<algorithm>

using namespace std;

int main(){
    int N;
    string a, b;
    cin >> N >> a >> b;
    int st = N;
    while(st>0){
        string t1,t2;
        t1 = a.substr(N-st,st);
        t2 = b.substr(0,st);
        if(t1.compare(t2) == 0)
            break;
        st--;
    }
    cout << ((2*N)-st) << endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>

using namespace std;

#define reps(i,f,n) for(int i=f; i<int(n); ++i)
#define rep(i,n) reps(i,0,n)

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

int main()
{
	int n;
	while(scanf("%d", &n), n){
		const int age[] = {10, 20, 30, 40, 50, 60};
		int cnt[7] = {0};
		rep(i, n){
			int a;
			scanf("%d", &a);
			cnt[upper_bound(age, age+6, a)-age]++;
		}
		rep(i, 7)
			printf("%d\n", cnt[i]);
	}
	return 0;
}

Measured memory_bytes: 1028
import bisect
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))


book_a = [0] * (n + 1)
for i in range(n):
    book_a[i + 1] = book_a[i] + a[i]

book_b = [0] * (m + 1) 
for j in range(m):
    book_b[j + 1] = book_b[j] + b[j]
count = 0
for read in range(n + 1):
    tmp = k - book_a[read]
    if tmp < 0:
        break
    read_b = bisect.bisect_right(book_b, tmp) -1
    count = max(count, read_b + read)

print(count)
    







Measured memory_bytes: 47464
#include<bits/stdc++.h>
#define N 10
using namespace std;
int n,a[N],z[N],ans;
string s,t;

void check(){
  int cp[N],cnt=0;
  for(int i=0;i<n;i++)cp[i]=a[i];
  for(int i=0;i<n;i++){
    int x=cp[i];
    if(!x)continue;
    cnt++;
    for(int j=i;j<=z[i];j++)
      cp[j]=(cp[j]-x+10)%10;
  }
  ans=min(ans,cnt);
}

void dfs(int x){
  if(x==n){
    check();
    return;
  }
  for(int i=x;i<n;i++){
    z[x]=i;
    dfs(x+1);
  }
}

int main(){
  while(1){
    cin>>n;
    if(!n)break;
    cin>>s>>t;
    for(int i=0;i<n;i++)
      a[i]=((s[i]-'0')-(t[i]-'0')+10)%10;
    ans=n;
    dfs(0);
    cout<<ans<<endl;
  }
  return 0;
}

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

int main(){
  cin >> n >> m >> l;
  ll a,b;
  a = m / l;
  b = n / l;
  if(n % l == 0)a++;
  print(a-b);
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(ll i=1;i<=n;i++)
#define rep_start(a,i,n) for(ll i=a;i<=n;i++)
#define rev(i,n) for(ll i=n-1;i>=0;i--)
#define rev1(i,n) for(ll i=n;i>0;i--)
#define sz(a) int((a).size())
#define all(c) c.begin(),c.end()
#define tr(c,i) for(typeof(c).begin() i+=c.begin; i!=c.end(); i++)
#define present(c,x) (c.find(x)!=c.end())
#define cpresent(c,x) (find(all(c),x)!=c.end())
#define pb push_back
#define F first
#define S second
#define INF INT_MAX
#define mod 1000000007
#define print1(a) cout<<a<<"\n";
#define print2(a,b) cout<<a<<" "<<b<<"\n";
#define print3(a,b,c) cout<<a<<" "<<b<<" "<<c<<"\n";
#define mt make_tuple
#define eb emplace_back

typedef long long int ll;
typedef vector<ll> vi;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef pair<ll,ll> ii;
typedef vector<ii> vii;
typedef tuple<int,int,int> State;

void solve(){
    int a,b;cin>>a>>b;
    int tmp1=b-2*a;
    int tmp2=4*a-b;
    if(tmp1>=0 && tmp2>=0 && tmp1%2==0 && tmp2%2==0) cout<<"Yes";
    else cout<<"No";
}

signed main() {
    // your code goes here
    IOS
    ll t=1;
    //cin>>t;
    rep1(i,t){
        solve(); 
    }
    return 0;
}

Measured memory_bytes: 3640
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("unroll-loops")

#include <iostream>
#include <stdlib.h>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <unordered_map>
#include <random>
#include <assert.h>
#include <memory.h>
#include <time.h>
#include <bitset>

#define uint unsigned int
#define ll long long
#define ull unsigned long long
#define ld long double
#define rep(i, l, r) for (int i = l; i < r; i++)
#define repb(i, r, l) for (int i = r; i > l; i--)
#define sz(a) (int)a.size()
#define fi first
#define se second
#define mp(a, b) make_pair(a, b)
#define rank qwertyuio
#define next dfghjk

using namespace std;

inline bool setmin(int &x, int y) { return (y < x) ? x = y, 1 : 0; }
inline bool setmax(int &x, int y) { return (y > x) ? x = y, 1 : 0; }
inline bool setmin(ll &x, ll y) { return (y < x) ? x = y, 1 : 0; }
inline bool setmax(ll &x, ll y) { return (y > x) ? x = y, 1 : 0; }

const int N = 10000;
const int inf = (int)1e9 + 1;
const ll big = (ll)1e18 + 1;
const int P = 239;
const int P1 = 31;
const int P2 = 57;
const int MOD = (int)1e9 + 7;
const int MOD1 = (int)1e9 + 9;
const int MOD2 = 998244353;
const double eps = 1e-9;
const double pi = atan2(0, -1);
const int ABC = 26;

vector<int> g[N];
int p = 0;
int a[N];
int ans[N];
int tot = 0;

void dfs(int u, int par) {
    for (int v : g[u]) {
        if (v != par) {
            dfs(v, u);
        }
    }
    ans[u] = a[p++];
    if (par != -1) {
        tot += ans[u];
    }
}

int main()
{
    //freopen("a.in", "r", stdin);
    //freopen("a.out", "w", stdout);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.precision(20);
    cout << fixed;
    //ll TL = 0.95 * CLOCKS_PER_SEC;
    //clock_t time = clock();
    int n;
    cin >> n;
    rep(i, 0, n - 1) {
        int u, v;
        cin >> u >> v;
        u--; v--;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    rep(i, 0, n) {
        cin >> a[i];
    }
    sort(a, a + n);
    dfs(0, -1);
    cout << tot << "\n";
    rep(i, 0, n) {
        cout << ans[i] << " ";
    }
    cout << "\n";
    return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp setprecision
#define pb(x) push_back(x)
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;
const ll MOD = 1e9+7;
const ll MOD2 = 998244353;
const int inf = INT_MAX;
const ll INF = LLONG_MAX;
const string alpha = "abcdefghijklmnopqrstuvwxyz";

int main(){
    ll N, K;
    cin >> N >> K;
    ll ans = 0;
    ll a = N/K;
    ans += a*a*a;
    if(K%2 == 0){
        ll b = N/(K/2);
        ll c = b-a;
        ans += c*c*c;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Numerics;
public class MainClass
{
	public const long Giri = 1000000007;
	public const long DpInf = 99999999999999;
	
	public static void Main(string[] args)
	{
		var n = Console.ReadLine().ToInt();
		int zoro = 0;
		int maxZoro = 0;
		for(int i = 0; i < n; i++)
		{
			var p = Input().ToInt();
			if(p[0] == p[1])
			{
				zoro++;
			}
			else
			{
				maxZoro = Math.Max(maxZoro, zoro);
				zoro=0;
			}
		}
				maxZoro = Math.Max(maxZoro, zoro);
		
		if(maxZoro >= 3)
		{
			Console.WriteLine("Yes");
		}
		else
			Console.WriteLine("No");
		
		
	}

	
	static long GCD(long a, long b)
	{
		var v = new[] { a, b };
		while (v[1] != 0) { v = new[] { v[1], v[0] % v[1] }; }
		return v[0];
	}
	public static string[] Input() { return Console.ReadLine().Split(); }
}

public static class Smarter
{
	public static int ToInt(this string str) { return int.Parse(str); }
	public static long ToLong(this string str) { return long.Parse(str); }
	public static int[] ToInt(this string[] str, int offset = 0)
	{
		var r = new int[str.Length];
		for(int i = 0; i < str.Length; i++) r[i] = str[i].ToInt() + offset;
		return r;
	}
}


Measured memory_bytes: 27560
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>

int main(){
    int n;
    scanf("%d", &n);
    int stu[n], ord[n];
    for (int i=1; i<=n; ++i) {
        scanf("%d", &stu[i]);
        //printf("%d ", stu[i]);
        ord[stu[i]] = i;
    }
    
    for (int i=1; i<=n; ++i) {
        if (i==n) {
            printf("%d\n", ord[i]);
            break;
        }
        printf("%d ", ord[i]);   
    }
}


Measured memory_bytes: 1536
//abc054_d.cpp
//Sun Apr  7 21:17:08 2019

#include <iostream>
#include <string>
#include <queue>
#include <map>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <math.h>
#include <set>
#define INTINF 2147483647
#define LLINF 9223372036854775807
using namespace std;
using ll=long long;
typedef pair<int,int> P;

int main(){
	int n,ma,mb;
	cin >> n >> ma >> mb;

	int a[n],b[n],c[n];
	for (int i=0;i<n;i++){
		cin >> a[i] >> b[i] >> c[i];
	}

	int dp[n+1][401][401];
	for (int i=0;i<401;i++){
		for (int j=0;j<401;j++){
			dp[0][i][j] = 5000;
		}
	}

	for (int i=1;i<n+1;i++){
		for (int j=0;j<401;j++){
			for (int k=0;k<401;k++){
				if (j-a[i-1]>=0 && k-b[i-1]>=0){
					if (j-a[i-1]==0 && k-b[i-1]==0){
						dp[i][j][k] = min(dp[i-1][j][k],c[i-1]);
					}else {
						dp[i][j][k] = min(dp[i-1][j][k],dp[i-1][j-a[i-1]][k-b[i-1]]+c[i-1]);
					}
				}else{
					dp[i][j][k] = dp[i-1][j][k];
				}
//				if (j<=3 && k<=3){
//					cout << dp[i][j][k] << " ";
//				}
			}
//			if (j<=3){
//				printf("\n");
//			}
		}
//		printf("\n");
	}

	int count = 1;
	int ans = 5000;
	int anscount = 0;
	while (count*ma < 401 && count*mb < 401){
//		if (count < 10){
//			cout << count << dp[n][count*ma][count*mb] << endl;
//		}
		if (dp[n][count*ma][count*mb] < ans){
			ans = dp[n][count*ma][count*mb];
			anscount = count;
		}
		count++;
	}

	if (ans == 5000){
		ans = -1;
	}
	
	cout << ans << endl;
//	printf("%.4f\n",ans);
}

Measured memory_bytes: 25984
#include<bits/stdc++.h>
#include<atcoder/dsu>
using namespace std;
using ll = long long;
const ll MOD = 1e9+7;

int main(){
  
  
  int n,q; cin>>n>>q;
  atcoder::dsu d(n);
  while(q--){
    int t,u,v; cin>>t>>u>>v;
    if(t==0){
      d.merge(u,v);
    }
    else{
      cout<<d.same(u,v)<<endl;
    }
  }
  
}


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

int main()
{
  string S,T;  
  cin >> S >> T;
  
  int ch = 1;
  
  for(int i=0;i<S.length();++i)
  {
    if(S[i]!=T[i])
    {
      ch = 0;
    }
  }
  if(ch==1)
  {
    cout<<"Yes"<<endl;
  }
  else
  {
    cout<<"No"<<endl;    
  }
  return 0;
}

Measured memory_bytes: 3580
import sys
stdin = sys.stdin
 
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

a,b,c = na()

print(['No','Yes'][(a-c)*(c-b) > 0])

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int h,w,sx,sy,m;
int d[256],dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};
char c[10][10],sc,nc[4]={'U','R','D','L'};
string ans;

bool dfs(int x,int y,char r,int cnt){
  if(cnt==m){return 1;}
  bool res=0;
  c[y][x]='.';
  for(int i=0;i<3;i++){
    int p=(d[r]+i)%4,nx=x,ny=y;
    while(0<=nx&&nx<w&&0<=ny&&ny<h&&c[ny][nx]!='o')
      nx+=dx[p],ny+=dy[p];
    if(0<=nx&&nx<w&&0<=ny&&ny<h)
      if(dfs(nx,ny,nc[p],cnt+1))ans=nc[p]+ans,res=1;
  }
  c[y][x]='o';
  return res;
}

int main(){
  cin>>h>>w;
  d['U']=3,d['R']=0,d['D']=1,d['L']=2;
  for(int i=h-1;i>=0;i--)
    for(int j=0;j<w;j++){
      cin>>c[i][j];
      if(c[i][j]=='o')m++;
      else if(c[i][j]!='.')sx=j,sy=i,sc=c[i][j];
    }
  dfs(sx,sy,sc,0);
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 3220
import sys
input = sys.stdin.readline
from collections import deque

nn = 200200
mod = 10**9+7

fa = [1] * (nn+1)
fainv = [1] * (nn+1)
for i in range(nn):
    fa[i+1] = fa[i] * (i+1) % mod
fainv[-1] = pow(fa[-1], mod-2, mod)
for i in range(nn)[::-1]:
    fainv[i] = fainv[i+1] * (i+1) % mod

inv = lambda i: fainv[i] * fa[i-1] % mod

N = int(input())
X = [[] for i in range(N)]
for i in range(N-1):
    x, y = map(int, input().split())
    X[x-1].append(y-1)
    X[y-1].append(x-1)

P = [-1] * N
Q = deque([0])
R = []
while Q:
    i = deque.popleft(Q)
    R.append(i)
    for a in X[i]:
        if a != P[i]:
            P[a] = i
            X[a].remove(i)
            deque.append(Q, a)

unit = 1
f = lambda a, b: a * b % mod
g_bu = lambda a, i=-1: a * inv(SI[i]) % mod
g_td = lambda a, i=-1: a * inv(N - SI[i]) % mod

SI = [1] * N
for i in R[1:][::-1]:
    SI[P[i]] += SI[i]

BU = [unit] * N
TD = [unit] * N
for i in R[1:][::-1]:
    BU[i] = g_bu(BU[i], i)
    p = P[i]
    BU[p] = f(BU[p], BU[i])
BU[R[0]] = g_bu(BU[R[0]], R[0])

AX = [1] * N
for i in R:
    ac = unit
    for j in X[i]:
        AX[j] = ac
        ac = f(ac, BU[j])
    ac = unit
    for j in X[i][::-1]:
        AX[j] = f(AX[j], ac)
        TD[j] = g_td(f(TD[i], AX[j]), j)
        ac = f(ac, BU[j])

print(*[BU[i] * SI[i] % mod * TD[i] % mod * fa[N - 1] % mod for i in range(N)], sep = "\n")

Measured memory_bytes: 126000
import math

h, w = map(int, input().split())

if h%3==0 or w%3==0:
    print(0)
    exit()

ans = float("inf")

if h%2==0:
    a = h//2
    b = h//2
else:
    a = h//2
    b = h//2+1

for i in range(1, w):
    l = [a*i, b*i, h*w-a*i-b*i]
    ans = min(ans, max(l)-min(l))


if w%2==0:
    a = w//2
    b = w//2
else:
    a = w//2
    b = w//2+1

for i in range(1, h):
    l = [a*i, b*i, h*w-a*i-b*i]
    ans = min(ans, max(l)-min(l))

ans = min(ans, h)
ans = min(ans, w)

print(ans)

Measured memory_bytes: 3064
def readinput():
    n=int(input())
    p=list(map(int,input().split()))
    return n,p

def main(n,p):
    count=0
    pmin=p[0]
    for i in range(n):
        pmin=min(p[i],pmin)
        if pmin>=p[i]:
            count+=1
    return count

if __name__=='__main__':
    n,p=readinput()
    ans=main(n,p)
    print(ans)


Measured memory_bytes: 32308
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
#include <functional>
using namespace std;

int main()
{
    int n, k, x0;
    cin >> n >> k >> x0;
    if(x0 == 0){
        cout << 0 << endl;
        return 0;
    }

    unsigned long long x = x0;
    vector<int> cnt(1024, 0);
    for(int i=0; i<n; ++i){
        unsigned long long y = x + LLONG_MAX + 1;
        ++ cnt[y / (ULLONG_MAX / 1024)];
        x ^= x << 13;
        x ^= x >> 7;
        x ^= x << 17;
    }

    int index = 0;
    while(cnt[index] < k){
        k -= cnt[index];
        ++ index;
    }

    x = x0;
    vector<unsigned long long> v;
    for(int i=0; i<n; ++i){
        unsigned long long y = x + LLONG_MAX + 1;
        if(y / (ULLONG_MAX / 1024) == index)
            v.push_back(y);
        x ^= x << 13;
        x ^= x >> 7;
        x ^= x << 17;
    }

    sort(v.begin(), v.end());
    long long ret = v[k-1] - LLONG_MAX - 1;
    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 2072
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#define MAX 10000

int main(){
  int n,i,j,find,count=0;
  int num[MAX];

  scanf("%d",&n);
  if( n < 1 || MAX < n ) exit(2);

  for( i = 0 ; i < n ; i++ )
    {
      scanf("%d",&num[i]);
      if( num[i] < 2 || 100000000 < num[i]) exit(3);
    }


  for( i = 0 ; i < n ; i++ )
    {
      find = 1;
      if( num[i] % 2 == 0 ) find = 0;
      else
     {	 
	for( j = 3 ; j <= sqrt(num[i]) ; j+=2)
	{
	  if( num[i] % j == 0 )  {
	    find = 0;
	    break;
	}
      }
     }
      if( find == 1 || num[i] == 2 ) count++;
    }

  printf("%d\n",count);
  
  return 0;
}

Measured memory_bytes: 628
#include <stdio.h>

unsigned xor128() {
	static unsigned x = 123456789, y = 362436069, z = 521288629, w = 88675123;
	unsigned t = x ^ (x << 11);
	x = y; y = z; z = w;
	return w = w ^ (w >> 19) ^ (t ^ (t >> 8));
}

typedef struct node_t {
	int val;
	struct node_t *lch, *rch;
	int size;
	unsigned int pri;
} node;

node* new_node(int val) {
	static int it = 0;
	static node pool[200000];
	pool[it] = (node) { val, 0, 0, 1, xor128() };
	return &pool[it++];
}

int count(node *t) {
	return !t ? 0 : t->size;
}

node *update(node *t) {
	t->size = count(t->lch) + count(t->rch) + 1;
	return t;
}

node *merge(node *l, node *r) {
	if (!l || !r) return !l ? r : l;
	if (l->pri > r->pri) {
		l->rch = merge(l->rch, r);
		return update(l);
	}
	r->lch = merge(l, r->lch);
	return update(r);
}

typedef struct{ node *a, *b; } pnode;

pnode split(node *t, int k) {
	if (!t) return (pnode) { 0, 0 };
	if (k <= count(t->lch)) {
		pnode s = split(t->lch, k);
		t->lch = s.b;
		return (pnode) { s.a, update(t) };
	}
	pnode s = split(t->rch, k - count(t->lch) - 1);
	t->rch = s.a;
	return (pnode) { update(t), s.b };
}

node* find(node *t, int val) {
	while (t) {
		if (t->val == val) break;
		t = val < t->val ? t->lch : t->rch;
	}
	return t;
}

int count_lower(node *t, int v) {
	if (!t) return 0;
	if (t->val < v) return count(t->lch) + 1 + count_lower(t->rch, v);
	if (t->val == v) return count(t->lch);
	return count_lower(t->lch, v);
}

node *insert(node *t, int val) {
	int k = count_lower(t, val);
	pnode s = split(t, k);
	return merge(merge(s.a, new_node(val)), s.b);
}

node *erase(node *t, int k) {
	pnode s1 = split(t, k), s2 = split(s1.b, 1);
	return merge(s1.a, s2.b);
}

int main(void)
{
	int q, com, x, cnt = 0;
	node *root = 0;
	scanf("%d", &q);
	while (q--) {
		scanf("%d%d", &com, &x);
		if (com == 0) {
			if (!find(root, x)) ++cnt, root = insert(root, x);
			printf("%d\n", cnt);
		}
		else if (com == 1) {
			puts(find(root, x) ? "1" : "0");
		}
		else {
			if (find(root, x)) --cnt, root = erase(root, count_lower(root, x));
		}
	}
	return 0;
}



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

using namespace std;

typedef long long ll;
#define mems(p) memset(p,-1,sizeof(p))
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define nl "\n"

const int mxN = 1e5;
const ll MOD = 1e9 + 7;

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

ll gcd(ll a, ll b) {
	return b ? gcd(b, a%b) : a;
}

int main() {
	fast();
	int n;
	cin >> n;
	map<ll,ll> mapp;
	ll sum = 0, x;
	for (int i = 0; i < n; ++i)
	{
		cin >> x;
		sum += x;
		if (mapp[x]) {
			++mapp[x];
		} else {
			mapp[x] = 1ll;
		}
	}
	int q;
	cin >> q;
	ll from, to;
	for (int i = 0; i < q; ++i)
	{
		cin >> from >> to;
		if (mapp[from]) {
			ll famt = mapp[from];
			sum += (to-from) * famt;
			mapp[from] = 0ll;
			if (mapp[to]) {
				mapp[to] += famt;
			} else {
				mapp[to] = famt;
			}
		}
		cout << sum << nl;
	}
}

Measured memory_bytes: 9348
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n,ans=0;
  cin >> n;
  for(int i =1;i<=n;i++){
    int a=0;
     for(int j =1;j<=i;j++){
      if(i%j==0&&i%2!=0)
      {
        a+=1;
      }
    }
     if(a==8)ans++;
  }
  cout <<ans;
}


Measured memory_bytes: 3580
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1e18;
const ll mod = 1000000007;

#define rep(i, n) for (int i = 0; i < (int)(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 ctoi(char c) {
  if (c >= '0' && c <= '9') {
    return c - '0';
  }
  return 0;
}
ll factorial(ll n) {
  if (n == 1) {
    return 1;
  }
  ll ans = factorial(n-1);
  return ans*n;
}
ll gcd(ll a, ll b) {
  if (a < b) {
    ll tmp = a;
    a = b;
    b = tmp;
  }
  ll r = a%b;
  while(r != 0) {
    a = b;
    b = r;
    r = a%b;
  }
  return b;
}
ll lcm(ll a, ll b) {
  return (a/gcd(a, b))*b;
}

int main() {
  ll n;
  cin >> n;
  vector <vector <ll>> dp(n, vector <ll> (n));
  vector <ll> v(n+1);
  rep(i, n) cin >> v.at(i) >> v.at(i+1);
  rep(i, n) dp.at(i).at(i) = 0;
  for (ll i = 2; i <= n; i++) {
    for (ll j =  0; i+j-1 < n; j++) {
      ll k = i+j-1;
      dp.at(j).at(k) = INF;
      for (ll l = j; l < k; l++) {
        dp.at(j).at(k) = min(dp.at(j).at(k), 
                             dp.at(j).at(l)+dp.at(l+1).at(k)+v.at(j)*v.at(l+1)*v.at(k+1));
      }
    }
  }
  cout << dp.at(0).at(n-1) << endl;
}


Measured memory_bytes: 3220
n = int(input())
a = [int(x) for x in input().split()]
ans = 0
flg = True
while flg:
    for i in range(n):
        if a[i] % 2 == 0:
            a[i] //= 2
        else:
            flg = False
            break
    if flg:
        ans += 1
print(ans)

Measured memory_bytes: 3060
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
		int n = in.nextInt();
		int k = in.nextInt();
		boolean[] s = new boolean[n];
		for (int i = 0; i < k; i++) {
			int d = in.nextInt();
			for (int j = 0; j < d; j++)
				s[in.nextInt() - 1] = true;
		}
		int r = 0;
		for (int i = 0; i < n; i++)
			if (!s[i])
				r++;
		System.out.println(r);
	}
}

Measured memory_bytes: 46292
import java.io.IOException;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws IOException{
		NotFound solver = new NotFound();
		solver.readInput();
		solver.solve();
		solver.writeOutput();
	}

	static class NotFound {

		private String s;
		private String output;
		private Scanner scanner;

		public NotFound() {
			this.scanner = new Scanner(System.in);
		}

		public void readInput() {
			s = scanner.next();
			return ;
		}
		public void solve() {

			boolean set[] = new boolean[26];

			for(char c:s.toCharArray()) {
				set[c-'a'] = true;
			}

			for (int i=0; i<26; i++) {
				if(!set[i]) {
					output = String.valueOf((char)(i+'a'));
					return;
				}
			}
			output = "None";
			return ;
		}
		public void writeOutput() {
			System.out.println(output);
			return ;
		}

	}


}

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

int main(){
	int n,m;
	cin>>n>>m;
	string a[51];
	string b[51];
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	for(int i=0;i<m;i++){
		cin>>b[i];
	}
	for(int i=0;i<n-m+1;i++){
		for(int j=0;j<n-m+1;j++){
			int flag=0;
			for(int k=i;k<i+m;k++){
				for(int l=j;l<j+m;l++){
					if(a[k][l]!=b[k-i][l-j]){
						flag=1;
						break;
					}
				}
				if(flag==1){
					break;
				}
			}
			if(flag==0){
				cout<<"Yes";
				return 0;
			}
		}
	}
	cout<<"No";
	return 0;
}

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

typedef long double     lf;

using namespace std;

const lf EPS = 1e-9;

struct pt {
  lf x, y;
  pt( ) { }
  pt( lf x, lf y ) : x( x ), y ( y ) { }
};

inline lf x( pt P ) { return P.x; }
inline lf y( pt P ) { return P.y; }

istream& operator >> ( istream& in, pt& p ) {
  lf x,y; in >> x >> y;
  p = pt(x,y); return in;
}

ostream& operator << ( ostream& out, const pt& p ) {
  out << double(p.x) << " " << double(p.y);
  return out;
}

pt operator + ( const pt& A, const pt& B ) {
  return pt( x(A)+x(B), y(A)+y(B) );
}

pt operator - ( const pt& A, const pt& B ) {
  return pt( x(A)-x(B), y(A)-y(B) );
}


pt operator * ( const lf& B, const pt& A ) {
  return pt( x(A)*B, y(A)*B );
}

pt operator * ( const pt& A, const lf& B ) {
  return pt( x(A)*B, y(A)*B  );
}

inline lf dot( pt A, pt B ) {
  return x(A)*x(B) + y(A)*y(B);
}

inline lf norm( pt A ) {
  return x(A)*x(A) + y(A)*y(A);
}

inline lf abs( pt A ) {
  return sqrt( norm(A) );
}

inline lf dist ( pt A, pt B ) { return abs( B - A ); }

lf distToLine (pt p, pt A, pt B, pt &c) {
  lf u = dot( p-A , B-A ) / norm( B-A );
  c = A + u*( B-A );
  return dist( p , c );
}

pt refPoint(pt X, pt A, pt B) {
  pt aux; distToLine(X, A, B, aux);
  return X + lf(2.0)*(aux-X);
}

pt p1,p2,p;
int n;

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout << fixed << setprecision(10);


  cin >> p1 >> p2 >> n;
  for( int i = 0; i < n; ++i ) {
    cin >> p;
    cout << refPoint( p, p1, p2 ) << '\n';
  }
}

Measured memory_bytes: 3304
#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.at(i);
  

  int count = 0;
  int ans = 0;
  for(int i=0; i<N-1; i++){
    
    if(H.at(i+1) > H.at(i)){
      if(count > ans)
        ans = count;
      count = 0;
    }else{
      count++;
      if(i==N-2){
        if(count > ans)
          ans = count;
      }
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 640
n, m, l = map(int, input().split())

a = []
for i in range(n):
    aj = [int(x) for x in input().split()]
    a.append(aj)
    
b = []
for i in range(m):
    bj = [int(x) for x in input().split()]
    b.append(bj)

answer = []
for i in range(n):
    answer_c = []
    for j in range(l):
        answer_cc = 0
        for k in range(m):
            answer_cc += a[i][k] * b[k][j]
        answer_c.append(answer_cc)
    answer.append(answer_c)

for a in answer:
    print(*a)
            


Measured memory_bytes: 6996
N = int(input())
A = []
B = []
for i in range(N):
    a,b = map(int, input().split())
    A.append(a)
    B.append(b)
c = 0
for i in range(N-1,-1,-1):
    if (A[i]+c) % B[i] == 0:
        continue
    if A[i]+c < B[i]:
        push = B[i] - (A[i]+c)
    elif A[i]+c > B[i]:
        push = B[i] - (A[i]+c) % B[i]
    c += push
print(c)

Measured memory_bytes: 85528
#include<stdio.h>

int main()
{
    int n, k,i;
    long ans=0;
    scanf("%d%d", &n, &k);
    for (i = 1; k + i <= n; i++)
    {
        ans += i * (n/(k+i));
        if (n % (k + i) >= k)
            ans += n % (k + i) - k + 1;
        if (k == 0)
            ans--;
    }
    printf("%ld", ans);
    return 0;
}

Measured memory_bytes: 128
N=int(input())
S=list(input())
K=int(input())
moji=S[K-1]
#print(moji)

for i in range(N):
    
    if S[i]!=moji:
        S[i]="*"
mojiretu=""
for x in S:
  mojiretu+=x
print(mojiretu)

Measured memory_bytes: 3060
n, x, y = int(input()), list(map(int, input().split())), list(map(int, input().split()))
 
 
def dist(p):
    return pow(sum(pow(abs(a - b), p) for a, b in zip(x, y)), 1.0 / p)
 
 
for i in [1, 2, 3]:
    print(dist(i))
 
print(max(abs(a - b) for a, b in zip(x, y)))


Measured memory_bytes: 5652
//shan61916
#include <bits/stdc++.h>
  using namespace std;
typedef   long long ll;
typedef   unsigned long long ull ;
typedef   double dll ;

#define   mp make_pair
#define   pb push_back
#define   ff first 
#define   ss second
#define   IOS ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define   endl "\n" 
#define   pll pair<ll, ll>
#define   all(x) x.begin(), x.end()
#define   vll vector<ll> 


int main(){
 IOS
#ifdef SHAN
    freopen("input.txt" , "r" , stdin);  
#endif
  ll n;
  cin >> n;
  ll ct = 0;
  for(ll i = 1; i <= n; i++) {
  	ll tp ;
  	cin >> tp;
  	if(tp != i) ct++ ;
  }
  if(ct > 2) cout << "NO" ;
  else cout << "YES"; 
  return 0;
} //good night.

Measured memory_bytes: 256
#include <iostream>
#include <vector>

#define ll long long
const ll R = 1000000007;

using namespace std;

int main()
{
  int n, m;
  cin >> n >> m;
  vector<ll> x, y;
  ll x2=0, y2=0;
  for(int i = 0; i < n; ++i){
    ll tmp;
    cin >> tmp;
    x.push_back(tmp);
  }
  for(ll i = 0; i < n-1; ++i){
    ll tmp = ((i+1)*(n-1-i))*(x[i+1]-x[i]);
    x2 += tmp;
    x2 %= R;
  }
  for(int i = 0; i < m; ++i){
    ll tmp;
    cin >> tmp;
    y.push_back(tmp);
  }
  for(ll i = 0; i < m-1; ++i){
    ll tmp = ((i+1)*(m-1-i))*(y[i+1]-y[i]);
    y2 += tmp;
    y2 %= R;
  }
  cout << (x2*y2)%R << endl;
  return 0;
}


Measured memory_bytes: 2548
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;

  map<pair<int, int>, int> p1;
  map<pair<int, int>, int> p2;

  int l = 10;
  int m = 1;
  int f = 0;
  int e = 0;

  for(int i = 1; i <= n; ++i) {
    e++;
    if(e == 10) e = 0;

    if(i < l) {
      if((i % m) == 0) {
        f++;
      }
    } else {
      f = 1;
      l *= 10;
      m *= 10;
    }

    p1[pair<int, int>(f,e)]++;
    p2[pair<int, int>(e,f)]++;
  }

  int c = 0;
  for(map<pair<int, int>, int>::iterator it = p1.begin(); it != p1.end(); ++it) {
    c += it->second * p2[it->first];
  }

  cout << c << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define SORT(a) sort((a).begin(), (a).end())
#define RSORT(a) reverse((a).begin(), (a).end())
#define rep(i, n) for (int i = 0; i < n; i++)
#define all(a) ((a).bigin(), (a).end())
typedef long long ll;
const long long INF = 1LL << 60;
// const int INF=1010101010;
using Graph = vector<vector<int>>;

ll calc(ll x) {
  if (x % 4 == 1) return 1;
  if (x % 4 == 2) return x + 1;
  if (x % 4 == 3) return 0;
  if (x % 4 == 0) return x;
  return 0;
}

int main() {
  ll a, b;
  cin >> a >> b;
  ll ans = calc(b) ^ calc(a - 1);
  cout << ans << endl;
}

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

public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line1 = br.readLine();
		String line2 = br.readLine();
		int days = Integer.parseInt(line1.split(" ")[0]);
		int homeworks = Integer.parseInt(line1.split(" ")[1]);
		String[] costs = line2.split(" ");
		int sum = 0;
		for(int i = 0; i < homeworks; i++) {
			sum += Integer.parseInt(costs[i]);
		}
		System.out.println(Math.max(days - sum, -1));
	}
}


Measured memory_bytes: 34384
const solve = (input) => {
  const [ab, bc, ca] = input.split(" ").map(Number)
  return (ab * bc) / 2
}

if (process.env.NODE_ENV === "test") {
  module.exports = (input) => solve(input.trim())
} else {
  const input = require("fs").readFileSync("/dev/stdin", "utf8")
  console.log(solve(input.trim()))
}


Measured memory_bytes: 7372
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;

typedef long long ll;
const int MOD=924844033;
const int MAXN=2005;

int n,m,ncnt;
int ed[MAXN*2];
ll f[MAXN],d[MAXN*2][MAXN][2],fac[MAXN];
bool vis[MAXN][2];

void Init(){
    fac[0]=1;
    for(int i=1;i<MAXN;i++)
        fac[i]=fac[i-1]*i%MOD;
}

int main(){
    Init();
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++)
        for(int j=0;j<=1;j++){
            if(vis[i][j]) continue;
            for(int x=i,y=j;x<=n;x+=m,y^=1)
                vis[x][y]=1,ncnt++;
            ed[ncnt]=1;
        }
    ed[0]=1;
    d[0][0][0]=1;
    for(int i=0;i<2*n;i++)
        for(int j=0;j<=n;j++){
            d[i+1][j][0]=(d[i][j][0]+d[i][j][1])%MOD;
            if(!ed[i]) d[i+1][j+1][1]=d[i][j][0];
        }
    for(int i=0;i<=n;i++) f[i]=(d[2*n][i][0]+d[2*n][i][1])%MOD;
    ll ans=0;
    for(int i=0,k=1;i<=n;i++,k*=-1)
        ans=(ans+1ll*k*fac[n-i]*f[i]%MOD)%MOD;
    printf("%lld\n",(ans+MOD)%MOD);

    fclose(stdin);
    fclose(stdout);
}


Measured memory_bytes: 125568
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>
#include <utility>
#include <tuple>

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
using namespace std;
using ll = long long int;
using P = pair<ll, ll>;

// clang-format off
#ifdef _DEBUG_
#define dump(...) do{ cerr << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; PPPPP(__VA_ARGS__); cerr << endl; } while(false)
template<typename T> void PPPPP(T t) { cerr << t; }
template<typename T, typename... S> void PPPPP(T t, S... s) { cerr << t << ", "; PPPPP(s...); }
#else
#define dump(...) do{ } while(false)
#endif
template<typename T> vector<T> make_v(size_t a, T b) { return vector<T>(a, b); }
template<typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v(ts...))>(a, make_v(ts...)); }
template<typename T> bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false; }
template<typename T> bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false; }
template<typename T> void print(T a) { cout << a << endl; }
template<typename T, typename... Ts> void print(T a, Ts... ts) { cout << a << ' '; print(ts...); }
template<typename T> istream &operator,(istream &in, T &t) { return in >> t; }
// clang-format on

class UnionFind {
public:
    vector<int> par;
    int N;
    UnionFind(int n) {
        par.resize(n, -1);
        N = n;
    }
    int Find(int n) {
        return par[n] < 0 ? n : par[n] = Find(par[n]);
    }
    bool Union(int x, int y) {
        x = Find(x);
        y = Find(y);
        if (x == y) return false;
        if (-par[x] > -par[y]) swap(x, y);
        par[y] += par[x];
        par[x] = y;
        N--;
        return true;
    }
    bool Same(int x, int y) {
        return Find(x) == Find(y);
    }
    int size(int x) {
        return -par[Find(x)];
    }
    int size() {
        return N;
    }
};


int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n, q;
    cin, n, q;
    UnionFind uf(n);
    REP(i, 0, q) {
        int t, a, b;
        cin, t, a, b;
        if (t == 0) {
            uf.Union(a, b);
        } else {
            print(uf.Same(a, b));
        }
    }
    return 0;
}


Measured memory_bytes: 3992
/**
 * Created at 1:14 on 2019/03/06
 */

import java.util.*;

public class Main {

  static Scanner sc = new Scanner(System.in);

  static int N;

  public static void main(String[] args) {

    int n = sc.nextInt();
    N = n/2;

    ArrayList<Integer> a = new ArrayList(N);
    ArrayList<Integer> b = new ArrayList(N);

    for (int i=0; i<N; i++) {
      a.add(sc.nextInt());
      b.add(sc.nextInt());
    }

    ArrayList<Integer[]> rankingA = getRanking(a); //[0] 個数 [1] 数値
    ArrayList<Integer[]> rankingB = getRanking(b);

    if (!rankingA.get(0)[1].equals(rankingB.get(0)[1])) {
      System.out.println(2 * N - rankingA.get(0)[0] - rankingB.get(0)[0]);
    } else {
      System.out.println(2 * N - Math.max(
              rankingA.get(0)[0] + rankingB.get(1)[0],
              rankingA.get(1)[0] + rankingB.get(0)[0]
      ));
    }

  }

  static ArrayList<Integer[]> getRanking(ArrayList<Integer> list) {
    ArrayList<Integer[]> ranking = new ArrayList(N);
    list.sort(null);
    for (int i=0; i<N;) {
      for (int j=i+1; j<=N; j++) {
        if (j == N || !list.get(j).equals(list.get(i))) {
          ranking.add(new Integer[]{j-i, list.get(i)});
          i = j;
          break;
        }
      }
    }

    ranking.sort((x, y) -> y[0]-x[0]);

    if (ranking.size() == 1) {
      ranking.add(new Integer[]{0, -1});
    }

    return ranking;
  }

}


Measured memory_bytes: 64176
#include <bits/stdc++.h>
using namespace std;
#define LL long long
int N,M,x,y,pt;
LL b[50];
int C[50];
int st[50],ne[5010],go[5010];
class rec{
	public:
	int x,l;
	LL d;
	bool operator < (const rec &X)const{
		return l<X.l;
	}
	bool operator > (const rec &X)const{
		return l>X.l;
	}
}p1,p2;
class poi{
	public:
	LL d;
	int x;
	bool operator < (const poi &X)const{
		if (x!=X.x)return x<X.x;
		return d<X.d;
	}
};
set <poi> used;
priority_queue <rec ,vector <rec >, greater <rec > > heap;
void Add(int x,int y){ne[++pt]=st[x];st[x]=pt;go[pt]=y;}
int main() {
	scanf("%d%d",&N,&M);
	for (int i=0;i<N;i++)scanf("%d",&C[i]);
	for (int i=1;i<=M;i++){
		scanf("%d%d",&x,&y);
		x--;y--;
		Add(x,y);
		Add(y,x);
		b[x]|=1ll<<y;
		b[y]|=1ll<<x;
	}
	p1.x=0;p1.d=1;p1.l=C[0];
	for (int i=st[0];i;i=ne[i])
		p1.l+=C[go[i]];
	heap.push(p1);
	for (;;){
		p1=heap.top();
		heap.pop();
		if (used.find((poi){p1.d,p1.x})!=used.end())continue;
		if (p1.x==N-1)break;
		used.insert((poi){p1.d,p1.x});
		for (int i=st[p1.x];i;i=ne[i]){
			if ((p1.d>>go[i])&1)continue;
			if (b[go[i]]&(p1.d^(1ll<<p1.x)))continue;
			p2.x=go[i];p2.d=p1.d^(1ll<<go[i]);p2.l=p1.l;
			for (int j=st[p2.x];j;j=ne[j])
				if (!(b[go[j]]&p1.d))
					if (!((p1.d>>go[j])&1))
						p2.l+=C[go[j]];
			if (used.find((poi){p2.d,p2.x})!=used.end())continue;
			heap.push(p2);
		}
	}
	printf("%d\n",p1.l);
    return 0;
}

Measured memory_bytes: 60960
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <functional>

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
    #define eprintf(...) 42
#endif

#define rep_(i, a_, b_, a, b, ...) for (int i = (a), i##_len = (b); i < i##_len; ++i)
#define rep(i, ...) rep_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define reprev_(i, a_, b_, a, b, ...) for (int i = (b-1), i##_min = (a); i >= i##_min; --i)
#define reprev(i, ...) reprev_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define all(x) (x).begin(), (x).end()
template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
// template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair <int,int> P;
typedef long double ld;

constexpr int MOD = 1000000007;

// + - * / ^
int mod(int a)
{
    int res = a % MOD;
    if(res < 0) {
        return res + MOD;
    }
    return res;
}
int mul_mod(int a, int b)
{
    ll res = ((ll)a * (ll)b) % MOD;
    return mod((int)res);
}
int pow_mod(int a, int b)
{
    ll res = 1;
    while (b > 0) {
        if(b & 1) {
            res = res * (ll)a % (ll)MOD;
        }
        a = mul_mod(a, a);
        b >>= 1;
    }
    return (int)res;
}
int inv_mod(int a)
{
    return pow_mod(a, MOD - 2);
}
int div_mod(int a, int b)
{
    return mul_mod(a, inv_mod(b));
}

// ! C
constexpr int FAC_MAX = 1500001;
ll fac[FAC_MAX], finv[FAC_MAX], inv[FAC_MAX];
void com_init()
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < FAC_MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
ll com_mod(int a, int b){
    if (a < b) return 0;
    if (a < 0 || b < 0) return 0;
    return fac[a] * (finv[b] * finv[a - b] % MOD) % MOD;
}

int main (void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    com_init();
    int n; cin >> n;
    vector<int> a(n + 1); rep (i, a.size()) cin >> a[i];
    map<int, int> m;
    int p, q;
    rep (i, a.size()) {
        if (m[a[i]] != 0) {
            p = m[a[i]] - 1; q = i;
            break;
        }
        m[a[i]] = i + 1;
    }
    rep (k, 1, n + 2) {
        cout << mod(com_mod(n + 1, k) - com_mod(n - (q - p), k - 1)) << "\n";
    }
    return 0;
}

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

using namespace std;
template<class I>void gi(I&x){
	static char c;
	for(c=getchar();c<'0'||c>'9';c=getchar());
	for(x=0;c<='9'&&c>='0';c=getchar())x=x*10+(c&15);
}

const int N=500005;
typedef long long ll;
const double eps=1e-10;

struct node{
	double E,V;
	node(double e=0,double v=0){E=e,V=v;}
	double T(){return E/V;}
	inline node friend operator+(const node&a,const node&b){return node(a.E+b.E,a.V+b.V);}
	inline node to(double V){return node(T()*V,V);}
};
deque<node> Q;
double E,V;int n,L;
inline node pop_front(){node t=Q.front();Q.pop_front();E-=t.E;V-=t.V;return t;}
inline node pop_back(){node t=Q.back();Q.pop_back();E-=t.E;V-=t.V;return t;}
inline void push_front(node t){E+=t.E;V+=t.V;Q.push_front(t);}
inline void push_back(node t){E+=t.E;V+=t.V;Q.push_back(t);}
inline void print(){printf("%.10lf\n",E/V);}

inline void extend(int te,int vo){
	double K=L-vo;
	while(V>K+eps){
		node t=pop_back();
		if(V<K)push_back(t.to(K-V));
	}
	node x=node((ll)te*vo,vo);
	while(Q.size()){
		node t=pop_front();
		if(t.T()<x.T()){push_front(t);break;}
		x=x+t;
	}
	push_front(x);
}

int main(){
	gi(n),gi(L);
	for(int i=1,x,y;i<=n;i++)gi(x),gi(y),extend(x,y),print();
	return 0;
}

Measured memory_bytes: 18708
#include <cmath>
#include <iostream>
#include <algorithm>
#pragma warning(disable : 4996)
using namespace std;
int N, D, Q, d[500009], p; long long l[500009], r[500009];
int main() {
	scanf("%d %d", &N, &D);
	for (int i = 0; i < N; i++) scanf("%d", &d[i]);
	l[0] = D;
	for (int i = 0; i < N; i++) l[i + 1] = min(l[i], abs(l[i] - d[i]));
	for (int i = N - 1; i >= 0; i--) {
		if (r[i + 1] < d[i] / 2) r[i] = r[i + 1];
		else r[i] = r[i + 1] + d[i];
	}
	scanf("%d", &Q);
	while (Q--) {
		scanf("%d", &p); p--;
		puts(l[p] > r[p + 1] ? "YES" : "NO");
	}
	return 0;
}

Measured memory_bytes: 11648
#include <bits/stdc++.h>
#define fore(x,a,b) for(int x=a, qwerty=b; x<qwerty; x++)
#define ALL(a) (a).begin(),(a).end()
#define SZ(a) ((int)(a).size())
#define pb push_back
#define FIN ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define fst first
#define snd second
using namespace std;
typedef long long ll;

const int N=3e5+5;
int n;
string s;
int leftW[N], rightE[N];

int main(){FIN;
	cin >> n >> s;
	fore(x,0,n){
		leftW[x]+=s[x]=='W';
		leftW[x+1]+=leftW[x];
	}
	for(int x=n-1; x>=0; x--)
		rightE[x]=rightE[x+1]+(s[x]=='E');
	int ans=n;
	fore(x,0,n){
		int tmp=(x?leftW[x-1]:0)+rightE[x+1];
		ans=min(ans,tmp);
	}
	cout << ans << "\n";
}

Measured memory_bytes: 2964
/*~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=
*$* WRITER:kakitamasziru/OxOmisosiru *$*
~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=*/
#ifdef LOCAL_JUDGE
#define _GLIBCXX_DEBUG //FOR THE DEBUG! COMMENT OUT THIS WHEN SUBMITTING!
#endif
/* I REALLY HOPE MY WISH REACH YOU , ATCODER'S ONLINE JUDGE */
#define WOULD
#define YOU
#define PLEASE
#define ACCEPT
#define MY
#define SUBMISSION
/* I REALLY HOPE MY WISH REACH YOU , ATCODER'S ONLINE JUDGE */
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <iomanip>
#include <limits>//setprecision
//#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <math.h>//pow,,,
#include <cmath>//abs,,,
#include <bitset> // bitset
//It is so troublesome that I include bits/stdc++.h !
using namespace std;

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
const long long INF = 100100100100;
const long long MOD = 998244353;
typedef pair<long long,long long> P;

//Solve N^M. This, mod_pow use Iterative Square Method.
long long mod_pow(long long N, long long M) {
    if (M == 0) return 1;
    long long res = mod_pow((N * N) % MOD, M / 2);
    //最下位ビット(*N)が1の時は単独でNをかける
    if (M & 1) res = (res * N) % MOD;

    return res %= MOD;
}

long long gcd(long long a, long long b) {
    if (b == 0) return a;
    else return gcd(b, a % b);
}
long long lcm(long long a, long long b) {
    return a * b / gcd(a, b);
}

int main() {
    string S,T;cin >> S >> T;
    int N = S.size();int M = T.size();
    vector<string> OUTPUT;
    if(N < M){
        cout << "UNRESTORABLE" << endl;
        return 0;
    }
    bool ok = true;
    string ans = S;
    for(int i = 0;i<N;i++){
        for(int j = 0;j<M;j++){
            if(i+j >= N){
                ok = false;
                break;
            }
            if(S.at(i+j) != T.at(j) && S.at(i+j) != '?') ok = false;
        }
        if(ok){
            for(int k = i;k<M+i;k++){
                ans.at(k) = T.at(k-i);
            }
            for(int l = 0;l<N;l++){
                if(ans.at(l) == '?') ans.at(l) = 'a';
            }
            OUTPUT.push_back(ans);
            ans = S;
        }
        ok = true;
    }
    if(OUTPUT.empty())cout << "UNRESTORABLE" << endl;
    else cout << OUTPUT.back() << endl;
}


Measured memory_bytes: 384
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);

        String c = sc.next();

        if(c.equals("a") || c.equals("i") || c.equals("u") || c.equals("e") || c.equals("o")){
            System.out.println("vowel");
        }
        else{
            System.out.println("consonant");
        }
    }
}

Measured memory_bytes: 22996
package main

import (
	"fmt"
)

func main() {
	var N int
	fmt.Scan(&N)
	a_lis := make([]int, N)
	for i := 0; i < N; i++ {
		var a int
		fmt.Scan(&a)
		a_lis[i] = a
	}

	cnt := make([]int, 1e6+5)
	for i := 0; i < N; i++ {
		x := a_lis[i]
		if cnt[x] != 0 {
			cnt[x] = 2
			continue
		}
		for j := x; j < len(cnt); j += x {
			cnt[j]++
		}
	}
	ans := 0
	for i := 0; i < N; i++ {
		if cnt[a_lis[i]] == 1 {
			ans++
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 14576
#include <iostream>

using namespace std;

int main(int argc, char *argv[])
{
	int N, D;

	cin >> N >> D;

	int t = 2 * D + 1;

	if (N % t == 0) {
		cout << N / t << endl;
	} else {
		cout << N / t + 1 << endl;
	}
	return 0;
}

Measured memory_bytes: 256
def resolve():
    n = int(input())
    li = [int(input()) for _ in range(n)]

    sorted_li = sorted(li)

    max_index = li.index(sorted_li[-1])

    for i in range(n):

        if i == max_index:
            print(sorted_li[-2])

        else:
            print(sorted_li[-1])

resolve()

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

// in-short-use macros

#define ll long long int
#define ld long double
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define mod 1000000007

//container-use 

typedef vector< ll > vl;
typedef vector< vl > vvl;
typedef pair< ll,ll > pll;
typedef vector<pair<ll,ll > > vpl;
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(typeof((c).begin() i = (c).begin(); i != (c).end(); i++)
#define present(c,x) ((c).find(x) != (c).end())
#define rep(i,a,b) for (int i = a; i <= b; i++)

//main function here

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    
    ll n,ans=(ll)(1e14);
    cin>>n;
    for(ll i=1;i*i<=n;i++)
    {
        if(n%i==0)
        {
            ans=min(ans,i+(n/i));
        }
    }
    cout<<ans-2<<"\n";
  return 0;
 }

Measured memory_bytes: 256
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
//using namespace __gnu_pbds;

#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define lb lower_bound
#define ub upper_bound

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
//template<class T> using oset=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
const ll mod=1000000007;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}

//head
int main()
{
	ios::sync_with_stdio(false);
  	cin.tie(0);
  	int k, s;
  	cin >> k >> s;
  	int total = 0;
  	for(int i = 0; i <= k; i++){
  		for(int j = 0; j <= k; j++){
  			int z = s - i - j;
  			if(z <= k && z >= 0){
  				total++;
  			}
  		}
  	}
  	cout << total << endl;
	return 0;
}


Measured memory_bytes: 256