akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = s; i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << '\n';
#define CFYN(n) cout << ( (n) ? "YES":"NO") << '\n';
#define OUT(n) cout << (n) << '\n';
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;

constexpr int MOD = 1000000007;

int mod(const ll &x){
    return x > 0 ? x % MOD : (x+MOD) % MOD;
}

int modm(const ll &x,const ll &m){
    return (x % MOD) * (m % MOD) % MOD;
}

int modpow(ll x, ll p) {
    int ret = 1;
    while(p > 0) {
        if (p & 1) ret = modm(ret,x);
        x = modm(x,x);
        p >>= 1;
    }
    return ret;
}

// x * modinv(d)
int modd(ll x,ll d) {
    return modm(x,modpow(d,MOD-2));
}

int main(void)
{
    IOS
    constexpr int N = 1000000;
    vector<int> prime;
    vector<int> erato(N+5);
    FOR(i,2,N+1) {
        if (erato[i]) continue;
        prime.push_back(i);
        for(int j = 1; i * j <= N; j++) erato[i*j] = i;
    }

    int n; cin >> n;
    vector<int> v(n);
    map<int,int> mp;
    REP(i,n) {
        cin >> v[i];
        map<int,int> tmp;
        int t = v[i];
        while(t != 1) {
            tmp[erato[t]]++;
            t /= erato[t];
        }
        for(auto x:tmp) {
            mp[x.first] = max(mp[x.first],x.second);
        }
    }

    int l = 1;
    for(auto x:mp) {
        l = modm(l,modpow(x.first,x.second));
    }

    int ans = 0;
    REP(i,n) {
        ans = mod(ans + modd(l,v[i]));
    }

    cout << ans << '\n';


    return 0;
}

Measured memory_bytes: 4984
# -*- coding: utf-8 -*-
from collections import Counter, defaultdict, deque

import sys
# sys.setrecursionlimit(10**6)
# buff_readline = sys.stdin.buffer.readline
buff_readline = sys.stdin.readline
readline = sys.stdin.readline

INF = 2**62-1


def read_int():
    return int(buff_readline())


def read_int_n():
    return list(map(int, buff_readline().split()))


def read_float():
    return float(buff_readline())


def read_float_n():
    return list(map(float, buff_readline().split()))


def read_str():
    return readline().strip()


def read_str_n():
    return readline().strip().split()

def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, A, Q, BC):
    ac = Counter(A)
    ans = sum(A)
    for b, c in BC:
        n = ac[b]
        ac[b] = 0
        ac[c] += n
        ans += -n*b + n*c
        print(ans)
    # return ans


def main():
    N = read_int()
    A = read_int_n()
    Q = read_int()
    BC = [read_int_n() for _ in range(Q)]
    slv(N, A, Q, BC)


if __name__ == '__main__':
    main()


Measured memory_bytes: 40268
import Control.Monad
import Data.List
import Data.Maybe
import qualified Data.Map as M
import qualified Data.Set as S

solve hs [] re = re
solve hs ([ai,bi]:abss) re
    | a < b = solve hs abss (S.delete ai re)
    | a > b = solve hs abss (S.delete bi re)
    | otherwise = solve hs abss (S.delete ai $ S.delete bi re)
        where
            a = hs M.! ai
            b = hs M.! bi

main = do
    [n,m] <- map read . words <$> getLine :: IO [Int]
    hs <- map read . words <$> getLine :: IO [Int]
    abss <- replicateM m (map read . words <$> getLine) :: IO [[Int]]
    print $ S.size $ solve (M.fromList $ zip [1..] $ hs) abss (S.fromList $ [1..n])


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

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

int N;
int X[15],Y[15],A[15];
double AS[1<<15],DS[1<<15],V[1<<15];
double D[15][15];
vector<int> C[1<<15];

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N;
	FOR(i,N) cin>>X[i]>>Y[i]>>A[i];
	FOR(x,N) FOR(y,N) D[x][y]=hypot(X[x]-X[y],Y[x]-Y[y]);
	
	for(int mask=1;mask<1<<N;mask++) {
		FOR(i,N) if(mask&(1<<i)) {
			AS[mask]+=A[i];
			C[mask].push_back(i);
		}
			
		if(__builtin_popcount(mask)==1) {
			V[mask]=AS[mask];
			continue;
		}
		
		DS[mask]=1e10;
		for(int smask=(mask-1)&mask; smask>0; smask=(smask-1)&mask) {
			FORR(x,C[smask]) FORR(y,C[smask^mask]) {
				DS[mask]=min(DS[mask],DS[smask]+DS[mask^smask]+D[x][y]);
			}
		}
		V[mask]=(AS[mask]-DS[mask])/__builtin_popcount(mask);
		for(int smask=(mask-1)&mask; smask>0; smask=(smask-1)&mask) {
			V[mask]=max(V[mask],min(V[smask],V[mask^smask]));
		}
	}
	_P("%.12lf\n",V[(1<<N)-1]);
	
}


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


Measured memory_bytes: 3712
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<ll> vi;
#define INF (1e9)

vi A;
// index が条件を満たすかどうか
bool isOK(int index, ll key) {
  if (A[index] <= key)
    return true;
  else
    return false;
}
// 汎用的な二分探索のテンプレ
int binary_search(ll key) {
  int ng = (int)A.size();
  int ok = -1;  //「index = 0」が条件を満たすこともあるので、初期値は -1

  // ok と ng のどちらが大きいかわからないことを考慮
  while (abs(ok - ng) > 1) {
    ll mid = (ok + ng) / 2;  // オーバーフロー注意

    if (isOK(mid, key))
      ok = mid;
    else
      ng = mid;
  }
  return ok;
}

int main() {
  int N, M, K;
  cin >> N >> M >> K;
  vi B(M + 1);
  A = vi(N + 1);
  for (ll i = 0; i < N; i++) {
    ll a;
    cin >> a;
    A[i + 1] = A[i] + a;
  }
  for (ll i = 0; i < M; i++) {
    ll b;
    cin >> b;
    B[i + 1] = B[i] + b;
  }

  ll ans = 0;
  for (int i = 0; i < M + 1; i++) {
    ll t = K - B[i];
    if (t < 0) continue;
    ll j = binary_search(t);
    ans = max(ans, i + j);
  }

  cout << ans << endl;
}


Measured memory_bytes: 6424
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

static const double EPS = 1e-8;
static const double PI = 4.0 * atan(1.0);
static const double PI2 = 8.0 * atan(1.0);

#define REP(i,n)	for(int i=0;i<(int)n;++i)
#define ALL(c)		(c).begin(),(c).end()
#define CLEAR(v)	memset(v,0,sizeof(v))
#define MP(a,b)		make_pair((a),(b))
#define ABS(a)		((a)>0?(a):-(a))
#define FOR(i,s,n)	for(int i=s;i<(int)n;++i)

int n;
int a[100000];

int main(int argc, char **argv) {
	cin >> n;
	REP(i, n) {
		cin >> a[i];
		--a[i];
	}
	int c = 0;
	REP(i, n) {
		c = a[c];
		if (c == 1) {
			cout << (i + 1) << endl;
			return 0;
		}
	}
	cout << -1 << endl;
	return 0;
}


Measured memory_bytes: 640
#include<iostream>
using namespace std;
int main(){
	int n;
	while(cin>>n){
		int a[n];
		for(int i=0;i<n;i++)
			cin>>a[i];
		cout<<a[n-1];
		for(int i=n-2;i>=0;i--)
			cout<<' '<<a[i];
		cout<<endl;
	}
	return 0;
} 


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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcountll

#define INF 1e16
#define mod 1000000007

struct UnionFind{
  vector<int> v;
  UnionFind(int n) : v(n, -1) {}
  void init(){ for(int i = 0;i < (int)v.size();i++)v[i]=-1; }
  int find(int x) { return v[x] < 0 ? x : v[x] = find(v[x]); }
  bool unite(int x, int y) {
    x = find(x); y = find(y);
    if (x == y) return false;
    if (-v[x] < -v[y]) swap(x, y);
    v[x] += v[y]; v[y] = x;
    return true;
  }
  bool root(int x) { return v[x] < 0; }
  bool same(int x, int y) { return find(x) == find(y); }
  int size(int x) { return -v[find(x)]; }
};

struct edge{
  ll u,v,cost;
};

ll n,q;
vector<ll> a,b,c;
vector<edge> es;
vector<vector<ll>> bs;

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

  cin>>n>>q;
  a.resize(q); b.resize(q); c.resize(q);
  bs.resize(2*n);
  rep(i,q){
    cin>>a[i]>>b[i]>>c[i];
    es.push_back((edge){a[i],b[i],c[i]});
    bs[a[i]].push_back(c[i]+1);
    if(a[i]+n<2*n) bs[a[i]+n].push_back(c[i]+1);
    bs[b[i]].push_back(c[i]+2);
    if(b[i]+n<2*n) bs[b[i]+n].push_back(c[i]+2);
  }

  ll mn=INF;
  rep(i,2*n-1){
    for(ll bb : bs[i]){
      minch(mn,bb);
    }
    es.push_back((edge){i%n,(i+1)%n,mn});
    mn+=2;
  }

  sort(all(es),[](const edge& a,const edge& b){
    return a.cost < b.cost;
  });

  ll res=0;
  UnionFind uf(n);
  rep(i,es.size()){
    if(uf.unite(es[i].u,es[i].v)){
      res+=es[i].cost;
    }
  }

  cout<<res<<endl;

  return 0;
}


Measured memory_bytes: 54696
#include <bits/stdc++.h>
#include <algorithm>
#include <map>
#include <cstdlib>
#include <cmath>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;
int main(){
    ll a,b,n;
    cin >> a >> b >> n;
    ll ans;
    //b==1
    if(b==1){
        cout << 0 << endl;
        return 0;
    }
    //n<b
    if(n<b){
        ans=a*n/b;
        cout << ans << endl;
        return 0;
    }
    //n>=b
    ans=a*(b-1)/b;
    ans=max(ans,(a*(2*b-1))/b-(2*b-1)/b*a);
    cout << ans << endl;
}

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

using namespace std;

int main()
{
    int n,k,i,num=1;
    cin>>n>>k;
    for(i=1;i<=n;i++){
       if(num*2<=num+k) num=num*2;
       else num=num+k;

    }cout<<num;
    return 0;
}


Measured memory_bytes: 3576
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n;
  cin >> n;
  vector<int> vec(n);
  for (int i = 0; i<n; i++){
    cin >> vec.at(i);
  }
  
  sort(vec.begin(), vec.end());
  reverse(vec.begin(), vec.end());
  
  int stage = 1;
  for (int i = 0; i<n-1; i++){
    if (vec.at(i) > vec.at(i+1)){
      stage += 1;
    }
  }
  
  cout << stage << endl;  
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
 
struct Node{
  int key;
 struct Node *r,*l,*p;
};
 
struct Node *root,*NIL;
 
void insert(int);
void inorder(struct Node *);
void preorder(struct Node *);
struct Node* find(struct Node *,int);
 
int main(){
  int n,i,x;
  char s[20];
 
  scanf("%d",&n);
 
  for(i=0;i<n;i++){
    scanf("%s",s);
    if(strcmp(s,"find")==0){
      scanf("%d",&x);
      struct Node *t = find(root,x);
      if(t != NIL)printf("yes\n");
      else printf("no\n");
    }
    else if(strcmp(s,"insert")==0){
      scanf("%d",&x);
      insert(x);
    }
    else if(strcmp(s,"print")==0){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
  }
 
  return 0;
}
 
void insert(int k){
  struct Node *y = NIL,*x = root,*z;
 
  z = malloc(sizeof(struct Node));
  z->key = k;
  z->l = NIL;
  z->r = NIL;
 
  while(x != NIL){
    y = x;
    if(z->key < x->key)x = x->l;
    else x = x->r;
  }
 
  z->p = y;
  if(y == NIL)root = z;
  else {
    if(z->key < y->key)y->l = z;
    else y->r = z;
  }
}
 
void inorder(struct Node *u){
 
  if(u == NIL)return;
  inorder(u->l);
  printf(" %d",u->key);
  inorder(u->r);
}
 
void preorder(struct Node *u){
 
  if(u == NIL)return;
  printf(" %d",u->key);
  preorder(u->l);
  preorder(u->r);
}
 
struct Node* find(struct Node *u,int k){
 
  while(u != NIL && k != u->key){
    if(k < u->key)u = u->l;
    else u = u->r;
  }
  return u;
}

Measured memory_bytes: 19364
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main(){
	int h,w;
	cin>>h>>w;
	vector<string>S(h);
	for(int i=0;i<h;i++){
		cin>>S[i];
	}
	vector<vector<int>>left(h,vector<int>(w,0));
	vector<vector<int>>right(h,vector<int>(w,0));
	vector<vector<int>>up(h,vector<int>(w,0));
	vector<vector<int>>down(h,vector<int>(w,0));
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			if(S[i][j]=='.'){
				left[i][j]=1;
				if(j-1>=0)
					left[i][j]+=left[i][j-1];
			}
		}
	}
	for(int i=0;i<h;i++){
		for(int j=w-1;j>=0;j--){
			if(S[i][j]=='.'){
				right[i][j]=1;
				if(j+1<w)
					right[i][j]+=right[i][j+1];
			}
		}
	}
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			if(S[i][j]=='.'){
				up[i][j]=1;
				if(i-1>=0){
					up[i][j]+=up[i-1][j];
				}
			}
		}
	}
	for(int i=h-1;i>=0;i--){
		for(int j=0;j<w;j++){
			if(S[i][j]=='.'){
				down[i][j]=1;
				if(i+1<h){
					down[i][j]+=down[i+1][j];
				}
			}
		}
	}
	int max_value=INT_MIN;
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			if(S[i][j]=='.'){
				int temp=1;
				if(j-1>=0)
					temp+=left[i][j-1];
				if(j+1<w)
					temp+=right[i][j+1];
				if(i-1>=0)
					temp+=up[i-1][j];
				if(i+1<h)
					temp+=down[i+1][j];
				max_value=max(max_value,temp);
			}
		}
	}
	cout<<max_value;
	return 0;
}

Measured memory_bytes: 67200
import sys
sys.setrecursionlimit(10**7)
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return sys.stdin.readline().strip()
INF = 10 ** 18
MOD = 10 ** 9 + 7

debug = True
debug = False

def dprint(*objects):
    if debug == True:
        print(*objects)

def warshall_floyd(d):
    #d[i][j]: iからjへの最短距離
    n = len(d)
    for k in range(n):
        for i in range(n):
            for j in range(n):
                d[i][j] = min(d[i][j],d[i][k] + d[k][j])
    return d

def solve():
    N = II()

    for i in range(1, 10):
        for j in range(i, 10):
            if N == i*j:
                print('Yes')
                return
    print('No')

solve()

Measured memory_bytes: 3064
#include <stdio.h>
#define N 100

void swap(int *,int *);
int main(){
  int n,A[N];
  int i,j,minj;
  int count=0;
  
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);  
  }

  for(i=0;i<=n-2;i++){
    minj=i;
    for(j=i;j<=n-1;j++){
      if(A[j]<A[minj]){
	minj=j;
      }
    }
    if(minj != i) count++;
    swap(&A[i],&A[minj]);
  }
  
  for(i=0;i<n;i++){
    if(i==n-1){
      printf("%d\n",A[i]);
      break;
    }
    printf("%d ",A[i]);
  }
  printf("%d\n",count);
  return 0;
}

void swap(int *a,int *b){
  int tmp;
  tmp=*a;
  *a=*b;
  *b=tmp;
}

Measured memory_bytes: 600
s=list(input())
ans=0
for i in range(len(s)):
    for j in range(len(s)):
        ss=s[i:j+1]
        if len(ss)==ss.count('A')+ss.count('T')+ss.count('G')+ss.count('C'):
            cnt=len(ss)
            ans=max(ans,cnt)
print(ans)

Measured memory_bytes: 3060
hn = input().split(" ")
h = int(hn[0])
n = int(hn[1])

aintlist = input().split(" ")
alist=[]
for i in range(n):
    alist.append(int(aintlist[i]))

max = 0
for i in range(n):
    max = max + alist[i]

if max >= h:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 13784
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>

typedef std::pair<int, int> Pair;

constexpr int MAX_HW = 1000;
constexpr int MAX_N = 9;
constexpr int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};

int H, W, N;
int sx[MAX_N], sy[MAX_N], gx[MAX_N], gy[MAX_N];
char map[MAX_HW][MAX_HW];

int bfs(const int& n);

int main(){
    scanf("%d%d%d", &H, &W, &N);
    
    for(int i = 0; i < H; ++i){
        scanf("\n");
        for(int j = 0; j < W; ++j){
            scanf("%c", &map[j][i]);
            if(map[j][i] == 'S'){
                sx[0] = j, sy[0] = i;
            }
            if(map[j][i] >= '1' && map[j][i] < (N + '0')){
                sx[map[j][i] - '0'] = j, sy[map[j][i] - '0'] = i;
                gx[map[j][i] - '0' - 1] = j, gy[map[j][i] - '0' - 1] = i;
            }
            if(map[j][i] == (N + '0')){
                gx[N - 1] = j, gy[N - 1] = i;
            }
        }
    }
    
    int ans = 0;
    for(int i = 0; i < N; ++i){
        ans += bfs(i);
    }
    
    printf("%d\n", ans);
    
    return 0;
}

int bfs(const int& n){
    int dis[MAX_HW][MAX_HW];
    memset(dis, -1, sizeof(dis));
    dis[sx[n]][sy[n]] = 0;
    
    std::queue<Pair> que;
    que.push(Pair(sx[n], sy[n]));
    
    while(que.size()){
        Pair p = que.front(); que.pop();
        
        if(p.first == gx[n] && p.second == gy[n]){
            break;
        }
        
        for(int i = 0; i < 4; ++i){
            int nx = p.first + dx[i], ny = p.second + dy[i];
            if(nx >= 0 && ny >= 0 && nx < W && ny < H && map[nx][ny] != 'X' && dis[nx][ny] == -1){
                que.push(Pair(nx, ny));
                dis[nx][ny] = dis[p.first][p.second] + 1;
            }
        }
    }
    
    return dis[gx[n]][gy[n]];
}

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

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    ll n;
    cin >> n;
    vll a(n+2);
    a[0] = 0; a[n+1] = 0;
    rep(i, n){
        cin >> a[i+1];
    }
    vll lmax(n+2), rmax(n+2);
    lmax[0] = 0;
    rmax[n+1] = 0;
    repr(i, 1, n+2){
        lmax[i] = max(lmax[i-1], a[i]);
    }
    for(ll i = n; i >= 0; i--){
        rmax[i] = max(rmax[i+1], a[i]);
    }
    repr(i, 1, n+1){
        cout << max(lmax[i-1], rmax[i+1]) << endl;
    }
    return 0;
}

Measured memory_bytes: 6272
//...Bismillahir Rahmanir Rahim...
// Code by    Asad Bin Saber

#include <bits/stdc++.h>

using namespace std;

// typedefs...
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<ll, ll> pll;

// constants...
const double PI = acos(-1);
const int MOD = 1e9+7; // 998244353;
const int MX = 2e5+5;
const ll INF = 1e18+5;

// defines...
#define MP make_pair
#define PB push_back
#define fi first
#define se second
#define si(a) scanf("%d", &a)
#define sii(a, b) scanf("%d%d", &a, &b)
#define siii(a, b, c) scanf("%d%d%d", &a, &b, &c)
#define sl(a) scanf("%lld", &a)
#define sll(a, b) scanf("%lld%lld", &a, &b)
#define slll(a, b, c) scanf("%lld%lld%lld", &a, &b, &c)
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)

// chess moves...
// int dx[] = {+0, +0, -1, +1}; ///Up-down, Left-Right
// int dy[] = {+1, -1, +0, +0};
// int dx[] = {+0,+0,+1,-1,-1,+1,-1,+1}; ///King's Move
// int dy[] = {-1,+1,+0,+0,+1,+1,-1,-1};
// int dx[] = {-2, -2, -1, -1,  1,  1,  2,  2}; ///Knight's Move
// int dy[] = {-1,  1, -2,  2, -2,  2, -1,  1};

// structs...
struct hash_pair { 
    template <class T1, class T2> 
    size_t operator()(const pair<T1, T2>& p) const
    { 
        auto hash1 = hash<T1>{}(p.first); 
        auto hash2 = hash<T2>{}(p.second); 
        return hash1 ^ hash2; 
    } 
}; 

// functions...
ll gcd(ll a, ll b) {
    while (b) {
        a %= b;
        swap(a, b);
    }
    return a;
}
ll lcm(ll a, ll b)
{
    return (a/gcd(a, b)*b);
}
ll comb(ll a, ll b)
{
    ll x = max(a-b, b), ans=1;

    for(ll K=a, L=1; K>=x+1; K--, L++){
        ans *= K;
        ans /= L;
    }

    return ans;
}


void task()
{
    //code here...
    
    ll n, x, y, ans=0, d;
    
    cin >> n >> d;
    while(n--){
		cin >> x >> y;
		
		if(x*x+y*y<=d*d) ans++;
	}
	
	cout << ans << "\n";
}


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

    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    task();

    return 0;
}


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


int main(){
    int n,l;cin>>n>>l;
    vector<string> s(n);
    rep(i,n)cin>>s.at(i);
    string ans= "";
    sort(s.begin(),s.end());
    rep(i,n){
        ans+=s.at(i);
    }
    cout<<ans<<endl;

}


Measured memory_bytes: 256
#-*-coding:utf-8-*-
import sys
input=sys.stdin.readline

def main():
    a,b = map(int,input().split())

    if a % 3 ==0 or b %3 == 0 or (a+b)%3 ==0:
        print("Possible")
    else:
        print("Impossible")

if __name__=="__main__":
    main()

Measured memory_bytes: 9036
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int k,n,i,mx=0;
    cin>>k>>n;
    int a[n+1];
    for(i=0; i<n; i++)cin>>a[i];
    a[n]=k+a[0];
    for(i=0; i<n; i++)
    {
        mx=max(mx,a[i+1]-a[i]);
    }
    cout<<k-mx<<endl;
    return 0;
}


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


int main(int argc, char const *argv[])
{
	int a, b, t; cin >> a >> b >> t;
	int ans = 0;
	int now = a;
	while (now <= t) {
		ans += b;
		now += a;
	}
	cout << ans << endl;
	return 0;
}


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

using namespace std;
typedef long long ll;
const int MAXN = 55;
const int MAXS = 3000;

int N, M;
int S;

int C[MAXN], D[MAXN];
vector <pair <int, pair <int, int> > > edge[MAXN];

ll dist[MAXN][MAXS];

priority_queue <pair <ll, pair <int, int> > > q;

void dijk()
{
    dist[0][S] = 0;
    q.push (make_pair (0, make_pair (0, S)));

    while (!q.empty())
    {
        ll cd = -q.top().first;
        int cloc = q.top().second.first;
        int cs = q.top().second.second;

        q.pop();
        if (dist[cloc][cs] != cd)
            continue;

        int ns = min (MAXS - 1, cs + C[cloc]);
        if (dist[cloc][ns] > cd + D[cloc])
        {
            dist[cloc][ns] = cd + D[cloc];
            q.push(make_pair (-dist[cloc][ns], make_pair (cloc, ns)));
        }

        for (auto ppp : edge[cloc])
        {
            int neigh = ppp.first;
            int a = ppp.second.first;
            int b = ppp.second.second;

            if (cs < a) continue;
            if (dist[neigh][cs-a] > cd + b)
            {
                dist[neigh][cs-a] = cd + b;
                q.push(make_pair (-dist[neigh][cs-a], make_pair (neigh, cs - a)));
            }
        }
    }
}

int main()
{
    ios_base::sync_with_stdio(0);

    cin >> N >> M >> S;
    for (int i = 0; i < M; i++)
    {
        int u, v, a, b;
        cin >> u >> v >> a >> b;
        u--, v--;
        edge[u].push_back(make_pair(v, make_pair (a, b)));
        edge[v].push_back(make_pair(u, make_pair (a, b)));
    }
    for (int i = 0; i < N; i++)
        cin >> C[i] >> D[i];

    for (int i = 0; i < MAXN; i++)
        for (int j = 0; j < MAXS; j++)
            dist[i][j] = 1e15;

    S = min (S, MAXS - 1);

    dijk();

    for (int i = 0; i < N; i++)
        for (int j = 0; j < MAXS; j++)
            dist[i][0] = min (dist[i][0], dist[i][j]);
    for (int i = 1; i < N; i++)
        cout << dist[i][0] << "\n";
}

Measured memory_bytes: 6664
using System;
using System.Linq;

class Program
{
    static void Main()
    {
        var a = Console.ReadLine().Split(' ').Select(x=>int.Parse(x)).ToList();

        if (a[0] < a[1])
        {
            Console.WriteLine("a < b");
        }
        else if (a[0] > a[1])
        {
            Console.WriteLine("a > b");
        }
        else
        {
            Console.WriteLine("a == b");
        }
    }
}



Measured memory_bytes: 16268
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.stream.Collectors;

public class Main {

	public static void main(String args[]) {
		FastScanner cin = new FastScanner(System.in);
		PrintWriter cout = new PrintWriter(System.out);
		solve(cin, cout);
		cout.flush();
	}

	private static void solve(FastScanner cin, PrintWriter cout) {
		// assert solve(1) == 1;

		int n = cin.nextInt();

		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = cin.nextInt();

		int[] ans = solve(n, a);
		String ansstr = Arrays.stream(ans).mapToObj(Integer::toString).collect(Collectors.joining(" "));
		cout.println(ansstr);
	}

	private static int[] solve(int n, int[] a) {
		int[] b = new int[n];
		for (int i = 0; i < n; i++)
			b[n / 2 + (i % 2 == 0 ? i / 2 : (-i - 1) / 2)] = a[i];
		if (n % 2 == 1)
			// reverese
			for (int i = 0; i < n / 2; i++) {
				int t = b[i];
				b[i] = b[n - 1 - i];
				b[n - 1 - i] = t;
			}
		return b;
	}

	static class FastScanner {
		private final InputStream in;
		private final byte[] buf = new byte[1 << 14];
		private int bufs = 0;
		private final long[] num = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
		private int ptr = 0;

		public FastScanner(InputStream in) {
			super();
			this.in = in;
		}

		boolean hasNext() {
			while (hasNextByte() && !isMeaningful(buf[ptr]))
				ptr++;
			return hasNextByte();
		}

		private boolean hasNextByte() {
			if (ptr < bufs)
				return true;
			ptr = 0;
			try {
				bufs = in.read(buf);
			} catch (IOException e) {
				throw new IllegalArgumentException(e);
			}
			if (bufs <= 0)
				return false;
			return true;
		}

		private static boolean isMeaningful(int b) {
			return 33 <= b && b <= 126;
			// return b != -1 && !Character.isWhitespace(b);
		}

		String next() {
			if (!hasNext())
				throw new IllegalArgumentException();
			StringBuilder sb = new StringBuilder();
			int b = read();
			while (isMeaningful(b)) {
				sb.appendCodePoint(b);
				b = read();
			}
			return sb.toString();
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		int nextInt() {
			long nl = nextLong();
			int ni = (int) nl;
			if (ni != nl)
				throw new IllegalArgumentException();
			return ni;
		}

		long nextLong() {
			if (!hasNext())
				throw new IllegalArgumentException();
			long n = 0;
			int plus = 1;
			int b = read();
			if (b == '-') {
				plus = -1;
				b = read();
			}
			if ('0' > b || b > '9')
				throw new java.lang.IllegalArgumentException();
			while (true) {
				if (!isMeaningful(b))
					return plus * n;
				n *= 10;
				n += num[b - '0'];
				b = read();
			}
		}

		private int read() {
			if (hasNextByte())
				return buf[ptr++];
			else
				return -1;
		}

	}
}


Measured memory_bytes: 47048
import java.util.*;

public class Main {
	public static void main(String[] args) {
		
		Scanner keyboard = new Scanner(System.in); 
		
		int N = keyboard.nextInt();
		int[] A = new int[100010];
		long ans = 0;
		
		for(int n = 0; n<N; n++) {
			int a = keyboard.nextInt();
			A[a]++;
			ans += a;
		}
		
		int Q = keyboard.nextInt();
		StringBuilder ANS = new StringBuilder();
		
		for(int q = 0; q<Q; q++) {
			int b = keyboard.nextInt();
			int c = keyboard.nextInt();
			//掛け算してLongになるとき、先頭にLongの形式で1をかけておくと、型がlongになる
			ans += 1L*c*A[b];
			ans -= 1L*b*A[b];
			
			A[c] += A[b];
			A[b] = 0;
			
			ANS.append(Long.toString(ans) + "\n");
		}
		
		System.out.println(ANS);
		keyboard.close();
	}
}


Measured memory_bytes: 63784
def solve():
  while True:
    m, n  = int(input()), int(input())
    if not m:
      break
    ices = [[0] + list(map(int,input().split())) + [0] for _ in range(n)]
    ices.insert(0, [0] * (m + 2),)
    ices.append([0] * (m + 2))
    score = [[0] * (m + 2) for _ in range(n + 2)]
    
    for x in range(1, n + 1):
      for y in range(1, m + 1):
        if ices[x][y]:
          score[x - 1][y] += 1
          score[x + 1][y] += 1
          score[x][y - 1] += 1
          score[x][y + 1] += 1
    
    def search(x, y, imap, acc):
      imap[x][y] = 0
      acc += 1
      a = b = c = d = 0
      if imap[x - 1][y]:
        a = search(x - 1, y, imap, acc)
      if imap[x + 1][y]:
        b = search(x + 1, y, imap, acc)
      if imap[x][y - 1]:
        c = search(x, y - 1, imap, acc)
      if imap[x][y + 1]:
        d = search(x, y + 1, imap, acc)
      imap[x][y] = 1
      return max(acc, a, b, c, d)
    
    ans = 0
    for x in range(1, n + 1):
      for y in range(1, m + 1):
        if score[x][y] in [1, 2] and ices[x][y]:
          a = search(x, y, ices, 0)
          if ans < a:
            ans = a
    
    print(ans)

solve()


Measured memory_bytes: 5812
#include <iostream>
#include <algorithm>
#include <vector>

using lint = long long;

bool solve() {
    int n;
    lint m, k;
    std::cin >> n >> m >> k;
    --m, --k;

    if (n == 0) return false;

    std::vector<int> ans(n, 0);
    for (int i = 0; i < n; ++i) {
        int j = n - i - 1;
        if ((m >> j) & 1) {
            ans[i] = 1 - ((k >> i) & 1);
            m = m & ((1LL << j) - 1);
        } else {
            for (auto& a : ans) a = 1 - a;
            ans[i] = ((k >> i) & 1);
            m = ~m & ((1LL << j) - 1);
        }
    }

    std::reverse(ans.begin(), ans.end());
    for (auto x : ans) std::cout << "LR"[x];
    std::cout << std::endl;

    return true;
}

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

    while (solve()) {}

    return 0;
}



Measured memory_bytes: 3112
def test
	n, k = gets.split(" ").map(&:to_i)
	h = n.times.map{gets.to_i}.sort

	ans = 10 ** 9 + 1
	(n-k+1).times do |i|
		delta = h[i..(i+k-1)][-1] - h[i..(i+k-1)][0]
		ans = delta if delta < ans
	end
	ans
end

puts test


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

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

  bool ok = false;
  for(int i = 1;i < 10;i++){
    if(N % i == 0){
      int a = N/i;
      if(0 < a && a < 10){
	ok = true;
	break;
      }
    }
  }

  std::cout << (ok ? "Yes" : "No") << std::endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pi acos(-1)
#define el << endl
using namespace std;
typedef long long ll;
const ll maxn = 2e5+10;
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);


    int n;
    cin>>n;
    int x = n%10;
    
    if(x ==2 || x==4 || x==5 || x==7 || x==9){
		cout << "hon" << "\n";
    }
    else if(x == 3){
		cout << "bon" << "\n";
    }
    else cout << "pon" << "\n";

    return 0;
}
/** Author: Me */
/** Alhamdulillah*/



Measured memory_bytes: 3648
a, b, c, d = gets.split.map(&:to_i)
ans = 0
if c == 1 || d == 1
elsif c == d
  ans = b - (a - 1)
  ans -= b / c - (a - 1) / c
else
  ans = b - (a - 1)
  ans -= b / c - (a - 1) / c
  ans -= b / d - (a - 1) / d
  ans += b / c.lcm(d) - (a - 1) / c.lcm(d)
end
puts ans

Measured memory_bytes: 1788
#include<cstdio>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<cstdlib>
#include<bitset>
#include<utility>
using namespace std;

unsigned long long n,num=0;


int main(void) {

	cin>>n;

	for (unsigned long long s = 1; s < sqrt(n); s++) {
		if(n%s==0&&(n/s)-1>s){
			num+=(n/s)-1;
			//cout<<s<<"\n";
			//cout<<(n/s)-1<<"\n";
		}
	}


	cout<<num<<"\n";

	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc= new Scanner(System.in);

		int h = sc.nextInt();
		int a = sc.nextInt();

		if(h % a == 0) {
			System.out.println(h / a);
		} else {
			System.out.println(h/a + 1);
		}
	}
}

Measured memory_bytes: 22868
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
using pll = pair<ll, ll>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(i) begin(i), end(i)

const int INF = 0x3fffffff;
const ll MINF = 0x7fffffffffff;
const ld DINF = numeric_limits<ld>::infinity();
const int MOD = 1000000007;
const int MODD = 998244353;
const ld EPS = 1e-9;
const ld PI = 3.1415926535897932;

template<class T> bool chmin(T &a, const T &b){ if(a > b){ a = b; return 1; } else return 0; }
template<class T> bool chmax(T &a, const T &b){ if(a < b){ a = b; return 1; } else return 0; }
template<class T> auto min(const T& a){ return *min_element(all(a)); }
template<class T> auto max(const T& a){ return *max_element(all(a)); }

ll gcd(ll a, ll b){ while(b){ ll c = b; b = a % b; a = c; } return a; }
ll lcm(ll a, ll b){ if(!a || !b) return 0; return a * b / gcd(a, b); }
ll pow_mod(ll n,ll k,ll m){ll r = 1;for(; k > 0;k >>= 1) {if (k & 1) r = (r * n) % m; n = (n * n) % m;}return r;}

//ここから。
int main(){
    int a;
    cin >> a;
    cout << a + a*a + a*a*a << endl;
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
#define SORT(a) sort(a.begin(), a.end())
#define RSORT(a) sort(a.rbegin(), a.rend())
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, start, end) for (int i = start; i < end; i++)
#define ALL(a) a.begin(), a.end()
#define MOD(a) a %= 1'000'000'007
using ll = long long;
using namespace std;
const int INF32       = 1'050'000'000;
const long long INF64 = 4'000'000'000'000'000'000;
const int MOD7        = 1'000'000'007;
const int MOD9        = 1'000'000'009;
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;
}

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

    int A, B, C;
    cin >> A >> B >> C;
    int cnt    = 0;
    auto print = [&cnt]() {
        std::cout << cnt << '\n';
        exit(0);
    };
    auto check = [&]() {
        if (A % 2 != 0)
            print();
        if (B % 2 != 0)
            print();
        if (C % 2 != 0)
            print();
        if (A == B && B == C) {
            std::cout << -1 << '\n';
            exit(0);
        }
    };

    while (true) {
        check();
        int a = A / 2;
        int b = B / 2;
        int c = C / 2;
        A     = b + c;
        B     = a + c;
        C     = a + c;
        cnt++;
    }

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
//#include <vector>
//#include <string>
//#include <algorithm>
//#include <math.h>
//#include <queue>
//#include <stack>
//#include <iomanip>

// sometimes used
//#include <set>
//#include <map>
//#include <numeric>
//#include <list>
//#include <deque>
//#include <unordered_map>

typedef long long LL;
//typedef long double LD;
using namespace std;
 
//#define MOD 1000000007
//#define MAX 100100
//#define NIL -1
//#define INFTY 1000000000000000000

int main(){
    LL a;
    LL b;
    LL c;
    LL x;
    LL ans=0;
    cin >> a;
    cin >> b;
    cin >> c;
    cin >> x;
    for(LL i=0; i<=a; i++){
        for(LL j=0; j<=b; j++){
            LL tmp=x-500*i-100*j;
            if(tmp%50==0 && tmp/50<=c && tmp/50>=0){
                ans++;
            }
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3560
def fun():

  x = int(input())
  y = [input().split() for i in range(x)]

  place = [0,0]
  time = 0
  
  for i in y:
    move = abs(int(i[1]) - place[0]) + abs(int(i[2]) - place[1])
    if (int(i[0]) - time) >= move and ((int(i[0]) - time) - move) % 2 == 0:
      place[0] = int(i[1])
      place[1] = int(i[2])
      time = int(i[0])
    else:
      return "No"
  return "Yes"

print(fun())

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

int n;

int main(){
	scanf("%d", &n);
	int pre = 0, ans = 0;
	for (int i = 1, x; i <= n; ++ i){
		scanf("%d", &x);
		if (x != i){
			ans += i - pre >> 1;
			pre = i;
		}
	}
	ans += n + 1 - pre >> 1;
	return printf("%d\n", ans), 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<string.h>
#include <iomanip>
#include<math.h>
#include<queue>
#include<vector>
#include<algorithm>
#define Max (int)1e5+5
#define MAX2 (int)1e5+5
#define MOD ((int)1e9+7)
using namespace std;

long long int dp[Max];

long long int ways(int n,int a[]){
	if(n == 0)
		return 1;
	else if(n < 0)
		return 0;
	if(dp[n] != -1)
		return dp[n];
	long long int tmp = 0;
	if(a[n-1] == 0)
		tmp = (tmp%MOD + ways(n-1,a)%MOD)%MOD;
	if(a[n-2] == 0)
		tmp = (tmp%MOD + ways(n-2,a)%MOD)%MOD;
	dp[n] = tmp;
	return tmp;
	
}

int main(){
	int n,m,a[Max],i,x;
	for(i=0;i<Max;i++){
		dp[i] = -1;
		a[i] = 0;
	}
	scanf("%d%d",&n,&m);
	for(i=0;i<m;i++){
		scanf("%d",&x);
		a[x]++;
	}
	long long int tmp;
	for(i=n;i>=1;i--){
		if(a[i] == 0){
			tmp = ways(i,a)%MOD;
			break;
		}
	}
	printf("%lld\n",tmp);
	return 0;
}



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

bool solve() {
    int N;
    cin >> N;

    if(!N) return false;

    int ans = 0;
    bool l = false, r = false;
    bool nxt = true;
    for(int i = 0; i < N; i++) {
        string s;
        cin >> s;
        bool &b = (s[0] == 'l' ? l : r);
        b = (s[1] == 'u' ? true : false);
        if(l == nxt && r == nxt) {
            ans++;
            nxt = !nxt;
        }
    }
    cout << ans << endl;
    return true;
}

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



Measured memory_bytes: 3076
x, n = map(int, input().split())
if n == 0:
    print(x)
else:
    p = {int(i) for i in input().split()}
    for i in range(55):
        if x-i not in p:
            print(x-i)
            break
        if x+i not in p:
            print(x+i)
            break

Measured memory_bytes: 9184
using System;
using System.Linq;

namespace A___ringring
{
    class Program
    {
        static void Main(string[] args)
        {
            var a_b_c = Console.ReadLine().Split().Select(int.Parse).OrderBy(x => x).ToArray();

            Console.WriteLine(a_b_c.Where((e, i) => i < 2).Sum());
        }
    }
}


Measured memory_bytes: 11348
g,l=input().split()
c=int(l)
a=[]
n=[]
m=[]

for i in range(c):
  i1,i2=input().split()
  a.append([i1,i2])
  if i1 =='1':
    n.append(i2)
  if i2 =='1':
    n.append(i1)
  if i1 ==g:
    m.append(i2)
  if i2 ==g:
    m.append(i1)

if list(set(m) & set(n)):
  print('POSSIBLE')
else:
  print('IMPOSSIBLE')

  

Measured memory_bytes: 52640
#include<bits/stdc++.h>
using namespace std;
//#define int long long
#define fo(a,b) for(int a=0;a<b;a++)
#define Sort(a) sort(a.begin(),a.end())
#define rev(a) reverse(a.begin(),a.end())
#define fi first
#define se second
#define co(a) cout<<a<<endl
#define sz size()
#define bgn begin()
#define en end()
#define pb(a) push_back(a)
#define pop pop_back
#define V vector
#define P pair
#define V2(a,b,c) V<V<int>> a(b,V<int>(c))
#define V2a(a,b,c,d) V<V<int>> a(b,V<int>(c,d))
#define incin(a) int a; cin>>a
//#define min min<int>
//#define max max<int>
template<class T>
 void cou(vector<vector<T>> a){
  int b=a.size();
  int c=a[0].size();
  fo(i,b){
    fo(j,c){
      cout<<a[i][j];
      if(j==c-1)
        cout<<endl;
      else
        cout<<' ';
    }
  }
}
/*template<>
 void cou(vector<vector<char>> a){
  int b=a.size();
  int c=a[0].size();
  fo(i,b){
    fo(j,c){
      cout<<a[i][j];
      if(j==c-1)
        cout<<endl;
      else
        cout<<' ';
    }
  }
}*/
 int wari(int a,int b) {
   if(a%b==0)
     return a/b;
   else
     return a/b+1;
 }
 int keta(int a){
  double b=a;
  b=log10(b);
  int c=b;
  return c+1;
 }
 int souwa(int a){
  return a*(a+1)/2;
 }
 int lcm(int a,int b){
  int d=a,e=b,f;
  if(a<b)
    swap(a,b);
  int c,m=1;
  while(m){
    c=a%b;
    if(c==0){
       f=b;
      m--;
    }
    else{
      a=b;
      b=c;
 }
  }
  return d*e/f;
    }
  int gcm(int a,int b){
      int d=a,e=b,f;
  if(a<b)
    swap(a,b);
  int c,m=1;
  while(m){
    c=a%b;
    if(c==0){
       f=b;
      m--;
    }
    else{
      a=b;
      b=c;
 }
  }
  return f;
  }
 bool prime(int a){
   if(a<2)
     return false;
   else if(a==2)
     return true;
   else if(a%2==0)
     return false;
   double b=sqrt(a);
    for(int i=3;i<=b;i+=2){
      if(a%i==0){
        return false;
      }
    }
   return true;
 }
struct Union{
  vector<int> par;
  Union(int n){
	par= vector<int>(n, -1);
  }
  int find(int x){
    if(par[x]<0)
      return x;
    else
      return par[x]=find(par[x]);
  }
  bool same(int a,int b){
    return find(a)==find(b);
  }
  int Size(int a){
    return -par[find(a)];
  }
  void unite(int a,int b){
    a=find(a);
    b=find(b);
    if(a==b)
      return;
    if(Size(b)>Size(a))
      swap<int>(a,b);
    par[a]+=par[b];
    par[b]=a;
  }
};
int ketas(int a){
  string b=to_string(a);
  int c=0;
  fo(i,keta(a)){
    c+=b[i]-'0';
  }
  return c;
}
/*struct aa{
	vector<int> gt;
  aa(int n){
	gt= vector<int>(n, 1);
  }
	void c(V<int> d,int b){
	if(d[b]==0){
		gt[d[b]-1]++;
		gt[gt.sz-1]++;
	}
	else{
		gt[d[b]-1]++;
		c(d,d[d[b]]-1);
	}
}
void cok(int a){
	cout<<gt[a-1]<<endl;
	fo(i,a-1)
	cout<<gt[i]<<endl;
}
};
*/
signed main(){
	int a,b;
	cin>>a>>b;
	if(a%3==0||b%3==0||(a+b)%3==0)
		cout<<"Possible"<<endl;
	else
		cout<<"Impossible"<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define int long long
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e18;

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    int n = s.size();
    int a = 0, b = 0;
    rep(i, 0, n){
        if(s[i] == '0') a++;
        else b++;
    }
    cout << min(a, b) * 2 << endl;
}


Measured memory_bytes: 512
#include <iostream>
#include <math.h>
using namespace std;

#define int long long
const int INF = 1e18+1, EPSILON = 1e7;
int n, s;
int func(int b, int n)
{
    if (n < b) return n;
    else return func(b,(n/b))+(n%b);
}

signed main()
{
    cin >> n >> s;
    if (n == s)
    {
        return cout << n+1, 0;
    }
    for (int i = 2; i <= sqrt(n); i++)
    {
        if (func(i,n) == s)
            return cout << i, 0;
    }
    int tmp = n-s;
    for (int i = sqrt(tmp); i >= 1; i--)
    {
        if (tmp % i == 0)
        {
            int k = tmp/i;
            if (func(k+1,n) == s)
                return cout << k+1,0;
        }
    }
    cout << -1;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> Pii;
#define pb push_back
#define mp make_pair
#define MOD 1000000007
#define INF 1000000000
#define rep(i,a,b) for(int i =(a);i<(b);i++)
#define fs first
#define ss second
inline int Scan() {
    int x=0;int f=1; char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-') f=-1; ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0'; ch=getchar();}
    return x*f;
}

template<typename T, typename U>
static inline void amin(T &x, U y)
{
    if (y < x)
        x = y;
}

// call by reference is used in x
template<typename T, typename U>
static inline void amax(T &x, U y)
{
    if (x < y)
        x = y;
}
//////////////////////////////////////end of template//////////////////////////////////////

int main(){

    int n,k;
    cin >> n >> k;
    
    vector<ll> a(n+1,0);
    
    for(int i= 1;i<=n;i++) cin >> a[i];
    
    for(int i =1;i<=n;i++) a[i]+=a[i-1];
    
    //for(int i =1;i<=n;i++) a[i] = (a[i] - i)%k; 
    
    map<ll,ll> m;
    
    ll ans = 0;
    
    
    
    for(int i =0;i<=n;i++){
		
		if( i >= k) m[(a[i-k]-(i-k))%k]--;
		
		ans += m[(a[i]-i)%k];
		m[(a[i]-i)%k]++;	
		 
		}
     
   cout << ans << endl;

}




Measured memory_bytes: 14336
#include <bits/stdc++.h>
using namespace std;
int pro(int x, int y, int z) {
  return x*x+y*y+z*z+x*y+y*z+z*x;
}
int main() {
  int N;
  cin >> N;
  for(int i = 1; i <= N; i++) {
    int c = 0;
    for(int m = 1; pro(m, 1, 1) <= i; m++) {
      for(int j = 1; pro(m, j, 1) <= i; j++) {
        for(int k = 1; pro(m, j, k) <= i; k++) {
          if(pro(m, j, k) == i) {
            c++;
          }
        }
      }
    }
    cout << c << endl;
  }
}

Measured memory_bytes: 3552
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
//order_of_key(x) : number of items less than x
//find_by_order(x) : iterator to x

#define mem(dp,a)           memset(dp,a,sizeof dp)
#define rep(i,a,b)          for(ll i=a;i<b;i++)
#define pb(x)               push_back(x)
#define mp(x,y)             make_pair(x,y)
#define fastio              ios_base::sync_with_stdio(false);cin.tie(NULL)
#define F                   first
#define S                   second
#define all(v)              (v).begin(),(v).end()
#define pi                  3.14159265359
ll INF=1e18+10;
ll MOD=998244353;
ll mod=1e9+7;

int main()
{
    ll n,r;cin>>n>>r;
    ll i=0;
    if(n>=10)
        i=r;
    else
        i=r+100*(10-n);
    cout<<i<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ADD(a, b) a = (a + (ll)b) % mod
#define MUL(a, b) a = (a * (ll)b) % mod
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define rep(i, a, b) for(int i = a; i < b; i++)
#define rer(i, a, b) for(int i = a - 1; i >= b; i--)
#define all(a) (a).begin(), (a).end()
#define sec second
#define fst first
#define debug(fmt, ...) Debug(__LINE__, ":", fmt, ##__VA_ARGS__)

using namespace std;

typedef long long ll;
typedef pair<int, int> pi;
typedef pair<int, pi> ppi;
typedef vector<ll> vec;

const int MAX_N = 200010;
const double eps = 1e-6;
const ll mod = 1000000007;
const int inf = 1 << 30;

void Debug() {cout << '\n'; }

template<class FIRST, class... REST> 
void Debug(FIRST arg, REST... rest) { cout << arg << " "; Debug(rest...); }

template<class T>
ostream& operator<< (ostream& out, const vector<T>& v) {
	out << "[";
	if(!v.empty()) {
		rep(i, 0, (int)v.size() - 1) out << v[i] << ", ";
		out << v.back();
	}
	out << "]";
  return out;
}

template<class S, class T>
ostream& operator<< (ostream& out, const pair<S, T>& v) {
	out << "(" << v.first << ", " << v.second << ")";
	return out;
}

///g++ -g3 -std=c++0x -DLOCAL -Wall -ftrapv -D_GLIBCXX_DEBUG -Wl,-stack,268435456 -o
///g++ -O2 -std=c++0x -DLOCAL -Wall -Wl,-stack,268435456 -o

////////////////////////////////////////////////////////////////////////

int N;
string str;

void solve() {
	int a = 0, b = 0;
	cin >> N;
	cin >> str;
	rep(i, 0, N) {
		if(str[i] == '(') a++;
		else {
			if(a > 0) a--;
			else b++;
		}
	}
	string s1 = string(b, '(');
	string s2 = string(a, ')');
	cout << s1 + str + s2 << '\n';
}

int main() {
	ios::sync_with_stdio(false);
    cin.tie(0);	
    cout << fixed;
	cout.precision(20);
#ifdef LOCAL
    freopen("in.txt", "rt", stdin);
#endif	
	solve();
#ifdef LOCAL
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
	return 0;
}



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

using namespace std;
 
#define rep(i, n) for(int i=0; i<(n); i++)
#define FOR(i, m, n) for(int i=(m);i<(n);i++)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define SORT(x) sort((x).begin(),(x).end())
#define REVE(x) reverse((x).begin(),(x).end())
#define mp make_pair
#define pb push_back
 
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PII;
typedef long long LL;
typedef vector<bool> VB;

int main() {
    int n;
    cin >> n;
    char s[n];
    cin >> s;
    if(n%2 != 0) {
        puts("No");
        return 0;        
    }
    if(n%2 == 0) {
        for(int i = 0;i<n/2;i++) {
            if(s[i] != s[n/2 + i]) {
                puts("No");
                return 0;
            }
        }
    }
    puts("Yes");
}

Measured memory_bytes: 256