akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define rep(i,n) for(ll i = 0;i < n;++i)

int main(){
    ll x;
    cin >> x;
    ll a,b;
    rep(i,150){
        rep(j,150){
            a = pow(i,5);
            b = pow(j,5);
            if(a+b == x){ 
                cout << i << " -" << j << endl;
                return 0;
            }else if(a-b == x){
                cout << i << " " << j << endl;
                return 0;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 3992
a,b,c = [input().split() for i in range(3)]

a.extend(b)
a.extend(c)
N = int(input())
b = [input() for i in range(N)]
for b1 in b:
    a = ['a' if b1 == s in s else s for s in a]

if a[0] == 'a' and a[1] == 'a' and a[2] == 'a':
    print("Yes")
elif a[3] == 'a' and a[4] == 'a' and a[5] == 'a':
    print("Yes")
elif a[6] == 'a' and a[7] == 'a' and a[8] == 'a':
    print("Yes")
elif a[0] == 'a' and a[3] == 'a' and a[6] == 'a':
    print("Yes")
elif a[1] == 'a' and a[4] == 'a' and a[7] == 'a':
    print("Yes")
elif a[2] == 'a' and a[5] == 'a' and a[8] == 'a':
    print("Yes")
elif a[0] == 'a' and a[4] == 'a' and a[8] == 'a':
    print("Yes")
elif a[2] == 'a' and a[4] == 'a' and a[6] == 'a':
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
 
#define FOR(n) for(int i=0;i<n;i++)
#define ll long long
 
ll mob=1000000007;
 
using namespace std;
int main()
{ int a,s;
 cin>>a>>s;
 if((a*500)>=s) 
   cout<<"Yes";
  else 
    cout<<"No";
 
 
 
 
return 0;
}

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

vector<vector<int>> g;
vector<int> ans;

void dfs(int s, int p) {
  for (auto t : g[s]) {
    if (t == p) continue;
    ans[t] += ans[s];
    dfs(t, s);
  }
}

int main() {
  int n, q;
  cin >> n >> q;
  g.resize(n);
  ans.assign(n, 0);
  for (int i = 0; i < n - 1; i++) {
    int a, b;
    cin >> a >> b, --a, --b;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  for (int i = 0; i < q; i++) {
    int p, x;
    cin >> p >> x, --p;
    ans[p] += x;
  }
  dfs(0, -1);
  for (int i = 0; i < n; i++) {
    cout << ans[i] << endl;
  }
}


Measured memory_bytes: 23552
#include <iostream>
#include <cmath>

#include <vector>
#include <algorithm>
#include <limits>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <array>
#include <queue>

typedef long long ll;

using namespace std;


int main() {
    string s;
    cin >> s;
    if (s[s.length()-1] == 's') {
        cout << s + "es" << endl;
    } else {
        cout << s + "s" << endl;
    }
}


Measured memory_bytes: 3624
n, a, b = map(int, input().split())
c = 0
cb = 0
s = input()
for x in s:
    if x == "a":
        if c < a + b:
            c += 1
            print("Yes")
        else:
            print("No")
    if x == "b":
        if c < a + b and cb < b:
            c += 1
            cb += 1
            print("Yes")
        else:
            print("No")
    if x == "c":
        print("No")


Measured memory_bytes: 4016
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
using namespace std;
typedef complex<double> P;
#define REP(i, j) for(int i = 0; i < (int)(j); ++i)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
const double EPS = 1e-8;
const double INF = 1e12;

struct L : public vector<P> {
  L(const P &a, const P &b) {
    push_back(a); push_back(b);
  }
};

double dot(const P& a, const P& b) {
  return real(conj(a)*b);
}

P projection(const L &l, const P &p) {
  double t = dot(p-l[0], l[0]-l[1]) / norm(l[0]-l[1]);
  return l[0] + t*(l[0]-l[1]);
}

P reflection(const L &l, const P &p) {
  return p + P(2, 0) * (projection(l, p) - p);
}

int main(){
  double x0, y0, x1, y1, x2, y2;
  while(scanf("%lf,%lf,%lf,%lf,%lf,%lf", &x0, &y0, &x1, &y1, &x2, &y2) != EOF){
    P P1(x0, y0), P2(x1, y1), Q(x2, y2);
    P ans = reflection(L(P1, P2), Q);
    printf("%.8lf %.8lf\n", ans.real(), ans.imag());
  }
  return 0;
}

Measured memory_bytes: 1268
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

void solve() {
	string s;
	cin >> s;
	int n = s.size();
	int sum = 0;
	for (int i = 0; i < n; i++)
		sum += s[i] - '0';
	cout << (sum % 9 == 0 ? "Yes" : "No");
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
#if defined(_DEBUG)
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	int q = 1;
	//cin >> q;
	for (; q > 0; q--) {
		solve();
		cout << endl;
	}
}

Measured memory_bytes: 3716
#include<bits/stdc++.h>
using namespace std;
const long long INF = (1LL << 32);
const long long MOD = 1000000007;
const long double PI = 3.1415926;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()
typedef long long int ll;
typedef vector<ll> vi;
typedef vector<pair<ll, ll>> vp;
typedef vector<string> vs;
typedef vector<char> vc;
typedef list<ll> lst;
typedef pair<ll, ll> P;
template <class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <class T> T &chmax(T &a, const T &b) { return a = max(a, b); }
ll n, m, k, ans = 0, sum = 0, cnt = 0;
string s;
char c;

#define Endl endl

/*--------------------template--------------------*/


int main() {
    cin >> n;
    vi v(n), vv(n), va(n), vva(n);
    REP(i,n) {
        cin >> v[i];
        if(i==0){
            va[i] = v[i];
            continue;
        }
        va[i] = v[i] + va[i - 1];
    }
    REP(i,n) {
        cin >> vv[i];
    }
    RREP(i,n){
        if (i == n-1)
        {
            vva[i] = vv[i];
            continue;
        }
        vva[i] = vv[i] + vva[i + 1];
    }
    REP(i,n) {
        chmax(ans, va[i] + vva[i]);
    }
    cout << ans << endl;
    
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <utility>
#define rep(i, s, g) for (i = s; i <= g; i++)
using namespace std;
using ll = long long;
const ll MOD = 1e9 + 7;

vector<vector<int>> G;
vector<int> dp(100010, -1);

int memorize(int n)
{
    if (dp[n] != -1)
    {
        return dp[n];
    }

    int res = 0;
    for (auto x : G[n])
    {
        res = max(res, memorize(x) + 1);
    }

    return dp[n] = res;
}

int main(void)
{
    int N, M;
    int x, y;
    int i, j;
    int ans = 0;

    cin >> N >> M;

    G.assign(N + 1, vector<int>());

    rep(i, 1, M)
    {
        cin >> x >> y;
        G[x].push_back(y);
    }

    rep(i, 1, N)
    {
        ans = max(ans, memorize(i));
    }

    cout << ans << endl;
}

Measured memory_bytes: 8192
#include<stdio.h>

int num[2000009];

int quicksort(int left,int right)
{
	int i,j,mid;
	i=left;j=right;
	mid=num[(left+right)>>1];
	while (i<j) 
	{
		while (num[i]>mid) ++i;
		while (num[j]<mid) --j;
		if (i<=j)
		{
			int tmp;
			tmp=num[i];num[i]=num[j];num[j]=tmp;
			++i;--j;
		}
	}
	if (i<right) quicksort(i,right);
	if (j>left) quicksort(left,j);
}

main()
{
	int n,i;
	scanf("%d",&n);
	for (i=1;i<=n;i++) 
		scanf("%d",&num[i]);
	quicksort(1,n);
	for (i=2;i<=n;i++)
		if (num[i]==num[i-1])
		{
			printf("NO");
			return 0;
		}
	printf("YES");
	return 0;
}


Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
typedef  long long   ll;
typedef  long double ld;
#define ceil(n, m) ((n / m) + ( n % m ? 1 : 0))
#define mod(n, m) (((n % m) + m) % m)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()


int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    //freopen("input.txt", "r", stdin);
    ll x, k, d;
    cin >> x >> k >> d;
    x = abs(x);
    if(abs(x - d) >= x){
        if(k & 1)
            cout << abs(x - d);
        else cout << x;
        return 0;
    }
    ll mn = min(k, ceil(x, d));
    x -= d * mn, k -= mn;
    if(k & 1)
        x += d;
    cout << abs(x);
//    cout << x << " " << k << '\n';
//    cout << mn;





}

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

#define ll long long
#define int ll
#define pii pair<int, int>
#define pb push_back
#define INF 1e18
#define REP(i, n) for (int i=0; i<n; i++)
#define FOR(i, a, b) for (int i=a; i<b; i++)
#define REPD(i, n) for (int i=n-1; i>=0; i--)
#define FORD(i, a, b) for (int i=a; i>=b; i--)
#define vi vector<int>
#define all(v) v.begin(), v.end()
#define print(x) cout << x << endl
#define debug(x) cout << #x << " = "<< x << endl

const double PI=3.141592653589793238462643383279502884197169399375105820974944;

using namespace std;

void solve() {
    int T, X;
    cin >> T >> X;

    double ans = (double)T / X;
    cout << fixed << setprecision(10) << ans << endl;
}

signed main() {
    solve();
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>

using namespace std;

const int INFTY=1<<29;

string substitute(string s,string a,string b)
{
	for(int i=0;(i=s.find(a,i))!=-1;i+=b.size())
		s.replace(i,a.size(),b);
	return s;
}

int dfs(string from,string to,vector<string>& a,vector<string>& b)
{
	if(from==to) return 0;
	if(from.size()>=to.size()) return INFTY;
	
	int res=INFTY;
	for(int i=0;i<a.size();i++)
		if(from.find(a[i])!=-1)
			res=min(res,1+dfs(substitute(from,a[i],b[i]),to,a,b));
	return res;
}

int main()
{
	for(int n;cin>>n,n;){
		vector<string> a(n),b(n);
		for(int i=0;i<n;i++) cin>>a[i]>>b[i];
		string from,to; cin>>from>>to;
		
		int res=dfs(from,to,a,b);
		cout<<(res==INFTY?-1:res)<<endl;
	}
}

Measured memory_bytes: 1228
def resolve():

    n, m,x = map(int, input().split())
    c=[]
    a=[]
    ans=10**13
    nedan=0
    rikai=[0]*m
    for i in range(n):
        A = list(map(int, input().split()))
        c.append(A[0])
        a.append(A[1:])
        for j in range(m):
            rikai[j]+=a[i][j]

    if min(rikai)>=x:
        for Bin in range(1,2**n):
            rikai = [0] * m
            nedan = 0
            for hon in range(n):
                if (Bin>>hon) & 1:
                    for aru in range(m):
                        rikai[aru]+=a[hon][aru]
                    nedan+=c[hon]
            if min(rikai)>=x:
                ans=min(ans,nedan)
        print(ans)

    else:
        print(-1)
resolve()

Measured memory_bytes: 68296
//Code By PMD
#include<bits/stdc++.h>
#define faster() ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
typedef long long i64;
int n;
string s;
void input(){
    cin >> n >> s;
}
void solve(){
    string tmp = s.substr(0,n/2);
    tmp += tmp;
    if ( tmp == s ) cout << "Yes";
    else cout << "No";
}
int main(){
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    faster();int t=1; 
    //cin>>t; cin.ignore();
    while(t--){ input();solve();}
    cerr << "\nRunning is : " << 1.0*clock()/1000 ;
    return 0;
}
//Code By PMD
 

Measured memory_bytes: 256
#include <iostream>
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_dec_float.hpp>

using namespace std;
int main(void){
  	namespace mp = boost::multiprecision;
    mp::cpp_dec_float_50 a,b;
  	cin>>a>>b;
  
	cout<<mp::cpp_dec_float_50(mp::floor(a*b)).str()<<endl;
  	
}


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

int main () {
  int k, n;
  cin >> k >> n;
  vector<int> a (n);
  
  for (int i = 0; i < n; i++)
    cin >> a[i];
  
  int maxDifference = 0;
  for (int i = 0; i < n-1; i++) {
    int difference = a[i+1] - a[i];
    if (difference > maxDifference)
      maxDifference = difference;
  }
  
  if (k - a[n-1] + a[0] > maxDifference)
    maxDifference = k - a[n-1] + a[0];
  
  cout << k - maxDifference << endl;
  
}

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

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

Measured memory_bytes: 256
#!/usr/bin/python3
# -*- coding: utf-8 -*-

def cal(mozi, r, s, p):
    if mozi == "r":
        return r
    if mozi == "s":
        return s
    if mozi == "p":
        return p

n, k = map(int, input().split())
r, s, p = map(int, input().split())
t = input()
dasu_list = []
for i in range(0, k):
    dasu_list.append([])
for i in range(0, len(t)):
    j = i % k
    if t[i] == "r":
        dasu_list[j].append("p")
    if t[i] == "s":
        dasu_list[j].append("r")
    if t[i] == "p":
        dasu_list[j].append("s")
score = 0
for i in range(0, k):
    check_list = dasu_list[i]
    score += cal(check_list[0], r, s, p)
    for j in range(1, len(check_list) - 1):
        if check_list[j - 1] == check_list[j]:
            if check_list[j - 1] == "r":
                if check_list[j + 1] == "r":
                    check_list[j] = "s"
                if check_list[j + 1] == "s":
                    check_list[j] = "p"
                if check_list[j + 1] == "p":
                    check_list[j] = "s"
            if check_list[j - 1] == "s":
                if check_list[j + 1] == "r":
                    check_list[j] = "p"
                if check_list[j + 1] == "s":
                    check_list[j] = "p"
                if check_list[j + 1] == "p":
                    check_list[j] = "r"
            if check_list[j - 1] == "p":
                if check_list[j + 1] == "r":
                    check_list[j] = "s"
                if check_list[j + 1] == "s":
                    check_list[j] = "r"
                if check_list[j + 1] == "p":
                    check_list[j] = "r"
        else:
            score += cal(check_list[j], r, s, p)
    if check_list[len(check_list) - 2] != check_list[len(check_list) - 1]:
        score += cal(check_list[len(check_list) - 1], r, s, p)
print(score)

Measured memory_bytes: 13428
#include <stdio.h>

int main(void)
{
	int a,b,c,d,e;
	scanf("%d",&a);
	b=a/1000;
	c=a/100-b*10;
	d=a/10-b*100-c*10;
	e=a-b*1000-c*100-d*10;
	if(b==c&&c==d){
		printf("Yes");
	}else if(c==d&&d==e){
		printf("Yes");
	}else{
		printf("No");
	}
	return 0;
}

Measured memory_bytes: 128
input = readlines()
meta = input.shift.chomp.to_i

list = {'AC' => 0, 'WA' => 0, 'TLE' => 0, 'RE' => 0}
input.each do |l|
  jdg = l.chomp
  list[jdg] += 1
end

['AC', 'WA', 'TLE', 'RE'].each do |key|
  puts "#{key} x #{list[key]}"
end


Measured memory_bytes: 22088
import sys
import numpy as np

MOD = 10 ** 9 + 7

n, *a = map(int, sys.stdin.read().split())
a = np.array(a, dtype=np.int64)

def main():
    ans = 0
    for i in range(60):
        b = (a >> i) & 1
        x = np.count_nonzero(b)
        y = n - x
        x *= y
        x *= pow(2, i, MOD)
        ans += x
    ans %= MOD
    return ans

if __name__ == '__main__':
    ans = main()
    print(ans)

Measured memory_bytes: 49952
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<set>
#include<iomanip>
#define pi 3.14159265358979323846
#define ll long long
#define rep(i, a, n) for(int i = a; i < n; i++)
using namespace std;
int main(){
  int a, b, c;
  cin >> a >> b >> c;
  if(a > c){
    cout << "No\n";
    return 0;
  }
  if(b < c){
    cout << "No\n";
    return 0;
  }
  cout << "Yes\n";
}

Measured memory_bytes: 3624
import math


def main():
    n, k = map(int, input().split())
    a = list(map(int, input().split()))
    if k == 1:
        print(sum(a))
        return
    cum = [0] * (len(a) + 1)
    for i in range(len(a)):
        cum[i+1] = cum[i] + a[i]
    b = [0] * (n * (n+1) // 2)
    index = 0
    for i in range(len(cum)):
        for j in range(i+1, len(cum)):
            b[index] = cum[j] - cum[i]
            index += 1

    ret = 0
    for i in range(45, -1, -1):
        b.sort(reverse=True, key=lambda x:x & 1 << i)
        tmp = search(b, i)
        if tmp + 1 < k:
            continue
        t = 1 << i
        ret += t
        b = b[:tmp+1]


    print(ret)


def search(array, i):
    le = 0
    ri = len(array)
    while ri - le > 1:
        mi = (ri + le) // 2
        if array[mi] & 1 << i:
            le = mi
        else:
            ri = mi
    return le


main()


Measured memory_bytes: 31020
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <utility>
#include <iomanip>
using namespace std;
typedef long long ll;

const ll MOD = 1e9+7;
ll a[500];
ll b[500];

vector<ll> divisor(ll n)
{
	vector<ll> ret;
  for(ll i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      ret.push_back(i);
      if(i * i != n) ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
	reverse(ret.begin(),ret.end());
  return (ret);
}

int main()
{
	int n;
	ll k;
	ll ss=0;
	ll ans=0;
	cin>>n>>k;
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
		ss+=a[i];
	}
	vector<ll> yaku=divisor(ss);
	for(int j=0;j<yaku.size();j++)
	{
		//cerr<<yaku[j]<<endl;
		fill(b,b+500,0);
		//順番にyaku[j]の倍数にするのにかかる手数を調べる
		for(int i=0;i<n;i++)
			b[i]=(a[i]+yaku[j])%yaku[j];
		//検証する
		sort(b,b+n);
		for(int i=0;i<n+1;i++)
		{
			ll sum=0;
			ll psum=0;
			ll msum=0;
			//マイナスを加える
			for(int k=0;k<i;k++)
			{
				sum+=-b[k];
				msum+=b[k];
			}
			for(int k=i;k<n;k++)
			{
				if(b[k]!=0)
				{
					sum+=(yaku[j]-b[k]);
					psum+=(yaku[j]-b[k]);
				}
			}
			//cerr<<yaku[j]<<" "<<sum<<" "<<absum<<endl;
			if(sum==0 && max(psum,msum)<=k)
			{
				ans=yaku[j];
				break;
			}
		}
		if(ans>0)
			break;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <random>
#include <chrono>

using namespace std;
using namespace __gnu_pbds;

#define endl '\n'

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

//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

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

	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	
	ll a, b, c;
	cin >> a >> b >> c;
	
	ll mn = min(c, a);
	a -= mn;
	c -= mn;
	
	mn = min(c, b);
	b -= mn;
	
	cout << a << " " << b << endl;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    long long int A,B,C;
    long long int K;
    long long int count=0;
    cin>>A>>B>>C>>K;
    for(int i=0;i<K;i++){
        if(i+1<=A){
            count++;
        }
        else if(A+B<i+1 & i+1<=A+B+C){
            count--;
        }
    }
    cout<<count<<endl;
}


Measured memory_bytes: 3596
from heapq import heapify, heappop
w,h = map(int, input().split())
heap = []
for i in range(w):
    p = int(input())
    heap.append((p,0))
for i in range(h):
    q = int(input())
    heap.append((q,1))
heapify(heap)

ans = 0
h += 1
w += 1
while heap:
    c, f = heappop(heap)
    if f==0:
        ans += c*h
        w -= 1
    else:
        ans += c*w
        h -= 1
print(ans)

Measured memory_bytes: 23772
#include <iostream>

using namespace std;

int main()
{
	int N;
	int num[200][3],c[101],score[200]={0};
	cin>>N;
	for (int i=0; i<N; i++) cin>>num[i][0]>>num[i][1]>>num[i][2];
	for (int i=0; i<3; i++) {
		for (int j=1; j<=100; j++) c[j]=0;
		for (int j=0; j<N; j++) c[num[j][i]]++;
		for (int j=0; j<N; j++) {
			if (c[num[j][i]]==1) score[j]+=num[j][i];
		}
	}
	for (int i=0; i<N; i++) {
		cout<<score[i]<<endl;
	}
}

Measured memory_bytes: 1164
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <map>
#include <queue>
#include <string>

#define reps(i,s,n) for(int (i) = (s); (i) < (n); (i)++)
#define rep(i,n) reps(i,0,n)
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using vi = vector<int> ;
using vl = vector<ll>;

int main(){
    int x;
    cin >> x;
    if(x == 0){
        cout << 1 << endl;
    }else{
        cout << 0 << endl;
    }


    return 0;
}

Measured memory_bytes: 3632
#include <iostream>

using namespace std;
#define MAXW 20
#define MAXH 20
int w, h, sx, sy, gx, gy, ans;
int table[MAXH][MAXW];
int dx[4] = {0, 0, 1, -1};
int dy[4] = {1, -1, 0, 0};

void get_start_point(){
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            if (table[i][j] == 2) {
                sy = i; sx = j;
                return;
            }
        }
    }
}

void dfs(int y, int x, int count){
    if (count > ans) {
        return;
    }
    for (int i = 0; i < 4; i++) {
        int mx = x + dx[i];
        int my = y + dy[i];
        if (mx < 0 || mx >= w || my < 0 || my >= h) {
            continue;
        }
        if (table[my][mx] == 1) {
            continue;
        }
        while (true) {
            if (table[my][mx] == 3) {
                ans = count;
                return;
            }
            mx += dx[i];
            my += dy[i];
            if (mx < 0 || mx >= w || my < 0 || my >= h) {
                break;
            }
            if (table[my][mx] == 1) {
                table[my][mx] = 0;
                dfs(my - dy[i], mx - dx[i], count + 1);
                table[my][mx] = 1;
                break;
            }
        }
    }
}

int main()
{
    while (true) {
        cin >> w >> h;
        if (w == 0 && h == 0) {
            break;
        }
        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                cin >> table[i][j];
            }
        }
        get_start_point();
        ans = 11;
        dfs(sy, sx, 1);
        if (ans == 11) {
            cout << -1 << endl;
        }else{
            cout << ans << endl;
        }
    }
    return 0;
}

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

int main(){
    int n, m;
    cin >> n >> m;
    vector<int> a(n, 0);
    int poll = 0;
    rep (i, n){
        cin >> a.at(i);
        poll += a.at(i);
    }
    sort(a.begin(), a.end());
    reverse(a.begin(), a.end());
    float thr = poll * 1.0 / (4*m);
    int cnt = 0;
    for (auto i: a){
        if (i >= thr) cnt++;
        else break;
    }
    if (cnt >= m) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int q,z,y=0;
  cin>>q;
  z=q;
  while(z>0){
    y+=z%10;
    z/=10;
  }
  if(q%y==0) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

Measured memory_bytes: 3536
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a
def lcm(a, b):
    return a * b // gcd (a, b)
n, m = map(int, input().split())
S = input()
T = input()
jn = 0
jm = 0
l = lcm(n,m)
ln = l // n
lm = l // m
d = lcm(ln, lm)
for i in range(0, l, d):
    if S[i // ln] != T[i // lm]:
        print(-1)
        exit()
print(l)

Measured memory_bytes: 3316
a,b,c,k = (int(x) for x in input().split())

max  = 0

if(a > k):
  max += k
  k = 0
else:
  max += a
  k -= a 
  
if(k != 0)and(b > k):
  k = 0
elif k != 0:
  k -= b
  
if(c > k):
  max -= k
elif k != 0:
  max -= c

print(max)
  

Measured memory_bytes: 9200
#include <bits/stdc++.h>
#include <cmath>
#include <numeric>
using namespace std;
using ll=long long;
#define rep(i,a,b) for(int i=(a); i<(b); ++i) // a ≦ i < b 
#define Rrep(i,a,b) for(int i=(a);i>=(b);--i) // reverse repeat. a から b まで減少．
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend() //逆イテレータ
#define RANGE(a,b,c) (a).begin()+b,(a).begin()+c // コンテナ a の 要素 b から c へのイテレータ
#define MOD 1000000007
// typedef
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<PII> VP;


int main() {
int A, B, C; cin >> A >> B >> C;

rep(a, 1, B){
    if ((a*A)%B == C) {
        cout << "YES" << "\n";
        return 0;
    }
}
cout << "NO" << "\n";

return 0;
}

// 境界，出力文字列 チェック
// int は ± 2*10⁹.
// map[]は対数時間．unordered_map[]は一定時間．


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define endl "\n"
#define pb push_back
#define ll long long
#define d1(x)  cerr << #x << "--> " << x << endl
#define d2(x, y)  cerr << #x << "--> " << x << " | " << #y << "--> " << y <<endl
#define d3(x, y,z)  cerr << #x << "--> " << x << " | " << #y << "--> " << y <<" | " << #z << "--> "<< z<< endl
#define vpll vector<pair<ll,ll>>
#define F first
#define S second
#define T ll tt; cin>>tt; while(tt--)
using namespace std;
ll mode=pow(10,9)+7;
bool cmp(pair<long double ,int > x, pair<long double , int> y){ return x.F<y.F; }
const ll MAXN=1e3+5;
ll __lcm(ll a, ll b){ return (a*b)/__gcd(a,b); }
 
int main(){ 
    
//    #ifndef ONLINE_JUDGE
//  		freopen("input.txt", "r", stdin);
//    #endif
    
    ios::sync_with_stdio(0);
    cin.tie(0);
	
	ll n;
	cin>>n;
	ll a[n];
	for (int i=0;i<n;i++) cin>>a[i];
	
	ll ans=0;
	ll minn[n];
	minn[0]=a[0];
	for (int i=1;i<n;i++){
		minn[i]=min(minn[i-1], a[i]);
	}
	for (int i=0;i<n;i++){
		ans+=(minn[i]==a[i]);
	}
	//	cout<<ans<<endl;
	
	cout<<ans<<endl;
		
	return 0;
}
	


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

using namespace std;
typedef long long int ll;
typedef pair<ll, ll > pi;  
typedef pair<pair<ll, ll >, ll > pii;  
vector<ll > vec;
vector<vector<ll > > vec2;
ll MOD = 1000000007;

int main(){

    ll N; string S;
    cin >> N >> S;

    for(ll i = 0; i < S.size();){
        ll j = i;
        //一緒の間ループを回し続けて，切れ目を探す
        while(j < S.size() && S[j] == S[i]){
            ++j;
        }
        vec.push_back(j - i);
        //次の始点へすっ飛ばす
        i = j;
    }

    cout << vec.size() << endl;

}

Measured memory_bytes: 1528
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<(n); i++)
int main()
{
    int h, w;
    cin >> h >> w;

    char mat[100][100];
    rep(i, h){
        rep(j, w){
            cin >> mat[i][j];
        }
    }

    bool row[100] = {false}, column[100] = {false};

    rep(i, h){
        rep(j, w){
            if(mat[i][j] != '.' && !row[i]){
                row[i] = true;
            }
        }
    }
    rep(i, w){
        rep(j, h){
            if(mat[j][i] != '.' && !column[i]){
                column[i] = true;
            }
        }
    }

    rep(i, h){
        rep(j, w){
            if(row[i] && column[j]){
                cout << mat[i][j];
            }
        }
        cout << '\n';
    } 

    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static  void main(String args[]){
        Scanner scanner = new Scanner(System.in);
       int x = scanner.nextInt();
       double ans = 1;
       for (int i = 2; i < x; i++){
           for(int j = 2; Math.pow(i,j) <= x; j++){
               if(ans < Math.pow(i,j)){
                   ans = Math.pow(i,j);
               }
           }
       }
       System.out.println((int)ans);
    }
}


Measured memory_bytes: 22100
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <iomanip>
#include <cassert>
#include <stack>
#include <queue>
#include <deque>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
//using namespace __gnu_pbds;

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

// template<typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
//  order_of_key (k) : Number of items strictly smaller than k .
//  find_by_order(k) : K-th element in a set (counting from zero).
#define sz(a) (int)a.size()
#define all(a) a.begin(), a.end()
#define pb push_back
#define ppb pop_back
#define mkp make_pair
#define F first
#define S second
#define show(a) cerr << #a <<" -> "<< a <<"\n"
#define fo(a, b, c, d) for(int (a) = (b); (a) <= (c); (a) += (d))
#define foo(a, b, c ,d) for(int (a) = (b); (a) >= (c); (a) -= (d))
//#define int ll


const int N = 2e5 + 5;
const int oo = 1e9 + 5;
const double P = acos(-1.0);

int a[N], k, n, ans = oo;

void solve() {
	cin >> k >> n;
	fo (i, 1, n, 1)
		cin >> a[i];
	fo (i, 1, n, 1) {
		int d1 = a[i] - a[1] + a[i] - a[1] + a[n] - a[i];
		int d2 = a[n] - a[i] + a[n] - a[i] + a[i] - a[1];
		int d3 = k - a[i] + a[i-1];
		int d4 = a[i] + k - a[i+1];
		ans = min({ans, d1, d2, d3, d4});
	}	
	cout << ans;
}

 main () {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int tt = 1;
	while (tt --) {
		solve();
	}
	return 0;
}
/*
	“I’m not gonna run away, I never go back on my word! That’s my nindo: my ninja way.” Naruto
*/

Measured memory_bytes: 1024
n,k=map(int,input().split())
H=list(map(int,input().split()))

dp=[float('inf') for _ in range(n)]
dp[0]=0
for i in range(n):
  for j in range(1,k+1):
    if i+j<n:
      dp[i+j]=min(dp[i+j],dp[i]+abs(H[i+j]-H[i]))
print(dp[-1])

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

class Main{
  static class Scnr{
    private final InputStream ins;
    private final byte[] buf=new byte[1024];
    private int ptr=0;
    private int buflen=0;
    Scnr(){
      this(System.in);
    }
    Scnr(InputStream ins){
      this.ins=ins;
    }
    private boolean hasNextByte(){
      if(ptr<buflen){
        return true;
      }
      ptr=0;
      try{
        buflen=ins.read(buf);
      }catch(IOException e){
        e.printStackTrace();
      }
      return buflen>0;
    }
    private int readByte(){
      if(hasNextByte()){
        return buf[ptr++];
      }else{
        return -1;
      }
    }
    private static boolean isChar(int c){
      return '!'<=c&&c<='~';//33~126
    }
    public boolean hasNext(){
      while(hasNextByte()&&!isChar(buf[ptr])){
        ptr++;
      }
      return hasNextByte();
    }
    public String next(){
      if(!hasNext()){
        throw new NoSuchElementException();
      }
      StringBuilder sb=new StringBuilder();
      int b=readByte();
      while(isChar(b)){
        sb.appendCodePoint(b);
        b=readByte();
      }
      return sb.toString();
    }
    public long nextLong(){
      if(!hasNext()){
        throw new NoSuchElementException();
      }
      long res=0;
      int b=readByte();
      boolean minus=false;
      if(b=='-'){
        minus=true;
        b=readByte();
      }
      if(b<'0'||'9'<b){
        throw new NumberFormatException();
      }
      while(true){
        if('0'<=b&&b<='9'){
          res*=10;
          res+=b-'0';
        }else if(b==-1||!isChar(b)){
          return minus?-res:res;
        }else{
          throw new NumberFormatException();
        }
        b=readByte();
      }
    }
    public int nextInt(){
      long nl=nextLong();
      if(nl<Integer.MIN_VALUE||Integer.MAX_VALUE<nl){
        throw new NumberFormatException();
      }
      return (int) nl;
    }
  }
  static int n;
  static int m;
  static int q;
  static int[] ary;
  static int[] a;
  static int[] b;
  static int[] c;
  static int[] d;
  static int max=0;
  public static void main(String[] args){
    Scnr sc=new Scnr();
    n=sc.nextInt();
    m=sc.nextInt();
    q=sc.nextInt();
    a=new int[q];
    b=new int[q];
    c=new int[q];
    d=new int[q];
    for(int i=0;i<q;i++){
      a[i]=sc.nextInt()-1;
      b[i]=sc.nextInt()-1;
      c[i]=sc.nextInt();
      d[i]=sc.nextInt();
    }
    ary=new int[n];
    calc(0);
    System.out.println(max);
  }
  static void calc(int p){
//    System.err.println(p);
    if(p<n){
      for(ary[p]=(p==0?1:ary[p-1]);ary[p]<=m;ary[p]++){
        calc(p+1);
      }
    }else{
//      System.err.println(Arrays.toString(ary));
      int ten=0;
      for(int i=0;i<q;i++){
        if(ary[b[i]]-ary[a[i]]==c[i]){
          ten=ten+d[i];
        }
      }
      max=Math.max(ten,max);
    }
  }
}

Measured memory_bytes: 33720
#include <bits/stdc++.h>
#include <sstream>
#include <iomanip>
#define ll long long
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define vi vector <ll> 
#define qu queue <ll>
#define min_3(a,b,c) min(a,min(b,c))
#define max_3(a,b,c) max(a,max(b,c))
#define nout(ans) cout << (ans) << "\n"
#define sout(ans) cout << (ans) << " "
using namespace std;

/*
Decimal Places: cout << fixed << setprecision(n) << ans << endl

String to integer:
stringstream dark(s);
int x = 0; dark >> x;
*/

bool compare(const pair<int, int>&i, const pair<int, int>&j)
{
    return i.second < j.second;
}


void solve()
{
    int k; string s; cin >> k >> s;
    if (s.size()<=k) nout(s);
    else {
        for (int i=0; i<k; i++) {
            cout<<s[i];
        }
        cout<<"..."<<endl;
    }
}

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

Measured memory_bytes: 3660
import java.util.Scanner;
//import java.util.Arrays;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int r = sc.nextInt();
		int d = sc.nextInt();
		int x = sc.nextInt();
		int[] xArray = new int[10];
		xArray[0] = r * x - d;
		for(int i=1; i<10; i++){
			xArray[i] = r * xArray[i-1] - d;
		}
		for(int a : xArray){
			System.out.println(a);
		}
	}
}


Measured memory_bytes: 35568
#include <iostream>
#include <vector>
#include <bitset>

using namespace std;

unsigned long long f(unsigned long long x, const vector<unsigned long long> &A) {
	unsigned long long out = 0;
	bitset<40> a(x);
	for(auto &y: A) {
		bitset<40> b(y);
		b ^= a;
		out += b.to_ullong();
	}
	return out;
}

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

	//10^12 < 2^40

	bitset<40> k(K);

	vector<unsigned long long> A(N);
	for(auto &x: A) cin >> x;

	vector<int> c(40);
	for(auto &&x: A) {
		bitset<40> b(x);
		for(int i = 0; i < 40; i++) {
			if(b[i]) c[i]++;
		}
	}


	bitset<40> x(0);
	for(int i = 0; i < 40; i++) {
		if(c[i] <= N / 2) x[i] = true;
	}

	//cout << k << endl;
	//cout << x << endl;
	bool flag = false;
	for(int i = 39; i >= 0; i--) {
		if(flag == true) continue;
		if(k[i] == false) x[i] = false;
		if(k[i] == true && x[i] == false) flag = true;
	}

	//cout << x << endl;
	// f(X) = sum (X ^ A_i)
	// MAXとなるのはX^A_iが可能な限り11111...111となるとき

	cout << f(x.to_ullong(), A) << endl;
}


Measured memory_bytes: 1152
#include<stdio.h>
int main(){
	int n,ai,bi,i,k,c;
	scanf("%d",&n);
	scanf("%d",&k);
	for(i=0;i<k;i++){
		scanf("%d%d",&ai,&bi);
		if(n+1-ai<ai)ai=n+1-ai;
		if(n+1-bi<bi)bi=n+1-bi;
		if(ai>bi)c=(bi-1)%3+1;
		else c=(ai-1)%3+1;
		printf("%d\n",c);
	}
	return 0;
}


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

int const N = 100;
int fr[N][N];
char s[N];

void ad(){
	scanf("%s", s);
	ll a = 0, b = 0;
	int i = 0;
	while (s[i] && s[i] != '.')a = 10 * a + s[i] - '0', ++i;
	int z = 100000000;
	if (s[i] == '.'){
		++i;
		while (s[i])b += z * (s[i] - '0'), ++i, z /= 10;
	}
	a = a * 1000000000 + b;
	int x = 0, y = 0;
	while (!(a & 1))++x, a >>= 1;
	while (a % 5 == 0)++y, a /= 5;
	++fr[x][y];
}

int main(){
	int n;
	scanf("%d", &n);
	f(i, 0, n)ad();
	ll an = 0;
	f(i, 0, N)f(j, 0, N)if (fr[i][j]){
		if (i << 1 >= 18 && j << 1 >= 18)an += (ll)fr[i][j] * (fr[i][j] - 1);
		f(k, 0, N)f(w, 0, N)if (!(i == k && j == w) && fr[k][w] && i + k >= 18 && j + w >= 18)an += (ll)fr[i][j] * fr[k][w];
	}
	printf("%lld\n", an >> 1);
}

Measured memory_bytes: 3832
import java.io.IOException;
import java.io.InputStream;
import java.util.*;

public class Main {

    public static void main(String[] args) {
        FastScanner fs = new FastScanner();
        int D = fs.nextInt();
        int N = fs.nextInt();

        if (D == 0) {
            if (N == 100) {
                System.out.println(101);
            }
            else {
                System.out.println(N);
            }
        }
        else if (D == 1) {
            if (N == 100) {
                System.out.println(10100);
            }
            else {
                System.out.println(N*100);
            }
        }
        else {
            if (N == 100) {
                System.out.println(1010000);
            }
            else {
                String s = N + "0000";
                System.out.println(Integer.parseInt(s));
            }
        }
    }
}

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;

    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }

    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}

    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }

    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }

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




Measured memory_bytes: 35960
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
main(){
    ll A,B,C,D;
    cin >> A >> B >> C >> D;
    while(A){
        /*
        (A + xD) / B >= C
        A + xD >= C * B
        xD >= C * B - A
        x >= (C * B - A)/D

        (A + xD) / (B + y) = C

        */
        if(A >= B * C)cout << 0 << endl;
        else cout << (C * B - A + D - 1) / D << endl;
        cin >> A >> B >> C >> D;
    }
}


Measured memory_bytes: 3072
#include<bits/stdc++.h>
#include<numeric>
#include<cassert>
//#include <boost/multiprecision/cpp_int.hpp>
#define ll long long int
#define CON 100010
const long long mod=1e9+7;
const int INF=1001001001;
//const int inf=100000;
//const ll ful=1e18;
using namespace std;
//namespace mp = boost::multiprecision;
int main() 
{
	int n;
	cin>>n;
	string a;
	cin>>a;
	decltype(a)::iterator itr=unique(a.begin(),a.end());
	a.erase(itr,a.end());
	cout<<a.size()<<endl;
	return 0;
}

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

using namespace std;

#define F first
#define S second
#define modulo ll (1e9 + 7)

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

void init(){
    cin.tie(0);
    cin.sync_with_stdio(0);
}

const int N = 59, M = 5e3 + 9, OO = 0x3f3f3f3f;
const ll llOO = 0x3f3f3f3f3f3f3f3f;

int main(){
    init();

    string a, b;    cin >> a >> b;

    if(a == b)  return cout << "EQUAL", 0;
    if(a.size() > b.size()) return cout << "GREATER", 0;
    if(b.size() > a.size()) return cout << "LESS", 0;


    for(int i = 0;i < a.size();i++){
        if(a[i] > b[i]) return cout << "GREATER", 0;
        if(b[i] > a[i]) return cout << "LESS", 0;
    }

}

Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
using namespace std;
typedef long long ll;
const int maxn=110;
template <typename Tp> inline int getmin(Tp &x,Tp y){return y<x?x=y,1:0;}
template <typename Tp> inline int getmax(Tp &x,Tp y){return y>x?x=y,1:0;}
template <typename Tp> inline void read(Tp &x)
{
    x=0;int f=0;char ch=getchar();
    while(ch!='-'&&(ch<'0'||ch>'9')) ch=getchar();
    if(ch=='-') f=1,ch=getchar();
    while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
    if(f) x=-x;
}
int n,a[maxn],vis[maxn];
int check()
{
	if(a[n]>=n) return 0;
	if(a[1]!=((a[n]+1)>>1)) return 0;
	for(int i=1;i<=n;i++) vis[a[i]]=1;
	for(int i=a[1];i<=a[n];i++) if(!vis[i]) return 0;
	if(~a[n]&1)
	{
		if(a[2]==a[1]) return 0;
	}
	else
	{
		if(a[1]!=a[2]) return 0;
		if(a[1]==a[2]&&a[1]==a[3]) return 0;
	}
	return 1;
}
int main()
{
	read(n);
	for(int i=1;i<=n;i++) read(a[i]);
	sort(a+1,a+n+1);
	if(check()) puts("Possible");
	else puts("Impossible");
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <fstream>
using namespace std;
const int nmax=105;
int n,a[nmax],ap[nmax],req[nmax];
int ok,i,mx;
int main()
{
   // freopen("data.in","r",stdin);
    cin>>n;
    for(i=1;i<=n;i++)
        {cin>>a[i];mx=max(mx,a[i]);ap[a[i]]++;}
    if(mx==1&&n!=2)
    {
        cout<<"Impossible";
        return 0;
    }
    for(i=(mx+1)/2;i<=mx;i++)
        req[i]=2;
    if(mx%2==0)
        req[mx/2]=1;
    ok=1;
    for(i=1;i<=n;i++)
        if(ap[i]<req[i])
             ok=0;
    for(i=1;i<(mx+1)/2;i++)
        if(ap[i])
            ok=0;
    if(mx%2==0&&ap[mx/2]>1)
        ok=0;
    if(mx%2==1&&ap[(mx+1)/2]>2)
        ok=0;
    if(ok) cout<<"Possible";
    else cout<<"Impossible";
    return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;

class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String strNum = "";
		ArrayList<String> squea = new ArrayList<String>();
		while (true) {
			strNum = br.readLine();
			if ("0 0".equals(strNum)) {
				break;
			}
			for (int i = 0; i < Integer.parseInt(strNum.split(" ")[0]); i++) {
				String line = "";
				if ((i % 2) == 0) {
					for (int j = 0; j < Integer.parseInt(strNum.split(" ")[1]); j++) {
						if ((j % 2) == 0) {
							line += "#";
						} else {
							line += ".";
						}
					}
				} else {
					for (int j = 0; j < Integer.parseInt(strNum.split(" ")[1]); j++) {
						if ((j % 2) == 0) {
							line += ".";
						} else {
							line += "#";
						}
					}
				}
				squea.add(line);
			}
			squea.add("");
		}
		for (int i = 0; i < squea.size(); i++) {
			System.out.println(squea.get(i));
		}
	}

}

Measured memory_bytes: 61016
#include <iostream>
#include <array>
#include <vector>
#include <iomanip>
#include <string>
#include <cmath>
#include <array>
#include <algorithm>
#include <queue>
#include <map>
using namespace std;
const int  INF=10e7;

typedef  pair<int,int> P;

int main(){
    int we,hn,n;
    cin>>we>>hn>>n;
    int ww=0,hs=0;
    
    for(int i=0;i<n;++i){
        int x,y,a;
        cin>>x>>y>>a;
        if(a==1){
            ww=max(ww,x);
        }
        else if(a==2){
            we=min(we,x);
        }
        else if(a==3){
            hs=max(hs,y);
        }
        else if(a==4){
            hn=min(hn,y);
        }
    }
    cout<<max((hn-hs),0)*max(0,(we-ww))<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#include <numeric>
#include <fstream>
using namespace std;
typedef long long ll;

#define _ { \
	ios_base::sync_with_stdio(false); \
    cin.tie(NULL); \
}


int main(){
   _;
   int x,y,a,b,c;cin>>x>>y>>a>>b>>c;
   vector<ll> p(a),q(b),r(c),v,vv;
   for(int i=0;i<a;i++)cin>>p[i];
   for(int i=0;i<b;i++)cin>>q[i];
   for(int i=0;i<c;i++)cin>>r[i];
   sort(p.rbegin(),p.rend());
   sort(q.rbegin(),q.rend());
   sort(r.rbegin(),r.rend());
   for(int i=0;i<x;i++)v.push_back(p[i]);
   for(int i=0;i<y;i++)v.push_back(q[i]);
   for(int i=0;i<c;i++)v.push_back(r[i]);
   sort(v.rbegin(),v.rend());
   ll ans=0;
   for(int i=0;i<x+y;i++)ans+=1ll*v[i];
   cout<<ans;
   
}

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

using namespace std;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n, a[100];
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a, a + n);
  cout << a[n - 1] - a[0] << '\n';
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
void __print(int x) {cout << x;}
void __print(long x) {cout << x;}
void __print(long long x) {cout << x;}
void __print(unsigned x) {cout << x;}
void __print(unsigned long x) {cout << x;}
void __print(unsigned long long x) {cout << x;}
void __print(float x) {cout << x;}
void __print(double x) {cout << x;}
void __print(long double x) {cout << x;}
void __print(char x) {cout << '\'' << x << '\'';}
void __print(const char *x) {cout << '\"' << x << '\"';}
void __print(const string &x) {cout << '\"' << x << '\"';}
void __print(bool x) {cout << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cout << '{'; __print(x.first); cout << ','; __print(x.second); cout << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cout << '{'; for (auto &i: x) cout << (f++ ? "," : ""), __print(i); cout << "}";}
void _print() {cout << "\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cout << ", "; _print(v...);}
#define debug(x...) cout << #x << " = "; _print(x)
typedef long long ll; typedef vector<int> vi; typedef vector<ll> vll;
#define rep(i,a,b) for (int i = (a); i < (b); ++i)
#define per(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define all(x) begin(x), end(x)
#define mp make_pair 
#define pb push_back
#define ff first
#define ss second
#define fast ios_base::sync_with_stdio(NULL);cin.tie(NULL);cout.tie(NULL)
#define ld long double

int solve(){
	int a, b, c, d;
	cin>> a>> b>> c>> d;
	int cnt = 1;
	while(a > 0 and  c > 0){
		if(cnt%2)
			c -= b;
		else
			a -= d;
		cnt++;
	}
	if(cnt%2 == 0)
		cout<< "Yes";
	else
		cout<< "No";
	return 0;
}
 
int main()
{
	fast;
	int t = 1;
	//cin>> t;
	while(t--){  
		solve();
	}
	return 0;
}
//upper_bound returns an iterator pointing to the 
//first element in the range [first,last) which has a value greater than ‘val’

Measured memory_bytes: 3656
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,i;
	long long ans=0;
	cin>>n;
	vector<int>a(n);
	vector<int>b(n);
	vector<int>c(n);
	for(i=0;i<n;i++) cin>>a[i];
	for(i=0;i<n;i++) cin>>b[i];
	for(i=0;i<n;i++) cin>>c[i];
	sort(a.begin(),a.end());
	sort(c.begin(),c.end());
	for(int i=0;i<n;i++){
		long long j=lower_bound(a.begin(),a.end(),b[i])-a.begin();
    	long long k=upper_bound(c.begin(),c.end(),b[i])-c.begin();
    	ans+=j*(c.size()-k);
	}
	cout<<ans;
	return 0;
}

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

typedef long long ll;

void solve() {
    ll N, K, ans = 0;
    cin >> N >> K;
    if (K == 0) ans = N * N;
    else for (ll b = K + 1; b <= N; b++) {
        ans += (b - K) * (N / b);
        if (N % b - K + 1 > 0) ans += N % b - K + 1;
    }
    cout << ans << endl;
    return;
}

int main() {
    solve();
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
static const int N=1000;

int lcs(string X,string Y){
  int c[N+1][N+1];
  int m=X.size();
  int n=Y.size();
  int maxl=0;
  X=' '+X;
  Y=' '+Y;
  for(int i=1;i<=m;i++)c[i][0]=0;
  for(int j=0;j<=n;j++)c[0][j]=0;
  for(int i=1;i<=m;i++){
    for(int j=1;j<=n;j++){
      if(X[i]==Y[j]){
        c[i][j]=c[i-1][j-1]+1;
      }else{
        c[i][j]=max(c[i-1][j],c[i][j-1]);
      }
      maxl=max(maxl,c[i][j]);
    }
  }
  return maxl;
}
int main(){
  string s1,s2;
  int n; cin>>n;
  for(int i=0;i<n;i++){
    cin>>s1>>s2;
    cout<<lcs(s1,s2)<<endl;
  }
  return 0;
}

Measured memory_bytes: 7036
// abc058_b_∵∴∵.cpp : コンソール アプリケーションのエントリ ポイントを定義します。
//


#include <iostream>
#include <string>
using namespace std;

int main()
{
	string o, e;
	cin >> o >> e;

	int i;
	for (i = 0; o[i]; i++) {
		if(o[i]) cout << o[i];
		if(e[i]) cout << e[i];
	}
	cout << endl;

	return 0;
}




Measured memory_bytes: 256