akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<math.h>
#include<queue>
#include<stdlib.h>
#include<vector>
#include<stack>
#include<bitset>
#include<set>
#define maxn 305
using namespace std;
typedef long long ll;
int n,m,k;
char s[maxn][maxn];
int main()
{
	scanf("%d%d%d",&n,&m,&k);	
	for(int i=0;i<n;i++)
		scanf("%s",s[i]);
	int ans=0;
	for(int i=0;i<(1<<n);i++)
	{
		for(int j=0;j<(1<<m);j++)
		{
			int cnt=0;
			for(int x=0;x<n;x++)
			{
				for(int y=0;y<m;y++)
				{
					if(!((1<<x)&i) && !((1<<y)&j) && s[x][y]=='#')
					{
						cnt++;
					}
				}
			}
			if(cnt==k)
				ans++;
		}
	}
	printf("%d\n",ans);
}


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

class Program
{
    static string InputPattern = "InputX";

    static List<string> GetInputList()
    {
        var WillReturn = new List<string>();

        if (InputPattern == "Input1") {
            WillReturn.Add("4");
            WillReturn.Add("hoge");
            WillReturn.Add("english");
            WillReturn.Add("hoge");
            WillReturn.Add("enigma");
            //No
        }
        else if (InputPattern == "Input2") {
            WillReturn.Add("9");
            WillReturn.Add("basic");
            WillReturn.Add("c");
            WillReturn.Add("cpp");
            WillReturn.Add("php");
            WillReturn.Add("python");
            WillReturn.Add("nadesico");
            WillReturn.Add("ocaml");
            WillReturn.Add("lua");
            WillReturn.Add("assembly");
            //Yes
        }
        else if (InputPattern == "Input3") {
            WillReturn.Add("8");
            WillReturn.Add("a");
            WillReturn.Add("aa");
            WillReturn.Add("aaa");
            WillReturn.Add("aaaa");
            WillReturn.Add("aaaaa");
            WillReturn.Add("aaaaaa");
            WillReturn.Add("aaa");
            WillReturn.Add("aaaaaaa");
            //No
        }
        else if (InputPattern == "Input4") {
            WillReturn.Add("3");
            WillReturn.Add("abc");
            WillReturn.Add("arc");
            WillReturn.Add("agc");
            //No
        }
        else {
            string wkStr;
            while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr);
        }
        return WillReturn;
    }

    static void Main()
    {
        List<string> InputList = GetInputList();
        var WList = new List<string>();
        foreach (string EachStr in InputList.Skip(1)) {
            WList.Add(EachStr);
        }
        if (WList.Count > WList.Distinct().Count()) {
            Console.WriteLine("No");
            return;
        }

        for (int I = 1; I <= WList.Count - 1; I++) {
            if (WList[I - 1].ToCharArray().Last() != WList[I][0]) {
                Console.WriteLine("No");
                return;
            }
        }
        Console.WriteLine("Yes");
    }
}


Measured memory_bytes: 13396
#include<stdio.h>
#include<stdlib.h>

#define MAX 100

void MatrixChain(int, int*);

int main(void){
  int n, i, x;
  int P[MAX];

  scanf("%d", &n);
  for(i=0; i<n; i++) scanf("%d%d", &P[i+1], &x);

  P[i+1] = x;

  MatrixChain(n, P);

  return 0;
}

void MatrixChain(int n, int *P){
  int i, j, k, x, q;
  int M[MAX][MAX];

  for(i=1; i<=n; i++) M[i][i] = 0;

  for(i=2; i<=n; i++){
    for(j=1; j<=n-i+1; j++){

      x = i+j-1;
      M[j][x] = 1000000;
      for(k=j; k<=x-1; k++){

        q = M[j][k]+M[k+1][x]+P[j]*P[k+1]*P[x+1];
        if(q < M[j][x]) M[j][x] = q;

      }
    }
  }

  printf("%d\n", M[1][n]);

  return;
}

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

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

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

    sort(a.begin(), a.end());
    cout << a[n - 1] - a[0] << endl;

    return 0;
}

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

#define INF 1.1e9
#define LINF 1.1e18
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(), (v).end()
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define BIT(x,n) bitset<n>(x)

typedef long long ll;
typedef pair<int,int> P;
typedef pair<P,int> PP;

struct edge {
	int to,cost;
	edge(int t,int c):to(t),cost(c) {}
};

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

ll mypow(ll x,ll n,ll m) {	//xのn乗をmで割った余り
	if(n==0) return 1;
	if(n%2==0) return mypow(x*x%m,n/2,m);
	else return x*mypow(x,n-1,m)%m;
}

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

int n,ma,mi=INF;

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

	cin>>n;
	REP(i,n) {
		int a;cin>>a;
		mi=min(mi,a);
		ma=max(ma,a);
	}
	cout<<ma-mi<<endl;

	return 0;
}


Measured memory_bytes: 256
# しゃくとり法
N, K = map(int, input().split())
S = list(map(int, input()))

j = 1
r = 0
t = []
for i in range(N):
    if S[i] == j:
        r += 1
    else:
        t.append(r)
        r = 1
        j ^= 1
t.append(r)
if j == 0:
    t.append(0)

if K >= (len(t) - 1) // 2:
    print(sum(t))
else:
    result = sum(t[:2 * K + 1])
    j = result
    i = 2
    while i + 2 * K < len(t):
        j += t[i + 2 * K - 1] + t[i + 2 * K] - (t[i - 2] + t[i - 1])
        result = max(result, j)
        i += 2
    print(result)


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



int main(){
    int k,a,b;

    cin >> k >> a >> b;

    int c = a/k;

    while(c*k <= b){
        if(c*k <= b && c*k >= a){
            cout << "OK" << endl;
            return 0;
        }
        c++;
    }

    cout << "NG" << endl;
    return 0;


}

Measured memory_bytes: 3596
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>
#include<functional>
#include<numeric>
#include<queue>
#include<stack>
#include<map>
#include<unordered_map>
#include<set>
#include<bitset>
#include<random>
#pragma region
using namespace std;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define rep(i,n) FOR(i,0LL,n)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define rrep(i,n) RFOR(i,0LL,n)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define COUNT(a,y,x) upper_bound(all(a), y) - lower_bound(all(a), x)
#define UNIQUE(a) sort(all(a)); a.erase(unique(all(a)), a.end())
#define pb push_back
typedef long long int ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<string> vs;
typedef map<ll, ll> MAP;
const ll inf = 1LL << 61;
const ll mod = 1000000007LL;
//const ll mod = 998244353LL;

ll n = 0, m = 0, ans = 0, tmp = 0, ma = -inf, mi = inf;
string s;
ll dx[9] = { 0,1,0,-1,0,1,1,-1,-1 }, dy[9] = { 0,0,1,0,-1,1,-1,1,-1 };
#define endl '\n'
#pragma endregion
#define MAX 222222


vll divosor(ll val) {
  vll ret, ret2;
  for (ll i = 1; i*i <= val; i++) {
    if (val%i == 0) {
      ret.pb(i);
      if (i*i != val) ret2.pb(val / i);
    }
  }
  ret.insert(ret.end(), ret2.rbegin(), ret2.rend());
  return ret;
}


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


  cin >> n >> m;
  vll a(n);
  rep(i, n) cin >> a[i];
  ll sum = 0;
  ans = 1;
  rep(i, n) sum += a[i];
  vll d = divosor(sum);
  rrep(i, d.size()) {
    vll v(n);
    rep(j, n) v[j] = a[j] % d[i];
    sort(all(v));
    ll x = 0, y = 0;
    rep(j, n) {
      if (x + v[j] <= m) x += v[j];
      else y += d[i] - v[j];
    }
    if (x <= m && y <= m) {
      cout << d[i] << endl;
      return 0;
    }
  }


  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#include <math.h>

int main(void) {
    int N, Q;
    int A[100001] = {0};
    long long B;
    long long C;
    long long sum = 0;

    scanf("%d", &N);
    for(int i = 0; i < N; i++) {
        int tmp;
        scanf("%d", &tmp);
        A[tmp]++;
        sum += tmp;
    }
    scanf("%d", &Q);
    for(int i = 0; i < Q; i++) {
        scanf("%lld %lld", &B, &C);
        sum = sum - (B * A[B]) + (C * A[B]);
        A[C] += A[B];
        A[B] = 0;
        printf("%lld\n", sum);
    }
    return 0;
}


Measured memory_bytes: 2120
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define IFOR(i, m, n) for (ll i = n - 1; i >= m; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define FOREACH(x, a) for (auto&(x) : (a))
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) ll(x.size())

int main() {
  ll N;
  cin >> N;
  vector<ll> P(N), Q(N);
  REP(i, N) {
    cin >> P[i];
    P[i]--;
    Q[P[i]] = i;
  }
  ll len = 1;
  ll maxi = 1;
  FOR(i, 1, N) {
    if (Q[i - 1] < Q[i])
      len++;
    else
      len = 1;
    maxi = max(maxi, len);
  }
  cout << N - maxi << endl;
}

Measured memory_bytes: 3328
N = int(input())
A = [int(a) for a in input().split()]

S = sum(A)
for i in range(N):
    A[i] = [A[i], i+1]

A.sort(reverse=True)
ans = [0]*(N+1)
i = 0
num = N+1
while i < N-1:
    num = min(num, A[i][1])
    while i < N-1 and A[i][0] == A[i+1][0]:
        num = min(num, A[i+1][1])
        i += 1
    if i == N-1:
        break
    ans[num] += (i+1)*(A[i][0]-A[i+1][0])
    i += 1

ans[1] += S-sum(ans)
for i in range(1, N+1):
    print(ans[i])

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

int main() {
	ios_base::sync_with_stdio( false );

	int N;
	cin >> N;

	vector<int> A( N );
	vector<int> B( N );
	vector<int> C( N-1 );
	for( auto& v: A ) { cin >> v; }
	for( auto& v: B ) { cin >> v; }
	for( auto& v: C ) { cin >> v; }

	int result = 0;
	int p = INT_MIN;

	for( int i = 0; i < N; ++i ) {
		int x = A[i] - 1;
		result += B[x];

		if( p+1 == x ) {
			result += C[p];
		}

		p = x;
	}

	cout << result << endl;
}


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

int main(){
  int n;
  cin >> n;
  vector<int> h(n);
  int ans = 0;
  for(int i = 0; i < n; i++){
    cin >> h.at(i);
    ans += h.at(i);
  }
  
  for(int i = 1; i < n; i++){
    int k = min(h.at(i), h.at(i-1));
    ans -= k;
  }
  
  cout << ans << endl;
}

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

struct UnionFind{
  vector<int> par;

  UnionFind(int N): par(N){
    for(int i=0;i<N;i++) par[i] = i;
  }

  int root(int x){
    if(par[x] == x) return x;
    return par[x] = root(par[x]);
  }

  void unite(int x, int y){
    int rx = root(x);
    int ry = root(y);
    if(rx==ry)return;
    par[rx] = ry;
  }

  bool same(int x, int y){
    int rx = root(x);
    int ry = root(y);

    return rx == ry;
  }

};


int main(){

  int N,Q,com,x,y;
  cin>>N>>Q;
UnionFind tree(N+1);

for(int i=0;i<Q;i++){
  cin>>com>>x>>y;
  if(com==0){
    tree.unite(x,y);
  }
  if(com==1){
    bool che = tree.same(x,y);
    if(che){
      cout<<1<<endl;
    }else{
      cout<<0<<endl;
    }
  }
}

}



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

typedef long long int ll;

#define FOR(i,n,m) for(ll i=(ll)(m);i<(ll)(n);++i)
#define REP(i,n) FOR(i,n,0)
#define IREP(i,n) for(ll i=(ll)(n);i>=0;--i)

const ll MOD = 1000000007;

using namespace std;

int main()
{
	ll N, M;
	cin >> N >> M;

	ll ans = 0;
	ans += min(N, M / 2);
	M -= ans * 2;

	ans += M / 4;

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

Measured memory_bytes: 256
// {{{
#include <iostream>
#include <iomanip>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <complex>
#include <vector>
#include <list>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <string>
#include <algorithm>
#include <numeric>
using namespace std;

#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define FOR(i, a, b) for(ll i = static_cast<ll>(a); i < static_cast<ll>(b); i++)
#define FORR(i, a, b) for(ll i = static_cast<ll>(a); i >= static_cast<ll>(b); i--)
#define REP(i, n) for(ll i = 0ll; i < static_cast<ll>(n); i++)
#define REPR(i, n) for(ll i = static_cast<ll>(n); i >= 0ll; i--)
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> IP;
typedef pair<ll, LP> LLP;

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

constexpr int INF = 100000000;
constexpr ll LINF = 10000000000000000ll;
constexpr int MOD = static_cast<int>(1e9 + 7);
constexpr double EPS = 1e-9;
// }}}

ll N, T;
ll t[200000];

void init()
{
}

void solve()
{
    ll ans = 0;
    FOR(i, 1, N){
        ans += min(T, t[i]-t[i-1]);
    }
    ans += T;
    cout << ans << endl;
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N >> T;
    REP(i, N) cin >> t[i];
    solve();
    return 0;
}

// vim:set foldmethod=marker:


Measured memory_bytes: 1792
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
/// <summary>
/// https://atcoder.jp/contests/dp/tasks/dp_d
/// </summary>
internal static class CR
{
    public static string GetText() { return Console.ReadLine(); }
    public static List<string> GetTexts() { return Console.ReadLine().Split(' ').ToList(); }
    public static long GetLong() { return long.Parse(Console.ReadLine()); }
    public static List<long> GetLongs() { return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToList(); }
}

namespace AtCoder.D
{
    public class Program
    {
        public static long N { get; private set; }
        public static long W { get; private set; }

        public static void Main() { var r = GetResult(); Debug.WriteLine(r); Console.Write(r); }

        private static object GetResult()
        {
            var inputs = CR.GetLongs();
            N = inputs[0];
            W = inputs[1];

            var items = new List<Item>() { new Item { Weight = 0, Value = 0 } };
            for (int i = 0; i < N; i++)
            {
                inputs = CR.GetLongs();
                items.Add(new Item
                {
                    Weight = inputs[0],
                    Value = inputs[1],
                });
            }

            var dp = new long[N + 1, W + 1];
            for (int n = 1; n <= N; n++)
            {
                var item = items[n];

                for (int w = 1; w <= W; w++)
                {
                    if (item.Weight <= w)
                    {
                        // 新たな荷物を選択可能な場合
                        dp[n, w] = Math.Max(dp[n - 1, w], dp[n - 1, w - item.Weight] + item.Value);
                    }
                    else
                    {
                        dp[n, w] = dp[n - 1, w];
                    }
                }
            }

            return dp[N, W];
        }
        class Item
        {
            public long Weight { get; set; }
            public long Value { get; set; }
        }
    }
}


Measured memory_bytes: 89184
class UnionFind:
    def __init__(self, n):
        self.par = [i for i in range(n)]
        self.rank = [0 for _ in range(n)]
        
    def find_root(self, x):
        if self.par[x] == x:
            return x
        self.par[x] = self.find_root(self.par[x])
        return self.par[x]
    
    def union(self, x, y):
        x_root = self.find_root(x)
        y_root = self.find_root(y)
        if x_root != y_root:
            if self.rank[x_root] < self.rank[y_root]:
                x_root, y_root = y_root, x_root
            if self.rank[x_root] == self.rank[y_root]:
                self.rank[x_root] += 1
            self.par[y_root] = x_root
            
    def is_same(self, x, y):
        x_root = self.find_root(x)
        y_root = self.find_root(y)
        return x_root == y_root
    
n,m=map(int,input().split())
xyz=[list(map(int,input().split())) for _ in range(m)]
xy=[[x-1,y-1] for x,y,z in xyz]
u=UnionFind(n)
for x,y in xy:
    u.union(x,y)
res=[]
for i in range(n):
    res.append(u.find_root(i))
print(len(set(res)))

Measured memory_bytes: 104408
#include <bits/stdc++.h>
#define ios ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
typedef long long ll;
#define pb push_back
#define ins insert
#define pll pair<ll,ll>
#define fi first
#define se second
#define mpr make_pair
#define vtr vector
#define itor iterator 
#define N ll(1e9+7)
#define endl '\n'
#define cont continue
using namespace std;
//ll power(ll a,ll b,ll mod)
//{
//	if(b==0)return 1;
//	ll ans=1;
//	while(b>0)
//	{
//		if(b&1)ans=(ans*a)%mod;
//		a=(a*a)%mod;
//		b>>=1;
//	}
//	return ans;
//}
int main()
{
	string s,t;
	cin>>s>>t;
	if(s==t.substr(0,s.size()))cout<<"Yes\n";else cout<<"No\n";	
}

Measured memory_bytes: 3580
#include <stdio.h>
int main(){
	int a,b,c,k,sum=0;
	scanf("%d%d%d%d",&a,&b,&c,&k);
	if(k<=a)return 0*printf("%d\n",k);
	if(k>a)sum+=a,k-=a;
	if(k<=b)return 0*printf("%d\n",sum);
	if(k>b)sum+=0,k-=b;
	return 0*printf("%d\n",sum-k);
	return 0;
}

Measured memory_bytes: 1728
#include <iostream>
#include <vector>
#include <algorithm>
#include <ctime>
#include <cmath>
#include <string>
#include <stdlib.h>
#include <fstream>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <iterator>
#include <iomanip>
using namespace std;


int main(){
    long long m, k, p = -1;
    cin >> m >> k;
    long long mm = 1 << m;
    if(k >= mm || (mm == 2 && k != 0)){
        cout << -1;
        return 0;
    }
    if(mm == 2 && k == 0){
        cout << "0 0 1 1";
        return 0;
    }
    vector<long long> a;
    for(int i = 0; i < mm; ++i){
        if(i != k){
            a.push_back(i);
        }
    }
    a.push_back(k);
    for(int j = mm - 1; j >= 0; --j){
        if(j != k){
            a.push_back(j);
        }
    }
    a.push_back(k);
    
    for(int i = 0; i < a.size(); ++i) cout << a[i] << " ";
}


Measured memory_bytes: 3952
n=int(input())
h=list(map(int,input().split()))
ans=0
count=0
hei=h[0]
for i in range(1,n):
    if hei>=h[i]:
        count+=1
    else:
        ans=max(ans,count)
        count=0
    hei=h[i]
print(max(ans,count))

Measured memory_bytes: 15020
/*#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>

#include <boost/rational.hpp>
*/
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
using ll = long long;
using ld = long double;
using pll = pair<ll,ll>;
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define rep3(i, n) for (ll i = 1; i < (ll)(n+1); i++)
#define rep4(i, s, n) for (ll i = (s); i < (ll)(n+1); i++)
#define repr(i,n) for (ll i = (n-1); i>=0;i--)
#define repr3(i,n) for(ll i = (n);i>0;i--)
#define repr4(i,s,n) for(ll i = (n);i>=(s);i--)
#define stlen(s) ll s.size()-1
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define cout(n) cout<<std::fixed<<std::setprecision(n)
using Graph = vector<vector<int>>;
using Graphw = vector<vector<pair<ll,ll>>>;
#define INF1  INT_MAX;
#define INF2  LLONG_MAX;
#define PI  3.14159265358979323846;
#define MOD 1000000007;
/*
namespace mp = boost::multiprecision;
// 任意長整数型
using Bint = mp::cpp_int;
// 仮数部長が32の浮動小数点数型
using Real32 = mp::number<mp::cpp_dec_float<32>>;
// 仮数部長が1024の浮動小数点数型
using Real1024 = mp::number<mp::cpp_dec_float<1024>>;
// 有理数型
using Rat = boost::rational<Bint>;
*/
const int mod = 1000000007;



int main(){
int N;
cin>>N;
int sil=0;
map<int,int> m;
rep(i,N){
    int a;
    cin>>a;
    if(a<3200){
        m[a/400]++;
    }
    else{
        sil++;
    }
}
if(sil>0){
    cout<<max(1,(int)m.size())<<" "<<(int)m.size()+sil<<endl;


}
else{
    cout<<m.size()<<" "<<m.size()<<endl;
}

return 0;
}

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

int main() {
  const vector<char> X = {'A', 'T', 'C', 'G'};
  string s;
  cin >> s;
  int ans = 0;
  int pre_ans = 0;
  bool matched = false;
  for(int i=0;i<s.size();++i) {
    for(char b : X) {
      if(s[i] == b) {
        matched = true;
        break;
      }else{
        matched = false;
      }
    }
    if(matched) ++pre_ans;
    else {
      if(ans<pre_ans) ans = pre_ans;
      pre_ans=0;
    }
    if(i==s.size()-1 && ans<pre_ans) ans = pre_ans;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <vector>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <iostream>
#include <string>
#include <cstring>

using namespace std;
#define vi vector<int>
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define SZ(x) (int)(x.size())
#define rep(i,a,b) for(int i=a;i<b;i++)
#define per(i,a,b) for(int i=b-1;i>=a;i--)
#define inf 1000000007
#define mod 1000000007
#define ull unsigned long long
#define ll long long
template <class T,class U>inline void Max(T &a,U b){if(a<b)a=b;}
template <class T,class U>inline void Min(T &a,U b){if(a>b)a=b;}


int K;
ll A[100005];

const pair<ll,ll> bad={-1,-1};

pair<ll,ll> solveMany(ll a, ll l, ll r) {
	ll cl = (
		(l%a==0)?l/a:(l/a+1)
		);
	ll cr = r/a;
	return (cl<=cr?
			make_pair(cl*a,cr*a+a-1)
			:
			bad);
}

pair<ll,ll> solve() {
	ll a = A[K]; ll l,r;
	l=r=2;
	for(int i=K;i>=1;--i){
		a = A[i];
		auto res = solveMany(a,l,r);
		l = res.first; r = res.second;
	}
	return {l,r};
}

int main(){
	ios_base::sync_with_stdio(false);cin.tie(NULL);
	cin >> K;
	for(int i=1;i<=K;++i) cin >> A[i];
	auto res = solve();
	if (res == bad) {
		cout << -1 << endl;
	} else {
		cout << res.first << " " << res.second << endl;
	}
}









Measured memory_bytes: 1024
#include<iostream>
using namespace std;
int main()
{
  int a,b,c;
  cin>>a>>b>>c;
  int res1=c*a;
  int res2=b/a;
  if(res1<b)
    cout<<c<<endl;
  else 
   cout<<res2<<endl;
   return 0;
}

Measured memory_bytes: 256
a,b,c=map(int,raw_input().split())
if a<=b :
    if b<=c:
        print a,b,c
    elif a<=c:
        print a,c,b
    else:
        print c,a,b
else :
    if a<=c:
        print b,a,c
    elif b<=c:
        print b,c,a
    else:
        print c,b,a
    

Measured memory_bytes: 6440
#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 int long long
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;

signed main(){
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, 0, n) cin >> a[i];
    int now = 1;
    rep(i, 0, n){
        now = a[now - 1];
        if(now == 2){
            cout << i + 1 << endl;
            return 0;
        }
    }
    cout << -1 << endl;
}

Measured memory_bytes: 1024
# https://atcoder.jp/contests/abc137/tasks/abc137_c
# C - Green Bin
import collections
import itertools
import math

n = int(input().split()[0])
s_list = []
c_list = []

for _ in range(n):
    s = input().split()[0]
    s_list.append(''.join(sorted(s)))

counter = collections.Counter(s_list)

def C(n, k):
    return math.factorial(n) / (math.factorial(k) * math.factorial(n-k))

p_list = [C(value, 2) for key, value in counter.items() if value > 1]
ans = int(sum(p_list))

print(ans)


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

using namespace std;	
typedef long long LL;
const int nn = 1e6 + 5;
int arr[nn];

int main() {
	int N, M, l, r, maks = 0, card;
	scanf("%d %d", & N, & M);
	for (int i = 0; i < M; i++) {
		scanf("%d %d", & l, & r);
		arr[l]++;
		arr[r + 1]--;	
	}
	for (int i = 1; i <= N; i++) {
		arr[i] += arr[i - 1];
		if (arr[i] > maks) {
			maks = arr[i];
			card = 1;
		} else if (arr[i] == maks) card++;
	}
	if (maks == M) printf("%d\n", card);
	else printf("0\n");
}

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

int ABC[3];
int counter5 = 0;
int counter7 = 0;

int main(){
    for(int i = 0;i < 3; ++i)cin >> ABC[i];
    if(ABC[0] == 5) ++counter5;
    if(ABC[0] == 7) ++counter7;
    if(ABC[1] == 5) ++counter5;
    if(ABC[1] == 7) ++counter7;
    if(ABC[2] == 5) ++counter5;
    if(ABC[2] == 7) ++counter7;
    if(counter5 == 2  && counter7 == 1){
        cout <<"YES";}
    else{
        cout <<"NO";
    }
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<vector>
using namespace std;
long long w[3][2], n, D[25100000];
struct point {
	long long A, B;
};
long long Get(int S, vector<point> V) {
	int i;
	for (i = 1; i <= S; i++) {
		D[i] = D[i - 1];
		for (auto &x : V) {
			if (x.A <= i)D[i] = max(D[i], D[i - x.A] + x.B);
		}
	}
	return D[S];
}
int main() {
	scanf("%lld", &n);
	int i, j;
	for (i = 0; i < 2; i++) {
		for (j = 0; j < 3; j++)scanf("%lld", &w[j][i]);
	}
	vector<point>V;
	for (i = 0; i < 3; i++) {
		if (w[i][0] < w[i][1]) {
			V.push_back({ w[i][0], w[i][1] - w[i][0] });
		}
	}
	n += Get(n, V);
	V.clear();
	for (i = 0; i < 3; i++) {
		if (w[i][0] > w[i][1]) {
			V.push_back({ w[i][1], w[i][0] - w[i][1] });
		}
	}
	n += Get(n, V);
	printf("%lld\n", n);
}

Measured memory_bytes: 195584
#pragma GCC optimize("Ofast")
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"

using namespace std;

using u8 = uint8_t;
using u16 = uint16_t;
using u32 = uint32_t;
using u64 = uint64_t;
using i8 = int8_t;
using i32 = int32_t;
using i64 = int64_t;
constexpr char newl = '\n';

template<typename T1, typename T2> inline void chmin(T1& a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define F0R(i,b) FOR(i,0,b)
#define RFO(i,a,b) for (int i = ((b)-1); i >=(a); i--)
#define RF0(i,b) RFO(i,0,b)
//#define F first
//#define S second
#define debug(x) cout << #x << ": " << x << '\n';
template<class T> void Print(vector<T> v) {
  F0R(i, v.size()) {
    cout << v[i] << ' ';
  }
  cout << newl;
}

#if 1


// INSERT ABOVE HERE
signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  string S;
  cin >> S;
  bool a = false, b = false;
  for (auto c : S) {
    c == 'A' ? a = true : c == 'B' ? b = true : 0;
  }
  cout << (a && b ? "Yes" : "No");
}
#endif


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

#ifdef ONLINE_JUDGE
    #define DEBUG(...) // Skip Debug
#else
    #define DEBUG(...) fprintf(stderr,__VA_ARGS__)
#endif

#define rep(i , l , r) for(int i = (l) , ___ = (r) ; i <= ___ ; ++i )
#define per(i , r , l) for(int i = (r) , ___ = (l) ; i >= ___ ; --i )

using namespace std;

string S;
int tot;

int main()
{
	cin >> S;
	rep(i , 0 , S.size()-1)
	{
		if(S[i] == '+') tot++;
		if(S[i] == '-') tot--;
	}
	cout << tot << endl;
    return 0;
}


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

typedef long long ll;

int a, b;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> a >> b;
    --a;
    int res = 1;
    int cnt = 0;
    while (res < b) {
        res += a;
        ++cnt;
    }
    cout << cnt << endl;

    return 0;
}



Measured memory_bytes: 3624
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>	// require sort next_permutation count __gcd reverse etc.
#include <cstdlib>	// require abs exit atof atoi 
#include <cstdio>		// require scanf printf
#include <functional>
#include <numeric>	// require accumulate
#include <cmath>		// require fabs
#include <climits>
#include <limits>
#include <cfloat>
#include <iomanip>	// require setw
#include <sstream>	// require stringstream 
#include <cstring>	// require memset
#include <cctype>		// require tolower, toupper
#include <fstream>	// require freopen
#include <ctime>		// require srand
#define rep(i,n) for(int i=0;i<(n);i++)
#define ALL(A) A.begin(), A.end()

using namespace std;

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

string itos (int n )
{
	string res = "";
	stringstream ss;
	ss << n;
	ss >> res;
	if (n < 10 ) res = '0' + res;

	return res;
}

string disp_time (int t )
{
	int h = t/60/60;
	int m = (t/60 % 60);
	int s = (t % 60);

	string res = "";
	res += itos (h );
	res += ':';
	res += itos (m );
	res += ':';
	res += itos (s );

	return res;
}

int main()
{
//	cut here before submit 
//	freopen ("testcase.Videotape", "r", stdin );
	while (1 ){
		int h, m, s;
		scanf ("%d %d %d", &h, &m, &s );
		if (h == -1 && m == -1 && s == -1 ) break;
		int total = h*60*60 + m*60 + s;
		int remain = 120*60 - total;
		string r = disp_time (remain );
		string r3 = disp_time (3*remain );
		cout << r << endl;
		cout << r3 << endl;
	} // end loop
		
	return 0;
}

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

string read(const vector<vector<int>> &dp, string s1, string s2, int i, int j) {

    if(i==0 || j==0) {
        return "";
    }

    if(s1[i-1] == s2[j-1]) {
        return read(dp, s1, s2, i-1, j-1) + s1[i-1];
    }

    if(dp[i-1][j] > dp[i][j-1]) {
        return read(dp, s1, s2, i-1, j);
    }

    return read(dp, s1, s2, i, j-1);

}

void lcs(string s1, string s2) {
    vector<vector<int>> dp(s1.size()+1, vector<int>(s2.size()+1));
    for(int i=0; i<s1.size()+1; i++) {
        for(int j=0; j<s2.size()+1; j++) {
            if(i==0 || j==0) {
                dp[i][j] = 0;
            }

            else if(s1[i-1] == s2[j-1]) {
                dp[i][j] = 1+dp[i-1][j-1];
            }

            else {
                dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
            }
        }

    }
    cout<<read(dp, s1, s2, s1.size(), s2.size());
}

int main() {
    string s1, s2;
    cin>>s1>>s2;

    lcs(s1,s2);

}

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

using namespace std;

#define all(x) (x).begin(), (x).end()
#define sz(x) ( (int)(x).size() )
using LL = long long;

const int mod = 3;
mt19937 rng( (int)chrono::steady_clock::now().time_since_epoch().count() );

struct Mint {
  int a;
  Mint(int _a = 0) : a(_a) {}
  friend ostream& operator << (ostream &out, const Mint &_) {
    out << _.a;
    return out;
  }

  bool operator == (const Mint &_) const { return a == _.a; }
  bool operator ! () const { return !a; }

  Mint operator + (const Mint &_) const {
    int ret = a + _.a;
    return ret < mod ? Mint(ret) : Mint(ret - mod);
  }
  Mint operator - (const Mint &_) const { return *this + Mint(mod - _.a); }
  Mint operator * (const Mint &_) const { return Mint( (int)( (LL)a * _.a % mod) ); }
  friend Mint& operator += (Mint &a, const Mint &b) { return a = a + b; }
  friend Mint& operator -= (Mint &a, const Mint &b) { return a = a - b; }
  friend Mint& operator *= (Mint &a, const Mint &b) { return a = a * b; }
  Mint& operator ++ () { return *this = *this + Mint(1); }
  Mint& operator -- () { return *this = *this - Mint(1); }

  template<class T> Mint binPow(T exp) const {
    Mint ret(1), c = *this;
    for (; exp; exp >>= 1, c *= c) if (exp & 1) ret *= c;
    return ret;
  }
};

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

  #ifdef FourLeafClover
  freopen("input", "r", stdin);
  #endif // FourLeafClover

  string s, t; cin >> s >> t;
  vector<Mint> prefS(sz(s) + 1), prefT(sz(t) + 1);
  for (int i = 0; i < sz(s); ++i) prefS[i + 1] = prefS[i] + Mint(s[i] == 'A' ? 1 : 2);
  for (int i = 0; i < sz(t); ++i) prefT[i + 1] = prefT[i] + Mint(t[i] == 'A' ? 1 : 2);

  int q; cin >> q;
  while (q--) {
    int beS, enS, beT, enT; cin >> beS >> enS >> beT >> enT; --beS; --beT;
    cout << (prefS[enS] - prefS[beS] == prefT[enT] - prefT[beT] ? "YES" : "NO") << '\n';
  }

  return 0;
}


Measured memory_bytes: 1744
import java.io._
import java.util.StringTokenizer
import scala.util.control.Breaks.{breakable,break}
import scala.collection.mutable.{Map, Stack, Queue, PriorityQueue, Set}

object Main extends App {
  val in = new InputReader(System.in)
  val pw = new PrintWriter(System.out)

  val N = in.next().toInt
  val A = new Array[Long](N+1)
  for (i <- 0 to N) {
    A(i) = in.next().toLong
  }

  //
  var flag = true
  val dpMax = new Array[Long](N+1)
  var cnt = 1L
  breakable {
    for (i <- 0 to N) {
      cnt -= A(i)
      if (cnt < 0) {
        flag = false
        break
      }

      dpMax(i) = cnt
      cnt = Math.min(cnt * 2, Long.MaxValue / 100)
    }
  }


  if (!flag)
    println(-1)
  else  {
    var ans = 0L
    var nodes = 0L

    breakable {
      for (i <- (0 to N).reverse) {
        val now = A(i)

        nodes = (nodes min dpMax(i)) + now
        ans += nodes
      }
    }

    if (!flag)
      println(-1)
    else
      println(ans)
  }
}

class InputReader(stream: InputStream) {
  private[this] val reader = new BufferedReader(new InputStreamReader(stream))
  private[this] var tokenizer: StringTokenizer = new StringTokenizer(reader.readLine())
  def next(): String = {
    while (!tokenizer.hasMoreTokens()) {
      tokenizer = new StringTokenizer(reader.readLine())
    }
    tokenizer.nextToken()
  }
}


Measured memory_bytes: 59672
#include<bits/stdc++.h>
using namespace std;
typedef pair<int, bool> PIB;

int dp[4001][4001];
int ans = 0;

int main()
{
  while(true){
    string s, t;
    cin >> s;
    if(!s.size())
      break;
    cin >> t;
    ans = 0;
    memset(dp, 0, sizeof dp);

    for(int i = 0; i < s.size(); i++)
      for(int j = 0; j < t.size(); j++)
	if(s[i] == t[j]){
	  dp[i + 1][j + 1] = dp[i][j] + 1;
	  ans = max(ans, dp[i + 1][j + 1]);
	}
    
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 63748
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
bool cmp(int a,int b){
	return a>b;
}
int main(){
	int n,m,a[110],sum=0,t,ans=0;
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]);
		sum+=a[i];
	}
	sort(a+1,a+1+n,cmp);
	if(sum%(4*m)==0){
		t=sum/(4*m);
	}
	else{
		t=sum/(4*m)+1;
	}
	for(int i=1;i<=n;i++){
		if(a[i]>=t){
			ans++;
		}
		else{
			break;
		}
	}
	if(ans>=m){
		printf("Yes\n");
	}
	else{
		printf("No\n");
	}
	return 0;
} 

Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vin=vector<int>;
using vll=vector<long long>;
using vdo=vector<double>;
using vvin=vector<vector<int>>;
using vvll=vector<vector<long long>>;
using vvdo=vector<vector<double>>;
using vstr=vector<string>;
using vvstr=vector<vector<string>>;
using vch=vector<char>;
using vvch=vector<vector<char>>;
using pqin=priority_queue<int>;
using pqsin=priority_queue<int,vector<int>,greater<int>>;
#define mp make_pair
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,s,n) for(int i=(s);i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define decp(n) cout<<fixed<<setprecision((int)n)
#define _GLIBCXX_DEBUG
int main(){
    int n;
    cin>>n;
    vin x(n),l(n);
    vector<pair<int,int>> p(n);
    rep(i,n){
        cin>>x[i]>>l[i];
        p[i]=mp(x[i]+l[i],x[i]-l[i]);
    }
    sort(all(p));
    int sum=1;
    int t=p[0].first;
    rep2(i,1,n){
        if(t<=p[i].second){
            sum++;
            t=p[i].first;
        }
    }
    cout<<sum<<endl;
}

Measured memory_bytes: 1920
#include<bits/stdc++.h>
using namespace std;
typedef int64_t ll;
typedef long double ld;
const ll MOD=1000000007;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define change(a,b) do{ll c=a; a=b; b=c;}while(0)
long long gcd(long long a,long long b){
    ll gcdmax=max(a,b);
    ll gcdmin=min(a,b);
    while(true){
        if(gcdmax%gcdmin==0)break;
        else gcdmax%=gcdmin;
        change(gcdmin,gcdmax);
    }
    return gcdmin;
}
ll powerup(ll N,ll P,ll M){
    if(P==0)return 1;
    else if(P%2==0){
        ll t=powerup(N,P/2,M);
        return t*t%M;
    }
    else return N*powerup(N,P-1,M)%M;
}
int main()
{
  ll N,M;
  cin>>N>>M;
  cout<<N*(N-1)/2+M*(M-1)/2<<endl;
}

Measured memory_bytes: 256
class UnionFind:

    def __init__(self, n):
        self.p = {i: i for i in range(n)}
        self.r = {i: 0 for i in range(n)}

    def root(self, x):
        if self.p[x] == x:
            return x
        self.p[x] = self.root(self.p[x])
        return self.p[x]

    def merge(self, x, y):
        x = self.root(x)
        y = self.root(y)
        if x == y:
            return
        if self.r[x] < self.r[y]:
            self.p[x] = y
        else:
            self.p[y] = x
            if self.r[x] == self.r[y]:
                self.r[x] += 1

    def cluster(self):
        c = {}
        for x in self.p:
            xx = self.root(x)
            if xx not in c:
                c[xx] = {x}
            else:
                c[xx].add(x)
        return c


def main():
    n, m = list(map(int, input().split()))
    pp = list(map(int, input().split()))
    uf = UnionFind(n)
    for _ in range(m):
        x, y = map(int, input().split())
        uf.merge(x - 1, y - 1)
    cc = uf.cluster()
    count = 0
    for clt in cc.values():
        p = set(pp[i] - 1 for i in clt)
        count += len(p & clt)
    print(count)


if __name__ == '__main__':
    main()


Measured memory_bytes: 121192
n, m = map(int, input().split())

even = m // 2
odd = m - even

odd_left = 1
odd_right = 2 * odd

even_left = odd_right + 1
even_right = even_left + 2 * even

for _ in range(odd):
    print(odd_left, odd_right)
    odd_left += 1
    odd_right -= 1

for _ in range(even):
    print(even_left, even_right)
    even_left += 1
    even_right -= 1


Measured memory_bytes: 9288
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 7+1e5;
typedef long long LL;
int n,m;
int Lmin[MAXN],Rmin[MAXN];
int a[MAXN];
 
void Read()
{
    //#define TASK "ABC"
    //freopen(TASK ".inp", "r", stdin); freopen(TASK ".out", "w", stdout);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> n;
    for(int i=1 ; i<=n ; ++i) cin >>a[i];
}
void Magic(){
	
	a[n+1] = MAXN;
	Lmin[0] = 0;
    Rmin[n] = n+1;
 
    for (int i=1; i<=n; ++i)
        if ( a[i] < a[i-1] ) Lmin[i] = i-1;
        else {
            int x = Lmin[i-1];
            while( a[x] < a[i] && x)
                x = Lmin[x];
            Lmin[i] = x;
        }
 
    for (int i=n-1; i; --i)
        if ( a[i] < a[i+1] ) Rmin[i] = i+1;
        else {
            int x = Rmin[i+1];
            while( a[x] < a[i] && x <= n)
                x = Rmin[x];
            Rmin[i] = x;
        }
}

void Solve(){
	
	LL ans = 0;
    for (int i=1; i<=n; ++i) {
        int cnt = 0,
            l = Lmin[i],
            r = Rmin[i];
        if ( l>0 ) {
            --l;
            while( a[l] < a[i] && l ) l = Lmin[l];
            cnt += (Rmin[i] - i )* (Lmin[i] - l);
        }
        if ( r<n+1 ) {
            ++r;
            while( a[r] < a[i] && r<=n) r = Rmin[r];
            cnt += (r - Rmin[i] )* (i - Lmin[i]) ;
        }
        ans += LL(cnt)*a[i];
    }
    
    cout <<ans;
}

int main(){
	
	Read();
	Magic();
	Solve();
	return 0;
	
}
 
    


Measured memory_bytes: 4832
#include<iostream>
#include<string>
#include<cmath>

using namespace std;

int ans = 0;

bool is753(int a, int n){
    int b[3] = {0,0,0};
    if (a > n || a == 0) {
        return false;
    }
    

    while(a > 0){
        int m = a % 10;
        if (m == 3) {
            b[0]++;
        }else if (m == 5) {
            b[1]++;
        }else{
            b[2]++;
        }
        a /= 10;
    }
    for(int i = 0; i < 3; i++){
        if (b[i] == 0) {
            return false;
        }
        
    }
    return true;
    
}

void gene(int a, int keta, int n){
    if (keta == 10){
        return ;
    }
    if (is753(a, n)){
        ans++;
    }
    int c[3] = {3,5,7};
    for(int i = 0; i < 3; i++){
        int d = 10 * a + c[i];
        gene(d, keta + 1, n);
    }
    
}

int main(){
    int n;
    cin >> n;
    gene(0, 0, n);
    cout << ans << '\n';


    
    

    
    
    
    

}

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



int main() 
{
  ll N;
  cin >> N;
  vector<ll> queue(N);
  vector<ll> queue2(N);
  rep (i,N)
  {
    cin >> queue.at(i);
  }
  ll count = 0,recount = 0;
  rep (i,100)
  {
    recount = count;
    rep(j,N)
    {
      if (queue.at(j) == 100 - i)
      {
        count++;
      }
    }
    rep (j,count - recount)
    {
      queue2.at(j + recount) = 100 - i;
    }
  }
  //rep(i,N){cout << queue2.at(i);};
  ll a = 0,b = 0;
    rep(i,(N + 1) / 2)
    {
      a += queue2.at(2 * i);
    }
    rep(i,N / 2)
    {
      b += queue2.at(2 * i + 1);
    }
  cout << a - b << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef set<int> si;
typedef set<ll> sl;
typedef pair<int,int> pii;
#define rep(i,a,b) for(int i=(a); i<(b); ++i)
#define per(i,a,b) for(int i=(b)-1; i>=(a); --i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define F first
#define S second

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

int main(void) {
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	//freopen("in.txt", "r", stdin);
	ll n, k;
	cin >> n >> k;
	vl v(n);
	rep(i,0,n) {
		cin >> v[i];
	}

	ll maxNum = 0;
	rep(i,0,n) {
		maxNum = max(maxNum, v[i]);
	}
	if(maxNum < k) {
		cout << "IMPOSSIBLE" << endl;
		return 0;
	}
	ll g = v[0];
	rep(i,0,n) {
		g = gcd(g, v[i]);
	}
	if(k % g) {
		cout << "IMPOSSIBLE" << endl;
	} else {
		cout << "POSSIBLE" << endl;
	}
	return 0;
}

Measured memory_bytes: 1024
import java.util.Scanner;

class Main {
    static public void main(String args[]){

        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();

        String s = scan.next();
        int west[] = new int[n+1];
        int east[] = new int[n+1];

        west[0] = 0;
        east[n] = 0;

        for(int i = 0; i < n; i++){
            if(s.charAt(i) == 'W'){
                west[i+1] = west[i]+1;
            }
            else{
                west[i+1] = west[i];
            }

            if(s.charAt(n-1-i) == 'E'){
                east[n-1-i] = east[n-i]+1;
            }
            else{
                east[n-1-i] = east[n-i];
            }
        }

        int min = (int)1e9;
        int sum;
        for(int i = 0; i < n; i++){
            sum = west[i]+east[i+1];
            if(sum < min)min = sum;
        }
        System.out.println(min);

    }
}


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

int main(){
	int a,b,c,d;
	cin >> a >> b >> c >> d;
  	if ((a+b) > (c+d))
      cout << " Left" << endl;
    else if ((a+b)==(c+d))
		cout << "Balanced" <<endl;
  	else 
      cout << "Right" <<endl;
}

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

int main() {
	int xa, ya, xb, yb;
	cin >> xa >> ya >> xb >> yb;
	cout << xb+ya-yb << endl;
	cout << xb+yb-xa << endl;
	cout << xa+ya-yb << endl;
	cout << xb+ya-xa << endl;
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define INF ((1LL<<62)-(1LL<<31))
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define bit(n,m)(((n)>>(m))&1)
int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}
ll pom(ll a,ll n,int m){ll x=1;for(a%=m;n;n/=2)n&1?x=x*a%m:0,a=a*a%m;return x;}
//#define MOD 998244353
#define MOD 1000000007
#define invp(a,p)pom(a,p-2,p)

ll n,m;
char s[99];
int main(){
	scanf("%lld%lld%s",&n,&m,s);
	rep(i,0,n)putchar(s[i]^(i+1==m?32:0));
}

Measured memory_bytes: 128
Q = int(input())
import math
le = [0]*Q
for i in range(Q):
    le[i]=list(map(int, input().split()))

# print(le)
def is_prime(n):
    if n <= 1: return False

    for k in range(2, int(math.sqrt(n)) + 1):
        if n % k == 0:
            return False

    return True





list2017 = [0]*(10**5+1)
sum = 0
for i in range(0,10**5+1):
    if is_prime(i) and is_prime((i+1)//2) and i%2!=0:
        sum += 1
    list2017[i]=sum 
        


# print(list2017[:10])

for i in range(Q):
    print(list2017[le[i][1]]-list2017[le[i][0]-1])





Measured memory_bytes: 29056
#include <iostream>
#include <cmath>
#include <algorithm>

using namespace std;

int n,hx,hy,dx,dy;

float dist[21][21];
struct Crystal{
    int x,y;
    float dist;
    bool visited;
};
Crystal crystals[21];//[0]????????????????????????????????????

bool rec(int s,float t){
    crystals[s].visited=true;
    bool b=true;
    for(int i=1;i<=n;i++){
        if(crystals[i].visited) continue;
        if(dist[i][s]+t<crystals[i].dist){
            if(rec(i,dist[i][s]+t)){
                //cout << s << ",";
                return true;
            }else{
                b=false;
            }
        }else{
            //???????????????????????????????????£??????
            crystals[s].visited=false;
            return false;
        }
    }
    //??¨???????????????????????????????????????
    //cout << s << ",";
    crystals[s].visited=false;
    return b;
}

int main(void){
    while(cin >> n >> crystals[0].x >> crystals[0].y >> dx >> dy,n){
        for(int i=1;i<=n;i++){
            cin >> crystals[i].x >> crystals[i].y;
            crystals[i].dist=sqrt(pow(crystals[i].x-dx,2)+pow(crystals[i].y-dy,2));
        }
        sort(crystals+1,crystals+n+1,[](const Crystal& a, const Crystal& b){return (a.dist==b.dist)?(a.x<b.x):(a.dist)<(b.dist);});
        for(int i=0;i<=n;i++){
            crystals[i].visited=false;
            for(int k=i+1;k<=n;k++){
                dist[i][k]=dist[k][i]=sqrt(pow(crystals[i].x-crystals[k].x,2)+pow(crystals[i].y-crystals[k].y,2));
            }
        }
        if(rec(0,0)){
            cout << "YES" << endl;
        }else{
            cout << "NO" << endl;
        }
    }
    return 0;
}

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

typedef long long ll;
ll mod = 1000000007;

int main() {
    ll h;
    scanf("%lld",&h);
    ll ans = 0;
    ll tmp = 1;
    while (h > 0) {
        ans += tmp;
        h /= 2;
        tmp *= 2;
    }
    printf("%lld\n",ans);
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        ArrayList<Integer> result = new ArrayList<Integer>();
        String operand;
        int a, b;
        label:
            while(sc.hasNextLine()){
                a = sc.nextInt();
                operand = sc.next();
                b = sc.nextInt();
                if((operand.charAt(0) == '/') && (b == 0)){
                    System.out.println("ゼロ除算");
                    System.exit(0);
                }
                switch(operand.charAt(0)){
                case '+' :
                    result.add(a + b);
                    break;
                case '-' :
                    result.add(a - b);
                    break;
                case '*' :
                    result.add(a * b);
                    break;
                case '/' :
                    result.add(a / b);
                    break;
                case '?' :
                    break label;
                default:
                    System.out.println("不正なオペランド");
                }
            }
         
            for(int i = 0; i < result.size(); i++){
                System.out.println(result.get(i));
            }
        }
     
}


Measured memory_bytes: 26008