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

#define REP(i,n) for(int i=0;i<(int)(n);++i)

string table[128];

void dfs(int r, int c, int R, int C, int ch) {
  if (!(0 <= r && r < R && 0 <= c && c < C)) return;
  if (table[r][c] != ch) return;
  table[r][c] = '.';
  dfs(r + 1, c, R, C, ch);
  dfs(r - 1, c, R, C, ch);
  dfs(r, c + 1, R, C, ch);
  dfs(r, c - 1, R, C, ch);
}

int main() {
  for (int R, C; cin >> R >> C, (R || C); ) {
      REP(r, R) cin >> table[r];
      int ans = 0;
      REP(r, R) REP(c, C) {
          if (table[r][c] != '.') {
              dfs(r, c, R, C, table[r][c]);
              ans++;
          }
      }
      cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 0
/*

  _|_|                              _|  _|    _|
_|    _|  _|  _|_|  _|_|_|_|        _|  _|  _|
_|    _|  _|_|          _|          _|  _|_|
_|    _|  _|          _|      _|    _|  _|  _|
  _|_|    _|        _|_|_|_|    _|_|    _|    _|

*/
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<vector>
#include<queue>
#include<set>
//#define ls (rt<<1)
//#define rs (rt<<1|1)
#define vi vector<int>
#define pb push_back
#define mk make_pair
#define pii pair<int,int>
#define rep(i,a,b) for(int i=(a),i##end=(b);i<=i##end;i++)
#define fi first
#define se second
typedef long long ll;
using namespace std;
const int maxn=1e5+1000;
vi side[maxn];
int d[maxn];
int vis[maxn];
int st,ed;
void dfs(int u){
    vis[u]=1;
    for(int i=0;i<side[u].size();i++){
        int v=side[u][i];
        if(vis[v]==1)continue;
        if(vis[v]==-1){if(st)ed=v;else st=v;continue;}
        dfs(v);
    }
    return;
}
int main(){
    ios::sync_with_stdio(0);
    int n,m;cin>>n>>m;
    rep(i,1,m){
        int u,v;cin>>u>>v;side[u].pb(v);side[v].pb(u);d[u]++,d[v]++;
    }
    int mxd=0,mxcnt=0;
    rep(i,1,n){
        if(d[i]&1){
            cout<<"No";return 0;
        }
        if(d[i]>mxd){
            mxd=d[i];mxcnt=1;
        }
        else if(mxd==d[i])mxcnt++;
    }
    if(mxd>=6){cout<<"Yes";return 0;}
    else if(mxd==2){cout<<"No";return 0;}
    else if(mxcnt==1){cout<<"No";return 0;}
    else if(mxcnt>2){cout<<"Yes";return 0;}
    else{
        int te=0;
        rep(i,1,n)if(d[i]==4)vis[i]=-1;
        rep(i,1,n)if(vis[i]==0)st=ed=0,dfs(i),te+=(st==ed);
        if(te){
            cout<<"Yes";return 0;
        }else {cout<<"No";return 0;}
    }
    return 0;
}

Measured memory_bytes: 10536
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int inf = 0x3f3f3f3f;
const int maxn = 2e5 + 7;
const int mod = 1e9 + 7;
int a[107];

int main(){
	int n;
	cin >> n; 
	for(int i = 1;i <= n;i++) scanf("%d",&a[i]);
	ll minx = 0x3f3f3f3f;
	for(int i = 1;i <= 100;i++){
		ll ans = 0;
		for(int j = 1;j <= n;j++){
			ans += (ll)pow(a[j]-i,2);
		}
		minx = min(minx,ans);
	}
	printf("%lld\n",minx);
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define rrep(i,n) for(int i=(n)-1; i>=0; i--)
#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 ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define pb push_back
using ll = long long;
using D = double;
using LD = long double;
using P = pair<int, int>;
const int mod = 1e9+7;
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(){
    int n; cin >> n;
    cout << (n+1)/2 << endl;
}


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

ll tree[MAX], h[MAX], a[MAX];

void update(int idx, ll val) {
    idx = MAX - idx;
    for( ; idx < MAX; idx += idx & -idx)
        tree[idx] = max(tree[idx], val);
}

ll query(int idx) {
    ll ret = 0;
    idx = MAX - idx;
    for( ; idx > 0; idx -= idx & -idx)
        ret = max(tree[idx], ret);
    return ret;
}

int main() {
    int n;
    cin >> n;
    for(int i = 1; i <= n; ++i)
        cin >> h[i];
    for(int i = 1; i <= n; ++i)
        cin >> a[i];

    ll ans = 0;
    for(int i = n; i >= 1; --i) {
        ll x = query(h[i]) + a[i];
        //cerr << i << " :: " << x << " + " << query(h[i]) << endl;
        update(h[i], x);
        ans = max(ans, x);
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
typedef long long i64;
const int MAXN = 100000 + 10;

int N;
i64 sum;
int answer;
vector <pair<int, int>>Adj[MAXN];

inline void addEdge(int u, int v, int w)
{
	Adj[u].emplace_back(v, w);
	Adj[v].emplace_back(u, w);
}

int centroid, val[MAXN], siz[MAXN], mx[MAXN];

void DFS(int cur, int fa)
{
	siz[cur] = 1, mx[cur] = 0;
	for(auto x : Adj[cur])
		if(x.first != fa)
		{
			val[x.first] = x.second;
			DFS(x.first, cur);
			siz[cur] += siz[x.first];
			mx[cur] = max(mx[cur], siz[x.first]);
		}

	mx[cur] = max(mx[cur], N - siz[cur]);
	if(mx[cur] * 2 < N)
		centroid = cur;
	if(siz[cur] * 2 == N)
		answer = val[cur];
	sum += 2LL * min(siz[cur], N - siz[cur]) * val[cur];
}

int main()
{
	int u, v, w;
	answer = 0x7F7F7F7F;
	cin >> N ;
	for(int i = 1; i < N; i++)
		cin >> u >> v >> w, addEdge(u, v, w);

	DFS(1, 0);

	if(answer >= 0x7F7F7F7F)
		for(auto x : Adj[centroid])
			answer = min(answer, x.second);

	cout << sum - answer << endl ;
}


Measured memory_bytes: 12288
#include <stdio.h>
int n, q, k;
char s[1000001];
long long a, b, c, d;
int main() {
	scanf("%d", &n);
	scanf(" %s", s);
	scanf("%d", &q);
	for (int j = 0; j < q; j++) {
		a = 0;
		b = 0;
		c = 0;
		d = 0;
		scanf("%d", &k);
		for (int i = 0; i < n; i++) {
			if (0 <= i - k) {
				if (s[i - k] == 'D') {
					a--;
					c -= b;
				}
				if (s[i - k] == 'M')b--;
			}
			if (s[i] == 'D')a++;
			if (s[i] == 'M') {
				b++;
				c += a;
			}
			if (s[i] == 'C')d += c;
		}
		printf("%lld\n", d);
	}
}

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

int main()
{   
    string s,t;
    cin>>s>>t;
    int n=s.size();
    int cnt_s[26],cnt_t[26];
    int a_s[n],a_t[n];
    
    for(int i=0;i<26;i++){
        cnt_s[i]=0;
        cnt_t[i]=0;
    }
    
    for(int i=0;i<n;i++){
        cnt_s[s[i]-'a']++;
        cnt_t[t[i]-'a']++;
    }

    for(int i=0;i<n;i++){
        a_s[i]=cnt_s[s[i]-'a'];
        a_t[i]=cnt_t[t[i]-'a'];
    }
    for(int i=0;i<n;i++){
        if(a_s[i]!=a_t[i]){
            cout<<"No"<<endl;
            return 0;
        }
    
    }
    cout<<"Yes"<<endl;
    
    
}

Measured memory_bytes: 2312
/// Containers Start
#include <algorithm>
#include <bitset>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
/// C Header Files
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <math.h>
#include <stdio.h>
/// Containers End

using namespace std;

/// Math Start
#define PI acos(-1.0)
#define Pi 3.141592653589793
#define EPS (1e-7)
#define INF (0x3f3f3f3f)
/// Math End

/// Extra Start
#define nn '\n'
#define pb push_back
#define ull unsigned long long
#define ll long long
#define MOD 1000000007
#define sz(a) int((a).size())
#define space " "
#define All(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
/// Extra End

#define rep(i, n) for (int i = 0; i < n; i++)
#define Cini(a)                                                                \
    int a;                                                                     \
    cin >> a;
#define Cinii(a, b)                                                            \
    int a, b;                                                                  \
    cin >> a >> b;
#define Ciniii(a, b, c)                                                        \
    int a, b, c;                                                               \
    cin >> a >> b >> c;
#define Cins(s)                                                                \
    string s;                                                                  \
    cin >> s;
#define Cinss(s1, s2)                                                          \
    string s1, s2;                                                             \
    cin >> s1 >> s2;
#define Cinc(c)                                                                \
    char c;                                                                    \
    cin >> c;
/// Functions End

/// Debug Start
#define deb(x) cout << #x << ": " << x << endl
#define deb2(x, y) cout << #x << ": " << x << '\t' << #y << ": " << y << endl;
#define deb3(x, y, z)                                                          \
    cout << #x << ": " << x << '\t' << #y << ": " << y << '\t' << #z << ": "   \
         << z << endl;
/// Debug End

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

/**>>>>>>>>>>>>>>>>>>> END <<<<<<<<<<<<<<<<<<**/

/// template

signed main(void) {
    cin.sync_with_stdio(false);
    cin.tie(0);
    Cins(S);
    int ans =0;
    rep(i,S.length())if(S[i]=='2')ans++;
    cout << ans << nn;
    return 0;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {

    public static void main(String args[]) throws Exception {

        Scanner sc = new Scanner(System.in);
        char[] s = sc.nextLine().toCharArray();
        Arrays.sort(s);

        char[] t = sc.nextLine().toCharArray();
        Arrays.sort(t);

        int result = new String(s).compareTo(new StringBuilder(new String(t)).reverse().toString());
        System.out.println(result < 0 ? "Yes" : "No");
    }
}

Measured memory_bytes: 23892
#pragma GCC optimize("O3")
#include<bits/stdc++.h>
#include<map>
#include<iostream>
#include <cstring>
#include <iomanip>
#include <algorithm>
#define forr(i,a,b) for(int i=a;i<=b;i++)
#define F first
#define S second
#define input ios_base::sync_with_stdio(0);cin.tie(0);

const double PI  = acos(-1.0);
using namespace std;
//typedef pair<double,double>pdd;
typedef long long  ll;
typedef pair<ll, ll>pii;
//typedef complex<double> point;
//int x[8]={1,0,0,-1,-1,-1,1,1};
//int y[8]={0,1,-1,0,-1,1,-1,1};
//char rv[4]={'D','R','L','U'};
const double EPS = 1e-9;
const int N = 300 + 9;
int n,m,a[4];
double mem[N][N][N];


double dp(int p1, int p2, int p3)
{
    if(p1 + p2 + p3 == 0)return 0;
    if(mem[p1][p2][p3] == mem[p1][p2][p3])return mem[p1][p2][p3];

    double f = 0;
    if(p1) f += 1.0 * p1/n * (1.0 + dp(p1-1, p2, p3));
    if(p2) f += 1.0 * p2/n * (1.0 + dp(p1+1, p2-1 ,p3));
    if(p3) f += 1.0 * p3/n * (1.0 + dp(p1, p2+1, p3-1));
    double ex = f + 1.0 * (n-p1-p2-p3) / n ;
    ex/= (1.0 - 1.0 * (n-p1-p2-p3) / n);
   // ex += 1.0 * (n-p1-p2-p3) / (n - 1);
  //  ex = (n - (n-p1-p2-p3)) * 1,0 / (n-p1-p2-p3) ;
    return mem[p1][p2][p3] = ex ;
}

 int main()
{
//freopen("calc.in","r",stdin);
//freopen("calc.out","w",stdout);
//__builtin_popcount()
input
        cin>>n;
        int x;
        forr(i,1,n)
        {
            cin>>x;
            a[x]++;
        }

        memset(mem,-1,sizeof mem);
        cout<<fixed<<setprecision(9)<<dp(a[1],a[2],a[3])<<endl;






return 0;
}


Measured memory_bytes: 234332
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(void){
  int k,a,b,i;
  (void)scanf("%d",&k);
  (void)scanf("%d %d",&a,&b);
  for(i=k;i<=b;i+=k){
    if(a<=i){
      printf("OK\n");
      return 0;
    }
  }
  printf("NG\n");
  return 0;
}

Measured memory_bytes: 1632
import sys

class Node:
    def __init__(self, x):
        self.key = x
        self.left = None
        self.right = None

class BinaryTree:
    def __init__(self):
        self.root = None

    def insert(self, x):
        if self.root is None:
            self.root = Node(x)
            return self

        node = self.root
        while True:
            if x > node.key:
                if node.right is None:
                    node.right = Node(x)
                    break
                else:
                    node = node.right
            elif x < node.key:
                if node.left is None:
                    node.left = Node(x)
                    break
                else:
                    node = node.left
            else:
                break

        return self

    def pre_order(self):
        keys = []
        self.do_pre_order(self.root, keys)
        print(' ' + ' '.join(map(str, keys)))

    def do_pre_order(self, node, keys):
        if node is None:
            return
        keys.append(node.key)
        self.do_pre_order(node.left, keys)
        self.do_pre_order(node.right, keys)

    def in_order(self):
        keys = []
        self.do_in_order(self.root, keys)
        print(' ' + ' '.join(map(str, keys)))

    def do_in_order(self, node, keys):
        if node is None:
            return
        self.do_in_order(node.left, keys)
        keys.append(node.key)
        self.do_in_order(node.right, keys)

# main
tree = BinaryTree()
lines = sys.stdin.readlines()

for line in lines[1:]:
    if len(line.rstrip()) == 0:
        continue

    command = line.rstrip().split(' ')

    if command[0] == 'insert':
        tree.insert(int(command[1]))
    elif command[0] == 'print':
        tree.in_order()
        tree.pre_order()
    else:
        raise 'unknown command: ' + command[0]

Measured memory_bytes: 185160
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
using namespace std;

class BinaryIndexedTree
{
private:
    int n;
    vector<int> data;
public:
    BinaryIndexedTree(int n){ // コンストラクタ
        this->n = n;
        data.assign(n+1, 0);
    }
    void add(int k, int x){ // k番目の要素にxを加算する
        ++ k;
        while(k <= n){
            data[k] += x;
            k += k & -k;
        }
    }
    int sum(int k){ // 区間[0,k]の総和を返す
        ++ k;
        int ret = 0;
        while(k > 0){
            ret += data[k];
            k -= k & -k;
        }
        return ret;
    }
    int sum(int a, int b){ // 区間[a,b]の総和を返す
        return sum(b) - sum(a-1);
    }
};

int main()
{
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    for(int i=0; i<n; ++i)
        cin >> a[i];

    vector<BinaryIndexedTree> dp1(n+1, BinaryIndexedTree(k+1));
    vector<BinaryIndexedTree> dp2(n+1, BinaryIndexedTree(k+1));
    dp1[0].add(0, 1);
    dp2[0].add(0, 1);
    for(int i=0; i<n; ++i){
        for(int j=0; j<=k; ++j){
            if(dp1[i].sum(j, j) > 0){
                dp1[i+1].add(j, 1);
                int j2 = min(k, j + a[i]);
                dp1[i+1].add(j2, 1);
            }
            if(dp2[i].sum(j, j) > 0){
                dp2[i+1].add(j, 1);
                int j2 = min(k, j + a[n-1-i]);
                dp2[i+1].add(j2, 1);
            }
        }
    }

    int ans = n;
    for(int i=0; i<n; ++i){
        for(int x=0; x<k; ++x){
            if(dp1[i].sum(x, x) > 0 && dp2[n-1-i].sum(k-x-a[i], k-x-1)){
                -- ans;
                break;
            }
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 198144
#include<cstdio>
#include<algorithm>
#include<cstring>
#define ll long long
using namespace std;
struct Node
{
	ll val;
	ll w;
	ll num;
}a[55];
int n,x,d,size[55],pa[55],up[55];
ll v[405],w[405],m[55],tot;
ll f[125005],sum[55];
bool cmp(Node a,Node b)
{
	return 1ll*a.val*b.w>1ll*a.w*b.val;
}
ll check(ll x)
{
	ll ans=0;
	for(int i=1;i<=n;i++)
	{
		if(sum[i]>x)
		{
			ans+=x/a[i].w*a[i].val;
			x-=x/a[i].w*a[i].w;
		}
		else
		{
			ans+=a[i].num*a[i].val;
			x-=a[i].num*a[i].w;
		}
	}
	return ans;
}
int main()
{
	scanf("%d%d%d",&n,&x,&d);
	for(int i=1;i<=n;i++)
	{
		scanf("%lld",&m[i]);
		if(i!=1)scanf("%d",&pa[i]);
		size[i]=1;
	}
	for(int i=n;i>=1;i--)size[pa[i]]+=size[i],m[pa[i]]+=m[i];
	int t=0;
	for(int i=1;i<=n;i++)
	{
		up[i]=n;
		if(i!=1)up[i]=min(up[i],d);
		up[i]=min(up[i],(int)(x/m[i]));
		a[i].val=size[i];
		a[i].w=m[i];
		if(i==1)a[i].num=1000000000;
		else a[i].num=d-up[i];
		a[i].num=min(a[i].num,x/m[i]);
		t+=up[i]*size[i];
		int j=1;
		while(j<=up[i])
		{
			up[i]-=j;
			v[++tot]=size[i]*j;
			w[tot]=m[i]*j;
			j<<=1;
		}
		if(up[i])
		{
			v[++tot]=size[i]*up[i];
			w[tot]=m[i]*up[i];
		}
	}
	for(int i=0;i<=t;i++)
	  f[i]=1e18;
	f[0]=0;
	for(int i=1;i<=tot;i++)
	{
		for(int j=t;j>=v[i];j--)
		  f[j]=min(f[j],f[j-v[i]]+w[i]);
	}
	sort(a+1,a+n+1,cmp);
	for(int i=1;i<=n;i++)sum[i]=1ll*a[i].w*a[i].num;
	ll ans=0;
	for(int i=0;i<=t;i++)
	  if(f[i]<=x)
	    ans=max(ans,i+check(x-f[i]));
	printf("%lld\n",ans);
	return 0;
}

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

int main() {
    int A, B;
    cin >> A >> B;
    ll ans = 0;
    int c = 1;
    while (c < B){
        ans++;
        c += (A-1);
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 256
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

#define debug(...) fprintf(stderr, __VA_ARGS__)
#define int long long int
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
typedef pair<int, int> pii;
typedef long long ll;
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1001001001001001LL;
const ll MOD = 1000000007LL;
 
signed main() {
    int N, K; cin >> N >> K;
    if(N > K) cout << 0 << endl;
    else cout << 1 << endl;
    return 0;
}



Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#define maxn 100010
using namespace std;
int n,l,q;
int a[maxn],tp[maxn][25];
void init(){
	int to=1;
	for(int t=1;t<=n;++t){
		while(to<n&&a[t]+l>=a[to+1])to++;
		tp[t][0]=to;
	}
	for(int t=n;t>=1;--t){
		for(int i=1;i<=20;++i){
			tp[t][i]=tp[tp[t][i-1]][i-1];
		}
	}
}
bool check(int a,int b,int k){
	int now=0;
	for(int t=20;t>=0;--t){
		if(now+(1<<t)<=k){
			now+=1<<t;
			a=tp[a][t];
		}
	}
	return a>=b;
}
int getans(int a,int b){
	int l=1,r=n,ans=n;
	while(l<=r){
		int mid=(l+r)>>1;
		if(check(a,b,mid)){
			ans=mid;
			r=mid-1;
		}
		else l=mid+1;
	}
	return ans;
}
int main(){
	scanf("%d",&n);
	for(int t=1;t<=n;++t)scanf("%d",&a[t]);
	scanf("%d%d",&l,&q);
	init();
	for(int t=1;t<=q;++t){
		int a,b;
		scanf("%d%d",&a,&b);
		if(a>b)swap(a,b);
		printf("%d\n",getans(a,b));
	}
}

Measured memory_bytes: 11008
using System;
using System.Linq;

class aizu_judge
{
    static void Main()
    {
        int[] num = System.Console.ReadLine().Split().Select(int.Parse).ToArray();
        if (num[0] < num[1] && num[1] < num[2])
            Console.WriteLine("Yes");
        else
            Console.WriteLine("No");
    }
}

Measured memory_bytes: 9324
# -*- coding: utf-8 -*-
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys

def s():
    return raw_input().strip()
def n():
    return int(raw_input())
def d():
    return float(raw_input())

def ls():
    return raw_input().strip().split()
def ln():
    return map(int, raw_input().strip().split())
def ld():
    return map(float, raw_input().strip().split())

def fs():
    return [raw_input().strip() for i in xrange(input())]
def fn():
    return [int(raw_input().strip()) for i in xrange(input())]
def fd():
    return [float(raw_input().strip()) for i in xrange(input())]

N, L = ln()

A = ln()

candidate = -1

for i in xrange(N - 1):
    if A[i] + A[i + 1] >= L:
        candidate = i

if candidate != -1:
    print 'Possible'
    for i in xrange(candidate):
        print i + 1
    for i in xrange(N - 1, candidate, -1):
        print i
else:
    print 'Impossible'


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

#define repr(i,a,b) for (int i=a; i<b; i++)
#define rep(i,n) for (int i=0; i<  n; i++)
 
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
 
const long long INF = 1LL << 60;
#define PI 3.14159265359 
bool dp[100100];

template<typename T>
void remove(std::vector<T>& vector, unsigned int index)
{
    vector.erase(vector.begin() + index);
}



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

    string S, T;
    cin >> S >> T;

    rep(i,N){
        cout << S[i] << T[i];
    }
    cout << endl;

}


Measured memory_bytes: 3604
#include<iostream>
#include<cstdio>
#include<array>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<string>
#include<algorithm>
#include<cmath>

#define rep(i, a) for (int i = 0; i < a; i++)
#define reps(i, s, a) for (int i = s; i < a; i++)
#define llint long long int
using namespace std;

const int N_MAX = 505;
const int INF = 9999999;

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

    if (s.size() == 2) {
        cout << s;
    }
    else {
        for (int i = 2; i >= 0; i--) cout << s[i];
    }
}

Measured memory_bytes: 256
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
#include<assert.h>
#include<list>
#include<bitset>
#include<stack>
#include<memory>
#include<numeric>
using namespace std;
using namespace std::chrono;
typedef long long int llint;
typedef long double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
#define REP(i, n) for(int i = 0;i < (n);i++)
/*cout<<fixed<<setprecision(20);cin.tie(0);ios::sync_with_stdio(false);*/
const llint mod=998244353;
const llint inf=2.19e18+1;
const long double pai=3.141592653589793238462643383279502884197;
const long double eps=1e-10;
template <class T,class U>bool chmin(T& a,U b){if(a>b){a=b;return true;}return false;}
template <class T,class U>bool chmax(T& a,U b){if(a<b){a=b;return true;}return false;}
llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);}
llint lcm(llint a,llint b){if(a==0){return b;}return a/gcd(a,b)*b;}
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());}
template<class T>llint LBI(const vector<T>&ar,T in){return lower_bound(ar.begin(),ar.end(),in)-ar.begin();}
template<class T>llint UBI(const vector<T>&ar,T in){return upper_bound(ar.begin(),ar.end(),in)-ar.begin();}

int main(void){
	int Ha,Ma,Hb,Mb,K;cin>>Ha>>Ma>>Hb>>Mb>>K;
	Ma+=Ha*60;
	Mb+=Hb*60;
	cout<<(Mb-Ma-K)<<endl;
	return 0;
}


Measured memory_bytes: 3160
n = gets.chomp.to_i
s = gets.chomp.split('')

ng = 0
1.upto(n-2) do |i|
  (i+1).upto(n-1) do |j|
    k = 2*j - i
    next if k > n
    if s[i-1] != s[j-1] && s[j-1] != s[k-1] && s[k-1] != s[i-1]
      ng += 1
    end
  end
end

r = 0
g = 0
b = 0
s.each do |ss|
  if ss == 'R'
    r += 1
  elsif ss == 'G'
    g += 1
  else
    b += 1
  end
end

p r*g*b - ng


Measured memory_bytes: 14404
# -*- coding: utf-8 -*-
import math
import sys
input = sys.stdin.readline


def main():
    n = int(input())
    a = list(map(int, input().split()))

    result = [0 for i in range(n)]
    for i in range(1, n):
        result[a[i - 1] - 1] += 1

    for ai in result:
        print(ai)


if __name__ == '__main__':
    main()


Measured memory_bytes: 32044
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define rep2(i,s,f) for(int i=s;i<f;i++)
#define INF 1000000000000000000
#define MOD 1000000007
#define endl "\n"
#define fcout cout<<fixed<<setprecision(15)
typedef pair<int, int> P;
//struct edge { int to, cost; };

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

bool prime(int n) {
    for (int i = 2; i <= sqrt(n); i++) {
        if (n % i == 0)return false;
    }
    return n != 1;
}
int gcd(int x, int y) {
    if (y == 0)return x;
    return gcd(y, x % y);
}
int lcm(int x, int y) {
return x / gcd(x, y) * y;
}
int mod_pow(int n, int p, int m) {
    if (p == 0) return 1;
    if (p % 2 == 0) {
        int t = mod_pow(n, p / 2, m);
        return (t * t) % m;
    }
    return n * mod_pow(n, p - 1, m) % m;
}
int extGCD(int a, int b, int& x, int& y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    long long d = extGCD(b, a % b, y, x);
    y -= a / b * x;
    return d;
}
int modinv(int a, int m) {
    int b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
int modinv2(int a, int mod) {
    return mod_pow(a, mod - 2, mod);
}
int digit(int x) {
    int cnt = 0;
    while (x > 0) {
        cnt += x % 10;
        x /= 10;
    }
    return cnt;
}
int read() {
    int tmp;
    cin >> tmp;
    return tmp;
}
int xor128() {
    static int x = 123456789, y = 362436069, z = 521288629, w = 88675123;
    int t = (x xor (x << 11));
    x = y; y = z; z = w;
    return (w = (w xor (w >> 19)) xor (t xor (t >> 8)));
}
map<int, int> factaring(int x) {
    map<int, int>ans;
    int now = 2;
    while (now * now <= x) {
        if (x % now == 0) {
            x /= now;
            ans[now]++;
        }
        else now++;
    }
    if (x != 1) ans[x]++;
    return ans;
}
int comb(int n, int k, int mod) {
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    k = min(k, n - k);
    int x = 1, y = 1;
    rep(i, k) {
        y *= i + 1;
        y %= mod;
    }
    for (int i = n - k + 1; i <= n; i++) {
        x *= i;
        x %= mod;
    }
    return x * modinv(y, mod) % mod;
}


signed main() {
    //srand((unsigned)time(NULL));

    cin.tie(0);
    ios::sync_with_stdio(false);

    int n;
    int ans = 0;
    cin >> n;
    for (int i = 1; i <= n; i++) {
        string s = to_string(i);
        if (s.size() % 2 == 1) ans++;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
using System;
using System.IO;
using CompLib.Util;

public class Program
{
    private int D;
    private int[] C;
    private int[] S;
    private const int Col = 26;


    public void Solve()
    {
        var sc = new Scanner();
        D = sc.NextInt();
        C = sc.IntArray();
        S = new int[D * Col];
        for (int i = 0; i < D * Col; i++)
        {
            S[i] = sc.NextInt();
        }

        int[] t = new int[D];
        for (int i = 0; i < D; i++)
        {
            t[i] = sc.NextInt();
        }

        int[] last = new int[Col];
        for (int i = 0; i < Col; i++)
        {
            last[i] = -1;
        }

        long score = 0;
        Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) {AutoFlush = false});

        for (int i = 0; i < D; i++)
        {
            score += S[Conv(i, t[i] - 1)];
            last[t[i] - 1] = i;
            for (int j = 0; j < 26; j++)
            {
                score -= (long) C[j] * (i - last[j]);
            }

            Console.WriteLine(score);            
        }
        
        Console.Out.Flush();

    }

    int Conv(int i, int j)
    {
        return i * Col + j;
    }

    public static void Main(string[] args) => new Program().Solve();
}


namespace CompLib.Util
{
    using System;
    using System.Linq;

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}

Measured memory_bytes: 28656
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools
import random

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def pe(s): return print(str(s), file=sys.stderr)


def main():
    a,b,c,n = LI()
    r = 0
    for i in range(0,n+1,a):
        t = n - i
        for j in range(0,t+1,b):
            k = t - j
            if k % c == 0:
                r += 1

    return r


print(main())




Measured memory_bytes: 6220
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }


signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s; cin >> s;
	int n = s.size();
	int cnt[26] = {};
	rep(i, 0, n) {
		cnt[s[i] - 'a']++;
	}
	int u = n*(n - 1) / 2 + n + 1;
	rep(i, 0, 26) {
		if (cnt[i] >= 2)
			u -= cnt[i] * (cnt[i] - 1) / 2;
	}
	u -= n;
	cout << u << endl;
	return 0;
}

Measured memory_bytes: 720
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;

namespace x
{
    class Program
    {
        static void Main(string[] args)
        {
            var len = IOUtils.ReadInt();
            var nums = Console.ReadLine()
                              .Split(' ')
                              .Select(v => int.Parse(v))
                              .OrderBy(n => n)
                              .ToList();
            var max = nums.Last();

            var pre = -1;
            var excluded = new HashSet<int>();
            foreach (var num in nums)
            {
                if (excluded.Contains(num)) continue;

                if (pre == num) {
                    excluded.Add(num);
                    continue;
                }
                pre = num;

                var i = 2;

                while(true) {
                    var val = num * i;
                    if (max < val) break;
                    excluded.Add(val);
                    i++;
                }
            }

            var result = nums.Distinct().Where(n => !excluded.Contains(n)).Count();
            System.Console.WriteLine(result);
        }
    }

    
    static class IOUtils
    {
        public static (int a, int b) Read2Ints()
        {
            var vals = ReadInts();
            return (vals[0], vals[1]);
        }
        public static (int a, int b, int c) Read3Ints()
        {
            var vals = ReadInts();
            return (vals[0], vals[1], vals[2]);
        }
        public static IEnumerable<int[]> ReadIntLines(int count)
        {
            for (int i = 0; i < count; i++)
            {
                yield return ReadInts();
            }
        }
        public static IEnumerable<long[]> ReadLongLines(int count)
        {
            for (int i = 0; i < count; i++)
            {
                yield return ReadLongs();
            }
        }
        public static int ReadInt()
        {
            return int.Parse(Console.ReadLine());
        }
        public static long ReadLong()
        {
            return long.Parse(Console.ReadLine());
        }
        public static ulong ReadUlong()
        {
            return ulong.Parse(Console.ReadLine());
        }
        public static int[] ReadInts()
        {
            return Console.ReadLine().Split(' ').Select(v => int.Parse(v)).ToArray();
        }
        public static long[] ReadLongs()
        {
            return Console.ReadLine().Split(' ').Select(v => long.Parse(v)).ToArray();
        }

        public static void WriteNums(params int[] nums)
        {
            Console.WriteLine(string.Join(" ", nums));
        }
    }
}


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

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

    auto defer_inc = vector<int>(m);
    auto defer_dec = vector<int>(m);

    for (int i = 0; i < m; ++i) {
        int l, r;
        cin >> l >> r;
        --l, --r;

        defer_inc[i] = l;
        defer_dec[i] = r + 1;
    }

    sort(defer_inc.begin(), defer_inc.end());
    sort(defer_dec.begin(), defer_dec.end());

    auto cards = vector<int>(n);
    int i = 0;
    int sum = 0;
    for (auto ad : defer_inc) {
        for (; i < ad; ++i) {
            cards[i] += sum;
        }
        ++sum;
    }
    for (; i < n; ++i)
        cards[i] += sum;

    i = 0;
    sum = 0;
    for (auto idec : defer_dec) {
        for (; i < idec; ++i) {
            cards[i] -= sum;
        }
        ++sum;
    }
    for (; i < n; ++i)
        cards[i] -= sum;

    auto cnt = count_if(cards.begin(), cards.end(), [=](auto c) { return c == m; });
    cout << cnt;
    return 0;
}


Measured memory_bytes: 1408
#include<bits/stdc++.h>
#define mod 1000000007
using namespace std;
int n, m, x[100007], y[100007], ss[100007], t[100007], dp[100007], tot, cnt, res = 1;
pair<int, int>p[100007];
int read()
{
	int num = 0;
	char c = getchar();
	while (c < '0' || c>'9')c = getchar();
	while (c >= '0' && c <= '9')num = num * 10 + c - '0', c = getchar();
	return num;
}
int cmp(pair<int, int>a, pair<int, int>b)
{
	if (a.first == b.first)return a.second > b.second;
	else return a.first < b.first;
}
int add(int x, int v)
{
	while (x <= tot)t[x] = (t[x] + v) % mod, x += x & -x;
	return 0;
}
int ask(int x)
{
	int res = 0;
	while (x)res = (res + t[x]) % mod, x -= x & -x;
	return res;
}
int main()
{
	n = read();
	m = read();
	for (int i = 1; i <= n; i++)
		x[i] = read();
	for (int i = 1; i <= m; i++)
		y[i] = read();
	sort(x + 1, x + n + 1);
	sort(y + 1, y + m + 1);
	for(int i=1;i<=n;i++)
		if (x[i] > y[1] && x[i] < y[m])
		{
			int pos = lower_bound(y + 1, y + m + 1, x[i]) - y;
			if (x[i] == y[pos])continue;
			p[++cnt] = make_pair(x[i] - y[pos - 1], y[pos] - x[i]);
		}
	sort(p + 1, p + cnt + 1, cmp);
	cnt = unique(p + 1, p + cnt + 1) - p - 1;
	for (int i = 1; i <= cnt; i++)
		ss[++tot] = p[i].second;
	sort(ss + 1, ss + tot + 1);
	tot = unique(ss + 1, ss + tot + 1) - ss - 1;
	for (int i = 1; i <= cnt; i++)
	{
		int pos = lower_bound(ss + 1, ss + tot + 1, p[i].second) - ss;
		dp[i] = (ask(pos - 1) + 1) % mod;
		add(pos, dp[i]);
	}
	for (int i = 1; i <= cnt; i++)
		res = (res + dp[i]) % mod;
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 2816
#include <bits/stdc++.h>
using namespace std;
using pii = pair<int,int>;
#define rep(i, j) for(int i=0; i < (int)(j); i++)
template<class T> bool set_min(T &a, const T &b) { return a > b  ? a = b, true : false; }
const int INF = 1 << 30;

class Solver {
  public:
    bool solve() {
        int N, M; cin >> N >> M;
        vector<vector<int>> G(N, vector<int>(N));
        rep(i, M) {
            int a, b; cin >> a >> b;
            a--; b--;
            G[a][b] = 1;
            G[b][a] = 1;
        }
        rep(i, N) rep(j, N) {
            if(i != j) G[i][j] = 1 - G[i][j];
        }
        vector<int> color(N);
        function<pii(int, int)> coloring = [&] (int now, int c) {
            pii res = make_pair(0, 0);
            color[now] = c;
            (c == 1 ? res.first : res.second) += 1;
            rep(i, N) if(G[now][i]) {
                if(not color[i]) {
                    pii tmp = coloring(i, c == 1 ? 2 : 1);
                    if(tmp.first < 0) return make_pair(-1, -1);
                    res.first += tmp.first;
                    res.second += tmp.second;
                } else if(color[i] == c) return make_pair(-1, -1);
            }
            return res;
        };
        vector<pii> group;
        rep(i, N) {
            if(not color[i]) {
                group.push_back(coloring(i, 1));
                if(group.back().first < 0) {
                    cout << -1 << endl;
                    exit(0);
                }
            }
        }

        vector<vector<int>> dp(group.size() + 1, vector<int>(N + 1));
        dp[0][0] = 1;
        rep(i, group.size()) {
            rep(j, N) {
                if(not dp[i][j]) continue;
                if(j + group[i].first <= N) dp[i + 1][j + group[i].first] = 1;
                if(j + group[i].second <= N) dp[i + 1][j + group[i].second] = 1;
            }
        }
        int ans = INF;
        rep(i, N + 1) {
            if(dp[group.size()][i]) set_min(ans, i * (i - 1) / 2 + (N - i) * (N - i - 1) / 2);
        }
        cout << ans << endl;
        return 0;
    }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    Solver s;
    s.solve();
    return 0;
}


Measured memory_bytes: 4224
T=input()
res=''
for i in range(len(T)):
	if T[i]=='?':
		if i==0:
			if len(T)==1:
				res+='D'
			else:
				if T[i+1]=='P':
					res+='D'
				else:
					res+='P'
		else:
			if i+1<len(T):
				if res[i-1]=='P' or T[i+1]=='P':
					res+='D'
				else:
					res+='P'
			else:
				res+='D'
	else:
		res+=T[i]
print(res)


Measured memory_bytes: 9504
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <string>
#include <map>
using namespace std;
int main() {
	int sum = 0,a,b,n;
	cin >> n;
	for (int i = 0; i < n;i++) {
		cin >> a >> b;
		sum += (b - a)+1;
	}
	cout << sum << endl;
	
	

	return 0;
}



Measured memory_bytes: 256
using System;
class atcoder
{
	public static void Main()
	{
		string[] a = Console.ReadLine().Split(' ');

		if (a[0] == "H")
		{
			Console.WriteLine(a[1]);
		}
		else
		{
			if (a[1] == "H")
			{
				Console.WriteLine("D");
			}
			else
			{
				Console.WriteLine("H");
			}
		}
	}
}


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

#define REP(i, n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(), (x).end()

using namespace std;

template <typename T> T &chmin(T &a, const T &b) {return a = min(a, b);}
template <typename T> T &chmax(T &a, const T &b) {return a = max(a, b);}

vector<int> digit(1000);
vector<int> target;
int N;

int main(){
	cin >> N;
	REP(i, N)	cin >> digit[i];
	vector<int> target;
	REP(i, 10000){
		target.clear();
		int tgt = i;
	  do{
			target.push_back(tgt%10);
			tgt /= 10;
		} while(tgt > 0);
		reverse(ALL(target));
		bool find = false;
		REP(j, N-target.size()+1){
			REP(k, target.size()){
				if(digit[j+k] != target[k]) break;
				if(k == target.size()-1) find = true;
			}
			if(find) break;
		}
		if(!find) { cout << i << endl; return 0;}
	}
	return 0;
}

Measured memory_bytes: 3140
import re
S = input()

if S[0] != 'A':
    print('WA')
    exit()

l = len(S)
if S.count('C',2,l-1) != 1:
    print('WA')
    exit()
    
if len(re.findall('[A-Z]',S)) == 2:
    print('AC')
else:
    print('WA')

Measured memory_bytes: 3188
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        Integer a[] = new Integer[n];
        for(int i = 0; i < n; i++){
            a[i] = sc.nextInt();
        }
        Arrays.sort(a, Comparator.reverseOrder());
        int alice = 0, bob = 0;
        for(int i = 0; i < n; i++){
            if(i % 2 == 0){
                alice += a[i];
            }else{
                bob += a[i];
            }
        }
        System.out.println(alice - bob);
    }
}


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

using namespace std;

int main(void){
    
    int n,y;
    cin >> n >> y;
    int f=0;
    for(int i=0;i<=n && f == 0;i++){
        for(int j=0;j<=n-i&& f == 0;j++){
            int k=n-i-j;
                if(i*10000+j*5000+k*1000==y){
                    cout <<i<<" "<<j<<" "<<k<<endl;
                    f=1;
                }
        }
    }
    if(f == 0)
    cout <<"-1 -1 -1" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  
  int N;
  
  int x;
  
  int A = 0;
  
  int K;
  
  cin >> N >> K;
  
  for (int i = 0; i < N; i++) {
   
    cin >> x;
    
    if (x < K - x) {
        
        A = A + x * 2;
        
      }
      else if (x >= K - x) {
        
        A = A + ( K - x ) * 2;
        
      }
  }
  
  cout << A << endl;
  
}

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

int main () {

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

    int ans = 0;
    int cnt = 0;

    for (int i = min(A, B); i > 0; i--) {
        if (A % i == 0 && B % i == 0) {
            cnt++;
            ans = i;
            if (cnt == K) {
                break;
            }
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
n=int(input())
A=[int(i) for i in input().split()]
q=int(input())
M=[int(i) for i in input().split()]

list.sort(A, reverse=True)

def solve(i,m):
  global n
  global A
  if m==0:
    return True
  elif m >0:
    if i >= n:
      return False
    res =solve(i+1,m)|solve(i+1,m-A[i])
    return res
  else:
    return False

sum_A=sum(A)

for i in range(q):
  if sum_A < M[i]:
    print('no')
  else:
    if solve(0,M[i]):
      print('yes')
    else:
      print('no')


Measured memory_bytes: 5624
/// 3:38 PM 24/05/20
/// Author: t_bone_289 (An Immature Programmer.... I'm still developing !!)
#include<bits/stdc++.h>

using namespace std;
#define pll pair<ll,ll>
#define fi first
#define se second
#define mp make_pair
#define pb emplace_back
#define endl '\n'
#define VARIABLE_ERROR(x) cout << #x << " = " << x << endl;
#define CONTAINER_ERROR(v) cout << "{";for (auto &x:v) { cout << x << ','; }cout << "}" << endl;
#define PI 3.14159265358979323846
#define M 1000000007
#define INF 1e15
typedef long long ll;

void build(ll l, ll r, ll in, vector<ll> &v, vector<ll> &tree) {
    if (l > r) {
        return;
    }
    if (l == r) {
        tree[in] = v[l];
        return;
    }
    ll mid = (l + r) >> 1ll;
    build(l, mid, 2 * in + 1, v, tree);
    build(mid + 1, r, 2 * in + 2, v, tree);
    tree[in] = max(tree[2 * in + 1], tree[2 * in + 2]);
}

ll query(ll l, ll r, ll ql, ll qr, ll in, vector<ll> &tree) {
    if (l > qr || r < ql || l > r) {
        return -INF;
    }
    if (l >= ql && r <= qr) {
        return tree[in];
    }
    ll mid = (l + r) >> 1ll;
    ll left = query(l, mid, ql, qr, 2 * in + 1, tree);
    ll right = query(mid + 1, r, ql, qr, 2 * in + 2, tree);
    ll ans = max(left, right);
    return ans;
}

void update(ll l, ll r, ll index, ll in, vector<ll> &tree, vector<ll> &v) {
    if (l > r) {
        return;
    } else if (index < l || index > r) {
        return;
    } else if (l == r) {
        tree[in] = v[index];
        return;
    }
    ll mid = (l + r) >> 1;
    update(l, mid, index, 2 * in + 1, tree, v);
    update(mid + 1, r, index, 2 * in + 2, tree, v);
    tree[in] = max(tree[2 * in + 1], tree[2 * in + 2]);
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    ll n;
    cin >> n;
    vector<ll> h(n);
    vector<ll> a(n);
    for (auto &x:h) {
        cin >> x;
        x--;
    }
    for (auto &x:a) {
        cin >> x;
    }
    vector<ll> maxVal(n, -INF);
    vector<ll> dp(n);
    dp[0] = a[0];
    maxVal[h[0]] = a[0];
    vector<ll> tree(4 * n + 4);
    build(0, n - 1, 0, maxVal, tree);
    for (ll i = 1; i < n; i++) {
        ll mv = query(0, n - 1, 0, h[i] - 1, 0, tree);
        if (mv == -INF) {
            maxVal[h[i]] = a[i];
            update(0, n - 1, h[i], 0, tree, maxVal);
        } else {
            ll temp = mv + a[i];
            maxVal[h[i]] = a[i] + mv;
            update(0, n - 1, h[i], 0, tree, maxVal);
        }
    }
    ll ans = -INF;
    for (ll i = 0; i < n; i++) {
        ans = max(ans, maxVal[i]);
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 12800
#include<iostream>
using namespace std;
#define int long long
int to[200001],v[200001],nex[200001],st[100001],dis[100001],fa[100001];
int n,m,cnt;
void addedge(int x,int y,int z)
{
    to[++cnt]=y;
    v[cnt]=z;
    nex[cnt]=st[x];
    st[x]=cnt;
}
void dfs(int x)
{
	//cout<<x<<endl;
    for(int i=st[x];i;i=nex[i])
    {
    	if(to[i]==fa[x])continue;
        dis[to[i]]=dis[x]+v[i];
        fa[to[i]]=x;
        dfs(to[i]);
    }
}
signed main()
{
    cin>>n;
    for(int i=1;i<n;i++)
    {
        int x,y,z;
        cin>>x>>y>>z;
        addedge(x,y,z);
        addedge(y,x,z);
    }
    dfs(1);
    for(int i=1;i<=n;i++)
    {
        cout<<dis[i]%2<<endl;
    }
    return 0;
}

Measured memory_bytes: 8832
n = gets.to_i
n = n % 10;


if (n == 2 || n == 4 || n == 5 || n == 7 || n == 9)
    puts "hon"
elsif n == 0 || n == 1|| n == 6 || n == 8 
    puts "pon"
else
    puts "bon"
end


Measured memory_bytes: 14340
import bisect

n = int(input())

a = list(map(int , input().split()))
b=list(map(int , input().split()))
c=list(map(int , input().split()))

b.sort()
c.sort()

bsum=[0 for i in range(n)]#bsum[i]=\sum_{k=i}^{n-1}(b[k]より大きいc内の要素の個数)

for i in reversed(range(n)):
    bsum[i] += (n - bisect.bisect_right(c, b[i]))
    if(i != (n-1)) :bsum[i] += bsum[i+1]

ans = 0
for aa in a:
    pos = bisect.bisect_right(b, aa)
    if (pos < n) :ans += bsum[pos]

print(ans)

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

int main() {
    int n;
    int64_t x, y, ans;
    cin >> n >> x;
    if (n == 1) {
        cin >> y;
        cout << abs(x - y);
        return 0;
    }
    cin >> y;
    ans = abs(x - y);
    for (int i = 0; i < n-1; i++) {
        cin >> y;
        ans = __gcd(abs(x - y), ans);
    }
    cout << ans << endl;
}



Measured memory_bytes: 256