akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;

int main() {
    int x, y; cin >> x >> y;
    {
        int ans = ~1U >> 1;
        if ( x <=  y) ans = min(ans,  y - x + 0);
        if (-x <=  y) ans = min(ans,  y + x + 1);
        if ( x <= -y) ans = min(ans, -y - x + 1);
        if (-x <= -y) ans = min(ans, -y + x + 2);
        cout << ans << endl;
    }
    return 0;
}


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

constexpr double INF = 1e9;
constexpr int MAX = 2e5;

int main() {
    int N;
    cin >> N;
    vector<int> a(N);
    for(int i=0; i<N; ++i) {
        cin >> a[i];
    }
    vector<vector<double>> dp(N+1, vector<double>(MAX, INF));
    for(int i=0; i<MAX; ++i) {
        dp[0][i] = 0;
    }
    for(int i=0; i<N; ++i) {
        for(int j=1; j<MAX; ++j) {
            for(int k=1; j*k < MAX; ++k) {
                dp[i+1][j*k] = min(dp[i+1][j*k], max(dp[i][j], abs((double)a[i] - j*k) / a[i]));
            }
        }
    }
    cout << fixed << setprecision(10) << *min_element(dp[N].begin(), dp[N].end()) << endl;
}


Measured memory_bytes: 37128
import java.util.*;

class Main {

	public static void main(String args[]){
		Scanner in = new Scanner(System.in);
		int ns[] = new int[101];
		while(in.hasNext()) ns[in.nextInt()]++;
		int best=0;
		for(int e: ns)if(e>best)best=e;
		for(int i=1; i<=100; i++)if(ns[i]==best)System.out.println(i);
	}

}

Measured memory_bytes: 12000
//Power Of Ninja Go
#include <bits/stdc++.h>
//#ifdef atom #else #endif
using namespace std;
typedef long long ll; typedef pair<int, int> ii;
#define X first
#define Y second
#define vi vector<int>
#define vii vector< ii >
#define pb push_back
const int maxn = 105;
ii R[maxn], B[maxn];
vi adj[2*maxn+2];
int res[2*maxn+2][2*maxn+2];
int p[2*maxn+2];
int vis[2*maxn+2];
int s, t;
int augment(int u, int minnow)
{
    if(u == s) return minnow;
    if(p[u] == -1) return 0;
    int cap = augment(p[u], min(minnow, res[p[u]][u]));
    res[p[u]][u] -= cap; res[u][p[u]] += cap;
    return cap;
}
int main()
{
    //#ifndef atom freopen(".in", "r", stdin); freopen(".out", "w", stdout); #endif
    int n; scanf("%d", &n);
    for(int i = 1; i<= n; i++) scanf("%d %d", &R[i].X, &R[i].Y);
    for(int i = 1; i<= n; i++) scanf("%d %d", &B[i].X, &B[i].Y);
    for(int i = 1; i<= n; i++)
    {
        for(int j = 1; j<= n; j++)
        {
            if(R[i].X< B[j].X && R[i].Y< B[j].Y)
            {
                adj[i].pb(n+j);
                adj[n+j].pb(i);
                res[i][n+j] = 1;
            }
        }
    }
    for(int i = 1; i<= n; i++) adj[0].pb(i), res[0][i] = 1, adj[i].pb(0);
    for(int i = n+1; i<= 2*n; i++) adj[i].pb(2*n+1), res[i][2*n+1] = 1, adj[2*n+1].pb(i);
    int mf = 0;
    s = 0, t = 2*n+1;
    while(true)
    {
        memset(p, -1, sizeof p);
        memset(vis, 0, sizeof vis);
        queue<int> Q;
        Q.push(0);
        vis[0] = 1;
        while(!Q.empty())
        {
            int u = Q.front(); Q.pop();
            //printf("%d\n", u);
            if(u == t) break;
            for(auto v : adj[u])
            {
                if(!vis[v] && res[u][v])
                {
                    vis[v] = 1;
                    p[v] = u;
                    Q.push(v);
                }
            }
        }
        int f = augment(t, 1e9);
        if(!f) break;
        mf += f;
    }
    printf("%d\n", mf);
}


Measured memory_bytes: 512
#float型を許すな
#numpyはpythonで
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi,factorial
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7

n=I()
ans=0
for i in range(1,n+1):
    #print(n-i,i)
    if (n-i)%i==0 and i<(n-i)//i:
        ans+=((n-i)//i)
        #print(i)
    if (n-i)+100<i**2:
        #print(i)
        break
    #print(i)
print(ans)
    

Measured memory_bytes: 9392
import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict

s = list(input())
t = list(input())
c = 0
for i in range(len(s)):
    if s[i] != t[i]:
        c+=1

print(c)


Measured memory_bytes: 12672
/*Author -> Sambhu show(JGEC)*/
#include<bits/stdc++.h>
using namespace std;
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);
#define itc ll t;cin>>t;while(t--)
#define PI 3.141592653589793238
#define Max(a,b,c) max(a,max(b,c));
#define Min(a,b,c) min(a,min(b,c));
#define all(v) v.begin(),v.end()
#define ll long long int
#define ld long double
#define pb push_back
#define eb emplace_back
#define gcd(a,b) __gcd(a,b)
#define fi first
#define se second
#define endl "\n"
void solve()
{
	int n;
	cin>>n;
	for(int i=0;i<n;i++)
		cout<<"ACL";
}
int main()
{
/*#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif*/
	fio
	//itc
	solve();

	return 0;
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; --i)
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define FORR(i, a, b) for (int i = b - 1; i >= a; --i)
#define SORT(v) sort(v.begin(), v.end())
#define SORTR(v) sort(v.rbegin(), v.rend())
#define REV(v) reverse(v.begin(), v.end())
#define ITER(itr, v) for (auto itr = v.begin(); itr != v.end(); ++itr)
#define LB(v, x) (lower_bound(v.begin(), v.end(), x) - v.begin())
#define UB(v, x) (upper_bound(v.begin(), v.end(), x) - v.begin())
#define SZ(v) (int)v.size()
using namespace std;
using ll = long long;
using P = pair<int, int>;

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

    int N, M;
    cin >> N >> M;
    vector<int> H(N);
    REP(i, N) cin >> H[i];
    vector<vector<int>> edge(N);
    REP(i, M) {
        int a, b;
        cin >> a >> b;
        edge[--a].emplace_back(--b);
        edge[b].emplace_back(a);
    }
    int res = 0;
    REP(i, N) {
        bool flg = true;
        for (auto &j : edge[i]) {
            if (H[i] <= H[j]) flg = false;
        }
        if (flg) ++res;
    }
    cout << res << endl;

    return 0;
}

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

int main(){
  map<int,int> m,m2;
  int n; cin >> n;
  
  rep(i,n){
    int x; cin >> x;
    if(i%2) m2[x]++;
    else m[x]++;
  }
  
  vector<pair<int, int>> L,R;
  
  for (auto a:m){
    L.push_back(make_pair(a.second,a.first));
  }
  for (auto a:m2){
    R.push_back(make_pair(a.second,a.first));
  }
  
  sort(L.begin(),L.end(),greater<pair<int,int>>());
  sort(R.begin(),R.end(),greater<pair<int,int>>());
  
  if(L[0].second != R[0].second){
    cout << n - L[0].first - R[0].first;
  }
  else{
    cout << n - max(L[0].first + R[1].first, L[1].first + R[0].first);
  }
}


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

using namespace std;
typedef long long ll;

int main(){
    int w,h,n;
    cin >> w >> h >> n;
    int x,y,a;
    int xl=0,xh=w,yl=0,yh=h;
    for(int i=0;i<n;i++){
        cin >> x >> y >> a;
        if(a==1){if(xl<x)xl=x;}
        if(a==2){if(xh>x)xh=x;}
        if(a==3){if(yl<y)yl=y;}
        if(a==4){if(yh>y)yh=y;}
    }
    if(xh-xl<0||yh-yl<0)cout << 0 << endl;
    else cout << (xh-xl)*(yh-yl) << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h> 
using namespace std; 
int gi() { 
	int res = 0, w = 1; 
	char ch = getchar(); 
	while (ch != '-' && !isdigit(ch)) ch = getchar(); 
	if (ch == '-') w = -1, ch = getchar(); 
	while (isdigit(ch)) res = res * 10 + ch - '0', ch = getchar(); 
	return res * w; 
}
const int INF = 1e9; 
const int MAX_N = 105;
int N; 
struct Graph { 
	vector<int> E[MAX_N]; 
	int fa[MAX_N], deg[MAX_N]; 
	void init() { for (int i = 1; i <= N; i++) fa[i] = deg[i] = 0, E[i].clear(); } 
	void Add_Edge(int u, int v) { E[u].push_back(v), ++deg[v]; } 
	void dfs(int x) { 
		for (int v : E[x]) 
			if (v != fa[x]) fa[v] = x, dfs(v); 
	} 
} A, B, C; 
bool check(int x) { return A.fa[x] == B.fa[x]; } 
int solve() { 
	int res = 0; 
	for (int i = 1; i <= N; i++) res += !check(i); 
	C.init(); 
	for (int i = 1; i <= N; i++) { 
		if (check(i)) {
			if (!check(A.fa[i])) return INF; 
			else continue; 
		} 
		if (!check(A.fa[i])) C.Add_Edge(i, A.fa[i]); 
		if (!check(B.fa[i])) C.Add_Edge(B.fa[i], i); 
	} 
	queue<int> que; int siz = 0;
	for (int i = 1; i <= N; i++) if (!C.deg[i]) que.push(i); 
	while (!que.empty()) {
		int x = que.front(); que.pop(), ++siz; 
		for (int v : C.E[x]) 
			if (!--C.deg[v]) que.push(v); 
	} 
	return siz == N ? res : INF; 
} 
int main () { 
	int T = gi(); 
	while (T--) { 
		N = gi(); 
		for (int i = 1; i < N; i++) { 
			int u = gi(), v = gi(); 
			A.Add_Edge(u, v), A.Add_Edge(v, u); 
		} 
		for (int i = 1; i < N; i++) { 
			int u = gi(), v = gi(); 
			B.Add_Edge(u, v), B.Add_Edge(v, u); 
		} 
		int ans = INF; 
		for (int i = 1; i <= N; i++) { 
			A.fa[i] = B.fa[i] = 0; 
			A.dfs(i), B.dfs(i), ans = min(ans, solve()); 
			if (A.deg[i] != 1) continue; 
			for (int j = 1; j <= N; j++) {
				if (i == j) continue; 
				A.fa[j] = i, A.dfs(j), A.fa[i] = 0, ans = min(ans, solve() + 1); 
			} 
		} 
		printf("%d\n", ans == INF ? -1 : ans); 
		A.init(), B.init(), C.init(); 
	} 
    return 0; 
} 

Measured memory_bytes: 3728
from collections import deque
K=int(input())
q=deque([1,2,3,4,5,6,7,8,9])
for i in range(K):
    ans=q.popleft()
    tmp=ans
    if tmp%10 >0:
        q.append(tmp*10+tmp%10-1)
    q.append(tmp*10+tmp%10)
    if tmp%10 < 9:
        q.append(tmp*10+tmp%10+1)
print(ans)

Measured memory_bytes: 11908
#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;
ll n,k;
ll a[200005];
ll ans; 
inline void read(ll &x)
{
	ll f;char c;
	for (f=1,c=getchar();c<'0'||c>'9';c=getchar()) if(c=='-') f=-1;
	for (x=0;c<='9'&&c>='0';c=getchar()) x=x*10+(c&15);x*=f;
}
inline int mn(int _x,int _y)
{
	return _x<_y?_x:_y;
}
inline int mx(int _x,int _y)
{
	return _x>_y?_x:_y;
}
inline int ab(int _x)
{
	if(_x<0) return -_x;
	else return _x;
}
inline bool cmp(ll x,ll y)
{
	return x>y; 
}
int main()
{
	read(n);read(k);
	for(ll i=1;i<=n;i++) read(a[i]);
	sort(a+1,a+n+1,cmp);
	if(k>=n) puts("0");
	else
	{
		for(ll i=k+1;i<=n;i++)
			ans+=a[i];
		printf("%lld\n",ans); 
	}
	return 0;
}



Measured memory_bytes: 1792
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner scn = new Scanner(System.in);
   	int n = scn.nextInt();
    String s = scn.next();
    int asc ;
    char ch[] = new char[s.length()];
    
    for(int i=0; i<s.length();i++){
    	asc = (int)s.charAt(i) + n;
      	if(asc > 90) asc -=26;
      	ch[i] = (char)asc;
    }
     for(int i=0; i<s.length();i++){
    	System.out.print(ch[i]);
    }
  }
}


Measured memory_bytes: 39276
#include<stdio.h>
int fib(int);
int d[50];
int main(){
  int N,i;
  for(i=0;i<50;i++)d[i]=-1;
  scanf("%d",&N);
  printf("%d\n",fib(N));
}
int fib(int n){
  if(n==1||n==0){
    return d[n]=1;
  }
  if(d[n]!=-1){
    return d[n];
  }
  return d[n]=fib(n-1)+fib(n-2);
}



Measured memory_bytes: 2104
open System

let getIntLine() = Console.ReadLine().Split(' ') |> Array.map Int32.Parse

let rec getMaxMin lMax rMin = function
 | [] -> failwith "Undefined"
 | [ _ ] ->
    let [| l; r |] = getIntLine()
    max l lMax, min r rMin
 | _ :: xs ->
    let [| l; r |] = getIntLine()
    getMaxMin (max l lMax) (min r rMin) xs

[<EntryPoint>]
let main _ =
    let [| n; m |] = getIntLine()
    let lMax, rMin = getMaxMin 0 Int32.MaxValue [ 1..m ]
    let res =
        if lMax <= rMin && lMax <= n then
            (min rMin n) - lMax + 1
        else
            0
    printfn "%d" res

    0



Measured memory_bytes: 23352
#include<iostream>
#include<math.h>
#include<vector>
#include<algorithm>
#include<string.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
long long int mod=1e9+7;
bool debug=false;
typedef long long ll;
int main(){
	int a,b;
	cin>>a>>b;
	int u,v,w;
	u=a+b;
	v=a-b;
	w=a*b;
	if(u<v)u=v;
	if(u<w)u=w;
	cout<<u<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define F first
#define S second
#define pb push_back
using namespace std;
const int maxn=1e6+3;
const int M=998244353;
typedef long long ll;
typedef pair<int,int> pi;
int n,pre[maxn],nxt[maxn][26],cnt[maxn][26],a[maxn],c[maxn],cc;
ll ans;
int go(int x,int y){
    if (!nxt[x][y]){
        nxt[x][y]=++cc;
        pre[cc]=x;
    }
    return nxt[x][y];
}
void add(int x,int mask){
    for (int i=0;i<26;i++) if (mask&(1<<i)) cnt[x][i]++;
}
int main(){
    scanf("%d",&n);
    for (int i=1;i<=n;i++){
        string s; cin >> s;
        reverse(s.begin(),s.end());
        int p=0,mask=0,m=s.size();
        for (int j=0;j<m;j++) p=go(p,s[j]-'a');
        a[i]=p; c[i]=s[m-1]-'a';
        for (int j=m-1;j>=0;j--) p=pre[p],mask|=1<<(s[j]-'a'),add(p,mask);
    }
    for (int i=1;i<=n;i++) ans+=cnt[pre[a[i]]][c[i]];
    printf("%lld\n",ans-n);
    return 0;
}


Measured memory_bytes: 210476
#include<cstdio>
inline int in();
inline void wr(int);
int main(int argc,char**argv){
	register int n=in();
	register int ans=1000-n%1000;
	wr(ans==1000?0:ans),putchar('\n');
}
inline int in(){
	register char c=getchar();
	register int x=0,f=1;
	for(;c<'0'||c>'9';c=getchar())
		if(c=='-')f=-1;
	for(;c>='0'&&c<='9';c=getchar())
		x=(x<<1)+(x<<3)+(c&15);
	return x*f;
}
inline void wr(int x){
	if(x<0)putchar('-'),x=-x;
	if(x/10)wr(x/10);
	putchar(x%10+'0');
}


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

#define rep(i, x, n) for (int i = x; i < n; i++)
typedef long long ll;

const int INF = 1e9 + 7;

using namespace std;

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

	cout << pow(n, 3) << endl;

	return 0;
}


Measured memory_bytes: 384
// mapはキー／値の対を保持する理想コンテナ
// 連想配列
// 配列の添字？が数でなくても使えるイメージ？
// 

#include <iostream>
#include <string>
#include <map>
#include <algorithm>

using namespace std;

int main(void){

  string s;
  map< string , int > count; // キー(添字？)がstring型、値がintのmap
  string num;
  string len;

  while( cin >> s ){
    int c = ++count[s];                    //初期化は必要なし？  
    if( c > count[num] ) num = s;          //ここで単語
    if( s.size() > len.size() ) len = s;   //ここで文字数
  }
  cout << num << " " << len << endl;
  return 0;
}

Measured memory_bytes: 1196
from fractions import gcd
A, B, C, D = map(int,input().split())
total = B - A + 1
divC = B//C - (A-1)//C
divD = B//D - (A-1)//D
lcm = int(C * D / gcd(C, D))
divCD = B//lcm - (A-1)//lcm
print(total - divC - divD + divCD)

Measured memory_bytes: 5088
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;

ll INF = (1LL << 60);

class Graph{
public:
    struct edge{
        int from, to;
        ll cost;
    };

    int N;
    vector<ll> d;
    vector<edge> E;

    Graph(int _N){
        N = _N;
        d.resize(N, INF);
    }

    void make_edge(int s, int t, ll c){
        E.push_back(edge{s, t, c});
    }

    bool bellman_ford(int s){
        d[s] = 0;
        for(int i = 0; i < 3 * N; i++){
            bool update = false;
            for(int j = 0; j < (int)E.size(); j++){
                edge e = E[j];
                if(d[e.from] != INF && d[e.to] > d[e.from] + e.cost){
                    //cout << e.from << "  " << e.to << endl;
                    update = true;
                    d[e.to] = d[e.from] + e.cost;
                    if(e.to == N - 1 && i >= N - 1) return true;
                }
            }

            if(!update) return false;
        }

        return false;
    }

    ll get_cost(int t){
        return d[t];
    }
};

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

    Graph gr = Graph(N);
    for(int i = 0; i < M; i++){
        int a, b;
        ll c;
        cin >> a >> b >> c;
        gr.make_edge(a - 1, b - 1, -c);
    }

    if(gr.bellman_ford(0)){
        cout << "inf" << endl;
    } else {
        cout << -gr.get_cost(N - 1) << endl;
    }

    return 0;
}

Measured memory_bytes: 256
while True:
    a, b = map(int, raw_input().split(' '))
    if a == 0 and b == 0:
        break
    for i in range(a):
        if b == 1:
            print "#"
        elif i == 0:
            print "#" * b
        elif i == a - 1:
            print "#" * b
        else:
            print "#" + "." * (b-2) + "#"
    print ''

Measured memory_bytes: 6288
s=[input()]
q=int(input())
turn=True
l=""
for i in range(q):
    qq=input().split()
    if qq[0]=='1':
        turn=not turn
    else:
        if turn==bool(int(qq[1])-2):
            l+=qq[2]
        else:
            s.append(qq[2])

text=l[::-1]+"".join(s)
print(text if turn else text[::-1])

Measured memory_bytes: 5140
#include<stdio.h>
#include<string.h>
 
#define M 30000000
#define L 14
 
char H[M];
char str[L]; 

int getChar(char ch)
{
  if(ch == 'A')return 1;
  else if(ch == 'C')return 2;
  else if(ch == 'G')return 3;
  else if(ch == 'T')return 4;
}
 

int getkey(){
  long long sum = 0, p = 1;
  long long i;
  
  for(i = 0;i < strlen(str);i ++)
    {
    sum += p * (getChar(str[i]));
    p *= 5;
  }
  return sum;
}
 
 
int find(){
  int key = getkey();

  if(H[key])
    {
    return 1;
  }
  return 0;
}
 
void insert(){
  
  H[getkey()] = 1;
  
}

int main(){
  
  int i,n,h;
  char com[9];
 
  scanf("%d",&n);
 
  for(i = 0;i < n;i++)
    {
    scanf("%s %s",com,str);
 
    if(com[0] == 'i'){
      insert(str);
    }
    else{
      if(find(str)){
    printf("yes\n");
      }
      else{
    printf("no\n");
      }
    }
  }
  return 0;
}

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

int main(){
	string s, t; cin>>s>>t;
	int ans = 1e9;
	rep(i, s.size() - t.size() + 1){
		int c = 0;
		rep(j, t.size()) if(s[i+j] != t[j]) c++;
		ans = min(ans, c);
	}
	cout<< ans <<endl;
}


Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
long long const MAX=3002;
long long dp[MAX][MAX];
void funk()
{long long i,j;
for(i=0;i<MAX;i++)
{for(j=0;j<MAX;j++)
{dp[0][0]=0;}}}
int main()
{long long i,j,n,r,k,p,w,y,sum,m,x;
cin>>n;
long long a[n];
for(i=0;i<n;i++)
{cin>>a[i];}
for(i=0;i<n;i++)
{dp[i][i]=a[i];}
for(i=n-1;i>=0;i--)
{for(j=i+1;j<n;j++)
{dp[i][j]=max(a[j]-dp[i][j-1],a[i]-dp[i+1][j]);}}
cout<<dp[0][n-1];

return 0;}


Measured memory_bytes: 70016
#include<iostream>
#include<cstdio>
#define _USE_MATH_DEFINES
#include<math.h>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<list>
#include<map>
#include<unordered_map>
#include<set>
#include <algorithm>
#include <utility>

using std::cin;
using std::cout;
using std::endl;
using std::string;

typedef unsigned long long ull;

#define Prime1 1000000007
#define Prime2 9999973

int i, j, k, l, m, n;
int H, W, N,K, M, Q;
int a, b, c;

//ユークリッドの互除法
int gcd(int a, int b) {
	return b != 0 ? gcd(b, a % b) : a;
}

int main()
{
	cin >> N >> K;
	int Max = 0;
	int GCD;
	std::vector<int> A(N);
	for (i = 0; i < N; i++)
	{
		cin >> A[i];
		if (Max < A[i])Max = A[i];
	}
	if (Max < K)
	{
		cout << "IMPOSSIBLE\n";
		return 0;
	}
	std::sort(A.begin(), A.end());
	GCD = A[N-1];
	for (i = 0; i < N; i++)
	{
		k = gcd(GCD, A[i]);
		if (k != GCD)
		{
			A.push_back(k);
			N++;
			i = -1;
			GCD = k;
		}
		if (K%GCD == 0)
		{
			cout << "POSSIBLE\n";
			return 0;
		}
	}

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

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

struct SegTree {
  int n;
  string s;
  vector<string> d;

  SegTree(int _n, string _s) {
    init(_n);
    build(_n, _s);
  }
  void init(int _n) {
    n = 1;
    while (n < _n) n *= 2;
    d = vector<string>(2*n-1, "");
  }
  void build(int _n, string _s) {
    if (_n != (int)_s.size()) return;
    for (int i=0; i<_n; i++) d[i+n-1] = _s[i];
    for (int i=n-2; i>=0; i--) {
      d[i] = d[2*i+1]+d[2*i+2];
      sort(d[i].begin(),d[i].end());
      d[i].erase(unique(d[i].begin(), d[i].end()), d[i].end());
    }
  }
  void update(int k, char a) {
    k += n-1;
    d[k] = a;
    while (k > 0) {
      k = (k-1)/2;
      d[k] = d[k*2+1] + d[k*2+2];
      sort(d[k].begin(),d[k].end());
      d[k].erase(unique(d[k].begin(), d[k].end()), d[k].end());
    }
  }
  string _query(int a, int b, int k, int l, int r) {
    if (r <= a || b <= l) return "";
    if (a <= l && r <= b) return d[k];
    else {
      string vl = _query(a, b, k*2+1, l, (l+r)/2);
      string vr = _query(a, b, k*2+2, (l+r)/2, r);
      string t = vl + vr;
      sort(t.begin(),t.end());
      t.erase(unique(t.begin(), t.end()), t.end());
      return t;
    }
  }
  int query(int a, int b) {
    string t = _query(a, b, 0, 0, n);
    return t.size();
  }
};

int main()
{
  int n; cin>>n;
  string s; cin>>s;
  int q; cin>>q;
  vector<int> ans;
  SegTree st(n, s);
  rep(i, q) {
    int a; cin >> a;
    if (a==1) {
      int b; cin >> b; b--;
      char c; cin >> c;
      st.update(b, c);
    } else {
      int b, c; cin>>b>>c; b--; c--;
      cout << st.query(b, c+1) << endl;
    }
  }

  return 0;
}


Measured memory_bytes: 57220
/*
* @Author: wxyww
* @Date: 2020-02-16 21:22:02
* @Last Modified time: 2020-02-16 21:25:16
*/
#include<cstdio>
#include<iostream>
#include<cstdlib>
#include<cmath>
#include<ctime>
#include<bitset>
#include<cstring>
#include<algorithm>
#include<string>
#include<queue>
#include<vector>
using namespace std;
typedef long long ll;

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

int main() {
	int n = read();
	for(int i = 1;i <= n;++i) {
		int x = read();
		if(x & 1) continue;
		if(x % 3 && x % 5) {
			puts("DENIED");return 0;
		}
	}
	puts("APPROVED");

	return 0;
}

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

#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define ll long long

int main()
{
	string s;
	cin>>s;
	rep(i,s.size()) s[i]='x';
	cout<<s<<endl;
	return 0;
}


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

using namespace std;

#define intt long long
#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

const int N = 1005;

int n;
int a[N];

int main() {

	FAST;

	string s;
	int k;
	cin >> s >> k;
	set <string> subs;
	for (int i = 0; i < s.length(); i ++) {
		string tmp = "";
		for (int j = i; j < min(int(s.length()), i + 5); j ++) {
			tmp += s[j];
			subs.insert(tmp);
		}
	}
	k --;
	while (k) {
		subs.erase(subs.begin());
		k --;
	}
	cout << *subs.begin() << '\n';
	return 0;
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
 
vector<int> to[200005];
vector<int> ans;
 
void def(int v, int p=-1) {
    for (int u : to[v]) {
        if (u == p) continue;
        ans[u] += ans[v];
        def(u,v);
    }
}
 
int main() {
    int n, q;
    cin >> n >> q;
    rep(i, n-1) {
        int a, b;
        cin >> a >> b;
        --a; --b;
        to[a].push_back(b);
        to[b].push_back(a);
    }
    ans.resize(n);
    rep(i,q) {
        int p, x;
        cin >> p >> x;
        --p;
        ans[p] += x;
    }
    def(0);
    rep(i,n) {
        cout << ans[i] << endl;
    }
    return 0;
}

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

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

  int x[100010];
  for(int i = 0;i < n;i++) cin >> x[i];
  x[n] = X;
  n++;
  sort(x,x+n);

  int mins = INT_MAX;
  for(int i = 0;i < n-1;i++){
    mins = min(mins,x[i+1]-x[i]);
  }

  int wal = 2;
  do{
    int i;
    for(i = 0;i < n-1;i++){
      if((x[i+1]-x[i]) % mins != 0){
        break;
      }
    }
    if(i == n-1){
      cout << mins << endl;
      return 0;
    }
    while(mins % wal != 0) wal++;
    mins /= wal;
  }while(mins > 1);

  cout << mins << endl;
  return 0;
}

Measured memory_bytes: 640
class Array
  def swap(x, y)
    self[x], self[y] = self[y], self[x]
  end
end

def selectionSort(n, a)
  c = 0
  n.times{|i|
    min = i
    (i..n-1).each{|j|
      a[j]<a[min]&&min=j
    }
    i!=min&&a.swap(i,min)&&c+=1
  }
  return a, c
end

a, c = selectionSort(gets.to_i, gets.split.map(&:to_i))
puts a.join(" ")
puts c

Measured memory_bytes: 8644
#include <stdio.h>
#include <stdbool.h>

int n;  /* 商品の金額 */
int k;  /* 嫌いな数字の個数を指定 */
int k_array[10]; /* 嫌いな数を指定する */

bool num_chcek(int n){
    while(n > 0){   /* 0より大きい間ループ */
        for(int i = 0; i < k; i++){
            if(n%10 == k_array[i]){ /* n/10の剰余 */
                return false;   /* 0 */
            }
        }
        n /= 10;   /* 桁ずらし */
    }
    return true;    /* 1 */
}

int main(){
    scanf("%d%d",&n,&k);
    for(int i = 0;i < k; i++){
        scanf("%d",&k_array[i]);   
    }
    
    for(int i = n;;i++){
        if(num_chcek(i)){   /* trueなら出力 */
            printf("%d\n",i);
            break;
        }   
    }
}

Measured memory_bytes: 128
#include<iostream>
#include<string>
#include<algorithm>
//#include<iterator>

using namespace std;

#define NMAX 100000//10^5

int main(void){
	int N;//not use
	cin >> N;//not use
	
	string S;
	cin >> S;
	
	//string::iterator end_pt = unique(S.begin(), S.end());
	auto end_pt = unique(S.begin(), S.end());
	cout << distance(S.begin(), end_pt) << endl;
	
	return 0;
}


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

p_e = [0] + [ (x + 1) * 0.5 for x in p]
p_p = [0]

for i in range(1, n+1):
    p_p.append(p_p[i-1] + p_e[i])

e_sum = [p_p[i] - p_p[i - k] for i in range(k, n+1)]
print(max(e_sum))

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

int main() {
	int H = 0, N = 0;
	int result = 0;
	cin >> H >> N;
	vector<int> A(N);

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

	result = accumulate(A.begin(), A.end(), 0);
 	cout << ((result >= H) ? "Yes" : "No") << endl;
	return 0;
}


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

int main()
{
    int N;
    vector<string> W;
    cin >> N;
    for (int i = 0; i < N; i++)
    {
        string temp;
        cin >> temp;
        W.push_back(temp);
    }

    for (int i = 0; i < N - 1; i++)
    {
        if (W[i].back() != W[i + 1].front())
        {
            cout << "No";
            return 0;
        }
    }

    for (int i = 0; i < N; i++)
    {
        for (int j = i + 1; j < N; j++)
        {
            if (W[i] == W[j])
            {
                cout << "No";
                return 0;
            }
        }
    }

    cout << "Yes";

    return 0;
}

Measured memory_bytes: 764
#include <iostream>

using namespace std;

int main(void){
    int min, max, num;
    cin >> min >> max >> num;
    
    int count = 0;
    for (int i = min; i <= max; i++) {
        if (num % i == 0) {
            count++;
        }
    }
    
    cout << count << endl;

    return 0;
}

Measured memory_bytes: 3108
#include<stdio.h>

int main (void)
{
 char s[5];
 int x,i;

 x=0;
 scanf("%s", s);
 for(i=0;i<4;i++){
    if(s[i]=='+') x++;
    else if(s[i]=='-') x--;
 }
 printf("%d\n",x);
 return 0;
}


Measured memory_bytes: 128
import itertools
from sys import stdin


def get_result(data):
    N, M, X = data[0]
    C_A = data[1:]
    min_const = float('inf')
    for bit in itertools.product([0, 1], repeat=N):
        cost = 0
        comp = [0] * M
        for i, val in enumerate(bit):
            if val == 1:
                cost += C_A[i][0]
                for j in range(M):
                    comp[j] += C_A[i][j+1]

        if min(comp) >= X and cost < min_const:
            min_const = cost

    return -1 if min_const == float('inf') else min_const


if __name__ == '__main__':
    raw_data = [val.rstrip() for val in stdin.readlines()]
    data = [list(map(int, val.split(' '))) for val in raw_data]
    result = get_result(data)
    print(result)


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

#define ll long long
#define INF_LL 1LL << 60
#define INF 99999999
#define MOD (ll)1000000007
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, a, n) for(int i = a; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

void put_double(double obj){printf("%.12f\n",obj);};

template < typename T > std::string to_string( const T& n )
{
    std::ostringstream stm ;
    stm << n ;
    return stm.str() ;
}

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; }


int main()
{
    string s;
    cin >> s;

    cout << s[0] << s.size()-2 << s[s.size()-1] << endl;
}


Measured memory_bytes: 256
<?php
    // define ('DEBUG', true);
    define ('DEBUG', false);

    fscanf(STDIN, "%d", $N);
    $x = trim(fgets(STDIN));
    if (DEBUG) echo $x . PHP_EOL;
    $A = explode(" ", $x);
    if (DEBUG) echo $N . PHP_EOL;
    if (DEBUG) var_dump($A);
    $e = 0;
    $o = 0;

    for ($i = 0; $i < $N; $i++) {
        if ($A[$i] % 2 == 0) {
            $e++;
        } else {
            $o++;
        }
    }

    if (DEBUG) echo "e:{$e} o:{$o}\n";

    if ($e > 1) {
        $e = 1;
    }
    $o %= 2;
    if ($e == 1 && $o == 1) {
        echo "NO\n";
    } else {
        echo "YES\n";
    }




Measured memory_bytes: 11124
N=int(input())
P=list(map(int,input().split()))
P_answer=[i+1 for i in range(N)]
swap=[0 for i in range(N)]
k=0

for i in range(N):
    if P[i]!=i+1:
        k+=1

if k==0 or k==2:
    print('YES')
else:
    print("NO")

Measured memory_bytes: 3064
#[allow(unused_imports)]
use std::char::*;
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;

#[allow(unused_macros)]
macro_rules! debug {($($a:expr),*) => {println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);}}
#[allow(unused_macros)]
macro_rules! input { ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; let mut next = || { iter . next ( ) . unwrap ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; ( $ ( $ r : tt ) * ) => { let stdin = std :: io :: stdin ( ) ; let mut bytes = std :: io :: Read :: bytes ( std :: io :: BufReader :: new ( stdin . lock ( ) ) ) ; let mut next = move || -> String { bytes . by_ref ( ) . map ( | r | r . unwrap ( ) as char ) . skip_while ( | c | c . is_whitespace ( ) ) . take_while ( | c |! c . is_whitespace ( ) ) . collect ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules! input_inner { ( $ next : expr ) => { } ; ( $ next : expr , ) => { } ; ( $ next : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules! read_value { ( $ next : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ next , $ t ) ) ,* ) } ; ( $ next : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ next , $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ next : expr , chars ) => { read_value ! ( $ next , String ) . chars ( ) . collect ::< Vec < char >> ( ) } ; ( $ next : expr , usize1 ) => { read_value ! ( $ next , usize ) - 1 } ; ( $ next : expr , $ t : ty ) => { $ next ( ) . parse ::<$ t > ( ) . expect ( "Parse error" ) } ; }

#[derive(PartialEq, PartialOrd)]
pub struct Total<T>(pub T);
impl<T: PartialEq> Eq for Total<T> {}
impl<T: PartialOrd> Ord for Total<T> { fn cmp(&self, other: &Total<T>) -> std::cmp::Ordering { self.0.partial_cmp(&other.0).unwrap() }}

#[allow(dead_code)]
const MAX:usize = 100006;
#[allow(dead_code)]
const INF_U32:u32 = 1 << 31;
#[allow(dead_code)]
const INF_I32:i32 = 1 << 30;
#[allow(dead_code)]
const INF_U64:u64 = 1 << 63;
#[allow(dead_code)]
const INF_I64:i64 = 1 << 62;


fn main() {
    input! {n:i64};
    if n == 1 {
        println!("1");
        return ();
    }

    let mut l = 0i64;
    let mut l1 = 2i64;
    let mut l2 = 1i64;
    for _i in 2..n+1 {
        l = l1 + l2;
        l1 = l2;
        l2 = l;
        //debug!(l,l1,l2);
    }
    println!("{}", l);

}

Measured memory_bytes: 4476
import java.util.Scanner;


public class Main{
	public static void main(String[] args){
		String key_1 = "the",key_2 = "this" ,key_3 = "that";
		@SuppressWarnings("resource")
		Scanner sc = new Scanner(System.in);

		while(sc.hasNext())
		{
			String s= sc.nextLine();
			char[] c = s.toCharArray();
			for(int i=0;i<26;i++){
				for(int j=0;j<c.length;j++){
					 if (c[j] != ' ' && c[j] != '.'){
						 c[j]++;
						 if (c[j] > 'z') c[j] = (char)(c[j] - 26);
					 }
				}
				String _s = new String(c);
				if(_s.contains(key_1)) System.out.println(_s);
				else if(_s.contains(key_2)) System.out.println(_s);
				else if(_s.contains(key_3)) System.out.println(_s);
			}
		}
	}
}

Measured memory_bytes: 18012
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef string str;
const long long INF = INT64_MAX;

#define REP(i, n) for(ll i=0;i<n;i++)
#define ASC(v) sort((v).begin(), (v).end())
#define DESC(v) sort((v).rbegin(), (v).rend())
#define INV(v) reverse((v).rbegin(), (v).rend())
#define FOLDL(src, dst, lambda) partial_sum((src).begin(), (src).end(), (dst).begin(), lambda)
#define ACCUM(v, d0, lambda) accumulate((v).begin(), (v).end(), d0, lambda)
#define FOLDR(src, dst, lambda) INV(src);partial_sum((src).begin(), (src).end(), (dst).begin(), lambda);INV(dst)
#define DESC(v) sort((v).rbegin(), (v).rend())
#define ERASE(v, i) v.erase(v.begin() + i)
#define UNIQ(v) ASC(v);erase(unique(v.begin(), v.end()), v.end())
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL);

map<ll, ll> count_vec(vll v) {
    map<ll, ll> ctr;
    for(auto &a:v) ctr[a]++;
    return ctr;
}

void solve() {
    ll N;
    cin >> N;
    vll A(N+1), S(N + 1);
    A[0] = 0;
    for(int i = 1; i <= N; i++) {
        cin >> A[i];
    }
    FOLDL(A, S, [](ll a, ll b){return a+b;});
    auto ctr = count_vec(S);
    ll ans = 0;
    for(auto &a:ctr) {
        ans += (a.second * (a.second - 1)) / 2;
    }
    cout << ans << endl;
}

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

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

#ifdef DEBUG
#include ".inc/debug.hpp"
#else
#define debug(...) 42
#define rdfile(...) 42
#endif

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    // rdfile("_input.txt");

    int N;
    cin >> N;
    vector<double> A(N);
    for (int i = 0; i < N; ++i) cin >> A[i];

    double d = 0;
    for (int i = 0; i < N; ++i) {
        d += 1.0 / A[i];
    }

    printf("%.9f\n", 1.0 / d);

    return 0;
}

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

using namespace std;

#define sqr(x) ((x) * (x))
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()

typedef vector<int> vi;
typedef pair<int, int> pii;
typedef long long ll;

int col, row;
vector<vector<char>> field;

const pii dir[] = {
    {-1, 0},
    {1, 0},
    {0, -1},
    {0, 1},
};

bool is_in_field(const pii p) {
  const int c = p.second;
  const int r = p.first;
  return (0 <= c && c < col) && (0 <= r && r < row);
}

int wfs(const pii start) {
  vector<vi> memo;
  for (int i = 0; i < row; ++i) {
    vi v(col, 0);
    memo.push_back(v);
  }

  queue<pii> q;
  q.push(start);

  while (!q.empty()) {
    pii cur = q.front();
    q.pop();

    for (const auto d : dir) {
      pii next = cur;
      next.first += d.first;
      next.second += d.second;
      if (is_in_field(next)) {
        const char p = field[next.first][next.second];
        if (p == '.' && next != start) {
          if (memo[next.first][next.second] == 0) {
            q.push(next);
            memo[next.first][next.second] = memo[cur.first][cur.second] + 1;
          }
        }
      }
    }
  }

  int ret = 0;
  for (int i = 0; i < row; ++i) {
    for (int j = 0; j < col; ++j) {
      ret = max(ret, memo[i][j]);
    }
  }

  return ret;
}

void solve() {
  cin >> row >> col;
  for (int i = 0; i < row; ++i) {
    vector<char> v(col, 0);
    for (int j = 0; j < col; ++j) {
      cin >> v[j];
    }
    field.push_back(v);
  }

  int ans = 0;
  for (int i = 0; i < row; ++i) {
    for (int j = 0; j < col; ++j) {
      if (field[i][j] == '.') {
        pii start = make_pair(i, j);
        ans = max(ans, wfs(start));
      }
    }
  }
  cout << ans << endl;
}

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

  solve();

  return 0;
}


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

int main()
{
    string s;
    cin >> s;
    int max = 0;
    for (int i=0; i<s.length(); i++) {
        if (s.at(i) == 'A') {
            for (int j=s.length()-1; j>i; j--) {
                if (s.at(j) == 'Z') {
                    max = j-i+1;
                    break;
                }
            }
            break; 
        }
    }
    cout << max << endl;
}


Measured memory_bytes: 640
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <functional>
#include <utility>
#include <tuple>
#include <cctype>
#include <bitset>
#include <complex>
#include <cmath>
#include <array>
#include <numeric>
using namespace std;
#define INF 0x3f3f3f3f
#define INFLL 0x3f3f3f3f3f3f3f3fLL
//#define mod 998244353
#define MOD 1000000007
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pint;
typedef pair<ll,ll> pll;
typedef tuple<int,int,int> tint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<ull> vull;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
typedef vector<tint> vtint;
typedef vector<vint> vvint;
int dx[8]={0,0,-1,1,1,1,-1,-1};
int dy[8]={-1,1,0,0,1,-1,1,-1};
const int SIZE=10050;
//↑templete
signed main(){

	int K, X;
	cin>>K>>X;
	if(500*K>=X)
		cout<<"Yes"<<endl;
	else
		cout<<"No"<<endl;

	return 0;
}

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

int main() {
   string s;
   cin >> s;

   int count = 0;
   rep(i, 3) {
       if (s[i] == '1') count++;
   }

   cout << count << endl;
}

Measured memory_bytes: 256
#[allow(unused_imports)]
use std::cmp;
use std::io::Write;

// Input macro from https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
  (source = $s:expr, $($r:tt)*) => {
    let mut iter = $s.split_whitespace();
    input_inner!{iter, $($r)*}
  };
  ($($r:tt)*) => {
    let s = {
      use std::io::Read;
      let mut s = String::new();
      std::io::stdin().read_to_string(&mut s).unwrap();
      s
    };
    let mut iter = s.split_whitespace();
    input_inner!{iter, $($r)*}
  };
}

macro_rules! input_inner {
  ($iter:expr) => {};
  ($iter:expr, ) => {};

  ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
    let $var = read_value!($iter, $t);
    input_inner!{$iter $($r)*}
  };
}

macro_rules! read_value {
  ($iter:expr, ( $($t:tt),* )) => {
    ( $(read_value!($iter, $t)),* )
  };

  ($iter:expr, [ $t:tt ; $len:expr ]) => {
    (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
  };

  ($iter:expr, chars) => {
    read_value!($iter, String).chars().collect::<Vec<char>>()
  };

  ($iter:expr, usize1) => {
    read_value!($iter, usize) - 1
  };

  ($iter:expr, $t:ty) => {
    $iter.next().unwrap().parse::<$t>().expect("Parse error")
  };
}

fn is_odd(x: i32) -> bool {
  if x < 10 {
    return true;
  }
  if x < 100 {
    return false;
  }
  if x < 1000 {
    return true;
  }
  if x < 10000 {
    return false;
  }
  if x < 100000 {
    return true;
  }
  return false;
}

fn main() {
  let out = std::io::stdout();
  let mut out = std::io::BufWriter::new(out.lock());
  macro_rules! puts {
    ($($format:tt)*) => (write!(out,$($format)*).unwrap());
  }
  input! {
    n: i32,
  }
  let mut count = 0;
  for i in 1 .. n + 1 {
    if is_odd(i) {
      count += 1;
    }
  }

  puts!("{}\n", count);
}


Measured memory_bytes: 4352
using AtCoderBeginnerContest132.Questions;
using AtCoderBeginnerContest132.Extensions;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace AtCoderBeginnerContest132.Questions
{
    public class QuestionB : AtCoderQuestionBase
    {
        public override IEnumerable<object> Solve(TextReader inputStream)
        {
            var n = inputStream.ReadInt();
            var p = inputStream.ReadIntArray();

            var count = 0;
            for (int i = 1; i < n - 1; i++)
            {
                if ((p[i - 1] < p[i] && p[i] < p[i + 1]) || (p[i + 1] < p[i] && p[i] < p[i - 1]))
                {
                    count++;
                }
            }

            yield return count;
        }
    }
}


namespace AtCoderBeginnerContest132
{
    class Program
    {
        static void Main(string[] args)
        {
            IAtCoderQuestion question = new QuestionB();    // 問題に合わせて書き換え
            var answers = question.Solve(Console.In);
            foreach (var answer in answers)
            {
                Console.WriteLine(answer);
            }
        }
    }
}

#region Base Classes

namespace AtCoderBeginnerContest132.Questions
{

    public interface IAtCoderQuestion
    {
        IEnumerable<object> Solve(string input);
        IEnumerable<object> Solve(TextReader inputStream);
    }

    public abstract class AtCoderQuestionBase : IAtCoderQuestion
    {
        public IEnumerable<object> Solve(string input)
        {
            var stream = new MemoryStream(Encoding.Unicode.GetBytes(input));
            var reader = new StreamReader(stream, Encoding.Unicode);

            return Solve(reader);
        }

        public abstract IEnumerable<object> Solve(TextReader inputStream);
    }

}

#endregion

#region Extensions

namespace AtCoderBeginnerContest132.Extensions
{
    internal static class TextReaderExtensions
    {
        internal static int ReadInt(this TextReader reader) => int.Parse(ReadString(reader));
        internal static long ReadLong(this TextReader reader) => long.Parse(ReadString(reader));
        internal static double ReadDouble(this TextReader reader) => double.Parse(ReadString(reader));
        internal static string ReadString(this TextReader reader) => reader.ReadLine();

        internal static int[] ReadIntArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(int.Parse).ToArray();
        internal static long[] ReadLongArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(long.Parse).ToArray();
        internal static double[] ReadDoubleArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(double.Parse).ToArray();
        internal static string[] ReadStringArray(this TextReader reader, char separator = ' ') => reader.ReadLine().Split(separator);
    }
}

#endregion

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

typedef vector<int> vi;
typedef pair<int,int> ii;
typedef long long int ll;
typedef unsigned long long int ull;
#define inf INT_MAX
#define minf INT_MIN
#define watch(x)	cout<<(#x)<<"=>"<<x<<'\n';
#define sz(a) (int)(a).size()
#define all(x) x.begin(),x.end()


ll ans;
int arr[300009];
vi vr;
void solve()
{
    ll a,b,c,d;
    cin>>a>>b>>c>>d;

    ll nax = max(b*d,a*c);
    nax = max(nax, a*d);
    nax = max(nax, b*c);
    cout<<nax;
    cout<<'\n';
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int testc;  testc = 1;
    for(int t = 0; t < testc; ++t){
        solve();
    }
    return 0;
}

	//Sun 13 Sep 2020 05:33:06 PM IST


		/***astrainL3gi0N***/


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

int main(){
	long long N,A,B;
	cin >> N >> A >> B;
	if((B-A)%2==0)cout << (B-A)/2 << endl;
	else{
		long long tmp1=0;
		long long tmp2=0;
		
		tmp1+=A-1;
		long long a=1;
		long long b=B-(A-1);
		tmp1+=(b-a+1)/2;

		tmp2+=N-B;
		b=N;
		a=A+N-B;
		tmp2+=(b-a+1)/2;

		cout << min(tmp1,tmp2) << endl;
	}
	return 0;
}

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

const int MAXN = 100005;

int x[MAXN], y[MAXN];
int vis[MAXN], hav[MAXN];
int n, m;

int main()
{
	scanf("%d%d", &n, &m);
	for (int i = 1; i <= n; i++) vis[i]++;
	hav[1] = 1;
	for (int i = 1; i <= m; i++) {
		int x, y;
		scanf("%d%d", &x, &y);
		vis[x]--, vis[y]++;
		if (hav[x]) hav[y] = 1;
		if (vis[x] == 0) hav[x] = 0;
	}
	int cnt = 0;
	for (int i = 1; i <= n; i++)
		if (hav[i])
			cnt++;
	cout << cnt << endl;
	return 0;
}


Measured memory_bytes: 1024
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
        int ans = 0;
		int [] [] [] in = new int [n][n][2];       
        for(int i=0;i<n;i++){in[i][0][0]=sc.nextInt();
                             for(int j=1;j<=in[i][0][0];j++){
                               for(int k=0;k<2;k++){in[i][j][k] = sc.nextInt();}
                             }
                            }
        int max = 1;
        for(int i=0;i<n;i++){max*=2;}
        max--;
        int [] check = new int [n];  
        for(int i=0;i<=max;i++){int p = i; int count = 0; int bool = 0;
                                for(int j=0;j<n;j++){check[j]=p%2;
                                                     p/=2;
                                                     count+=check[j]%2;
                                                    }
                                for(int j=0;j<n;j++){
                                  if(check[j]==1){
                                  for(int k=1;k<=in[j][0][0];k++)
                                {if(check[in[j][k][0]-1]!=in[j][k][1])
                                {bool=1;}
                                }                                
                                }
                                }
                               if(bool==0){ans=Math.max(ans,count);}
                               }        
		System.out.println(ans);
}
}

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

using namespace std;

typedef long long ll;
typedef vector<ll> vl;
typedef long double ld;
typedef vector<ld> vd;
typedef bool bl;
typedef vector<bl> vb;
typedef vector<vl> mt;
typedef unordered_map<ll,unordered_map<ll,ll>> graph;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
typedef vector<string> vs;
typedef vector<vs> table;
typedef vector<vl> v2;
typedef vector<v2> v3;
typedef vector<v3> v4;


const ll e5 = 1 << 20;
const ll mod = 1000000007;
const ll e3 = 1 << 13;
const ll INF = 1ll << 50;

ll n,k;
vl a;
vl b;
vl c;
mt arg_a;
ll cicle = 0;
vl s;

int main(){
  cin >> n >> k;
  a = vl(n);
  b = vl(n);
  for(ll i = 0;i < n;i++) cin >> a[i];
  c = vl(*max_element(a.begin(),a.end())+1, -1);
  for(ll i = 0;i < 2*n;i++){
    if(c[a[i%n]] >= 0) b[c[a[i%n]]] = i%n;
    c[a[i%n]] = i%n;
  }
  ll x = 0;
  if(k > 1){
    while(true){
      if(cicle+1 >= k) break;
      if(x >= b[x]) cicle++;
      x = b[x];
      x = (x+1)%n;
      if(x == 0){
        cicle++;
        break;
      }
    }
    if(x == 0){
      k %= cicle;
      cerr << cicle << endl;
      cicle = 0;
      if(k == 0) return 0;
      while(true){
        if(cicle+1 >= k) break;
        if(x >= b[x]) cicle++;
        x = b[x];
        x = (x+1)%n;
        if(x == 0) cicle++;
      }
    }
  }


  cerr << x << endl;
  for(ll i = x;i < n;i++){
    if(i >= b[i]) s.push_back(a[i]);
    else i = b[i];
  }
  for(ll i = 0;i < s.size();i++) cout << s[i] << " ";
  cout << endl;


}


Measured memory_bytes: 7920