akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
 
int main(){
    int n;
    cin>>n;
    string s;
    cin>>s;
    int a=0,b=0;
    string ans="";
    for(int i=0;i<n;i++){        
        if(s[i]=='('){
            a++;
            ans+='(';
        }
        else {
            if(a==0){
                auto it = ans.begin();
                ans.insert(it,'(');
                ans+=')';
            }
            else {
                ans+=')';
                a--;
            }
        }
    }
    for(int i=0;i<a;i++){
        ans+=')';
    }
    cout<<ans;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scan = new Scanner(System.in);
		
		while(true) {
			String str = scan.next();
			
			if(str.equals("-")) break;
			
			int m = scan.nextInt();
			
			int[] h = new int[m];
			for(int i = 0; i < m; i++) {
				h[i] = scan.nextInt();
			}
			
			StringBuilder str2 = new StringBuilder();
			str2.append(str);
			for(int i = 0; i < m; i++) {
				String str_temp = str2.substring(0, h[i]);
				str2.delete(0, h[i]);
				str2.append(str_temp);
			}
			
			System.out.println(str2);
		}
		
	}

}



Measured memory_bytes: 26204
/***
 ** " Dream is not that which you see while sleeping it is something that does not let you sleep "
 ** 	-- A.P.J Abdul Kalam
***/

/**
  *  Author: dhruv_gheewala
  *  Date:   12.03.2020
  *  Time:   18:12:24
**/

#define DEBUG
#if __has_include("debug.h")
    #include "debug.h"
#else
    #include<bits/stdc++.h>
    using namespace std;

    #define p(str) 42
    #define o(str) 108
    #define fundri 137
    #define d(...) 1729
#endif

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

const bool testcases = 0;
#define fast ios_base::sync_with_stdio(0)
#define test int __T__=1;if(testcases)cin>>__T__;while(__T__--)
#define nl cout<<'\n'
#define pb push_back
#define pop pop_back
#define all(s) s.begin(),s.end()
#define ff first
#define ss second
#define sort_by(cont,expr) sort(all(cont),[&](const auto &lhs,const auto &rhs){return expr;})

#define rep(i,n) for(int i=0;i<(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define loop(i,l,r) for(int i=l;i<=r;i++)
#define rloop(i,r,l) for(int i=r;i>=l;i--)

ll seed;auto random_address=[]{char *p=new char;delete p;return (uint64_t)p;};
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()*(random_address()|1));
inline int rnd(int l=0,int r=INT_MAX){return uniform_int_distribution<int>(l,r)(rng);}

template<typename T,typename U>inline bool exist(T cont,U val){return cont.find(val)!=cont.end();}
template<typename T>bool isPrime(T n){for(T i=2;i*i<=n;i++)if(n%i==0)return 0;return 1;}
template<typename TAIL>inline void inp(TAIL& T){cin>>T;}
template<typename HEAD,typename... TAIL>inline void inp(HEAD &H,TAIL&... T){cin>>H;inp(T...);}
template<typename T>inline bool in_range(T a,T l,T r){return (a>=l&&a<=r);}
template<typename T,typename U>inline istream& operator >>(istream& in,pair<T,U> &a){in>>a.ff>>a.ss;return in;}
template<typename T>inline istream& operator >>(istream& in,vector<T> &a){for(auto &x : a)in>>x;return in;}

bool f(int n,vi &den)
{
    while(n)
    {
        if(binary_search(all(den),n%10))
            return 0;
        n/=10;
    }
    return 1;
}

int main()
{
    std::chrono::time_point<std::chrono::high_resolution_clock> start_time, end_time;
    start_time = std::chrono::high_resolution_clock::now();

    #ifdef DHRUV_GHEEWALA
        freopen("INPUT.txt","r",stdin);
        freopen("OUTPUT.txt","w",stdout);
        freopen("DEBUG.txt","w",stderr);
    #endif
    
    fast;
    int n,k;
    test{
    
    cin>>n>>k;
    vi den(k);
    cin>>den;
    sort(all(den));

    while(1)
    {
        if(f(n,den))
        {
            cout<<n,nl;
            break;
        }
        n++;
    }
    fundri;
    
    }

    end_time = std::chrono::high_resolution_clock::now();
    ll elapsed_time = std::chrono::duration_cast<std::chrono::milliseconds>(end_time-start_time).count();
    o("\n\n======\n");
    o("Elapsed Time: "<<elapsed_time<<" ms\n");

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  vector<int> a(n),b(n);
  for(int i=0;i<n;i++){
    cin>>a[i];
    b[i]=a[i];
  }
  sort(a.begin(),a.end());
  int c=a[n/2-1],d=a[n/2];
  for(int i=0;i<n;i++){
    if(b[i]<=c){
      cout<<d<<endl;
    }else{
      cout<<c<<endl;
    }
  }
}

Measured memory_bytes: 3712
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
using namespace std;

int arr[200010];

int main() {
    int n, k;
    cin >> n >> k;
    for(int i = 0;i < n;i ++) scanf("%d", &arr[i]);
    for(int i = 0;;i ++) {
        if(i + k >= n) break;
        if(arr[i] < arr[i+k]) printf("Yes\n");
        else printf("No\n");
    }
    return 0;
}

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

#define pb         push_back

typedef long long ll;
const ll INF = 1000000000ll;
const ll MOD = 1000000007ll;
const double EPS = 1e-8;

int cnt[100003];

int main(void) {
	//ios_base::sync_with_stdio(false);
	//cin.tie(0);
	
	int n;
	cin >> n;
	vector<int> a;
	for(int i=0; i<n; i++){
		int t;
		cin >> t;
		a.pb(t);
		cnt[t]++;
	}

	ll ans = 1;
	if(n % 2 == 0){
		for(int i=0; i<n; i++){
			if(cnt[i] == 2) {
				ans *= 2;
				ans %= MOD;
			}else if(cnt[i] > 0){
				ans = 0;
				break;
			}
		}
	}else{
		for(int i=0; i<n; i++){
			if(i == 0 && cnt[i] == 1){
				ans *= 1;
			}else if(i == 0){
				ans = 0;
				break;
			}else if(cnt[i] == 2) {
				ans *= 2;
				ans %= MOD;
			}else if(cnt[i] > 0){
				ans = 0;
				break;
			}
		}
	}
	
	cout << ans << endl;

	
	return 0;
}


Measured memory_bytes: 1276
#include <iostream>
using namespace std;
int main(){
  int t;
  cin>>t;
  for(int i=0;i<t;i++){
    int n,d;
    cin>>n>>d;
    if(n==1) cout<<d<<endl;
    else if(n%2) cout<<127*(n-1)+d<<endl;
    else cout<<127*n-d<<endl;
  }
  return 0;
}

Measured memory_bytes: 256
use std::io::prelude::*;

fn input<T>() -> T
where
    T: std::str::FromStr,
{
    let stdin = std::io::stdin();
    let token = stdin
        .lock()
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect::<String>();
    token.parse().ok().unwrap()
}

fn main() {
    let n = input::<i64>();
    println!("{}", if n < 1000 { "ABC" } else { "ABD" });
}


Measured memory_bytes: 4352
def calc(a, op, b):
    if op=='+':
        print(a+b)
    elif op=='-':
        print(a-b)
    elif op=='*':
        print(a*b)
    elif op=='/':
        print(a//b)

while True:
    a, op, b = input().split()
    a = int(a)
    b = int(b)
    if op=='?':
        break
    calc(a, op, b)


Measured memory_bytes: 5600
#include<bits/stdc++.h>
#define rep(i, n) for(int (i)=0 ;i <(n); ++(i))
#define REP(i,m,n) for(int (i) = (m); (i) <= (n); ++(i))
#define yorn(f) puts((f)?"Yes":"No")
#define YORN(f) puts((f)? "YES":"NO")
typedef long long ll;
using namespace std;

int main() {
  int n, a;
  cin >> n >> a;
  cout << n*n-a << endl;
  return 0;
}

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

using namespace std;

typedef long long int ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int INF = 1000000000;
const ll LINF = (ll) 4000000000000000000;
const ll MOD = (ll) 1000000007;
const double PI = acos(1.0);
const int limit = 100010;

#define REP(i,m,n) for(ll i = m; i < (ll)(n); i++)
#define rep(i,n) REP(i, 0, n)
#define MP make_pair
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define NP(v) next_permutation(v.begin(),v.end())
#define smaller_queue  priority_queue <ll, vector<ll>, greater<ll> >
//------------------------------------------------------

int main() {
    int n, c;
    cin >> n >> c;
    int d[c + 1][c + 1];
    REP(i, 1, c + 1) REP(j, 1, c + 1) cin >> d[i][j];
    int grid[n][n];
    rep(i, n) rep(j, n) cin >> grid[i][j];

    int colors[c + 1][3] = {};

    rep(i, n) rep(j, n) {
        colors[grid[i][j]][(i + j) % 3]++;
    }

    int Min = INF;

    REP(i, 1, c + 1) REP(j, 1, c + 1) REP(k, 1, c + 1) {
        if (i == j || j == k || k == i) continue;
        int discomfort = 0;

        REP(a, 1, c + 1) rep(mod, 3) {
            switch (mod) {
                case 0:
                    discomfort += colors[a][mod] * d[a][i];
                    break;
                case 1:
                    discomfort += colors[a][mod] * d[a][j];
                    break;
                case 2:
                    discomfort += colors[a][mod] * d[a][k];
                    break;
            }
        }
        Min = min(Min, discomfort);
    }

    cout << Min << endl;

    return 0;
}



Measured memory_bytes: 1280
import java.util.*;
import java.util.function.*;
import java.math.*;
public class Main {
    public static void main(String[] args){
		Scanner s = new Scanner(System.in);
		int D = s.nextInt();
		int G = s.nextInt();
		int[] p = new int[D]; 
		int[] c = new int[D]; 
		for(int i = 0; i < D; i++) {
			p[i] = s.nextInt();
			c[i] = s.nextInt();
		}
		
		boolean[] complete = new boolean[D];
		int[][] score = new int[D][];
		for(int i = 0; i < D; i++) {
			score[i] = new int[p[i]];
			for(int j = 0; j < p[i]; j++) {
				score[i][j] = (100 * (i + 1)) * (j + 1) + (j == p[i] - 1 ? c[i] : 0);
			}
		}
		
		// 引数1：必要点数 戻り値：必要点数を取得するのに必要な問題数
		final BiFunction<Integer, boolean[], Integer> up = (i, fcomplete) -> {
			int count = 0;
			// 総問題数分繰り返す（1 ～ D 問）
			for(int j = D - 1; j > -1; j--) {
				if(fcomplete[j])
					continue;
				// j + 1 問目の問題をk問解いたときの点数をマイナスする
				for(int k = 1; k < p[j]; k++) {
					i -= 100 * (j + 1);
					count++;
					if(i <= 0) {
						return count;
					}
				}
			}
			return -1;
		};
		
		// 初期設定
		int result = Integer.MAX_VALUE;
		int candidate = 0;
		int count = 0;
		for(int i = 0; i < (1<<D); i++, count = 0, candidate = 0, complete = new boolean[D]) {
			// j = j + 1 問目の問題を解いたかいなか
			for(int j = 0; j < D; j++) {
				if(((i>>j)&1) == 1) {
					candidate += score[j][score[j].length - 1];
					count += p[j];
					complete[j] = true;
				}
			}
			int additinal = 0;
			if(candidate < G) {
				additinal = up.apply(G - candidate, complete);
				if(additinal == -1)
					continue;
			}
			result = Math.min(result, count + additinal);
		}
		
		System.out.println(result);
    }
}

Measured memory_bytes: 32660
package main

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

var (
	readString func() string
	stdout     *bufio.Writer
)

func init() {
	readString = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readIntSlice(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = readInt()
	}
	return b
}

func readLengthAndSlice() []int {
	n := readInt()
	return readIntSlice(n)
}

func printf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(stdout, f, args...)
}

func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(stdout, args...)
}

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

func minUint(a, b uint) uint {
	if a < b {
		return a
	}
	return b
}

func minInt64(a, b int64) int64 {
	if a < b {
		return a
	}
	return b
}

func minUint64(a, b uint64) uint64 {
	if a < b {
		return a
	}
	return b
}

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

func maxUint(a, b uint) uint {
	if a < b {
		return b
	}
	return a
}
func maxInt64(a, b int64) int64 {
	if a < b {
		return b
	}
	return a
}

func maxUint64(a, b uint64) uint64 {
	if a < b {
		return b
	}
	return a
}

func absInt(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func absInt64(a int64) int64 {
	if a < 0 {
		return -a
	}
	return a
}

// readString() string
// readInt() int
// readIntSlice(n int) []int
// readLengthAndSlice() []int
func main() {
	defer stdout.Flush()

	a1 := readInt()
	a2 := readInt()
	a3 := readInt()

	ans := 10000
	calc := func(x1, x2, x3 int) int {
		return absInt(x2-x1) + absInt(x3-x2)
	}
	ans = minInt(ans, calc(a1, a2, a3))
	ans = minInt(ans, calc(a1, a3, a2))
	ans = minInt(ans, calc(a2, a1, a3))
	ans = minInt(ans, calc(a2, a3, a1))
	ans = minInt(ans, calc(a3, a1, a2))
	ans = minInt(ans, calc(a3, a2, a1))
	println(ans)
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mp make_pair
#define pii pair<ll,ll>
#define vi vector<ll>
#define vs vector<string>
#define vii vector<pii>
#define mi map<ll,ll>
#define mii map<pii,ll>
#define mc map<char,ll>
#define itr ::iterator
#define f(i,a,b) for(ll i=a;i<b;i++)
#define fe(i,a,b) for(ll i=a;i<=b;i++)
#define fn(i,a,b) for(ll i=a;i>b;i--)
#define fne(i,a,b) for(ll i=a;i>=b;i--)
#define fm(it,m) for(it = m.begin();it != m.end();++it)
#define all(v) v.begin(),v.end()
#define M 1000000007
#define pi 3.14159265358979323846


int main()
{  
   #ifndef ONLINE_JUDGE
   freopen("input.txt","r",stdin);
   freopen("output.txt","w",stdout);
   #endif
   ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

   ll n=0;
   string s;
   cin>>s;
   f(i,0,s.size())
    n+=s[i]-'0';
   if(n%9==0)
    cout<<"Yes";
   else cout<<"No";

   return 0;
}


Measured memory_bytes: 3736
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int q = sc.nextInt();
        String str = sc.next();
        String[] strAry = new String[n];
        for (int i = 0; i < n; i++) {
            strAry[i] = String.valueOf(str.charAt(i));
        }
        
        int[] cumsum = new int[n + 1];
        for (int i = 1; i < n; i++) {
            if (str.charAt(i - 1) == 'A' && str.charAt(i) == 'C') {
                cumsum[i + 1] = cumsum[i] + 1;
            } else {
                cumsum[i + 1] = cumsum[i];
            }
        }
        
        while (q-- > 0) {
            int start = sc.nextInt();
            int end = sc.nextInt();
            int count = cumsum[end] - cumsum[start];
            
            System.out.println(count);
        }
    }
}

Measured memory_bytes: 73584
//package src.com.jetman.atcoder;

import java.util.Arrays;
import java.util.Scanner;

/**
 * @description:
 * @author: Jetman
 * @create: 2020-08-29 14:39
 **/
public class Main {

    Scanner sc = new Scanner(System.in);

    private void slove() {
        long s = Math.abs(sc.nextLong());
        long k = sc.nextLong();
        long d = sc.nextLong();
        long ans = 0;
        if (s/d > k) {
            ans = s - (k*d);
        } else {
            if (s%d == 0) {
                ans = (k-(s/d))%2==0 ? 0 : d;
            } else {
                ans = (k-(s/d))%2==0 ? s%d : d-(s%d);
                ans = Math.min(ans,(k-(s/d)-1)%2==0 ? d-(s%d) : Long.MAX_VALUE);
            }
        }

        System.out.println(ans);
    }

    public static void main(String[] args) {
        new Main().slove();
    }
}


Measured memory_bytes: 35728
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int main() {
	char a[100];
	char b[100];
	char c[200];
	scanf("%s %s", a, b);
	strcpy(c, a);
	strcat(c, a);
	if(strstr(c, b) != NULL)printf("Yes\n");
	else printf("No\n");
	return 0;
}


Measured memory_bytes: 3148
#include <bits/stdc++.h>
//#include <unordered_map>
#define N 111
#define ID(x, y) (pre[(x)-1]+(y-1))
#define CHECK(x, y) ((x)>0 && (x)<= 2 * n - 1 && (y)>0 && (y)<=(linelimit))
using namespace std;
typedef long long LL;
LL n, mod, m, l;
LL a[N][N], b[N][N], c[N][N], mat[N][N], pre[N];
void mul(LL A[N][N],LL B[N][N],LL t[N][N],LL n,LL m,LL l)
{
    LL tmp[N][N];
    for(LL i=0;i<n;i++)
        for(LL j=0;j<l;j++){
            tmp[i][j]=0;
            for(LL k=0;k<m;k++)
                tmp[i][j]=(tmp[i][j]+A[i][k]*B[k][j]%mod)%mod;
        }
    for(LL i=0;i<n;i++)
        for(LL j=0;j<l;j++)
            t[i][j]=tmp[i][j];
}
void expo(LL p[N][N],LL e[N][N],LL k,LL n)
{
    if(k!=1){
        for(LL i = 0; i < n; ++i)
            for(LL j = 0; j < n; ++j)
                e[i][j] = (i == j);
        while(k){
            if(k&1)
                mul(e,p,e,n,n,n);
            mul(p,p,p,n,n,n);
            k>>=1;
        }
    }else {
        for(LL i=0;i<n;i++)
            for(LL j=0;j<n;j++)
                e[i][j]=p[i][j];
    }
}
void addOneP(LL idx, LL x, LL y, LL linelimit)
{
    if(CHECK(x, y)) b[ID(x, y)][idx] = 1;
}
int main()
{
    LL cas = 1;
    while(~scanf("%lld%lld%lld", &n, &mod, &l) && (n || mod || l))
    {
        m = n;
        LL add = 1;
        LL num = 0;
        pre[0] = 0;
        for(LL i=1; i <= 2 * n -1; i++){
            pre[i] = m + pre[i-1];
            for(LL j=1;j<=m;j++)
                scanf("%lld", &mat[i][j]), a[0][num++] = mat[i][j]%mod;
            if(i == n) add = -1;
            m += add;
        }
        memset(b, 0, sizeof(b));
        m = n, add = 1;
        for(LL i=1; i <= 2 * n -1; i++){
            for(LL j=1;j<=m;j++)
            {
                addOneP(ID(i, j), i, j, m);
                addOneP(ID(i, j), i, j - 1, m);
                addOneP(ID(i, j), i, j + 1, m);
                addOneP(ID(i, j), i - 1, j, m - add);
                addOneP(ID(i, j), i + 1, j, m + (i < n ? 1 : -1));
                if(i < n) addOneP(ID(i, j), i - 1, j - 1, m - 1), addOneP(ID(i, j), i + 1, j + 1, m + 1);
                if(i == n) addOneP(ID(i, j), i - 1, j - 1, m - 1), addOneP(ID(i, j), i + 1, j - 1, m - 1);
                if(i > n) addOneP(ID(i, j), i - 1, j + 1, m + 1), addOneP(ID(i, j), i + 1, j - 1, m - 1);
            }
            if(i == n) add = -1;
            m += add;
        }
        expo(b, c, l, num);
        mul(a, c, b, 1, num, num);
        LL ans = 0;
        for(LL i=0;i<num;i++)
            ans += b[0][i];
        printf("Case %lld: %lld\n", cas++, ans);
    }
    return 0;
}

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

int main() {
  ll x;
  cin >> x;
  if(x<=6){
    cout << 1 << endl;
    return(0);
  }else if(x<=11){
    cout << 2 << endl;
    return(0);
  }

  ll q,r;
  q = x/11;
  r = x%11;
  if(r == 0){
    cout << 2*q << endl;
  }else if(r <= 6){
    cout << 2*q+1 << endl;
  }else{
    cout << 2*q+2 << endl;
  }
  return(0);
}

Measured memory_bytes: 3604
#include<iostream>
#include<string>
using namespace std;
int main(){
	int N,A,B,C,D;
	cin >> N >> A >> B >> C >> D;
	string S;
	cin >> S;
	int roop,lim=0;
	int revpos=0;
	if(C>D){
		for(roop=A;roop<N-1;roop++){
			if(S[roop]=='#'){
				if(S[roop+1]=='#'){
					lim=roop;
					break;
				}
			}else if(revpos==0&&roop<N-2){
				if(S[roop]==S[roop+1]&&S[roop+1]==S[roop+2]&&B<=roop+2&&roop+2<=D){
					revpos=1;
				}
			}
		}
		if(lim==0){
			roop=N-1;
			if(S[roop]=='#'){
				lim=N-1;
			}else{
				lim=N;
			}
		}
		if(revpos&&lim>=C){
			cout << "Yes" << endl;
		}else{
			cout << "No" << endl;
		}
	}else{
		for(roop=A;roop<N-1;roop++){
			if(S[roop]=='#'){
				if(S[roop+1]=='#'){
					lim=roop;
					break;
				}
			}
		}
		if(lim==0){
			roop=N-1;
			if(S[roop]=='#'){
				lim=N-1;
			}else{
				lim=N;
			}
		}
		if(lim>=D){
			cout << "Yes" << endl;
		}else{
			cout << "No" << endl;
		}
	}
	return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()
#ifdef _DEBUG_
	#define debug(...) printf(__VA_ARGS__)
#else
	#define debug(...) (void)0
#endif
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
 
const int MAXN = 2e5 + 1000;
int p[MAXN];
VI e[MAXN], er[MAXN];
int out[MAXN];
int a[MAXN];
 
int mex(VI &vec) {
	sort(ALL(vec));
	if(SZ(vec) == 0 || vec[0] > 0)
		return 0;
	for(int i = 1; i < SZ(vec); i++)
		if(vec[i - 1] < vec[i] - 1)
			return vec[i - 1] + 1;
	return vec.back() + 1;
}
 
int main() {
	int N;
	scanf("%d", &N);
	for(int i = 1; i <= N; i++) {
		scanf("%d", &p[i]);
		e[p[i]].PB(i);
		out[p[i]]++;
	}
	VI nxt, tmp;
	for(int i = 1; i <= N; i++)
		if(out[i] == 0)
			nxt.PB(i);
	while(SZ(nxt) > 0) {
		int v = nxt.back(); nxt.pop_back();
		tmp.clear();
		for(int u : e[v]) {
			tmp.PB(a[u]);
		}
		a[v] = mex(tmp);
		out[p[v]]--;
		if(out[p[v]] == 0)
			nxt.PB(p[v]);
	}
	int tar = 0;
	for(int i = 1; i <= N; i++)
		if(out[i] > 0) {
			tar = i;
			break;
		}
	int x, y;
	tmp.clear();
	for(int u : e[tar]) {
		if(out[u] > 0) continue;
		tmp.PB(a[u]);
	}
	x = mex(tmp);
	tmp.PB(x);
	y = mex(tmp);
 
	a[tar] = x;
	int v = p[tar];
	while(v != tar) {
		tmp.clear();
		for(int u : e[v])
			tmp.PB(a[u]);
		a[v] = mex(tmp);
		v = p[v];
	}
	tmp.clear();
	for(int u : e[tar]) {
		tmp.PB(a[u]);
	}
	if(mex(tmp) == a[tar]) {
		puts("POSSIBLE");
		return 0;
	}
 
	a[tar] = y;
	v = p[tar];
	while(v != tar) {
		tmp.clear();
		for(int u : e[v])
			tmp.PB(a[u]);
		a[v] = mex(tmp);
		v = p[v];
	}
	tmp.clear();
	for(int u : e[tar]) {
		tmp.PB(a[u]);
	}
	if(mex(tmp) == a[tar]) {
		puts("POSSIBLE");
		return 0;
	}
	puts("IMPOSSIBLE");
	return 0;
}


Measured memory_bytes: 17536
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**8)
INF = float("inf")


def solve(N: int, M: int):
    # N <= 10**5

    # 差が異なる組み合わせならば、N回を通して同じ組み合わせにはならない。
    # 前に奇数差、後ろに偶数差を作る
    ans = []

    if N % 2 == 0:
        # 差は偶数
        a, b = (0, N//2-1)
        # print(a, b)
        while a < b:
            ans.append((a+1, b+1))
            a += 1
            b -= 1
        # 差は奇数
        a, b = (N//2, N-2)
        while a < b:
            ans.append((a+1, b+1))
            a += 1
            b -= 1
    if N % 2 == 1:
        # 差は偶数
        a, b = (0, N//2)
        while a < b:
            ans.append((a+1, b+1))
            a += 1
            b -= 1
        # 差は奇数
        a, b = (N//2+1, N-1)
        while a < b:
            ans.append((a+1, b+1))
            a += 1
            b -= 1
    for i in range(M):
        print(*ans[i], sep=" ")
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    solve(N, M)


if __name__ == '__main__':
    main()


Measured memory_bytes: 21220
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<string>
#include<map>
#include<set>
#include<queue>

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
#define repn(i, n) for(int i = 1; i <= n; i++)
#define repr(i, n) for(int i = (n-1); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define lint long long

struct edge{ int from, to, l; };

int main(){
    int L; cin >> L;
    int r = 0;
    while(1){
        if((int)pow(2, r + 1) <= L) r++;
        else break;
    }
    
    int N = r + 1;
    vector<edge> E;
    for(int i = N - 1; i >= 1; i--){
        if(L - (int)pow(2, i - 1) >= (int)pow(2, r)){
            E.push_back(edge{i, N, L - (int)pow(2, i - 1)});
            L -= (int)pow(2, i - 1);
        }
    }

    int M = r * 2 + (int)E.size();
    cout << N << " " << M << endl;
    repn(i, r){
        cout << i << " " << i + 1 << " " << 0 << endl;
        cout << i << " " << i + 1 << " " << (int)pow(2, i - 1) << endl;
    }
    for(auto& e : E){
        cout << e.from << " " << e.to << " " << e.l << endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;cin>>N;
  int A,B;cin>>A>>B;
  int r=0;
  for(int i=1;i<=N;i++){
    int c=0,t=i;
    for(int j=0; j<5; j++)c+=t%10,t/=10;
    if(A<=c&&c<=B)r+=i;
  }
  cout<<r<<endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#pragma GCC optimize("O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
static inline void PUT(char c)
{
  static char buf[1<<15],*ptr=buf;
  if(ptr==buf+strlen(buf)||c==0){fwrite(buf,1,ptr-buf,stdout),ptr=buf;}*ptr++=c;
}
static inline int IN(void)
{
  int x=0,f=0,c=getchar();while(c<48||c>57){f^=c==45,c=getchar();}
  while(c>47&&c<58){x=x*10+c-48,c=getchar();}return f?-x:x;
}
static inline void OUT(int a)
{
  if(a<0)PUT('-'),a=-a;
  int d[40],i=0;do{d[i++]=a%10;}while(a/=10);
  while(i--){PUT(d[i]+48);}PUT('\n');
}
static inline int Max(int a,int b){return a>b?a:b;}
static inline int Min(int a,int b){return a<b?a:b;}
#define rep(i,n) for(int i=0;i<(int)n;i++)
const int INF=0x7f7f7f7f;
int K,N,sqrtn=0,dat[500000],bucket[707]={0},lazy[707]={0},lazyflag[707]={0};
static inline void Init(int x){N=x;while(sqrtn*sqrtn<=N){sqrtn++;}K=(N+sqrtn-1)/sqrtn;rep(i,N){dat[i]=i;}}
static inline void Eval(int b)
{
  if(!lazyflag[b]){return;}lazyflag[b]=0;
  rep(i,sqrtn){dat[sqrtn*b+i]=lazy[b];}
}
static inline void Update(int l,int r,int x)
{
  rep(i,K)
  {
    int p=sqrtn*i,q=sqrtn*(i+1);
    if(q<=l||r<=p){continue;}
    if(l<=p&&q<=r){bucket[i]=p-x;lazyflag[i]=1;lazy[i]=x;}
    else
    {
      Eval(i);
      rep(j,Min(r,q)-Max(l,p)){dat[Max(l,p)+j]=x;}
      bucket[i]=INF;
      rep(j,q-p){bucket[i]=Min(bucket[i],p+j-dat[p+j]);}
    }
  }
}
static inline int Query(int l,int r)
{
  int ret=INF;
  rep(i,K)
  {
    int p=sqrtn*i,q=sqrtn*(i+1);
    if(q<=l||r<=p){continue;}
    if(l<=p&&q<=r){ret=Min(ret,bucket[i]);}
    else{Eval(i);rep(j,Min(r,q)-Max(l,p)){ret=Min(ret,Max(l,p)+j-dat[Max(l,p)+j]);}}
  }
  return ret;
}
int main(void)
{
  int H=IN(),W=IN();Init(W);
  rep(i,H)
  {
    int l=IN()-1,r=IN(),u=-INF;
    if(l>0){int b=(l-1)/sqrtn;Eval(b);u=dat[l-1];}Update(l,r,u);
    int res=Query(0,W);if(res>=INF){res=-1;}else{res+=i+1;}OUT(res);
  }
}

Measured memory_bytes: 2416
import java.util.Scanner;
 
public class Main {

	public static final MyScanner in = new MyScanner();

	public static void main(String[] args) {

		int N = in.nextInt();
		char[] S = in.next().toCharArray();
		char[] T = in.next().toCharArray();

		StringBuffer sb = new StringBuffer();
		for(int i=0; i < N*2; i++) {
			if (i % 2 == 0) {
				sb.append(S[i/2]);
			}else {
				sb.append(T[i/2]);
			}
		}

		System.out.println(sb.toString());

	}

	public static class MyScanner{
		Scanner sc = new Scanner(System.in);
		String nextLine() {return sc.nextLine();}
		String next() {return sc.next();}
		int nextInt() {return Integer.valueOf(sc.next());}
		long nextLong() { return Long.valueOf(sc.next());}
	}
}

Measured memory_bytes: 23764
#include <iostream>
int main() {
	int n, a, b, c, d, ac, cc;
	std::cin >> n >> a >> b >> c >> d;
	if (n%a >= 1) {
		ac = n / a + 1;
	}
	else {
		ac = n / a;
	}
	if (n%c >= 1) {
		cc = n / c + 1;
	}
	else {
		cc = n / c;
	}
	if (ac*b > cc*d) {
		std::cout << cc * d << std::endl;
	}
	if (ac*b < cc*d) {
		std::cout << ac * b << std::endl;
	}
	if (ac*b == cc*d) {
		std::cout << cc * d << std::endl;
	}
}


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

int times(int n) {
  int tmp = 0;
  while (n % 2 == 0) {
    n /= 2;
    ++tmp;
  }
  
  return tmp;
}

int main() {
  int n;
  cin >> n;
  int ans = 30;
  
  REP(i, n) {
    int tmp;
    cin >> tmp;
    
    ans = min(ans, times(tmp));
  }
  
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 256
sA=input()
sB=input()
sC=input()

k=sA[0]
sA=sA[1:]
while k=="a" or k=="b" or k=="c":
    if k=="a":
        if sA=="":
            k="A"
        else:
            k=sA[0]
            sA=sA[1:]
    elif k=="b":
        if sB=="":
            k="B"
        else:
            k=sB[0]
            sB=sB[1:]
    elif k=="c":
        if sC=="":
            k="C"
        else:
            k=sC[0]
            sC=sC[1:]

print(k)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
    int n;
    cin>>n;
    int k = n/2;
    if(n%2==0)
    {
        cout<<k-1<<endl;
    }
    else
        cout<<k<<endl;
    return 0;
}

Measured memory_bytes: 256
#!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    N = I()
    f = [1]*(N+1)
    for p in range(2,N+1):
        f[p] += 1
        j = 2*p
        fp = f[p]
        while j <= N:
            f[j] += 1
            j += p
    ans = 0
    for i in range(1,N+1):
        ans += i*f[i]
    print(ans)
    return

#Solve
if __name__ == "__main__":
    solve()


Measured memory_bytes: 146180
import java.io.*;
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner in=new Scanner (System.in);
        PrintWriter out=new PrintWriter(System.out);
        TreeSet<Integer> set=new TreeSet<>();
        int q=Integer.parseInt(in.next());
        for(int i=0;i<q;i++) {
            int odr=Integer.parseInt(in.next());

            switch(odr) {
            case 0:
            	int x0=Integer.parseInt(in.next());
            	if(!set.contains(x0)) set.add(x0);
            	out.println(set.size());
            	break;

            case 1:
            	int x1=Integer.parseInt(in.next());
            	out.println(set.contains(x1)? 1:0);
            	break;
            	
            case 2:
            	int x2=Integer.parseInt(in.next());
            	set.remove(x2);
            	break;
            	
            case 3:
            	int L=Integer.parseInt(in.next()),R=Integer.parseInt(in.next());
            	NavigableSet<Integer> sub=set.subSet(L, true, R, true);
            	Iterator<Integer> itr=sub.iterator();
            	
            	while(itr.hasNext()) {
            		int key=itr.next();
            		out.println(key);
            	}
            }

        }
        out.flush();
    }

}


Measured memory_bytes: 121736
#include <iostream>
using namespace std;
int n,d,c;
int a[105];
int main(void){
    cin>>n;
    for(int i=0;i<n;i++){
        int t;
        cin>>t;
        d=max(t,d);
        a[t]++;
    }
    for(int i=d;i>(d+1)/2;i--){
        if(a[i]<2){
            cout<<"Impossible\n";
            return 0;
        }
        c+=a[i];
    }
    c+=a[(d+1)/2];
    if(c!=n||(a[(d+1)/2]!=1+d%2))cout<<"Impossible\n";
    else cout<<"Possible\n";
}

Measured memory_bytes: 256
use proconio::*;
use proconio::marker::*;

#[fastout]
fn run() {
    input! {
        _n: usize,
        s: Bytes,
        q: usize,
        ask: [usize; q],
    }
    for k in ask {
        let mut d = 0u64;
        let mut m = 0;
        let mut dm = 0;
        let mut dmc = 0;
        for (i, &c) in s.iter().enumerate() {
            if i >= k {
                match s[i - k] {
                    b'D' => {
                        dm -= m;
                        d -= 1;
                    },
                    b'M' => m -= 1,
                    _ => (),
                }
            }
            match c {
                b'D' => d += 1,
                b'M' => {
                    dm += d;
                    m += 1;
                },
                b'C' => dmc += dm,
                _ => (),
            }
        }
        println!("{}", dmc);
    }
}

fn main() {
    run();
}


Measured memory_bytes: 4008
while (h, w = gets.split(" ").map(&:to_i)) != [0,0]
  line = ["#." * (w / 2) + "#" * (w % 2), ".#" * (w / 2) + "." * (w % 2)]
  h.times do |i|
    puts line[i % 2]
  end
  puts
end

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

using namespace std;

typedef long double ld;

ld n, d1, x, ans;

int main() {
  cin >> n >> d1 >> x;
  while (n) {
    ld s = d1 * 2 * n + n * (2 * n - 1) * x;
    ans += s / 2 / n;
    s = s - (4 * d1 + 4 * n * x - 2 * x)  / 2 / n;
    d1 = ((2 * n - 2) * d1 + d1 + 2 * x + 3 * d1 + 3 * x) / 2 / n;
    n--;
    x = (s - 2 * n * d1) / n / (2 * n - 1);
  }
  printf("%Lf\n", ans);
  return 0;
}

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

#define MAX(X,Y) ((X)>(Y)?(X):(Y))
#define MIN(X,Y) ((X)<(Y)?(X):(Y))
#define ABS(X) ((X)>0?(X):-(X))

int fld[2010][2010];
int lenx[2010][2010];
int leny[2010][2010];
int w,h;

void checkX(int y){
  int left = 0;
  for (int x=0; x<w; x++){
    if (fld[x][y]==1){
      lenx[x][y] = 0;
      left = 0;
    } else {
      lenx[x][y] = left + 1;
      left = lenx[x][y];
    }
  }
  for (int x=w-2; x>=0; x--){
    if (fld[x][y]==0 && fld[x+1][y]==0) lenx[x][y] = lenx[x+1][y];
  }
}
void checkY(int x){
  int above = 0;
  for (int y=0; y<h; y++){
    if (fld[x][y]==1){
      leny[x][y] = 0;
      above = 0;
    } else {
      leny[x][y] = above + 1;
      above = leny[x][y];
    }
  }
  for (int y=h-2; y>=0; y--){
    if (fld[x][y]==0 && fld[x][y+1]==0) leny[x][y] = leny[x][y+1];
  }
}

int main(void){
  int ans;
  cin >> h >> w;
  for (int i=0; i<h; i++){
    char buf[2010];
    cin >> buf;
    for (int j=0; j<w; j++){
      fld[j][i] = buf[j]=='.'?0:1;
      lenx[j][i] = leny[j][i] = 0;
    }
  }
  for (int i=0; i<w; i++) checkY(i);
  for (int i=0; i<h; i++) checkX(i);
  ans = 0;
  for (int i=0; i<h; i++){
    for (int j=0; j<w; j++){
//      cout << leny[j][i] << " ";
      ans = MAX(ans, lenx[j][i]+leny[j][i]-1);
    }
//    cout << endl;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 47488
#include<stdio.h>
 int n,m,i,j;
char z[1000][2],x[9];
 int main(){ 
   scanf("%d",&n);
    while(n!=0){
        for(i=0;i<n*2;i++){
scanf("%s",z[i]);
}
       scanf("%d",&m);   
     for(i=0;i<m;i++){  
          scanf("%s",x);     
       for(j=0;j<=n;j++){       
         if(x[0]==z[j*2][0]){      
                 x[0]=z[j*2+1][0];  
                  break;   
             }    
        }         
   printf("%c",x[0]);  
      }       
 printf("\n");  
      scanf("%d",&n);
    }    
     return 0;
}

Measured memory_bytes: 576
#include <bits/stdc++.h>
 
using namespace std;
 
const long long MOD=1e9+7;
const double PI=3.14159265359;



int main() {
    
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n,m,r;
    cin>>n>>m>>r;
    vector<int> vr(r);
    for(int &i:vr){
        cin>>i;
    }
    vector<vector<pair<int,int>>> graph(n+1);
    for(int i=0; i<m; i++){
        int x,y,w;
        cin>>x>>y>>w;
        graph[x].push_back(make_pair(y,w));
        graph[y].push_back(make_pair(x,w));
    }
    vector<vector<int>> dist(r,vector<int>(n+1,1000000000));
    for(int i=0; i<r; i++){
        dist[i][vr[i]]=0;
        for(int j=1; j<=n; j++){
            for(int k=1; k<=n; k++){
                for(auto p:graph[k]){
                    //cout<<p.first<<" "<<p.second<<endl;
                    
                    if(dist[i][p.first]>dist[i][k]+p.second){
                        //cout<<i<<" "<<j<<" "<<p.first<<endl;
                        dist[i][p.first]=dist[i][k]+p.second;
                    }
                }
            }
        }
    }
    vector<int> perm;
    for(int i=0; i<r; i++){
        perm.push_back(i);
    }
    long long ans=0;
    for(int i=0; i<r-1; i++){
        ans+=dist[i][vr[i+1]];
        //cout<<vr[i]<<" "<<vr[i+1]<<" "<<dist[i][vr[i+1]]<<endl;
    }
    while(next_permutation(perm.begin(),perm.end())){
        long long cur=0;
        for(int i=0; i<r-1; i++){
            cur+=dist[perm[i]][vr[perm[i+1]]];
        }
        ans=min(ans,cur);
    }
    cout<<ans;
    
   
   
    
    return 0;
    
}

Measured memory_bytes: 768
#include "bits/stdc++.h"
using namespace std;
#define INF 1e9
#define rep(i, n) for (int i = 0; i < n; i++)
#define rep2(i, l, r) for (int i = (l); i < (r); i++)
#define ALL(x) (x).begin(), (x).end()     //昇順
#define RALL(x) (x).rbegin(), (x).rend()  // 降順
#define FOR(i, c) \
  \ for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
const long long mod = 1e9 + 7;
typedef long long ll;  // ll とdoubleは違う
typedef priority_queue<int> PQ;
typedef vector<long long> VL;
typedef vector<bool> VB;
typedef vector<int> VI;  // VI a(n);
typedef vector<double> VD;
typedef vector<string> VS;
typedef vector<char> VC;
typedef vector<VS> VSS;
typedef vector<VC> VCC;
typedef vector<VI> VII;  // VII a(n,vector<int>(m)) n * m
typedef vector<VL> VLL;
typedef pair<int, int> PII;
typedef map<int, int> MP;  // MP a;
typedef vector<pair<ll, ll>> PS;

template <class T, class U>  // chmax(max, a);
bool chmax(T &a, U b) {
  if (a <= b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T, class U>  // chmin(min,a)
bool chmin(T &a, U b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename T>  // operator << (cout,a);
ostream &operator<<(ostream &os, vector<T> &v) {
  os << "{";
  rep(i, (int)v.size()) { os << v[i] << (i < v.size() - 1 ? ", " : ""); }
  os << "}";
  return os;
}

// g++ -std=c++11 prac.cpp


int main() {
  ll x=0,y=0,z=0,k,n,m,h,w,sum=0,ans=0,Max=1,Min=1e9+1;
  string s,t,u;
  bool ok = true;
  cin >> n;
  VI a(n);
  rep(i,n) cin >> a[i];
  for(int j=1; j<=100;j++){
  rep(i,n)
    sum += (a[i]-j)*(a[i]-j);
  chmin(Min,sum);
  sum=0;
  }
  cout << Min << endl;
  return 0;
}

Measured memory_bytes: 256
#if 0
date +%Y.%m.%d

首先跳跃次数最多是 logV ，每次跳跃后，可以通过普通的移动走尽可能多的点。
那么按照 V 分 logV 层，每层 [1, n] 被拆分为若干线段，
每个线段 [l, r] 表示在该层内从这个区间任一点开始可以遍历整个区间。
那么问题转换为钦定第一层线段，求是否能从其他层中每层拿一个线段使得所有线段的并为 [1, n] 。

由于层数很少，可以状压 DP 出 exl[S] 表示选 S 集合内的线段覆盖 [1, k] 的最大 k ，
类似的有 exr[S] 表示覆盖 [k, n] 的最小 k 。
转移通过 l[k][i]/r[k][i] 表示 k 层第 i 个点的左/右端点即可。

统计答案时，枚举第一层的所有线段 [l, r]，
并判断是否存在集合 S 使得 [1, exl[S]], [l, r], [exr[S], n] 的并为 [1, n] 即可。
而如果第一层线段的数量如果超过总层数说明所有点都不会合法。
#endif
#include <cstdio>
#include <algorithm>
#define debug(...) fprintf(stderr, __VA_ARGS__)

typedef long long ll;

struct {
	inline operator int () { int x; return scanf("%d", &x), x; }
	inline operator ll () { ll x; return scanf("%lld", &x), x; }
	template<class T> inline void operator () (T &x) { x = *this; }
	template<class T, class ...A> inline void operator () (T &x, A &...a)
	{ x = *this; this -> operator ()(a...); }
} read;

const int maxn = 800005, maxk = 20;
int x[maxn];
int exl[maxn], exr[maxn];
int l[maxk][maxn], r[maxk][maxn];
int len[maxk];

int main() {
	int n = read, v = read;
	for(int i = 1; i <= n; i ++)
		read(x[i]);

	int d = 0;
	while(v) {
		len[d ++] = v;
		v >>= 1;
	}
	++ d;

	for(int k = 0; k < d; k ++) {
		l[k][1] = 1;
		for(int i = 2; i <= n; i ++)
			if(x[i - 1] + len[k] >= x[i])
				l[k][i] = l[k][i - 1];
			else
				l[k][i] = i;

		r[k][n] = n;
		for(int i = n - 1; i; i --)
			if(x[i] + len[k] >= x[i + 1])
				r[k][i] = r[k][i + 1];
			else
				r[k][i] = i;
	}

	for(int S = 0; S < (1 << d); S ++) {
		exl[S] = 0;
		exr[S] = n + 1;
		for(int k = 0; k < d; k ++)
			if(S >> k & 1) {
				int T = S ^ (1 << k);
				exl[S] = std::max(exl[S], r[k][exl[T] + 1]);
				exr[S] = std::min(exr[S], l[k][exr[T] - 1]);
			}
		/* debug("%d: %d %d\n", S, exl[S], exr[S]); */
	}

	int tot = 0;
	for(int i = 1; i <= n; i = r[0][i] + 1)
		++ tot;

	if(tot > d) {
		for(int i = 1; i <= n; i ++)
			puts("Impossible");
		return 0;
	}

	for(int i = 1; i <= n; i = r[0][i] + 1) {
		bool ok = 0;
		for(int S = 0; S < (1 << d); S += 2) {
			int T = ((1 << d) - 2) ^ S ;
			/* if(exl[S] + 1 >= exr[T] or (exl[S] + 1 >= i and r[0][i] + 1 >= exr[T])) { */
			if(exl[S] + 1 >= i and r[0][i] + 1 >= exr[T]) {
				ok = 1;
				break;
			}
		}
		for(int j = i; j <= r[0][i]; j ++)
			if(ok)
				puts("Possible");
			else
				puts("Impossible");
	}
}


Measured memory_bytes: 117760
import java.util.*;
import java.lang.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int x = sc.nextInt();
		int a = sc.nextInt();
		if (x < a) {
			System.out.println(0);
		} else {
			System.out.println(10);
		}
	}
}



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

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

    string s;
    cin>>s;
    vector<pair<string,pair<int,int>>>v;
    for(int i=0;i<s.size()-1;i++)
    {
      if(s[i]==s[i+1])
      {
          cout<<i+1<<" "<<i+1+1<<"\n";
          return 0;
      }
    }
    for(int i=0;i<s.size()-2;i++)
    {
       if(s[i]==s[i+2])
       {
           cout<<i+1<<" "<<i+2+1<<"\n";
           return 0;
       }
    }


    cout<<-1<<" "<<-1<<"\n";


}


Measured memory_bytes: 3788
#include <bits/stdc++.h>
using namespace std;
 
#define int long long
//#define uint __int128_t
 
#define pb push_back
#define fi first
#define se second
#define rep(i,s,n) for(int i = s;i<n;i++)
#define rrep(i,s,n) for(int i = (n)-1;i>=(s);i--)
#define all(v) (v).begin(),(v).end()
#define chmin(a,b) a=min((a),(b))
#define chmax(a,b) a=max((a),(b))
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0)
typedef long long ll;
typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<vint> vvint;
typedef vector<pint>vpint;
typedef pair<pint,int> P1;
typedef pair<int,pint> P2;
typedef pair<pint,pint> PP;
const ll MOD=1000000007,INF=1e18;

int N;
int gcd(int x,int y)
{
	if(x==0) return y;
	return gcd(y%x,x);
}

signed main() {
    IOS();
    //(1ll<<N)シフト演算のオーバーフローに気をつける
    //MOD同士の引き算に注意
    cin>>N;
    vint a(N);
    int ans=0;
    rep(i,0,N){
        cin>>a[i];
        if(i)ans=gcd(ans,a[i]);
        else ans=a[i];
    }
    cout<<ans<<endl;
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <stack>
#include <set>
#include <string>
#include <cmath>
#include <algorithm>

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
using namespace std;

int main()
{
    stack<int> stk;
    string s;

    while (cin >> s)
    {
        if (atoi(s.c_str()))
        {
            stk.push(atoi(s.c_str()));
        }
        else
        {
            int tmp1, tmp2;
            tmp2 = stk.top();
            stk.pop();
            tmp1 = stk.top();
            stk.pop();

            if (s == "+")
            {
                stk.push(tmp1 + tmp2);
            }
            else if (s == "-")
            {
                stk.push(tmp1 - tmp2);
            }
            else
            {
                stk.push(tmp1 * tmp2);
            }
        }        
    }
    
    cout << stk.top() << endl;
}


Measured memory_bytes: 3216
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
ll MOD = 1e9+7;

#define vec     vector<int>
#define vecll   vector<ll>
#define vec2    vector<vector<int>>
#define vec2ll  vector<vector<ll>>
#define vpair   vector<pair<int, int>>
#define vpairll vector<pair<ll, ll>>
#define vecst   vector<string>
#define vecb    vector<bool>

#define rep(i,n)         for(ll i=(ll)0; i<(ll)n; i++)
#define REP(i,m,n)       for(ll i=(ll)m; i<(ll)n; i++)
#define arr(var, n)      vec var(n); rep(i,n){cin >> var[i];}
#define arrll(var, n)    vecll var(n); rep(i,n){cin >> var[i];}
#define arrst(var, n)    vecst var(n); rep(i,n){cin >> var[i];}
#define all(var)         (var).begin(), (var).end()
#define sortall(var)     sort(all(var))
#define uniqueall(v)     v.erase(unique(v.begin(), v.end()), v.end());
#define f_sum(var)       accumulate(all(var), 0)
#define f_sumll(var)     accumulate(all(var), 0LL)
#define chmin(v1, v2)    v1 = min(v1, v2)
#define chmax(v1, v2)    v1 = max(v1, v2)
#define mpair(v1, v2)    make_pair(v1, v2)
#define pb(var)          push_back(var)
#define prt(var)         cout << var << "\n"
#define prtd(n, var)     cout << fixed << setprecision(n) << var << "\n"
#define prtfill(n, var)  cout << setw(n) << setfill('0') << var;
#define prt2(v1, v2)     cout << v1 << " " << v2 << "\n"
#define prt3(v1, v2, v3) cout << v1 << " " << v2 << " " << v3 << "\n"
#define prtall(v)        rep(i,v.size()){cout<<v[i]<<(i!=v.size()-1?" ":"\n");}
void prtok(bool ok){prt((ok ? "Yes" : "No"));}
//----------------------------------------------------------------
int divi[1001];

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

  prt(max(a*b,c*d));

}


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

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

  int count=0,max=0;

  for(int i=0;i<s.length();i++){
    if(s[i]=='A' || s[i]=='T' || s[i]=='G' || s[i]=='C'){
      count++;
    }
    else{
      if(count>max) max=count;
      count=0;
    }
  }
  if(count>max) cout<<count;
  else cout<<max;
  return 0;
}


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

#define REP(i, x, n) for (int i = x; i < (int)(n); i++)
#define rep(i, n) REP (i, 0, n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x.size())
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define uniq(x) x.erase(unique(x.begin(), x.end()), x.end())
#define F first
#define S second
#define mp make_pair
#define eb emplace_back

using namespace std;

typedef long long ll;

// const int INF = 1 << 29;
// const ll INF = 1LL << 60;
// const int MOD = 1000000007;

int cnt[100005][30];

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

  rep (i, N) {
    int s, t, c;
    cin >> s >> t >> c;
    cnt[s - 1][c - 1]++;
    cnt[t][c - 1]--;
  }

  rep (i, 100005) rep (j, C) {
    cnt[i + 1][j] += cnt[i][j];
    if (cnt[i][j] > 0) cnt[i][j] = 1;
  }

  int ans = 0;
  rep (i, 100005) {
    int sum = 0;
    rep (j, C) sum += cnt[i][j];
    ans = max(ans, sum);
  }

  cout << ans << endl;
}


Measured memory_bytes: 11904
#include <stdio.h>

void right_triangle(int a, int b, int c)
{
    if ((a * a + b * b == c * c) || (a * a + c * c == b * b) || (b * b + c * c == a * a)) {
        printf("YES\n");
    }
    else {
        printf("NO\n");
    }
}

int main(void)
{
    int n, a, b, c;
    scanf("%d", &n);
    for (int i = 0; i < n; ++i) {
        scanf("%d %d %d", &a, &b, &c);
        right_triangle(a, b, c);
    }    
    return 0;
}

Measured memory_bytes: 1008
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <sstream>
#include <set>
#include <iostream>
#include <string>
#include <algorithm>
#define maxsize 100000
#define ERROR -2
#define OK 1
#define maxi 100000
using namespace std;
typedef long long ll;
int n,m,p[maxi+1];
int main()
{
    int a,b,c;
    while(scanf("%d %d %d",&a,&b,&c)==3)
    {
        if((a*100+b*10+c)%4==0)
            printf("YES\n");
        else
            printf("NO\n");
    }
    return 0;
}



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

int main(){
  long long int N,K;
  cin >> N >> K;
  long long int num=0;
  long long int s = pow(10,9)+7;
  int k=K;
  for(k; k<=N+1; k++){
    num += (N-k+1)*k + 1;
    num = num % s;
  }
  cout << num << endl;
  return 0;
}


Measured memory_bytes: 3592
def read_int():
    return int(input().strip())


def read_ints():
    return list(map(int, input().strip().split(' ')))


def solve():
    W, H, N = read_ints()
    x0, y0, x1, y1 = 0, 0, W, H
    for _ in range(N):
        x, y, a = read_ints()
        if a == 1:
            x0 = min(max(x, x0), x1)
        if a == 2:
            x1 = max(min(x, x1), x0)
        if a == 3:
            y0 = min(max(y, y0), y1)
        if a == 4:
            y1 = max(min(y, y1), y0)
    return (x1-x0)*(y1-y0)


if __name__ == '__main__':
    print(solve())


Measured memory_bytes: 62744