akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace ConsoleApp2
{
    class Program
    {
        static void Main(string[] args)
        {
            var NMX = Console.ReadLine().Split().Select(s=>int.Parse(s)).ToArray();
            var N = NMX[0];
            var M = NMX[1];
            var X = NMX[2];
            var ca = new List<int[]>();
            for(var i=0;i<N;i++)
            {
                ca.Add(Console.ReadLine().Split().Select(s => int.Parse(s)).ToArray());
            }
            var ans = int.MaxValue;
            for(var i=0;i<(1<<N);i++)
            {
                var skills = new int[M];
                var cost = 0;
                for(var bt=1;bt<(1<<N);bt=bt<<1)
                {
                    var tmpbt = i & bt;
                    if(tmpbt != 0)
                    {
                        for(var k=0; ;k++)
                        {
                            if(tmpbt==1)
                            {
                                for(var z = 0;z<M;z++)
                                {
                                    skills[z] += ca[k][z+1];
                                }
                                cost += ca[k][0];
                                break;
                            }
                            tmpbt = tmpbt >> 1;
                        }
                    }
                }
                if (skills.All(sk => sk >= X))
                {
                    ans = Math.Min(ans, cost);
                }
            }
            Console.WriteLine(int.MaxValue == ans ? -1 : ans);
        }
    }
}

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

int main() {
  string S;
  cin >> S;
  if(S.at(0) == S.at(1) && S.at(1) != S.at(2) && S.at(2) == S.at(3)){
    cout << "Yes" << endl;
  }
  else if(S.at(0) == S.at(2) && S.at(3) != S.at(2) && S.at(1) == S.at(3)){
    cout << "Yes" << endl;
  }
  else if(S.at(0) == S.at(3) && S.at(1) != S.at(0) && S.at(1) == S.at(2)){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}




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

int main() {
	int n;
	cin >> n;
	ll mi;
	cin >> mi;
	ll ans = -1e10;
	for (int i = 0; i < n-1; ++i)
	{
		ll r;
		cin >> r;
		ans = max(ans, r-mi);
		mi = min(r, mi);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3100
N, M = map(int, input().split())
D = [[] for i in range(N)]

for i in range(M):
    p, y = map(int, input().split())
    D[p-1].append((y, i))

ans = [None]*M

for i, d in enumerate(D):
    d.sort()
    for k, (y, j) in enumerate(d):
        ans[j] = "%06d%06d" % (i+1, k+1)
    
print(*ans, sep='\n')

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

using namespace std;


char data[24][6] = {{0, 1, 2, 3, 4, 5}, {0, 3, 1, 4, 2, 5}, {0, 4, 3, 2, 1, 5}, {0, 2, 4, 1, 3, 5},
		    {1, 5, 2, 3, 0, 4}, {1, 3, 5, 0, 2, 4}, {1, 0, 3, 2, 5, 4}, {1, 2, 0, 5, 3, 4},
		    {2, 5, 4, 1, 0, 3}, {2, 1, 5, 0, 4, 3}, {2, 0, 1, 4, 5, 3}, {2, 4, 0, 5, 1, 3},
		    {3, 5, 1, 4, 0, 2}, {3, 4, 5, 0, 1, 2}, {3, 0, 4, 1, 5, 2}, {3, 1, 0, 5, 4, 2},
		    {4, 5, 3, 2, 0, 1}, {4, 2, 5, 0, 3, 1}, {4, 0, 2, 3, 5, 1}, {4, 3, 0, 5, 2, 1},
		    {5, 4, 2, 3, 1, 0}, {5, 3, 4, 1, 2, 0}, {5, 1, 3, 2, 4, 0}, {5, 2, 1, 4, 3, 0}};
string dice[8];
bool used[8];
int id[8][3] = {{},
		{0},
		{0},
		{1, 2},
		{0},
		{1, 4},
		{2, 4},
		{3, 5, 6}};
int face[8][3] = {{},
		  {2},
		  {5},
		  {5, 2},
		  {4},
		  {4, 2},
		  {4, 5},
		  {4, 5, 2}};
int size[8] = {0, 1, 1, 2, 1, 2, 2, 3};
pair<int, int> now[8];

bool solve(int pos){
  if(pos == 8) return true;
  for(int i=0;i<8;i++){
    if(used[i]) continue;
    used[i] = true;
    for(int j=0;j<24;j++){
      bool f = true;
      for(int k=0;k<size[pos];k++){
	int idx = id[pos][k];
	char a = dice[now[idx].first][data[now[idx].second][face[pos][k]]];
	char b = dice[i][data[j][5-face[pos][k]]];
	if(a>b){
	  if(a-b != 'a'-'A') f = false;
	}else{
	  if(b-a != 'a'-'A') f = false;
	}
      }
      if(!f) continue;
      now[pos] = make_pair(i, j);
      if(solve(pos+1)) return true;
    }
    used[i] = false;
  }
  return false;
}

main(){
  while(cin >> dice[0]){
    if(dice[0] == "0") break;
    for(int i=1;i<8;i++){
      cin >> dice[i];
    }
    fill(used, used+8, false);
    cout << (solve(0)?"YES":"NO") << endl;
  }
  return 0;
}

Measured memory_bytes: 896
#include <iostream>
#include <vector>
#include<algorithm>
#include <string>
#include <set>
#include <limits.h>
#include <map>
#include <queue>
#include <stack>

using namespace std;

#define rip(i,n,s) for (int i=(s);i<(int)(n);i++)
#define all(a) (a).begin(),(a).end()
typedef long long ll;
typedef pair<int,int> P;

int n,k;

ll cal(set<int> &da, int si){
    if (da.size() < k){
        return LLONG_MAX;
    }
    int ret = INT_MAX;
    auto fo = da.begin(),ba = da.begin();
    int no=1;
    while (fo!=da.end()){
        //printf("%d\n",*fo);
        if(no < k){
            fo++;
            no++;
        }else{
            ret=min(ret,*fo-*ba);
            fo++;
            ba++;
        }
    }
    if (ret==INT_MAX){
        return LLONG_MAX;
    }
    return (ll) si * ret;
}

int main(){
    cin >> n >> k;
    vector <P> x (n), y (n);
    ll ans=LLONG_MAX;
    rip(i,n,0){ 
        cin >> x[i].first >> y[i].first;
        x[i].second = i;
        y[i].second = i;
    }
    sort(all(x));
    set<int> se;
    vector <bool> ju(n, false);
    rip(i, n, 0){
        rip(j,n,i+1){
            se.clear();
            rip(k,j+1,i){
                se.insert(y[x[k].second].first);
            }
            ans = min (ans,cal(se, x[j].first-x[i].first));
        }
    }
    printf("%lld\n",ans);
}

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

#if __has_include("print.hpp")
  #include "print.hpp"
#endif

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define MOD 1000000007

typedef long long ll;
typedef pair<ll, ll> p;


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  ll res = 0;
  for (int i = 1; i < ceil(double(n)/2.0); i++) {
    if(2 * i == n) continue;
    if(i > n - i) continue;
    res++;
  }
  cout << res << endl;
}


Measured memory_bytes: 256
import sys
import math
MAX_INT = int(10e15)
MIN_INT = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

N = I()
s, t = SL()

ans = ""
for ss,tt in zip(s,t):
  ans += ss
  ans += tt
print(ans)

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

using namespace std;
typedef pair<int,int> pii;
typedef long long int ll;

#define INF 1 << 29
#define REP(i,n) for(ll i=0; i<(int)(n); i++)
#define FOR(i,k,n) for(ll i=(k);i<(int)(n);i++)



vector<bool> gen_sosuu(vector<bool> sosuu){
  int size = sosuu.size();
  REP(i,size){
    sosuu[i] = true;
  }
  sosuu[0] = false;
  sosuu[1] = false;
  sosuu[2] = true;
  FOR(i,2,sqrt(size)+1){
    if(sosuu[i] == false) continue;
    for(int j = 2; i*j<size;j++){
      sosuu[i*j] =false;
    }
  }
  return sosuu;
}

string s;

int ans = 0;
int g = 0,p = 0;

int main(){
  cin >> s;
  REP(i,s.size()){
    if(s[i]=='g'){
      if(g>p){
        ans++;
        p++;
      }else{
        g++;
      }
    }else{
      if(g>p){
        p++;
      }else{
        ans--;
        g++;
      }
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 512
N = int(input())
S = list(input())

count = 0

if N >= 3:
    for i in range(N - 1):
        if (i + 2) < N and S[i] == 'A' and S[i + 1] == 'B' and S[i + 2] == 'C':
           count += 1
    print(count)
else:
    print(0)



Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define pb push_back
#define F first
#define S second
#define MAX_N 100000 + 100
using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
const int maxn = 53;
ll seq[maxn];
int main(){
    ll k;
    cin >> k;
    if (k == 0){
        cout << 2 << endl;
        cout << 0 << ' ' << 0 << endl;
        return 0;
    }
    if (k == 1){
        cout << 2 << endl;
        cout << 0 << ' '  << 2 << endl;
        return 0;
    }
    if (k <= 50){
        cout << k << endl;
        for (int i = 1;i <= k;i++) cout << i << ' ';
        cout << endl;
        return 0;
    }
    ll ks = k / 50;
    ks--;
    ll a = 1;

    for (int i = 1;i <= 50;i++){
        seq[i] = (i + ks);
    }
    k %= 50;
    for (int i = 0;i < k;i++){
        int index = 50 - i;
        seq[index]++;
    }
    cout << 50 << endl;
    for (int i = 1;i <= 50;i++) cout << seq[i] << ' ';
    cout << endl;
    return 0;
}


Measured memory_bytes: 256
#pragma warning disable

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.Serialization.Formatters.Binary;
using System.Text;
using System.Text.RegularExpressions;
using System.Diagnostics;
using System.Numerics;
using System.Collections;
using System.Timers;

static class MainClass
{
    public static void Main(string[] args)
    {
        var a = Console.ReadLine().ToInt32();
        var b = Console.ReadLine().ToInt32();
        var h = Console.ReadLine().ToInt32();
        Console.WriteLine((a + b) * h / 2);
    }



    #region ライブラリ
    public static long ToInt64(this string str) => long.Parse(str);
    public static int ToInt32(this string str) => int.Parse(str);
    public static BigInteger ToBigInteger(this string str) => BigInteger.Parse(str);
    public static List<string> SplittedStringToList(this string str) => str.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).ToList();
    public static List<int> SplittedStringToInt32List(this string str) => str.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Select(x => int.Parse(x)).ToList();
    public static List<BigInteger> SplittedStringToBigInteger(this string str) => str.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Select(x => BigInteger.Parse(x)).ToList();

    public const int INF = int.MaxValue / 2;
    #endregion
}


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

int64_t MOD = 1e9+7;

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

  // dp[i][0]: 先頭からi桁について，A+B<Sが確定している(a,b)の数
  // dp[i][1]: 先頭からi桁について，A+BとSが一致している(a,b)の数
  vector<vector<int64_t>> dp(1000010, vector<int64_t>(2, 0));
  dp[1][0] = 1;  dp[1][1] = 2;

  for(int i=1; i<S.length(); i++){
    int d = S[i] - '0'; //現在の桁
    for(int da = 0; da<=1; da++){ // aの次の桁が da=0,1
      for(int db = 0; db<=1; db++){ // bの次の桁が db=0,1
        if(da == 1 && db == 1) continue;
        dp[i+1][0] += dp[i][0];

        if(da + db == d){
          dp[i+1][1] += dp[i][1];
        } else if (da + db < d){
          dp[i+1][0] += dp[i][1];
        }

        dp[i+1][0] %= MOD; dp[i+1][1] %= MOD;
      }
    }
  }

  cout << (dp[S.length()][0] + dp[S.length()][1]) % MOD << endl;
}

Measured memory_bytes: 55040
#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
  int n;
  cin>>n;
  int a[n];
  for(int i=0;i<n;i++) cin>>a[i];
  cout<<*max_element(a,a+n)-*min_element(a,a+n)<<endl;
  return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define EPS (1e-7)
#define INF (1e9)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
const double PI = acos(-1);
const ll MOD = 1000000007;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}
 
template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
///////////////////////////////////////////////////////////////

class UnionFind {
public:
  vector <ll> par;
  vector <ll> siz;
  UnionFind(ll sz_): par(sz_), siz(sz_, 1LL) {
	for (ll i = 0; i < sz_; ++i) par[i] = i;
  }
  void init(ll sz_) {
	par.resize(sz_);
	siz.assign(sz_, 1LL);
	for (ll i = 0; i < sz_; ++i) par[i] = i;
  }
  ll root(ll x) {
	while (par[x] != x) {
	  x = par[x] = par[par[x]];
	}
	return x;
  }
	bool merge(ll x, ll y) {
		x = root(x);
		y = root(y);
		if (x == y) return false;
		if (siz[x] < siz[y]) swap(x, y);
		siz[x] += siz[y];
		par[y] = x;
		return true;
	}
	bool issame(ll x, ll y) {
		return root(x) == root(y);
	}
	ll size(ll x) {
		return siz[root(x)];
	}
};

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
	int N; cin >> N;
	vector<vector<ll>> A(N, vector<ll>(N));
	rep(i,N) rep(j,N) cin >> A[i][j];

	priority_queue<tuple<ll, int, int>, vector<tuple<ll, int, int>>, greater<tuple<ll, int, int>>> pq;
	rep(i,N-1) for (int j = i+1; j < N; j++) pq.emplace(A[i][j],i,j);
    
	vector<vector<ll>> G(N, vector<ll>(N,1e15));
	UnionFind uf(N);
	bool ok = true;
	rep(i,N) G[i][i] = 0;
	ll ans = 0;
	while(!pq.empty()) {
		ll l; int p,q;
		tie(l,p,q) = pq.top(); pq.pop();
		if (uf.issame(p,q)) {
			if (l > G[p][q]) {
				ok = false;
				break;
			} else if (l < G[p][q]){
				G[p][q] = G[q][p] = l;
                ans += l;
				rep(i,N) {
					rep(j,N) {
						chmin(G[i][j], G[i][p] + l + G[q][j]);
						chmin(G[i][j], G[i][q] + l + G[p][j]);
						G[j][i] = G[i][j];
					}
				}
			}
		} else {
			uf.merge(p,q);
			G[p][q] = G[q][p] = l;
			ans += l;
			rep(i,N) {
				rep(j,N) {
					chmin(G[i][j], G[i][p] + l + G[q][j]);
					chmin(G[i][j], G[i][q] + l + G[p][j]);
					G[j][i] = G[i][j];
				}
			}
		}
	}

	cout << (ok ? ans : -1) << endl;
}


Measured memory_bytes: 2428
#include<iostream>
#include<cstdio>
using namespace std;
const int N=100005;
int n,l,a[N],mx,w;
int read()
{
	int r=0,f=1;
	char p=getchar();
	while(p<'0'||p>'9')
	{
		if(p=='-')
			f=-1;
		p=getchar();
	}
	while(p>='0'&&p<='9')
	{
		r=r*10+p-48;
		p=getchar();
	}
	return r*f;
}
int main()
{
	n=read(),l=read();
	for(int i=1;i<=n;i++)
	{
		a[i]=read();
		if(a[i]+a[i-1]>mx)
			mx=a[i]+a[i-1],w=i;
	}
	if(mx<l)
	{
		puts("Impossible");
		return 0;
	}
	puts("Possible");
	for(int i=1;i<=w-2;i++)
		printf("%d\n",i);
	for(int i=n-1;i>=w;i--)
		printf("%d\n",i);
	printf("%d\n",w-1);
	return 0;
}

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

#include <algorithm>
#include <cstdio>
#include <functional>
#include <vector>

using namespace std;

typedef long long ll;
#define all(x) (x).begin(), (x).end()
#define lim 100010
#define mod 1e9 + 7
#define INF 1e9
#define REP(i, n) for (int i = 0; i < n; i++)

ll GCD(int x, int y) { return x % y == 0 ? y : GCD(y, x % y); }

bool is_prime(int x) {
  if (x <= 1) return false;
  for (int i = 2; i * i <= x; i++) {
    if (x % i == 0) return false;
  }
  return true;
}

int main() {
  int X;
  scanf("%d", &X);
  int ans = X;
  while (!is_prime(ans)) ans++;
  printf("%d", ans);

  return 0;
}

Measured memory_bytes: 256
# coding: utf-8
# Your code here!
s=list(input())
cnt=''
ans='NO'
for i in range(len(s)):
    for j in range(len(s)):
        if i<=j<=i+len(s)-8:
            continue
        cnt+=s[j]
    #print(cnt)
    if cnt=='keyence':
        ans='YES'
        break
    else:
        cnt=''
print(ans)

Measured memory_bytes: 38768
import Numeric

showF f = showFFloat Nothing f ""
readNums = fmap (map read . words) getLine

infinity = read "Infinity"

minkowskiDistance :: (RealFloat a, Floating a, Ord a) => a -> [a] -> [a] -> a
minkowskiDistance p xs ys | isInfinite p =
  maximum $ map abs $ zipWith (-) xs ys
                          | otherwise =
  (sum [(abs a)**p | a <- zipWith (-) xs ys]) ** (1/p)

main = do
  _ <- getLine
  xs <- readNums
  ys <- readNums
  putStrLn $ showF $ xs `manhattanDistance` ys
  putStrLn $ showF $ xs `euclidDistance` ys
  putStrLn $ showF $ minkowskiDistance 3 xs ys
  putStrLn $ showF $ xs `chebyshevDistance` ys
    where
      manhattanDistance = minkowskiDistance 1
      euclidDistance = minkowskiDistance 2
      chebyshevDistance = minkowskiDistance infinity

Measured memory_bytes: 4460
#include <bits/stdc++.h>
using namespace std;
bool mem[500][500];
bool lis[500];
int n,m,kazu;
int kazoe(){
    for(int i=0;i<n;i++){
        if(mem[0][i]==1){
            lis[i]=1;
            for(int j=0;j<n;j++){
                if(mem[i][j]==1){
                    lis[j]=1;
                }
            }
        }
    }

}
int main(){
    while(1){
        kazu=0;
        fill(lis,lis+500,0);
        for(int i=0;i<500;i++){
            for(int j=0;j<500;j++){
                mem[i][j]=0;
            }
        }
        cin>>n;
        cin>>m;
        if(n+m==0)break;
        int a,b;
        for(int i=0;i<m;i++){
            cin>>a>>b;
            mem[a-1][b-1]=1;
            mem[b-1][a-1]=1;
        }


        kazoe();
        lis[0]=0;
        for(int i=0;i<n;i++){
            if(lis[i]==1){kazu++;}
        }
        cout<<kazu<<endl;
    }
}

Measured memory_bytes: 3248
#include<iostream>

using namespace std;

int main(void) {

    int N, Y;
    int res10000 = -1, res5000 = -1, res1000 = -1;

    cin >> N >> Y;

    for (int i = 0; i <= N; i++) {
        for (int j = 0; j <= N - i; j++) {
            int k = N - i - j;

            if (Y==i*10000 + j*5000 + k*1000) {
                res10000 = i;
                res5000 = j;
                res1000 = k;
            }

        }
    }

    cout << res10000 << " " << res5000 << " " << res1000 << endl;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
	int a[31];
	for(int i=0;i<31;i++){
		a[i] = i;
	}
	int w,n;
	cin >> w;
	cin >> n;
	int k,l;
	while(scanf("%d,%d",&k,&l)+1){
		a[0] = a[k];
		a[k] = a[l];
		a[l] = a[0];
	}
	for(int i=1;i<=w;i++){
		cout << a[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 0
/**
 * @copyright (c) 2020 Daisuke Hashimoto
 */

#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
using Pair = pair<int64_t, int64_t>;

// std::cout << std::setprecision(20) << 1.1 << endl;

int64_t MyPow(const int64_t a, const int64_t b) {
  if (b == 0LL) {
    return 1LL;
  } else if (b == 1LL) {
    return a;
  } else if (a == 1LL) {
    return 1LL;
  } else if (a > static_cast<int64_t>(INT32_MAX)) {
    return -1;
  }
  int64_t result = MyPow(a * a, b / 2LL);
  if (b % 2LL == 1LL) {
    result *= a;
  }
  return result;
}

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

  int64_t result = 1LL;
  int64_t N, P;
  cin >> N >> P;
  int64_t max_a = static_cast<int64_t>(pow(static_cast<double>(P), 1.0 / static_cast<double>(N))) + 1;
  for (int64_t a = max_a; a >= 2LL; --a) {
    if (P % a == 0LL) {
      const int64_t a_n = MyPow(a, N);
      if (a_n < 0) {
        result = 1;
        break;
      } else if (P % a_n == 0LL) {
        result = a;
        break;
      }
    }
  }
  cout << result << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <fstream>
#include <sstream>
#include <iomanip>
#define ll long long

using namespace std;

long long MOD = 1000000007;

int main(){
    ll K;
    cin >> K;
    ll tmp=7;
    ll fact=70;
    for(int i=1; i<=2*K; i++){
        if(tmp%K==0){
            cout << i << endl;
            return 0;
        }
        tmp=(tmp+fact)%K;
        fact=(fact*10)%K;
    }
    cout << -1 << endl;
}

Measured memory_bytes: 3632
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Numerics;

namespace AtCoderWorkspace
{
    public class Solver
    {
        public void Solve()
        {
            var cin = new Scanner();
            var n = cin.nextInt();
            
            Console.WriteLine((n==3||n==5||n==7)? "YES":"NO");
        }
    }

    class Scanner
    {
        string[] s;
        int i;

        char[] cs = new char[] { ' ' };

        public Scanner()
        {
            s = new string[0];
            i = 0;
        }

        public string next()
        {
            if (i < s.Length) return s[i++];
            string st = Console.ReadLine();
            while (st == "") st = Console.ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            if (s.Length == 0) return next();
            i = 0;
            return s[i++];
        }

        public int nextInt()
        {
            return int.Parse(next());
        }
        public int[] ArrayInt(int N, int add = 0)
        {
            int[] Array = new int[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextInt() + add;
            }
            return Array;
        }

        public int[] DPArrayInt(int N, int ex)
        {
            int[] Array = new int[N + ex];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextInt();
            }
            return Array;
        }

        public long nextLong()
        {
            return long.Parse(next());
        }

        public long[] ArrayLong(int N, long add = 0)
        {
            long[] Array = new long[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextLong() + add;
            }
            return Array;
        }

        public long[] DPArrayLong(int N, int ex)
        {
            long[] Array = new long[N + ex];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextLong();
            }
            return Array;
        }

        public double nextDouble()
        {
            return double.Parse(next());
        }


        public double[] ArrayDouble(int N, double add = 0)
        {
            double[] Array = new double[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextDouble() + add;
            }
            return Array;
        }
    }

    class Program
    {
        static void Main(string[] s) => new Solver().Solve();
    }
}


Measured memory_bytes: 11092
#include <iostream>
#include <math.h>
using namespace std;

void check_composite(int &n, int &count) {
    
    for(int i = 2; i <= floor(sqrt(n)); i++) {
        if(n % i == 0) {
            count++;
            break;
        }
    }
    return;
}
int main() {
    int num;
    cin >> num;
    int n, count;
    for(int j = 0; j < num; j ++) {
        cin >> n;
        check_composite(n, count);
    }
    cout << num - count << endl; 
}


Measured memory_bytes: 3112
#include <bits/stdc++.h>
#define SORT(x) sort((x).begin(), (x).end())
#define RSORT(x) sort((x).rbegin(), (x).rend())
#define ALL(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < n; i++)
#define reps(i, m, n) for (ll i = m; i < n; i++)
#define repr(i, m, n) for (ll i = m; i >= n; i--)
#define de(x) cout << #x << "=" << x << endl;
#define SP << " " <<
template <class T> bool maxi(T &a, const T &b) {
    if (a < b) { a = b; return 1;} return 0;}
template <class T> bool mini(T &a, const T &b) {
    if (b < a) { a = b; return 1;} return 0;}
#define dame {cout<< "-1" <<"\n"; return;}
#define INF2 1000000000000000037
#define INF  1000000007
//#define MOD  1000000007
#define MOD  2
using namespace std;
using ll = long long;
using ld = long double;
using P  = pair<ll,ll>;
//--GLOBAL---------------------------------

//--MAIN-----------------------------------
void Main() {
    ll N;
    cin>>N;
    string S; cin>>S;
    ll ct=0;
    rep(i,N) if(S[i]=='2') ct^=(N-1&i)==i;
    if(ct) {cout<< 1 <<"\n"; return;}
    rep(i,N) if(S[i]=='2') {cout<< 0 <<"\n"; return;}
    rep(i,N) if(S[i]=='3') ct^=(N-1&i)==i;
    if(ct) {cout<< 2 <<"\n"; return;}
    cout<< 0 <<"\n";

}

//--START----------------------------------
int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
}
//-----------------------------------------


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

using namespace std;

#define INF 210000000
#define int long long

int gcd(int a, int b) {
  int amari = a % b;
  int c = b;
  if (amari == 0) {
    return b;
  } else {
    return gcd(b, amari);
  }
}

int lcm(int a, int b) { return a * b / gcd(a, b); }

signed main() {
		int n;
		cin >> n;
		int ans = ceil((float)n / 111) * 111;
		cout << ans;
}


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

using namespace std;

using ll = long long;
using ld = long double;

const double PI = 3.1415926535897932384626433832795;

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

int gcd(int x, int y) { return y ? gcd(y, x % y) : abs(x); }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : abs(x); }
int lcm(int x, int y) { return x / gcd(x, y) * y; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }

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

	int n;
	cin >> n;
	vector<int> h(n);
	for (auto &v : h) {
		cin >> v;
	}

	vector<int> dp(n);
	dp[1] = abs(h[0] - h[1]);
	for (int i = 2; i < n; i++) {
		dp[i] = min(dp[i - 1] + abs(h[i - 1] - h[i]),
					dp[i - 2] + abs(h[i - 2] - h[i]));
	}

	cout << dp[n - 1] << endl;
	return 0;
}


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

using ll = long long;
using ull = unsigned long long;
using ld = long double;

#define forn(i, a, n) for (int i = (int)(a); i < (int)(n); ++i)
#define ford(i, a, n) for (int i = (int)(n - 1); i >= (int)(a); --i)
#define fore(i, a, n) for (int i = (int)(a); i <= (int)(n); ++i)
#define all(a) (a).begin(), (a).end()
#define fs first
#define sn second
#define trace(a)\
    for (auto i : a) cerr << i << ' ';\
    cerr << '\n'
#define eb emplace_back

#ifndef M_PI
const ld M_PI = acos(-1.0);
#endif

const ld eps = 1e-9;
const int INF = 2000000000;
const ll LINF = 1ll * INF * INF;
const ll MOD = 1000000007;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    vector<int> a(n);
    forn(i, 0, n) {
        cin >> a[i];
        --a[i];
    }
    ll sum = 0;
    forn(i, 1, n)
        sum += (a[i] - a[i - 1] + m) % m;
    ll val = 0;
    int cnt = 0;
    forn(i, 1, n)
        if (a[i] < a[i - 1]) {
            ++cnt;
            val += m - a[i - 1];
        }
    ll best = val - cnt;
    vector<int> add_cnt(m), rem_cnt(m);
    vector<ll> rem_rez(m);
    forn(i, 0, n - 1)
        ++add_cnt[a[i]];
    forn(i, 1, n)
        ++rem_cnt[a[i]];
    forn(i, 1, n)
        rem_rez[a[i]] += (a[i] - a[i - 1] + m) % m;
    //cerr << sum << '\n';
    //cerr << "sums: \n";
    //cerr << sum - val + cnt << ' ';
    forn(i, 1, m) {
        cnt -= rem_cnt[i - 1];
        cnt += add_cnt[i - 1];
        val += cnt;
        //cerr << cnt << '\n';
        val -= rem_rez[i - 1];
        best = max(best, val - cnt);
        //cerr << sum - val + cnt << ' ';
    }
    //cerr << '\n';
    cout << sum - best << '\n';
}


Measured memory_bytes: 2176
#include<bits/stdc++.h>
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define ri(x) scanf("%d",&(x))
#define ri2(x,y) scanf("%d %d",&(x),&(y))
#define ri3(x,y,z) scanf("%d %d %d",&(x),&(y),&(z))
#define rll(x) scanf("%lld",&(x))
#define rll2(x,y) scanf("%lld %lld",&(x),&(y))
#define rll3(x,y,z) scanf("%lld %lld %lld",&(x),&(y),&(z))
#define gc(x) ((x) = getchar())
using namespace::std;

const long double PI = acos(-1);
const long long MOD = 1000000000 +7;

typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<ll,pll> tll;
typedef pair<int,int> ii;
typedef pair<int,ii> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<ll> vll;
typedef vector<pll> vpll;
typedef vector<tll> vtll;
typedef vector<string> vs;
typedef set<int> si;
typedef set<ii> sii;
typedef set<iii> siii;

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

ll add(ll a, ll b, ll m = MOD){ return (a%m + b%m+2*m)%m;}

ll mul(ll a, ll b, ll m = MOD){ return ((a%m+m)*(b%m+m))%m;}

ll pow_mod(ll a, ll b, ll m = MOD){
	ll res = 1LL;
	a = a%m;
	while(b){
		if(b&1) res = mul(res,a,m);
		b >>= 1;
		a = mul(a,a,m);
	}
	return res;
}

ll fastexp(ll a, ll b){
	ll res = 1LL;
	while(b){
		if(b&1) res = res*a;
		b >>= 1;
		a *= a;
	}
	return res;
}

int gcdExtendido(int a, int b, int *x, int *y){
	if(a == 0){
		*x = 0;
		*y = 1;
		return b;
	}
	int x1, y1;
	int gcd = gcdExtendido(b%a,a,&x1,&y1);
	
	*x = y1-(b/a)*x1;
	*y = x1;
	return gcd;
}

int modInverso(int a, int m){
	int x, y;
	int g = gcdExtendido(a,m,&x,&y);
	if(g!=1) return -1;
	else return (x%m + m)%m;
}

/****************************************
*************P*L*A*N*T*I*L*L*A************
*****************************************/

const int N = 3000+5;

int n, m;
string s, t;
bool vis[N][N];
int choicex[N][N];
int choicey[N][N];
int memo[N][N];

int DP(int i, int j){
	if(i == -1 or j == -1) return 0;
	if(vis[i][j]) return memo[i][j];
	int ans = -1;
	if(s[i] == t[j]){
		ans = 1 + DP(i-1,j-1);
		choicex[i][j] = -1;
		choicey[i][j] = -1;
	}
	else{
		if(ans < DP(i-1,j)){
			choicex[i][j] = -1;
			choicey[i][j] = 0;
			ans = DP(i-1,j);
		}
		if(ans < DP(i,j-1)){
			choicex[i][j] = 0;
			choicey[i][j] = -1;
			ans = DP(i,j-1);
		}
	}
	vis[i][j] = true;
	return memo[i][j] = ans;
}

int main(){
	cin >> s >> t;
	n = s.size();
	m = t.size();
	int res = DP(n-1,m-1);
	int x = n-1, y = m-1;
	stack<char> S;
	while(x != -1 and y != -1){
		if(s[x] == t[y]){
			S.push(s[x]);
		}
		int nx = x + choicex[x][y];
		int ny = y + choicey[x][y];
		x = nx;
		y = ny;
	}
	while(!S.empty()){
		putchar(S.top());
		S.pop();
	}
	puts("");
	return 0;
}


Measured memory_bytes: 115328
"""
dp[i][j][k] => i行目j列到達時点での最大価値。i行目において拾えるアイテムの数はK個。
"""
def main():
    import sys
    input = sys.stdin.readline
    R,C,K = map(int,input().split())
    items = [[0]*C for _ in range(R)]
    for _ in range(K):
        r,c,v = map(int,input().split())
        items[r-1][c-1] = v

    dp = [[0]*4 for _ in range(C)]

    for i in range(R):
        for j in range(C):
            v = items[i][j]

            #上から入るパターン
            dp[j][0] = max(dp[j])
            if v:
                dp[j][1] = dp[j][0]+v
            
            #左から入ってくるパターン
            if j > 0:
                for k in range(4):
                    #このマスのアイテムをとらないパターン
                    dp[j][k] = max(dp[j][k],dp[j-1][k])
                    if v and k>0:
                        dp[j][k] = max(dp[j][k],dp[j-1][k-1]+v)

    print(max(dp[-1]))
main()

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

typedef long long ll;
#define pii pair<int , int>
#define _FastIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define MAXX 1005

string s;

int main()
{
    _FastIO;
    cin >> s;
    multiset<int> ms;
    multiset<int>::iterator it;
    for(int i = 0; i < 4; i++){
        ms.insert(int(s[i]));
    }
    string ans = "Yes";
    for(it = ms.begin(); it != ms.end(); it++){
        int k = ms.count(*it);
        if(k != 2)  ans = "No";
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
x=int(input())
if x==2:
    print(2)
    exit()
for i in range(x,100004):
    for j in range(2,int(i**(1/2))+2):
        if i%j==0:
            break
        if j==int(i**(1/2))+1:
            print(i)
            exit()


Measured memory_bytes: 2940
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<bitset>
#include<cctype>
#include<climits>
#include<cmath>
#include<cstdio>
#include<deque>
#include<list>
#include<map>
#include<set>
#include<stack>
#include<string>
#include<sstream>
#include<queue>
#include<vector>
using namespace std;

int main() {
	string str; cin >> str;
	int q; cin >> q;
	for (int i = 0; i < q; i++) {
		string s; cin >> s;
		int a, b; cin >> a >> b;
		if (s == "replace") {
			string r; cin >> r;
			str = str.substr(0, a) + r + str.substr(b + 1);
		}
		else if (s == "reverse") {
			string r = str.substr(a, b - a + 1);
			reverse(r.begin(), r.end());
			str = str.substr(0, a) + r + str.substr(b + 1);
		}
		else if (s == "print") {
			cout << str.substr(a, b - a + 1) << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1228
from collections import deque, defaultdict

def main():
    n = int(input())
    UVW = [[int(e) for e in input().split()] for i in range(n - 1)]

    D = defaultdict(list)
    for uvw in UVW:
        u, v, w = uvw
        D[u].append([v, w])
        D[v].append([u, w])

    A = [''] * (n + 1)
    A[UVW[0][0]] = '0'

    Q = deque()
    Q.append(UVW[0][0])

    while True:
        if len(Q) == 0:
            break

        qe = Q.pop()
        for de in D[qe]:
            if A[de[0]] == '':
                Q.append(de[0])

            if de[1] % 2 == 0:
                A[de[0]] = A[qe]
            else:
                if A[qe] == '0':
                    A[de[0]] = '1'
                else:
                    A[de[0]] = '0'

    for i in range(n):
        print(A[i + 1])

if __name__ == "__main__":
    main()


Measured memory_bytes: 109144
s = input()
t = input()
q = int(input())
xa = [0]*len(s)+[0]
xb = [0]*len(s)+[0]
ya = [0]*len(t)+[0]
yb = [0]*len(t)+[0]
for i in range(len(s)):
  if s[i] == "A":
    xa[i+1] = xa[i] + 1
    xb[i+1] = xb[i]
  else:
    xa[i+1] = xa[i] 
    xb[i+1] = xb[i] + 1
for i in range(len(t)):
  if t[i] == "A":
    ya[i+1] = ya[i] + 1
    yb[i+1] = yb[i]
  else:
    ya[i+1] = ya[i] 
    yb[i+1] = yb[i] + 1
for i in range(q):
  a,b,c,d = map(int,input().split())
  sa = (xa[b] -xa[a-1]) %3
  sb = (xb[b] -xb[a-1]) %3
  ta = (ya[d] -ya[c-1]) %3
  tb = (yb[d] -yb[c-1]) %3
  if [(sa-1)%3,(sb+2)%3] == [ta,tb] or [(sa+2)%3,(sb-1)%3] == [ta,tb] or [sa,sb] == [ta,tb] or [(sa-2)%3,(sb+4)%3] == [ta,tb] or [(sa+4)%3,(sb-2)%3] == [ta,tb]:
    print("YES")
  else:
    print("NO")

Measured memory_bytes: 62556
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

int main(int argc, char const *argv[]) {
    int h,w,a,b;
    cin>>h>>w>>a>>b;
    vector<string> ans;
    if (w / 2 < a || h / 2 < b) {
        cout << "No" << endl;
        return 0;
    }
    string s,t;
    for (int i = 0; i < (w-a); ++i) {
        s.push_back('0');
        t.push_back('1');
    }
    rep(i,a) {
        s.push_back('1');
        t.push_back('0');
    }

    rep(i,h-b) {
        ans.push_back(s);
    }

    rep(i,b) ans.push_back(t);

    for (auto &&e: ans) cout << e << endl; 

    return 0;
}


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

int main() {
    ll a,b,c,x,y;
    cin>>a>>b>>c>>x>>y;
    ll n = a*x+b*y;
    ll m = 2*c*min(x,y);
    if(x<y) m += (y-x) * min(b, 2*c);
    else if(x>y) m += (x-y) * min(a, 2*c);
    cout<<min(n,m);
}

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

using namespace std;

typedef long long lo;
typedef pair< lo,lo > PII;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define FOR for(int i=1;i<=n;i++)
#define mid ((start+end)/2)
#define ort ((bas+son)/2)

const lo MAX = -1000000000000000000;
const lo MIN = 1000000000000000000;
const lo inf = 1000000000;
const lo KOK = 100000;
const lo LOG = 30;
const lo li = 500005;
const lo mod = 1000000007;

lo n,m,b[li],a[li],k,flag,t,dp[li];
lo cev;
string s;
vector<lo> v;

int main(void){
	scanf("%lld %lld",&n,&k);
	FOR{
		scanf("%lld",&a[i]);
	}
	for(int i=a[1];i<=k;i++){
		for(int j=1;j<=n;j++){
			if(i-a[j]<0)continue;
			if(dp[i-a[j]]==0)dp[i]=1;
		}
	}
	if(dp[k]==1)printf("First\n");
	else printf("Second\n");
	return 0;
}


Measured memory_bytes: 3072
#include<iostream>
using namespace std;
typedef long long ll;

void solve()
{
    int l,r,d;
    cin>>l>>r>>d;
    int cnt=0;
    for(int i=l;i<=r;i++)
    {
        if(i%d==0)
            cnt++;
    }
    cout<<cnt<<endl;
}

int main()
{
    solve();
}


Measured memory_bytes: 3620
#include<iostream>
#include<cstdio>
#include<stack>
#include<queue>
#include<algorithm>
#include<string>
#include<set>
#include<map>
#include<vector>
#include<math.h>
#include<tuple>
#include<string.h>
#include <numeric> 
#include<unordered_map>
using namespace std; 
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define pp(...) "\033[94m [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "]\033[0m"
#define pp1(...) "\033[1;47;35m" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "]\033[0m"
#define dg(x) debug() << pp1(x)
#define dg1(x) debug() << "[line : " << __LINE__ <<"]"<< pp(x)
#define dg2(x,y) debug() << "[line : " << __LINE__ <<"]"<< pp(x) pp(y)
#define dg3(x,y,z) debug() << "[line : " << __LINE__ <<"]"<< pp(x) pp(y) pp(z)
#define dg4(w,x,y,z) debug() << "[line : " << __LINE__ <<"]"<< pp(w) pp(x) pp(y) pp(z)
template<typename T> void db(T x ){ debug() <<">>> " <<  x; }
template<typename T> void db(T x , T y){ debug() <<">>> " <<  x <<" , "<< y; }
template<typename T> void db(T x , T y , T z){ debug() <<">>> "<< x <<" , "<< y <<" , "<< z; }
template<typename T> void db(T x , T y , T z , T a){ debug() <<">>> "<< x <<" , " << y <<" , "<< z <<" , "<< a; }
#define int long long
#define all(x) x.begin() , x.end()
#define clr(x , y) memset(x , y , sizeof x);
#define sz(x) (int)x.size()

const int Mod = 1e9 + 7;
const int inf = 1e18;

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N, M;
  cin >> N >> M;
  vector<int> a(M), b(M);
  vector<vector<int>>c(M , vector<int>(N));
  for(int i = 0; i < M; i++) {
    cin >> a[i] >> b[i];
    for(int j = 0; j < b[i]; j++) {
      cin >> c[i][j];
    }
  }
  vector<int>dp(5000, inf);
  dp[0] = 0;
  
  for(int i = 0;i < M; i++) {
    int item = 0;
    for(int j = 0;j < b[i]; j++) {
      item |= 1 << (c[i][j] - 1);
    }
    for(int bit = 0; bit < (1 << N); bit++) {
      dp[item | bit] = min(dp[item | bit] , dp[bit] + a[i]);
    }   
  }
  int ans = dp[(1 << N) - 1];
  if(ans == inf) ans = -1;
  cout << ans << '\n';
}

Measured memory_bytes: 3820
import sys
import itertools
# import numpy as np
import time
import math
from heapq import heappop, heappush
from collections import defaultdict
from collections import Counter
from collections import deque
sys.setrecursionlimit(10 ** 7)
 
INF = 10 ** 18
MOD = 10 ** 9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

# map(int, input().split())
N, M = map(int, input().split())
X = list(map(int, input().split()))
Y = list(map(int, input().split()))

xs = 0
for i in range(N):
    xs += i  * X[i]
    xs -= (N - i - 1) * X[i]
    xs %= MOD
ys = 0
for i in range(M):
    ys += i  * Y[i]
    ys -= (M - i - 1) * Y[i]
    ys %= MOD
print(xs * ys % MOD)




Measured memory_bytes: 24488
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;

map<ll, int> prime_factor(ll n) {
  map<ll, int> ret;
  for (ll i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if (n != 1)
    ret[n] = 1;
  return ret;
}

int main() {
  ll a, b;
  cin >> a >> b;
  map<ll, int> f1 = prime_factor(a), f2 = prime_factor(b);
  int ans = 0;
  for (auto one : f1) {
    if (f2[one.first] > 0)
      ans++;
  }

  cout << ans + 1 << endl;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(void)
{
    int x,y;
 
    while(1){

    scanf("%d %d",&x,&y);
 
    if(x == 0 && y == 0)break;
    if(x > y ){
        printf("%d %d\n",y,x);
    }
    if(y > x ){
        printf("%d %d\n",x,y);
    }
    if(x == y){
        printf("%d %d\n",x,y);
    }
    }
     return 0;
}

Measured memory_bytes: 1800
#include <bits/stdc++.h>
using namespace std;
int main() {
  int w,h;
  cin >> w >> h;
  char t[110][110];
  for (int i=0; i<w+2; i++) {
    for (int j=0; j<h+2; j++) {
      t[i][j] = '#';
    }
  }
  for (int i=1; i<=w; i++) {
    for (int j=1; j<=h; j++) {
      cin >> t[i][j];
    }
  }
  for (int i=0; i<w+2; i++) {
    for (int j=0; j<h+2; j++) {
      cout << t[i][j];
    }
    cout << endl;
  }
}

Measured memory_bytes: 256
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <math.h>
#include <numeric>
#include <set>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;

#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, n) for(ll i = 1; i < n + 1; i++)

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

    if(N == 0){
        cout << X << endl;
        return 0;
    }

    ll p[N];
    rep(i, N){
        cin >> p[i];
    }

    sort(p, p + N);

    ll l = 0;
    ll r = N - 1;
    ll pointer;
    while(r - l > 1){
        if(p[(l + r) / 2] < X){
            l = (l + r) / 2;
        }else if(p[(l + r) / 2] > X){
            r = (l + r) / 2;
        }else{
            l = (l + r) / 2;
            r = (l + r) / 2;
        }
    }
    if(p[l] == X){
        r = l;
    }
    if(p[r] == X){
        l = r;
    }

    ll Xl, Xr;
    Xl = X;
    Xr = X;
    ll found = 0;
    ll ans;
    while(found == 0){
        if(Xl != p[l]){
            ans = Xl;
            found = 1;
            break;
        }
        Xl--;
        if(l > 0){
            l--;
        }
        if(Xr != p[r]){
            ans = Xr;
            found = 1;
            break;
        }
        Xr++;
        if(r < N - 1){
            r++;
        }
    }

    cout << ans << endl;

    return 0;
}


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

int main(){
    int N;
    int K;

    cin>>N>>K;

    vector<int> X(N);

    for(int i = 0; i < N;i++) cin>>X[i];

    int sum = 0;

    for(int i=0;i<N;i++){
        sum += min(X[i]*2 ,(K-X[i]) * 2);
    }

    cout<<sum<<endl;
}


Measured memory_bytes: 256
#include <vector>
#include <math.h>
#include <iostream>
#include <string>
#include <algorithm>


using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;
#define rep(i, n) for(int i = 0; i<n; i++)
#define rep_s(i, start, n) for(int i= start;  i<n; i++)
string alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

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

ll lcm(ll a, ll b){
  ll g = gcd(a, b);
  return a/g * b;
}

int main(void){
  int N;
  cin >> N;
  ll ans = 1LL;
  for (int i = 0; i<N; ++i){
    ll T;
    cin >> T;
    ans = lcm(ans, T);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define rep(i,n) for(ll i = 0; i < (ll)(n); i++)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll INF = 1LL << 60;

vector<ll> fact(ll n){
    vector<ll> res;
    for(ll i=1; i*i<=n; i++){
        if(n%i!=0) continue;
        res.push_back(i);
        if(i*i!=n) res.push_back(n/i);
    }
    return res;
}
int main(){
    ll n;
    cin >> n;
    vector<ll> nfact = fact(n);
    ll ans = 0;
    for(ll f : nfact){
        if(f==1) continue;
        ll ncp = n;
        while(ncp % f == 0) ncp /=f;
        if(ncp%f==1) ans++;
    }
    ans += fact(n-1).size()-1;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 384
// Copyright 2017 wu_qing
#include <cstdio>
#include <algorithm>

const int N = 1e5 + 10;
int n, k, a[N], cur, ma;

template <typename T>
inline T gcd(T a, T b) {
    return b == 0 ? a : gcd(b, a % b);
}

int main() {
    scanf("%d%d", &n, &k);
    for (int i = 1; i <= n; i++)
        scanf("%d", a + i);
    ma = cur = a[1];
    for (int i = 2; i <= n; i++) {
        cur = gcd(cur, a[i]);
        ma = std::max(ma, a[i]);
    }
    if (k % cur == 0 && k <= ma)
        puts("POSSIBLE");
    else
        puts("IMPOSSIBLE");
    return 0;
}



Measured memory_bytes: 512
N = gets.chomp.to_i
numbers = gets.chomp.split(" ").map(&:to_i)

counts = 0
for i in 0...N do
  loop do
    break if numbers[i] % 2 != 0
    numbers[i] /= 2
    counts += 1
  end
end

print("#{counts}\n")

Measured memory_bytes: 2812
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <numeric>
using namespace std;
typedef long long int ll;
#define EPS (1e-7)
#define INF (1e9 + 10)
#define PI (acos(-1))
#define MOD (1000000007)
#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)
#define ALL(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<x<<endl
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;
    vector<int> a(N, 0);
    REP(i, N) {
        cin >> a[i];
    }
    double ave = (double)accumulate(ALL(a), 0) / N;
    int ans = 0;
    REP(i, N) {
        if (abs(ave - a[i]) < abs(ave - a[ans]) ){
            ans = i;
        }
    }
    cout << ans << endl;
}

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

#define EPSILON 1e-6
#define ll long long
#define pii pair<int, int>

int main(int argc, char* argv[]) {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  int n;
  cin >> n;

  vector<pii> edges;
  vector<int> weights;
  vector<int>* adjlist = new vector<int>[n]();
  for (int i=0; i<n-1; i++) {
    int u, v, w;
    cin >> u >> v >> w;
    edges.push_back({u, v});
    weights.push_back(w);
    adjlist[u-1].push_back(i);
    adjlist[v-1].push_back(i);
  }

  vector<int> colors;
  for (int i=0; i<n; i++) {
    colors.push_back(2);
  }

  colors[0] = 0;
  set<int> avail;
  avail.insert(0);
  while (avail.size() != 0) {
    auto it = avail.begin();
    int i = *it;
    if (colors[i] != 2) {
      for (int j=0; j<adjlist[i].size(); j++) {
        pii ed = edges[adjlist[i][j]];
        int w = weights[adjlist[i][j]];
        int v = (ed.first == i+1) ? ed.second-1 : ed.first-1;
        // cerr << i << " " << v << " " << w << " " << colors[i] << " " << colors[v] << "\n";
        if (colors[v] == 2) {
          if (w%2 != 0) colors[v] = (colors[i]+1)%2;
          else colors[v] = colors[i];
          avail.insert(v);
        }
      }
    }
    avail.erase(i);
  }

  for (int i=0; i<n; i++) {
    cout << colors[i] << "\n";
  }

  return 0;
}


Measured memory_bytes: 8312