akhauriyash/Code-Regression huggingface dataset:
/* Author rumoisen */
/* created 2018/11/17 */

#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <string>
#include <cmath>
#include <iomanip>
#include <numeric>
#include <cmath>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define INF (ll)1e18
#define MOD (ll)1e9 + 7
#define pb push_back

void no() { cout << "No" << endl;exit(0);}
void yes() { cout << "Yes" << endl;exit(0);}
void No() { cout << "NO" << endl;exit(0);}
void Yes() { cout << "YES" << endl;exit(0);}

typedef long long ll;
typedef long long int llt;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;

using namespace std;

int main()
{
    char s;
    cin >> s;
    bool flag = false;
    if(s=='a'||s=='i'||s=='u'||s=='e'||s=='o')
        flag = true;
    if(flag)
        cout << "vowel" << endl;
        else
            cout << "consonant" << endl;
    return 0;
}

Measured memory_bytes: 256
import kotlin.math.*

fun str() = readLine()!!
fun int() = str().toInt()
fun long() = str().toLong()

fun read(d:String = " ") = str().split(d)
fun <T> list(d:String = " ",f:String.()->T) = read(d).map {f(it)}
fun list() = list {toInt()}.toIntArray()

fun <T> T.print() = println(this)

fun main() {
	abc000X()
}

fun abc000X() {
	val n = int()
	val p = list()
	val a = IntArray(1000001) {0}

	for(i in p) {
		++a[i]
		if(a[i]>1) continue
		for(j in (i*2..1000000).step(i))
			++a[j]
	}

	println(p.count {a[it]==1})
}


Measured memory_bytes: 70096
#include <iostream>
#include <algorithm>
using namespace std;
long long n,s,a[1001],h;
int main()
{ cin>>n>>s;
  for(int i=1;i<=n;i++)
    cin>>a[i];
  sort(a+1,a+n+1);
  for(int i=1;i<=n && s>=a[i];i++)
  { if(s>=a[i])
       h++,s-=a[i];
  }
  if(s!=0 && h==n)
     h--;
  cout<<h;
  return 0;
}


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

#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(a) (int)(a.size())
#define ALL(a) a.begin(),a.end()
#define SET(a,b) memset(a,b,sizeof(a))
#define off ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
typedef pair<int,int>   II;
typedef vector< II >      VII;
typedef vector<int>     VI;
typedef vector< VI > 	VVI;
typedef long long int 	LL;
typedef vector<LL> 		VL;
#define si(n) cin>>n
#define dout(n) cout<<n<<"\n"
#define DRT() int t; si(t); while(t--)
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
//# define M_PI           3.14159265358979323846264338327950288
// DSU
void IO(){
	#ifndef ONLINE_JUDGE
    freopen("../input.txt", "r", stdin);
    freopen("../output.txt", "w", stdout);
	#endif
	srand(chrono::steady_clock::now().time_since_epoch().count());
	off;
}
int cnt1[41];
int cnt2[41];
void give1(LL a){
	a++;
	LL one = 1;
	LL zero = 0;
	for(LL i = 1;i<=40;i++){
		LL up = (one << i);
		LL p = (one << (i-1));
		// cout<<up<<" "<<p<<"\n";
		LL t = a/up;
		LL ans = t * p;
		LL rem = a % up;
		rem = max(zero, rem - p);
		ans += rem;
		cnt1[i-1] = ans;
	}
}
void give2(LL a){
	a++;
	LL one = 1;
	LL zero = 0;
	for(LL i = 1;i<=40;i++){
		LL up = (one << i);
		LL p = (one << (i-1));
		LL t = a/up;
		LL ans = t * p;
		LL rem = a % up;
		rem = max(zero, rem - p);
		ans += rem;
		cnt2[i-1] = ans;
	}
}
int main(){
	IO();
	LL a,b;
	cin>>a>>b;
	rep(i,0,41){
		cnt2[i] = cnt1[i] = 0;
	}
	LL ans = 0;
	if(a){
		give1(b);
		give2(a-1);
	}
	else{
		give1(b);
	}
	LL one = 1;
	for(LL i = 0;i<40;i++){
		LL diff = cnt1[i] - cnt2[i];
		if(diff&1)
			ans += (LL)(one << i);
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 3600
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <string>
#include <stack> // s.top()
#include <bitset>
#include <queue> // s.front()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define print(x) cout<<(x)<<endl
#define INF10 1001001001 
#define INF5 100000
#define EPS 1e-10


int main() {
	int N; cin >> N;
	vector<int>A(N);
	vector<int>B(N);
	vector<int>C(N);
	for (int i = 0; i < N; i++) {
		cin >> A[i];
		A[i]--;
	}
	for (int i = 0; i < N; i++) {
		cin >> B[i];
	}
	for (int i = 0; i < N - 1; i++) {
		cin >> C[i];
	}

	int cnt = 0;
	for (int i = 0; i < N; i++) {
		cnt += B[A[i]];
		if (i != 0 && A[i - 1] + 1 == A[i]) cnt += C[A[i - 1]];
	}
	cout << cnt << endl;


	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<bits/stdc++.h>
#include<algorithm>
#define FasterIO     ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define PI acos(-1)
#define all(a) a.begin(),a.end()
#define f first
#define s second
#define pb push_back
#define ppb pop_back
#define pf push_front
#define ppf pop_front
#define mp make_pair
#define f0(i,n) for(i=0;i<n;i++)
#define f1(i,n) for(i=1;i<n;i++)
#define f1n(i,n) for(i=1;i<=n;i++)
#define szf sizeof()
#define sz size()
#define ln length()
using namespace std;
using ll=long long;
int cnt,element;
long long int arr[100000001];
vector<ll>vec;
int main()
{
    int n;
    string a;
    cin>>n;
    vector<string>str;
    set<string>ans;
    for(int i=0;i<n;i++)
    {
         cin>>a;
         str.push_back(a);
         ans.insert(a);
    }
    int rafi=ans.size();
    cout<<rafi<<endl;

    return 0;
}


Measured memory_bytes: 25124
#include <bits/stdc++.h>
using namespace std;
int main()
{
    string s, t;
    int m, h;
    while (1)
    {
        cin >> s;
        if (s == "-")
            break;
        cin >> m;
        for(int i = 0; i < m; i++) {
            cin >> h;
            t = s.substr(h);
            s.erase(h);
            s = t + s;
        }
        cout << s << '\n';
    }
    
  
    return 0;
}


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

using namespace std;

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

#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<(b);i++)
#define repr(i,b,a) for(int i=int(b);i>=(a);i--)
#define all(x) x.begin(),x.end()

const ll mod = 1e9+7;
const ll INF = 1e9;

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
bool valid(int lx,int ux,int ly,int uy,int x,int y){
	return lx<=x&&x<ux&&ly<=y&&y<uy; 
}
ll power(ll x,ll p){
	if(p==0)return 1;
	ll res=power(x*x%mod,p/2);
	if(p%2==1)res=res*x%mod;
	return res;
}


int main()
{
	int n;
	cin>>n;
	vector<ll> a(n);
	rep(i,n)cin>>a[i];
	vector<ll> sum(n,0);
	sum[0]=a[0];
	repi(i,1,n)sum[i]=sum[i-1]+a[i];

	ll ans=1LL<<60;
	rep(i,n-1){
		ll left = sum[i];
		ll right = sum[n-1]-sum[i];

		ans =min(ans,abs(left-right));
	}
	cout<<ans<<endl;

	return 0;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vs = vector<string>;
using pll = pair<ll, ll>;
using vp = vector<pll>;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define repr(i, a, b) for(ll i = (a); i < (b); i++)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((ll)(x).size())
const ll MOD = 1000000007;
const ll INF = 100000000000000000LL;
inline ll GCD(ll a, ll b){ return b?GCD(b, a % b):a; }
inline ll LCM(ll a, ll b){ return a/GCD(a, b)*b; }
inline ll powint(ll x, ll y){ ll r=1; while(y){ if(y&1) r*=x; x*=x; y>>=1; } return r; }
inline ll powmod(ll x, ll y, ll m = MOD){ ll r=1; while(y){ if(y&1) r*=x; x*=x; r%=m; x%=m; y>>=1; } return r; }
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; }
#ifdef OJ_LOCAL
#include "dump.hpp"
#else
#define dump(...) ((void)0)
#endif

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    ll n, d;
    cin >> n >> d;
    ll p = 2 * d + 1;
    cout << (n+p-1)/p << endl;
    return 0;
}

Measured memory_bytes: 256
#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
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 ll INF = LLONG_MAX;
const string alpha = "abcdefghijklmnopqrstuvwxyz";

int main(){
    int N;
    cin >> N;
    int A[N], sum = 0;
    rep(i, N){
        cin >> A[i];
        sum += A[i];
    }
    bitset<2000*2000+1> bs;
    bs.set(0);
    rep(i, N){
        bs |= bs << A[i];
    }
    int i = (sum+1)/2;
    while(true){
        if(bs[i]){
            cout << i << endl;
            break;
        }
        else i++;
    }
}

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

#define F(i,a,b,c) for(int i=a;i<b;i+=c)

using namespace std;

int a,b;
string m[105][105];
int x;

void print()
{
	F(i,0,100,1)
	{
		F(j,0,100,1)cout<<m[i][j];
		puts("");
	}
}

int main()
{
    
    cin>>a>>b;
    
	F(i,0,100,1)F(j,0,50,1)m[i][j]='#';
    F(i,0,100,1)F(j,50,100,1)m[i][j]='.';
    
    a--;
    b--;
    
    if(a>0)F(i,0,100,2)
    {
    	x=0;
    	
        while((x<50)&&(a>0))
		{
        	m[x][i]='.';
            a--;
            x+=2;
        }
    }
    
    if(b>0)F(i,0,100,2)
	{
		x=51;
		
		while((x<=99)&&(b>0))
		{
			m[i][x]='#';
			b--;
			x+=2;
        }
    }
    
    puts("100 100");
    
    print();
    
    return 0;
    
}

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

using namespace std;
int a , b ;
int main()
{
	cin >> a >> b ;
	if(a == 0 || b == 0){
		cout << "Zero" ;
	}
	else if((a < 0 && b > 0) || (a > 0 && b < 0)){
		cout << "Zero";
	}
	else if(a < 0 && b < 0){
		if((a - b) % 2 == 0){
			cout << "Negative";
		}
		else{
			cout << "Positive";
		}
	}
	else{
		cout << "Positive";
	}
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <stdio.h>
#include <unordered_set>

using namespace std;

#define ll long long

ll p[10001];
vector<ll> prime;

int main(){
  for(ll i = 0; i < 10001; i++){
    p[i] = 0;
  }
  p[0] = p[1] = 1;
  
  ll id = 2;
  while(1){
    while(id <= 10000 &&  p[id] == 1){
      id++;
    }
    if(id >= 10000){
      break;
    }
    ll temp = 2 * id;
    while(temp <= 10000){
      p[temp] = 1;
      temp += id;
    }
    id++;
  }

  for(ll i = 0; i <= 100; i++){
    //    cout << i << ' ' << p[i] << endl;
  }

  for(ll i = 2; i <= 10000; i++){
    if(p[i] == 0){
      prime.push_back(i);
    }
  }

  for(vector<ll>::iterator it = prime.begin(); it != prime.end(); it++){
    //   cerr << *it << ' ';
  }
  //  cerr << '\n';
  
  ll n = prime.size();
  vector<ll> sum(n);
  sum[0] = prime[0];
  unordered_set<ll> us;
  us.insert(sum[0]);
  for(ll i = 1; i < n; i++){
    sum[i] = sum[i-1] + prime[i];
    us.insert(sum[i]);
  }
  us.insert(0);

  ll k;
  while(cin >> k && k){
    ll cnt = 0;
    for(ll i = 0; i < n; i++){
      if(us.find(k+sum[i]) != us.end() || k == sum[i]){

	cnt ++;
      }
    }
    cout << cnt << endl;
  }
}
  

Measured memory_bytes: 3236
# Python3 (3.4.3)
import sys
input = sys.stdin.readline

# -------------------------------------------------------------
# function
# -------------------------------------------------------------


# -------------------------------------------------------------
# main
# -------------------------------------------------------------
N,D = map(int,input().split())
X = [list(map(int,input().split())) for _ in range(N)]

ans = 0
for i in range(N):
    for j in range(i+1,N):
        total = 0
        for k in range(D):
            total += (X[i][k] - X[j][k])**2
        if int(total**.5)**2 == total:
            ans += 1

print(ans)


Measured memory_bytes: 3060
#include<stdio.h>
long minc(a,b){
if(a<b)return a;
  else return b;
}
int main(void){
  long l,r;
  scanf("%ld%ld",&l,&r);
	r=minc(r,l+4038);
  int min=2019;
  for(long i=l;i<=r;i++){
	for(long j=l;j<=r;j++){
      if(i==j)continue;
	if(min>(i*j)%2019)min=(i*j)%2019;
    }
  }
  printf("%d",min);
  return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define cs const
#define pb push_back
#define rez resize
#define bg begin
#define poly vector<int>
using namespace std;
cs int Mod = 924844033;
int add(int a, int b){ return a + b >= Mod ? a + b - Mod : a + b; }
int dec(int a, int b){ return a - b < 0 ? a - b + Mod : a - b; }
int mul(int a, int b){ return 1ll * a * b % Mod; }
void Add(int &a, int b){ a = add(a,b); }
void Mul(int &a, int b){ a = mul(a,b); }
void Dec(int &a, int b){ a = dec(a,b); }
int ksm(int a, int b){ int as=1; for(;b;b>>=1,Mul(a,a)) if(b&1) Mul(as,a); return as; }
cs int N = 2e5 + 50;
int n, sz[N]; vector<int> G[N];
int fc[N], ifc[N]; poly f, g;
int C(int n, int m){ return mul(fc[n],mul(ifc[n-m],ifc[m])); }
void fc_init(int n){
	fc[0]=fc[1]=ifc[0]=ifc[1]=1;
	for(int i=2;i<=n;i++)fc[i]=mul(fc[i-1],i);
	ifc[n]=ksm(fc[n],Mod-2);
	for(int i=n-1;i>=2;i--)ifc[i]=mul(ifc[i+1],i+1);
}
void dfs(int u, int fa){
	sz[u]=1; for(int v:G[u])
	if(v!=fa) dfs(v,u),sz[u]+=sz[v],++f[sz[v]];
	++f[n-sz[u]];
}
cs int M = 1 << 19;
int up, bit, rv[M];
void init(int d){
	up=1, bit=0; while(up<d) up<<=1,++bit;
	for(int i=0; i<up; i++) 
	rv[i] = (rv[i>>1]>>1)|((i&1)<<(bit-1));
}
void dft(poly &a){
	for(int i=0;i<up;i++) 
	if(i<rv[i]) swap(a[i],a[rv[i]]);
	for(int i=1;i<up;i<<=1)
	for(int j=0,t=i<<1,wn=ksm(5,(Mod-1)/t);j<up;j+=t)
	for(int k=0,w=1;k<i;k++,Mul(w,wn)){
		int x=a[k+j], y=mul(w,a[k+j+i]);
		a[k+j]=add(x,y), a[k+j+i]=dec(x,y);
	} 
} void idft(poly &f){ 
	dft(f); reverse(f.bg()+1,f.end());
	for(int i=0,iv=ksm(up,Mod-2);i<up;i++)
	Mul(f[i],iv);
}
int main(){
	#ifdef FSYolanda
	freopen("1.in","r",stdin);
	#endif
	scanf("%d",&n); fc_init(n);
	for(int i=1,u,v;i<n;i++)
	scanf("%d%d",&u,&v),G[u].pb(v),G[v].pb(u);
	f.rez(n+1); g.rez(n+1); dfs(1,0);
//	for(int i=1;i<=n;i++)cout<<f[i]<<" ";cout<<endl;
	for(int i=1;i<=n;i++) Mul(f[i],fc[i]); 
	reverse(f.bg(),f.end());
	for(int i=0; i<=n; i++) g[i]=ifc[i];
	init(n+n+1); f.rez(up), g.rez(up);
	dft(f), dft(g);
	for(int i=0;i<up;i++)Mul(f[i],g[i]);
	idft(f); 
//	for(int i=1; i<=n; i++) cout << mul(ifc[i],f[n-i]) << endl;
	for(int i=1;i<=n;i++)
	cout<<dec(mul(n,C(n,i)),mul(ifc[i],f[n-i]))<<'\n';
	return 0;
}

Measured memory_bytes: 36540
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define vi vector<int>
#define pb push_back
#define INF 999999999
//#define INF (1LL<<59)

int h,w;


void dfs(int y,int x,vector<string> data,bool used[101][101]){
    int dy[]={1,0,-1,0};
    int dx[]={0,1,0,-1};

    rep(i,4){
        int ddy = y+dy[i];
        int ddx = x+dx[i];
        
        if( ddx>=0 && ddy>=0 && ddx<w && ddy<h && data[ddy][ddx]==data[y][x] && !used[ddy][ddx]){
            used[ddy][ddx]=true;
            dfs(ddy,ddx,data,used);
        }
    }
}


int main(){
    
    while(cin>>h>>w&&(h||w)){
        vector<string> data(h);
        
        rep(i,h)cin>>data[i];
        
        bool used[101][101]={};
        int c=0;
        rep(i,h){
            rep(j,w){
                if(!used[i][j]){
                    used[i][j]=true;
                    dfs(i,j,data,used);
                    c++;
                }
            }
        }
        cout<<c<<endl;
    }
    
}

Measured memory_bytes: 17872
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<stack>
#include<queue>
#include<set>
#include<tuple>
#include<ctime>
#include<functional>
#include<cmath>
#include<cassert>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> p; 
#define rep(i,n) for(ll i=0;i<(n);i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("Yes")
#define p_no() p("No")
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
int main(){
    int N,l[110],cnt=0;
    cin>>N;
    rep(i,N) cin>>l[i];
    for(int j=1;j<N-1;j++){
        for(int i=0;i<j;i++){
            for(int k=j+1;k<N;k++){
                if(l[i]!=l[k]&&l[i]!=l[j]&&l[j]!=l[k]){
                    if(l[i]<l[j]+l[k] && l[j]<l[i]+l[k] && l[k]<l[i]+l[j]) cnt++;
                }
            }
        }
    }
    cout<<cnt<<endl;
}

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

using namespace std;

#define INF 1e9
#define ll long long
#define vi vector<int>
#define vll vector<long long>
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)

ll H,W;
vector<string> Cs;

void solve(){
    rep(i,Cs.size()){
        cout << Cs[i] << endl;
        cout << Cs[i] << endl;
    }
}

int main(){
    cin >> H >> W;
    Cs.resize(H);

    rep(i,H)
        cin >> Cs[i];

    solve();
}


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

using Int = long long;
const char newl = '\n';

template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
template<typename T> void drop(const T &x){cout<<x<<endl;exit(0);}
template<typename T=Int>
vector<T> read(size_t n){
  vector<T> ts(n);
  for(size_t i=0;i<n;i++) cin>>ts[i];
  return ts;
}

//INSERT ABOVE HERE

const Int INF = 1e18;

Int dp[2][55][22];
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(0);

  Int n;
  cin>>n;
  vector<string> ss(n);
  vector<Int> cs(n);
  for(Int i=0;i<n;i++) cin>>ss[i]>>cs[i];

  for(Int i=0;i<55;i++)
    for(Int j=0;j<22;j++)
      dp[0][i][j]=dp[1][i][j]=INF;

  Int ans=INF;
  using T = tuple<Int, Int, Int, Int>;

  priority_queue<T, vector<T>, greater<T>> pq;
  auto push=[&](Int LR,Int x,Int d,Int dist){
    // cout<<LR<<' '<<x<<' '<<d<<':'<<dist<<endl;
    if(dp[LR][x][d]<=dist) return;
    dp[LR][x][d]=dist;
    pq.emplace(dp[LR][x][d],LR,x,d);
  };

  auto palin=[&](string s){
    string t(s.rbegin(),s.rend());
    return s==t;
  };

  for(Int i=0;i<n;i++){
    if(palin(ss[i])){
      chmin(ans,cs[i]);
      continue;
    }

    Int len=ss[i].size();
    push(0,i,len,cs[i]);
    push(1,i,len,cs[i]);

    // center on a character
    for(Int c=0;c<len;c++){
      Int flg=1;
      Int L=c;
      Int R=len-(c+1);
      for(Int j=1;j<=min(L,R);j++)
        flg&=(ss[i][c-j]==ss[i][c+j]);
      if(flg) push(L<R,i,abs(L-R),cs[i]);
    }

    // center between characters
    for(Int c=1;c<len;c++){
      Int flg=1;
      Int L=c;
      Int R=len-c;
      for(Int j=1;j<=min(L,R);j++)
        flg&=(ss[i][c-j]==ss[i][c+j-1]);
      if(flg) push(L<R,i,abs(L-R),cs[i]);
    }
  }
  // exit(0);
  // cout<<"UKU"<<endl;

  while(!pq.empty()){
    auto [dist, LR, x, d] = pq.top();pq.pop();
    if(dp[LR][x][d]<dist) continue;

    for(Int i=0;i<n;i++){
      Int len=ss[i].size();
      if(LR==0){
        Int L=d;
        Int R=len;

        Int flg=1;
        for(Int j=0;j<min(L,R);j++)
          flg&=(ss[i][j]==ss[x][L-(j+1)]);

        if(flg){
          if(L==R) chmin(ans,dist+cs[i]);
          else push(L<R,(L<R?i:x),abs(L-R),dist+cs[i]);
        }
      }
      if(LR==1){
        Int L=len;
        Int R=d;

        Int flg=1;
        for(Int j=0;j<min(L,R);j++)
          flg&=(ss[i][L-(j+1)]==ss[x][ss[x].size()-R+j]);

        if(flg){
          if(L==R) chmin(ans,dist+cs[i]);
          else push(L<R,(L<R?x:i),abs(L-R),dist+cs[i]);
        }
      }
    }
  }

  if(ans==INF) ans=-1;
  cout<<ans<<newl;
  return 0;
}


Measured memory_bytes: 3696
import sys
import math
from collections import defaultdict
from bisect import bisect_left, bisect_right

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def LI(): return list(map(int, input().split()))
def LIR(row,col):
    if row <= 0:
        return [[] for _ in range(col)]
    elif col == 1:
        return [I() for _ in range(row)]
    else:
        read_all = [LI() for _ in range(row)]
        return map(list, zip(*read_all))

#################

# 高橋君のスコア：a*b(a<b)とする
# 1~a-1 は b+a-1~b+1 と組み合わせればok
# a は b-1 と組み合わせればok
# [a+1,b-2]*2 から何ペアできるか二分探索

Q = I()
A,B = LIR(Q,2)

for i in range(Q):
    a,b = min(A[i],B[i]), max(A[i],B[i])
    ab = a*b
    if b-a <= 1:
        print(2*(a-1))
    else:
        ok = 0
        ng = b-a-1
        while abs(ok-ng) > 1:
            mid = (ok+ng)//2
            if mid%2 == 0:
                max_val = (a+mid//2)*(a+mid//2+1)
            else:
                max_val = (a+(mid+1)//2)**2
            if max_val < ab:
                ok = mid
            else:
                ng = mid
        print(2*(a-1)+1+ok)

Measured memory_bytes: 39280
#include <iostream>
#include <vector>
#include <cstring>

#define MAX 100005

using namespace std;

vector<int> stones;

int frog(int k);
int frog2(int k);

int n;

int dp[MAX];

int main() {

    scanf("%d", &n);

    for (int i; i < n; ++i){
        int x;
        scanf("%d", &x);
        stones.push_back(x);
        dp[i] = -1;
    }

    //memset(&dp, -1, sizeof dp);

    printf("%d", frog(n-1));
}

int frog2(int k)
{
    if(k > n-1)
        return 1000000;
    if(k == n-1)
        return 0;
    int a = abs(stones[k] - stones[k + 1]) + frog(k +1);
    int b = abs(stones[k] - stones[k + 2]) + frog(k +2);

    return min(a, b);

}

int frog(int k)
{
    if(k < 0)
        return 1000000;
    if(k == 0)
        return 0;
    if(dp[k] != -1)
        return dp[k];
    int a = abs(stones[k] - stones[k - 1]) + frog(k - 1);
    int b = abs(stones[k] - stones[k - 2]) + frog(k - 2);

    dp[k] = min(a, b);
    return dp[k];
}

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

using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using vint = vector<int>;
using vvint = vector<vint>;
using vvvint = vector<vvint>;
using vdouble = vector<double>;
using vvdouble = vector<vdouble>;
using vvvdouble = vector<vvdouble>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using uint = unsigned int;
using ull = unsigned long long;

template<typename T> using uset = unordered_set<T>;
template<typename T1, typename T2> using umap = unordered_map<T1, T2>;

constexpr int INF = (1 << 30) - 1;
constexpr ll LLINF = 1LL << 60;
constexpr int dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dx[] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr char el = '\n';
constexpr int mod = 1000000007;
constexpr int mod2 = 998244353;
template<typename T> T gcd(T a, T b) { return (b ? gcd(b, a % b) : a); }
template<typename T> T lcm(T a, T b) { return (a / gcd(a, b) * b); }
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) { return (a > b && (a = b, true)); }
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) { return (a < b && (a = b, true)); }

template<typename T>
vector<T> makeVector(size_t a, T b) { return (vector<T>(a, b)); }
template<typename... Ts>
auto makeVector(size_t a, Ts... ts) { 
	return (vector<decltype(makeVector(ts...))>(a, makeVector(ts...)));
}

template<typename T>
bool isin(T y, T x, T h, T w) { return (0 <= y && 0 <= x && y < h && x < w); }
template<typename T>
bool isin1(T y, T x, T h, T w) { return (0 < y && 0 < x && y <= h && x <= w); }

template<typename T>
ostream& operator <<(ostream &os, vector<T> &v) {
	if (v.size()) {
		os << v[0];
		for (int i = 1; i < v.size(); i++) os << " " << v[i];
	}
	return (os);
}

template<typename T>
istream& operator >>(istream &is, vector<T> &v) {
	for (auto &u : v) is >> u;
	return (is);
}

template<typename T1, typename T2>
istream& operator >>(istream &is, pair<T1, T2> &p) {
	return (is >> p.first >> p.second);
}


void Main() {
	int N; cin >> N;
	vint cnt(N+1, 0);
	for (int x = 1; x <= 100; x++) {
		for (int y = 1; y <= 100; y++) {
			for (int z = 1; z <= 100; z++) {
				int val = x*x + y*y + z*z + x*y + y*z + z*x;
				if (val <= N) {
					cnt[val]++;
				}
			}
		}
	}

	for (int i = 1; i <= N; i++) {
		cout << cnt[i] << el;
	}
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(0);
	cout << fixed << setprecision(20);
	Main();
	return (0);
}


Measured memory_bytes: 3612
#include <iostream>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <string>
#include <sstream>
#include <algorithm>
#include <random>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
#include <cassert>
#include <climits>
#include <bitset>
#include <functional>

#define FOR_LT(i, beg, end) for (int i = beg; i < end; i++)
#define FOR_LE(i, beg, end) for (int i = beg; i <= end; i++)
#define FOR_DW(i, beg, end) for (int i = beg; end <= i; i--)

using namespace std;

int64_t kRem = 1000000007;


int64_t factorial[2001];

void prepare(int n) {
	factorial[0] = 1;
	int64_t v = 1;
	FOR_LE(i, 1, n) {
		v = (v * i) % kRem;
		factorial[i] = v;
	}
}

int64_t pow_rem(int64_t x, int64_t m, int64_t rem)
{
	if (m == 0) {
		return 1;
	}
	if (m == 1) {
		return x;
	}

	if (m & 1) {
		int64_t val = pow_rem(x, m / 2, rem);
		val = val * val;
		val %= rem;
		val *= x;
		val %= rem;
		return val;
	}
	else {
		int64_t val = pow_rem(x, m / 2, rem);
		val = val * val;
		val %= rem;
		return val;
	}
}

int64_t pow_remdiv(int64_t val, int64_t rem)
{
	return pow_rem(val, rem - 2, rem);
}

int64_t divide_rem(int64_t divident, int64_t dividor, int64_t rem)
{
	int64_t ret = pow_remdiv(dividor, rem);
	ret *= divident;
	ret %= rem;

	return ret;
}


int64_t nCr(int a, int b)
{
	int64_t ans = factorial[a];
	ans = divide_rem(ans, factorial[b], kRem);
	ans %= kRem;
	ans = divide_rem(ans, factorial[a - b], kRem);
	ans %= kRem;

	return ans;
}

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

	int k, n; cin >> n >> k;
	prepare(n);

	int kr = n - k;
	FOR_LE(i, 1, k) {
		if (i > kr + 1) {
			cout << 0 << endl;
			continue;
		}

		int64_t bcase = nCr(k - 1, i - 1);
		int64_t rcase = 0;
		{
			int kc = i - 1;
			int nc = kr - i + 1;
			rcase = nCr(kc + nc + 1, nc);
		}

		cout << (bcase * rcase) % kRem << endl;
		
	}


	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int compare(const void *a, const void *b)
{
    return *(int *)b - *(int *)a;
}

int main(){
  int n,k;
  cin>>n>>k;
  int l[n];
  for (int  i = 0; i < n; i++) {
    cin>>l[i];
  }

  qsort(l,n,4,compare);

  int ans=0;
  for(int i=0;i<k;i++){
    ans +=l[i];
  }
  cout<<ans;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main() {
    int  N,W;
    cin>>N>>W;
    int w[N];
    int v[N];
    for(int i=0;i<N;i++)
      cin>>w[i]>>v[i];

    ll dp[2][W+1];
    for(ll i=0;i<2;i++)
      for(ll j=0;j<=W;j++)
        dp[i][j] = 0;
    bool turn = 1;
    for(ll i=0;i<N;i++)
    {
      for(ll wt=0;wt<=W;wt++)
      {
        dp[turn][wt] = dp[1-turn][wt];
        if(wt-w[i]>=0)
          dp[turn][wt] = max(dp[1-turn][wt],v[i]+dp[1-turn][wt-w[i]]);
      }
      turn = 1-turn;
    }
    cout<<dp[1-turn][W]<<endl;
  /*
    ll dp[N+1][W+1];
    for(int i=0;i<=N;i++)
      dp[i][0] = 0;
    for(int i=0;i<=W;i++)
      dp[0][i] = 0;
    for(int i=1;i<=N;i++)
    {
      for(int j=1;j<=N;j++)
      {
        dp[i][j] = dp[i-1][j];
        if(j-w[i]>=0)
        {
          dp[i][j] = max(dp[i][j],v[i]+dp[i-1][j-w[i]]);
        }
      }
    }
    for(int i=0;i<=N;i++)
    {
      for(int j=0;j<=W;j++)
      {
        cout<<dp[i][j]<<" ";
      }
      cout<<endl;
    }
    */
    return 0;
}

Measured memory_bytes: 1792
def main():
    import sys
    import bisect
    import collections
    input = sys.stdin.readline
    N = int(input())
    A = [int(input()) for i in range(N)]
    tmp = collections.deque()
    for i in range(N):
        insert_index = bisect.bisect_left(tmp,A[i])
        if insert_index == 0:
            tmp.appendleft(A[i])
        else:
            tmp[insert_index-1] = A[i]
    answer = len(tmp)
    print(answer)

if __name__ == '__main__':
    main()

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

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

	long long ret = 0;
	for (int i = k + 1; i <= n; ++i) {
		if (k == 0) {
			ret += n;
			continue;
		}
		int j = n / i;
		ret += j * (i - k);
		ret += max(0, n - i * j - k + 1);
	}
	cout << ret << endl;

	return 0;
}

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

int N, T;
int t[364364];
long ans;

int main(){
	cin >> N >> T;
	for (int i = 0; i < N; i++)cin >> t[i];
	ans = t[N - 1] + T;
	for (int i = 1; i < N; i++) {
		if (t[i] - t[i - 1] > T) {
			ans -= t[i] - t[i - 1] - T;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define ll long long
#define mod 1000000007
using namespace std;
 
void solve(){
    int n,m,u,v;
    cin>>n>>m;
    vector<vector<int>> adj(n+1,vector<int>());
    vector<int> indegree(n+1,0);
    for(int i=0;i<m;++i){
        cin>>u>>v;
        adj[u].push_back(v);
        ++indegree[v];
    }
    vector<bool> done(n+1,false);
    vector<int> dp(n+1,0);
    for(int i=1;i<=n;++i){
        if(!indegree[i] && !done[i]){ 
            queue<int> q;
            q.push(i);
            while(!q.empty()){
                u=q.front();   q.pop();
                for(int v : adj[u]){
                    if(indegree[v]){
                        dp[v]=max(dp[v],dp[u]+1);
                        --indegree[v];
                        if(!indegree[v]){
                            done[v]=true;
                            q.push(v);
                        }
                    } 
                }
            }
        } 
    }
    cout<<*max_element(dp.begin(),dp.end());
}

int main(){
    ios::sync_with_stdio(false); cin.tie(0);
    solve(); cout<<endl;
    return 0;
}

Measured memory_bytes: 9356
#include <stdio.h>
#include <stdlib.h>
#define MAX 100

int main() {
  int N;
  int a[MAX] = {};
  int b[MAX] = {};

  int i, j, k;

  scanf("%d", &N);
  for (i = 0; i < N; i++) {
    scanf("%d", &b[i]);
  }

  for (i = 0; i < N; i++) {
    for (j = N - i - 1; j >= 0; j--) {
      if (b[j] == j + 1) {
        a[i] = j + 1;
        for (k = j; k < N - i - 1; k++) {
          b[k] = b[k + 1];
        }
        break;
      }
    }
    if (j < 0) {
      printf("-1\n");
      return 0;
    }
  }

  for (i = N - 1; i >= 0; i--) {
    printf("%d\n", a[i]);
  }

  return 0;
}


Measured memory_bytes: 128
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"strconv"
)

const mod = 998244353
const facNum = 300001

func main() {
	sc := newScanner(os.Stdin)
	N := sc.i()
	S := sc.s()
	var r, g, b int
	for _, rune := range S {
		if rune == 'R' {
			r += 1
		} else if rune == 'G' {
			g += 1
		} else {
			b += 1
		}
	}
	cnt := r * g * b
	for i := 0; i < N-2; i++ {
		for j := i + 1; j < N-1; j++ {
			d := j - i
			if j+d >= N {
				continue
			}
			a := S[i]
			b := S[j]
			c := S[j+d]
			if a != b && b != c && c != a {
				cnt -= 1
			}
		}
	}
	fmt.Println(cnt)
}

// fmt.Println("Yes")
// fmt.Println("No")

// I/O
type scanner struct {
	sc *bufio.Scanner
}

func newScanner(input io.Reader) *scanner {
	sc := bufio.NewScanner(input)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &scanner{sc}
}

func (s *scanner) s() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *scanner) i() int {
	i, e := strconv.Atoi(s.s())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *scanner) f() float64 {
	f, e := strconv.ParseFloat(s.s(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *scanner) bs() []byte {
	return []byte(s.s())
}

func (s *scanner) is(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.i()
	}
	return res
}

func (s *scanner) fs(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.f()
	}
	return res
}

//const factorial = new
func Pow(a, n int) int {
	ans := 1
	for n > 0 {
		if (n & 1) == 1 {
			ans = ans * a % mod
		}
		a = a * a % mod
		n = n >> 1
	}
	return ans
}

func Gcd(a, b int) int {
	if a < b {
		return Gcd(b, a)
	}
	for b != 0 {
		a, b = b, a%b
	}
	return a
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func combination(n, k int, fac, ifac []int) int {
	if n < k || n < 0 {
		return 0
	}
	if k == 0 {
		return 1
	}
	//while n != 0
	ans := ifac[k] * ifac[n-k] % mod
	return ans * fac[n] % mod
}

// 階乗: factorial
// コンビネーションを計算する際に前もって計算しておく
// fac[k] => k! (mod M)
// ifac[k] => k!^(M-2) (mod M)
// n: ex. 2 * 10^5 => 200001
// fac, ifac := factorial()
func factorial() (fac []int, ifac []int) {
	fac = make([]int, facNum)
	fac[0] = 1
	ifac = make([]int, facNum)
	ifac[0] = 1
	for i := 1; i < facNum; i++ {
		fac[i] = fac[i-1] * i % mod
		ifac[i] = ifac[i-1] * Pow(i, mod-2) % mod
	}
	return
}

// vs: sorted slice int value
func lowerBound(vs []int, v int) (index int) {
	n := len(vs) / 2
	m := len(vs)
	for m != n {
		if vs[n] < v {
			n = (m-n+1)/2 + n
			//m = m
		} else {
			m = n
			n = n / 2
		}
	}
	return n
}

func IntSlice(n, init int) []int {
	r := make([]int, n)
	for i := range r {
		r[i] = init
	}
	return r
}


Measured memory_bytes: 1788
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        long ans = 0;
        for(int a=1; a<N; a++){
            //a * b == N - c < N
            ans += (N-1)/a;
        }      
        System.out.println(ans);
    }
}

Measured memory_bytes: 35712
import sys
input = sys.stdin.readline
from collections import *

K = int(input())
N = 50
s, a = divmod(K, N)
ans = [N-1+s]*N

for i in range(a):
    ans[i] += N
    
    for j in range(N):
        if i!=j:
            ans[j] -= 1

print(N)
print(*ans)

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

using namespace std;
int main() {
  int n;
  cin >> n;
  int taste[n];
  for (int i = 0; i < n; i++) {
    cin >> taste[i];
  }

  int total = 0;
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      total += taste[i] * taste[j];
    }
  }
  cout << total << endl;
  return 0;
}

Measured memory_bytes: 256
N = int(input())
if N <= 9:
  print(N)
  exit()
A = [[] for _ in range(11)]
A[0] = [1,2,3,4,5,6,7,8,9]
now = 9
keta = 1
while True:
  for x in A[keta-1]:
    x = str(x)
    last = int(x[-1])
    if last - 1 >= 0:
      temp = x+str(last-1)
      A[keta].append(int(temp))
      now += 1
      if now == N:
        print(temp)
        exit()
    temp = x+str(last)
    A[keta].append(int(temp))
    now += 1
    if now == N:
      print(temp)
      exit()
    if last+1 <= 9:
      temp = x+str(last+1)
      A[keta].append(int(temp))
      now += 1
      if now == N:
        print(temp)
        exit()
  keta += 1



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

int main(){
  int n, m;
  int sum = 0;
  cin >> n;
  int t[n], p, x, tmp;
  for(int i = 0; i < n; i++){
    cin >> t[i];
    sum += t[i];
  }
  cin >> m;
  for(int i = 0; i < m; i++){
    cin >> p >> x;
    cout << sum - t[p - 1] + x << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 5e5 + 10;
int n, m;
const ll mod = 1e9 + 7;
ll ans;
ll fac[maxn], inv[maxn], facinv[maxn], bin[maxn];
void pre()
{
	fac[0] = 1; for(int i = 1; i < maxn; ++i) fac[i] = fac[i - 1] * i % mod;
	inv[1] = 1; for(int i = 2; i < maxn; ++i) inv[i] = (mod - mod / i) * inv[mod % i] % mod;
	facinv[0] = 1; for(int i = 1; i < maxn; ++i) facinv[i] = facinv[i - 1] * inv[i] % mod;
	bin[0] = 1; for(int i = 1; i < maxn; ++i) bin[i] = bin[i - 1] * 2 % mod;
}
ll square(ll x) { return x * x % mod;}
ll C(int n, int m) { return n < m ? 0 : fac[n] * facinv[m] % mod * facinv[n - m] % mod;}
int main()
{
	pre();
	scanf("%d%d", &n, &m);
	ll flag = -1;
	for(int i = 0; i <= n; ++i)
	{
		flag *= -1;
		ll ret = flag * C(n, i) * C(m, i) % mod * fac[i] % mod * square(C(m - i, n - i) * fac[n - i] % mod);
		ans = (ans + ret) % mod;
	}
	cout << (ans + mod) % mod << endl;
	return 0;
}
	
	

Measured memory_bytes: 19356
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> p(n);
  for (int i = 0; i < n; i++) cin >> p[i];
  sort(all(p));
  int ans = 0;
  for (int i = 0; i < k; i++) {
    ans += p[i];
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3564
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

# doublingしてみる

import numpy as np

S = np.array(list(read().rstrip().decode('utf-8')))

L = len(S)
x = np.arange(L,dtype=np.int32)
x[S=='R'] += 1
x[S=='L'] -= 1
dp = [x]

for _ in range(20):
    x = dp[-1]
    dp.append(x[x])

answer = np.bincount(dp[-1],minlength=L)

print(' '.join(answer.astype(str)))

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

int main() {
    priority_queue<int> A;

    string command;
    int target;
    while(true) {
        cin >> command;
        if (command == "insert") {
            cin >> target;
            A.push(target);
        } else if (command == "extract") {
            cout << A.top() << endl;
            A.pop();
        } else {
            break;
        }
    }

    return 0;
}



Measured memory_bytes: 7064
#include <stdio.h>
#include <cmath>
#include <algorithm>

using namespace std;

struct Info{
	Info(){
		id = -1;
		rank = 0;
		num = -1;
	}
	int id,num,rank;

};

int main(){
	Info info[101];

	int id,number,result[101];

	while(true)
	{
		scanf("%d,%d",&id,&number);
		if(id == 0 && number == 0)break;

		info[id].num = number;
		info[id].id = id;
	}

	for(int i = 1; i <= 100; i++){
		for(int k=100; k >= i; k--){
			if(info[k].num > info[k-1].num)swap(info[k],info[k-1]);
		}
	}

	int rank = 0,tmp_num = 0;

	for(int i=0; i <= 100; i++){
		if(info[i].num != tmp_num){
			rank++;
			info[i].rank = rank;
			result[info[i].id] = rank;
			tmp_num = info[i].num;
		}else{
			info[i].rank = rank;
			result[info[i].id] = rank;
			tmp_num = info[i].num;
		}
	}

	int q;
	while(scanf("%d",&q)!=EOF){
		printf("%d\n",result[q]);
	}


	return 0;
}

Measured memory_bytes: 2692
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

n = ni()
x_li = []
y_li = []
h_li = []
for i in range(n):
    x, y, h = na()
    x_li.append(x)
    y_li.append(y)
    h_li.append(h)
H = -1
ansX = -1
ansY = -1
flag = False
if h_li.count(0) == len(h_li) - 1:
    idx = h_li.index(1)
    print(x_li[idx], y_li[idx], h_li[idx])
else:
    for x in range(101):
        for y in range(101):
            for i in range(n):
                tmp = h_li[i] + abs(x_li[i] - x) + abs(y_li[i] - y)
                if H == -1 and h_li[i] != 0:
                    H = tmp
                    ansX = x
                    ansY = y
                elif H == tmp or h_li[i] == 0:
                    if i == n - 1:
                        flag = True
                        break
                else:
                    H = -1
                    break
            if flag:
                break
        if flag:
            break

    print(ansX, ansY, H)

Measured memory_bytes: 3064
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		char[] s = sc.next().toCharArray();
		int N = s.length;
		
		int[] count = new int[2019];
		
		count[0] = 1;
		int mod = 0;
		int base = 1;
		long ans = 0;
		for(int i=N-1; i>=0; i--) {
			mod = (mod + base*(s[i]-'0'))%2019;
			ans += count[mod];
			count[mod]++;
			base = (base*10)%2019;
		}

		System.out.println(ans);
		sc.close();
	}
}


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

int main()
{
  int n;

  cin >> n;

  vector<int> a(n-1);

  vector<int> b(n);

  rep(i, n-1)
  {
    cin >> a.at(i);
  }

  rep(i,n-1){
    b.at(a.at(i)-1) += 1;
  }

  rep(i,n){
    cout << b.at(i) << endl;
  }
}


Measured memory_bytes: 4716
#include<stdio.h>
#include<string.h>
int main()
{
	int a,b,i;
	char c[20];
	scanf("%s",c);
	for(i=0;i<5;i++)
	 	printf("%c",c[i]);
		printf(" ");
	for(i=6;i<13;i++)
	 	printf("%c",c[i]);
		printf(" ");
	for(i=14;i<19;i++)
	 	printf("%c",c[i]);
		printf("\n"); 		 
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
using P = pair<int, int>;
const int MX = 100005;
int n, u, h, w, a, r[MX], c[MX];
P pr[MX];
ll ans;
int p[MX*2], fu[MX*2];
void ufini(int n){ fill(p, p+n, -1);}
int find(int x){return (p[x] < 0 ? x : p[x] = find(p[x]));}
void uni(int x, int y, int z){
	x = find(x); y = find(y);
	if(x != y){
		if(p[x] > p[y]) swap(x, y);
		p[x] += p[y];
		p[y] = x;
		ans += z - min({fu[x], fu[y], z});
		fu[x] = max({fu[x], fu[y]});
	}else if(!fu[x]){
		ans += z;
		fu[x] = z;
	}
}

int main(){
	scanf("%d%d%d", &n, &h, &w);
	u = h + w;
	rep(i,n){
		scanf("%d%d%d", r+i, c+i, &a);
		r[i]--; c[i]--;
		pr[i] = P(a,i);
	}
	sort(pr,pr+n, greater<P>());
	ufini(u);
	rep(i,n) uni(r[pr[i].second], h+c[pr[i].second], pr[i].first);
	printf("%lld\n", ans);
}

Measured memory_bytes: 2944
using System;
using System.Linq;//リストの使用
using System.Collections.Generic;
class Program
{
	static void Main()
	{
	long n = long.Parse(Console.ReadLine());
	long[] nums = Array.ConvertAll(Console.ReadLine().Split(' '),long.Parse);
  long answer = n;
  long[] numA = new long[100000];
  long[] numB = new long[100000];
  long check = 0;
  long biggestA = 0;
  long biggestAnum = 0;
  long biggestB = 0;
  long biggestBnum = 0;

  for(long i = 0; i < n; i++)
  {
    if(i % 2 == 0) numA[nums[i]-1]++;
    else numB[nums[i]-1]++;
  }

  for(long i = 0; i < numA.Length; i++)
  {
    if(numA[i] > biggestAnum)
    {
      biggestAnum = numA[i];
      biggestA = i;
    }
    if(numB[i] > biggestBnum)
    {
      biggestBnum = numB[i];
      biggestB = i;
    }
  }

  Array.Sort(numA);
  Array.Reverse(numA);
  Array.Sort(numB);
  Array.Reverse(numB);

//Console.WriteLine(numA[0]+ " " + numB[0]);
  if(biggestA != biggestB)
  {
  
    answer -= numA[0] + numB[0];
  }else
  {
    if(numA[1] > numB[1]) answer -= numA[1] + numB[0];
    else answer -= numA[0] + numB[1];
  }
  
	Console.WriteLine(answer);
	}
}

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

using namespace std;

int a[5], k;

int main() {
	for (int i = 0; i < 5; i++) scanf("%d", &a[i]);
	scanf("%d", &k);
	
	if (a[4] - a[0] <= k) printf("Yay!\n");
	else printf(":(\n");
}


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

using namespace std;

#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define DEBUG_MAT(v) cerr<<#v<<endl;for(int i=0;i<v.size();i++){for(int j=0;j<v[i].size();j++) {cerr<<v[i][j]<<" ";}cerr<<endl;}


typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
template<class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first + t.first, s.second + t.second); }
template<class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first - t.first, s.second - t.second); }
template<class S, class T> ostream& operator<<(ostream& os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
#define X first
#define Y second
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(n);i>0;i--)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define in(x, a, b) (a <= x && x < b)
#define all(c) c.begin(),c.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 (a>b) { a = b; return 1; } return 0; }
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
const ll inf = 1000000001;
const ll INF = (ll)1e18 + 1;
//const ll MOD = 1000000007;
const ll MOD = 1000003;
//const ll MOD = 998244353;
const double pi = 3.14159265358979323846;
#define Sp(p) cout<<setprecision(15)<< fixed<<p<<endl;
int dx[4] = { -1,0, 1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
#define fio() cin.tie(0); ios::sync_with_stdio(false);
//#define mp make_pair


const int MAXN = 1111111;

vl fact(MAXN);
vl rfact(MAXN);

ll mod_pow(ll x, ll p, ll M = MOD) {
  ll a = 1;
  while (p) {
    if (p % 2)
      a = a*x%M;
    x = x*x%M;
    p /= 2;
  }
  return a;
}

ll mod_inverse(ll a, ll M = MOD) {
  return mod_pow(a, M - 2, M);
}

void set_fact(ll n, ll M = MOD) {
  fact[0] = fact[1] = rfact[0] = rfact[1] = 1;
  for (ll i = 2; i <= n; i++) {
    fact[i] = i * fact[i - 1] % M;
    rfact[i] = mod_inverse(fact[i], M);
  }
}


int main() {
  int q;
  cin >> q;
  set_fact(1111000);
  rep (aaa, q) {
    ll x, d, n;
    cin >> x >> d >> n;
    if (d == 0) {
      cout << mod_pow(x, n) << endl;
      continue;
    }
    if (n >= 1000003) {
      cout << 0 << endl;
      continue;
    }
    ll xl = (x + (n - 1) * d);
    ll k1 = x * mod_inverse(d) % MOD;
    ll k2 = xl * mod_inverse(d) % MOD;
    if (k1 > k2 || k1 == 0 || k2 == 0) {
      cout << 0 << endl;
      continue;
    }
    ll ans = fact[k2] * rfact[k1 - 1] % MOD;
    ans = ans * mod_pow(d, k2 - k1 + 1) % MOD;
    cout << (ans + MOD) % MOD << endl;
  }
}  


Measured memory_bytes: 20096
from collections import defaultdict
from heapq import heappop, heappush
import sys
input = sys.stdin.readline


def dijkstra1(V, n, inf, source):
    # O(ElogV)

    dist = [inf] * (n+1)
    dist[source] = 0
    q = [(0, source)]

    while q:
        cost, u = heappop(q)
        if dist[u] < cost:
            continue
        for c, v in V[u]:
            if dist[v] > dist[u] + c:
                dist[v] = dist[u] + c
                heappush(q, (dist[v], v))

    return dist


def solve():
    N, M = map(int, input().split())
    INF = 10**20
    l = []
    V = defaultdict(list)

    for _ in range(M):
        L, R, C = map(int, input().split())
        V[L].append((C, R))

    for i in range(1, N):
        V[i+1].append((0, i))

    dj = dijkstra1(V, N, INF, 1)
    print(dj[N] if dj[N]!=INF else -1)


if __name__ == "__main__":
    solve()


Measured memory_bytes: 86108
#include  <iostream>
#include  <stdio.h>
using namespace std;


int main(){

    long K;
    long A;
    long B;
    long count2;
    long count;
    long base;

    base = 1000000000;
    count2 = 0;
    cin >> K;
    cin >> A;
    cin >> B;

    if( A > K ){
        cout << 1 + K;
    }else{
        if(B - A > 2){

            K = K - ( A - 1);
            count = A;
            if(K % 2 == 0){
                for(long ki =0; ki < int(K/2) ; ki++){
                    count = count + (B-A);
                    if(count > base){
                        count = count % base;
                        count2 = count2 + 1;
                    }
                }
            }else{
                for(long ki =0; ki < int((K-1)/2) ; ki++){
                    count = count + (B-A);
                    if(count > base){
                        count = count % base;
                        count2 = count2 + 1;
                    }
                }
                count = count + 1;
            }
            if(count2 > 0){
                cout << count2 << count;
            }else{
                cout << count;
            }
        }else{
            cout << 1 + K;
        }
    }

}

Measured memory_bytes: 256