akhauriyash/Code-Regression huggingface dataset:
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class Main {

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

		// 整数の入力
		int a1 = sc.nextInt();
		int b1 = sc.nextInt();
		int a2 = sc.nextInt();
		int b2 = sc.nextInt();
		int a3 = sc.nextInt();
		int b3 = sc.nextInt();

		ArrayList<Integer> aryPath = new ArrayList<Integer>();

		aryPath.add(a1);
		aryPath.add(a2);
		aryPath.add(a3);
		aryPath.add(b1);
		aryPath.add(b2);
		aryPath.add(b3);

		ArrayList<Integer> aryCnt = new ArrayList<Integer>();

		aryCnt.add(Collections.frequency(aryPath, 1));
		aryCnt.add(Collections.frequency(aryPath, 2));
		aryCnt.add(Collections.frequency(aryPath, 3));
		aryCnt.add(Collections.frequency(aryPath, 4));

		if (Collections.frequency(aryCnt, 2) == 2) {
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}

		sc.close();
	}
}


Measured memory_bytes: 21844
#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#if __cplusplus >= 201103L
#include <unordered_map>
#include <unordered_set>
#endif
#include <vector>
#define lson rt << 1, l, mid
#define rson rt << 1 | 1, mid + 1, r
#define LONG_LONG_MAX 9223372036854775807LL
#define pblank putchar(' ')
#define ll LL
#define fastIO ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int, int> P;
int n, m, k;
const int maxn = 1e5 + 10;
template <class T>
inline T read()
{
    int f = 1;
    T ret = 0;
    char ch = getchar();
    while (!isdigit(ch))
    {
        if (ch == '-')
            f = -1;
        ch = getchar();
    }
    while (isdigit(ch))
    {
        ret = (ret << 1) + (ret << 3) + ch - '0';
        ch = getchar();
    }
    ret *= f;
    return ret;
}
template <class T>
inline void write(T n)
{
    if (n < 0)
    {
        putchar('-');
        n = -n;
    }
    if (n >= 10)
    {
        write(n / 10);
    }
    putchar(n % 10 + '0');
}
template <class T>
inline void writeln(const T &n)
{
    write(n);
    puts("");
}
template <typename T>
void _write(const T &t)
{
    write(t);
}
template <typename T, typename... Args>
void _write(const T &t, Args... args)
{
    write(t), pblank;
    _write(args...);
}
template <typename T, typename... Args>
inline void write_line(const T &t, const Args &... data)
{
    _write(t, data...);
    puts("");
}
map<string, int> mp;
int main(int argc, char const *argv[])
{
#ifndef ONLINE_JUDGE
    // freopen("in.txt", "r", stdin);
    // freopen("out.txt", "w", stdout);
#endif
    mp["SAT"] = 1;
    mp["SUN"] = 7;
    mp["MON"] = 6;
    mp["TUE"] = 5;
    mp["WED"] = 4;
    mp["THU"] = 3;
    mp["FRI"] = 2;
    string s;
    cin >> s;
    cout << mp[s];
    return 0;
}

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


int main() {

    int n, a;
    cin >> n >> a;
    if (n % 500 <= a) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int n;
int mx=-1;

int main()

{
	ios::sync_with_stdio(false);
	cin>>n;
	for (int i=1;i<=n;i++){
		int x;
		cin>>x;
		if (mx-x>=2){
			cout<<"No"<<endl;
			return 0;
		}
		mx=max(mx,x);
	}
	cout<<"Yes"<<endl;
	return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC target ("avx2")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

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

	int A, B;
	cin >> A >> B;

	co(A * B);

	Would you please return 0;
}

Measured memory_bytes: 3664
N = int(input())
F = [list(map(int,input().split())) for i in range(N)]
P = [list(map(int,input().split())) for i in range(N)]

ans = -float('inf')
for k in range(1,1<<10):
    tmp = 0
    for fs,ps in zip(F,P):
        cnt = 0
        for b in range(10):
            if (k>>b)&1 and fs[b]:
                cnt += 1
        tmp += ps[cnt]
    ans = max(ans, tmp)
print(ans)

Measured memory_bytes: 3064
using System;

namespace AtCoderDeverta2019A
{
    class Program
    {
        static void Main(string[] args)
        {
            int ans = 0;

            string[] s = Console.ReadLine().Split(' ');

            int N = int.Parse(s[0]);
            int M = int.Parse(s[1]);

            ans = N - M + 1;

            Console.WriteLine(ans.ToString());
        }
    }
}


Measured memory_bytes: 13140
#include <iostream>

using namespace std;

bool recursive(int left, int right, int* list, int index)
{
	int next = list[index];

	if(index == 9)
	{
		if(next <= left && next <= right)
			return false;
		return true;
	}

	if(left < next)
		if(recursive(next, right, list, index+1))
			return true;
	if(right < next)
		if(recursive(left, next, list, index+1))
			return true;

	return false;
}

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

	while( n-- > 0 )
	{
		int list[10];
		for(auto& n : list)
			cin >> n;

		if( recursive(0, 0, list, 0) )
			cout << "YES" << endl;
		else
			cout << "NO" << endl;
	}

	return 0;
}

Measured memory_bytes: 1148
N=int(input())
S = []
for _ in range(N):
    S.append(input())
a=0
b=0
c=0
d=0
for i in S:
  if i=='AC':
    a+=1
  elif i=='WA':
    b+=1
  elif i=='TLE':
    c+=1
  else:
    d+=1
print('AC x '+str(a))
print('WA x '+str(b))
print('TLE x '+str(c))
print('RE x '+str(d))




Measured memory_bytes: 16332
#include <stdio.h>
int main(void)
{
  int  d,s,t;
  scanf("%d%d%d", &d,&t,&s);
  if(d%s==0){
    if(t>=d/s)printf("Yes");
    else printf("No");
  }else{
    if(t>d/s) printf("Yes");
    else printf("No");
  }  
  return 0;
}


Measured memory_bytes: 1736
while True:
    n = int(input())
    if n == 0:
        break

    vote = list(map(str, input().split()))
    res = [0 for i in range(26)]

    for i, per in enumerate(vote):
        res[ord(per) - ord("A")] += 1
        sres = sorted(res, reverse = True)
        if sres[0] - sres[1] > n - i - 1:
            win = chr(res.index(sres[0]) + ord("A"))
            print(win, i + 1)
            break

        if i == n - 1:
            print("TIE")


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

using namespace std;

typedef long long ll;

int main(){
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  ll N, C; cin >> N >> C;
  ll x[N+2], v[N+2];
  ll score[N+2], revscore[N+2];
  ll max_score[N+2], max_revscore[N+2];
  max_score[0] = 0, max_revscore[N+1] = 0;
  for(int i=1;i<=N;i++){
    cin >> x[i] >> v[i];
  }
  score[0] = 0;
  x[0] = 0;
  for(int i=1;i<=N;i++){
    score[i] = score[i-1] + v[i] - (x[i] - x[i-1]);
    max_score[i] = max(score[i], max_score[i-1]);
  }
  /*
  for(int i=1;i<=N;i++){
    cout << i << " " << max_score[i] << endl;
  }
  */
  revscore[N+1] = 0;
  x[N+1] = C;
  for(int i=N;i>=1;i--){
    revscore[i] = revscore[i+1] + v[i] - (x[i+1] - x[i]);
    max_revscore[i] = max(revscore[i], max_revscore[i+1]);
  }
  /*
  cout << "max_revscore is" << endl;
  for(int i=1;i<=N;i++){
    cout << i << " " << max_revscore[i] << endl;
  }
  */
  ll ans = 0;
  // i=0, i=N
  for(int i=0;i<=N;i++){
    ll tmp = max(max_score[i], max_score[i] + max_revscore[i+1] - x[i]);
    ans = max(ans, tmp);
  }
  for(int i=N;i>=1;i--){
    ll tmp = max(max_revscore[i], max_revscore[i] + max_score[i-1] - (C - x[i]));
    ans = max(ans, tmp);
  }
  cout << ans << endl;
}

Measured memory_bytes: 4992
n, x = map(int, input().split())
a = list(map(int, input().split()))

a.sort()

ans = 0
i = 0

for i in a:
    if i > x:
        x = 0
        break
    else:
        x -= i
        ans += 1

if x != 0 and ans != 0:
    ans -= 1

print(ans)


Measured memory_bytes: 3060
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include <cmath>

using namespace std;
const long long INF = (long long) (1e18)+1;

int main() {
  string s;
  cin >> s;
  if (s[2] == s[3] && s[4] == s[5]) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}

Measured memory_bytes: 256
L = 100
@memo = Array.new(9) {Array.new(101) {[]}}

def solve(num, start, sum)
  return 0 if sum < 0 or start > L
  return (start <= sum and sum <= L) ? 1 : 0 if num == 1
  a = @memo[num - 1][start][sum]
  return a if a
  co = 0
  lim = [L, sum].min
  (start..lim).each do |i|
    co += solve(num - 1, i + 1, sum - i)
  end
  @memo[num - 1][start][sum] = co
end
  
until (a = $<.gets.split.map(&:to_i)) == [0, 0]
  puts solve(a.first, 0, a.last)
end


Measured memory_bytes: 12616
import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

A = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]

K = ir()
print(A[K-1])


Measured memory_bytes: 3060
#include "bits/stdc++.h"
using namespace std;

//諸機能
#pragma region MACRO 
#define putans(x)  std::cerr << "[ answer ]: " ; cout << (x) << endl
#define dputans(x) std::cerr << "[ answer ]: "; cout << setprecision(27) << (double)(x) << endl
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define RREP(i,a,n) for(int i=(int)(n-1); i>= a; i--)
#define rep(i,n) REP(i,0,n)
#define rrep(i,n) RREP(i,0,n)
#define all(a) begin((a)),end((a))
#define mp make_pair
#define exist(container, n) ((container).find((n)) != (container).end())
#define equals(a,b) (fabs((a)-(b)) < EPS)
#ifdef _DEBUG //ファイルからテストデータを読み込む
std::ifstream ifs("data.txt");
#define put ifs >>
#else //ジャッジシステムでいい感じにやる
#define put cin >>
#endif
#pragma endregion
//デバッグなどの支援
#pragma region CODING_SUPPORT
#ifdef _DEBUG
#define dbg(var0) { std::cerr << ( #var0 ) << "=" << ( var0 ) << endl; }
#define dbg2(var0, var1) { std::cerr << ( #var0 ) << "=" << ( var0 ) << ", "; dbg(var1); }
#define dbg3(var0, var1, var2) { std::cerr << ( #var0 ) << "=" << ( var0 ) << ", "; dbg2(var1, var2); }
#define dbgArray(a,n) {std::cerr << (#a) << "=";  rep(i,n){std::cerr <<(a[i])<<",";} cerr<<endl;} 
#else
#define dbg(var0) {}
#define dbg2(var0, var1) {}
#define dbg3(var0, var1, var2) {}
#define dbgArray(a,n) {}
#endif 
#pragma endregion 
//typedef（書き換える、書き足す可能性ある）
#pragma region TYPE_DEF
typedef long long ll;
typedef pair<int, int> pii; typedef pair<string, string> pss; typedef pair<int, string>pis;
typedef vector<string> vs; typedef vector<int> vi;
#pragma endregion
//諸々の定数(書き換える可能性ある)
#pragma region CONST_VAL
#define PI (2*acos(0.0))
#define EPS (1e-10)
#define MOD (ll)(1e9 + 7)
#define INF (ll)(2*1e9)
#pragma endregion

int main() {
	int n; put n;
	vi l(2*n); rep(i, 2*n) put l[i];
	sort(all(l));
	ll ret = 0;
	rep(i, n) {
		ret += min(l[2 * i], l[2 * i + 1]);
	}
	putans(ret);
END:
	return 0;
}

//
//vi v;
//vi w; ;
//ll nz1() {
//	return 0;
//}
//
//ll nz2() {
//	ll dp[201][1000*200+1];
//
//}
//
//ll nz3() {
//
//}
//	int n, wkazu; put n >> wkazu;
//	v.resize(200); 
//	w.resize(200);
//	rep(i, n) {
//		put v[i] >> w[i];
//	}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <stdio.h>
#include<iostream>
#include<cstdio>
#include<bitset>
#include<algorithm>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<string>
#include<string.h>
#include<cmath>
#include<utility>
#include<functional>
#include<map>
#include<set>
#include<cctype>
#include<fstream>
#include <numeric>
#include <iomanip>
#include <cstring> 
using namespace std;
using ll=long long;

#define FOR(i, a, b) for( int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for( int i=(a);i>=(b);i--)
#define LFOR(i, a, b) for( long long int i=(a);i<=(b);i++)
#define LRFOR(i, a, b) for(long long int i=(a);i>=(b);i--)
#define MOD 1000000007
#define LLONG_MAXs 9223372036854775800

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

 
bool isPrimeNum( ll x ){ // 素数である場合 true を返す
  if( x <= 1 ){ // 1以下である場合は素数でないことがすぐにわかる
    return false;
  }
  // sqrt( double型 ) は引数の平方根を double型で返すので、int型でキャスト
  int n = (int)sqrt( (double)x );
  for( int i = 2; i <= n; i++ ){
    if( x % i == 0 ){ // 割り切る整数がある場合、即判定終了
      return false;
    }
  }
  return true; // 割り切る整数がない場合、素数である
}

constexpr ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
constexpr ll lcm(ll a,ll b){return a*b/gcd(a,b);}
constexpr ll abs(ll a,ll b){
if(a>=b)return a-b;
if(a<b)return b-a;
}
constexpr ll min(ll a,ll b){
if(a>=b)return b;
if(a<b)return a;
}

constexpr ll max(ll a,ll b){
if(a>=b)return a;
if(a<b)return b;
}

int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

int main() {
  ll N,T;
  cin>>N>>T;
  ll t[N];
  ll ans =0;
  FOR(i,0,N-1){
    cin>>t[i];
  }

  FOR(i,1,N-1){
    ans =ans+ min(T,t[i]-t[i-1]);

  }
  ans=ans+T;


  cout <<ans<<endl;

  return 0;
}
 


Measured memory_bytes: 1792
# PD?D??P
t = list(input())
for i in range(len(t)):
  # そもそも違ったらスキップ
  if t[i] != "?":
    continue
  else:
    # ?---
    if i == 0:
      t[i] = "D"
      continue
    
    # ---?
    if i == len(t) - 1:
      t[i] = "D"
    else:
      # P?
      if t[i-1] == "P":
        t[i] = "D"
        continue

      # ?D
      if t[i+1] == "D":
        t[i] = "P"
        continue

      t[i] = "D"


print("".join(t))


Measured memory_bytes: 10912
#include<bits/stdc++.h>
using namespace std;
int main(){
	int N;cin>>N;
	vector<int> B(N);bool flag=true;
	for(int i=0;i<N;i++){
		cin>>B[i];
		if(B[i]>i+1){
			flag=false;
		}
	}if(!flag){
		cout<<-1<<endl;
		return 0;
	}vector<int> ans(N);
	for(int i=N-1;i>=0;i--){
		for(int j=i;j>=0;j--){
			if(B[j]==j+1){
				B.erase(B.begin()+j);
				ans[i]=j+1;
				break;
			}
		}
	}for(int i=0;i<N;i++){
		cout<<ans[i]<<endl;
	}
}

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

#define ll long long

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

	string s;
	cin >> s;

	if (s[2] == s[3] && s[4] == s[5])
		cout << "Yes";
	else
		cout << "No";
}


Measured memory_bytes: 256
# DP法でトライ
N = int(input())
A = list(map(int, input().split()))

# i 日目に、株の売却が終了した時点の所持金の最大値
dp = [0]*N
dp[0] = 1000

for i in range(1,N):
    for j in range(0,i):
        dp[i] = max(dp[i], dp[i-1],(dp[j]//A[j])*A[i]+dp[j]%A[j])

print(dp[-1])

Measured memory_bytes: 8980
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

int main() {
	int n, m, X, Y;
	cin >> n >> m >> X >> Y;
	vector<int> x(n), y(m);
	for (int i = 0; i < n; i++)
		cin >> x[i];
	for (int i = 0; i < m; i++)
		cin >> y[i];
	int zmin, zmax;
	int xmax = -101;
	for (int i = 0; i < n; i++)
		if (xmax < x[i])
			xmax = x[i];
	zmin = max(X + 1, xmax + 1);
	int ymin = 101;
	for (int i = 0; i < m; i++)
		if (ymin > y[i])
			ymin = y[i];
	zmax = min(Y, ymin);
	if (zmax - zmin >= 0)
		cout << "No War" << endl;
	else
		cout << "War" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
 
using namespace std;
 
#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
 
#define MOD 1000000007

int main(){
  int n;
  cin>>n;
  int mxa = -1;
  int mxb = -1;
  int mna = 325000;
  int mnb = 325000;
  int old_f,old_a,old_t,old_x,old_y;
  cin>>old_f>>old_a>>old_t>>old_x>>old_y;
  rep(i,1,n){
    int f,a,t,x,y;
    cin>>f>>a>>t>>x>>y;
    if(t==old_t&&a!=old_a){
      int l = (x-old_x)*(x-old_x)+(y-old_y)*(y-old_y);
      int ff = f-old_f;
      
      if(t==0){
        if(mxa<l){
          mxa = max(mxa,l);
          mna = ff;
        }
        else if(mxa==l){
          mna = min(mna,ff);
        }
      }
      else{
        if(mxb<l){
          mxb = max(mxb,l);
          mnb = ff;
        }
        else if(mxb==l){
          mnb = min(mnb,ff);
        }
      }
    }
    old_f = f;
    old_a = a;
    old_t = t;
    old_x = x;
    old_y = y;
  }
  if(mxa==-1){
    printf("-1 -1\n");
  }
  else{
    printf("%.8f %.8f\n",pow(mxa,0.5),mna/60.);
  }
  if(mxb==-1){
    printf("-1 -1\n");
  }
  else{
    printf("%.8f %.8f\n",pow(mxb,0.5),mnb/60.);
  }
  return 0;
}

Measured memory_bytes: 1244
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
int d[5];
int main()
{
	for(int i=1;i<=6;i++)
	{
		int x;
		scanf("%d",&x);
		d[x]++;
		if(d[x]>2)
		{
			printf("NO\n");
			return 0;
		}
	}
	printf("YES\n");
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#include <queue>
#define rep(i,cc,n) for(int i=cc;i<=n;++i)
#define drep(i,cc,n) for(int i=cc;i>=n;--i)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const long long INF = 1LL <<60;
typedef long long ll;
using namespace std;
 
ll gcd(ll a, ll b) {
    if (b==0) return a;
    else return gcd(b, a%b);
}
 
ll lcm(ll a, ll b) {
    return a * b / gcd(a, b);
}
 
ll choose2(ll n){
    return n*(n-1)/2;
}
 
int main() {
    int n,m,x;
    cin>>n>>m>>x;
    vector<int> a(m);
    rep(i,0,m-1) cin>>a[i];
    int cst1 = 0;
    int cst2 = 0;
    rep(i,0,m-1){
        if(a[i] < x) cst1++;
        else if(a[i] > x) cst2++;
    }
    cout<<min(cst1,cst2)<<endl;
    return 0;
}

Measured memory_bytes: 256
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def TUPLE(): return tuple(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7 
#mod = 998244353
from decimal import *
import numpy as np
#decimal.getcontext().prec = 10

N, L = MAP()
a = LIST()

for i in range(1, N):
	if L <= a[i]+a[i-1]:
		idx = i
		break
else:
	print("Impossible")
	exit()

print("Possible")
ans = list(range(1, idx)) + list(range(N-1, idx, -1)) + [idx]
print(*ans, sep="\n")

Measured memory_bytes: 38288
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const long long INF = 1e18;
# define len(x) ((int)(x).size())
# define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
# define reps(i, n) for(int i=1, i##_len=(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 foreps(i, m, n) for(int i = m;i < n;i++)
# define ALL(x) (x).begin(), (x).end()
# define rall(x) (x).rbegin(), (x).rend()
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main() {
    ll N, T; cin >> N >> T;
    vector<ll> t(N);
    rep(i, N) cin >> t[i];

    ll sum = T;
    rep(i, N - 1) {
        ll now = t[i + 1] - t[i];
        sum += min(T, now);
    }
    cout << sum << endl;
}

Measured memory_bytes: 4772
#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 a,b,T;
cin >> a >> b >> T;
int t = a,cnt = 0;
while(t < T + 0.5){
  cnt += b;
  t += a;
 
}
cout << cnt << endl;
}
  


Measured memory_bytes: 256
def isPrime(i):
    if i < 2:
        return False
    elif i == 2:
        return True
    elif i % 2 == 0:
        return False
    for j in range(3, int(i**0.5)+1, 2):
        if i % j == 0:
            return False
    return True

def inpl(): return list(map(int, input().split()))

Q = int(input())
# query = [inpl() for i in range(Q)]
N = 10 ** 5


prime = [True] * (N+1)
prime[0] = False
prime[1] = False
for i in range(2, N+1):
    if prime[i] is False:
        continue
    
    tmp = i * 2
    while tmp <= N:
        prime[tmp] = False
        tmp += i

dst = [0] * (N+1)
for i in range(1, N+1):
    dst[i] = dst[i-1] + int(prime[i] and prime[(i+1)//2])

# print(rsq.tree[rsq.bottom:rsq.bottom+10])
for _ in range(Q):
    l, r = inpl()
    print(dst[r]-dst[l-1])

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

int main(){
  int N, K;
  cin >> N >> K;
  int distance;
  for(int i = 0;i<N;i++){
    int x;
    cin >> x;
    if(x <= K - x){
      distance += x * 2;
    }
    else{
      distance += (K - x)*2;
    }
  }
  
  cout << distance <<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)


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

  int a,b,c,d;
  cin >> a >>  b >> c >> d;
  while(a>0 && c>0){
    c -= b;
    if(c<=0) {
      cout << "Yes" << endl;
      return 0;
    }
    a -= d;
  }
  cout << "No" << endl;
  return 0;
    

}


Measured memory_bytes: 3652
import java.util.*;
 
public class Main {
 
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String[] chars={"a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"};
        long output=1;
        long mod=1000000007;
        int n=sc.nextInt();
        String s=sc.next();
        for(int i=0;i<26;i++){
            output*=(long)(s.length()-s.replaceAll(chars[i],"").length()+1);
            output%=mod;
        }
        System.out.println(output==0?mod-1:output-1);
    }
}


Measured memory_bytes: 44628
package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	i, _ := strconv.Atoi(sc.Text())
	return i
}

func main() {
	n, cnt := 0, 0
	if sc.Scan() {
		n = nextInt()
	}
	for i := 0; i < n; i++ {
		if !sc.Scan() {
			break
		}
		if isPrime(nextInt()) {
			cnt++
		}
	}
	fmt.Println(cnt)
}

func isPrime(x int) bool {
	if x == 2 {
		return true
	} else if x < 2 || x%2 == 0 {
		return false
	}
	max := int(math.Sqrt(float64(x)))
	for i := 3; i < max+1; i = i + 2 {
		if x%i == 0 {
			return false
		}
	}
	return true
}



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

# include <ext/pb_ds/assoc_container.hpp>
# include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;
 
template<typename T> using ordered_set = tree <T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define _USE_MATH_DEFINES_
#define ll long long
#define ld long double
#define Accepted 0
#define pb push_back
#define mp make_pair
#define sz(x) (int)(x.size())
#define every(x) x.begin(),x.end()
#define F first
#define S second
#define lb lower_bound
#define ub upper_bound
#define For(i,x,y)  for (ll i = x; i <= y; i ++) 
#define FOr(i,x,y)  for (ll i = x; i >= y; i --)
#define SpeedForce ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
// ROAD to...                                                                                                                                                                                                                Red

inline void Input_Output () {
	//freopen(".in", "r", stdin);
   //freopen(".out", "w", stdout);
}

const double eps = 0.000001;
const ld pi = acos(-1);
const int maxn = 1e7 + 9;
const int mod = 1e9 + 7;
const ll MOD = 1e18 + 9;
const ll INF = 1e18 + 123;
const int inf = 2e9 + 11;
const int mxn = 1e6 + 9;
const int N = 6e5 + 123;                                          
const int M = 22;
const int pri = 997;
const int Magic = 2101;

const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, -1, 0, 1};
 
int n, m, k;
vector < int > g[N];
int u[N];
int p[N];
int l[N], r[N];
int tin[N], tout[N], timer;

void dep (int v, int pr = 0) {
	for (auto to : g[v]) if (to != pr) {
		l[to] = max(l[to], l[v] - 1);
		r[to] = min(r[to], r[v] + 1);
		dep(to, v);
	}
}

void up (int v, int pr) {
	for (auto to : g[v]) if (to != pr) {
		up(to, v);
	
		l[v] = max(l[v], l[to] - 1);
		r[v] = min(r[v], r[to] + 1);
	}
}

void dfs (int v, int pr = 0) {
	if (l[v] > r[v]) {
		cout << "No\n";
		exit(0);

	}

	for (int to : g[v]) if (to != pr) {
		if (p[to] == -inf) {
			if(l[to] <= p[v] - 1 && r[to] >= p[v] - 1) p[to] = p[v] - 1;
			else p[to] = p[v] + 1;
		}
		dfs(to, v);

		if (abs(p[v] - p[to]) > 1) {
			cout << "No\n";
			exit(0);
		}
	}
}

int main () {
	SpeedForce;
	cin >> n;

	for (int i = 1; i < n; i ++) {
		int l, r;
		cin >> l >> r;
		g[l].pb(r);
		g[r].pb(l);
	}

	cin >> k;

	for (int i = 1; i <= n; i ++) {
		p[i] = -inf;
		l[i] = -inf;
		r[i] = inf;
	}

	int rt = 1;
	for (int i = 1; i <= k; i ++) {
		int v, x;
		cin >> v >> x;
		rt = v;
		if (p[v] == -inf) r[v] = l[v] = p[v] = x;
		
		if(p[v] != x) {
			cout << "No\n";
			exit(0);
		}
		
	}

	dep(rt);
	up(rt, 0);
	dfs(rt);

	cout << "Yes\n";
	for (int i = 1; i <= n; i ++)
		cout << p[i] << '\n';

   	return Accepted;
}

// B...a

Measured memory_bytes: 32256
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <climits>
#include <cstdlib>
#include <vector>
#include <unordered_map> 
#include <iomanip>
using namespace std;
#define ALL(a) (a).begin(),(a).end()
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define INF (INT_MAX/3)
#define PSB push_back
#define PN 1000000007
typedef long long LL;
//#define int long long


//booooooooooooost
//#include <boost/multiprecision/cpp_int.hpp>
//#include <boost/multiprecision/cpp_dec_float.hpp>
//namespace mp = boost::multiprecision;	//多倍長整数(mp::cpp_int), 多倍長小数(mp::cpp_dec_float_100)



int inv_mod(int a, int m)
{
	int b, x, u, q, tmp;

	b = m; x = 1; u = 0;
	while (b > 0) {
		q = a / b;
		tmp = u; u = x - q * u; x = tmp;
		tmp = b; b = a - q * b; a = tmp;
	}

	return (x < 0) ? m + x : x;
}



signed main() {

	string w;
	cin >> w;
	vector<int> f;
	f.assign(26, 0);

	REP(i, w.size()) {
		f[w[i] - 'a']++;
	}

	bool flag = true;
	REP(i, 26) {
		if (f[i] % 2 == 1) flag = false;
	}
	cout << (flag ? "Yes" : "No") << endl;

	
	return 0;
}

Measured memory_bytes: 256
from numpy import cumsum
from collections import Counter
import math
def count(n,r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
n = int(input())
a = list(map(int,input().split()))
wa = list(cumsum(a))
wa.append(0)
c = Counter(wa)
keys = set(wa)
ans = 0
for i in keys:
    num = c[i]
    if num >= 2:
        ans += count(num,2)
    else:
        pass
print(ans)

Measured memory_bytes: 56696
a, b, c, k = list(map(int, input().split()))
sum = 0
if a > 0:
  if k - a > 0:
    sum += a
  else:
    sum += k
  k -= a
if b > 0 and k > 0:
  k -= b
if c > 0 and k > 0:
  sum -= k
print(sum)

Measured memory_bytes: 9152
n=input()
a=[[int(i) for i in raw_input().split()]for j in range(n)]
flag=0
for i in range(2,n):
    if a[i][0]==a[i][1] and a[i-1][0]==a[i-1][1] and a[i-2][0]==a[i-2][1]:
        flag=1
if flag:
    print "Yes"
else:
    print "No"


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

#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
const int MD = (int)1e9 + 7; typedef vector<ll> VL;
void dbg(){ cerr << "\n"; }  template <class T, class ...T2>
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }


int main()
{

	cin.tie(0); ios_base::sync_with_stdio(false);
	int n; ll ans=0;
	cin >>n;
	vector<pii> p(n);
	rep(i, n){
		cin >>p[i].first; p[i].second=i+1;
	}
	sort(p.rbegin(), p.rend());
	set<int> st;
	

	rep(i, n){
		int cid = p[i].second;
		st.insert(cid);
		int l1=0, l2=0;
		int r1=n+1, r2=n+1;
		
		auto it = st.find(cid);
		if(it != st.begin()){
			it--; l2= *it;
			if(it != st.begin()){ it--; l1 =*it;}
		}
		it = st.find(cid);
		it++;
		if(it != st.end()){
			r1= *it; it++;
			if(it != st.end()){ r2 =*it;}
		}
		ll a=cid-l2, b=l2-l1;
		ll c=r1-cid, d=r2-r1;
		ans += (a*d + b*c) * p[i].first;
		//dbg(i, p[i].first, l1,l2,r1,r2, a*d+b*c, ans);
	}
	cout << ans <<"\n";
	if(0){
		VI q(n);
		ll ans =0;
		rep(i, n) rep2(j, i+1, n){
			int mx=q[i], mx2=-1;
			rep2(k, i+1, j+1){
				if(q[k] > mx){
					mx2 = mx; mx = q[k];
				}else if(q[k] > mx2){
					mx2 = q[k];
				}
			}
			//dbg(i, j, mx,mx2);
			ans += mx2;
		}
		dbg("bfans=",ans);
	}

}


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

int main()
{
    int N, M;
    cin >> N >> M;
    vector<pair<int, int>> pos_s(N);
    for (int i = 0; i < N; i++)
    {
        cin >> pos_s.at(i).first >> pos_s.at(i).second;
    }
    vector<pair<int, int>> pos_c(M);
    for (int i = 0; i < M; i++)
    {
        cin >> pos_c.at(i).first >> pos_c.at(i).second;
    }
    
    for (int i = 0; i < N; i++)
    {
        int ai = pos_s.at(i).first, bi = pos_s.at(i).second;
        int mn = INT_MAX, res = 0;
        for (int j = 0; j < M; j++)
        {
            int cj = pos_c.at(j).first, dj = pos_c.at(j).second;
            int dis = abs(ai - cj) + abs(bi - dj);
            if (dis < mn)
            {
                mn = dis;
                res = j + 1;
            }
        }
        cout << res << endl;
    }
}

Measured memory_bytes: 256
from collections import deque

N = int(input())
A = list(map(int, input().split()))
A.sort()
d = deque(A)
if A[0] <= 0 and A[-1] >= 0:
    print(sum(map(abs, A)))
    while len(d) > 2:
        while d[1] < 0:
            x = d.pop()
            y = d.popleft()
            print(x, y)
            d.append(x - y)
        x = d.popleft()
        y = d.pop()
        if d:
            print(x, y)
        else:
            print(y, x)
        d.appendleft(x - y)
    if len(d) >= 2:
        print(d[1], d[0])

elif A[0] > 0:
    print(sum(A) - 2 * A[0])
    x = d.popleft()
    y = d.pop()
    if not d:
        print(y, x)
    else:
        print(x, y)
    d.appendleft(x - y)
    while len(d) > 2:
        x = d.popleft()
        y = d.pop()
        print(x, y)
        d.appendleft(x - y)
    if len(d) >= 2:
        print(d[1], d[0])
else:
    print(-sum(A) + 2 * A[-1])
    x = d.pop()
    y = d.popleft()
    print(x, y)
    d.append(x - y)
    while len(d) > 2:
        while d[1] < 0 and len(d) > 2:
            x = d.pop()
            y = d.popleft()
            print(x, y)
            d.append(x - y)
        x = d.pop()
        y = d.popleft()
        print(x, y)
        d.appendleft(x - y)
    if len(d) >= 2:
        print(d[1], d[0])


Measured memory_bytes: 14740
#include<iostream>
using namespace std;
int main()
{
    int N;

    cin >> N;

    if(N%2 == 1){
        cout << ((N+1)/2.000000)/N <<endl;
    }

    if(N%2 == 0){
        cout << 1/2.000000 <<endl;
    }

    
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
int main()
{
	int i=0,num;
	char str[1200],c='a';
	while(c!='\n'){
		scanf("%c",&c);
		str[i]=c;
		i++;
	}
	num=i;
	for(i=0;i<num;i++){
		if(97<=str[i]&&str[i]<=122){
			str[i]=str[i]-32;
		}else if(65<=str[i]&&str[i]<=90){
			str[i]=str[i]+32;
		}
	}
	i=-1;
	while(str[i++]!='\n'){
		if(str[i]=='\n')break;
		std::cout<<str[i];
	}
	std::cout<<std::endl;
	return 0;
}

Measured memory_bytes: 1144
S = input()
l = [0]*(len(S)+1)

for i in range(len(S)):
    if S[i] == '<':
        l[i+1] = l[i]+1

l = l[::-1]
S = S[::-1]

for i in range(len(S)):
    if S[i] == '>':
        l[i+1] = max(l[i]+1, l[i+1])

print(sum(l))

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

#define LL long long
typedef pair<int, int> pii;

template< typename T > inline void read(T &x)
{
    static char _c;
    static bool _f;

    x = 0;
    _f = 0;
    _c = getchar();

    while(_c < '0' || '9' < _c) {if(_c == '-') _f = true; _c = getchar();}
    while('0' <= _c && _c <= '9') {x = (x << 1) + (x << 3) + (_c & 15); _c = getchar();}
    if(_f) x = -x;
}

template < typename T > inline void Min(T &x, T y) {if(y < x) x = y;}
template < typename T > inline void Max(T &x, T y) {if(x < y) x = y;}


#define lowbit(x) ((x) & -(x))
#define lson l,mid,id<<1
#define rson mid+1,r,id<<1|1
#define ls id<<1
#define rs id<<1|1
#define MID(l,r) ((l)+(((r)-(l))>>1))
#define fi first
#define se second
#define mk make_pair
#define pb push_back

const int INF = 0x3f3f3f3f;
const int MOD = (int) 20050321;
const int maxn = (int) 2e5 + 20;
const int maxm = (int) 1000000 + 20;
const double pi = (double) acos(-1.0);
const double eps = (double) 1e-8;

inline int sig(double x) {return x < -eps ? -1 : eps < x;}
LL fp(LL a, LL n, LL m = MOD) {LL res = 1; for(; n; n >>= 1, a = a * a % m) if(n & 1) res = res * a % m; return res;}

int n, m;
char s[maxn];
int a[maxn], b[maxn];

struct Node
{
    int val, pre;
};
Node T[maxn << 2];

Node mer(const Node &x, const Node &y)
{
    if(x.val == y.val)
    {
        if(x.pre > y.pre) return x;
        return y;
    }
    else
    {
        if(x.val < y.val) return x;
        return y;
    }
}

void update(int pos, int val, int pre, int l, int r, int id)
{
    if(l == r)
    {
        T[id].val = val;
        T[id].pre = pre;
        return ;
    }

    int mid = MID(l, r);

    if(pos <= mid) update(pos, val, pre, lson);
    else update(pos, val, pre, rson);

    T[id] = mer(T[ls], T[rs]);
}

Node query(int L, int R, int l, int r, int id)
{
    if(L <= l && r <= R) return T[id];

    int mid = MID(l, r);

    if(R <= mid) return query(L, R, lson);
    if(mid < L) return query(L, R, rson);
    return mer(query(L, R, lson), query(L, R, rson));
}

void work()
{
    cin >>n >>m;
    cin >>s;
    reverse(s, s + n + 1);

    if(s[0] == '1' || s[n] == '1')
    {
        cout <<-1 <<endl;
        return ;
    }

    a[0] = 0;
    b[0] = 0;
    update(0, 0, 0, 0, n, 1);

    for(int i = 1; i <= n; i++)
    {
        if(s[i] == '1')
        {
            a[i] = INF;
            b[i] = 0;
        }
        else
        {
            Node it = query(max(0, i - m), i - 1, 0, n, 1);
            a[i] = it.val + 1;
            b[i] = it.pre;
        }

        update(i, a[i], i, 0, n, 1);
    }

    if(a[n] >= INF)
    {
        cout <<-1 <<endl;
        return ;
    }

    int x = n;
    while(x)
    {
        int px = b[x];
        cout <<x - px <<" ";
        x = px;
    }
    cout <<endl;
}

int main()
{
#ifdef yukihana0416
freopen("in.txt", "r", stdin);
//freopen("out.txt", "w", stdout);
#endif // yukihana0416
//    get_prime();
    int tc = 1;
//    read(tc);
    for(int ca = 1; ca <= tc; ca++)
    {
//        printf("Case #%d: ", ca);
        work();
    }
    return 0;
}


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

int main(){
  int N,K; cin >> N >> K;
  string S; cin >> S;
  S='1'+S;
  
  //逆直逆直、…の配列
  //最初逆立ちでなければrotate[0]=0;
  int rotate[100010]={};
  int cnt=0,ind=0;
  for(int i=0; i<N; i++){
    if(S[i]==S[i+1]){
      cnt++;
    }else{
      rotate[ind]=cnt;
      ind++;
      cnt=1;
    }
  }
  rotate[ind]=cnt;
  ind++; //要素数
  
  //直立の個数が入っている枠が連続K個になるように逆立ちさせてく
  //累積和
  int result=0;
  if(K>=ind/2){
    result=N;
  }else{
    int tmp=0;
    for(int i=0; i<2*K+1; i++){
      tmp+=rotate[i];
    }
    result=tmp;
    for(int i=0; i<ind/2-K; i++){
      tmp=(tmp-rotate[2*i]-rotate[2*i+1]+rotate[2*i+2*K+1]+rotate[2*i+2*K+2]);
      result=max(result,tmp);
    }
  }
  cout << result << endl;
}

Measured memory_bytes: 892
// È¥°É£¡Æ¤¿¨Çð! °ÑAC´ø»ØÀ´£¡
//      ¤Ø¡¡¡¡¡¡¡¡¡¡£¯|
// ¡¡¡¡/£Ü7¡¡¡¡¡¡ ¡Ï£ß/
// ¡¡ /¡¡©¦¡¡¡¡ £¯¡¡£¯								AC		AC		AC		AC
//    ©¦¡¡Z £ß,£¼¡¡£¯¡¡¡¡ /`©c						AC		AC		AC		AC
//    ©¦¡¡¡¡¡¡¡¡¡¡©c¡¡¡¡ /¡¡¡¡¡µ					AC		AC		AC		AC
// ¡¡Y¡¡¡¡¡¡¡¡¡¡`¡¡ /¡¡¡¡/  /						AC		AC		AC		AC
// ¡¡Øé¡ñ¡¡.¡¡¡ñ¡¡¡¡¡´¡¡/¡¡/						AC		AC		AC		AC
// ¡¡()¡¡ ¤Ø¡¡¡¡¡¡¡¡|¡¡£Ü¡´							AC		AC		AC		AC
// ¡¡¡¡>- ._¡¡ ¥£¡¡ ©¦ £¯£¯							AC		AC		AC		AC
// ¡¡ / ¤Ø¡¡¡¡ /¡¡/£¼| £Ü£Ü							AC		AC		AC		AC
// ¡¡ ©c_/¡¡¡¡(_£¯¡¡ ©¦£¯£¯							AC		AC		AC		AC
// ¡¡¡¡ 7¡¡¡¡¡¡¡¡¡¡¡¡¡¡|£¯							AC		AC		AC		AC
// ¡¡¡¡ £¾¨Dr£þ£þ`-¨D£ß/							AC		AC		AC		AC
//**************************************Accepted*****************************************//

#include<bits/stdc++.h>

#define all(x) x.begin(),x.end()
#define pb push_back
#define mp make_pair
#define Unique(x) x.erase(unique(all(x)),x.end());

#define CIN_FILE "input.txt"
#define COUT_FILE "output.txt"

#define Pig (OO)

using namespace std;

const int dx[]={-1,0,1,0};
const int dy[]={0,-1,0,1};

const int Days[]={-1,31,28,31,30,31,30,31,31,30,31,30,31};

inline int read()
{
	#define gc getchar
	int ans=0;
	bool f=1;
	char ch=gc();
	
	while(!isdigit(ch))f^=ch=='-',ch=gc();
	
	while(isdigit(ch))ans=((ans<<2)+ans<<1)+(ch^48),ch=gc();
	
	return f?ans:-ans;
	
	#undef gc
}

typedef long long ll;

int main(int argc, char const *argv[])
{
	ios::sync_with_stdio(false);
	
	int t;
	
	ll n,k;
	cin>>n>>k;
	ll ans=n%k;
	cout<<min(ans,k-ans);
	
	//printf("Time used = %.12f",(double)(clock())/CLOCKS_PER_SEC);
	return 0;
}

/*  GOD BLESS  */


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
const int inf=1<<30;
int W,H,N;
struct Point{
	int x,y;
	void read(){scanf("%d%d",&x,&y);}
	bool operator<(const Point&p)const{return y<p.y;}
}Ps[2][300010],Sd[300010],Su[300010];
int min(int a,int b){return a<b?a:b;}
int max(int a,int b){return a>b?a:b;}
int T[1<<20],tag[1<<20];
#define Def int o,int L,int R
#define Mid (L+R>>1)
#define Ls o<<1,L,Mid
#define Rs o<<1|1,Mid,R
void build(Def){
	T[o]=-inf;tag[o]=0;
	if(R-L>1)build(Ls),build(Rs);
}
void modify(Def,int i,int x){
	if(R-L==1)T[o]=x;
	else{
		if(i<Mid)modify(Ls,i,x);
		else modify(Rs,i,x);
		T[o]=max(T[o<<1],T[o<<1|1])-tag[o];
	}
}
void minus(Def,int l,int r,int x){
	//printf("mn [%d,%d) [%d,%d) %d\n",L,R,l,r,x);
	if(l==L&&r==R)T[o]-=x,tag[o]+=x;
	else{
		if(r<=Mid)minus(Ls,l,r,x);
		else if(l>=Mid)minus(Rs,l,r,x);
		else minus(Ls,l,Mid,x),minus(Rs,Mid,r,x);
		T[o]=max(T[o<<1],T[o<<1|1])-tag[o];
	}
}
/*
void dfs(Def,int a=0){
	if(R-L==1)printf("%d,",T[o]-a);
	else dfs(Ls,a+tag[o]),dfs(Rs,a+tag[o]);
}
*/
int solve(int l,int r,int yl,int yr,int d){
	if(r-l<2){
		Ps[d][l]=Ps[0][l];
		return max(W+max(Ps[0][l].y-yl,yr-Ps[0][l].y),max(Ps[0][l].x,W-Ps[0][l].x)+yr-yl);
	}
	int mid=l+r>>1,ymid=Ps[0][mid].y,ans=max(solve(l,mid,yl,ymid,!d),solve(mid,r,ymid,yr,!d));
	Point*P=Ps[d]+l,*Q=Ps[!d],*td=Sd,*tu=Su;
	*++td=(Point){0,yl};
	*++tu=(Point){0,yr};
	build(1,0,r-l+1);
	modify(1,0,r-l+1,0,yr-yl);
	//printf("y=(%d,%d,%d)\n",yl,ymid,yr);
	//dfs(1,0,r-l+1);printf("(%d)\n",T[1]);
	for(int i=l,j=mid,k=0;i<mid||j<r;k++){
		if(j==r||i<mid&&Q[i].x<Q[j].x){
			//printf("(%d,%d)\n",Q[i].x,Q[i].y);
			ans=max(ans,Q[i].x+T[1]);
			while(td>Sd&&td->y<Q[i].y){
				if(td-1>Sd&&td[-1].y<Q[i].y)minus(1,0,r-l+1,td->x,k+1,td[-1].y-td->y),--td;
				else minus(1,0,r-l+1,td->x,k+1,Q[i].y-td->y),td->y=Q[i].y;
			}
			*++td=(Point){k+1,yl};
			modify(1,0,r-l+1,k+1,yr-yl-Q[i].x);
			P[k]=Q[i++];
		}
		else{
			ans=max(ans,Q[j].x+T[1]);
			//printf("(%d,%d) ans=%d+%d=%d\n",Q[j].x,Q[j].y,Q[j].x,T[1],Q[j].x+T[1]);
			while(tu>Su&&tu->y>Q[j].y){
				if(tu-1>Su&&tu[-1].y>Q[j].y)minus(1,0,r-l+1,tu->x,k+1,tu->y-tu[-1].y),--tu;
				else minus(1,0,r-l+1,tu->x,k+1,tu->y-Q[j].y),tu->y=Q[j].y;
			}
			*++tu=(Point){k+1,yr};
			modify(1,0,r-l+1,k+1,yr-yl-Q[j].x);
			P[k]=Q[j++];
			//for(Point*p=Su+1;p<=tu;p++)printf("(%d,%d)",p->x,p->y);puts("");
		}
		//dfs(1,0,r-l+1);printf("(%d)\n",T[1]);
	}
	return max(ans,W+T[1]);
}
int main(){
	scanf("%d%d%d",&W,&H,&N);
	for(int i=0;i<N;i++)Ps[0][i].read();
	std::sort(Ps[0],Ps[0]+N);
	printf("%d\n",solve(0,N,0,H,0)*2);
}

Measured memory_bytes: 17664
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <algorithm>

#define FOR(i,k,n) for (int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define sz size()
#define pb push_back
#define mp make_pair
#define ALL(X) (X).begin(),(X).end()

using namespace std;

const int INF = 1000000000;
const double eps = 1e-8;

int main(void) {
	while(1)
	{
  	int n,w,d;
  	cin>>n>>w>>d;
  	if(!(n||w||d))
  		break;
  	vector<int> cakew(1,w);
  	vector<int> caked(1,d);
  	REP(i,n)
  	{
  		int p,s;
  		cin>>p>>s;
  		int cw = cakew[p-1];
  		int cd = caked[p-1];
  		cakew.erase(cakew.begin()+p-1);
  		caked.erase(caked.begin()+p-1);
  		s %= (cw+cd);
  		int w1,w2,d1,d2;
  		if(s < cw)
  		{
  			d1 = d2 = cd;
  			w1 = min(s,cw-s);
  			w2 = max(s,cw-s);
  		}
  		else
  		{
  			s -= cw;
  			w1 = w2 = cw;
  			d1 = min(s,cd-s);
  			d2 = max(s,cd-s);
  		}
  		cakew.push_back(w1);
  		cakew.push_back(w2);
  		caked.push_back(d1);
  		caked.push_back(d2);
  	}
  	vector<int> area(n+1);
  	REP(i,n+1)
  	{
  		area[i] = cakew[i]*caked[i];
  	}
  	sort(ALL(area));
  	REP(i,n)
  	{
  		cout << area[i]<<' ';
  	}
  	cout<<area[n]<<endl;
  }
  return 0;
}

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

#define fast ios::sync_with_stdio(false); cin.tie(0);
#define fi first
#define se second
#define em emplace
#define eb emplace_back
#define mp make_pair
#define all(v) (v).begin(), (v).end()

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int inf = 1e9;
const ll INF = 1e18;

int n;
bool chk[1000010];
vector<int> prime;
int cnt[1000010];
int a[1000010];
int d = 0;

int main() {
	fast;

	for(ll i=2; i<=1000; i++) {
		if(chk[i]) continue;

		prime.eb(i);
		
		for(ll j = i * i; j <= 1000; j += i)
			chk[j] = true;
	}

	cin >> n;

	for(int i=1; i<=n; i++) {
		cin >> a[i];
		d = __gcd(d, a[i]);

		for(auto j : prime) {
			if(j * j > a[i]) break;
			if(a[i] % j == 0) {
				cnt[j]++;
				
				while(a[i] % j == 0) a[i] /= j;
			}
		}

		if(a[i] > 1) cnt[a[i]]++;
	}

	for(int i=2; i<=1000000; i++) {
		if(cnt[i] > 1) {
			if(d == 1) {
				cout << "setwise coprime";
			}
			else {
				cout << "not coprime";
			}

			return 0;
		}
	}

	cout << "pairwise coprime";
}

Measured memory_bytes: 11460
#include<bits/stdc++.h>
using namespace std;
int main(){
	string s, ans;
	cin >> s;
	for(int i = 0; i < s.length(); i++){
		if(s[i] == '0') ans.push_back('0');
		if(s[i] == '1') ans.push_back('1');
		if(s[i] == 'B' && ans.size() != 0) ans.pop_back();
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
from sys import stdin
import math
from operator import itemgetter
from bisect import bisect_left, bisect_right
readline = stdin.readline

def main():
  xy = [tuple(map(int, readline().split())) + (i, ) for i in range(int(readline()))]
  xy.sort()
  root = int(math.sqrt(len(xy)))

  low = [x for x, y, i in xy[::root]]
  high = [x for x, y, i in xy[root - 1::root]] + [float('inf')]

  xy = [sorted(xy[i:i+root], key=itemgetter(1)) for i in range(0, len(xy),root)]
  xy = [([y for x, y, i in xyi], xyi) for xyi in xy]
  for sx, tx, sy, ty, in (map(int, readline().split()) for _ in range(int(readline()))):
    ret =[]
    for i in range(bisect_left(high, sx), bisect_right(low, tx)):
      k,v = xy[i]
      for i in range(bisect_left(k, sy), bisect_right(k, ty)):
        if sx <= v[i][0]<=tx:
          ret.append(v[i][2])
    if ret:
      ret.sort()
      print('\n'.join(map(str, ret)))
    print()
main()



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

using namespace std;



int main()
{
    int d, t, s;
    cin >> d >> t >> s;
    cout << ((d <= t*s) ? "Yes" : "No") << endl;
    return 0;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define o(a) cout << a << endl
#define int long long
using namespace std;
typedef pair<int, int> P;

signed main(){
    int n;
    string s;
    cin >> n >> s;
    vector<int> f(n, -1);  
    rep(i, 0, 2){
        rep(j, 0, 2){
            int ans = 0;    
            rep(k, 0, n) f[k] = -1;
            f[0] = i;
            f[n - 1] = j;
            rep(k, 0, n){
                int l = (k - 1 + n) % n;
                int r = (k + 1) % n;
                int next;
                if(f[k] == 0){
                    if(s[k] == 'o') next = f[l];
                    else next = (f[l] + 1) % 2;
                }else if(f[k] == 1){
                    if(s[k] == 'o') next = (f[l] + 1) % 2;
                    else next = f[l];
                }
                if(f[r] == -1){
                    f[r] = next;
                }else if(f[r] != next){
                    ans = -1;
                    // cout << f[r] << next << k << endl;
                }
                // cout << f[r] << " ";
            }
            // cout << endl;
            if(ans == 0){
                rep(k, 0, n){
                    if(f[k] == 0) cout << 'S';
                    else cout << 'W';
                }
                cout << endl;
                return 0;
            }
        }
    }
    cout << -1 << endl;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
#define ll long long 
#define log(x) cout << (#x) << " is " << (x) << endl

 int dp[3001][3001];

void print_lcs(string X,string Y){
  	int m = X.length();
  	int n = Y.length();
  	int index = dp[m][n]; 
   // Create a character array to store the lcs string 
   char lcs[index+1]; 
   lcs[index] = '\0'; 
	int i = m, j = n; 
   while (i > 0 && j > 0) 
   { 
      // If current character in X[] and Y are same, then 
      // current character is part of LCS 
      if (X[i-1] == Y[j-1]) 
      { 
          lcs[index-1] = X[i-1]; // Put current character in result 
          i--; j--; index--;     // reduce values of i, j and index 
      } 
  
      // If not same, then find the larger of two and 
      // go in the direction of larger value 
      else if (dp[i-1][j] > dp[i][j-1]) 
         i--; 
      else
         j--; 
   } 
  
   // Print the lcs 
   cout<< lcs; 
}

int main(int argc, char const *argv[])
{
    string s,t;
    cin>>s>>t;
    int n = s.length() , m = t.length();
   
    for(int i=0;i<=n;i++){
        for(int j=0;j<=m;j++){
            if(i==0 || j == 0){
                dp[i][j]=0;
            }else{
                if(s[i-1]==t[j-1]){
                    dp[i][j] = 1 + dp[i-1][j-1];
                }else{
                    dp[i][j] = max(dp[i-1][j] , dp[i][j-1]);
                }
            }
        
        }
        
    }
    

    print_lcs(s,t);
    return 0;
}



Measured memory_bytes: 35456