akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  vector<int> diameter(N);
  for (int i=0; i<N ; i++){
    int d;
    cin >> d;
    diameter.at(i) = d;
  }
  sort(diameter.begin(),diameter.end());
  reverse(diameter.begin(),diameter.end());
  
  int count = 1;
  int previous = diameter.at(0);
  for (int i=0; i<N-1 ; i++){
    if (diameter.at(i+1) < previous){
      previous = diameter.at(i+1);
      count ++;
    }
  }
  cout << count << endl;
}


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

// #define int long long
#define rep(i, n) for (long long i = (long long)(0); i < (long long)(n); ++i)
#define reps(i, n) for (long long i = (long long)(1); i <= (long long)(n); ++i)
#define rrep(i, n) for (long long i = ((long long)(n)-1); i >= 0; i--)
#define rreps(i, n) for (long long i = ((long long)(n)); i > 0; i--)
#define irep(i, m, n) for (long long i = (long long)(m); i < (long long)(n); ++i)
#define ireps(i, m, n) for (long long i = (long long)(m); i <= (long long)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) long long(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const ll INF = 1e9;
const ll MOD = 1e9+7;
const ll LINF = 1e18;

vpll G[200100];
ll dist[200100];

signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  ll n,m,s,t; cin>>n>>m>>s>>t;
  s--,t--;
  rep(i,m){
    ll u,v,a,b; cin>>u>>v>>a>>b; u--,v--;
    G[u].emplace_back(v,a);
    G[v].emplace_back(u,a);
    ll nu=n+u, nv=n+v;
    G[nu].emplace_back(nv,b);
    G[nv].emplace_back(nu,b);
  }
  
  priority_queue<pll, vector<pll>, greater<pll>> q;
  q.emplace(0,s);
  q.emplace(0,t+n);
  ll inf=1e15;
  rep(i,2*n+1) dist[i]=inf;
  dist[s]=dist[t+n]=0;
  
  while(!q.empty()){
    auto p=q.top(); q.pop();
    ll v=p.second, c=p.first;
    if(dist[v]<c) continue;
    for(auto np: G[v]){
      ll nv=np.first, nc=np.second;
      if(chmin(dist[nv],dist[v]+nc)){
        q.emplace(dist[nv],nv);
      }
    }
  }
  
  ll base=1e15;
  ll prev=0;
  vll ans(n);
  rrep(i,n){
    chmax(prev,base-(dist[i]+dist[n+i]));
    ans[i]=prev;
  }
  rep(i,n){
    cout<<ans[i]<<endl;
  }
  
}


Measured memory_bytes: 20088
N = gets.to_i
as = gets.split.map(&:to_i)

sum = 0
sqsum = 0

N.times do |i|
  sum += as[i]
  sqsum += as[i]**2
end

x = (sum.to_f / N).round

puts N * x**2 - 2 * sum * x + sqsum


Measured memory_bytes: 1916
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define INF 1e9

signed main()
{
    int a,b,c,d;
    cin >> a >> b >> c >> d;

    while(a > 0 && b > 0) {
        c -= b;
        if(c <= 0) {
            cout << "Yes" << endl;
            return 0;
        }
        a -= d;
    }

    cout << "No" << endl;
}

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

using namespace std;

int main()
{ 
	char c[3];
	for (int i = 0; i < 3; i++)
	{
		cin >> c[i];
	}


	string ans = "No";
	for (char x : c)
	{
		if (x == '7')
		{
			ans = "Yes";
			break;
		}
	}

	cout << ans;
}

Measured memory_bytes: 3632
N = int(input())
H = list(map(int, input().split()))

ans = []
count = 0

for i in range(N-1):
    if H[i] >= H[i+1]:
        count += 1
    else:
        ans.append(count)
        count = 0
ans.append(count)

print(max(ans))    

Measured memory_bytes: 14252
#include<stdio.h>
int main(){
  int s;
  scanf("%d", &s);
  int b= s%100,a= (s-b)/100;
  if(a < 13 && a!=0){
    if(b < 13 && b!=0) printf("AMBIGUOUS\n"); 
    else printf("MMYY\n");
  }
  else{
    if(b < 13 && b!=0) printf("YYMM\n");
    else printf("NA\n");
  }
  return 0;
}

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

using namespace std;

#define int long long

string S;

int rec(int idx, int out, int val)
{
  if(idx == S.size()) return (out * (val == 0));
  return (rec(idx + 1, out, val * 10 + S[idx] - '0') +
          rec(idx + 1, out + val * 10 + S[idx] - '0', 0));
}

signed main()
{
  cin >> S;
  cout << rec(0, 0, 0) << endl;
}

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

ruiseki=[0]
for i in range(n):
    ruiseki.append(ruiseki[i] + A[i])

mydict={}
for i in range(n+1):
    tmp=ruiseki[i]%m
    if(tmp in mydict):
        mydict[tmp]+=1
    else:
        mydict[tmp]=1


total=0
_list=list(mydict.values())
for i in _list:
    total+=i*(i-1)//2
print(total)

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

typedef long long int ll;

const int MAX = 1e5 + 10;

ll gcd(ll x,ll y){
	if(y==0) return x;
	else return gcd(y,x%y);
}

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

	ll a[MAX]; ll mx=0;

	for(int i=0;i<n;i++) {cin>>a[i]; mx = max(mx,a[i]); if(a[i]==k){cout<<"POSSIBLE"; return 0;}}

	ll g=a[0];

	for(int i=1;i<n;i++) g = gcd(g,a[i]);

	if(k%g == 0){
		if(k <= mx) {cout<<"POSSIBLE";}
		else cout<<"IMPOSSIBLE";
	}	
	else cout<<"IMPOSSIBLE";
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
using ll=long long int;
#define rep(i,n) for(ll i=0;i<n;i++)
const ll INF=1e18;
const int inf=2e9;
const ll MOD=1000000007;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,-1,0,1};

int main(){
    ll N,M;cin>>N>>M;
    N=pow(2,N);
    ll dp[N];
    rep(i,N)dp[i]=INF;
    dp[0]=0;
    rep(i,M){
        ll a,b;cin>>a>>b;
        ll key=0;
        rep(j,b){
            ll c;cin>>c;
            key+=(1<<(c-1));
        }
        rep(j,N){
            dp[j|key]=min(dp[j|key],dp[j]+a);
        }
    }
    if(dp[N-1]==INF)cout<<-1<<endl;
    else cout<<dp[N-1]<<endl;
    return 0;
}

Measured memory_bytes: 512
n,x,*a = map(int,open(0).read().split())
INF = float("inf")
ref = [INF]*n
ans = INF
for i in range(n):
	ref = [min(ref[j],a[(j+i)%n]) for j in range(n)]
	ans = min(ans,sum(ref)+i*x)
print(ans)

Measured memory_bytes: 43100
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repp(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define repm(i,n) for(int (i)=(n);(i)>0;(i)--)
#define INF (1ll<<60)
typedef long long lint;
const lint MOD =1000000007;
const lint MAX = 10000000;

 
lint fac[MAX], finv[MAX], inv[MAX];

void COMinit() // 二項係数を求める時は前処理としてCOMinit()をする
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (lint i = 2; i < MAX; i++)
    {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
 
// 二項係数計算
long long COM(lint n, lint k)
{
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

lint primary(lint num)
{
    if (num < 2) return 0;
    else if (num == 2) return 1;
    else if (num % 2 == 0) return 0; // 偶数はあらかじめ除く

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return 0;
        }
    }

    // 素数である
    return 1;
}


int main(){
    lint N;
    cin>>N;
    lint a[N];
    rep(i,N){
        cin>>a[i];
    }
    lint ans=INF;
    repp(i,-100,101){
        lint l=0;
    rep(j,N){
        l+=(a[j]-i)*(a[j]-i); 
    }
    ans=min(ans,l);
    }
    cout<<ans;
}

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

using namespace std;

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

    vector<long long> vt(n);
    for (int i = 0; i < n; ++i) {
        cin >> vt[i];
    }

    sort(vt.begin(), vt.end());
    long long ans = 0; // 
    if (k < n) {
        ans = accumulate(vt.begin(), vt.begin() + n - k, 0LL);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1792
let KS: [Int] = readLine()!.characters.split(" ").map{ Int(String($0))! }
var res: Int = 0

for x in 0...KS[0] {
    for y in 0...KS[0] {
        let z: Int = KS[1] - x - y
        if 0 <= z && z <= KS[0] { res += 1}
    }
}
print(res)

Measured memory_bytes: 4208
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define mfill(x,y) memset(x,y,sizeof(x))
#define all(v) v.begin(), v.end()
#define in(x,y,h,w) if(0<=x&&x<h&&0<=y&&y<w)
#define y0 y12345
#define y1 y54321

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

using ul = unsigned long;
using ll = long long;
using P = pair<int, int>;
using vint = vector<int>;using vvint = vector<vector<int>>;
using vll = vector<ll>;using vvll = vector<vector<ll>>;
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;}
template <class T>void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
    v.assign(a, vector<T>(b, t));
}
template <class T>T gcd(T &a, T &b){if(a<b){swap(a,b);} T r = a%b; while(r!=0){a=b;b=r;r=a%b;} return b;}

vint dx = {-1, 0, 1, 0}, dy = {0, -1, 0, 1};
vint dx8 = {-1, -1, -1, 0, 1, 1, 1, 0}, dy8 = {-1, 0, 1, 1, 1, 0, -1, -1};
ll mod = 1000000007;
ll pow2(ll x, ll p){
    if(p == 0){return 1;}
    ll ret = pow2(x, p/2);
    return ((ret*ret%mod)*(p%2==1?x:1))%mod;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    debug("debug test\n");
    ll n, a, b;cin>>n>>a>>b;
    ll base = pow2(2, n) - 1;
    
    ll par = 1;
    ll chil = 1;
    for(int i = n;i>n-min(a, n-a);i--){
        //if(i<=n+1-i)break;
        par = par*i%mod;
        chil = chil*(n+1-i)%mod;
    }
    ll minusa = par*pow2(chil, mod-2) % mod;
    par = 1;
    chil = 1;
    for(int i = n;i>n-min(b, n-b);i--){
        //if(i<=n+1-i)break;
        par = par*i%mod;
        chil = chil*(n+1-i)%mod;
    }
    ll minusb = par*pow2(chil, mod-2) % mod;
    debug("nf %d\n", base);
    cout << (base - minusa - minusb + mod*3) % mod << endl;
    return 0;
}


Measured memory_bytes: 256
import numpy as np

def func(x,y):
    if y-x == 2:
        return 1
    else:
        return 0


H,W = map(int,input().split())
l = [input() for i in range(H)]

d = np.zeros((H,W))
dp = np.zeros((H,W))

for i in range(H):
    for j in range(W):
        if l[i][j] == "#":
            d[i][j] = 1
        else:
            d[i][j] = -1



for i in range(H-1):
    dp[i+1][0] = dp[i][0]+func(d[i][0],d[i+1][0])

for i in range(W-1):
    dp[0][i+1] = dp[0][i]+func(d[0][i],d[0][i+1])

for i in range(H-1):
    for j in range(W-1):
        dp[i+1][j+1]=min(dp[i][j+1]+func(d[i][j+1],d[i+1][j+1]),dp[i+1][j]+func(d[i+1][j],d[i+1][j+1]))

a = int(dp[-1][-1])
if d[0][0] == 1:
    a +=1
print(a)


Measured memory_bytes: 21696
#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define REP(i,a,b) for (int i = a; i <b; i++)
typedef long long ll;
#define int ll
typedef vector<int> vi;
typedef vector<long long> vl;
typedef pair<int,int> pi;
#define trace(x) cout<<#x<<"="<<x<<"\n";
#define llp 1000000007
#define mod 1000000007


template < typename F, typename S >
ostream& operator << ( ostream& os, const pair< F, S > & p ) {
    return os << "(" << p.first << ", " << p.second << ")";
}

template < typename T >
ostream &operator << ( ostream & os, const vector< T > &v ) {
    os << "{";
    typename vector< T > :: const_iterator it;
    for( it = v.begin(); it != v.end(); it++ ) {
        if( it != v.begin() ) os << ", ";
        os << *it;
    }
    return os << "}";
}

template < typename T >
ostream &operator << ( ostream & os, const set< T > &v ) {
    os << "[";
    typename set< T > :: const_iterator it;
    for ( it = v.begin(); it != v.end(); it++ ) {
        if( it != v.begin() ) os << ", ";
        os << *it;
    }
    return os << "]";
}

template < typename F, typename S >
ostream &operator << ( ostream & os, const map< F, S > &v ) {
    os << "[";
    typename map< F , S >::const_iterator it;
    for( it = v.begin(); it != v.end(); it++ ) {
        if( it != v.begin() ) os << ", ";
        os << it -> first << " = " << it -> second ;
    }
    return os << "]";
}

#define deb(x) cerr << #x << " = " << x << endl;
struct DSU {
    vector<ll> par;
    vector<ll> sz;
    vector<list<ll>> parts;
    DSU(int n) {
        REP(i, 0, n) {
            par.PB(i);
            sz.PB(1);
            parts.PB({i});
        }
    }

    ll find(ll a) {
        return par[a] = par[a] == a ? a : find(par[a]);
    }

    bool same(ll a, ll b) {
        return find(a) == find(b);
    }

    void unite(ll a, ll b) {
        a = find(a);
        b = find(b);
        if(a == b) return;
        if(sz[a] > sz[b]) swap(a, b);
        // sz[a] <= sz[b]
        sz[b] += sz[a];
        par[a] = b;
        parts[b].splice(parts[b].end(), parts[a]);
    }
};
vector<pair<ll,ll>>edg;
int32_t main(){
    ios::sync_with_stdio(false);
    int n,m;
    cin>>n>>m;

    REP(i,0,m){
        int A,B;
        cin>>A>>B;
        A--;
        B--;
        edg.PB({A,B});
    }
    DSU dd(n);
    //dd.DSU(n);
    vl  aa;
    aa.PB(n*(n-1)/2);
    for(int i=edg.size()-1;i>=0;i--){
        ll ans=aa[aa.size()-1];
        if(dd.find(edg[i].F)!=dd.find(edg[i].S))
        ans-=dd.sz[dd.find(edg[i].F)]*dd.sz[dd.find(edg[i].S)];
        dd.unite(edg[i].F,edg[i].S);
        aa.PB(ans);
    }
    //deb(aa);
    for(int i=aa.size()-2;i>=0;i--){
        cout<<aa[i]<<"\n";
    }
    //cout<<"\n";



    return 0;
}

Measured memory_bytes: 11376
from collections import Counter
def ii():return int(input())
def iim():return map(int,input().split())
def iil():return list(map(int,input().split()))
n = ii()
A = iil()
c = Counter(A)

ans = 0

for k,v in c.items():
    if v < k:
        ans += v
    else:
        ans += v-k
print(ans)

Measured memory_bytes: 18668
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int NIL = -1;
const int MAX = 10000;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */
/* function */
/* main */
int main(){
    string S;
    cin >> S;
    int ans = 0;
    for (char c : S) {
        if (c == '+') ans++;
        else ans--;
    }
    cout << ans << '\n';
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String args[]){
        Scanner scanner = new Scanner(System.in);
        int S = scanner.nextInt();
        int W = scanner.nextInt();

        if(W >= S){
            System.out.println("unsafe");
        } else {
            System.out.println("safe");
        }


        scanner.close();
    }

}


Measured memory_bytes: 27012
if __name__ == "__main__":
    A,B,C = map(int,input().split())
    K = int(input())
    count = 0
    while A>=B:
        B *= 2
        count += 1
    while B>=C:
        C *= 2
        count += 1
    print("Yes" if count <= K else "No")

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

int main(){
    string s;
    cin >> s;
    if(s[0] == s[1] && s[1] == s[2]) cout << "No" << endl;
    else cout << "Yes" << endl;
    return 0;
}

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

using namespace std;
using ll = long long;

//container util
#define SORT(c) sort((c).begin(),(c).end())

//repetition
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)


int main(void){

	
	int N; cin >> N;
	vector<int> d(N);

	REP(i,N) cin >> d[i];

	int ans = 0;
	REP(i,N-1){
		FOR(j,i+1,N){
			ans += d[i] * d[j];
		}
	}

	cout << ans << endl;

	return 0;

}


Measured memory_bytes: 256
N, K = map(int, input().split())

# trees = []
# for _ in range(N)
#    trees.append(int(input()))
trees = [int(input()) for _ in range(N)]

new_trees = sorted(trees)  # .sort()は破壊型なので避ける

d = 10 ** 9
for idx in range(N - K + 1):
    need_d = new_trees[idx + K - 1] - new_trees[idx]
    if d > need_d:
        d = need_d
print(d)

Measured memory_bytes: 8280
#include <cstdio>

using namespace std;

typedef long long ll;

inline ll read()
{
  char ch=getchar();
  ll f = 1, x = 0;
  while (ch < '0' || '9' < ch) {
    if (ch == '-') {f = -1;}
    else {ch = getchar();}
  }
  while ('0' <= ch && ch <= '9') {
    x = 10*x + (ch-'0');
    ch = getchar();
  }
  return f * x;
}

ll n;
ll as[100000];
ll mod = 1000000007;
ll ans = 1;

int main(int argc, char const* argv[])
{
  scanf("%lld", &n);
  for (ll i = 0; i < n; i++) {
    ++as[read()];
  }

  for (ll i = n-1; i > 0; i -= 2) {
    if (as[i] != 2) {
      printf("%d\n", 0);
      return 0;
    }
    (ans*=2)%=mod;
  }

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

  return 0;
}

Measured memory_bytes: 1024
#include <cmath>
#include <iostream>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <bitset>
#include <algorithm>
#include <functional>
#include <utility>
#include <iomanip>

#define int long long int
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )

using namespace std;

typedef pair<int, int> P;

const int INF = 1e15;
const int MOD = 1e9+7;

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

    int n, k;
    cin >> n >> k;
    vector<int> h(n);
    rep(i, n) cin >> h[i];

    int ans = INF;
    sort(ALL(h));
    rep(i, n - k + 1){
        ans = min(ans, h[i+k-1] - h[i]);
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;

int main()
{
	int n, m;
	const int INF = 1 << 30;
	while (cin >> n >> m) {
		if (n == 0 && m == 0)
			break;

		vector<vector<int> > charge(m, vector<int>(m, INF));
		vector<vector<int> > time(m, vector<int>(m, INF));
		for (int i = 0; i < n; ++i) {
			int s, t, c, tm;
			cin >> s >> t >> c >> tm;
			--s;
			--t;
			charge[s][t] = charge[t][s] = c;
			time[s][t] = time[t][s] = tm;
		}

		vector<vector<pair<int, int> > > ans(m, vector<pair<int, int> >(m, pair<int, int>(INF, INF)));
		// dijkstra(charge)
		for (int i = 0; i < m; ++i) {
			ans[i][i].first = 0;
			priority_queue<pair<int, int>, vector<pair<int, int> >, greater<pair<int, int> > > que;
			que.push(pair<int, int>(0, i));
			
			while (!que.empty()) {
				pair<int, int> q = que.top();
				que.pop();
				int v = q.second;
				if (ans[i][v].first < q.first)
					continue;
				for (unsigned int j = 0; j < charge[v].size(); ++j) {
					if (ans[i][j].first > ans[i][v].first + charge[v][j]) {
						ans[i][j].first = ans[i][v].first + charge[v][j];
						que.push(pair<int, int>(ans[i][j].first, j));
					}
				}
			}
		}

		// dijkstra(time)
		for (int i = 0; i < m; ++i) {
			ans[i][i].second = 0;
			priority_queue<pair<int, int>, vector<pair<int, int> >, greater<pair<int, int> > > que;
			que.push(pair<int, int>(0, i));
			
			while (!que.empty()) {
				pair<int, int> q = que.top();
				que.pop();
				int v = q.second;
				if (ans[i][v].second < q.first)
					continue;
				for (unsigned int j = 0; j < time[v].size(); ++j) {
					if (ans[i][j].second > ans[i][v].second + time[v][j]) {
						ans[i][j].second = ans[i][v].second + time[v][j];
						que.push(pair<int, int>(ans[i][j].second, j));
					}
				}
			}
		}

		int k;
		cin >> k;
		for (int i = 0; i < k; ++i) {
			int p, q, r;
			cin >> p >> q >> r;
			--p;
			--q;
			if (r == 0)
				cout << ans[p][q].first << endl;
			else
				cout << ans[p][q].second << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 1076
#include <iostream>
#include <algorithm>
using namespace std;
const int nmax=100005;
struct grm
{
    long long a,b;
}a[nmax];
bool comp(grm unu,grm doi)
{
    return (unu.a+unu.b<doi.a+doi.b);
}
long long ans,sgn;
int x,y,n,i;
int main()
{
    cin>>n;
    for(i=1;i<=n;i++)
    {
        cin>>a[i].a>>a[i].b;
    }
    sort(a+1,a+n+1,comp);
    sgn=1;
    for(i=n;i>=1;i--)
    {
        if(sgn==1) ans+=1LL*a[i].a;
        else ans-=1LL*a[i].b;
        sgn*=-1;
    }
    cout<<ans;
    return 0;
}


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

int main() {
  int n, k;
  cin >> n >> k;
  if((n+1)/2>=k) {
    cout << "YES" << endl;
    return 0;
  }
  else {
    cout << "NO" << endl;
    return 0;
  }
}

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

int main(){

 
  int n;
  int m;
  while(cin >> n >> m){
    vector<int> v;
    vector<int>::iterator it;
    if(n==0&&m==0)
      break;
    for (int i = 1 ; i <= n; i++)
      v.push_back(i);
    it = v.begin();
    int index = m-1;
    while(n!=1){
      v.erase(it+index);
      n--;
      index += m-1;
      if(index>=n)
	index %= n;
    }
    cout << v[0] << endl;
  }

  return 0;
}

Measured memory_bytes: 1228
n, k = map(int, input().split())

def get_min(n, k):
    s = set()
    min_num = n
    while n not in s:
        s.add(n)
        n = k - n
        min_num = min(min_num,n)
    return min_num

print(get_min(n%k,k))

Measured memory_bytes: 3064
n,h = map(int,input().split())
b = []
sum_b = 0
max_a = 0
for _ in range(n):
    ta,tb = map(int,input().split())
    b.append(tb)
    sum_b += tb
    if ta > max_a:
        max_a = ta

b.sort()
sum_b2 = 0
count = 0
bbb = 0

while True:
    if (len(b) > 0):
        bbb=b.pop()
    if bbb > max_a:
        sum_b2 += bbb
        bbb = 0
        count += 1
    else:
        if (h-sum_b2)%max_a == 0:
            print (count + (h-sum_b2)//max_a)
        else:
            print (count + (h-sum_b2)//max_a + 1)
        break
    if sum_b2 >= h:
        print (count)
        break

Measured memory_bytes: 7388
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define RNG(i,from,to) for(int i=(from); i<(int)(to); i++)
#define gcd(i,j) __gcd((i), (j))
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<ll> vecll;
template<typename S, typename T> string to_string(pair<S, T> p) { return "("+to_string(p.first)+","+to_string(p.second)+")"; }
template<typename T> string to_string(T p[2]) { return "["+to_string(p[0])+","+to_string(p[1])+"]"; }
template<typename T> void println(T e){ cout << to_string(e) << endl; }
template<typename T> void println(const vector<T>& v){ cout << "[";for(const auto& e : v){ cout << to_string(e) << ","; }cout << "]";cout << endl; }
template<typename T> void println(const vector<vector<T>>& vv){ for(const auto& v : vv){ println(v); } }
template<typename Iter> void println(Iter first, Iter last){ for(auto it=first; it != last; it++){ cout << *it << " "; }; cout << endl; }
const ll DVSR = 1e9+7;


int main(int argc, char const *argv[])
{
  ll N, res = 10e10;
  cin >> N;
  vecll XS(N);
  REP(i, N) {
    cin >> XS[i];
  }

  RNG(i, 1, 101) {
    ll cost = 0;
    REP(j, N) cost += (XS[j]-i)*(XS[j]-i);
    res = min(cost, res);
  }
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String args[]){
		
		Scanner cin = new Scanner(System.in);
		
		long S = cin.nextLong();
		long c = cin.nextLong();
		
		long count = 0L;
		
		if(2*S<=c){
			count +=S;
			c -=2*S;
			count +=(long)c/4;
		}else{
			count +=(long)c/2;
		}
		
		System.out.println(count);
	}
}


Measured memory_bytes: 23764
K, N = map(int, input().split())
A = list(map(int, input().split()))

diff = [0]*N
diff[N-1] = A[0] + K - A[N-1]
for i in range(N-1):
  diff[i] = A[i+1] - A[i]

ans = sum(diff) - max(diff)
print(ans)

Measured memory_bytes: 32360
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define rrep(i,a,b) for(ll i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()

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

    ll a[n];
    rep(i, 0, n){
        cin >> a[i];
    }

    sort(a, a + n);

    ll b[n];
    b[0] = a[0];
    rep(i, 1, n){
        b[i] = a[i] + b[i - 1];
    }

    ll ans = n;
    rep(i, 0, n - 1){
        if(b[i] * 2 < a[i + 1]){
            ans = n - i - 1;
        }
    }

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


Measured memory_bytes: 1792
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
import java.util.Set;

public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        // Scanner sc = new Scanner("");
        double w = Double.parseDouble(sc.next());
        double h = Double.parseDouble(sc.next());
        double x = Double.parseDouble(sc.next());
        double y = Double.parseDouble(sc.next());
        double  area = w * h / 2;

        int flagBit = 0;

        if(x*2==w && y*2==h){
            flagBit = 1;
        }
        System.out.println(area + " " + flagBit);
        
    }
}

Measured memory_bytes: 22612
#include<bits/stdc++.h>
typedef long long ll;
typedef long double ld;
using namespace std;

#define REP(i, l, n) for(int i=(l), i##_len=(n); i<i##_len; ++i)
#define ALL(x) (x).begin(),(x).end()
#define pb push_back

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

int dx[4] = {-1, 1, 0, 0};
int dy[4] = {0, 0, 1, -1};

int main(){
    int n; cin >> n;
    string s; cin >> s;
    char t = s[0];
    ll ans = 1;
    REP(i, 1, n){
        if(t == s[i]){
            continue;
        }else{
            ans++;
            t = s[i];
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define debug(x) cout << '[' << #x << " is: " << x << "] " <<"\n";
#define sor(v) sort(v.begin(),v.end())
#define rsor(v) sort(v.rbegin(),v.rend())
#define rev(v) reverse(v.begin(),v.end())
#define print(v) for(auto f:v)cout<<f<<" ";
#define printpair(v) for(auto f:v)cout<<f.first<<" "<<f.second<<endl;
#define int long long
vector<int>wt , v ;
vector<vector<int>>dp(1e2 + 1 , vector<int> (1e5 + 1 , -1));
int n , w;
int calc(int idx , int c ){

    if(idx == 0 || c == 0)
        return dp[idx][c] = 0 ;
    if(dp[idx][c] != -1)
        return dp[idx][c];
    int firstc = -1 , secondc = -1 ;
    if(c < wt[idx])
        return dp[idx][c] =  calc(idx - 1 , c) ;
    else {
        firstc = v[idx] + calc(idx - 1 , c - wt[idx] );
        secondc = calc(idx - 1 , c);

    }
    return  dp[idx][c] = max(firstc , secondc) ;


}
int32_t main(){
     ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
    cin >> n >> w ;
    v.resize(n + 1) , wt.resize(n + 1);
   for(int x = 1 ; x <= n ; x++)
        cin >> wt[x] >> v[x] ;
    cout << calc(n  , w );

    return 0;
}


Measured memory_bytes: 80256
a = input()
b = input()
c = input()

la = len(a)
lb = len(b)
lc = len(c)

def match(x,y):
    if x == y or x == "?" or y == "?":
        return True
    return False
    
ab = [True]*15000
ac = [True]*15000
bc = [True]*15000

for i in range(4000-lb,4000+la):
    for j in range(lb):
        if 4000 <= i+j < 4000+la:
            if not match(a[i+j-4000],b[j]):
                ab[i] = False

for i in range(4000-lc,4000+la):
    for j in range(lc):
        if 4000 <= i+j < 4000+la:
            if not match(a[i+j-4000],c[j]):
                ac[i] = False

for i in range(4000-lc,4000+lb):
    for j in range(lc):
        if 4000 <= i+j < 4000+lb:
            if not match(b[i+j-4000],c[j]):
                bc[i] = False

res = la+lb+lc

for i in range(4000-lb-lc,4000+la+lc+1):
    for j in range(0,4000+la+lb+1):
        if ab[i] and ac[j]:
            if (j-i+4000 >= 15000) or bc[j-i+4000]:
                res = min(res, max(4000+la,i+lb,j+lc)-min(4000,i,j))

print(res)





Measured memory_bytes: 53932
#include <iostream>
#include <string>
#include <vector>
#include <cctype>

using namespace std;

const int dx[] = { 0, 1, 0, -1 };
const int dy[] = { -1, 0, 1, 0 };

int main(){
	while(true){
		int W, H;
		cin >> W >> H;
		if(W == 0 && H == 0){ break; }
		vector<string> field;
		field.push_back(string(W + 2, '#'));
		for(int i = 0; i < H; ++i){
			string line;
			cin >> line;
			field.push_back("#" + line + "#");
		}
		field.push_back(string(W + 2, '#'));
		W += 2; H += 2;
		for(int i = 0; i < H; ++i){
			for(int j = 0; j < W; ++j){
				switch(field[i][j]){
				case 'N': field[i][j] = '0'; break;
				case 'E': field[i][j] = '1'; break;
				case 'S': field[i][j] = '2'; break;
				case 'W': field[i][j] = '3'; break;
				}
			}
		}
		int answer = 0;
		while(answer <= 180){
			bool goal = true;
			for(int i = 0; i < H; ++i){
				for(int j = 0; j < W; ++j){
					if(isdigit(field[i][j])){ goal = false; }
				}
			}
			if(goal){ break; }
			++answer;
			for(int i = 0; i < H; ++i){
				for(int j = 0; j < W; ++j){
					if(!isdigit(field[i][j])){ continue; }
					int next = field[i][j] - '0', offset = 'a';
					for(int k = 5; k >= 0; --k){
						next = (field[i][j] - '0' + k) % 4;
						if(field[i + dy[next]][j + dx[next]] == '.'){ offset = '0'; break; }
						if(field[i + dy[next]][j + dx[next]] == 'X'){ offset = '0'; break; }
					}
					field[i][j] = next + offset;
				}
			}
			for(int i = 0; i < H; ++i){
				for(int j = 0; j < W; ++j){
					int c = field[i][j];
					if(c != '.' && c != 'X'){ continue; }
					for(int k = 5; k > 1; --k){
						int x = j + dx[k % 4], y = i + dy[k % 4];
						if(isdigit(field[y][x])){
							int px = x + dx[field[y][x] - '0'], py = y + dy[field[y][x] - '0'];
							if(px != j || py != i){ continue; }
							field[i][j] = c == 'X' ? '*' : field[y][x] - '0' + 'a';
							field[y][x] = '@';
							break;
						}
					}
				}
			}
			for(int i = 0; i < H; ++i){
				for(int j = 0; j < W; ++j){
					int c = field[i][j];
					if(islower(c)){ field[i][j] = c - 'a' + '0'; }
					if(c == '@'){ field[i][j] = '.'; }
					if(c == '*'){ field[i][j] = 'X'; }
				}
			}
		}
		if(answer > 180){
			cout << "NA" << endl;
		}else{
			cout << answer << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 936
#include<bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n ; i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define whole(f, x, ...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x) // decltypeで型取得、引数があればva_argsのところに入れる
using namespace std;
typedef long long ll; // long longをllでかけるようにした
const int INF = 1e9;

int main(void){
    int n; cin >> n;
    int ans = 0;
    for(int i = 0; i <= sqrt(n); i++){
        int tmp = i * i;
        if(tmp <= n) ans = tmp;
    }
    cout <<  ans << endl;
}

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

#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define FOR(i,m,n) for(int i=((int)(m));i<(int)(n);++i)

#include<algorithm>

using namespace std;
typedef long long ll;

int main() {
  int N;
  cin >> N;
  ll a[N];
  REP(i,N) cin >> a[i];
  sort(a,a+N);
  bool ret = true;
  REP(i,N-1){
    if(a[i] == a[i+1]){
      ret = false;
      break;
    }
  }
  if(ret) cout << "YES" << endl;
  else cout << "NO" << endl;
  return 0;
}

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

typedef signed long long ll;
const int MX = 1e6 + 5;
int A[10][10];

string to_s(int n) {
	stringstream ss;
	ss << n;
	return ss.str();
}

int main() {
	int n; cin >> n;
	for(int i = 1; i <= n; i++) {
		string num = to_s(i);
		int st = num[0] - '0', en = num[num.size() - 1] - '0';
		A[st][en]++;
	}

	ll ans = 0;
	for(int i = 1; i <= 9; i++) {
		for(int j = 1; j <= 9; j++) {
			ans += A[i][j] * A[j][i];
		}
	} 

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

Measured memory_bytes: 256
fun main (args : Array<String>) {
	val (a, b, k) = readLine()!!.split(" ")
	var list : MutableList<Long> = mutableListOf()
	var K : Long = k.toLong()
	val N : Long = 0
	list.add(a.toLong())
	list.add(b.toLong())
	if (k.toLong() >= (list[0] + list[1])) {
		return println("0 0")
	}
	if (list[0] >= K) {
		list[0] = list[0] - K
		return println("${list[0]} ${list[1]}")
	} else {
		K = K - list[0]
		list[0] = 0
	}
	if (list[1] >= K) {
		list[1] = list[1] - K
		return println("${list[0]} ${list[1]}")
	} else {
		println("0 0")
	}
}

Measured memory_bytes: 37932
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define int long long
#define double long double
#define mod 1000000007
#define P pair<long long,long long>
#define all(a) a.begin(),a.end()
#define INF 10000000000000000
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using namespace std;

//ABC130
signed main(void){
    cin.tie(0); cout.tie(0);
    ios::sync_with_stdio(false);

    int x,a; cin>>x>>a;
    if(x<a)cout<<0<<endl;
    else cout<<10<<endl;

}

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

long long n,val[100005],w,v,k,mxw,ans;
bool dp[100005]; 
int main(){
	dp[0]=true;
	scanf("%lld%lld",&n,&mxw);
	for (int i=1;i<=n;i++){
		scanf("%lld%lld",&w,&v);
		for (int j=mxw;j>=0;j--){
			if (dp[j]== true && j+w <= mxw){
				dp[j+w]=true;
				val[j+w]=max(val[j+w],val[j]+v);
			}
		}
	}
	ans=0;
	for (int i=mxw;i>=1;i--){
		ans=max(ans,val[i]);
	}
	printf("%lld\n",ans);
	return 0;
} 

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

int main(){
    string moji;
    cin >> moji;
    int len=0;
    for(int i=moji.length()-2;i>0;i-=2){
        len=i/2;//(moji.length()-i)/2;
        bool flag=true;
        for(int j=0;j<len;j++){
            if (moji[j] != moji[j+len]){
                flag=false;
                break;
            }
        }
 //       cout << moji.substr(0,len*2)<<endl;
        if (flag){
            break;
        }
    }
    cout << to_string(len*2) <<endl;
    return 0;
}

Measured memory_bytes: 256
/*我是萌新*/
#include<iostream>
#include<cmath>
#include<cstring>
#include<string>
#include<algorithm>
#include <iomanip> 
typedef long long LL;
const int mod = 1000000009;
using namespace std;
int main()
{
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    LL n, m,x,i,k,r,j;
    while (cin >> n >> m)
    {
        LL* p = new LL[n + 5]; LL ans = 0,min=1,max=n;
        
        for (i = 1; i <=m; i++)
        {
            cin >> k >> r;
            
            for (j = min; j < k; j++)
            {
                p[j] = 1;
            }
            if (j > min) min = j;
            for (j = max; j > r; j--)
            {
                p[j] = 1;
            }
            if (j < max)max = j;
        }
        
        for (i = 1; i <= n; i++)
        {
            if (p[i] == 1){}
            else ans++;
        }
        cout << ans << '\n';
    }
}



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

using namespace std;

int main() {
	int n, m; cin >> n >> m;
	vector<int> a(m + 1, 0);
	int k, tmp;
	for (int i = 0; i < n; ++i) {
		cin >> k;
		while (k--) {
			cin >> tmp;
			a[tmp]++;
		}
	}
	int ans = 0;
	for (int i = 1; i <= m; ++i)
		if (a[i] == n) ans++;

	cout << ans << endl;

	return 0;
}

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

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

  int cake_max = N / 4;
  int donut_max = N / 7;

  bool enabling = false;
  for (int i = 0; i <= cake_max; i++) {
    for (int j = 0; j <= donut_max; j++) {
      int sum = 4 * i + 7 * j;
      if (sum == N) {
        enabling = true;
      }
    }
  }

  cout << (enabling ? "Yes" : "No") << endl;
  return 0;
}

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

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
#include <string>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cmath>
#include <climits>
#include <bitset>
#include <array>
#include <deque>
#include <queue>
#include <map>
#include <set>
#define all(x) (x).begin(),(x).end()

const int MOD = 1e9 + 7;

void solve(){

}
int N;

int getDigit(int n) {
    int ret = 0;
    while (n != 0) {
        ++ret;
        n /= 10;
    }
    return ret;
}

//n進数 d桁までの全探査
//Need setting data type of return value 
int allDec(int n, int d){
    int ret = 0;
    vector<int> t(d,0);
    for (int i = 0; i < pow(n,d); i++){
        int x = i;
        for (int k = 0; k < d; k++){
            t[k] = x % n;
            x /= n;
        }
        int cnt[3] = {};
        string num = "";
        for (int k = 0; k < d; k++){
            //t[k] == 0 ~ N-1の時それぞれの場合分け
            if (t[k] == 0){
                cnt[0]++;
                num += '3';
            } else if (t[k] == 1){
                cnt[1]++;
                num += '5';
            } else {
                cnt[2]++;
                num += '7';
            }
        }

        bool ok = true;
        for (int k = 0; k < 3; k++) {
            if (cnt[k] == 0) {
                ok = false;
            }
        }
        if (ok) { 
            if (stoi(num) <= N) {
                ret++;
            }
        }
    }
    return ret;
}
int main(){
    cin >> N;

    int ans = 0;
    for (int i = 3; i <= getDigit(N); ++i) {
        ans += allDec(3, i);
    }
    cout << ans << endl;

    return 0;
}


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

#define ms(s, n) memset(s, n, sizeof(s))
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define FORd(i, a, b) for (int i = (a) - 1; i >= (b); i--)
#define FORall(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
#define sz(a) int((a).size())
#define present(t, x) (t.find(x) != t.end())
#define all(a) (a).begin(), (a).end()
#define uni(a) (a).erase(unique(all(a)), (a).end())
#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define prec(n) fixed<<setprecision(n)
#define bit(n, i) (((n) >> (i)) & 1)
#define bitcount(n) __builtin_popcountll(n)
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pi;
typedef vector<int> vi;
typedef vector<pi> vii;
const int MOD = (int) 1e9 + 7;
const int INF = (int) 1e9;
const ll LINF = (ll) 1e18;
const ld PI = acos((ld) -1);
const ld EPS = 1e-9;
inline ll gcd(ll a, ll b) {ll r; while (b) {r = a % b; a = b; b = r;} return a;}
inline ll lcm(ll a, ll b) {return a / gcd(a, b) * b;}
inline ll fpow(ll n, ll k, int p = MOD) {ll r = 1; for (; k; k >>= 1) {if (k & 1) r = r * n % p; n = n * n % p;} return r;}
template<class T> inline int chkmin(T& a, const T& val) {return val < a ? a = val, 1 : 0;}
template<class T> inline int chkmax(T& a, const T& val) {return a < val ? a = val, 1 : 0;}
template<class T> inline T isqrt(T k) {T r = sqrt(k) + 1; while (r * r > k) r--; return r;}
template<class T> inline T icbrt(T k) {T r = cbrt(k) + 1; while (r * r * r > k) r--; return r;}
inline void addmod(int& a, int val, int p = MOD) {if ((a = (a + val)) >= p) a -= p;}
inline void submod(int& a, int val, int p = MOD) {if ((a = (a - val)) < 0) a += p;}
inline int mult(int a, int b, int p = MOD) {return (ll) a * b % p;}
inline int inv(int a, int p = MOD) {return fpow(a, p - 2, p);}

const int maxn = 100000 + 10;
int n;
string s;
set<pi> st;
set<int> pos;

void upd(int k) {
	if (k == -1) return;
	set<pi>::iterator it1 = st.lower_bound(mp(k, -INF)), it2 = it1;
	if (it1-- != st.begin() && ++it2 != st.end()) {
		if (it1->se != it2->se) {
			pos.insert(k);
		}
		else {
			if (present(pos, k)) {
				pos.erase(k);
			}
		}
	}
}

void rem(int k) {
	set<pi>::iterator it = st.lower_bound(mp(k, -INF)), it1 = it, it2 = it;
	int ix1 = -1, ix2 = -1;
	if (it1-- != st.end()) {
		ix1 = it1->fi;
	}
	if (++it2 != st.end()) {
		ix2 = it2->fi;
	}
	st.erase(mp(k, s[k]));
	upd(ix1), upd(ix2);
}

void solve() {
	cin >> s;
	n = sz(s);
	FOR(i, 0, n) {
		st.insert(mp(i, s[i]));
	}
	FOR(i, 0, n) upd(i);
	int ans = 0;
	while (sz(pos)) {
		int u = *pos.begin();
		pos.erase(u);
		rem(u);
		ans++;
	}
	if (ans & 1) {
		cout << "First\n";
	}
	else {
		cout << "Second\n";
	}
}

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);
#ifdef _LOCAL_
	freopen("in.txt", "r", stdin); //freopen("out.txt", "w", stdout);
#endif
	solve();
#ifdef _LOCAL_
	//printf("\nTime elapsed: %dms", 1000 * clock() / CLOCKS_PER_SEC);
#endif
	return 0;
}

Measured memory_bytes: 9552
#include <bits/stdc++.h>
#define va first
#define vb second
#define lb lower_bound
#define ub upper_bound
#define pp push_back
#define ep emplace_back
#define all(v) (v).begin(),(v).end()
#define szz(v) ((int)(v).size())
#define psm partial_sum
#define acm accumulate
#define fio ios_base::sync_with_stdio(0);cin.tie(0);
using namespace std;
using ll = long long; using lf = long double;
using pii = pair<int,int>; using ppi = pair<int,pii>;
using pss = pair<short,short>; using pll = pair<ll,ll>;
const lf PI = 3.14159265358979323846264338L;
template <typename T>
inline T umax(T& u, T v){return u = max(u, v);}
template <typename T>
inline T umin(T& u, T v){return u = min(u, v);}

int n, m;
int rep[100005];
int f(int x){return x == rep[x] ? x : rep[x] = f(rep[x]);}
int c(int x, int y){
    x = f(x); y = f(y);
    if(x != y){
        rep[y] = x;
        return 1;
    }
    return 0;
}
pii E[100005];
vector<int> G[100005];
bool vis[100005];
int odeg[100005];

int dfs(int x){
    vis[x] = 1;
    for(int e : G[x]){
        int u = E[e].va + E[e].vb - x;
        if(vis[u]) continue;
        int v = dfs(u);
        if(v != (E[e].va == u)) swap(E[e].va, E[e].vb);
        odeg[x] ^= (E[e].va == x);
    }
    return odeg[x];
}

int main(){
    fio;
    cin >> n >> m;
    if(m & 1){
        cout << -1 << '\n';
        return 0;
    }
    iota(rep + 1, rep + n + 1, 1);
    for(int i = 0; i < m; i++){
        cin >> E[i].va >> E[i].vb;
        if(c(E[i].va, E[i].vb)){
            G[ E[i].va ].pp(i);
            G[ E[i].vb ].pp(i);
        }else{
            odeg[ E[i].va ] ^= 1;
        }
    }
    dfs(1);
    for(int i = 0; i < m; i++){
        cout << E[i].va << ' ' << E[i].vb << '\n';
    }
}

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

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vint;
typedef vector<double> vd;
typedef vector<ll> vll;
typedef vector<string> vstr;
typedef vector<vector<int>> vvint;
typedef vector<pair<int, int>> vpii;
typedef vector<pair<ll, ll>> vpll;
typedef priority_queue<int, vector<int>, greater<int>> spqint; //小さい順に取り出し
typedef priority_queue<ll, vector<ll>, greater<ll>> spqll;     //小さい順に取り出し
typedef priority_queue<int, vector<int>, less<int>> bpqint;    //大きい順に取り出し
typedef priority_queue<ll, vector<ll>, less<ll>> bpqll;        //大きい順に取り出し

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (int)a; i < (int)b; i++)
#define IREP(i, v) for (auto i = (v).begin(); i != (v).end(); i++)
#define FI first
#define SE second
#define MP make_pair
#define MT make_tuple
#define PB push_back
#define PF push_front
#define TS to_string
#define BS binary_search
#define LB lower_bound
#define UB upper_bound
#define NP next_permutation
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) (ll) x.size()
#define SP(x) setprecision((ll)x)

int INF = 1e9;
int NIL = -1;
ll MOD = 1000000007;
ll LINF = 1e18;
double EPS = 1e-9;
double PI = M_PI;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } //最大公約数
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }     //最小公倍数

void yes(){ cout << "Yes" << endl;}
void no(){ cout << "No" << endl;}
//-----------------------------------------

//-----------------------------------------
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    std::chrono::system_clock::time_point start,end;
    start = std::chrono::system_clock::now();

    string s ;
    cin >> s ;
    int n = SZ(s) ;
    set<string> set ;
    int k ;
    cin >> k ;
    FOR(i,1,k+1){
        REP(j,n-i+1){
            set.insert(s.substr(j,i)) ;
        }
    }
    REP(i,k-1){
        set.erase(set.begin()) ;
    }
    cout << (*set.begin()) <<endl;


    end = std::chrono::system_clock::now();
    auto elapsed = std::chrono::duration_cast< std::chrono::milliseconds >(end - start).count();
    //std::cout << elapsed <<"ms"<< std::endl;

    

    return 0;
}



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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define MAXN 1000010
#define rep(i,n) for (int i = 0; i < (n); ++i)
const ll mod = 1e9+7;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

bool pairCompare(const P& firstElof, const P& secondElof)
{
    return firstElof.second < secondElof.second;
}

// 素因数分解する 
// たとえば 60 = 2^2 x 3 x 5 だったら {(2, 2), (3, 1), (5, 1)} を返す
vector<pair<ll, ll> > prime_factorize(ll n) {
    vector<pair<ll, ll> > res;
    for (ll p = 2; p * p <= n; ++p) {
        if (n % p != 0) continue;
        int num = 0;
        while (n % p == 0) { ++num; n /= p; }
        res.push_back(make_pair(p, num));
    }
    if (n != 1) res.push_back(make_pair(n, 1));
    return res;
}

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

ll lcm(ll a, ll b) {
    return a*b/gcd(a, b);
}


ll n;
int main() {
    cin >> n;
    auto pf = prime_factorize(n);
    ll j;
    ll ans = 0;
    vector<int> li(50);
    ll t = 0;
    for(int i=0; i<50; ++i) {
        t += i;
        li[i] = t;
    }

    for(int i=0; i<pf.size(); ++i) {

        int j = 1;
        while(pf[i].second > li[j]) {
            if (li[j+1] > pf[i].second) break;
            ++j;
        }
        ans += j;

    }

    cout << ans << endl;
}


Measured memory_bytes: 3636
import java.util.Scanner

object Main {
  val sc = new Scanner(System.in)
  def main(args: Array[String]): Unit = {

    val a = sc.nextInt
    val b = sc.nextInt

    val res =
      if(a >= 13) b
      else if (a >= 6) b /2
      else 0

    println(res)
  }
}


Measured memory_bytes: 27328
#include <stdio.h>

int main(void) {
	char Class[11][16] = {"light fly", "fly", "bantam", "feather", "light", "light welter", "welter", "light middle", "middle", "light heavy", "heavy"};
	double weight;
	int number;
	while (scanf("%lf", &weight) != EOF) {
		if (weight <= 48.00)
			number = 0;
		else if (weight <= 51.00)
			number = 1;
		else if (weight <= 54.00)
			number = 2;
		else if (weight <= 57.00)
			number = 3;
		else if (weight <= 60.00)
			number = 4;
		else if (weight <= 64.00)
			number = 5;
		else if (weight <= 69.00)
			number = 6;
		else if (weight <= 75.00)
			number = 7;
		else if (weight <= 81.00)
			number = 8;
		else if (weight <= 91.00)
			number = 9;
		else
			number = 10;
		printf("%s\n", Class[number]);
	}
	return 0;
}

Measured memory_bytes: 604