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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int H,W,Q;
string LR,UD;
int SY,SX,TY,TX;

vector<int> CY[202020];
vector<int> CX[202020];
int LU[202020],LD[202020];
int RU[202020],RD[202020];
int UL[202020],UR[202020];
int DL[202020],DR[202020];

int revx[202020],revy[202020];
ll dist[10][10];

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>H>>W>>Q;
	cin>>LR>>UD;
	
	
	int U=W-1,D=W-1;
	for(i=W-1;i>=0;i--) {
		if(UD[i]=='N') U=i;
		if(UD[i]=='S') D=i;
		CX[i].push_back(U);
		CX[i].push_back(D);
		CX[i].push_back(i);
	}
	U=D=0;
	FOR(i,W) {
		if(UD[i]=='N') U=i;
		if(UD[i]=='S') D=i;
		CX[i].push_back(U);
		CX[i].push_back(D);
	}
	int L=0,R=0;
	FOR(i,H) {
		if(LR[i]=='W') L=i;
		if(LR[i]=='E') R=i;
		CY[i].push_back(L);
		CY[i].push_back(R);
		CY[i].push_back(i);
	}
	L=R=H-1;
	for(i=H-1;i>=0;i--) {
		if(LR[i]=='W') L=i;
		if(LR[i]=='E') R=i;
		CY[i].push_back(L);
		CY[i].push_back(R);
	}
	
	while(Q--) {
		cin>>SY>>SX>>TY>>TX;
		SY--;
		SX--;
		TY--;
		TX--;
		vector<int> Xs,Ys;
		FORR(y,CY[SY]) Ys.push_back(y);
		FORR(y,CY[TY]) Ys.push_back(y);
		FORR(x,CX[SX]) Xs.push_back(x);
		FORR(x,CX[TX]) Xs.push_back(x);
		
		sort(ALL(Xs));
		sort(ALL(Ys));
		Xs.erase(unique(ALL(Xs)),Xs.end());
		Ys.erase(unique(ALL(Ys)),Ys.end());
		
		FOR(i,Xs.size()) revx[Xs[i]]=i;
		FOR(i,Ys.size()) revy[Ys[i]]=i;
		FOR(y,Ys.size()) FOR(x,Xs.size()) dist[y][x]=1LL<<60;
		priority_queue<pair<ll,int>> PQ;
		
		dist[revy[SY]][revx[SX]]=0;
		PQ.push({0,revy[SY]*10+revx[SX]});
		
		while(PQ.size()) {
			ll co=-PQ.top().first;
			int cy=PQ.top().second/10;
			int cx=PQ.top().second%10;
			PQ.pop();
			if(dist[cy][cx]!=co) continue;
			
			if(LR[Ys[cy]]=='W' && cx) {
				ll nc=co+abs(Xs[cx]-Xs[cx-1]);
				if(nc<dist[cy][cx-1]) {
					dist[cy][cx-1]=nc;
					PQ.push({-nc,(cy)*10+cx-1});
				}
			}
			if(LR[Ys[cy]]=='E' && cx<Xs.size()-1) {
				ll nc=co+abs(Xs[cx]-Xs[cx+1]);
				if(nc<dist[cy][cx+1]) {
					dist[cy][cx+1]=nc;
					PQ.push({-nc,(cy)*10+cx+1});
				}
			}
			if(UD[Xs[cx]]=='N' && cy) {
				ll nc=co+abs(Ys[cy]-Ys[cy-1]);
				if(nc<dist[cy-1][cx]) {
					dist[cy-1][cx]=nc;
					PQ.push({-nc,(cy-1)*10+cx});
				}
			}
			if(UD[Xs[cx]]=='S' && cy<Ys.size()-1) {
				ll nc=co+abs(Ys[cy]-Ys[cy+1]);
				if(nc<dist[cy+1][cx]) {
					dist[cy+1][cx]=nc;
					PQ.push({-nc,(cy+1)*10+cx});
				}
			}
		}
		if(dist[revy[TY]][revx[TX]]==1LL<<60) {
			dist[revy[TY]][revx[TX]]=-1;
		}
		cout<<dist[revy[TY]][revx[TX]]<<endl;
		
	}
	
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 25040
#include<bits/stdc++.h>
using namespace std;
int main() 
{
    long long int n,m1;
    cin>>n>>m1;
    long long int arr[n+1];
    for(long long int i=1;i<=n;i++)
    {
        cin>>arr[i];
    }
    map<long long int,list<long long int> >m;
    while(m1--)
    {
        long long int temp1,temp2;
        cin>>temp1>>temp2;
        m[temp1].push_back(temp2);
        m[temp2].push_back(temp1);
    }
    long long int ans=0;
    for(auto x:m)
    {
        long long int maxi=0;
        for(auto a:x.second)
        {
            maxi=max(maxi,arr[a]);
        }
        if(arr[x.first]>maxi)
        {
            ans++;
        }
    }

    for(long long int i=1;i<=n;i++)
    {
        if(m.count(i)==0)
        {
            ans++;
        }
    }
    cout<<ans;

    return 0;
}


Measured memory_bytes: 18572
import java.util.*;

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

        int N = sc.nextInt();
        int[] A = new int[N+1];

        for (int i = 0; i < N - 1; i++) {
            A[sc.nextInt()]++;
        }

        for (int i = 1; i <= N; i++) {
            System.out.println(A[i]);
        }

    }
}


Measured memory_bytes: 61652
import java.util.Scanner;

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

		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();

		if (n / 10 == 9 || n % 10 == 9) {
			System.out.print("Yes");
		} else {
			System.out.print("No");
		}
	}
}

Measured memory_bytes: 21972
#include <iostream>

int main() {
    char s[200]={},p[100]={};
    std::cin >> s;
    std::cin >> p;
    int i = 0;
    int k = 0;

    for(; s[i] != 0; i++) {}
    for(; p[k] != 0; k++) {}
    for(int j = i; j < 2 * i; j++) {
        s[j] = s[j-i];
    }
    bool flag;
    for(int j = 0; j < i; j++) {
        flag = true;
        for(int t = 0; t < k; t++) {
            if(s[j+t] != p[t]) flag = false;
        }
        if(flag == true) {
            std::cout << "Yes" << std::endl;
            return 0;
        }
    }
    std::cout << "No" << std::endl;
}


Measured memory_bytes: 3108
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N=1300005,M=924844033;
int ne[N],tot,fi[N],zz[N],size[N],a[N],b[N],fac[N],inv[N],n,m,x,y;
void jb(int x,int y){
	ne[++tot]=fi[x];
	fi[x]=tot;
	zz[tot]=y;
}
void dfs(int x,int y){
	size[x]=1;
	for (int i=fi[x];i;i=ne[i])
		if (zz[i]!=y)dfs(zz[i],x),size[x]+=size[zz[i]];
}
int ksm(int x,int y){
	int ans=1;
	for (;y;y>>=1,x=x*x%M)
		if (y&1)(ans*=x)%=M;
	return ans;	
}
int C(int x,int y){
	if (x<y)return 0;
	return fac[x]*inv[y]%M*inv[x-y]%M;
}
void init(int y[],int len){
	for (int i=1,j=len/2;i<len-1;i++){
		if (i<j)swap(y[i],y[j]);
		int k=len/2;
		while (j>=k){
			j-=k;
			k/=2;
		}
		j+=k;
	}
}
void ntt(int y[],int len,int opt){
	init(y,len);
	for (int h=2;h<=len;h<<=1){
		int wn=ksm(5,(M-1)/h);
		if (opt==-1)wn=ksm(wn,M-2);
		for (int j=0;j<len;j+=h){
			int w=1;
			for (int k=j;k<j+h/2;k++){
				int u=y[k],v=w*y[k+h/2]%M;
				y[k]=(u+v)%M;
				y[k+h/2]=(u-v+M)%M;
				w=w*wn%M;
			}
		}
	}
	if (opt==1)return;
	int temp=ksm(len,M-2);
	for (int i=0;i<len;i++)(y[i]*=temp)%=M;
}
signed main(){
	scanf("%lld",&n);
	fac[0]=inv[0]=1;
	for (int i=1;i<N;i++)fac[i]=fac[i-1]*i%M,inv[i]=ksm(fac[i],M-2);
	for (int i=1;i<n;i++){
		scanf("%lld%lld",&x,&y);
		jb(x,y);jb(y,x);
	}
	dfs(1,0);
	for (int i=0;i<=n;i++)b[i]=inv[i];
	for (int i=2;i<=n;i++)a[size[i]]++,a[n-size[i]]++;
	for (int i=0;i<=n;i++)(a[i]*=fac[i])%=M;
	reverse(a,a+n+1);
	int len=1;
	while (len<n*2+5)len*=2;
	ntt(a,len,1);ntt(b,len,1);
	for (int i=0;i<len;i++)(a[i]*=b[i])%=M;
	ntt(a,len,-1);
	for (int i=n+1;i<len;i++)a[i]=0;
	reverse(a,a+n+1);
	for (int i=1;i<=n;i++)printf("%lld\n",(n*C(n,i)-a[i]*inv[i]%M+M)%M);
	return 0;
}

Measured memory_bytes: 58624
#include "bits/stdc++.h"
#include<random>
using namespace std;
typedef long long int lint;
typedef pair<lint, lint> plint;
typedef pair<double long, double long> pld;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for(lint i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(lint i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
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<typename T1, typename T2> pair<T1, T2> operator+(const pair<T1, T2>& l, const pair<T1, T2>& r) { return make_pair(l.first + r.first, l.second + r.second); }
template<typename T1, typename T2> pair<T1, T2> operator-(const pair<T1, T2>& l, const pair<T1, T2>& r) { return make_pair(l.first - r.first, l.second - r.second); }
const lint MOD = 1e9 + 7, INF = 1e18;


template <std::int_fast64_t Modulus>
class modint
{
	using u64 = std::int_fast64_t;

public:
	u64 a;
	constexpr modint(const u64 x = 0) noexcept : a(x% Modulus) {}
	constexpr u64& value() noexcept { return a; }
	constexpr const u64& value() const noexcept { return a; }
	constexpr modint operator+(const modint rhs) const noexcept
	{
		return modint(*this) += rhs;
	}
	constexpr modint operator-(const modint rhs) const noexcept
	{
		return modint(*this) -= rhs;
	}
	constexpr modint operator*(const modint rhs) const noexcept
	{
		return modint(*this) *= rhs;
	}
	constexpr modint operator/(const modint rhs) const noexcept
	{
		return modint(*this) /= rhs;
	}
	constexpr modint& operator+=(const modint rhs) noexcept
	{
		a += rhs.a;
		if (a >= Modulus)
		{
			a -= Modulus;
		}
		return *this;
	}
	constexpr modint& operator-=(const modint rhs) noexcept
	{
		if (a < rhs.a)
		{
			a += Modulus;
		}
		a -= rhs.a;
		return *this;
	}
	constexpr modint& operator*=(const modint rhs) noexcept
	{
		a = a * rhs.a % Modulus;
		return *this;
	}
	constexpr modint& operator/=(modint rhs) noexcept
	{
		u64 exp = Modulus - 2;
		while (exp)
		{
			if (exp % 2)
			{
				*this *= rhs;
			}
			rhs *= rhs;
			exp /= 2;
		}
		return *this;
	}
};
typedef modint<MOD> ModInt;

ModInt mod_pow(ModInt x, ModInt n) {
	ModInt ret = 1;
	while (n.a > 0) {
		if (n.a & 1) (ret *= x);
		(x *= x);
		n.a >>= 1;
	}
	return ret;
}

ModInt func[200000];
void funcinit(int N)
{
	func[0] = 1;
	for (int i = 1; i <= N; i++)
	{
		func[i] = func[i - 1] * i;
	}
}
ModInt comb(ModInt n, ModInt r)
{
	if (n.a <= 0 || n.a < r.a)
	{
		return 0;
	}
	return func[n.a] / (func[r.a] * func[(n - r).a]);
}

lint N;
int main() {
	cin >> N;
	funcinit(100001);
	cout << func[N].a << endl;
}


Measured memory_bytes: 4320
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<string>
#include<cstring>
#include<algorithm>
#include<sstream>
#include<complex>
#include<functional>
#include<vector>
#include<map>
#include<queue>
#include<deque>
#include<stack>
#include<set>

using namespace std;
#define endl '\n'
#define eb emplace_back
#define fst first
#define scd second
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define YES(n) cout << ((n) ? "YES" : "NO" ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No" ) << endl

constexpr int MOD = 1000000007;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vector<int>> vii;
typedef vector<ll> vl;

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

// value
int A, B, C;

void solve() {
	
	cin >> A >> B >> C;

	cout << B + min(C, A + B + 1) << endl;

	return;

}

int main() {

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

	solve();

	return 0;

}

Measured memory_bytes: 256
# coding: utf-8
class UnionFind
  def initialize(n)
    @Parent = Array.new(n, -1)
  end

  def root(a)
    if @Parent[a] < 0 then
      a
    else
      @Parent[a] = root(@Parent[a])
    end
  end

  def size(a)
    -@Parent[root(a)]
  end

  def connect(a, b)
    a = root(a)
    b = root(b)
    if a == b then
      return false
    end

    if a < b then
      a, b = b, a
    end

    @Parent[a] += @Parent[b]
    @Parent[b] = a

    return true
  end
end

n, m = STDIN.gets.chomp.split(" ").map(&:to_i)
a = Array.new(0)
b = Array.new(0)

for i in 1..m
  tmpa, tmpb = STDIN.gets.chomp.split(" ").map(&:to_i)
  a.push(tmpa)
  b.push(tmpb)
end

uni = UnionFind.new(n)

ans = Array.new(m)
ans[m - 1] = n * (n - 1) / 2

(1..(m-1)).reverse_each do |i| 
  tmpa, tmpb = a[i] - 1, b[i] - 1
  if uni.root(tmpa) != uni.root(tmpb) then
    ans[i-1] = ans[i] - uni.size(tmpa) * uni.size(tmpb)
  else
    ans[i-1] = ans[i]
  end
  uni.connect(tmpa, tmpb)
end

for i in 0..(m-1)
  puts ans[i]
end


Measured memory_bytes: 6880
"""
s=1817181712114 なら
4
10
100
2000
10000
700000
1000000
80000000
100000000
7000000000
10000000000
800000000000
1000000000000
の数列とみて, 各々%2019を取ってzero sum range
"""
from collections import Counter
def make_modlist(Len,mod):
    modlist=[0]*Len
    modlist[0]=1
    for i in range(1,Len):
        modlist[i]=10*modlist[i-1]%mod
    return modlist
a=list(map(int,input()))
a.reverse()
n=len(a)
d=make_modlist(n,2019)
b=[0]*(n+1)
for i in range(n):
    b[i+1]=a[i]*d[i]%2019
for i in range(1,n+1):
    b[i]+=b[i-1]
    b[i]%=2019
ans=0
for i in Counter(b).values():
    ans+=i*(i-1)//2
print(ans)

Measured memory_bytes: 25440
import sys
import itertools
# import numpy as np
import time
import math
import heapq
from collections import defaultdict
sys.setrecursionlimit(10 ** 7)
 
INF = 10 ** 18
MOD = 10 ** 9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

# map(int, input().split())

S = input()

i = 1
count = 1
while i < len(S):
    if S[i] != S[i - 1]:
        count += 1
    i += 1
print(count - 1)


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

using namespace std;

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

  vector<int> v;
  for (int i = 0; i < 3; ++i) {
    int x;
    cin >> x;
    v.emplace_back(x);
  }

  sort(begin(v), end(v));

  if (v[0] == 5 && v[1] == 5 && v[2] == 7) cout << "YES" << "\n";
  else cout << "NO" << "\n";
}


Measured memory_bytes: 3588
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args)throws Exception {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		String s=br.readLine();
		String t=br.readLine();
		
		System.out.println(solve(s,t));

	}

	private static int solve(String s, String t) {
		int[][] dp=new int[t.length()+1][s.length()+1];
		
		for(int i=1;i<=t.length();i++) {
			for(int j=0;j<=s.length();j++) {
				if(j==0) {
					dp[i][j]=dp[i-1][j]+1;
				}
				else {
					if(i>j) dp[i][j]=Integer.MAX_VALUE;
					else {
						dp[i][j]=t.charAt(i-1)==s.charAt(j-1)?dp[i-1][j-1]:dp[i-1][j-1]+1;
					}
				}
			}
		}
		int ans=Integer.MAX_VALUE;
		for(int val:dp[t.length()]) {
			ans=Math.min(ans, val);
		}
		return ans;
	}

}


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

void Read(int &val) {
    val = 0; char c;
    do { c = getchar(); } while (!isdigit(c));
    while (isdigit(c)) { val = val * 10 + c - '0'; c = getchar(); }
}

const int N = 2e5 + 4;
int n, a[N], res, F[N];

void sol() {
    for (int i = 1; i <= n; ++i) {
        F[a[i]] = F[a[i]-1] + 1;
        res = max(res, F[a[i]]);
    }
    cout << n - res;
}

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

    Read(n);
    for (int i = 1; i <= n; ++i) Read(a[i]);

    sol();

    return 0;
}


Measured memory_bytes: 1792
N=io.read"*n"
io.read()
S={}
for i=1,N do table.insert(S,io.read())end

local lr={}

for i,s in ipairs(S)do
	local n
	repeat
		s,n=s:gsub("%(%)","")
	until(n==0)
	local l,r=s:match("%)*()%(*()")
	r=r-l
	l=l-1
	if(l~=0 or r~=0)then table.insert(lr,{l,r})end
end

if(#lr==0)then print"Yes"return end

do
local s=0
for _,v in ipairs(lr)do
	s=s+v[1]-v[2]
end
if(s~=0)then print"No"return end
end

local bl,br=-1,-1
for i,v in ipairs(lr)do
	if(v[1]==0)then bl=i end
	if(v[2]==0)then br=i end
end
if(bl==-1 or br==-1)then print"No"return end

local s=lr[bl][2]
table.remove(lr,math.max(bl,br))
table.remove(lr,math.min(bl,br))
table.sort(lr,function(a,b)return a[1]-a[2]<b[1]-b[2]end)

for i,v in ipairs(lr)do
	s=s-v[1]
	if(s<0)then print"No"return end
	s=s+v[2]
end

print"Yes"

Measured memory_bytes: 81516
#include <iostream>
#include <math.h>
#include <algorithm>
#include <functional>
#include <vector>
#include <typeinfo>
#include <climits>
using namespace std;
#define INIT cin.tie(0); ios::sync_with_stdio(false);
#define FOR(i, a, n) for (int i = a; i < n; i++)
#define REP(i, n) for(int i = 0; i < n; i++)

int main()
{
    INIT;

    string a, b, c;
    cin >> a >> b >> c;

    if(a[a.size() - 1] == b[0] and b[b.size() - 1] == c[0]){
        cout << "YES" << endl;
    }else cout << "NO" << endl;


    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define forinc(i,a,b) for(int i=a;i<=b;++i)
#define fordec(i,a,b) for(int i=a;i>=b;--i)
#define forv(i,x) for(auto &i:x)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int rnd(int l,int r)
{
    return l+rng()%(r-l+1);
}
#define in ({int x=0;int c=getchar(),n=0;for(;!isdigit(c);c=getchar()) n=(c=='-');for(;isdigit(c);c=getchar()) x=x*10+c-'0';n?-x:x;})
#define pii pair<int,int>
#define fi first
#define se second
#define batbit(i,x) (x|(1ll<<i))
#define getbit(i,x) ((x>>i)&1)

const int mn=1e5+100;
int n,cnt,id[3*mn],kq;
struct oo
{
    int u,v,c;
};
oo e[3*mn],a[mn];

bool dk(oo a,oo b)
{
    if(a.v!=b.v) return a.v<b.v;
    return a.u<b.u;
}

bool dk1(oo a,oo b)
{
    if(a.u!=b.u) return a.u<b.u;
    return a.v<b.v;
}

bool cmp(oo a,oo b)
{
    return a.c<b.c;
}

int root(int u)
{
    return id[u]<0?u:id[u]=root(id[u]);
}

void join(int u,int v)
{
    u=root(u),v=root(v);
    if(id[u]>id[v]) swap(u,v);
    id[u]+=id[v];
    id[v]=u;
}

main()
{
    memset(id,-1,sizeof id);
    cin >> n;
    forinc(i,1,n) cin >> a[i].u >> a[i].v,a[i].c=i;
    sort(a+1,a+n+1,dk1);
    forinc(i,1,n-1)
    {
        e[++cnt]={a[i].c,a[i+1].c,min(abs(a[i].u-a[i+1].u),abs(a[i].v-a[i+1].v))};
    }
    sort(a+1,a+n+1,dk);
    forinc(i,1,n-1)
    {
        e[++cnt]={a[i].c,a[i+1].c,min(abs(a[i].u-a[i+1].u),abs(a[i].v-a[i+1].v))};
    }
    sort(e+1,e+cnt+1,cmp);
    forinc(i,1,cnt)
    {
        int u=e[i].u,v=e[i].v,c=e[i].c;
        if(root(u)!=root(v))
        {
            join(u,v);
            kq+=c;
        }
    }
    cout << kq;
}


Measured memory_bytes: 12032
#include <bits/stdc++.h>
 
#define pb push_back
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define ll long long
#define ii pair<int,int>
#define vi vector<int>
#define vll vector<ll>
#define vii vector<ii>
 
using namespace std;

void solve(){

	return;
}
 
int32_t main(){

	int n=0,k;
	string s;

	cin >> k >> s;
	for(int i=2;i<s.size();i++){
		if(s[i]=='C' and s[i-1]=='B' and s[i-2]=='A') n++;
	}

	cout << n << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep2(i, a, n) for(ll i = a; i < (ll)(n); i++)
#define memi cout << endl
#define kono(n) cout << fixed << setprecision(n)
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define hina cout << ' '
#define in(n) cin >> n
#define in2(n, m) cin >> n >> m
#define in3(n, m, l) cin >> n >> m >> l
#define out(n) cout << n
const ll mei = (ll)1e9 + 7;

int main(){
  ll n, m, a;
  in2(n, m);
  vector<ll> s(n), x;
  vector<pair<ll, ll>> c(m);
  rep(i, n)
    in(s[i]);
  rep(i, m)
    in2(c[i].second, c[i].first);
  sort(all(s));
  sort(all(c));
  reverse(all(c));
  a = 0;
  ll i = 0;
  ll j = n - 1;
  while(a < n){
    while(s[j] >= c[i].first || i >= m){
      x.pb(s[j]);
      s.pop_back();
      a++;
      j--;
      if(a >= n)
        break;
    }
    rep(k, c[i].second){
      x.pb(c[i].first);
      a++;
    }
    i++;
  }
  sort(all(x));
  reverse(all(x));
  a = 0;
  rep(k, n){
    a += x[k];
  }
  out(a);
  memi;
}

Measured memory_bytes: 4724
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<numeric>
using namespace std;
int main(){
 int i,j,k,n,ans=0,a;
  scanf("%d",&n);
  for(i=1;i<=n;i++){
   for(j=1;j<=n;j++){
     for(k=1;k<=n;k++){
       a=gcd(i,j);
       ans+=gcd(a,k);
     }
   }
  }
  printf("%d",ans);
  
  return 0;
}


Measured memory_bytes: 3828
R=range
N,M,*S=open(0).read().split()
N=int(N)+1
M=int(M)-1
l=lambda:[[0]*N for _ in R(N)]
C=l()
D=l()
r=0
for t in R(M):
	for i in R(1,N):
		for j in R(1,N):u=C[i][j]=C[i-1][j-1]+(S[i-1][t]==S[j-1][t+1]);D[i][j]=min(D[i-1][j],D[i][j-1])+u
	r+=D[N-1][N-1]
print(r)

Measured memory_bytes: 46444
#include "bits/stdc++.h"
// Begin Header {{{
#define all(x)          (x).begin(), (x).end()
#define rep(i, n)       for (i64 i = 0, i##_limit = (n); i < i##_limit; ++i)
#define reps(i, s, t)   for (i64 i = (s), i##_limit = (t); i <= i##_limit; ++i)
#define repr(i, s, t)   for (i64 i = (s), i##_limit = (t); i >= i##_limit; --i)
#ifndef DBG
#define trace(...)
#endif
using namespace std;
using i64 = int_fast64_t;
using pii = pair<i64, i64>;
template <class T, class U> inline bool chmax(T &a, const U &b) { return b > a && (a = b, true); }
template <class T, class U> inline bool chmin(T &a, const U &b) { return b < a && (a = b, true); }
constexpr int INF  = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;

template <class T>
inline vector<T> make_v(const T &initValue, size_t sz) {
    return vector<T>(sz, initValue);
}

template <class T, class... Args>
inline auto make_v(const T &initValue, size_t sz, Args... args) {
    return vector<decltype(make_v<T>(initValue, args...))>(sz, make_v<T>(initValue, args...));
}

inline void read() {}

template <class Head, class... Tail>
inline void read(Head &head, Tail&... tail) { cin >> head; read(tail...); }

inline void print() { cout << "\n"; }

template <class Head, class... Tail>
inline void print(Head &&head, Tail&&... tail) {
    cout << head;
    if (sizeof...(tail)) cout << ' ';
    print(forward<Tail>(tail)...);
}

template <class T>
inline ostream& operator<< (ostream &out, const vector<T> &vec) {
    static constexpr const char *delim[] = { " ", "" };
    for (const auto &e : vec) out << e << delim[&e == &vec.back()];
    return out;
}
// }}} End Header

signed main() {
    ios_base::sync_with_stdio(false); cin.tie(nullptr);

    i64 N, K;
    read(N, K);

    vector<i64> A(N), F(N);
    rep(i, N) read(A[i]);
    rep(i, N) read(F[i]);

    sort(all(A));
    sort(all(F), greater<>());

    const auto isAble = [&](i64 limit) {
        multiset<i64> S(all(A));
        i64 cnt = 0;
        for (i64 f : F) {
            auto itr = S.upper_bound(limit / f);
            if (itr != S.begin()) --itr;
            cnt += max<i64>(0, *itr - (limit / f));
            S.erase(itr);
        }
        return cnt <= K;
    };

    i64 notAble = -1;
    i64 able = LINF;
    while (able - notAble > 1) {
        const i64 mid = (notAble + able) / 2;
        if (isAble(mid)) able = mid;
        else notAble = mid;
    }

    print(able);
    return 0;
}


Measured memory_bytes: 14848
#include <stdio.h>

int main() {
    int a,b;
    char ass[100];
    scanf("%d%d",&a,&b);
    scanf("%s",ass);
    if(ass[b-1]=='A'){
      ass[b-1]='a';
    }    
    if (ass[b-1]=='B'){ 
      ass[b-1]='b';
    }     
    if (ass[b-1]=='C'){ 
      ass[b-1]='c';
    }
    printf("%s\n",ass);
  return 0;
}

Measured memory_bytes: 2092
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,n) for(int i=(a); i<(n); i++)
#define all(v) v.begin(), v.end()
#define fi first
#define se second
#define sz(x) int(x.size())
using namespace std;
using ll = long long;
using P = pair<int ,int>;
const int INF = 1001001001;
const int MOD = 1000000007;
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 (b<a) {a=b; return 1;} return 0;}

#ifdef _DEBUG
#include "debug.h"
#else
#define debug(...)
#define print(...)
#endif

vector<vector<P>> G;
vector<ll> loc;
vector<bool> seen;
bool dfs(int v) {
    if (loc[v]==INF) loc[v] = 0;
    seen[v] = true;
    for(const auto& p: G[v]) {
        int nv = p.fi; ll tmp = loc[v]+p.se;
        debug(seen[nv], v, nv, tmp);
        if (seen[nv] && loc[nv]!=tmp) return false;
        if (!seen[nv]) {
            loc[nv] = tmp;
            dfs(nv);
        }
    }
    return true;
}

int main() {
    int n, m; cin >> n >> m;
    G.resize(n);
    rep(i, m) {
        int u, v, cost; cin >> u >> v >> cost;
        u--; v--;
        G[u].emplace_back(v, cost);
        G[v].emplace_back(u, -cost);
    }
    loc.assign(n, INF);
    seen.assign(n, false);
    rep(i, n) {
        if (seen[i]) continue;
        if (!dfs(i)) {
            cout << "No" << endl;
            return 0;
        }
        debug(seen);
        debug(loc);
    }
    rep(i, n) {
        for(const auto& p: G[i]) {
            if (loc[p.fi]!=loc[i]+p.se) {
                cout << "No" << endl;
                return 0;
            }
        }
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 12416
import java.util.*;
public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    String b = sc.next();
    if (b.equals("A")) {
      System.out.println("T");
    } else if  (b.equals("T")) {
      System.out.println("A");
    } else if  (b.equals("C")) {
      System.out.println("G");
    } else {
      System.out.println("C");
    }
  }
}

Measured memory_bytes: 22484
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <iterator>
#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 MOD 1000000007
using namespace std;

long n, m;
long ee[100][100];
long flag[100];

void dfs( long curr, long& val )
{
    if(flag[curr]) return;
    flag[curr]=1;

    val ++;
    long i;
    for(i=0; i<n; i++) {
        if(ee[curr][i]) dfs( i, val );
    }

    return;
}

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

    long a[100]={0};
    long b[100]={0};

    long i, j;
    for(i=0; i<m; i++) {
        scanf("%ld%ld", &a[i], &b[i]);
    }

    long count=0;
    long k;
    for(k=0; k<m; k++) {
        for(j=0; j<n; j++) flag[j]=0;
        for(j=0; j<n; j++) for(i=0; i<n; i++) ee[j][i]=0; 

        for(j=0; j<m; j++) {
            if(j==k) continue;
            ee[a[j]-1][b[j]-1]=1;
            ee[b[j]-1][a[j]-1]=1;
        }

        long val = 0;
        dfs( 0, val );
        if(val<n) count++;
    }

    printf("%ld\n", count);

  
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <queue>
#include <stack>

using namespace std;

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

const ll mod = 1000000007;

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

  int n;
  cin >> n;
  vector<ll> a(n);
  for (auto &x: a) cin >> x;

  if (n % 2 == 0) {
    ll now = 0;
    for (int i = 0; i < n; i += 2) now += a[i];
    ll maximum = now;
    for (int i = n-2; i >= 0; i -= 2) {
      now += (a[i+1] - a[i]);
      maximum = max(maximum, now);
    }

    cout << maximum << endl;
  }
  else {
    vector<vector<ll> > dp(n+2, vector<ll>(3, (ll) -1e18));
    dp[0][0] = a[0];
    dp[1][1] = a[1];
    dp[2][2] = a[2];
    for (int i = 0; i < n; i++) {
      if (i+2 < n) dp[i+2][0] = max(dp[i+2][0], dp[i][0] + a[i+2]);
      if (i+2 < n) dp[i+2][1] = max(dp[i+2][1], dp[i][1] + a[i+2]);
      if (i+2 < n) dp[i+2][2] = max(dp[i+2][2], dp[i][2] + a[i+2]);
      if (i+3 < n) dp[i+3][1] = max(dp[i+3][1], dp[i][0] + a[i+3]);
      if (i+3 < n) dp[i+3][2] = max(dp[i+3][2], dp[i][1] + a[i+3]);
      if (i+4 < n) dp[i+4][2] = max(dp[i+4][2], dp[i][0] + a[i+4]);
    }

    cout << max(max(dp[n-3][0], dp[n-2][1]), dp[n-1][2]) << endl;
  }

  return 0;
}


Measured memory_bytes: 15584
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#define MOD 1000000007
typedef long long ll;
using namespace std;

int N;
vector<ll> L,R;

int main(){
  cin>>N;
  for(int i=0;i<N;i++){
      int l,r;
      cin>>l>>r;
      L.push_back(l);
      R.push_back(r);
  }
  L.push_back(0ll);
  R.push_back(0ll);
  sort(L.begin(),L.end());
  reverse(L.begin(),L.end());
  sort(R.begin(),R.end());
  ll ans=0;
  for(int i=0;i<N;i++){
      ans+=max(L[i]-R[i],0ll)*2;
  }
  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 2036
#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;

int main(){
  int n;cin>>n;
  vector<ll> a(n+1),limit(n);
  rep(i, n+1)cin>>a[i];

  if(n==0){
    if(a[0]==1)cout<<1<<endl;
    else cout<<-1<<endl;
    return 0;
  }

  limit[n-1]=a[n]+a[n-1];
  rrep(i, n-1){
    limit[i] = limit[i+1]+a[i];
  }
  limit.push_back(a.back());

  ll result = 1;
  ll l=1;

  if(a[0]==1 && n>0) { cout<<-1<<endl; return 0; }

  rep(i, n){
    ll c=a[i];

    ll nl = min<ll>((l-c)*2, limit[i+1]);
    if(l-c<0) { cout<<-1<<endl; return 0;}
//    if(l-c<0 || nl-a[i+1]<0) { cout<<-1<<endl; return 0;}
//    if(l==0 && a[i]>0) { cout<<-1<<endl; return 0;}

    if(i<n-1)result += nl;
    swap(l, nl);
  }

  if(l!=a.back()) { cout<<-1<<endl; return 0;}

  cout<<result+a.back()<<endl;

  return 0;
}


Measured memory_bytes: 5648
#include <stdio.h>

int main() {
	
	int n, a, b;
	int total = 0;
	scanf("%d %d %d", &n, &a, &b);

	for (int i=1; i<=n; i++){
		int temp = i;
		int sum = 0;
		
		while (temp != 0){
			sum += (temp % 10);
			temp /= 10;
		}
		if (sum >= a && sum <= b){
			total += i;
		}
	}
	printf ("%d", total);
	
	return 0;
}


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

int main(){
	long n;
	string sign;
	getline(cin, sign,'\n');
	n = sign.length();
	
	long data[n+1];
	
	for(long i=0;i<=n;i++){
		data[i]=0;
	}
	
	long val = 1;
	for(long i=0;i<n;i++){
		if(sign[i]=='<'){
			data[i+1] = val;
			val++;
		}else{
			data[i+1] = 0;
			val = 1;
		}
	}
	val = 1;
	for(long i=n-1;i>=0;i--){
		if(sign[i]=='>'){
			data[i] = (data[i]<val)?val:data[i];
			val++;
		}else{
			val = 1;
		}
	}
	long sum = 0;
	for(long i=0;i<=n;i++){
		sum+=data[i];
	}
	cout << sum << "\n";
}


Measured memory_bytes: 7712
n = int(input())
A = list(map(int,input().split()))

total = abs(A[0]) + abs(A[n-1])

for i in range(n-1):
    total += abs(A[1+i] - A[i])
    
for i in range(n):
    if i == 0:
        ans = total - abs(A[1]-A[0]) - abs(A[0]) + abs(A[1])
        
    elif i == n-1:
        ans = total - abs(A[i]-A[i-1]) - abs(A[i]) + abs(A[i-1])
        
    else:
        ans = total - abs(A[i]-A[i-1]) - abs(A[i+1]-A[i]) + abs(A[i+1]-A[i-1])
        
    print(ans)

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




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

    int N;
    cin>>N;
    int streak = 0;
    for(int c=0;c<N;c++) {
        int a,b;
        cin>>a>>b;
        if(a==b) {
            streak++;
        } else streak = 0;
        if(streak >= 3) {
            cout<<"Yes";
            return 0;
        }
    }
    cout<<"No";
}


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

int main(){

	long long int N,i;

	cin>>N;

	long long int A[N];

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

	sort(A,A+N);

	cout<<A[N-1] - A[0];

	return 0;
}

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

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

    // vector<int> num(N, 0);
    // iota(num.begin(), num.end(), 1);

    // int ma = 0;
    // vector<int> ansv;
    // do {
    //
    //     int ans = 0;
    //     rep(i, N) {
    //         //cout << i+1 << ", " << num[i] << " := " << (i+1)%num[i] << endl;
    //         ans += (i+1)%num[i];
    //     }
    //     if (ma < ans) {
    //         ma = ans;
    //         ansv = num;
    //     }
    //     //cout << "ans: " << ans << endl;
    //     //cout << endl;
    //
    // } while (next_permutation(num.begin(), num.end()));
    //
    // cout << ma << endl;
    // rep(i, N) cout << i+1 << ", " << ansv[i] << ":= " << (i+1)%ansv[i] << endl;

    // 奇数の場合
    ll ans = 0;
    if (N%2) {
        ans += (2LL + N-1) * (N-2) / 2;
        ans++;
    }
    else {
        ans += (1 + N-1) * (N-1) / 2;
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cmath>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <numeric>
#include <random>
#include <algorithm>
#include <functional>

using namespace std;
typedef long long ll;

const int INF = (1 << 30) - 1;
const ll INFLL= (1LL << 61) - 1;
const int MOD = 1000000007;
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)


const double PI=3.14159265358979323846;

int main(){
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int a,b,x;
  cin>>a>>b>>x;
  double aa=a;
  double bb=b;
  double xx=x;
  if(2*x<=a*a*b){
    cout<<setprecision(12)<<90-atan(2.0*xx/aa/bb/bb)*180/PI<<endl;
  }else{
    double l=2.0*bb-2.0*xx/aa/aa;
    cout<<setprecision(12)<<atan(l/aa)*180/PI<<endl;
  }
}


Measured memory_bytes: 384
#include <iostream>
#include <vector>
using namespace std;
using ll = long long;

int N, W;
vector<ll> w, v;
vector<vector<ll>> dp;

ll knapsack(int ith, int weight) {
  if (dp[ith][weight] != 0) return dp[ith][weight];
  if (ith == N) return dp[ith][weight];
  if (weight + w[ith] > W) {
    dp[ith][weight] = knapsack(ith + 1, weight);
    return dp[ith][weight];
  } else {
    dp[ith][weight] = max(knapsack(ith + 1, weight + w[ith]) + v[ith],
                          knapsack(ith + 1, weight));
    return dp[ith][weight];
  }
}

int main() {
  cin >> N >> W;
  w.assign(N, 0);
  v.assign(N, 0);
  for (int i = 0; i < N; ++i) {
    cin >> w[i] >> v[i];
  }
  dp.assign(101, vector<ll>(100001, 0));
  ll ans = knapsack(0, 0);
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 80256
n, m=map(int, input().split())
l1 = [[] for _ in range(n)]
mn=1
ma=n
for i in range(1, m+1):
  l, r=map(int, input().split())
  mn=max(mn, l)
  ma=min(ma, r)
  if ma<mn:
    print(0)
    exit()
print(ma-mn+1)
  
  
 

Measured memory_bytes: 16168
#include<iostream>
using namespace std;
int main(){
  int A,B,C,D;
  int E,F;
  cin >> A >> B >> C >> D >> E >> F ;
  int max_water = F/(A*100),max_sugar;
  double conq,max_conq;
  double water,sugar;
  int w_result=100*A;
  int s_result=0;
  // 水を入れる回数はFで決まる
  // 水の量が決まると入れられる砂糖の最大値が決まる
  // 際限なく入れられる場合と、最大重量で律速する場合とある
  // 律速を始めたらもうやめるっていうのがあり。
  for(int a=0; a<=max_water; a++){
    for(int b=0; b<= (F-100.0*a)/(100.0*B); b++){

      water = a*100*A + b*100*B;
      if (water == 0){
        continue;
      }
      max_sugar = (F-water)/C;
      for(int c=0; c <= max_sugar; c++){
        for(int d=0; d <= double(F-water-c*C)/double(D); d++){
          sugar = c*C + d*D;

          max_conq = double(s_result)/double(w_result+s_result);
          conq = double(sugar)/double(water+sugar);
          //cout << water <<" "<< sugar << endl;

          if(max_conq < conq && water+sugar <= F && conq <= E/(E+100.0)){
            s_result = sugar;
            w_result = water;
          }
        }

      }
    }
  }
  cout << w_result+s_result <<" "<< s_result << endl;

  return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3


def main():
    n = int(input())
    h = map(int, input().split())
    current_max = 0
    ans = 0
    for hi in h:
        if hi >= current_max:
            ans += 1
        if hi > current_max:
            current_max = hi
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
#define rep(i,e) for(int i= 0; i< (int)(e); i++)
#define reps(i,s,e) for(int i = s; i < (int)(e); i++)
#define repr(i,s,e) for(int i = s; i > (int)(e); i--)
#define pb push_back
typedef long long ll;
const ll INF = 1LL << 60;

int main()
{
    int n;
    cin >> n;
    vector<int> b(n);
    rep(i,n){
        cin >> b[i];
    }
    bool exist = true;
    rep(i,n){
        if(b[i]>i+1){
            exist = false;
        }
    }
    vector<int> ans;
    if(!exist){
        cout << -1;
    }else{
        rep(i,n){
            repr(j,n-i-1,-1){
                if(b[j]==j+1){
                    b.erase(b.begin() + j);
                    ans.pb(j+1);
                    break;
                }
            }
        }
        reverse(ans.begin(),ans.end());
        rep(i,n){
            cout << ans[i] << endl;
        }
    }
}

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

int main(){
	int a,ans;
	cin >> a;
	ans=0;
	for(int i=1;!(a==4||a==2||a==1);i++){
		if(a%2==0){
			a /= 2;
		}
		else{
			a = 3*a+1;
		}
		ans++;
	}
	cout << ans+4;
	return 0;
}

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

int main() {
  int N;
  long long num;
  set<int> s;
  cin >> N;

  for (int i = 0; i < N; i++) {
    cin >> num;
    if (s.find(num) == s.end()) {
      s.insert(num);
    } else {
      s.erase(num);
    }
  }

  cout << s.size() << endl;
  return 0;
}


Measured memory_bytes: 4864
#include <algorithm>
#include <climits>
#include <iostream>
#include <string>
#include <utility>
#include<vector>
#include<iomanip>
#include<map>
#include <queue>
#include<cmath>
#include<cstdio>
#include<iomanip>

using namespace std;
using ll = long long int; 


ll keta(ll a){
  ll ans = 1;
  while(1){
    if(a/10 > 0){
      ans++;
      a = a/10;
    }
    if(a<10) break;
  }
  return ans;
}


int main(void){

  ll n, p;
  cin>>n>>p;
  if(n==1){
    cout<<p<<endl;
    return 0;
  }

  ll num = p;
  ll ans = 1;
  ll count;

  for(int i=2;i<=sqrt(p);i++){
    count = 0;
    while(1){
      if(num % i==0){
        count++;
        num = num/i;
       // cout<<count<<", "<<num<<" ";
      }else{
        break;
      }
    }
    if(count>=n) ans *= pow(i,(count/n));
  }

  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define yorn(f) cout<<((f)?"Yes":"No")<<endl;
#define YORN(f) cout<<((f)?"YES":"NO")<<endl;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, n) for (int i = 1; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define put(x) cout << x << endl;
#define println(x) cout << x << endl;
using namespace std;
int main()
{
    ll n, k;
    cin >> n >> k;
    ll ans = k;
    rep(i, n - 1) ans *= (k - 1);
    put(ans)
    return 0;
}

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

using namespace std;

#define Fast  ios::sync_with_stdio(false); cin.tie(0)
#define pb push_back
#define pf push_front
#define pp pop
#define ppb pop_back
#define ppf pop_front
#define mp make_pair
#define S second
#define F first
typedef long long ll;
const ll mod = 1e9 + 7;
const ll N = 1e6 + 5;
ll inf = 1e18;

ll a[N];
ll sm[N];

int main(){

    Fast;

    ll n;
    cin >> n;

    for(int i = 0  ;i < n ;i ++)cin >> a[i];

    sm[n-1] = a[n-1];

    for(int i = n-2; i >= 0 ; i --){
        sm[i] = a[i] + sm[i+1];
        sm[i] %= mod;
    }

    ll ans = 0;

    for(int i = 0 ; i < n-1 ;i ++){
        ans += a[i] * sm[i+1];
        ans %= mod;
    }

    cout << ans ;



    return 0;
}


Measured memory_bytes: 6712
import java.util.*;
import java.math.*;
import java.awt.geom.*;
import java.io.*;
     
     
public class Main {
	static int[] vx = new int[] {0,1,0,-1};
	static int[] vy = new int[] {1,0,-1,0};
	static int Y;
	static int X;
	static int MIN;
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(true) {
			int x = sc.nextInt();
			int y = sc.nextInt();
			X = x;
			Y = y;
			if(x == 0 && y == 0) break;
			char[][] map = new char[y][x];
			for(int i = 0; i < Y; i++) {
				for(int j = 0; j < X; j++) {
					map[i][j] = sc.next().charAt(0);
				}
			}
			boolean[][] same = new boolean[Y][X];
			same[0][0] = true;
			cc(map,same,new boolean[Y][X],0,0);
			MIN = Integer.MAX_VALUE;
			int count = dfs(map,same,0);
			System.out.println(count);
		}
	}
	static char[] change = new char[] {'R','G','B'};
	static int dfs(char[][] map, boolean[][] same, int count) {
		if(count >= MIN) return MIN;
		char c = map[0][0];
		boolean ok = true;
		IN:for(int i = 0; i < Y; i++) {
			for(int j = 0; j < X; j++) {
				if(map[i][j] != c) {
					ok = false;
					break IN;
				}
			}
		}
		if(ok) {
			MIN = count;
			return count;
		}
		int ret = Integer.MAX_VALUE;
		char[][]    before = new char[Y][X];
		boolean[][] check  = new boolean[Y][X];
		for(int i = 0; i < 3; i++) {
			if(c == change[i]) continue;
			for(int j = 0; j < Y; j++) {
				before[j] = Arrays.copyOf(map[j]  ,  X);
				check[j]  = Arrays.copyOf(same[j] , X);
			}
			for(int j = 0; j < Y; j++) {
				for(int k = 0; k < X; k++) {
					if(check[j][k]) before[j][k] = change[i];
				}
			}
			boolean go = cc(before,check,new boolean[Y][X],0,0);
			if(go) ret = Math.min(dfs(before,check,count+1),ret);
		}
		return ret;
	}
	static boolean cc(char[][] a, boolean[][] b, boolean[][] oc,int y, int x) {
		boolean ok = false;
		if(oc[y][x]) return ok;
		oc[y][x] = true;
		for(int k = 0; k < 4; k++) {
			int ty = vy[k] + y;
			int tx = vx[k] + x;
			if(ty < 0 || tx < 0 || ty >= Y || tx >= X) continue;
			if(a[y][x] == a[ty][tx]) {
				ok |= !b[ty][tx];
				b[ty][tx] = true;
				if(!oc[ty][tx])
				ok |= cc(a,b,oc,ty,tx);
			}
		}
		return ok;
	}
}

Measured memory_bytes: 162300
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif
using namespace std;

typedef long long ll;
//typedef pair<int,int> Pint;
typedef pair<ll, ll> P;
//typedef pair<ll, pair<ll, ll>> P;
//typedef tuple<int,int,int> T;
typedef vector<ll> vec;
typedef vector<vec> mat;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define revrep(i, n) for(ll i = n-1; i >= 0; i--)
#define pb push_back
#define f first
#define s second
const ll INFL = 1LL << 60;//10^18 = 2^60
const int INF = 1 << 30;//10^9
const ll MOD = 1e9 + 7;
const double EPS = 1e-10;
//ll MOD  = 998244353;
vector<ll> dy = {0, 0, 1, -1, 1, 1, -1, -1, 0};
vector<ll> dx = {1, -1, 0, 0, 1, -1, 1, -1, 0};

ll max(ll a, ll b){return (a > b) ? a : b;}
ll min(ll a, ll b){return (a < b) ? a : b;}
ll pow_long(ll x, ll k){
  ll res = 1;
  while(k > 0){
    if(k % 2) res *= x;
    x *= x;
    k /= 2;
  }
  return res;
}

ll pow_mod(ll x, ll k){
  x %= MOD; x += MOD; x %= MOD;
  ll res = 1;
  while(k > 0){
    if(k % 2){
      res *= x; res %= MOD;
    }
    x *= x; x %= MOD;
    k /= 2;
  }
  return res;
}
ll inverse(ll x){return pow_mod(x, MOD - 2);};


ll gcd(ll a, ll b){
    if(b == 0) return a;
    return gcd(b, a % b);
}

ll lcm(ll x, ll y){return x / gcd(x, y) * y;};

int main(void){
  ll N;
  cin >> N;
  vector<ll> A(N);
  rep(i, N) cin >> A[i];
  ll odd = 0, even = 0;
  rep(i, N){
    if(A[i] % 2) odd++;
    else even++;
  }

  if(odd % 2){
    cout << "NO" << endl;
  }else{
    cout << "YES" << endl;
  }


}


Measured memory_bytes: 1024
fun main(args: Array<String>) {
    val (a, b) = getInts()
    println("${a * (a - 1) / 2 + b * (b - 1) / 2}")
}

fun getInt() = readLine()!!.toInt()
fun getInts() = readLine()!!.split(" ").map { it.toInt() }

Measured memory_bytes: 35952
while True:
    try:
        a, b = map(int, raw_input().split())
        def gcd(a, b):
            if b == 0:
                return a
            else:
                return gcd(b, a%b)
        g = gcd(a,b)
        l = a*b/g
        print g, l
    except:
        break

Measured memory_bytes: 4208
#include<cstdio>
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<cstdlib>
#include<fstream>
using namespace std;
bool cmp(int a,int b)
{
	return a>b;
}
int main() 
{
    int n;
    cin>>n;
    int a[n+1];
    int k;
    cin>>k;
    for(int i=1;i<=n;i++)
    {
    	cin>>a[i];
    }
    sort(a+1,a+n+1,cmp);
    int sum=0;
    for(int i=1;i<=k;i++)
    {
    	sum+=a[i];
    }
    cout<<sum<<endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int K = sc.nextInt();
    int X = sc.nextInt();
    
    int l = X - (K-1) >= -1000000 ? X - (K-1) : -1000000;
    int r = X + (K+1) <=  1000000 ? X + (K-1) :  1000000;
    for (int i = l; i <= r; i++) {
      System.out.print(i + " ");
    }
  }
}

Measured memory_bytes: 21716
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<sstream>
#include<cmath>
#include<numeric>
#include<map>
#include<stack>
#include<queue>
#include<list>
#include<set>
#include<cstring>
using namespace std;
long long int mod = 1e9 + 7;
template <class T>
void inputV(vector<T> &x, int n){
  for(int i=0; i<n; i++) cin >> x[i];
}

int main() {

  int n;
  cin >> n;

  vector<int> p(n);
  map<int, int> m;
  for(int i=0; i<n; i++){
    cin >> p[i];
    m[p[i]] = i+1;
  }
  int ans = 1;
  int cnt = 1;
  for(int i=n; i>=2; i--){
    if( m[i] > m[i-1] ) cnt++;
    else {
      ans = max(ans, cnt);
      cnt = 1;
    }
  }
  ans = max(ans, cnt);
  cout << n - ans << endl;

  return 0;
}



//


Measured memory_bytes: 10368
#!/usr/bin/python
# coding: UTF-8
n,m = map(int,input().split())

res = [0 for _ in range(m)]

for i in range(n):
  res_tmp = [0 for _ in range(m)]
  for j in list(map(int,input().split()))[1:]:
    res[j-1] += 1

print(sum([res[i]==n for i in range(m)]))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A, B;
  cin >> A >> B;
 
  if (A == B) {
    cout << A + B << endl;
  }
  else if (A > B) {
    cout << A * 2 - 1 << endl;
  }
  else {
    cout << B * 2 -1 << endl;
  }
}

Measured memory_bytes: 384
#include<iostream>
#include<algorithm>
#include<cstring>
#include<vector>
#include<map>
#include<cstring>
#include <stack>
#include <numeric>
#include<climits>
#include<cmath>
#include<set>
#include<unordered_set>
#include<iomanip>
#include<queue>
#include<bitset>
#include<unordered_map>
#define vi vector<float>
#define vl vector<long long>
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define loop(i,n) for(int i=0; i<n; i++)
#define pb push_back
#define mp make_pair
#define ll long long
#define umap unordered_map
const int mod = 1e9 + 7;
using namespace std;

#define xx first
#define yy second


int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(NULL);

// #ifndef ONLINE_JUDGE
// 	freopen("input.txt", "r", stdin);
// 	freopen("nnout.txt", "w", stdout);
// #endif

	int n, weight;
	cin >> n >> weight;

	int w[n], v[n];


	for (int i = 0; i < n; i++) {
		cin >> w[i] >> v[i];
	}

	ll dp[n + 1][weight + 1];

	for (int i = 0; i <= n; i++) {
		for (int j = 0; j <= weight; j++) {
			if (i == 0 || j == 0) {
				dp[i][j] = 0;
			} else {
				if (w[i - 1] <= j)
					dp[i][j] = max(v[i - 1] + dp[i - 1][j - w[i - 1]], dp[i - 1][j]);
				else
					dp[i][j] = dp[i - 1][j];
			}
		}
	}

	cout << dp[n][weight] << endl;


	return 0;
}










Measured memory_bytes: 79232
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;

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

	if (n < 1200) cout << "ABC" << endl;
	else if (n < 2800) cout << "ARC" << endl;
	else cout << "AGC" << endl;
}


Measured memory_bytes: 256