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


void solve(long long N, long long A, long long B){
    if((B - A) % 2 == 0){
        cout<<(B - A) /2 << endl;
    }else{
        ll ans = 1e18+10;
        ll ins = 0, insA, insB;
        ins += N - B;
        insB = N;
        insA = A + ins;
        insA++;
        ins++;
        ins += (insB - insA) / 2;
        ans = min(ans, ins);
        ins = 0;
        insA = A;
        insB = B;

        ins += A - 1;
        insA = 1;
        insB = B - ins;
        insB--;
        ins++;
        ins += (insB - insA)/2;
        ans = min(ans, ins);
        cout<<ans<<endl;
    }
}

int main(){
    long long N;
    scanf("%lld",&N);
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    solve(N, A, B);
    return 0;
}


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

int main() {
  int n;
  cin >> n;
  map<int, int> nums;
  int a;
  rep(i,n) {
    cin >> a;
    nums[a]++;
  }
  int ans = 0;
  for (auto p : nums) {
    auto key = p.first;
    auto value = p.second;
    if (value%2) ans++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 4864
#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

int main() {
    int n, d;
    cin >> n;
    cin >> d;
    vector<vector<int> > data(n, vector<int>(d));
    for(int i = 0; i < n; i++) {
        for(int k = 0; k < d; k++) {
            int tmp;
            cin >> tmp;
            data[i][k] = tmp;
        }
    }
    int counter = 0;
/*     for(int i = 0; i < n; i++) {
        for(int k = 0; k < d; k++) {
            cout << data[i][k] << endl;
        }
    } */

    for(int i = 0; i < n-1; i++) {
        for(int j = i+1; j < n; j++) {
            int sum = 0;
            for(int k = 0; k < d; k++) {
                sum += pow(abs(data[i][k] - data[j][k]), 2);
            }
            auto root = sqrt(sum);
            if(ceil(root) == floor(root)){
                counter++;
            }
        }

        
       /*  if(root / 10 == 0) {
            counter++;
        }  */
    }
    cout << counter << endl; 
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#define MAX 10001
int prime[MAX];

void make_prime()
{
	int i,j;
	for(i=2; i<MAX; i++)prime[i]=1;
	for(i=2; i*i<MAX; i++)
		for(j=i*2; j<MAX; j+=i)prime[j]=0;
}
int main()
{
	int n;
	make_prime();
	while(std::cin>>n,n){
		for(int i=n; i>2; i--)
			if( prime[i] && prime[i-2] ){
				printf("%d %d\n",i-2,i);
				break;
			}
	}
	return 0;
}

Measured memory_bytes: 0
N = input()
K = int(input())
L = len(N)
dp0 = [[0]*(K+1) for i in range(L+1)]
dp1 = [[0]*(K+1) for i in range(L+1)]
dp0[0][0] = 1
for i in range(1,L+1):
  c = int(N[i-1])
  for j in range(K+1):
    if j==0:
      if c>0:
        dp1[i][j] = dp1[i-1][j]+dp0[i-1][j]
        dp0[i][j] = 0
      else:
        dp1[i][j] = dp1[i-1][j]
        dp0[i][j] = dp0[i-1][j]
    else:
      if c>0:
        dp1[i][j] = dp0[i-1][j-1]*(c-1)+dp1[i-1][j-1]*9+dp1[i-1][j]+dp0[i-1][j]
        dp0[i][j] = dp0[i-1][j-1]
      else:
        dp1[i][j] = dp1[i-1][j-1]*9+dp1[i-1][j]
        dp0[i][j] = dp0[i-1][j]
print(dp0[-1][-1]+dp1[-1][-1])

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

using namespace std;

int main(){
    int N;
    cin >> N;
    int num_of_div, num_of_8 = 0;
    for (int i = 105; i <= N; ++i) {
        num_of_div = 0;
        if(i%2 == 0){
            continue;
        }
        for (int j = 1; j <= sqrt(i); ++j) {
            if(i%j==0){
                num_of_div++;
                if(j*j != i){
                    num_of_div++;
                }
            }
        }
//        cout << num_of_div << endl;
        if(num_of_div == 8){
            num_of_8++;
        }
    }
    cout << num_of_8 << endl;
    return 0;
}


Measured memory_bytes: 256
N,M = map(int,input().split())
a = []
b = []
c = []
d = []
for i in range(N+M):
    x,y = map(int,input().split())
    if i<N:
        a.append(x)
        b.append(y)
    else:
        c.append(x)
        d.append(y)
for i in range(N):
    min_man = 10**10
    min_j = 0
    for j in range(M):
        man = abs(a[i]-c[j])+abs(b[i]-d[j])
        if min_man > man:
            min_man = man
            min_j = j
    print(min_j+1)

Measured memory_bytes: 3064
import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;
import std.math, std.random, std.bigint, std.datetime, std.format;
void main(string[] args){ if(args.length > 1) if(args[1] == "-debug") DEBUG = 1; solve(); } bool DEBUG = 0; 
void log(A ...)(lazy A a){ if(DEBUG) print(a); }
void print(){ writeln(""); } void print(T)(T t){ writeln(t); } void print(T, A ...)(T t, A a){ write(t, " "), print(a); }
string unsplit(T)(T xs){ return xs.array.to!(string[]).join(" "); }
string scan(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
T scan(T)(){ return scan.to!T; } T[] scan(T)(int n){ return n.iota.map!(i => scan!T()).array; }
T lowerTo(T)(ref T x, T y){ if(x > y) x = y; return x; } T raiseTo(T)(ref T x, T y){ if(x < y) x = y; return x; }

// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //

void solve(){
    long k = scan!long;
    int n = scan!int;
    long[] as = scan!long(n);

    long g = k - as[$ - 1] + as[0];
    foreach(i; 0 .. n - 1) g.raiseTo(as[i + 1] - as[i]);

    (k - g).writeln;

}



Measured memory_bytes: 9664
#include<iostream>
#include<string>

using namespace std;
using std::string;

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

	if (S == "Sunny") {
		cout << "Cloudy" << endl;
	}
	else if (S == "Cloudy") {
		cout << "Rainy" << endl;
	}
	else if (S == "Rainy") {
		cout << "Sunny" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
	"strconv"
)

func main() {
	var n int
	fmt.Scan(&n)

	c := 0
	for i := 1; i <= n; i++ {
		str := strconv.Itoa(i)
		if len(str)%2 == 1 {
			c++
		}
	}
	fmt.Println(c)
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
typedef long long int ll;
#define f(i,o,n) for(i=o;i<n;i++)
#define pb push_back
#define vll vector<ll>
#define s(x) sort(x.begin(),x.end())
using namespace std;

int main() {
    string s;
    cin>>s;
    ll n=s.length(),i,j,ss=0;
    f(i,0,n)
    {
        ss+=(s[i]-'0');
    }
    if(ss%9==0)
    cout<<"Yes";
    else
    cout<<"No";
}

Measured memory_bytes: 3724
//By Don4ick
//#define _GLIBCXX_DEBUG

#include <bits/stdc++.h>

typedef long long ll;
typedef long double ld;
typedef unsigned int ui;

#define forn(i, n) for (int i = 1; i <= n; i++)
#define pb push_back
#define all(x) x.begin(), x.end()
#define y1 qwer1234

const double PI = acos(-1.0);
const int DIR = 4;
const int X[] = {1, 0, -1, 0};
const int Y[] = {0, 1, 0, -1};

const int N = 55;
const ll INF = (long long)4e18 + 228;

using namespace std;

int y, n;
pair < int, int > a[N];
ll ans = INF;

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

	//freopen(".in", "r", stdin);
	//freopen(".out", "w", stdout);

	cin >> n >> y;
	forn(i, n)
		cin >> a[i].first >> a[i].second;
	sort(a + 1, a + n + 1);
	for (int i = 1; i <= n; i++)
	{
		for (int j = i; j <= n; j++)
		{
			for (int k = i; k <= j; k++)
			{
				for (int f = i; f <= j; f++)
				{
					int mx = max(a[k].second, a[f].second);
					int mn = min(a[f].second, a[k].second);
					int cnt = 0;
					for (int x = i; x <= j; x++)
					{
						if (a[x].second <= mx && a[x].second >= mn)
							cnt++;
					}
					if (cnt >= y)
					{
						ans = min(ans, (0ll + mx - mn) * (0ll + a[j].first - a[i].first));
					}
				}
			}
		}
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
n = gets.chomp.to_i
hash = Hash.new{0}
prev_word = ""
n.times do |i|
  word = gets.chomp
  if word[0] != prev_word[-1] && !i.zero?
    puts "No"
    exit
  else
    hash[word] += 1
    if hash[word] > 1
      puts "No"
      exit
    end
  end
  prev_word = word
end
puts "Yes"

Measured memory_bytes: 14420
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod = 1000000007;

int main()
{
	ll x;
	cin >> x;
	ll ans = 0;
	ll money = 100;
	while (money < x) {
		money += money * 0.01;
		ans++;
	}
	cout << ans << endl;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;
int main()
{
    int a[3];
    cin >> a[0] >> a[1] >> a[2];
    sort(a,a + 3);
    if(a[2] == a[0] + a[1])
    {
        cout << "Yes\n";
    }
    else
    {
        cout << "No\n";
    }
    
    return 0;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int,input().split()))
q = int(input())
cur = [0]*(10**5+1)

for i in range(n):
    cur[a[i]] += 1
wa = 0
for i in range(10**5+1):
    wa += cur[i] * i

for _ in range(q):
    b,c = map(int,input().split())
    
    wa = wa - (cur[b] * b) + (cur[b] * c)
    cur[c] += cur[b]
    cur[b] = 0
    
    print(wa)

Measured memory_bytes: 84280
#include<bits/stdc++.h>
//Problem Code

#define TC int t; cin>>t; while(t--)
#define MOD 1000000007
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define MEM(a, b) memset(a, (b), sizeof(a))
#define FOR(i, st, en, in) for (int i=st ; i<en ; i+=in)
#define RFOR(i, st, en, in) for (int i=st ; i>=en ; i-=in)
#define REP(i, n) FOR(i, 0, n, 1)
#define RREP(i, n) RFOR(i, n-1, 0, 1)
#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()
#define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define sz(a) int(a.size())
#define SORT(c) sort(all(c))
#define RSORT(c) sort(rall(c))

using namespace std;
using ull = unsigned long long int;
using ll = long long;
using pii = pair<int,int>;

ll gcd( ll a, ll b){
	if(a==0)
		return b;
	else
		return gcd(b%a,b);
}

ll bs(ll s,ll e,ll a[],ll v){
    ll m =(s+e)/2;
    if(v>a[m]) return bs(m+1,e,a,v);
    else if(v<a[m]) return bs(s,m-1,a,v);
    return m;
}

void fastio() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
}

void testingio(){
	freopen("input.txt","r",stdin); //redirects standard input
    freopen("output.txt","w",stdout); //redirects standard output	
}

int main(){
	// testingio();
	fastio();
        ll n; cin>>n;
        if(n&1) cout <<n*2;
        else cout<<n;	
	return 0;
}

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

int main() {
  int N;
  cin >> N;
  vector <int> a(N);
  for (int i=0; i<N; i++) {
    cin >> a.at(i);
  }
  
  int c = 0;
  int s = 1;
  for (int i=0; i<N; i++) {
    s = a.at(s-1);
    if (s == 2) {
      c = i+1;
      break;
    }
  }
  
  if (c > 0) {
    cout << c << endl;
  } else {
    cout << -1 << endl;
  }
}


Measured memory_bytes: 640
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		try {
			long N = sc.nextLong();
			long K = sc.nextLong();

			long amari = N % K;
			double kijun = K / 2;
			long ans;
			if (amari > kijun) {
				ans = K - amari;
			} else {
				ans = amari;
			}
			System.out.println(ans);

		} finally

		{
			sc.close();
		}
	}

}


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

int n;

int ans;

bool ok(int x){
	int s=0;
	while(x){
		s++;
		x/=10;
	}
	if(s%2)
		return 1;
	else
		return 0;
}

int main(){
	cin>>n;
	for(register int i=1;i<=n;i++)
		if(ok(i))
			ans++;
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 256
/**
 *      purpose : Tenka1 Programmer Beginner Contest B
 *      author  : kyomukyomupurin
 *      created : 2018-11-10 00:33:57
**/

#include <bits/stdc++.h>
using namespace std;
#define int64 long long
#define print(x) cout << (x) << '\n'

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int N; cin >> N;
    int a[N] = {}; int b[N] = {};
    for (int i = 0; i < N; ++i) cin >> a[i] >> b[i];

    print(*min_element(b, b + N) + *max_element(a, a + N));
    
    return 0;
}

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

int main(){
	int N, S = 0;
	cin >> N;
	int n = N;
	for(int i = 0; i < 10; i++)
	{
		S += N % 10;
		N /= 10;
		if(N == 0) break;
	}
	if(n % S == 0) cout << "Yes" << endl;
	else cout << "No" << endl;
	
		
}

Measured memory_bytes: 256
import java.util.Scanner;
 
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        
        int a = sc.nextInt();
        int b = sc.nextInt();
        
        if((a*b)%2 == 1){
            System.out.println("Odd");
        }else if((a*b)%2 == 0){
            System.out.println("Even");
        }
    }
}

Measured memory_bytes: 21716
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

bool CanObtain(const vector<int> &mods, int sum)
{
    constexpr int kMaxSum = 9000;
    vector<bool> obtained(2 * kMaxSum + 10, false);
    obtained[0 + kMaxSum] = true;

    for (const auto &m : mods) {
        vector<bool> new_obtained(obtained.size(), false);
        for (int i = 2 * kMaxSum; i >= m; i -= 1) {
            if (obtained[i - m]) {
                new_obtained[i] = true;
            }
        }
        for (int i = 0; i <= 2 * kMaxSum - m; i += 1) {
            if (obtained[i + m]) {
                new_obtained[i] = true;
            }
        }
        copy(new_obtained.begin(), new_obtained.end(), obtained.begin());
    }
    return sum + kMaxSum >= 0 && obtained[sum + kMaxSum];
}

bool Valid(const string &moves, int x, int y)
{
    int turns = 0;
    int units = 0;

    vector<int> mod_x;
    vector<int> mod_y;

    for (const auto &ch : moves) {
        if (ch == 'F') {
            units += 1;
            continue;
        }

        if (units > 0) {
            if (turns == 0) {
                x -= units;
            } else {
                (turns % 2 == 1 ? mod_y : mod_x).push_back(units);
            }
        }

        turns += 1;
        units = 0;
    }
    if (units > 0) {
        if (turns == 0) {
            x -= units;
        } else {
            (turns % 2 == 1 ? mod_y : mod_x).push_back(units);
        }
    }
    return CanObtain(mod_x, x) && CanObtain(mod_y, y);
}

int main()
{
    string moves;
    getline(cin, moves);

    int x, y;
    cin >> x >> y;

    cout << (Valid(moves, x, y) ? "Yes" : "No") << "\n";
    return 0;
}


Measured memory_bytes: 384
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

def main():
    N,K=map(int,input().split())
    if (N-1)*(N-2)//2<K:
        print(-1)
    else:
        ans=[]
        for i in range(2,N+1):
            ans.append((1,i))
        i,j=2,3
        for _ in range((N-1)*(N-2)//2-K):
            ans.append((i,j))
            j+=1
            if j>N:
                i+=1
                j=i+1
        print(len(ans))
        for a in ans:
            print(*a)

if __name__ == '__main__':
    main()


Measured memory_bytes: 42608
N, M = map(int, input().split())
L = []
R = []
for i in range(M):
  l, r = map(int, input().split())
  L.append(l)
  R.append(r)
L.sort()
R.sort()
if R[0] >= L[-1]:
  print(R[0] - L[-1] + 1)
else:
  print(0)

Measured memory_bytes: 11436
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
typedef vector<double> VD;
typedef vector<VD> VVD;

template<typename T> void chmin(T &a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T &a, T b) { if (a < b) a = b; }

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

int main() {
    ll n;
    cin >> n;
    VL a(n + 1), b(n);
    REP(i,n+1) a[i] = in();
    REP(i,n) b[i] = in();
    ll ans = 0;
    REP(i,n){
        ll x = min(a[i], b[i]);
        ans += x;
        b[i] -= x;
        x = min(a[i + 1], b[i]);
        ans += x;
        a[i + 1] -= x;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
#include <iostream>
using namespace std;
#define ll long long
#define io ios_base::sync_with_stdio(false); cin.tie(NULL);
#define pb push_back
#define endl '\n'
#define mod 1000000007
#define inf 1000000000000000000
#define pii pair<int, int>
const double pi = acos(-1);
const int sz = 200002;
ll n, m, q, k;
int main() {
	io
	int t = 1;
	//cin>>t;
	while(t--) {
		cin>>n>>m>>k;
		char a[n][m];
		int b = 0;
		for(int i = 0; i < n; i++) {
			for(int j = 0; j < m; j++) {
				cin>>a[i][j];
				if(a[i][j] == '#') b++;
			}
		}
		int toDelete = b-k;
		int ans = 0;
		if(toDelete < 0) cout<<0<<endl;
		else {
			int sx = pow(2, n);
			for(int i = 0; i < sx; i++) {
				unordered_set<int>rows;
				for(int j = 0; j < n; j++) {
					if(i & (1 << j)) rows.insert(j);
				}
				//if(rows.size() == 0) continue;
				int sy = pow(2, m);
				for(int i1 = 0; i1 < sy; i1++) {
					unordered_set<int>cols;
					for(int j = 0; j < m; j++) {
						if(i1 & (1 << j)) cols.insert(j);
					}
					b = 0;
					for(int l = 0; l < n; l++) {
						for(int r = 0; r < m; r++) {
							if(rows.count(l) == 0 && cols.count(r) == 0 && a[l][r] == '#') b++;
						}
					}
					if(b == k) ans++;
				}
			}
			cout<<ans;
		}
	}
}


Measured memory_bytes: 4040
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long a=sc.nextLong();
		long b=sc.nextLong();
		long c=sc.nextLong();
		long d=sc.nextLong();
//A以上  B以下の整数のうち、CでもDでも割り切れないものの個数を出力せよ。

//System.out.println(ans(b,c,d));
//System.out.println(ans(a-1,c,d));
System.out.println(ans(b,c,d)-ans(a-1,c,d));

	}

static public long ans(long a,long c,long d){
	long han=a;

	if(Math.log10(d)+Math.log10(c)-Math.log10(gcd(c,d))>17){
		han=han-(han/c)-(han/d)+((han/c)/d);

		return han;
	}else{
	han=han-(han/c)-(han/d)+(han/(lcm(c,d)));
	return han;
	}
}
static long gcd (long a, long b) {
	long temp;
	while((temp = a%b)!=0) {
		a = b;
		b = temp;
	}
	return b;
}

static long lcm (long a, long b) {
	long temp;
	long c = a;
	c *= b;
	while((temp = a%b)!=0) {
		a = b;
		b = temp;
	}
	return (long)(c/b);
}
}


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

using namespace std;

#define int long long
#define all(v) (v).begin(), (v).end()
#define resz(v, ...) (v).clear(), (v).resize(__VA_ARGS__)
#define reps(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep(i, n) reps(i, 0, n)

template<class T1, class T2> void chmin(T1 &a, T2 b){if(a>b)a=b;}
template<class T1, class T2> void chmax(T1 &a, T2 b){if(a<b)a=b;}

typedef pair<int, int> Pi;
typedef tuple<int, int, int> Ti;
typedef vector<int> vint;

const int inf = 1LL << 55;
const int mod = 1e9 + 7;

signed main()
{
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  int x, y;
  cin >> x >> y;
  cout << --x * --y << endl;

  return 0;
}


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

int main()
{
	int a,b;
	cin >> a >> b;
	if(a % 2 == 0 || b % 2 == 0){
		cout << "No\n";
	}else{
		cout << "Yes\n";
	}

	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<ctype.h>


int main(){
  int i, cnt[26]={};
  char c;

  while(scanf("%c", &c)!=EOF){
    if(isupper(c)) cnt[tolower(c)-'a']++;
    else cnt[c-'a']++;
  }
  for(i=0;i<26;i++){
    printf("%c : %d\n", 'a'+i, cnt[i]);
  }
  return 0;
}

Measured memory_bytes: 548
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>

using namespace std;

void inputData(vector<string>& data_set) {
	string buffer;
	while(getline(std::cin,buffer))
		data_set.push_back(buffer);
}

vector<string> splitString(const string& str, const string& separator = " ") {
	vector<string> ret;

	std::size_t bp, ep;
	bp = ep = 0;
	while((ep = str.find_first_of(separator, bp)) != string::npos){
		if(bp != ep){
			ret.push_back(string(str.begin() + bp, str.begin() + ep));
		}
		bp = ep + 1;
	}

	if(bp <= str.size() - 1){
		ret.push_back(string(str.begin() + bp, str.end()));
	}

	return ret;
}

template <class T>
T convertStringToNumber(const string& str) {
	stringstream ss;
	T ret;

	ss << str;
	ss >> ret;

	return ret;
}



vector<double> parseStringData(const string& data_str) {
	auto buff = splitString(data_str);

	vector<double> ret(buff.size());
	for(int i = 0; i < buff.size(); ++i){
		auto temp = convertStringToNumber<double>(buff[i]);
		ret[i] = temp;
	}

	return ret;
}


void displayAnswer(const vector<double>& data_set) {
	double det = 1.0 / (data_set[0] * data_set[4] - data_set[1] * data_set[3]); 
	double x = det * (data_set[4] * data_set[2] + -data_set[1] * data_set[5]);
	double y = det * (-data_set[3] * data_set[2] + data_set[0] * data_set[5]);

	auto func = [](double n) -> double {
		int buff = static_cast<int>(round(n * 1000));
		if(!abs(buff))
			return abs(buff);
		return buff / 1000.0;
	};

	x = func(x);
	y = func(y);

	cout << fixed << setprecision(3) << x << " " << y << std::endl;
}


void doAllProcess() {
	vector<string> buffer;
	inputData(buffer);

	for(int i = 0; i < buffer.size(); ++i){
		auto data_set = parseStringData(buffer[i]);
		displayAnswer(data_set);
	}
}


int main() {
	doAllProcess();

	return 0;
}


Measured memory_bytes: 3344
from collections import deque
n = int(input())
li = deque()

for _ in range(n):
  c = input()
  if c == "deleteFirst":
    li.popleft()
  elif c == "deleteLast":
    li.pop()
  else:
    c, v = c.split()
    if c == "insert":
      li.appendleft(v)
    else:
      try: 
        li.remove(v)
      except:
        pass

li = list(li)
print(' '.join(map(str, li)))


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

typedef long long ll;
using namespace std;

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

	ll a, b;
	cin >> a >> b;
    if(a >= 2*b) cout << a - 2*b;
    else cout << 0;

}


Measured memory_bytes: 256
program Project1;
     
{$APPTYPE CONSOLE}

uses
  SysUtils;
var
  g,l,r,a,h,w,i,j,count,x,y,sw,m,n,b,c,soeji,sum,max,k,t:Integer;
  //l:array of Integer;
  s,s123,s1,s2,s3:string;
  tf:Boolean;
  //nyu:TStringList;
begin
  try
    { TODO -oUser -cConsole Main : ここにコードを記述してください }
    Readln(n);
    Readln(k);

    sum:=1;
    for i := 0 to n - 1 do
      sum:=((sum+k)+(sum*2) - abs((sum+k)-(sum*2)) ) div 2;

    Writeln(sum);
    Readln;
  except
    on E: Exception do
      Writeln(E.ClassName, ': ', E.Message);
  end;
end.

Measured memory_bytes: 128
#include <stdio.h>

int main() {
    int N;
    scanf("%d",&N);
    int A[N];
    int B[N];
    int C[N];
    int ans = 0;
    for (int i = 0; i<N; i++) {
        scanf("%d",&A[i]);
    }
    for (int i = 0; i<N; i++) {
        scanf("%d",&B[i]);
    }
    for (int i = 0; i<N-1; i++) {
        scanf("%d",&C[i]);
    }
    for (int i = 0; i<N; i++) {
        ans = ans + B[(A[i]-1)];
        if (A[i] - 1 == A[i-1]) {
            ans = ans + C[A[i]-2];
        }
    }
    printf("%d",ans);
    return 0;
}


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

using namespace std;

const int MX = 500000;

int solve(vector<int>& a) {
	if (a.empty()) return 0;
	
	int f = 0, g = -2 * MX, h = -2 * MX;
	for (int x : a) {
		int ff = max(max(f, h), g + x);
		int gg = max(f, g + x - 1);
		if (x > 1) gg = max(gg, h);
		int hh = max(f, max(g, h - 1)) + x;
		
		f = ff;
		g = gg;
		h = hh;
	}
	
	return max(f, g);
}

char s[MX + 2];

int main() {
	int n;
	ignore = scanf("%d %s", &n, s);
	s[n] = s[n + 1] = '0';
	n += 2;
	
	int ans = 0;
	vector<int> a;
	for (int i = 0, o = 0, z = 0; i < n; i++) {
		if (s[i] == '1') {
			o++;
			z = 0;
		}
		else {
			if (o != 0) {
				a.push_back(o);
				o = 0;
			}
			z++;
			if (z == 2) {
				ans += solve(a);
				a.clear();
				o = z = 0;
			}
		}
	}
	
	printf("%d\n", ans);
	
	return 0;
}


Measured memory_bytes: 768
#include <bits/stdc++.h>
#define all(a) a.begin(), a.end()
using namespace std;
 
int N;
vector<int> v;

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> N;
  v.resize(N);
  long long res = 0;
  map<int, int> mp_pos, mp_neg;
  for(int i=0; i<N; ++i){
    cin >> v[i];
    v[i] -= i+1;
  }
  sort(all(v));
  if(!(N&1)){
    int b = v[N/2];
    for(int i=0; i<N; ++i)
      res += abs(v[i] - b);
    b = v[N/2 - 1];
    long long r = 0;
    for(int i=0; i<N; ++i)
      r += abs(v[i] - b);
    res = min(res, r);
  }
  else{
    int b = v[N/2];
    for(int i=0; i<N; ++i)
      res += abs(v[i] - b);
  } 
  cout << res << "\n";
}


Measured memory_bytes: 1024
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <list>
#include <ctime>
#include <sstream>
#include <queue>
#include <stack>
#include <bitset>
#include <numeric>
#include <cassert>
using namespace std;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long long ll;
#define FOR(x, b, e) for(int x=(b); x<=(e); ++x)
#define FORD(x, b, e) for(int x=((int)(b))-1; x>=(e); --x)
#define REP(x, n) for(int x=0; x<(n); ++x)
#define ALL(c) c.begin(),c.end()
#define sz(x) ((int)((x).size()))
#define pb push_back
#define st first
#define nd second
#define mp(x,y) make_pair(x,y)
typedef short int sint;

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it) {
	*this << ((it != d.b) ? ", " : "") << *it;
  }
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

const ll mod = 1000000000 + 7;
const int nax = 2 * 1010100;
ll sil[nax];

ll pot(ll a, int w) {
	ll res = 1;
	while (w) {
		if (w&1) {
			res = (res * a) % mod;
		}
		a = (a * a) % mod;
		w >>=1;
	}
	return res;
}

ll odw(ll a) {
	return pot(a, mod - 2);
}

ll choose(int r, int c) {
	// printf("choose(%d, %d)\n", r, c);
	ll pom = (sil[r+c] * odw(sil[r])) % mod;
	return (pom * odw(sil[c])) % mod;
}

int main() {
	ios_base::sync_with_stdio(false);
	int r1,c1,r2,c2;
	cin >> r1 >> c1 >> r2 >> c2;
	sil[0] = 1;
	FOR(i, 1, nax - 1) {
		sil[i] = (sil[i-1] * i) % mod;
	}
	ll res = 0;
	FOR(row, r1, r2) {
		ll rr = (choose(row + 1, c2) - choose(row + 1, c1 - 1) + mod) % mod;
		// cout << "row: " << row << ": " << rr << endl;
		res = ( res + rr ) %mod;
	}
	cout << res << endl;
}

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

using namespace std;

#define REP1(i,n) for(int i=1, i##_len=(n); i<i##_len; ++i)
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define pow(x) x*x
#define ll long long
static const ll MAX = 1000000;
static const ll INFTY = 1e12;

struct edge {
    ll to, cost;
};

using Graph = vector<vector<int>>;
using _Graph = vector<vector<edge>>;
// 入力
int H, W;
vector<vector<char>> field;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

// 深さ優先探索
vector<bool> seen;
vector<int> colors;

string make( vector<int> a, int N ){

}

 int main() {
 
     int N;
     cin >> N;
 
     vector<int> a(N + 1);
     for (int i = 1; i <= N; i++) {
         cin >> a[i];
     }
 
     vector<int> ans;
     vector<int> b(N + 1, 0);
     for (int i = N; i >= 1; i--) {
         int sum = 0;
         for (int j = i; j <= N; j += i) {
             sum += b[j];
         }
         if ((sum + a[i]) % 2 == 1) {
             b[i]++;
             ans.push_back(i);
         }
     }
 
     reverse(ans.begin(), ans.end());
 
     cout << ans.size() << endl;
     for(auto x: ans) cout << x << " ";
 
 }
/*
                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . __
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
         pass System Test!
*/


Measured memory_bytes: 3064
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <vector>
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define all(a) (a).begin(), (a).end()

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

using ll = long long;

ll H, W, K;
std::string S[310];
ll a[310][310];
bool fld[310];

int main()
{
  std::cin >> H >> W >> K;
  rep( i, H )
    std::cin >> S[i];

  rep( i, H )
  {
    bool fl = true;

    rep( j, W )
      fl &= S[i][j] == '.';

    if( fl )
      fld[i] = true;
  }

  ll cnt = 1;

  rep( i, H )
  {
    bool fst = true;

    if( fld[i] )
      continue;

    rep( j, W )
    {
      if( !fst && S[i][j] == '#' )
        ++cnt;

      if( fst && S[i][j] == '#' )
        fst = false;

      a[i][j] = cnt;
    }

    ll p = i;

    while( p >= 0 && fld[p-1] )
    {
      --p;

      rep( j, W )
        a[p][j] = a[p+1][j];
    }

    while( i < H && fld[i+1] )
    {
      ++i;

      rep( j, W )
        a[i][j] = a[i-1][j];
    }

    ++cnt;
  }

  rep( i, H )
  {
    rep( j, W )
      std::cout << a[i][j] << (j==W-1 ? '\n' : ' ');
  }

  return 0;
}

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

int main(){
  int N;
  cin >> N;
  vector<pair<int,int>> V(N);
  for(int i=0;i<N;i++){
    int x,y;
    cin >> x >> y;
    V[i] = make_pair(x,y);
  }
  
  vector<int> A(N),B(N);
  for(int i=0;i<N;i++){
    A[i] = V[i].first + V[i].second;
    B[i] = V[i].first - V[i].second;
  }
  sort(A.begin(),A.end());
  sort(B.begin(),B.end());
  
  cout << max(A[N-1]-A[0] , B[N-1]-B[0]);
  return 0;
}


Measured memory_bytes: 6356
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
using namespace std;
using Graph = vector<vector<int>>;
#define MOD 1000000007
#define MOD2 998244353
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long ll;
typedef pair<ll, ll> P;

ll a[300010];

int main(){
    ll n;
    cin >> n;
    rep(i, n) cin >> a[i];
    ll ans = 0;
    rep(i, 62){
        ll cnt = 0;
        rep(j, n) if ((a[j]>>i) & 1ll) cnt++;
        ans += (((1ll<<i)%MOD) * (cnt % MOD))%MOD * ((n - cnt)%MOD);
        ans %= MOD;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 2560
#!/usr/bin/env python3
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1

n,m=map(int,input().split())
A=[0]*(m+1); S=[0]*m

for i in range(m):
    a,b=map(int,input().split())
    A[i]=a
    s=0
    for ci in map(int,input().split()):
        s|=1<<(ci-1)
    S[i]=s
dp=[[inf]*(2**n) for i in range(m+1)]
for i in range(m+1):
    dp[i][0]=0
# print(dp)
# print(S)
for i in range(m):
    for s in range(2**n):
        dp[i+1][s]=min(dp[i+1][s],dp[i][s])
        # if i==1 and s==0:
        #     print(i,s,S[i])
        #     print(dp[i+1][s|S[i]],dp[i+1][s|S[i]],dp[i][s|S[i]],dp[i][s]+A[i])
        dp[i+1][s|S[i]]=min(dp[i+1][s|S[i]],dp[i][s|S[i]],dp[i][s]+A[i])
print(dp[m][(1 << n)-1] if dp[m][(1 << n)-1] != inf else -1)
# print(S)
# for di in dp:
#     print(*di)

Measured memory_bytes: 186392
#include <iostream>
using namespace std;
int n, m, a[109], mod = 1000000;
int main() {
	cin >> n >> m;
	if (m == 1) {
		int ret = 1;
		for (int i = 0; i < n; i++) ret = ret * 2 % mod;
		cout << ret << endl;
	}
	else {
		// OEIS A006192
		a[1] = 1, a[2] = 4, a[3] = 12;
		for (int i = 4; i < n + 2; i++) a[i] = (4 * a[i - 1] - 3 * a[i - 2] + 2 * a[i - 3] + a[i - 4] + 3 * mod) % mod;
		cout << a[n + 1] << endl;
	}
	return 0;
}

Measured memory_bytes: 3096
#include<bits/stdc++.h>
#define enld '\n'
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("Ofast")
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr double INFD = 1e100;
constexpr ll mod = 1000000007;
constexpr ll mod2 = 998244353;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
// ios::sync_with_stdio(false);
// cin.tie(nullptr);
// ---------------------------------------------------------------------------

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    string N;
    cin >> N;
    for(int i=0; i<N.size(); i++){
        if(N[i]-'0' == 7){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}

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

using namespace std;
typedef long long ll;
typedef long int li;
typedef long double lb;
#define rep(i,j,n) for (ll i = j; i < (n); i++)
#define repr(i,j,n) for(ll i = j; i >= (n); i--)
#define all(x) (x).begin(),(x).end()
#define CLR(mat,f) memset(mat, f, sizeof(mat))
#define IN(a, b, x) (a<=x&&x<b)
#define out(ans) cout << ans << endl
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
typedef pair<ll,ll>P;
const ll mod=1e9+7;
const ll INF = 1LL<<60;
const ll m=1LL<<32;

int main(){

  string s;cin>>s;
  if(s[0]==s[1]&&s[1]==s[2])out("No");
  else out("Yes");

  return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
"""
Created on Wed Mar  6 16:29:39 2019

@author: Yamazaki Kenichi
"""

H,W = map(int,input().split())
A = [input() for i in range(H)]
T = [[-1,0,0] for j in range(H*W)] 

def g(x,i,j):
    if x == '.':
        return 1 if (i+j)%2 == 0 else 2
    else:
        return 4 if (i+j)%2 == 0 else 3
def p(u):
    return T[u][0]
def findset(u):
    if p(u) == -1:
        return u
    else:
        T[u][0] = findset(p(u))
        return T[u][0]

def unite(u,v):
    if findset(u) == findset(v):
        return
#    if T[findset(u)[0]][findset(u)[1]][1]+T[findset(u)[0]][findset(u)[1]][0
#         ] >= T[findset(v)[0]][findset(v)[1]][0]+T[findset(v)[0]][findset(v)[1]][1]:
    T[findset(u)][1] += T[findset(v)][1]
    T[findset(u)][2] += T[findset(v)][2]
    T[findset(v)][0] = findset(u)
def unite_check(i1,j1,i2,j2):
    if g(A[i1][j1],i1,j1)%2 == 0 and g(A[i2][j2],i2,j2)%2 == 0:
        unite(i1 * W + j1, i2 * W + j2)
    elif g(A[i1][j1],i1,j1)%2 == 1 and g(A[i2][j2],i2,j2)%2 == 1:
        unite(i1 * W + j1, i2 * W + j2)

for i in range(H):
    for j in range(W):
        if g(A[i][j],i,j) <= 2:
            T[i * W + j][1] += 1
        else:
            T[i * W + j][2] += 1
        if i !=0:
            unite_check(i,j,i-1,j)
        if j !=0:
            unite_check(i,j,i,j-1)
ans = 0
for i in range(H):
    for j in range(W):
        if T[i * W + j][0] == -1:
            ans += T[i * W + j][1] * T[i * W + j][2]
print(ans)


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

#define pb push_back
#define vi vector < int >
#define ii pair < int, int >
#define vii vector < pair < int, int > >
#define vvi vector < vector < int > >
#define ll long long
#define X first
#define Y second
#define mp make_pair
#define FOR( i, lo, hi ) for( int i = (lo);i < (hi);i++ )
#define DFOR( i, hi, lo ) for( int i = (hi);i >= (lo);i-- )
#define pqueue priority_queue

using namespace std;

const long long int MOD = 1e9 + 7;

ll REM( ll a )
{
	a %= MOD;
	if ( a < 0 )
	   a += MOD;
	return a;
}

ll ADD( ll a, ll b )
{
	return REM( REM( a ) + REM( b ) );
}

ll SUB( ll a, ll b )
{
	return REM( REM( a ) - REM( b ) );
}

ll MUL( ll a, ll b )
{
	return REM( REM( a ) * REM( b ) );
}

ll POT( ll n, ll k )
{
	if ( k == 0 )
		return 1;

	ll ret = POT( n, k / 2 );
	ret = MUL( ret, ret );

	if ( k % 2 )
		return MUL( ret, n );
	return ret;
}

ll DIV( ll a, ll b )
{
	return MUL( a, POT( b, MOD - 2 ) );
}

bool isPrime( ll x )
{
	for ( ll i = 2;i <= sqrt( x ); i++ )
		if ( x % i == 0 )
			return false;
	return true;
}

const int MAXN = 1e5 + 10;

int n, u, v, maxd;
vi graph[ MAXN ];
int parent[ MAXN ];

vi path, v1;

void dfs( int par, int node )
{
	parent[ node ] = par;
	v1.pb( node );
	
	if ( node == u )
	{
		path = v1;
	}
	FOR( i, 0, ( int )graph[ node ].size() )
	{
		int where = graph[ node ][ i ];
		if ( where == par )
			continue;
		dfs( node, where );
	}
	v1.pop_back( ); 
}

void dfs1( int par, int node, int d )
{
	FOR( i, 0, ( int )graph[ node ].size() )
	{
		int where = graph[ node ][ i ];
		if ( where == par )
			continue;
		
		dfs1( node, where, d + 1 );
	}
	maxd = max( d, maxd );
}

int main()
{
	cin >> n>> u >> v;
	u--;v--;
	FOR( i, 0, n - 1 )
	{
		int x, y;cin >> x >> y;
		x--;y--;
		graph[ x ].pb( y );
		graph[ y ].pb( x );
	}
	
	bool ok = false, ok1 = false;;
	FOR( i, 0, ( int )graph[ u ].size() )
	{
		if ( graph[ u ][ i ] != v )
			ok = true;
	}
	
	if ( !ok )
	{
		cout << "0\n";return 0;
	}
	
	dfs( v, v );
	
	int turn = 0;
	while ( true )
	{
		if ( parent[ u ] == v )
			break;
		if ( parent[ u ] == path[ turn + 1 ] )
		{
			turn++;
			break;
		}
		turn++;
		u = parent[ u ];
		v = path[ turn ];
	}
	
	dfs1( parent[ u ], u, 0 );
	//cout << turn << "\n";
	cout << turn + maxd << "\n";
	return 0;
}


Measured memory_bytes: 12920
/*  -*- coding: utf-8 -*-
 *
 * c.cc: E: Bichrome Tree
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 1000;
const int MAX_X = 5000;
const int INF = 1 << 30;

/* typedef */

typedef vector<int> vi;
typedef queue<int> qi;

/* global variables */

int ps[MAX_N], cs[MAX_N], xs[MAX_N], ys[MAX_N];
int dp[2][MAX_X + 1];
vi nbrs[MAX_N];

/* subroutines */

inline void setmin(int &a, int b) { if (a > b) a = b; }

/* main */

int main() {
  int n;
  scanf("%d", &n);

  ps[0] = -1;
  for (int i = 1; i < n; i++) {
    scanf("%d", &ps[i]), ps[i]--;
    cs[ps[i]]++;
    nbrs[ps[i]].push_back(i);
  }

  for (int i = 0; i < n; i++) scanf("%d", &xs[i]);

  qi q;
  for (int i = 0; i < n; i++)
    if (cs[i] == 0) q.push(i);

  bool ok = true;
  while (ok && ! q.empty()) {
    int u = q.front(); q.pop();

    int &xu = xs[u];
    fill(dp[0], dp[0] + xu + 1, INF);
    dp[0][0] = 0;
    int cur = 0, nxt = 1;

    vi &nbru = nbrs[u];
    for (vi::iterator vit = nbru.begin(); vit != nbru.end(); vit++) {
      int &v = *vit;
      int &xv = xs[v], &yv = ys[v];
      fill(dp[nxt], dp[nxt] + MAX_X + 1, INF);

      for (int i = 0; i <= xu; i++)
	if (dp[cur][i] < INF) {
	  if (i + xv <= xu) setmin(dp[nxt][i + xv], dp[cur][i] + yv);
	  if (i + yv <= xu) setmin(dp[nxt][i + yv], dp[cur][i] + xv);
	}

      cur ^= 1, nxt ^= 1;
    }

    int mind = INF;
    for (int i = 0; i <= xu; i++) setmin(mind, dp[cur][i]);

    ys[u] = mind;
    ok = (mind < INF);

    if (--cs[ps[u]] == 0) q.push(ps[u]);
  }

  if (ok) puts("POSSIBLE");
  else puts("IMPOSSIBLE");
  return 0;
}


Measured memory_bytes: 384
import java.util.Scanner;

public class Main {

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

	    int h=gi();
	    int w=gi();
	    int n=gi();
	    
        int c=0;
        while(n>0) {
        	n-=Math.max(h, w);
        	c++;
        }
	    System.out.print(c);
//	    if (a==b && b==c) {
//	    	System.out.print("Yes");
//	    }else {
//	    	System.out.print("No");
//	    }



	}

	public static long d(long n) {
		String a=String.valueOf(n);
		return (long)a.length();
	}

	// 文字列として入力を取得
	public static String gs() {
		return scanner.next();
	}

	// intとして入力を取得
	public static int gi() {
		return Integer.parseInt(scanner.next());
	}

	// longとして入力を取得
	public static long gl() {
		return Long.parseLong(scanner.next());
	}

	// doubleとして入力を取得
	public static double gd() {
		return Double.parseDouble(scanner.next());
	}
}

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

using namespace std;

void print(vector<int> col){
    for(int i=0;i<col.size();i++){
        cout<<col[i]<<"\n";
    }
}

void col(vector<vector<int> > a,vector<vector<int> > cost){
    int v=a.size();
    vector<int> col(v,-1);
    queue<int> q;
    q.push(0);
    col[0]=0;
    while(!q.empty()){
        int v=q.front();
        q.pop();
        for(int i=0;i<a[v].size();i++){
            int d=a[v][i];
            int w=cost[v][i];
            if(col[d]!=-1){
                continue;
            }
            col[d]=(col[v]+w)%2;
            q.push(d);
        }
    }
    print(col);
}

int main(){
    int n;
    cin>>n;
    vector<vector<int> > a(n),cost(n);
    for(int i=0;i<n-1;i++){
        int d,w,s;
        cin>>s>>d>>w;
        --s;
        --d;
        a[s].push_back(d);
        cost[s].push_back(w);
        a[d].push_back(s);
        cost[d].push_back(w);
    }
    col(a,cost);
    return 0;
}

Measured memory_bytes: 23168
#include"iostream"
#include"cmath"
#include"vector"
#include"algorithm"
#include"list"
#include"set"
#include"unordered_set"
#include"map"
#include"unordered_map"
#include"string"
#include"cstring"
#include"iomanip"
using namespace std;
typedef long long ll;

ll count(vector<ll>&rec,vector<ll>&temp,ll l,ll h)
{
    if(h-l<1)
        return 0;
    ll m=(l+h)/2;
    ll ans=count(rec,temp,l,m)+count(rec,temp,m+1,h);
    ll a=l,b=m+1;
    ll i=l;
    for(i=l;i<h;++i)
    {
        if(a>m||b>h)
            break;
        if(temp[a]>temp[b])
        {
            ans+=m-a+1;
            rec[i]=temp[b];
            ++b;
        }
        else
        {
            rec[i]=temp[a];
            ++a;
        }
    }
    while(a<=m)
    {
        rec[i++]=temp[a++];
    }
    while(b<=h)
    {
        rec[i++]=temp[b++];
    }
    for(int i=l;i<=h;++i)
    {
        temp[i]=rec[i];
    }
    return ans;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,k;
    cin>>n>>k;
    vector<ll>pre(n+1),temp(n+1);
    pre[0]=0;temp[0]=0;
    for(int i=1;i<=n;++i)
    {
        ll x;cin>>x;
        pre[i]=pre[i-1]+x;
        temp[i]=pre[i];
    }
    for(int i=0;i<=n;++i)
    {
        pre[i]-=k*i;
        temp[i]=pre[i];
    }
    cout<<n*(n+1)/2-count(pre,temp,0,n)<<'\n';
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define rep(i, n) for (int i = 0, i##_len = (int)(n); i < i##_len; i++)
#define reps(i, n) for (int i = 1, i##_len = (int)(n); i <= i##_len; i++)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define repi(i, x) \
	for (auto i = (x).begin(), i##_fin = (x).end(); i != i##_fin; i++)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define solve(a) ((a) ? "Yes" : "No")
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef pair<int, int> Pi;
typedef vector<Pi> VPi;
typedef vector<long long> V;
typedef vector<V> VV;
typedef pair<long long, long long> P;
typedef vector<P> VP;
template <class T>
inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return 1;
	}
	return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return 1;
	}
	return 0;
}
const long long INFLL = 1LL << 60;
const int INF         = 1 << 30;
const double PI       = acos(-1);
const int MAX         = 510000;
const ll MOD          = 998244353LL;
long long fac[MAX], finv[MAX], inv[MAX];

void COMinit() {  // テーブルを作る前処理
	fac[0] = fac[1] = 1LL;
	finv[0] = finv[1] = 1LL;
	inv[1]            = 1LL;
	for (int i = 2LL; i < MAX; i++) {
		fac[i]  = (ll)fac[i - 1] * i % MOD;
		inv[i]  = (ll)MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = (ll)finv[i - 1] * inv[i] % MOD;
	}
}

long long COM(int n, int k) {  // 二項係数:nCk計算
	if (n < k) return 0LL;
	if (n < 0 || k < 0) return 0LL;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
int main() {
	ll n, a, b, k;
	COMinit();
	VP list;
	ll ans = 0LL;
	cin >> n >> a >> b >> k;
	for (ll i = 0LL; i <= n and i <= k / a; i++) {
		if ((k - a * i) % b == 0) {
			list.push_back(mp(i, (k - a * i) / b));
		}
	}
	repi(itr, list) {
		ans += COM(n, itr->F) * COM(n, itr->S) % MOD;
		ans %= MOD;
	}

	cout << ans << endl;
}

Measured memory_bytes: 23472
using System;

class Program
{
    static void Main(string[] args)
    {
        switch (Console.ReadLine())
        {
            case "25":
                Console.WriteLine("Christmas");
                return;
            case "24":
                Console.WriteLine("Christmas Eve");
                return;
            case "23":
                Console.WriteLine("Christmas Eve Eve");
                return;
            case "22":
                Console.WriteLine("Christmas Eve Eve Eve");
                return;
        }
    }
}


Measured memory_bytes: 11092
#include <bits/stdc++.h>
using namespace std;
using int64 = long long;
#define int int64
#define rep(i, n) for(int i=0; i<n; i++)
#define FOR(i, a, b) for(int i=a; i<b; i++)
#define SORT(x) sort(x.begin(), x.end())
#define GSORT(x) sort(x.begin(), x.end(), greater<int>())
#define mk make_pair
#define fi first
#define se second
#define pb push_back
#define ALL(x) x.begin(), x.end()
#define V(T) vector<T>
typedef pair<int, int> P;
typedef pair<P, P> PP;
typedef vector<int> vi;
typedef vector<vi> vvi;
int max(int a, int b) {if(b>a) return b; else return a;}
int min(int a, int b) {if(b<a) return b; else return a;}


signed main() {
    int n;
    cin >> n;
    map<int, int> mp;
    rep(i, n) {
        int a;
        cin >> a;
        mp[a]++;
    }

    bool yes = true;
    for(auto &p : mp) {
        if(p.se > 1) yes = false;
    }

    if(yes) cout << "YES" << endl;
    else cout << "NO" << endl;
    
    return 0;
}

Measured memory_bytes: 12800
n,k=map(int,input().split())
r,s,p=map(int,input().split())
t=input()
tt=[]
ans=0
def score(c):
    if c=='r':
        return p
    if c=='s':
        return r
    if c=='p':
        return s


for i in range(n):
    if i-k>=0 and i+k>=n:
        if t[i]==t[i-k]:
            ans+=0
        else:
            ans+=score(t[i])
    elif i-k>=0:
        if t[i]==t[i-k]:
            if t[i]=='r':
                if t[i+k]!='s':
                    t=t[:i]+'s'+t[i+1:]
                else:
                    t=t[:i]+'p'+t[i+1:]
            elif t[i]=='s':
                if t[i+k]!='p':
                    t=t[:i]+'p'+t[i+1:]
                else:
                    t=t[:i]+'r'+t[i+1:]
            elif t[i]=='p':
                if t[i+k]!='r':
                    t=t[:i]+'r'+t[i+1:]
                else:
                    t=t[:i]+'s'+t[i+1:]
        else:
            ans+=score(t[i])
        
    else:
        ans+=score(t[i])

print(ans)
            

Measured memory_bytes: 3528