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

struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

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

    UnionFind tree(N);

    vector<int> p(N), c(N);

    for(int i = 0; i < N; i++) {
        cin>>p[i];
        p[i]--;
    }
    for(int i=0;i<N;++i){
        tree.unite(p[p[i]],p[i]);
    }
    for(int i = 0; i < N; i++) {
        cin>>c[i];
    }
    if(K==1){
        sort(c.begin(),c.end());
        cout<<c[N-1]<<endl;
        return 0;
    }
    set<int>a;
    for(int i=0;i<N;++i){
        a.insert(tree.root(p[i]));
    }
    long long ans=-1e18;
    for(auto x:a){
        int s=x;
        vector<int>b;
        for(int j=0;j<N;++j){
            b.push_back(s);
            s=p[s];
            if(s==b[0])break;
        }
        int size=b.size();
        long long sum[size+1];
        sum[0]=0;
        for(int j=0;j<size;++j){
            sum[j+1]=sum[j]+c[b[j]];
        }
        if(K%size==0){
            ans=max(ans,sum[size]*(K/size));
        }
        else if(K/size>0){
            ans=max(ans,sum[size]*(K/size-1));
        }
        for(int j=0;j<size;++j){
            long long preto=-1e18;
            for(int k=1;k<=size;++k){
                if(j+k<=size){
                    preto=max(preto,sum[j+k]-sum[j]);
                }
                else{
                    preto=max(preto,(sum[size]-sum[j])+sum[k-(size-j)]);
                }
                if(K/size>0){
                    if(sum[size]>0){
                        if(K%size<k){
                            ans=max(ans,preto+sum[size]*(K/size-1));
                        }
                        else ans=max(ans,preto+sum[size]*(K/size));
                    }
                    else ans=max(ans,preto);
                }
                else{
                    if(k<=K){
                        ans=max(ans,preto);
                    }
                }
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3756
//#include "pch.h"
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <limits.h>
#include <string>
#include <stack>
#include <deque>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <time.h>
#include <cassert>
#include <fstream>
#include <stdio.h>
#include<unordered_map>

typedef long long ll;
typedef std::pair<int, int> Pii;
typedef std::pair<long long, long long> Pll;
typedef std::pair<double, double> Pdd;

#define rip(i, n, s) for (int i = (s);i < (int)( n ); i++)
#define mapa make_pair
#define all(a) a.begin(), a.end()
#define MM << " " <<

template<typename T>
using MaxHeap = std::priority_queue<T>;
template<typename T>
using MinHeap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

template<typename T>
inline bool chmax(T &a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
template<typename T>
inline bool chmin(T &a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}

template<typename T>
std::vector<T> vec(int len, T elem) { return std::vector<T>(len, elem); }
template<typename T>
void vdeb(std::vector<T> &da) {
	for (int i = 0;i < da.size();i++) {
		if (i == da.size() - 1) std::cout << da[i];
		else std::cout << da[i] << ' ';
	}
	std::cout << std::endl;
}
template<typename T>
void vdeb(std::vector<std::vector<T>> &da) {
	for (int i = 0;i < da.size();i++) vdeb(da[i]);
	std::cout << std::endl;
}

using namespace std;

int main(){
    int n; cin >> n;
    vector<int> da(n);
    rip(i,n,0) cin >> da[i];
    map<int, ll> mp;
    rip(i,n,0){
        if(mp.count(da[i])){
            mp[da[i]] ++;
        }
        else{
            mp[da[i]] = 1;
        }
    }
    ll pre = 0;
    for(auto i: mp){
        pre += i.second*(i.second-1)/2;
    }
    vector<ll> ans(n);
    rip(i,n,0){
        ans[i] = pre - mp[da[i]]+1;
    }
    rip(i,n,0) cout << ans[i] << endl;
}

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

int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  if ((A + B) > (C + D))
   cout << "Left" << endl;
  else if ((A + B) < (C + D))
   cout << "Right" << endl;
  else
   cout << "Balanced" << endl;
  
}

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

int main(){
  long long n,k;
  cin >> n >> k;
  vector<long long> a(n);
  for (int i=0; i<n;i++){
    cin >> a[i];
  }
  for (int i=k; i<n; i++){
    if (a[i] > a[i-k]) {
      cout << "Yes" << endl;
    }
    else{
      cout << "No" << endl;
    }
  }
}

Measured memory_bytes: 4768
//
//  main.cpp
//  atcoder-sushi2
//
//  Created by r on 6/14/19.
//  Copyright © 2019 r. All rights reserved.
//

#include <iostream>
#include <algorithm>
#include <cstring>
#include <iomanip>
#include <fstream>
#include <cmath>
#include <vector>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <map>
#include <stack>
#include <queue>
#include <assert.h>
#include <limits>
#include <cstdio>
using namespace std;

//#define RDEBUG 1
#ifdef RDEBUG
#define D(x) x
#else
#define D(x)
#endif
#define inf 0x7fffffff
#define MOD 1000000007

typedef long long ll;


ll add(ll a, ll b) {
    a += b;
    if(a >= MOD) {
        a -= MOD;
    }
    return a;
}
ll sub(ll a, ll b) {
    a -= b;
    if(a < 0) {
        a += MOD;
    }
    return a;
}
void add_self(ll& a, ll b) {
    a = add(a, b);
}
void sub_self(ll& a, ll b) {
    a = sub(a, b);
}

const ll MAXN = 310;

ll plates[MAXN];
double N;
double dp[MAXN][MAXN][MAXN];
ll s[4];


int main() {
    ios_base :: sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> N;
    for (int i = 0; i<N; i++) {
        cin >> plates[i];
        s[plates[i]]++;
    }
    dp[s[1]][s[2]][s[3]] = 1;
    double cnt = 0;
    for (ll k = s[3]; k>=0; k--) {
        for (ll j = s[2]+s[3]-k; j>=0; j--) {
            for (ll i = s[1]+s[2]+s[3]-j-k; i>=0; i--) {
                if (i == 0 && j == 0 && k == 0) {
                    continue;
                }
                cnt+=(double)dp[i][j][k]*N/(i+k+j);
                if (k>0) dp[i][j+1][k-1]+=dp[i][j][k] * k / (i+j+k);
                if (j>0) dp[i+1][j-1][k]+=dp[i][j][k] * j / (i+j+k);
                if (i>0) dp[i-1][j][k]+=dp[i][j][k] * i / (i+j+k);
            }
        }
    }
    
    cout << std::fixed;
    cout << setprecision(10);
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 225536
var  f,g:text; i,p:longint; n,a,b,k,tong,so,tong1,tong2:int64;
      gt,rev,rev1:array[0..300010] of int64;


 function mu(a1,b1,p1:int64):int64;
 var q:int64;
 begin
   if b1=0 then exit(1);

   q:=mu(a1,b1 div 2,p1);
   if b1 mod 2 = 0 then exit(q*q mod p1)
    else exit(q*q mod p1 *a1 mod p1);
 end;

 begin

  gt[0]:=1;
  p:=998244353; rev[0]:=1;
  for i:=1 to 300005 do
  begin
   gt[i]:=gt[i-1] * i mod p
  end;
  for i:=1 to 300005 do
   begin
    rev[i]:=mu(gt[i],p-2,p);
    end;

// write(g,((gt[n]* (rev[i] mod p)) mod p * (rev[n-i] mod p)) mod p ,' ');

  readln(n,a,b,k);
   //n:=90081; a:=33447; b:=90629; k:=6391049189;
   //n:=4; a:=1; b:=2; k:=5;
  tong:=0;
  for i:=0 to n do
   begin
    if (k-i*A)<0 then break;
    if (k-i*A) mod b = 0 then
     begin
     so:=(k-i*A) div B;
     if n<i then tong1:=0 else tong1:=gt[n]* rev[i]  mod p * rev[n-i] mod p ;
     if n<so then tong2:=0 else tong2:=gt[n]* rev[so]  mod p * rev[n-so] mod p;
     tong:=(tong+tong1*tong2 mod p) mod p;
     end;
   end;
  write(tong);

  end.


Measured memory_bytes: 6144
import numpy as np

N, D = map(int, input().split(" "))
X = []
for _ in range(N):
    x = list(map(int, input().split(" ")))
    X.append(x)

X = np.array(X)
count = 0
for i in range(N - 1):
    for j in range(i + 1, N):
        x1, x2 = X[i], X[j]
        dist = np.sqrt(((x1 - x2) ** 2).sum())
        if dist - int(dist) < 1e-10:
            count += 1
print(count)

Measured memory_bytes: 12424
#include "bits/stdc++.h"

#define rep(a,b) for(int a = 0;a < b;a++)
#define REP(i, x, n) for(int i = x; i < n; i++)
#define P(a) cout << a << endl
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define ssort(v) sort(v.begin(),v.end())
#define rev(v) reverse(v.begin(),v.end())
#define vP(v) for(int i = 0;i < v.size();i++){cout << v[i];if(i != v.size()-1)cout << endl;}
#define vcin(v,n) rep(i,n){int a;cin >> a;v.pb(a);}

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
int dx[] = { 1, -1 , 0 , 0 };
int dy[] = { 0,  0,  1, -1 };
ll MOD = 1000000007;

void solve(){
	int a,b;
	cin >> a >> b;
	a--;b--;
	P(a*b);
}

int main() {
    solve();
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <numeric>
#include <stdio.h>
#include <iomanip>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;
using ll = long long;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
int Max(int(a), int(b), int(c)) {
	return max(max(a, b), c);
}
int Min(int(a), int(b), int(c)) {
	return min(min(a, b), c);
}





int main() {
	ll N, K, an=0;
	cin >> N >> K;
	rep(i, N) {
		ll a;
		cin >> a;
		an += min(a, K - a);
	}
	cout << 2*an << endl;
}


Measured memory_bytes: 256
// वाह मोदी जी वाह!

#include<iostream>
#include<algorithm>
#include<bitset>

#include<cmath>
#include<cstring>
#include<climits>

#include<deque>
#include<vector>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>

#include<fstream>
#include<chrono>
using namespace std;

typedef long long LL;
typedef pair<LL,LL> p64;
typedef vector<LL> v64;

#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define rep(i,s,e) for(int i=s;i<=e;i++)
#define brep(i,s,e) for(int i=s;i>=e;i--)
#define all(x) x.begin(),x.end()
#define mem(x,y) memset(x,y,sizeof(x))
#define DANGER std::ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)

int main()
{
    // DANGER;
    ofstream out("output.txt");

    auto start = chrono::high_resolution_clock::now();
    
    LL n;
    cin>>n;

    LL a[n];
    rep(i,0,n-1) cin>>a[i];

    // LL i = 0, j = 0, mx = 0;
    // while( j<n && i<n )
    // {

    // }

    LL cur = 0, mx = 0;
    rep(i,1,n-1)
    {
        if( a[i]<=a[i-1] ) cur++;
        else cur = 0;
        mx = max( mx,cur );
    }
    
    cout<<mx<<endl;

    auto stop = chrono::high_resolution_clock::now();
    // auto duration = chrono::duration_cast<chrono::milliseconds>(stop - start); 
    // cout << "Time taken by function: " << duration.count() << " milliseconds" << endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define ll long long
using namespace std;

int dp[10001];

int main(){
    int n,m;
    scanf(" %d %d",&n,&m);
    char ma[n][m];
    for(int i = 0; i < n;++i)
        for(int j = 0; j < m;++j) scanf(" %c",&ma[i][j]);
    dp[m-1] = 1;
    for(int i = m-2; i > -1;--i)
        if(ma[n-1][i] != '#') dp[i] = dp[i+1];
    for(int i = n-2;i > -1;--i){
        for(int j = m-1;j > -1;--j){
            if(ma[i][j] == '#'){
                dp[j] = 0;
                continue;
            }
            if(j != m-1) dp[j] += dp[j+1];
            if(dp[j] >= 1000000007) dp[j] -= 1000000007;
        }
    }
    printf("%d\n",dp[0]);
    return 0;
}


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

#define INF (1<<31)-1
#define LINF (1LL<<63)-1LL
#define MOD 1000000007
#define MOD2 998244353

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

#define rep(i,n) for(int i=0,_i=(n);i<_i;++i)
#define rep1(i,a,b) for(int a_=(a),b_=(b),i=a_;i<b_;++i)
#define repr(i,n) for(int _i=(n),i=_i;i>0;--i)

#define db(x) cerr<<#x<<" = "<<x<<" ";
#define db2(x,y) cerr<<"("<<#x<<", "<<#y<<") = ("<<x<<", "<<y<<") ";
#define db3(x,y,z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = ("<<x<<", "<<y<<", "<<z<<") ";
#define ln cout<<endl;

#define all(a)  (a).begin(),(a).end()
#define dig(n)  to_string(n).length()

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define se second
#define fi first

typedef long long ll;

typedef pair<int,int> P;
typedef pair<int,P> iP;
typedef pair<P,P> PP;

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

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

int main(){

    bool flag=false;
    ll ans=0;

    int n,k;
    cin>>n>>k;

    ll p = n/k;
    ans += p*p*p;

    if(k%2 == 0){
        ll q = (n/(k/2))-p;
        ans += q*q*q;
    }

    cout<<ans<<endl;

    //cout <<fixed<<setprecision(16)<< << endl;

    //if(flag)cout << "Yes" <<endl;
    //else cout << "No" <<endl;

    return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include <algorithm>
#include <vector>
#include <cstdio>
using namespace std;
const int Maxn=100005;
const int mod=1000000007;
int n,m,a[Maxn],b[Maxn];
bool notok[Maxn];
int lef[Maxn],rig[Maxn];
vector <int> un;
vector <pair <int,int> > seq;
int rmq[Maxn];
inline void add(int x,int val){for (int i=x;i>0;i-=i&-i) rmq[i]=(rmq[i]+val)%mod;}
inline int sum(int x){int res=0;for (int i=x;i<Maxn;i+=i&-i) res=(res+rmq[i])%mod;return res;}
int main()
{
	scanf("%d %d",&n,&m);
	for (int i=0;i<n;i++) scanf("%d",&a[i]);
	for (int j=0;j<m;j++) scanf("%d",&b[j]);
	for (int i=0;i<n;i++)
	{
		int ind=upper_bound(b,b+m,a[i])-b;
		if (!ind || ind==m)
		{
			notok[i]=true;
			continue;
		}
		lef[i]=a[i]-b[ind-1];
		rig[i]=b[ind]-a[i];
		un.push_back(rig[i]);
	}
	sort(un.begin(),un.end());un.erase(unique(un.begin(),un.end()),un.end());
	for (int i=0;i<n;i++) if (!notok[i])
	{
		int tk=lower_bound(un.begin(),un.end(),rig[i])-un.begin()+1;
		seq.push_back(make_pair(-lef[i],tk));
	}
	sort(seq.begin(),seq.end());seq.erase(unique(seq.begin(),seq.end()),seq.end());
	add(Maxn-1,1);
	for (int i=0;i<seq.size();i++)
	{
		int ind=seq[i].second;
		add(ind,sum(ind+1));
	}
	printf("%d\n",sum(1));
	return 0;
}


Measured memory_bytes: 3320
import sys
N = int(input())
city_ls = list()
for i in range(N):
    city_ls.append([int(i) for i in sys.stdin.readline().split()])
sort_by_x = sorted([[i, j] for i,j in city_ls], key=lambda x:x[0])
G = []
pos2id = {tuple(j) : i for i, j in enumerate(city_ls)}
for i in range(len(sort_by_x)-1):
    current_by_x = sort_by_x[i]
    next_by_x = sort_by_x[i + 1]
    G.append((abs(current_by_x[0] - next_by_x[0]),current_by_x, next_by_x))
sort_by_x.sort(key=lambda x:x[1])
for i in range(len(sort_by_x) - 1):
    current_by_x = sort_by_x[i]
    next_by_x = sort_by_x[i + 1]
    G.append((abs(current_by_x[1] - next_by_x[1]), current_by_x, next_by_x))
G.sort(key=lambda x:x[0])
sum_cost = 0
par = [i for i in range(N)]
rank = [1 for i in range(N)]
def find(x):
    if par[x] == x:
        return x
    else:
        return find(par[x])

def unite(x, y):
    x = find(x)
    y = find(y)
    if x == y:
        pass
    else:
        if rank[x] > rank[y]:
            par[y] = x
            rank[x] += rank[y]
        else:
            par[x] = par[y]
            rank[y] += rank[x]

def is_same(x, y):
    if find(x) == find(y):
        return True
    else:
        return False

for i in G:
    (cost, _from, _to) = i
    _from = pos2id[tuple(_from)]
    _to = pos2id[tuple(_to)]
    if is_same(_from, _to):
        continue
    unite(_from, _to)
    sum_cost += cost
print(sum_cost)

Measured memory_bytes: 77676
A=int(input())
B=int(input())
C=int(input())
X=int(input())
count=0

for a in range(A+1):
  for b in range(B+1):
    for c in range(C+1):
      if (a*500+b*100+c*50) == X:
        count+=1
        
print(count)

Measured memory_bytes: 3060
from collections import deque

h,w=map(int,input().split())
l=[]
c=0
for i in range(h):
 t_l=list(input())
 c+=t_l.count('#')
 l.append(t_l)

sy,sx=0,0
gy,gx=h-1,w-1

dist=[[-1]*w for i in range(h)]
dist[0][0]=0

que=deque()
que.append((sy,sx))

while que:
 y,x=que.popleft()

 if y==gy and x==gx and dist[gy][gx]==c-1:
  print('Possible')
  exit()

 for dy,dx in [[1,0],[0,1]]:
  ny=y+dy
  nx=x+dx
  if ny<=h-1 and nx<=w-1 and l[ny][nx]=='#' and dist[ny][nx]==-1:
   que.append((ny,nx))
   l[ny][nx]=='.'
   dist[ny][nx]=dist[y][x]+1

print('Impossible')

Measured memory_bytes: 3316
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(i=0;i<(n);i++)
#define loop(i,a,n) for(i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;

int main(void) {
    int i,j;
    int a,b;
    cin >> a >> b;
    cout << (a-1)*(b-1) << endl;

}


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

bool chmin(int &x, const int y) {
    if (x > y) {
        x = y;
        return true;
    }
    return false;
}

struct edge {
    int from, to, cost;
    edge(int from, int to, int cost) : from(from), to(to), cost(cost) {}
};

vector<int> bellman_ford(vector<edge> &graph, int n, int s) {
    const int inf = 1LL << 60;
    vector<int> dist(n, inf);
    vector<bool> flag(n, false);

    dist[s] = 0;
    rep(i, 0, n - 1) {
        for (auto e : graph) {
            if (dist[e.from] == inf) continue;
            chmin(dist[e.to], dist[e.from] + e.cost);
        }
    }

    for (auto e : graph) {
        if (dist[e.from] == inf) continue;
        if (chmin(dist[e.to], dist[e.from] + e.cost)) flag[e.to] = true;
        if (flag[e.from]) flag[e.to] = true;
    }

    if (flag[n - 1]) return vector<int>();
    return dist;
}

signed main() {
    int n, m;
    cin >> n >> m;

    vector<edge> graph;
    rep(i, 0, m) {
        int a, b, c;
        cin >> a >> b >> c;
        graph.push_back(edge(--a, --b, -c));
    }

    auto ans = bellman_ford(graph, n, 0);
    if (ans.size()) {
        cout << -ans[n - 1] << endl;
    } else {
        cout << "inf" << endl;
    }
    
    return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
constexpr int64_t mod=1e9+7;

int64_t gcd(int64_t a,int64_t b){
  return (a%b==0)? b:gcd(b,a%b);
}

int main()
{
  int64_t n,k;
  cin>>n>>k;
  vector<int64_t> a(n);
  for(auto&& e: a) {
    cin>>e;
  }
  int64_t max=*max_element(a.begin(), a.end());
  if(k>max){
    cout<<"IMPOSSIBLE";
    return 0;
  }
  for(auto&& e: a) {
    if(k==e){
      cout<<"POSSIBLE";
      return 0;
    }
  }
  int64_t tmp=a[0];
  for (int i = 1; i < n; ++i)
  {
    tmp=gcd(tmp,a[i]);
  }
  if(k%tmp==0){
    cout<<"POSSIBLE";
    return 0;
  }
  else{
    cout<<"IMPOSSIBLE";
  }
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define rep(i,m,n) for(int (i)=(int)(m);(i)<(int)(n);++(i))
#define rREP(i,m,n) for(int (i)=(n)-1;(i)>=(m);--(i))
#define all(x) (x).begin(),(x).end()
#define out(y,x,h,w) (y)<0||(x)<0||(y)>=(h)||(x)>=(w)
constexpr int INF = 1000000001;
constexpr ll mod = 1000000007;
constexpr double PI = 3.1415926535897932;

template<class T>inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
template<class T>inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
inline void init() {
	cin.tie(nullptr); cout.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

int main() {
	init();

	ll x; cin >> x;
	rep(i, 0, 201) {
		ll A = pow((ll)i, 5);
		rep(j, 0, 201) {
			ll B = pow((ll)j, 5);
			if (A + B == x) {
				cout << i << " " << -j << "\n";
				return 0;
			}
			else if (A - B == x) {
				cout << i << " " << j << "\n";
			}
		}
	}

	return 0;
}


Measured memory_bytes: 4076
#include <iostream>
//#include <iomanip>
//#include <string>
#include <vector>
#include <algorithm>
//#include <utility>
//#include <set>
//#include <map>
//#include <queue>
//#include <deque>
//#include <bitset>
//#include <math.h>
using namespace std ;
using ll = long long ;
//using ld = long double ;
using vll = vector<ll> ;
//using vvll = vector<vll> ;
//using vc = vector<char> ;
//using vvc = vector<vc> ;
//using vb = vector<bool> ;
//using vvb = vector<vb> ;
//using pll = pair<ll,ll> ;
#define all(v) v.begin(),v.end()
//ll mod = 1000000007 ;
//long double pie = acos(-1) ;
//ll INF = 1000000000000 ;

//void yorn(bool a){if(a) cout << "Yes" << endl ; else cout << "No" << endl ;}
//void YorN(bool a){if(a) cout << "YES" << endl ; else cout << "NO" << endl ;}
//ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
//ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
//ll sa(long long a,long long b){if(a>b) return a-b ; return b-a ;}
//void fix_cout(){cout << fixed << setprecision(20) ;}

int main(){
	ll x,k,d ;
	cin >> x >> k >> d ;
	x = abs(x) ;
	ll m = x%d ;
	if((x-m)/d>=k) cout << x-k*d << endl ;
	else{
		k -= (x-m)/d ;
		if(k&1) cout << abs(m-d) << endl ;
		else cout << m << endl ;
	}
}


Measured memory_bytes: 3640
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cinttypes>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<string>
#include<stack>


#define FSCNd64 "%" SCNd64
#define FPRId64 "%" PRId64

using namespace std;

using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using pii=pair<int,int>;
using vll=vector<ll>;
using vvll=vector<vll>;
using vpii=vector<pii>;

#define PI 3.1415926535897932384626433832795

template<typename X>
bool max_u(X&m, X v)
{
	if(m<v)
	{
		m=v;
		return true;
	}
	return false;
}


template<typename X>
bool min_u(X&m, X v)
{
	if(m>v)
	{
		m=v;
		return true;
	}
	return false;
}


struct solve
{
	solve(){}
	ll operator()() {
		return 0;
	}
};

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

	for(;;)
	{
		string s, t;
		cin >> s >> t;
		if(cin.fail()) break;
		if(!islower(s[0])) break;

		int sl=s.length();
		int tl=t.length();

		int ans=tl;
		for(int i=0;i<=sl-tl;i++)
		{
			int match=0;
			for(int j=0;j<tl;j++)
			{
				if(s[i+j]==t[j]) match++;
			}
			min_u(ans, tl-match);
		}

		cout << ans << "\n";
	}
	return 0;
}


Measured memory_bytes: 3616
#include <cstdio>
int main(){
	long long int n;
	scanf("%lld", &n);
	if (n % 2 == 1){
		printf("0\n");
	}else{
		unsigned long long int ans = 0;
		for (unsigned long long int i = 1, j = 5; j <= n; i++, j *= 5){
			ans += (n / j) / 2;
		}
		printf("%llu\n", ans);
	}
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
#define endl "\n"
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();
// freopen("input.txt", "r", stdin);

int main() {
    ll n;
    cin >> n;
    unordered_map<ll, int> cnt;
    for(int i = 1; i <= 100; i++) {
        for(int j = 1; j <= 100; j++) {
            for(int k = 1; k <= 100; k++) {
                ll res = i*i + j*j+k*k + i*j + j*k + i*k;
                cnt[res] += 1;
            }
        }
    }
    for(int i = 1; i <= n; i++) {
        cout << cnt[i] <<endl;
    }
    return 0;
}


Measured memory_bytes: 5040
#include<cstdio>
#include<iostream>
#include<cctype>
using namespace std;
int main()
{
	char ch;
	int count[26]={};
	while(scanf("%c",&ch)!=EOF)
	{
		ch=tolower(ch);
		if(isalpha(ch)!=0)
		{
			count[ch-'a']++;
		}
		
	}
	for(int i=0;i<26;i++)
		{
			printf("%c : %d\n",i+'a',count[i]);    	
		}
		return 0;
}

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

bool inarr(int* arr, int n, int x) {
    for (int i=0;i<n;i++) {
        if (arr[i] == x) return true;
    }
    return false; 
}

int main() {
    int x,n;
    cin >> x >> n;
    if ( n == 0) {
        cout << x;
        return 0;
    }
    int* arr = new int[n];
    for (int i=0;i<n;i++) {
        cin >> arr[i];
    }
    int lower = x;
    for (int i=x;i>=0;i--) {
        if (!inarr(arr, n, i)) {
            lower = i;
            break;
        }
    }
    int j = x;
    while(1) {
        if (inarr(arr, n, j)) {
            j++;
        }else{
            if ( (x-lower) <= (j-x) ) {
                cout << lower;
            }else{
                cout << j;
            }
            return 0;
        }
    }
}

Measured memory_bytes: 3632
#include <iostream>
#include <cstdio>
int main(int argc, const char * argv[])
{
    int a, b, ab = 0, ans;
    
    while(scanf("%d %d", &a, &b) != EOF){
        if (a < 0 || 1000000 < a) {
            while (a < 0 || 1000000 < a) {
                scanf("%d %d", &a, &b);
            }
        }
        if (b < 0 || 1000000 < b) {
            while (b < 0 || 1000000 < b) {
            scanf("%d %d", &a, &b);
            }
        }
        ab = a + b;
        ans = 0;
        while (ab) {
            ans++;
            ab /= 10;
        }
        printf("%d\n", ans);
    }
    return 0;
}

Measured memory_bytes: 1188
/*input
1 2 0 4 5
*/
 
 
 
#include <bits/stdc++.h>
using namespace std;
 
 
 
#define int long long int
#define rep(i,n) \
    for(int i = 0; i < n; i++)
#define rep2(i, a, b) \
    for(int i = a; i < b; i++)
#define all(c) \
    c.begin(), c.end()
#define init(arr, num) \
    memset(arr, num, sizeof(arr))
#define fast\
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define inputFile \
    freopen("input.txt", "r", stdin); 
#define outputFile \
    freopen("output.txt", "w", stdout);
#define modM 1000000007
#define PI 3.1415926535897932
#define F first
#define S second  
#define pb push_back  
#define INF 3e18
#ifdef gaviria
#define TRACE
#endif
#ifdef TRACE
#define trace(...) _f(#VA_ARGS, __VA_ARGS_)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
    cout << name << " : " << arg1 << std::endl;
 
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
    const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...);
}
#else
#define trace(...)
#endif
 
 
typedef long long ll;
typedef vector<int> vi;
typedef vector< vi > vvi;
typedef pair< ll, ll > ii;
typedef unordered_set<int> usi;
 


ll n,i,j,k,m;

void solve()
{
  for(i=0;i<5;i++)
  {cin>>j;
    if(j==0)
        k=i+1;

  }
  cout<<k;

}



 
 
 
signed main()
{
 
    // inputFile;
    // outputFile;
    fast;
    int T = 1;
 // cin >> T;
ll h=T;
    while(T--){
 
        solve();
        cout<<endl;
 
     
        
        
 
    }
    
    
    return 0;
 
}

Measured memory_bytes: 3652
#include <iostream>
#include <iomanip>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>
#include <queue>
#include <cmath>
#include <numeric>
#include <set>

using namespace std;
struct aaa{aaa(){cin.tie(nullptr); ios::sync_with_stdio(false); cout<<fixed<<setprecision(20);};}aaa;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v){o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
#define debug(v) {cerr<<"\033[1;36m[debug]\033[m "<<#v<<" : "<<v<<endl;}

using int64 = long long;

void dfs(const int& u, const int& p, vector<int>& ans, const vector<vector<int>>& g) {
    for (auto v : g[u]) {
        if (v == p) continue;
        ans[v] += ans[u];
        dfs(v, u, ans, g);
    }
}

int main() {
    int n,q;
    cin >> n >> q;
    vector<vector<int>> g(n+1);
    for (int i=0; i<n-1; i++) {
        int a,b;
        cin >> a >> b;
        g[a].push_back(b);
        g[b].push_back(a);
    }

    vector<int> ans(n+1,0);
    for (int i=0; i<q; i++) {
        int p,x;
        cin >> p >> x;
        ans[p] += x;
    }
    dfs(1, -1, ans, g);

    for (int i=1; i<=n; i++) {
        cout << ans[i] << (i!=n? ' ' : '\n');
    }
}


Measured memory_bytes: 26624
function Main(input) {
    input = input.split("\n")
    input = input.map(e=>e.split(" "))
    //input = input.map(e=>e.map(f=>parseInt(f,10)))    
    
    var resultText = input[1][0].split("").reduce((pre,cur,ind,src)=>{        
        return pre + (cur == src[ind-1]?"":cur)
    },"")
      
    console.log(resultText.length);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 15180
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

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

    int n;
    cin >> n;

    int r = 0;
    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;

        while (a % 2 == 0) {
            a /= 2;
            r++;
        }
    }

    cout << r << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,m;
int a[5000],b[5000];
int solve(int I){
  int cnt=0;
  for(int i=0;i<n;i++){
    if(a[i]==b[I]){
      cnt++;
      I++;
    }
  }
  return cnt;
}
int main(){
  cin>>n>>m;
  for(int i=0;i<n;i++) cin>>a[i];
  for(int i=0;i<m;i++) cin>>b[i];
  int ans=-1;
  for(int i=0;i<m;i++){
    ans=max(ans,solve(i));
  }
  cout<<ans<<endl;
  
  return 0;
}

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

#pragma GCC optimize "trapv"
#define FASTIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define rep(i,a,b) for(int i=a; i<b; i++)
#define drep(i,a,b) for(int i=a; i>b; i--)
#define vi vector<int>
#define pii pair<int,int>
#define pb push_back
#define fi first
#define se second
#define ll long long
#define inf 1e+18L
#define mod 1000000007

const auto pi = 3.14159265358979;

template <typename T>
T numdigits(T n)
{
    return (floor(log10(n)) + 1);
}

template <typename T>
T modpower(T x, T y, T m=mod)
{
    T res = 1;
    x %= m;
    if(x == 0) return 0;
    while(y > 0)
    {
        if(y&1) res = (res*x)%m;
        y >>= 1;
        x = (x*x)%m;
    }
    return res;
}

void solve()
{
    //code
    ll n, k;
    cin >> n >> k;
    cout << ((2*k*k*k-3*k*k*n-6*k*k+3*k*n-2*k+n*n*n+3*n*n+8*n+12)/6)%mod;
}

int main()
{
    FASTIO
//    int t;
//    cin >> t;
//    while(t--)
        solve();
    return 0;
}

Measured memory_bytes: 3652
package main

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

var sc = bufio.NewReaderSize(os.Stdin, 1024*1024*1)

func main() {
	S := getStdin()

	if S == "ABC" {
		fmt.Printf("ARC\n")
	} else {
		fmt.Printf("ABC\n")
	}
}

func getStdin() string {
	return readLine()
}
func getStdinInt() int {
	str := getStdin()
	rtn, _ := strconv.Atoi(str)
	return rtn
}
func getStdinIntArr() []int {
	str := getStdin()
	list := strings.Split(str, " ")
	rtn := make([]int, len(list))
	for idx, val := range list {
		rtn[idx], _ = strconv.Atoi(val)
	}
	return rtn
}

func getStdinIntArr64() []int64 {
	str := getStdin()
	list := strings.Split(str, " ")
	rtn := make([]int64, len(list))
	for idx, val := range list {
		rtn[idx], _ = strconv.ParseInt(val, 10, 64)
	}
	return rtn
}

func readLine() string {
	buf := make([]byte, 0, 1024*1024*10)
	for {
		l, p, e := sc.ReadLine()
		if e != nil {
			panic(e)
		}
		buf = append(buf, l...)
		if !p {
			break
		}
	}
	return string(buf)
}


Measured memory_bytes: 2188
//IGNORANCE IS BLISS

#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define ll long long 
#define int ll
#define mod 1000000007
#define mod1 1000000006
#define modi 998244353
#define ff first
#define ss second
#define pb push_back
vector<ll> vi[300005];
int color[100005];
ll pa[500005];
ll si[500005];
#define pb push_back
bool visi[1000005]={false};
bool is[100005];
ll fac[10000001];
ll prime[400005];
ll bit[100005];
const long double eps = 1.0e-14; 
#define fio ios_base::sync_with_stdio(false); cin.tie(NULL);
 
 
void fact(){
    fac[0]=1;
    for(int i=1;i<=10000000;i++){
        fac[i]=(fac[i-1]*i)%mod;
    }
    return ;
}
void sieve(){
    prime[0]=0;
    prime[1]=0;
    for(int i=2;i<400005;i++){
        prime[i]=1;
    }
    for(int i=2;i*i<400005;i++){
        if(prime[i]==1){
            for(int j=i*i;j<400005;j+=i){
                prime[j]=0;
            }
        }
    }
    
}
 
ll power(ll n , ll p ){
    if(p==0)
        return 1;
    
    ll res = power((n*n)%mod,p/2);
    if(p%2==1)
        res = (n*res)%mod;
    
    return res;
}
 
 
void upd(ll i,ll val,ll n) {
    for(;i<=n;i+=i&(-i))
        bit[i]+=val;
}
 
ll qry(ll i) {
    ll sum=0;
    for(;i>0;i-=i&(-i))
        sum+=bit[i];
    return sum;
}
 
 
ll fin(ll u) {
    if(pa[u]==u)
        return u;
    return fin(pa[u]);
}
 
void uni(ll u,ll v) {
    ll p1=fin(u);
    ll p2=fin(v);
    if(p1==p2)
        return;
    if(si[p1]<si[p2])
        swap(p1,p2);
    si[p1]+=si[p2];
    pa[p2]=p1;
    return;
}
 
int32_t main() {
    fio

    long double a,b,c;
    cin >> a >> b >> c;
    
    //cout << fixed << setprecision(16);
    
    if(sqrt(a)+sqrt(b)+eps <sqrt(c)) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }

	return 0;
    
}


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

int main(){
	int i,j,x[10000],y[10000];
	for(i=0;i<10000;i++){
		cin>>x[i]>>y[i];
		
		if(x[i]==0&&y[i]==0)break;
	}
	for(j=0;j<i;j++){
		if(x[j]>y[j]){
			x[j]=x[j]+y[j];
			y[j]=x[j]-y[j];
			x[j]=x[j]-y[j];
		}
		cout<<x[j]<<' '<<y[j]<<endl;
	}
	return 0;
}

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

int main() {
  int K, X, Y;
  cin >> K >> X >> Y;
  X -= 1;
  Y -= 1;
  vector<int> vec(K-1);

  for (int i = 0; i < K-1; i++) {
    for (int j = i+1; j < K; j++) {
      int N = 0;
      if (i <= X && Y <= j) {
        N = j - i -(Y -X - 1);
      }
      else if ((X < i && i < Y) && (X >= j || j >= Y)) {
        N = min(j-i, j - Y + 1 + i - X);
      }
      else if ((X < j && j < Y) && (X >= i || i >= Y)) {
        N = min(j-i, Y - j + 1 + X - i);
      }
      else if (X < i && j < Y) {
        N = min(j-i, i - X + 1 + Y - j);
      }
      else {
        N = j - i;
      }
      vec.at(N-1) += 1;
    }
  }
  for (int i = 0; i < K-1; i++) {
    cout << vec.at(i) << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
using namespace std;
#define F first
#define S second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define SZ(x) (int)(x).size()
#define int ll

signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int x;
  cin >> x;
  int now = 100;
  for (int i = 1;; i++) {
    now += now / 100;
    if (now >= x) {
      cout << i << '\n';
      exit(0);
    }
  }
}
  

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

typedef long long ll;
typedef pair<int,int> ii;
typedef tree<ii,null_type,less<ii>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;

int eval(int H, int W, int K, vector<string> &S, vector<vector<int>> &gp) {
	int n=gp.size();
	vector<int> ct(n,0);
	int ret=0;
	for (int j=0; j<W; j++) {
		vector<int> tmp(n,0);
		for (int k=0; k<n; k++)
			for (int i : gp[k])
				if(S[i][j]=='1')
					tmp[k]++;
		for (int k=0; k<n; k++)
			if(tmp[k]>K)
				return -1;

		bool add=false;
		for (int k=0; k<n; k++)
			if(ct[k]+tmp[k]>K)
				add=true;

		if(add) {
			for (int k=0; k<n; k++)
					ct[k]=tmp[k];
			ret++;
		} else {
			for (int k=0; k<n; k++)
				ct[k]+=tmp[k];
		}
	}
	return ret;
}

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	int H,W,K; cin>>H>>W>>K;
	vector<string> S(H);
	for (int i=0; i<H; i++)
		cin>>S[i];
	ll ret=INT_MAX;
	for (int bt=0; bt<(1<<(H-1)); bt++) {
		vector<vector<int>> gp;
		int cur=1, idx=0;
		for (int i=0; i<H-1; i++) {
			if(bt&(1<<i)) {
				vector<int> tmp;
				for (int i=0; i<cur; i++)
					tmp.push_back(idx++);
				gp.push_back(tmp);
				cur=1;
			}
			else cur++;
		}
		vector<int> tmp;
		for (int i=0; i<cur; i++)
			tmp.push_back(idx++);
		gp.push_back(tmp);

		ll val=gp.size()-1;
		ll add=eval(H,W,K,S,gp);
		if(add==-1) val=INT_MAX;
		else val+=add;
		ret=min(ret,val);
	}
	cout<<ret<<"\n";
	return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define PI 3.141592
#define LL_INF 9000000000000000000
#define LL_MINF -9000000000000000000
#define INT_INF 2000000000
#define INT_MINF -2000000000
#define all(a) (a).begin(), (a).end()
#define fi first
#define se second

int main(){
    int N, D, X;
    cin >> N >> D >> X;
    vector<int> A(N);
    for(int i = 0; i < N; i++) cin >> A[i];
    int sum = 0;
    for(int a : A) sum += (D - 1) / a + 1;
    cout << sum + X << endl;
}


Measured memory_bytes: 3600
# 解説放送の方針
# 平面走査をし、各点について、左上、左下、右上、右下にある点を数え、計算する。
# 解説放送ではBITを2本使っていたが、座標圧縮の結果を利用してBIT１本で済むようにした

N = int(input())
xy = [tuple(map(int,input().split())) for _ in range(N)]

mod = 998244353

class BIT:
    '''https://tjkendev.github.io/procon-library/python/range_query/bit.html'''
    def __init__(self, n):
        self.n = n
        self.data = [0]*(n+1)
        self.el = [0]*(n+1)
    def sum(self, i):
        s = 0
        while i > 0:
            s += self.data[i]
            i -= i & -i
        return s
    def add(self, i, x):
        self.el[i] += x
        while i <= self.n:
            self.data[i] += x
            i += i & -i
    def query(self, i, j=None):
        if j is None:
            return self.el[i]
        return self.sum(j) - self.sum(i)

# 平面走査のためのソート（高速化のため１次元にしてソート）
xy2 = []
for i in range(N):
  x,y = xy[i]
  x += 10**9
  y += 10**9
  xy2.append(y<<80 | x << 40 | i)

# ソート後の復元+座標圧縮用の辞書作成
# 座標圧縮: 小さいyから順に1,2,3...と値を割り振る。
xy2 = sorted(xy2)
mask = (1<<40)-1
y_order=[0]*N
y_compress={}
for j,y in enumerate(xy2):
  i = y & mask
  y >>= 40
  x = y & mask
  x -= 10**9
  y >>= 40
  y -= 10**9
  y_order[i] = j
  y_compress[y] = j+1

xy2 = []
for i in range(N):
  x,y = xy[i]
  x += 10**9
  y += 10**9
  xy2.append(x<<80 | y << 40 | i)
  
xy2 = sorted(xy2)
mask = (1<<40)-1
bit=BIT(N)
ans = 0
for x in xy2:
  i = x & mask
  x >>= 40
  y = x & mask
  y -= 10**9
  x >>= 40
  x -= 10**9
  
  y = y_compress[y]
  bit.add(y,1)
  '''
  今現在みている点より左上と左下にある点の個数（今の点は含まない。以下同じ）。
  BITを使って求める。
  '''
  n1 = bit.query(y-1,N)-1
  n2 = bit.query(0,y)-1 
  '''
  右上と右下。座標圧縮の結果を利用。(N-y(座標圧縮済))はある点より上にある点の総数。
  そこからn1（走査済みの点の個数)を引くことで、まだ走査していない点の個数を求めることができる。
  '''
  n3 = N-y-n1 
  n4 = y-n2-1
  prod14 = (pow(2,n1,mod)-1)*(pow(2,n4,mod)-1)*pow(2,n2+n3,mod) %mod
  prod23 = (pow(2,n2,mod)-1)*(pow(2,n3,mod)-1)*pow(2,n1+n4,mod) %mod
  prod1234 = (pow(2,n1,mod)-1)*(pow(2,n4,mod)-1)*(pow(2,n2,mod)-1)*(pow(2,n3,mod)-1) %mod
  ans += pow(2,N-1,mod)+prod14+prod23-prod1234
  ans %= mod
  
print(ans)

Measured memory_bytes: 197072
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long long N,y,sum;
  long long min,max;
  
    cin >> N;
    for (int i = 1; i <= N; i++) {
      int x = i;
      if(x%3 == 0){
        cout << " " << i;
        continue;
      }
      for(; x > 0;x /= 10){
        if(x%10 == 3){
          cout << " " << i;
          break;
        }
      } 
    } 
  cout << endl;
}


Measured memory_bytes: 3116
#include <bits/stdc++.h>
using namespace std;
int main() {
    
  int D,L;
  int a= 0;
  int ans =0;
  cin >> D>>L;
  
  if(D >= L){
  
     a = D / L;
     
     ans = a;
     
  }
   if(a != 0){
      D -= a *L;
  }
   ans = D + ans;
 
  
  cout << ans << endl;
}


Measured memory_bytes: 3088
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <functional>
#include <climits>
using namespace std;
#define pb emplace_back
#define fi first
#define se second
#define rep(i,n) for(int i=0; i<(n); ++i)
#define ALL(x) (x).begin(), (x).end()
#define show(...) fprintf(stderr, __VA_ARGS__)
#define outl(x) cout << (x) << '\n'
template<class A, class B>inline bool chmax(A &a, B b){return b>a ? a=b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, B b){return b<a ? a=b,1 : 0;}
inline bool inside(int y, int x, int H, int W){return(y>=0 && x>=0 && y<H && x<W);}
inline bool inside(int x, int W){ return (0 <= x && x < W); }
const int dx[] = {1, 0, -1, 0,  1, 1, -1, -1};
const int dy[] = {0, 1, 0, -1,  -1, 1, 1, -1};
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
static constexpr int INF = 0x3f3f3f3f;

struct Team {
    int id, s;
    explicit Team(int i=0, int sc=0): id(i), s(sc) {}
    bool operator < (const Team &x) const {
        return (s == x.s) ? (id >= x.id) : (s < x.s);
    }
    bool operator > (const Team &x) const {
        return (s == x.s) ? (id <= x.id) : (s > x.s);
    }
};

const Team& max(const Team &a, const Team &b) {
    return a > b ? a : b;
}


struct SegTree
{
    vector<Team> dat;
    int size;

    SegTree(int n) {
        for (size =1; size <= n; size *= 2);
        dat.assign(size*2+5, Team(0, INT_MIN));
    }

    void update(int i, Team x) {
        i += size -1;
        dat[i] = x;
        while (i > 0) {
            i = (i-1)  /2;
            dat[i] = max(dat[i*2+1], dat[i*2+2]);
        }
    }

    const Team query(int a, int b, int k, int l, int r) {
        if (r <= a || b <= l) return Team(0, INT_MIN);
        if (a <= l && r <= b) return dat[k];
        int mid = (l + r) / 2;
        return max(query(a, b, 2*k+1, l, mid), query(a, b, 2*k+2, mid, r));
    }

    const Team query(int a, int b) { return query(a, b, 0, 0, size); }

    const Team& operator [] (int i) { return dat[i+size-1]; }

};

#define LIM 1000010
int N, R, L;
int timeSum[1000010];
int d[LIM], t[LIM], x[LIM];

signed main()
{
    cin.tie(0), ios::sync_with_stdio(false);
    cin >> N >> R >> L;
    for (int i=1; i<=R; ++i) {
        cin >> d[i] >> t[i] >> x[i];
        --d[i];
    }

    t[0] = 0;
    t[R+1] = L;
    SegTree seg(N+1);
    for (int i = 0; i < N; i++) {
        seg.update(i, Team(i, 0));
    }

    for (int i=1; i<=R; ++i) {
        Team top = seg.query(0, N);
        timeSum[top.id] += t[i] - t[i-1];
        seg.update(d[i], Team(d[i], seg[d[i]].s + x[i]));
    }
    Team top = seg.query(0, N);
    timeSum[top.id] += t[R+1] - t[R];

    /*
    for (int i=0; i<N;++i) {
        printf("timesum[%d] = %d   score = %d\n", i+1, timeSum[i], seg[i].s);
    }
    */

    int maxpos = 0;
    for (int i=1; i<N;++i) {
        if (timeSum[maxpos] < timeSum[i]) {
            maxpos = i;
        }
    }

    outl(maxpos + 1);
}




Measured memory_bytes: 12612
#include <iostream>
#include <string>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>

#define FOR(i, f, n) for(int (i) = (f); (i) < (n); (i)++)
#define RFOR(i, f, n) for(int (i) = (f); (i) >= (n); (i)--)
#define REP(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define RREP(i, n) for(int (i) = (n); (i) >= 0; (i)--)
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define rrep(i, n) for(int (i) = (n); (i) >= 0; (i)++)
#define p(...) printf(__VA_ARGS__); cout << endl;
#define input(x) x; cin >> x;
#define list_input(x, n) x[(n)]; for(int (i) = 0; (i) < (n); (i)++) cin >> x[i];
#define lambda(a, b, c) [](const a, const b){ return c ;}
#define key(t, x, compare) [](const t& a, const t& b){ return a x compare b x ;}

using namespace std;

using pii = pair<int, int>;

int main(){
  int list_input(a, 3);
  cout << (count(a, a + 3, 5) == 2 && count(a, a + 3, 7) == 1 ? "YES" : "NO") << endl;
}


Measured memory_bytes: 256
/*{{{*/
#include<iostream>
#include<algorithm>
#include<string>
#include<sstream>

typedef long long ll;

#define REP(i,n) for(ll i=0;i<n;i++)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define FORR(i,a,b) for(ll i=b-1;i>=a;i--)

#define DEBUG(x) cout<<#x<<": "<<x<<endl

using namespace std;
/*}}}*/

int main() {
  ll n;
  ll a,b;
  ll ma,mi;
  cin >> a >> b;
  ma = max(a,b);
  mi = min(a,b);
  ll ans = ma + max(ma-1,mi);
  cout << ans << endl;
  return 0;
}


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

#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define abs(a) max((a),-(a))
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define repe(i,n) rep(i,(n)+1)
#define per(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define pere(i,n) rep(i,(n)+1)
#define all(x) (x).begin(),(x).end()
#define SP <<" "<<
#define RET return 0
#define MOD 1000000007
#define INF 1000000000000000000

typedef long long LL;
typedef long double LD;

int main(){
  while(1){
    int h,w;
    cin >> w >> h;
    if(w==0) return 0;
    vector<vector<int>> field(h,vector<int>(w));
    for(int i=0;i<h;i++){
      for(int j=0;j<w;j++){
        cin >> field[i][j];
      }
    }
    queue<pair<int,int>> bfs;
    int nx,ny,hx[8]={-1,-1,-1,0,0,1,1,1},hy[8]={-1,0,1,-1,1,-1,0,1};
    int count=0;
    for(int i=0;i<h;i++){
      for(int j=0;j<w;j++){
        if(field[i][j]==1){
          count++;
          field[i][j]=0;
          bfs.push({j,i});
          while(!bfs.empty()){
            pair<int,int> now=bfs.front();
            bfs.pop();
            for(int i=0;i<8;i++){
              nx=now.first+hx[i];
              ny=now.second+hy[i];
              if(0<=nx&&nx<w&&0<=ny&&ny<h){
                if(field[ny][nx]==1){
                  field[ny][nx]=0;
                  bfs.push({nx,ny});
                }
              }
            }
          }
        }
      }
    }
    cout << count << endl;
  }
  return 0;
}



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

int main() {
    int N;
    cin >> N;
    if(N%2==0) {
        cout << N/2 << endl;
    }
    else {
        cout << (N/2)+1 << endl;
    }
}

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

using namespace std;

char in[120];
pair<pair<string,int>,int> p[110];
int main(){
int a;
cin>>a;
for(int i=0;i<a;i++){
int t;
cin>>in>>t;
string tmp=in;
p[i]=make_pair(make_pair(in,-t),i);
}
std::sort(p,p+a);
for(int i=0;i<a;i++)
cout<<p[i].second+1<<"\n";
}



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

int main(){
	ll n,m;
	cin>>n>>m;
	multiset<ll,greater<ll>> a;
	ll ans=0;
	for(ll i=0; i<n; i++){
		ll b=0;
		cin>>b;
		a.insert(b);
		ans+=b;
	}
	
	for(ll i=0; i<m; i++){
		ll k=0;
		for(ll j:a){//aの一番大きい数
			k=j;
			if(k>0){
				break;
			}
		}
		ans-=k-(k/2);
		a.insert(k/2);
		a.erase(a.find(k));
	}
	
	cout<<ans<<endl;
}
	
	

Measured memory_bytes: 8312
import java.util.Scanner;

//20180510
//08

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

		while(true) {
			String string = scanner.next();
			if("-".equals(string)){
				break;
			}
			int count = scanner.nextInt();
			for(int i = 0;i < count;i++) {
				int shuffle = scanner.nextInt();
				String tmp = string.substring(0, shuffle);
				String out = string.substring(shuffle);
				string = out + tmp;
			}
			System.out.println(string);
		}
		scanner.close();
    }
}


Measured memory_bytes: 26492