akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <vector>

#define MOD 998244353
std::pair<int,int> P[110];
long long int DP[400010];
int main()
{
	int a,b;
	scanf("%d%d",&a,&b);
	for(int i=1;i<=b;i++)
	{
		int c,d;
		scanf("%d%d",&c,&d);
		P[i]=std::make_pair(c,d);
	}
	DP[a] = 1;
	for(int i=a-1;i>=1;i--)
	{
		long long int S = 0;
		for(int j=1;j<=b;j++)
		{
			int s = i+P[j].first;
			int t = i+P[j].second;
			S += (DP[s]-DP[t+1]+MOD)%MOD;
			S %= MOD;
		}
		DP[i] = (DP[i+1] + S)%MOD;
	}
	printf("%lld",(DP[1]-DP[2]+MOD)%MOD);
}

Measured memory_bytes: 3292
# -*- coding: utf-8 -*-
import sys,copy,math,heapq,itertools as it,fractions,re,bisect,collections as coll

N = int(raw_input())
a = map(int, raw_input().split())
ans = 1e10
for b in xrange(-100, 101):
    tmp = 0
    for ai in a:
        tmp += (ai - b)**2
    ans = min(ans, tmp)
print ans



Measured memory_bytes: 4008
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<set>
#include<map>
#include<iomanip>

using namespace std;

int main(void) {
	int x, y;
	cin >> x >> y;
	if (x%y == 0) {
		cout << -1;
	}
	else {
		if ((2 * x) % y != 0) {
			cout << 2 * x;
		}
		else {
			cout << 3 * x;
		}
	}
	return 0;
}

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

public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		ArrayList<Double> data = new ArrayList<>();
		while (true) {
			int n = sc.nextInt();
			if (n == 0) {
				break;
			}
			int sum = 0;
			int[] s = new int[n];
			double m;
			double a;
			double sigma = 0;
			for (int i = 0; i < n; i++) {
				s[i] = sc.nextInt();
				sum += s[i];
			}
			m = (double) sum / n;
			for (int i = 0; i < n; i++) {
				sigma += Math.pow(s[i] - m, 2) / n;
			}
			a = Math.sqrt(sigma);
			data.add(a);
		}
		for (int i = 0; i < data.size(); i++) {
			System.out.printf("%f%n", data.get(i));
		}
		sc.close();
	}
}


Measured memory_bytes: 31460
#include <queue>
#include <vector>
#include <iostream>
#include <algorithm>
#pragma warning(disable : 4996)
using namespace std;
vector<int> G[100009]; int root = 0, parent[17][100009], depth[100009];
void dfs(int v, int p, int d) {
	parent[0][v] = p; depth[v] = d;
	for (int i : G[v]) if (i != p) dfs(i, v, d + 1);
}
void init(int v) {
	dfs(root, -1, 0);
	for (int i = 0; i < 16; i++) {
		for (int j = 0; j < v; j++) {
			if (parent[i][j] < 0) parent[i + 1][j] = -1;
			else parent[i + 1][j] = parent[i][parent[i][j]];
		}
	}
}
int query(int v1, int v2) {
	if (depth[v1] > depth[v2]) swap(v1, v2);
	for (int i = 0; i < 17; i++) {
		if ((depth[v2] - depth[v1]) >> i & 1) v2 = parent[i][v2];
	}
	if (v1 == v2) return v1;
	for (int i = 16; i >= 0; i--) {
		if (parent[i][v1] != parent[i][v2]) {
			v1 = parent[i][v1];
			v2 = parent[i][v2];
		}
	}
	return parent[0][v1];
}
int n, q, c, a, x, y;
int main() {
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%d", &c);
		for (int j = 0; j < c; j++) {
			scanf("%d", &a);
			G[i].push_back(a);
			G[a].push_back(i);
		}
	}
	init(n);
	scanf("%d", &q);
	for (int i = 0; i < q; i++) {
		scanf("%d%d", &x, &y);
		printf("%d\n", query(x, y));
	}
	return 0;
}

Measured memory_bytes: 20364
#include<bits/stdc++.h>
using namespace std;
int a[100],tot,cnt[100],b[100],ans,n,x;
void dfs(int x){
	if (x>tot){
		int num=1e9;
		for (int i=1;i<=n+tot;i++)
			for (int j=i+1;j<=n+tot;j++)
				num=min(num,min(24-abs(b[i]-b[j]),abs(b[i]-b[j])));
		ans=max(ans,num);
		return;		
	}
	b[x+n]=a[x];dfs(x+1);
	b[x+n]=24-a[x];dfs(x+1);
}
int main(){
	scanf("%d",&n);
	cnt[0]++;
	while (n--)scanf("%d",&x),cnt[x]++;
	n=0;
	for (int i=0;i<=12;i++)
		if (cnt[i]>2){
			puts("0");
			return 0;
		}
		else if (cnt[i]==2){
			if (!i){
				puts("0");
				return 0;
			}
			else b[++n]=i,b[++n]=24-i;
		}
		else if (cnt[i]==1)a[++tot]=i;
	dfs(1);
	printf("%d\n",ans);
}

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

int A, B, C;

int input(){
	std::cin >> A >> B >> C;
	return 0;
}

int run(){
	int f = 0, s;
	const char *re[2] = {"NO", "YES"};
	for( int i = 0; i <= B; i++ ){
		s = A*i;
		if( s % B == C ){
			f = 1;
			break;
		}
	}
	std::cout << re[f] << std::endl;
	return 0;
}

int main(){
	input();
	run();
	return 0;
}


Measured memory_bytes: 256
n, y = map(int, input().split())
a = 0
b = 0
c = 0
for i in range(n + 1):
    for j in range(n - i + 1):
        if 10000 * i + 5000 * j + 1000 * (n - i - j) == y:
            a = i
            b = j
            c = n - i - j
            break
        else:
            pass
if a + b + c > 0:
    print(str(a), ' ', str(b), ' ', str(c))
else:
    print("-1 -1 -1")                 


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

int main(void){
    string S; cin >> S;
    queue<int> A;
    stack<int> Z;
    for(int i=0; i<S.size(); i++){
        if(S[i]=='A') A.push(i);
        if(S[i]=='Z') Z.push(i);
    }

    cout << Z.top()-A.front()+1 << endl;

    return 0;
}

Measured memory_bytes: 1284
n = int(input())
tscore = 0
hscore = 0
for i in range(n):
    wlist = []
    t,h = map(str, input().split())
    wlist.append(t)
    wlist.append(h)
    order = sorted(wlist, key = str.lower)
    if (t.lower() == h.lower()):
        tscore += 1
        hscore += 1
    elif (order[1] == t):
        tscore += 3
    elif (order[1] ==h ):
        hscore += 3
print(tscore, hscore)
        


Measured memory_bytes: 5604
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define REP(i,k,n) for(int i = k; i < (int)(n); i++)

#define vi vector<int>
#define pb push_back

typedef long long ll;
using namespace std;



int main(){
    int x,y,s;
    while(cin >> x >> y >> s,s) {

        int mx = 0;
        REP(o1,1,s) REP(o2,1,s){
            int fx1 = o1 * (100 + x) / 100,fx2 = o2 * (100 + x) / 100;
            if(fx1 + fx2 == s) {
                int fy1 = o1 * (100 + y) / 100, fy2 = o2 * (100 + y) / 100;
                mx = max(mx,fy1 + fy2);
            }
        }
        cout << mx << endl;
    }
    return 0;
}



Measured memory_bytes: 3076
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF = 1000000007;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()

// #include <boost/multiprecision/cpp_dec_float.hpp>
// #include <boost/multiprecision/cpp_int.hpp>
// namespace mp = boost::multiprecision;
// using Bint = mp::cpp_int;
// using Real = mp::number<mp::cpp_dec_float<1024>>;

int main(){
    int K;
    string S;
    cin >> K >> S;
    if(S.size() <= K) cout << S << endl;
    else {
        rep(i, K) cout << S.at(i);
        cout << "..." << endl;
    }
}

Measured memory_bytes: 3628
//#pragma comment(linker, "/STACK:134217728")

#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <memory>
#include <cctype>
#include <cstring>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
using namespace std;

typedef long long Int;
typedef pair<int,int> PII;
typedef vector<int> VInt;

#define FOR(i, a, b) for(i = (a); i < (b); ++i)
#define RFOR(i, a, b) for(i = (a) - 1; i >= (b); --i)
#define CLEAR(a, b) memset(a, b, sizeof(a))
#define SIZE(a) int((a).size())
#define ALL(a) (a).begin(),(a).end()
#define PB push_back
#define MP make_pair

int P[1 << 20];
int I[1 << 20];
int R[1 << 20];


int main()
{
	int N;
	scanf("%d", &N);

	int i;
	FOR(i, 0, N)
	{
		int a;
		scanf("%d", &a);
		--a;
		P[i] = a;
		I[a] = i;
	}

	int res = 0;
	FOR(i, 0, N)
	{
		R[i] = 1;
		if (i != 0 && I[i - 1] < I[i]) R[i] = R[i - 1] + 1;
		res = max(res, R[i]);
	}

	printf("%d\n", N - res);
	return 0;
};


Measured memory_bytes: 5120
def dfs(nums, length, min_lim):
# 返り値は、すべての数列の得点の最大値 ans です。
# numsは数列の本体、lengthは数字の何個目まで決めたか、min_limは次の数字の最小値
    ans = 0
    if length == n:
    # 数列が完成したので、得点を計算します
        score_ret = 0
        for a, b, c, d in req:
            # nums[0]を捨てたので、nums[b-1]...としなくて済みます
            if nums[b] - nums[a] == c:  
                score_ret += d
        return score_ret  # この数列の得点を返します
    else:
        # まだ数列が完成していません
        for nu in range(min_lim, m + 1):
        # 次の数字の下限はmin_limで、上限はmです
            new_nums = nums + [nu]  # 長さ1のリスト[nu]を連結します
            # lengthは1増えて、次の下限は今付け加えた数字nuです
            score = dfs(new_nums, length + 1, nu)
            ans = max(ans, score) # 最大の得点を更新します

    # すべてが終わったので、答えを返します
    return ans


n, m, q = list(map(int, input().split()))

# 問題文のa,b,c,dの「リストのリスト」reqです。[[a1,b1,c1,d1],[a2,b2,c2,d2],[a3,b3,c3,d3]]のようになります。
req = [list(map(int, input().split())) for _ in range(q)]

# 最終的に答えが返ってくるようにします。処理はすべてdfsメソッドでやってもらいます。
# 数列の番号と添字を一致させたいので、適当な長さ1のリストを最初の状態にしておきます。
# 例えばサンプル1の1,3,4は[-1, 1, 3, 4]になります。
ans = dfs([-1], 0, 1)
print(ans)

Measured memory_bytes: 9224
#include <iostream>
#include <vector>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <utility>
#include <queue>
using namespace std;
const double EPS = 1e-9;
const double INF = 1e18;
vector<double> mincost((int)1e4, INF);

double prim(int s, vector<vector<pair<int, double> > > &adj){
    int n = adj.size();
    //vector<double> mincost(n, INF);
    priority_queue<pair<double, int> > wait;
    wait.push(make_pair(0, s));
    
    int v = 0;
    double ret = 0;
    while(!wait.empty() && v<n){
        double cost = -wait.top().first;
        int idx = wait.top().second;
        wait.pop();
        if(cost > mincost[idx] +EPS) continue;
        ret += cost;
        v++;
        mincost[idx] = -INF;
        for(int i=0; i<(int)adj[idx].size(); i++){
            int nidx = adj[idx][i].first;
            double ncost = adj[idx][i].second;
            if(ncost +EPS < mincost[nidx]){
                wait.push(make_pair(-ncost, nidx));
                mincost[nidx] = ncost;
            }
        }
    }
    
    for(int i=0; i<n; i++){
        if(mincost[i] == INF){
            ret += prim(i, adj);
        }
    }
    return ret;
}

int main(){
    int n,m;
    cin >> n >> m;
    vector<double> px(n), py(n);
    for(int i=0; i<n; i++){
        cin >> px[i] >> py[i];
    }
    vector<vector<pair<int, double> > > adj(n);
    double sum = 0;
    for(int i=0; i<m; i++){
        int p,q;
        cin >> p >> q;
        p--; q--;
        double d = sqrt((px[p]-px[q])*(px[p]-px[q]) +(py[p]-py[q])*(py[p]-py[q]));
        sum += d;
        adj[p].push_back(make_pair(q, -d));
        adj[q].push_back(make_pair(p, -d));
    }
    cout << fixed;
    cout << setprecision(3);
    cout << sum +prim(0, adj) << endl;
    return 0;
}

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

typedef long long ll;
#define rep(i,n) for(long long i=0; i<(long long)(n);i++)
#define rep2(i,s,n) for(long long i=(s); i<(long long)(n);i++)
#define mod 1000000007

int main() {
    int a,b;cin>>a>>b;

    if((a+1)/2>=b){
        cout<<"YES"<<endl;
    }
    else {
        cout<<"NO"<<endl;
    }
}


Measured memory_bytes: 256
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=0
for i in range(n):
  if b[i] <= a[i]:
    c+=b[i]
  elif b[i]>a[i] and b[i]-a[i]<=a[i+1]:
    c+=b[i]
    a[i+1]-=b[i]-a[i]
  else:
    c+=a[i]+a[i+1]
    a[i+1]=0
    
    
print(c)

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

int main() {
  int h, w;
  cin >> h >> w;
  vector<string> image(h);
  for(int i=0;i<h;i++){
    cin >> image[i];
    cout << image[i] << endl;
    cout << image[i] << endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define each(a,x) for(auto a : (x))
#define all(a) (a).begin(),(a).end()
#define chmin(a,b) ((a) = min((a),(b)))
#define chmax(a,b) ((a) = max((a),(b)))
#define in_range(x,l,r) ((l)<=(x) && (x)<(r))
#define fs first
#define sc second
#define pb push_back
#define sz size() 
#define MP make_pair
using namespace std;
typedef long long ll;
typedef double D;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<string> vs;

const int INF = 1e8;
const D EPS = 1e-8;

int main(){
  int ans = 0, s = 0;
  string x;
  cin >> x;
  for(char c : x){
    if(c == 'S') s++;
    if(c == 'T'){
      if(s) ans++, s--;
    }
  }
  cout << (int)x.size() - 2*ans << endl;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define PI 3.141592653589793238
int main()
{
    // #ifndef ONLINE_JUDGE
    // freopen("/home/pushkar/cpp/input.txt", "r", stdin);
    // freopen("/home/pushkar/cpp/output.txt", "w", stdout);
    // #endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n, ans = 0;
    cin >> n;
    double d, x, y, d1;
    cin >> d;
    while (n--)
    {
        cin >> x >> y;
        d1 = sqrt(x*x + y*y);
        if (d1 <= d)
        ans++;
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 3792
#!/usr/bin/node
// Generated by CoffeeScript 1.3.3
// manually optimized
(function() {
  var a=[];
  var stdin = process.openStdin();
  stdin.setEncoding('utf8');

  var proc = function(s){
    var bidx=s.indexOf('('),count,eidx,m;
    while(bidx!=-1){
      eidx=bidx+1;
      for(count=1;count;eidx++){
        if(s[eidx]=='(')count++;
        if(s[eidx]==')')count--;
      }
      s=s.substring(0,bidx)+proc(s.substring(bidx+1,eidx-1))+s.substring(eidx);
      bidx=s.indexOf('(');
    }
    while(m = /^(.*?)(-?\d+)([*/])(-?\d+)(.*)$/.exec(s)){
      if(m[3]=='*')s=m[1]+(parseInt(m[2])*parseInt(m[4]))+m[5];
      else s=m[1]+(parseInt(m[2])/parseInt(m[4])^0)+m[5];
    }
    while(m = /^(.*?)(-?\d+)([+Z])(-?\d+)(.*)$/.exec(s)){
      if(m[3]=='+')s=m[1]+(parseInt(m[2])+parseInt(m[4]))+m[5];
      else s=m[1]+(parseInt(m[2])-parseInt(m[4]))+m[5];
    }
    return s;
  };

  stdin.on('data', function(input) {
    var i=0,len,ref,x=[];
    ref=input.split("\n");
    for(len=ref.length;i<len;i++)x.push(ref[i]);
    if(x.length>2||!isNaN(x[1]))a=x;
    else a.push(x[0]);
  });

  stdin.on('end', function(z) {
    var i,n,s;
    n = parseInt(a[0]);
    for(i=1;i<=n;i++){
      s=a[i].substring(0,a[i].indexOf('=')).replace(/-/g,'Z');
      console.log(proc(s));
    }
  });
}).call(this);

Measured memory_bytes: 9220
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define All(V) V.begin(), V.end()
typedef long long int ll;
typedef pair<int, int> P;
const ll MOD = 1e9+7, INF = 1e9;

int main()
{
  ll n; cin >> n;
  ll ans = 0;
  ans += 1000*(n/500);
  n %= 500;
  ans += 5*(n/5);
  cout << ans << endl;
  system("pause");
}


Measured memory_bytes: 504
#include <cstdio>
#include <climits>
#include <cassert>
#include <cmath>
#include <iostream>
#include <string>
#include <algorithm>
#include <numeric>
#include <functional>
#include <tuple>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <vector>
#include <iterator>
#include <regex>

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
#define FOR(x,xs) for(auto &x: xs)

using namespace std;
typedef long long ll;
typedef pair<int,int> PI;
typedef pair<ll,ll> PL;
typedef vector<int> VI;
typedef vector<ll> VL;

template <class T, template <class, class> class C, class charT = char>
void vdump(const C<T, allocator<T>> &v, const charT* delimiter = ", ",
           ostream &stream = cout) {
  copy(v.begin(), v.end(), ostream_iterator<T>(stream, delimiter));
  stream << endl;
}

ll pow(ll x, ll y) {
  if(y == 0) {
    return 1;
  }
  if(y % 2) {
    return pow(x, y - 1) * x;
  }
  ll z = pow(x, y / 2);
  return z * z;
}

int main() {
  ios::sync_with_stdio(false);
  ll n, p;
  cin >> n >> p;
  if(n == 1) {
    cout << p << endl;
    return 0;
  }
  ll ans = 1;
  for(ll i = 2; i * i <= p; i++) {
    ll j = 0;
    for(; p % i == 0; j++) {
      p /= i;
    }
    ans *= pow(i, j / n);
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
//make_tuple emplace_back next_permutation push_back make_pair second first

#if MYDEBUG
#define DBG(...) {string dst__=#__VA_ARGS__;dbgsplit(dst__);stringstream dss__; dss__<<dst__; debug(dss__,__VA_ARGS__);}
#else
#define DBG(...)
#endif
void debug(stringstream& ds){cerr<<endl;return;}
template<typename F, typename... R>void debug(stringstream& ds,const F& f, const R&... r){string n; ds>>n; cerr<< n <<'='<<f<<' '; debug(ds,r...);}
void dbgsplit(string &s){int l=s.length(),n=0;for(int i=0; i<l; ++i){if(s[i]=='(')++n;if(s[i]==')')--n;if(s[i]==','&&!n)s[i]=' ';}}
using LL = long long;
constexpr LL LINF=334ll<<53;
constexpr int INF=15<<26;
constexpr LL  MOD=1E9+7;

struct Problem{
    int n;
    vector<int> a,b;
    const int nn=4004;
    vector<vector<LL>> _dp;
    Problem(LL n):n(n),a(n),b(n),_dp(nn,vector<LL>(nn)){};
    long long modpow(long long a, long long n,long long mod=MOD){
        long long i=1,ret=1,p=a;
        while(i<=n){
            if(i&n) ret=(ret*p)%mod;
            i=(i<<1);
            p=(p*p)%mod;
        }
        return ret;
    }
    void solve(){
        vector<LL> fac(2*nn);
        fac[0]=1;
        for(int i=1; i<(int)fac.size(); ++i){
            fac[i]=fac[i-1]*i%MOD;
        }
        auto dp = [&](int x, int y) -> auto& {return _dp[x+2001][y+2001];};
        for(int i=0; i<n; ++i){
            cin >> a[i] >> b[i];
            dp(-a[i],-b[i])++;
        }
        for(int i=-2000; i<=2000; ++i){
            for(int j=-2000; j<=2000; ++j){
                dp(i,j)=(dp(i,j)+dp(i-1,j)+dp(i,j-1))%MOD;
            }
        }
        LL ans =0;
        for(int i=0; i<n; ++i){
            ans=(ans+dp(a[i],b[i]))%MOD;
        }
        DBG(ans)
        for(int i=0; i<n; ++i){
            LL to_self=(fac[a[i]*2+b[i]*2]*modpow(fac[a[i]*2],MOD-2)%MOD)*modpow(fac[b[i]*2],MOD-2)%MOD;
            DBG(to_self)
            ans=(ans- to_self+MOD)%MOD;
        }
        cout << ans*modpow(2,MOD-2)%MOD <<"\n";
    }
};


int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    long long n;
    cin >> n;

    Problem p(n);
    p.solve();
    return 0;
}



Measured memory_bytes: 127360
#include <bits/stdc++.h>
#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define pf push_front
#define ll long long
using namespace std;
void TxtRead(){
    freopen("input.txt","r", stdin);
    freopen("output.txt","w", stdout);
}
void TheTime(){
    ios_base::sync_with_stdio(false);
	cin.tie();
}
const int N = 1e5+5;
const ll INF = 1e9+5;
const ll MOD = 1e9+7;
const double PI = 3.141592653589793116;

int n;
int ar[N][3], dp[N][3];

int main()
{
    //TxtRead();
    TheTime();

	scanf("%d", &n);
	for(int i=1; i<=n; i++){
		for(int j=1; j<=3; j++){
			scanf("%d", &ar[i][j]);
		}
	}
	for(int i=1; i<=n; i++){
		dp[i][1]=max({dp[i][1], 
			dp[i-1][2]+ar[i][1], dp[i-1][3]+ar[i][1]});
		dp[i][2]=max({dp[i][2], 
			dp[i-1][1]+ar[i][2], dp[i-1][3]+ar[i][2]});
		dp[i][3]=max({dp[i][3], 
			dp[i-1][1]+ar[i][3], dp[i-1][2]+ar[i][3]});
	}
	
	printf("%d\n", max({dp[n][1], dp[n][2], dp[n][3]}));
}

Measured memory_bytes: 2560
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws Exception {
		BufferedReader stdIn = new BufferedReader(new InputStreamReader(System.in));
		String s;
		int inCnt = 0;
		while ((s = stdIn.readLine()) != null) {
			inCnt++;
			String[] se = s.split(" ");
			int e = Integer.valueOf(se[0]);
			doMain(inCnt, e);
		}
		System.exit(0);
	}

	private static void doMain(int inCnt, int e) {
		for (int i = 1; i <= e; i++) {
			if (i % 3 == 0)
				System.out.print(" " + i);
			else
				for (int j = i; j != 0; j /= 10)
					if (j % 10 == 3) {
						System.out.print(" " + i);
						break;
					}
		}
		System.out.println("");

	}
}

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

int main(){

    long long int N, A, B;
    cin >> N >> A >> B;

    long long int fixedcount = (N/(A+B))*A;
    long long int remainder = (N%(A+B));
    if(remainder<A) cout << (fixedcount+remainder) << "\n";
    else cout << (fixedcount+A) << "\n";

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
typedef vector<int> vi;
typedef vector<double> vd;
 
double mypow(double b ,int e){
      if(e == 0) return 1;
      if(e%2==0)
            return mypow( b*b, e/2 );
      else
            return mypow( b*b, e/2 ) * b;
}
 
int main(){
 
 
      int N,M,L; cin >> N >> M >> L ;
      if(N==1){
            cout << 1.0 << endl;
            return 0;
      }
      vector<vd> prob(N,vd(M+1,0.0));
      vector<vd> dist(N,vd(M+1,0.0));
 
      vd p(N),t(N),v(N);
      for(int i=0; i<N; i++) cin >> p[i] >> t[i] >> v[i];
 
      // PRE PROCESS
      for(int i=0; i<N; i++){
            dist[i][0] = (double)L / v[i];
            for(int j=1; j<=M; j++){
                  dist[i][j] = dist[i][j-1] + t[i];
            }
      }
      for(int i=0; i<N; i++)
            prob[i][0] = mypow((100-p[i])/100,M);
      for(int i=0; i<N; i++){
            for(int j=1; j<=M; j++){
                  if(p[i] != 100)
                        prob[i][j] = (prob[i][j-1] * (p[i]/100)) / ((100-p[i])/100);
                  else
                        prob[i][j] = 1.0;
            }
      }
      double comb = 1;
      for(int j=1; j<=M; j++){
            comb = comb * (M - j + 1) / j; 
            for(int i=0; i<N; i++){
                  prob[i][j] *= comb;
            }
      }
       
      vector<vd> sum = prob;
      for(int i=0; i<N; i++){
            for(int j=M-1; j>=0; j--){
                  sum[i][j] += sum[i][j+1];
                  if(sum[i][j] > 1) sum[i][j] = 1;
            }
      }
 
      vector<vd> ans = prob;
      for(int i=0; i<N; i++){
            for(int j=0; j<=M; j++){
                  for(int k=0; k<N; k++){
                        if(i==k) continue;
                        int id = upper_bound(dist[k].begin(),dist[k].end(), dist[i][j]) - dist[k].begin();
                        if(id > M) ans[i][j] = 0.0;
                        else       ans[i][j] *= sum[k][id];
 
                  }
            }
      }
 
      for(int i=0; i<N; i++){
            double tmp = 0.0;
            if(p[i] == 100) tmp = ans[i][M];
            else
                  for(int j=0; j<=M; j++)
                        tmp += ans[i][j];
            if(tmp > 1) tmp = 0;
            printf("%.10f\n",tmp);
      }
                         
}

Measured memory_bytes: 3436
n, m = map(int, input().split())
ab = []
ans = [0] * n
for i in range(m):
    a, b = map(int, input().split())
    ab.append((a, b))
for i in ab:
    ans[i[0]-1] += 1
    ans[i[1]-1] += 1
for i in ans:
    print(i)

Measured memory_bytes: 3060
import collections
n = int(input())
si = []

for i in range(n):
    si.append(input())

ss = collections.Counter(si)
n_ma = max(ss.values())

ans = []
for i in ss.keys():
    if ss[i] == n_ma:
        ans.append(i)

ans.sort()

for i in range(len(ans)):
    print(ans[i])

Measured memory_bytes: 35576
#include <vector>
#include <string>
#include <iostream>
#include <iomanip>
#include <queue>
#include <algorithm>
#include <functional>
#include <map>
#include <array>
#include <cmath>
#include <set>
#include <numeric>

using namespace std;

template <typename T>
using TABLE = vector<vector<T>>;

using LONG = long long;
using LVEC = vector<long long>;

#define FOR(_i, s, e) for(_i = s; _i < e; ++_i)
#define FOR_INV(_i, s, e) for(_i = e - 1; _i >= s; --_i)

long long PRIME = 1e9 + 7;
long long PRIME2 = 998244353;


using pos = std::pair<LONG, LONG>;



int main(){
    LONG i, j, k;

    string T;
    cin >> T;

    char prev = 'A';
    LONG n = T.size();

    FOR(i, 0, n){
        if(T[i] == '?'){
            T[i] = 'D';
        }
    }

    cout << T << endl;

}




Measured memory_bytes: 3720
N = int(input())
A = list(map(int, input().split()))
m = 1000
s = 0
idx = 0
for i in range(N-1):
  if A[i]<A[i+1]:
    s = m//A[i]
    m = m%A[i]

  m += s*A[i+1]
  s = 0

print(m)

Measured memory_bytes: 9116
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;
using ll = long long int;
using int64 = long long int;
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const int INF = 1LL << 29;
const ll LONGINF = 1LL << 60;
const ll MOD = 1000000007LL;
 
int main() {
    int N; scanf("%d", &N);
    vector<int> D1(N+1), D2(N+1);
    D2[N] = 1;
    for(int i=0; i<N; i++) {
        scanf("%d%d", &D1[i], &D2[i]);
    }

    int cons = 0, ma = 0;
    for(int i=0; i<=N; i++) {
        if(D1[i] == D2[i]) cons++;
        else {
            ma = max(ma, cons);
            cons = 0;
        }
    }
    cout << (ma >= 3 ? "Yes" : "No") << endl;
    return 0;
}


Measured memory_bytes: 3692
/*
      H   H
       \ / 	
        C
       / \ 
      H   H
*/

#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define	endl		'\n'
#define pii         pair<ll, ll>
#define vi          vector<ll>
#define vvi			vector<vi>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll)x.size()
#define hell        998244353
#define rep(i,a,b)	for(ll i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define tr(c,i)		for(typeof((c).begin() i = (c).begin(); i != (c).end(); i++)
#define present(c,x)	((c).find(x) != (c).end()) 
#define cpresent(c,x)	(find(all(c),x) != (c).end()) 
#define int ll
using namespace std;

#define N  100005

int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int TESTS=1;
//	cin>>TESTS;
	while(TESTS--)
	{
		int n, m;
		cin >> n >> m;

		vi a[n+1];
		int visited[n+1];
		memset(visited, 0, sizeof(visited));

		rep(i, 0, m)
		{
			int x, y;
			cin >> x >> y;
			a[x].pb(y);
			a[y].pb(x);
		}

		queue<int> q;
		q.push(1);
		visited[1] = 1;


		while(!q.empty())
		{
			int v = q.front();
			q.pop();

			for(auto u: a[v])
			{
				if(!visited[u])
				{
					visited[u] = v;
					q.push(u);
				}
			}
		}

		for(int i = 2; i<=n; i++)
		{
			if(!visited[i])
			{
				cout << "No";
				return 0;
			}
		}
		cout << "Yes" << endl;
		for(int i = 2; i<=n; i++)
		{
			cout << visited[i] << " ";
		}

	}
	return 0;
}

Measured memory_bytes: 13012
#include "bits/stdc++.h"
// #pragma GCC optimize("Ofast")
// #pragma GCC optimize ("unroll-loops")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
using ll = long long int;

ll mpow(ll a, ll n, ll mod)
{
	ll r = 1;
	while (n) {
		if (n&1) r = r*a%mod;
		a = a*a%mod;
		n >>= 1;
	}
	return r;
}

ll sum[100001][40];
int link[100001][40];

int main()
{
	ios::sync_with_stdio(0); cin.tie(0);
	mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
	
	ll n, x, m; cin >> n >> x >> m;
	const int LOGN = 40;
	for (int i = 0; i < m; ++i) {
		sum[i][0] = i;
		link[i][0] = (1LL*i*i)%m;
	}
	for (int level = 1; level < LOGN; ++level) {
		for (int i = 0; i < m; ++i) {
			link[i][level] = link[link[i][level-1]][level-1];
			sum[i][level] = sum[i][level-1] + sum[link[i][level-1]][level-1];
		}
	}
	ll ans = 0;
	int node = x;
	for (int bit = LOGN-1; bit >= 0; --bit) {
		if ((n>>bit)&1) {
			ans += sum[node][bit];
			node = link[node][bit];
		}
	}
	cout << ans;
}

Measured memory_bytes: 50496
my $s = <STDIN>;
chomp $s;
my ($N,$K) = split(/ /,$s);
#print "$N,$K\n";
my $d;
my %data;
for(my $i=0;$i<$K;$i++){
    #print "i$i\n";
    $d = <STDIN>;
    $s = <STDIN>;
    chomp $s;
    my @dat = split(/ /,$s);
    for(my $j=0;$j<=$#dat;$j++){
        #print "$dat[$j]\n";
        $data{$dat[$j]} = 1;
    }
}
my $count =0;
foreach my $num (keys%data){
    #print "$num\n";
    $count++;
}
my $ans = $N - $count;
print "$ans";

Measured memory_bytes: 4804
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define Sort(Array) sort(Array.begin(), Array.end())
#define Reverse(a) reverse(a.begin(), a.end())
#define out(ans) cout << ans << endl;
const int MOD = 1000000007;
const int INF = 2147483647;
const ld PI = 3.14159265358979323846;

//------------↓------------- M -------------- E ---------------- M --------------- O ---------------↓--------------//
// コンパイル 
// g++ -std=c++1z
//
// -------型変換--------
// int を string に変換
// string s = to_string(n);
// string を int に変換
// int n = stoi(s);
//
// -------二分探索---------
// k以上の値が最初に現れる時のイテレータ
// lower_bound(data.begin(), data.end(), k)
// kより大きい値が最初の現れる時のイテレータ O(logN)
// upper_bound(data.begin(), data.end(), k)
// kがdataに存在するかをtrue or falseで返す O(logN)
// binary_search(data.begin(), data.end(), k)
// 
//
//
//
//
//
// 
//------------↑------------- M -------------- E ---------------- M --------------- O ---------------↑--------------//






int main(void) {

    int N, K;
    cin >> N >> K;
    int md[K]; 
    rep(i,K) md[i] = 0;
    for (int i = 1; i <= N; ++i) {
        ++md[i%K];
    } 
    ll ans = pow(md[0], 3);
    if (K % 2 == 0) {
        ans += pow(md[K/2], 3);
    }

    out(ans);

    
    return 0;
}









Measured memory_bytes: 1024
NQ = input().split(' ')
N = int(NQ[0])
Q = int(NQ[1])
out_put_list = [0] * N
tree_list = [[] for i in range(N)]

for i in range(N-1):
    ab = input().split(' ')
    a = int(ab[0]) -1
    b = int(ab[1]) -1
    tree_list[a].append(b)

for _ in range(Q):
    px = input().split(' ')
    p = int(px[0])
    x = int(px[1])
    out_put_list[p-1] += x

for i in range(len(tree_list)):
    for num in tree_list[i]:
        out_put_list[num] += out_put_list[i]

print(*out_put_list)

Measured memory_bytes: 47888
X = int(input())
A = [1,2,3,4,5,6,7,8,9]
B = [1,2,3,4,5,6,7,8,9]
C =[]

for i in A:
    for j in B:
        k=i*j
        C.append(k)

C= list(set(C))

if X in C:
    print("Yes")
else:
    print("No")       

Measured memory_bytes: 3064
#include <cstdio>
#include <cmath>

int main()
{

  int n ;

  int x[100],y[100] ;
  
  scanf(" %d", &n);
	for(int i=0; i<n; ++i)
		scanf(" %d", &x[i]); 
	for(int i=0; i<n; ++i)
		scanf(" %d", &y[i]); 

  double d ;

  for(int i=1;i<=3;i++){
    d = 0.0;

      for(int j=0;j<n;j++){
      d+=pow(fabs(x[j]-y[j]),i) ;
      }
     // cout << pow(d,1.0/i) << endl;
      printf("%lf\n", pow(d,1.0/i));
  }


  double max = 0;
  for(int i=0;i<n;i++){
      if(max<(fabs(x[i]-y[i]))) max = fabs(x[i]-y[i]) ;
  }
  printf("%lf\n", max);
//      cout << d << endl;
  
  
    return 0;
}


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


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

    int right, left;
    long long ans = 0;
    for(int i = 0; i < n; i++) {
        left = min(a[i], b[i]);
        ans += left;
        b[i] -= left;
        a[i] -= left;
        right = min(a[i+1], b[i]);
        ans += right;
        a[i+1] -= right;
        b[i] -= right;

    }
    // int ans = 0;



    cout << ans << endl;

}


Measured memory_bytes: 1024
import itertools

n = int(input())
f = [list(map(int, input().split())) for _ in range(n)]
p = [list(map(int, input().split())) for _ in range(n)]
times = list(itertools.product([0, 1], repeat=10))
times.remove((0, 0, 0, 0, 0, 0, 0, 0, 0, 0))
profit = float('-inf')
for exhibit in times:
    c = []
    for shop in f:
        c.append([exhibit[i] + shop[i] for i in range(10)].count(2))
    profit = max(profit, sum([p[i][c[i]] for i in range(n)]))
print(profit)

Measured memory_bytes: 3188
import java.io.*;
import java.util.*;
import java.awt.Point;
public class Main {
	static Scanner sc;
	static PrintWriter out;
	public static void main(String[] args) throws Exception{
		// TODO Auto-generated method stub
		sc = new Scanner(System.in); 
		out = new PrintWriter(System.out);
		String s = sc.nextLine();
		if(s.charAt(4) == s.charAt(5) && s.charAt(2) == s.charAt(3))
			out.println("Yes");
		else
			out.println("No");
		out.close();
	}
	static final int uncal = -1;
	static final long inf = Long.MIN_VALUE;
	static boolean isPalindrome(String s) {
		int l = s.length();
		char[] sa = s.toCharArray();
		for(int i=0;i<l/2;i++) {
			if(sa[i] != sa[l-i-1])
				return false;
		}
		return true;
	}

	static String reverse(String s) {
		int i = s.length();
		StringBuilder sb = new StringBuilder();
		while(i-->0) {
			sb.append(s.charAt(i));
		}
		return sb.toString();
	}
	static void merge(StringBuilder sb,Stack<Character> stack) {
		while(!stack.isEmpty())
			sb.append(stack.pop());		
	}
	static String max(String s,String s2) {
		if(s2.length() > s.length())
			return s2;
		return s;
	}

	static class Point extends java.awt.Point implements Comparable<Point>{
		public Point(int x,int y) {
			// TODO Auto-generated constructor stub
			super(x,y);
		}
		public String toString() {
			return x+" "+y;
		}
		@Override
		public int compareTo(Point p) {
			// TODO Auto-generated method stub
			if(x == p.x)
				return y - p.y;
			return x - p.x;
		}
		
	}
	static class Scanner{
		private BufferedReader br;
		private StringTokenizer st;
		public Scanner(InputStream in) {
			br = new BufferedReader(new InputStreamReader(in));
		}
		public String next() throws IOException{
			while(st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}
		public String nextLine() throws IOException {
			return br.readLine();
		}
		public int nextInt() throws IOException{
			return Integer.parseInt(next());
		}
		public long nextLong() throws IOException{
			return Long.parseLong(next());
		}
		public double nextDouble() throws IOException{
			return Double.parseDouble(next());
		}
		public int[] inArr(int n) throws Exception{
			int a [] = new int[n];
			st = new StringTokenizer(br.readLine());
			for(int i=0;i<n;i++) {
				a[i] = Integer.parseInt(st.nextToken());
			}
			return a;
		}
	}

}

Measured memory_bytes: 23124
#include <iostream>

using ldouble = long double;

void solve() {
    ldouble r;
    std::cin >> r;
    std::cout << r * 2 * 3.141592 << std::endl;
}

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

    solve();

    return 0;
}


Measured memory_bytes: 3800
#include <iostream>
#include <string>
using namespace std;
int main() {
	int sum;
	string s;
	while (cin >> s, s != "0") {
		sum = 0;
		for (int i = 0; i < s.size(); i++) sum += (s[i] - 48);
		cout << sum << endl;
	}
}

Measured memory_bytes: 1188
#include <bits/stdc++.h>
using namespace std;
using ll = long long ;
using P = pair<ll, ll>;
using Vec = vector<ll>;
using VecP = vector<P>;
#define REP(i, m, n) for(ll (i) = (m); (i) < (n); ++(i))
#define REPN(i, m, n) for(ll (i) = (m); (i) <= (n); ++(i))
#define REPR(i, m, n) for(ll (i) = (m); (i) >= (n); --(i))
#define rep(i, n) REP(i, 0, n)
#define repn(i, n) REPN(i, 1, n)
#define repr(i, n) REPR(i, n, 0)
#define repnr(i, n) REPR(i, n, 1)
#define co(n) cout << (n) << endl
#define cosp(n) cout << (n) << ' '
#define setp(n) cout << fixed << setprecision(n);
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fs first
#define sc second
template <typename T> bool chmax(T &a, const T& b){if(a < b){a = b; return true;} return false;}
template <typename T> bool chmix(T &a, const T& b){if(a > b){a = b; return true;} return false;}
const ll INF = 1e9+1;
const ll LINF = 1e18+1;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const double PI = acos(-1);
const double EPS = 1e-9;

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

	Vec a(n);
	vector<Vec> t(n, Vec(n, -1));
	rep(i, n){
		cin >> a[i];
		rep(j, a[i]){
			ll x, y;
			cin >> x >> y;
			t[i][x-1] = y;
		}
	}

	Vec honest(n);
	ll ans = 0, cnt = 0;
	rep(i, (1 << n)){
		bitset<30> bit(i);

		bool flg = true;
		rep(j, n){
			if(bit[j]){
				rep(k, n){
					if(t[j][k] != -1){
						if(t[j][k] != bit[k]){
							flg = false;
							break;
						}
					}
				}
			}
			if(!flg) break;
		}
		if(flg){
			ans = max(ans, (ll)bit.count());
		}
	}
	co(ans);

	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<queue>
#include<map>
using namespace std;
typedef pair < int , int > Pi;
typedef pair < int , Pi > Pii;
#define fr first
#define sc second
const int dy[] = { -1, -1, 0, 1, 1, 0 }, dx[] = { -1, 0, 1, 1, 0, -1 };
bool mas[256][256], used[256][256];
 
int main(){
  int n, t;
  while(cin >> t >> n , t || n){
    fill_n( *mas, 256 * 256, false);
    fill_n( *used, 256 * 256, false);
    for(int i = 0 ; i < n ; i++ ){
      int y, x;
      cin >> x >> y;
      mas[100 + y][100 + x] = true;
    }
    int sy, sx;
    cin >> sx >> sy;
    int ret = 0;
    queue< Pii > que;
    que.push(Pii( t, Pi(sy + 100, sx + 100)));
    while(!que.empty()){
      Pii p = que.front();
      que.pop();
      if(p.fr < 0 || used[p.sc.fr][p.sc.sc]++) continue;
      ret++;
      for(int i = 0 ; i < 6 ; i++ ){
        int ny = p.sc.fr + dy[i], nx = p.sc.sc + dx[i];
        if(!mas[ny][nx]) que.push(Pii( p.fr - 1, Pi( ny, nx)));
      }
    }
    cout << ret << endl;
  }
}


Measured memory_bytes: 3236
#include <bits/stdc++.h>
  
using namespace std;
  
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) (r).begin(),(r).end()
#define rall(r) (r).rbegin(),(r).rend()
#define fi first
#define se second
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;

int main(){
#ifdef LOCAL_TEST
    freopen("in", "r", stdin);
    freopen("out", "w", stdout);
#endif
    int r, g, b;
    cin >> r >> g >> b;
    string yes = "YES", no = "NO";
    cout << ((g*10 + b) % 4 == 0 ? yes : no) << endl;
    return 0;
}

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

const int MAX=1401;
int G[MAX][MAX];
int H,W;

int getLargestSquare(int H, int W){

    int maxWidth=0;
    int dp[H][W];
    for(int i=0; i<H; i++){
        for(int j=0; j<W; j++){
            if(G[i][j]) dp[i][j]=0;
            else{
                dp[i][j]=1;
                maxWidth=1;
            }
        }
    }

    for(int i=1; i<H; i++){
        for(int j=1; j<W; j++){
            if(dp[i][j]==1){
                dp[i][j]=min(dp[i-1][j],min(dp[i-1][j-1], dp[i][j-1]))+1;
            }
            //cout << dp[i][j]<< endl;
            maxWidth=max(maxWidth, dp[i][j]);
            
        }
    }

    return maxWidth*maxWidth;

}


int main(void){
    cin >> H >> W;
    for(int i=0; i<H; i++){
        for(int j=0; j<W; j++){
            cin >> G[i][j];
        }
    }

    cout << getLargestSquare(H,W) << endl;
}


Measured memory_bytes: 18380
#include<iostream>
#define _USE_MATH_DEFINES
#include<math.h>
#include<vector>
#include<array>
#include<algorithm>
#include<numeric>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<set>
#include<cstdio>
#include<cstring>
#include<string>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<ll> vec;
typedef vector<vector<ll>> mat;
typedef pair<ll,ll> P;
typedef map<ll,ll> MP;
typedef priority_queue<ll> PQ;
typedef stack<ll> ST;
typedef queue<ll> QUE;
#define pb push_back
#define st first
#define nd second
#define SZ(x) ((int)(x).size())
#define FOR(i,s,n) for(int i=(int)(s); i< (int)(n); i++)
#define rep(i,n) FOR(i,0,n)
#define all(x) (x).begin(),(x).end()
#define each(x,c) for(auto x: (c))
#define LB(x,a) lower_bound(all(x), a)
#define UB(x,a) upper_bound(all(x), a)
const ll mod=1e9+7;
const ll INF=1e18;
const double EPS=1.0e-10;
const double PI=M_PI;

int main(){
    int N; cin>>N;
    string S; cin>>S;
    bool exist1=false;
    rep(i,N){
        if(S[i]=='2') exist1=true;
    }
    vec ord1(N),ord2(N),parity(N); ord1[0]=ord2[0]=0; parity[0]=1;
    FOR(i,1,N){
        ll x=i, y=N-i, res1=0, res2=0;
        while(x%2 == 0){
            x/=2;
            res1++;
        }
        while(y%2 == 0){
            y/=2;
            res2++;
        }
        ord1[i] = ord1[i-1]+res1;
        ord2[i] = ord2[i-1]+res2;
        if(ord2[i] == ord1[i]) parity[i]=1;
        else parity[i]=0;
    }
    if(exist1){
        ll res=0;
        rep(i,N){
            res += parity[i]*(S[i]-'1');
        }
        if(res%2 == 0) cout<<0<<endl;
        else           cout<<1<<endl;
        return 0;
    }
    else{
        ll res=0;
        rep(i,N){
            res += parity[i] * ((S[i]-'1')/2); 
        }
        if(res % 2 == 0) cout<<0<<endl;
        else             cout<<2<<endl;
        return 0;
    }
}

Measured memory_bytes: 24836
A,B = map(int,input().split())

#素数列挙
def searchPrimeNum(N):
    max = int(N**0.5)
    seachList = [i for i in range(2,N+1)]
    primeNum = []
    while seachList[0] <= max:
        primeNum.append(seachList[0])
        tmp = seachList[0]
        seachList = [i for i in seachList if i % tmp != 0]
    primeNum.extend(seachList)
    return primeNum



#素因数分解(素数列挙が必要)
def pfact(N):
    plis = searchPrimeNum(int(N**0.5+1))
    ans = 1
    for p in plis:
        if N%p == 0:
            ans += 1
            N = N//p
        while N%p == 0:
            N = N//p
        if N == 1:
            break
    if N != 1:
        ans += 1
    return ans

#互除法(最大公約数)
def gcd(a,b):
    if b==0:
        return a
    else:
        return gcd(b,a%b)

print(pfact(gcd(A,B)))

Measured memory_bytes: 46496
#include <stdio.h>
#include <stdlib.h>
 
int main(void)
{
    int i,j,k;
    int count[50002]={};
    int temp[2][50002]={};
    int n,m,prevsize,nextsize=0,coin[20]; //input
    int *prevlist,*nextlist;
    scanf("%d %d",&n,&m);
    for(i=0;i<m;i++){
        scanf("%d",&coin[i]);
        count[coin[i]]=1;
	temp[0][i]=coin[i];
    }
    prevsize=n;
    i=1;
    while(1){
      prevlist=temp[(i-1)%2];
      nextlist=temp[i%2];
      for(j=0;j<prevsize;j++){    
	for(k=0;k<m;k++){
	  if(prevlist[j]+coin[k]<=n && count[prevlist[j]+coin[k]]==0){
	    count[prevlist[j]+coin[k]]=i+1;
	    nextlist[nextsize-1]=prevlist[j]+coin[k];
	    nextsize++;
	  }
	  if(count[n]!=0)break;
	}
      }
      if(count[n]!=0) break;
      if(count[n]!=0) break;
      prevsize=nextsize;
      nextsize=0;
      i++;
    }
    printf("%d\n",count[n]);
     
    return 0;
}

Measured memory_bytes: 1192
#include<bits/stdc++.h>
using namespace std;
 
typedef long long ll;
#define rep(i,a,b) for (int i = a; i < b; i++)
#define repn(i,a,b) for (int i = a; i >=b ;i--)
#define MOD 1000000007

void solve(){
  ll n,k;cin>>n>>k;
  ll ans=0;
  rep(i,k,n+2){
      ans=(ans+(n-i+2)+ (n-i+1)*(i-1))%MOD;//cout<<(n-i+2)+ (n-i+1)*(i-1)<<" ";
  }
  cout<<ans%MOD;
  

 
 
return ;
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
   int t=1;
   //cin>>t;
   rep(i,0,t){
     solve();
  }
return 0;
}

Measured memory_bytes: 3536
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		String s = scan.next();
		int a = 1;
		if (s.equals("SUN")) {
			a = 7;
		} else if (s.equals("MON")) {
			a = 6;
		} else if (s.equals("TUE")) {
			a = 5;
		} else if (s.equals("WED")) {
			a = 4;
		} else if (s.equals("THU")) {
			a = 3;
		} else if (s.equals("FRI")) {
			a = 2;
		} else {

		}

		System.out.println(a);

	}
}

Measured memory_bytes: 21204
#include <bits/stdc++.h> 
#define rep(i,n) for (int i = 0; i < (n); ++i)
using ll =long long;
using namespace std;
using graph=vector<vector<int>>;
using field=vector<string>;
using p =pair<int,int>;
const ll mod=1000000007;
const int dx[]={0,1,0,-1};
const int dy[]={1,0,-1,0};

int main(){
    string s;
    cin>>s;
    int a[4];
    rep(i,4)a[i]=s[i]-'0';
    rep(i,8){
        int ans=a[0];
        for(int j=2;j>=0;--j){
            if((i>>j)&1){
                ans+=a[3-j];
            }else{
                ans-=a[3-j];
            }
        }
        if(ans==7){
            cout<<a[0];
            for(int k=2;k>=0;--k){
                if((i>>k)&1){
                    cout<<"+"<<a[3-k];
                }else{
                    cout<<"-"<<a[3-k];
                }
            }
            cout<<"=7"<<endl;
            return 0;
        }
    }
}


Measured memory_bytes: 3576
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i <(n); ++i)
#define REP2(i,x,n) for (int i = x; i <(n); ++i)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
using namespace std;
using ll = long long;
using P = pair<int,int>;
static const double PI = acos(-1);
static const int INF = 1e9+7;
#define REP(i,n) for (int i = 0; i <(n); ++i)


int main(){
  int a, b, c;
  cin >> a >> b >> c;
  if(a < c && c < b) cout << "Yes" << endl;
  else if(c < a && b < c) cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;
}


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

int main()
{
    int t ;
    cin >> t ;
    int ans = 0;
    while(t--)
    {
        int a,b;
        cin >> a >> b ;
        ans += abs(a-b)+1;
    }
    cout << ans<< endl;
    return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import sys

N,M=map(int, sys.stdin.readline().split())
al=[ [] for i in range(N+1) ]	#隣接リスト
rev_al=[ [] for i in range(N+1) ]	#リバース隣接リスト
O=[ 0 for i in range(N+1) ] #出次数
edge=[] #辺の集合

for _ in range(M):
    s,t=map(int, sys.stdin.readline().split())
    al[s].append(t)
    rev_al[t].append(s)
    #I[t]+=1
    O[s]+=1
    edge.append((s,t))


#頂点毎の到達する確立
P=[ 0 for i in range(N+1) ]   #確率
P[1]=1
 
for x in range(1,N+1):
    if O[x]!=0:
        p=float(1)/O[x]
        for to in al[x]:
            P[to]+=P[x]*p
        
#頂点毎の期待値
E=[ 0 for i in range(N+1) ]   #期待値

for x in range(N,0,-1):
    for to in rev_al[x]:
        p=float(1)/O[to]
        E[to]+=(E[x]+1)*p


#消す辺
ans=E[1]
for del_s,del_t in edge:
    if O[del_s]-1==0:
        continue
    new_E=float(E[del_s]*O[del_s]-(E[del_t]+1))/(O[del_s]-1)
    if new_E<E[del_s]:
        ans=min(ans,E[1]-(E[del_s]-new_E)*P[del_s])

print ans

Measured memory_bytes: 67100
Option Strict On
Module ProblemB

    Sub Main()
        Dim s() As Char = Console.ReadLine.ToCharArray()
        Dim i, j As Integer
        Dim ans As Integer = 0

        For i = 0 To s.Length - 1
            j = s.Length - i - 1
            If s(i) <> s(j) Then
                ans += 1
            End If
            If i = j OrElse i + 1 = j Then Exit For
        Next

        Console.WriteLine(ans.ToString)
    End Sub

End Module

Measured memory_bytes: 13140
#include <stdio.h>

int main()
{
	int n, k, x;

	scanf("%d", &n);
	scanf("%d", &k);

	x = 1;

	for (int i = 0; i < n; i++) {
		if (x > k) {
			x += k;
		}
		else {
			x *= 2;
		}
	}

	printf("%d", x);

	return 0;
}


Measured memory_bytes: 256