akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <bitset>
#include <cctype>
#include <chrono>
#include <cmath>
#include <cstdio>
#include <ctime>
#include <iostream>
#include <map>
#include <random>
#include <string>
#include <unordered_map>
#include <vector>
using namespace std;

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

const int INF = 0x3f3f3f3f;
/*---------------------------------------*/

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  // freopen("input.txt", "r", stdin);

  int n; string s; int q; cin >> n >> s >> q;
  vector<int> k(q); REP(i, q) cin >> k[i];

  REP(i, q) {
    int d = 0, m = 0;
    long long dm = 0, ans = 0;
    REP(j, n) {
      if (j >= k[i]) {
        if (s[j-k[i]] == 'D') {
          --d;
          dm -= m;
        } else if (s[j-k[i]] == 'M') {
          --m;
        }
      }

      if (s[j] == 'D') {
        ++d;
      } else if (s[j] == 'M') {
        ++m;
        dm += d;
      } else if (s[j] == 'C') {
        ans += dm;
      }
    }
    cout << ans << "\n";
  }
  return 0;
}


Measured memory_bytes: 1948
#[allow(unused_macros)]
macro_rules ! input { ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; let mut next = || { iter . next ( ) . unwrap ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; ( $ ( $ r : tt ) * ) => { let stdin = std :: io :: stdin ( ) ; let mut bytes = std :: io :: Read :: bytes ( std :: io :: BufReader :: new ( stdin . lock ( ) ) ) ; let mut next = move || -> String { bytes . by_ref ( ) . map ( | r | r . unwrap ( ) as char ) . skip_while ( | c | c . is_whitespace ( ) ) . take_while ( | c |! c . is_whitespace ( ) ) . collect ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules ! input_inner { ( $ next : expr ) => { } ; ( $ next : expr , ) => { } ; ( $ next : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules ! read_value { ( $ next : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ next , $ t ) ) ,* ) } ; ( $ next : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ next , $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ next : expr , chars ) => { read_value ! ( $ next , String ) . chars ( ) . collect ::< Vec < char >> ( ) } ; ( $ next : expr , usize1 ) => { read_value ! ( $ next , usize ) - 1 } ; ( $ next : expr , $ t : ty ) => { $ next ( ) . parse ::<$ t > ( ) . expect ( "Parse error" ) } ; }

fn main() {
    input! {
        a: u64, b: u64, c: u64
    }

    println!("{}", if a+b>=c {"Yes"} else {"No"});
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n,m,k;
	cin >> n >> m >> k;
	for(int i=0;i<=n;i++){
		for(int j=0;j<=m;j++){
			if(i*m + j*n - 2*i*j == k){
				cout << "Yes" << endl;
				return 0;
			}
		}
	}
	cout << "No" << endl;
	return 0;
}

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

#define M 1046527
#define NIL (-1)
#define L 14

char H[M][L];

int getChar(char ch){
	if (ch == 'A')return 1;
	else if (ch == 'C')return 2;
	else if (ch == 'G')return 3;
	else if (ch == 'T')return 4;
	else return 0;
}

long long getKey(char str[]){
	long long sum = 0, p = 1, i;
	for (i = 0; i < strlen(str); i++){
		sum += p*(getChar(str[i]));
		p *= 5;
	}
	return sum;
}

int h1(int key){
	return key % M;
}

int h2(int key){
	return 1 + (key % (M - 1));
}

int find(char str[]){
	long long key, i, h;
	key = getKey(str);
	for (i = 0;; i++){
		h = (h1(key) + i*h2(key)) % M;
		if (strcmp(H[h], str) == 0)return 1;
		else if (strlen(H[h]) == 0)return 0;
	}
	return 0;
}

int insert(char str[]){
	long long key, i, h;
	key = getKey(str);
	for (i = 0;; i++){
		h = (h1(key) + i * h2(key)) % M;
		if (strcmp(H[h], str) == 0)return 1;
		else if (strlen(H[h]) == 0){
			strcpy(H[h], str);
			return 0;
		}
	}
	return 0;
}

int main(){
	int i, n, h;
	char str[L], com[9];
	for (i = 0; i < M; i++)H[i][0] = '\0';
	scanf("%d", &n);
	for (i = 0; i < n; i++){
		scanf("%s %s", com, str);
		if (com[0] == 'i'){
			insert(str);
		}
		else{
			if (find(str)){
				printf("yes\n");
			}
			else{
				printf("no\n");
			}
		}
	}
	return 0;
}

Measured memory_bytes: 16960
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <stack>
#include <climits>
#include <map>
#include <set>

using namespace std;

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

const ll mod = 1000000007;
const int inf = 1e9;
const long long INF = 1LL << 60;

struct UnionFind{
    vector<int> rank,p,size;
    UnionFind(int n){
        rank.resize(n,0);
        p.resize(n,0);
        size.resize(n,0);
        for(int i = 0; i < n; i++){
            p[i] = i;
            rank[i] = 0;
            size[i] = 1;
        }
    }
    bool same(int x,int y){
        return root(x) == root(y);
    }
    int root(int x){
        if(x != p[x]){
            p[x] = root(p[x]);
        }
        return p[x];
    }
    bool unite(int x,int y){
        int rx = root(x);
        int ry = root(y);
        if(rx == ry) return false;
        if(rank[rx] > rank[ry]){
            p[ry] = rx;
            size[rx] += size[ry];
        }else{
            p[rx] = ry;
            size[ry] += size[rx];
            if(rank[rx] == rank[ry]){
                rank[ry]++;
            }
        }
        return true;
    }
    int tree_size(int x){
        return (size[root(x)]);
    }
};


int main()
{
    int n,k,l;
    cin >> n >> k >> l;
    UnionFind a(n);
    UnionFind b(n);
    for(int i = 0; i < k; i++){
        int p,q;
        cin >> p >> q;
        p--; q--;
        a.unite(p,q);
    }
    for(int i = 0; i < l; i++){
        int r,s;
        cin >> r >> s;
        r--; s--;
        b.unite(r,s);
    }
    vector<pair<int,int> >v;
    for(int i = 0; i < n; i++){
        v.push_back(make_pair(a.root(i),b.root(i)));
    }
    map<pair<int,int>,int> mp;
    for(int i = 0; i < n; i++){
        auto iter = mp.find(v[i]);
        if(iter != mp.end()){
            mp[v[i]]++;
        }else{
            mp[v[i]] = 1;
        }
    }
    for(int i = 0; i < n; i++){
        cout << mp[v[i]] << ' ';
    }
}

Measured memory_bytes: 18160
import java.util.Scanner;
import java.util.stream.IntStream;

public class Main {

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			char[] s = scanner.next().toCharArray(), t = scanner.next().toCharArray();
			System.out.println(t.length
					- IntStream.rangeClosed(0, s.length - t.length).map(i -> calcResult(i, s, t)).max().getAsInt());
		}
	}

	private static int calcResult(int from, char[] s, char[] t) {
		int result = 0;
		for (int i = 0; i < t.length; i++) {
			result += (s[from + i] == t[i]) ? 1 : 0;
		}
		return result;
	}
}


Measured memory_bytes: 36212
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
template <typename X> ostream& operator << (ostream& x,const vector<X>& v){for(ll i=0;i<v.size();++i) x<<v[i]<<" ";return x;}
template <typename X> ostream& operator << (ostream& x,const set<X>& v){for(auto it:v) x<<it<<" ";return x;}
template <typename X, typename Y> ostream& operator << (ostream& x, const pair<X,Y>& v) {x<<v.ff<<" "<<v.ss;return x;}
template <typename T, typename S> ostream& operator << (ostream& os, const map<T, S>& v) { for (auto it : v) os << it.first << "=>" << it.second << endl; return os; }
struct pair_hash {inline std::size_t operator()(const std::pair<ll, ll> & v) const {return v.first*31+v.second;}};
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define speed ios_base::sync_with_stdio(false);cin.tie(NULL)
#define pb push_back
#define fr first
#define sc second
#define prnt(m) for(auto it = m.begin() ; it != m.end() ; ++it){cout<<*it<<endl;}
#define tra(it,m) for(auto it=m.begin();it!=m.end();++it)
#define DBG(x) cout<<"# # #     "<<x<<'\n';
#define fri(i,s,n) for(long long i=s;i<n;i++)
#define mod 1000000007LL
#define mod2 998244353
#define vct2 vector<vector<ll>>
#define vct vector<ll>
#define pll pair<ll,ll>
#define rz(n) resize(n)
#define all(v) v.begin(),v.end()
#define mkp make_pair
#define arrin(a,n) for(ll i = 0; i < n ; i++){cin>>a[i];}
#define arrout(a,n) for(ll i = 0;i < n; i++){cout<<a[i]<<" ";}
#define ex(s) cout<<s<<endl,exit(0);
#define infy 2e18
#define five 100005;
#define six 1000005;
#define printclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";
//___________________________________________________________________________________________________________________________________________________________
const int N = five;
ll dp[102][N];
ll a[102][N];
int n,wt;
ll w[102];
ll v[102];
ll f(int i,int j)
{
       if(i==n-1){
              dp[i][j] = 0;
              if(w[i]<=j){
                     dp[i][j] = v[i];
              }
              return dp[i][j];
       }
       if(dp[i][j] != -1){return dp[i][j];}
       if(w[i]<=j){
              return dp[i][j] = max(f(i+1,j-w[i])+v[i],f(i+1,j));
       }
       return dp[i][j] = f(i+1,j);
}
int main()
{
       cin>>n>>wt;
       fri(i,0,n){
              cin>>w[i]>>v[i];
       }
       memset(dp,-1,sizeof dp);
       cout<<f(0,wt)<<endl;
}


Measured memory_bytes: 81792
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,k,b=0;
    cin>>n>>k;
    int a[n];
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        if(a[i]>=k)
        b++;
    }
    cout<<b<<"\n";
}

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

int main() {
	int k,s,x,y,z;
	int count=0;
	cin >> k >> s; //範囲 和

	for(int x=0;x<=k;++x) {
		for(int y=0;y<=k;++y) {
			if(x+y<=s && x+y+k>=s) {
				++count;
			}
		}
	}
	cout << count << endl;
	return 0;
}



Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
char s[60],t[60];
int n,m;
bool check(int k,char ch)
{
	for(int i=k;i<m+k;i++)
		if(s[i]!=t[i-k]&&s[i]!=ch)return 0;
	return 1;
}
int main()
{
	scanf("%s%s",s,t);
	n=strlen(s);
	m=strlen(t);
	for(int i=0;i<n;i++)
		if(check(i,' '))
		{
			for(int j=0;j<n;j++)
				if(s[j]=='?')s[j]='a';
			puts(s);
			return 0;
		}
	for(int i=n-m;i>=0;i--)
		if(check(i,'?'))
		{
			for(int j=i;j<i+m;j++)s[j]=t[j-i];
			for(int j=0;j<n;j++)
				if(s[j]=='?')s[j]='a';
			puts(s);
			return 0;
		}
	puts("UNRESTORABLE");
	return 0;
}


Measured memory_bytes: 128
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<cstring>
#define LL long long
using namespace std;
const LL inf=1LL<<60;
LL n,a[200010],sum[200010],ans=inf;
LL k1,k2,p;
void solve()
{
	LL t1=max(max(sum[k1],sum[p]-sum[k1]),max(sum[k2]-sum[p],sum[n]-sum[k2]));
	LL t2=min(min(sum[k1],sum[p]-sum[k1]),min(sum[k2]-sum[p],sum[n]-sum[k2]));
	ans=min(ans,t1-t2);
}
int main()
{
	scanf("%lld",&n);
	for(LL i=1;i<=n;i++) scanf("%lld",&a[i]);
	for(LL i=1;i<=n;i++) sum[i]=sum[i-1]+a[i];
	k1=1;p=2;k2=3;solve();
	while(p<=n-2)
	{
		if(k2==p) k2++;
		while(k1<p&&abs(sum[p]-sum[k1]-sum[k1])>=abs(sum[p]-sum[k1+1]-sum[k1+1])) k1++;
		while(k2<n&&abs(sum[k2]-sum[p]-(sum[n]-sum[k2]))>=abs(sum[k2+1]-sum[p]-(sum[n]-sum[k2+1]))) k2++;
		solve();p++;
	}
	printf("%lld",ans);
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define EPS (1e-10)
using namespace std;
typedef long long ll;
typedef pair<int,int>P;

char s[2000][2000];
int dx[]{1,-1,0,0},dy[]{0,0,1,-1};
int d[2000][2000];

int main(){
	int h,w;cin>>h>>w;
	queue<P>que;
	memset(d,-1,sizeof(d));
	rep(i,h){
		scanf("%s",s[i]);
		rep(j,w){
			if(s[i][j]=='#'){
				que.push(P(i,j));
				d[i][j]=0;
			}
		}
	}
	while(!que.empty()){
		auto p=que.front();que.pop();
		rep(k,4){
			int nx=p.first+dx[k],ny=p.second+dy[k];
			if(0<=nx&&nx<h&&0<=ny&&ny<w&&d[nx][ny]==-1&&s[nx][ny]=='.'){
				d[nx][ny]=d[p.first][p.second]+1;
				que.push(P(nx,ny));
			}
		}
	}
	int Max=0;
	rep(i,h)rep(j,w)Max=max(Max,d[i][j]);
	cout<<Max<<endl;
}

Measured memory_bytes: 26896
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <queue>
#include <deque>
#include <list>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <string>
#include <bitset>
#include <fstream>
#include <iomanip>

using namespace std;

#define PB push_back
#define MP make_pair
#define X first
#define Y second
#define gcd __gcd

#define cil(a,b) ( ((a)%(b) == 0)?((a)/(b)):((a)/(b)+1) )
#define err(x) cerr << #x << " = " << x << endl;
#define read(a) freopen(a,"r",stdin)
#define write(a) freopen(a,"w",stdout)
#define forall(i,a,b) for(int i=a;i<b;i++)
#define foreach(v, c) for(typeof((c).begin())v=(c).begin();v!=(c).end();++v)

typedef long long ll;
typedef double db;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;
typedef vector<pii> vii;

clock_t start;
void Time(bool timeIt) {
	if (!timeIt) return;
	clock_t end = clock();
	double elapsed_time = ((db)end - (db)start) / (db)CLOCKS_PER_SEC;
	printf("Time elapsed = %0.4lf\n", elapsed_time); 
}

#define LINF (long long)1e18
#define EPS 1e-9
#define INF 1000000007ll
#define SIZE 100010
#define MAX_A 1000010

int a[2][111];
int main() {
	start = clock();
	int n;
	cin >> n;
	for (int i = 0 ; i < n ; ++i) cin >> a[0][i];
	for (int i = 0 ; i < n ; ++i) cin >> a[1][i];
	for (int i = 1 ; i < n ; ++i) a[0][i] += a[0][i - 1];
	for (int i = n - 2 ; i >= 0 ; --i) a[1][i] += a[1][i + 1];

	int mx = 0;
	for (int i = 0 ; i < n ; ++i) {
		mx = max(mx, a[0][i] + a[1][i]);		
	}
	cout << mx << endl;

	Time(false);
	return 0;
}

Measured memory_bytes: 256
import math
n=int(input())
plis=list(map(int,input().split()))
qlis=list(map(int,input().split()))
acounter=0
bcounter=0
pdic=[]
qdic=[]
for i in range(1,n+1):
	pdic.append(i)
	qdic.append(i)
for i in range(n):
	a=int((math.factorial(n-i)/(n-i))*(pdic.index(plis[i])))
	acounter+=a
	pdic.remove(plis[i])
	b=int((math.factorial(n-i)/(n-i))*(qdic.index(qlis[i])))
	bcounter+=b
	qdic.remove(qlis[i])
print(abs((acounter+1)-(bcounter+1)))

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

int main(){
	long long N;
	cin >> N;
	long long ans=99999999999999;
	for(long long i=1;i*i<=N;i++){
		if(N%i==0){
			ans=min(ans,i+N/i-2);
		}
	}
	cout << ans << endl;
	return 0;
}

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

struct mati{
    int x;
    int y;
};

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

    vector<mati> M(N);
    rep(i,N){
        cin >> M[i].x >> M[i].y;
    }

    vector<int> A;
    rep(i, N){
        A.push_back(i);
    }

    double ave = 0;
    do {
        rep(i, N-1){
            double dis = sqrt(pow(M[A[i]].x - M[A[i+1]].x, 2) + pow(M[A[i]].y - M[A[i+1]].y, 2));
            ave += dis;
        }

    } while (next_permutation(A.begin(),A.end()));


    int kaizyo = 1;
    rep(i, N){
        kaizyo *= i+1;
    }

    printf("%f\n", ave/kaizyo);



}

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

int main(){
    string s;
    getline(cin,s);
    char ch;
    int Aa = 'a' -'A';
    for(int i=0; i<s.size(); i++){
        ch = s.at(i);        
        if('A' <= ch && ch < 'a') cout << (char)(ch+Aa);
        else if('a' <= ch && ch <= 'z') cout << (char)(ch-Aa);
        else cout << ch; 
    }
    cout << endl;

    return 0;
}


Measured memory_bytes: 3168
A, B, C = map(int, input().split())
Max = max(A, B, C)

if A%2 == B%2 == C%2:
    ans = (3*Max-A-B-C) // 2
else:
    ABC = [A, B, C]
    ABC.sort()
    A, B, C = ABC[0], ABC[1], ABC[2]
    if A % 2 == B % 2:
        ans = (2*C-A-B-2) // 2 + 1
    else:
        ans = (2*(C+1)-A-B-1) // 2 + 1
print(ans)

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

typedef pair<int, int> pii;
typedef long long ll;
typedef vector<int> vi;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()

const int MN = 5010;
const int MM = 210;

const int SZ = 1 << 13;

struct segtree {
	vector<pii> dat;

	void init() {
		dat.resize(SZ * 2);
		rep(i, SZ * 2) dat[i] = mp(-1, -1);
	}

	void update(int pos, int x) {
		pos += SZ - 1;
		dat[pos] = mp(x, pos - (SZ - 1));

		while (pos > 0) {
			pos = (pos - 1) / 2;
			dat[pos] = max(dat[pos * 2 + 1], dat[pos * 2 + 2]);
		}
	}

	pii get(int a, int b, int k = 0, int l = 0, int r = SZ) {
		if (b <= l || r <= a) return mp(-1, -1);
		if (a <= l && r <= b) return dat[k];
		return max(get(a, b, k * 2 + 1, l, (l + r) / 2), get(a, b, k * 2 + 2, (l + r) / 2, r));
	}
} seg;

int N, M;
ll A[MN];
ll B[MN][MM];
ll imos[MN][MN];

inline void add(int a, int b, int c, int d, ll t) {
	imos[a][b] += t;
	imos[c][d] += t;
	imos[a][d] -= t;
	imos[c][b] -= t;
}

void solve(int id, int l, int r) {
	if (l + 1 > r) return ;

	pii res = seg.get(l, r);
	int m = res.se;
	add(l, m, m + 1, r, res.fi);
	solve(id, l, m);
	solve(id, m + 1, r);
}

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

	rep(i, N-1) {
		int x;
		cin >> x;
		A[i+1] = A[i] + x;
	}

	rep(i, N) {
		rep(j, M) {
			cin >> B[i][j];
		}
	}

	rep(id, M) {
		seg.init();
		rep(i, N) seg.update(i, B[i][id]);
		solve(id, 0, N);
	}

	ll ret = LLONG_MIN;

	rep(i, N) {
		rep(j, N) {
			imos[i][j+1] += imos[i][j];
		}
	}

	rep(i, N) {
		rep(j, N) {
			imos[i+1][j] += imos[i][j];
		}
	}

	for (int i = 0; i < N; ++i) {
		for (int j = i; j < N; ++j) {
			ret = max(ret, imos[i][j] - (A[j] - A[i]));
		}
	}

	cout << ret << endl;

	return 0;
}

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

int main() {
  int N;
  cin >> N;
  
  int a[10][10];
  for (int i = 0; i< 10; i++) {
    for (int j = 0; j < 10; j++) {
      a[i][j] = 0;
    }
  }
  
  for (int i = 0; i <= N;i++) {
    int x = i;
    int front, back;
    
    back = x % 10;
    while (x > 0) {
      front = x % 10;
      x /= 10;
    }
    a[front][back]++;
  }
  
  int ans = 0;
  for (int i = 1; i <= N; i++) {
    int x = i;
    int front, back;
    
    back = x % 10;
    while (x > 0) {
      front = x % 10;
      x /= 10;
    }
    ans += a[back][front];
  }
  
  cout << ans << endl;
       
}

Measured memory_bytes: 384
import java.io.IOException;
import java.io.InputStream;
import java.util.*;
import java.lang.Math;

public class Main {
    public static void main(String[] args) {
        FS reader = new FS();
        // write reader
        int N = reader.nextInt();
        int[] S = new int[N];
        int ans = 0;
        for (int i=0; i<N; i++) {
            S[i] = reader.nextInt();
            ans += S[i];
        }

        Arrays.sort(S);

        if (ans % 10 == 0) {
            for (int i=0; i<N; i++) {
                if (S[i] % 10 != 0) {
                    System.out.println(ans-S[i]);
                    return;
                }
            }
            System.out.println(0);
        } else {
            System.out.println(ans);
        }
    }
    
    public static void solver() {
        // write logic
    }
    
    // Read Class
    static class FS {
        private final InputStream in = System.in;
        private final byte[] buffer = new byte[1024];
        private int ptr = 0;
        private int buflen = 0;
        private boolean hasNextByte() {
            if (ptr < buflen) {
                return true;
            } else {
                ptr = 0;
                try {
                    buflen = in.read(buffer);
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (buflen <= 0) {
                    return false;
                }
            }
            return true;
        }
    
        private int readByte() { return hasNextByte() ? buffer[ptr++] : -1;}
        private boolean isPrintableChar(int c) {return 33 <= c && c <= 126;}
        private void skipUnprintable() {while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;}
    
        public boolean hasNext() { skipUnprintable(); return hasNextByte();}
        public String next() {
            if (!hasNext()) throw new NoSuchElementException();
            StringBuilder sb = new StringBuilder();
            int b = readByte();
            while(isPrintableChar(b)) {
                sb.appendCodePoint(b);
                b = readByte();
            }
            return sb.toString();
        }
        public int nextInt() {
            return (int)nextLong();
        }
        public long nextLong() {
            if (!hasNext()) throw new NoSuchElementException();
            long n = 0;
            boolean minus = false;
            int b = readByte();
            if (b == '-') {
                minus = true;
                b = readByte();
            }
            if (b < '0' || '9' < b) {
                throw new NumberFormatException();
            }
            while(true) {
                if ('0' <= b && b <= '9') {
                    n *= 10;
                    n += b - '0';
                } else if(b == -1 || !isPrintableChar(b)) {
                    return minus ? -n : n;
                } else {
                    throw new NumberFormatException();
                }
                b = readByte();
            }
        }
    }
}



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

#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define MIN(a) *min_element(all(a))
#define MAX(a) *max_element(all(a))
#define SUM(a) accumulate(all(a), 0LL)
#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define RREP(i, n) for(int (i)=(n)-1; (i)>=0; (i)--)
#define FOR(i, m, n) for(int (i)=(m); (i)<(n); i++)
#define FORR(i, m, n) for(int (i)=(n)-1; (i)>=(m); i--)
#define debug(x) cerr << #x << " = " << x << endl
//#define int long long

typedef long long ll;
//ll const MOD = 998244353;
ll const MOD = 1e9+7;
int const inf = 1e9;
ll const INF = 1e18;

inline void ios_(){cin.tie(0); ios::sync_with_stdio(false);}
template<typename T> int size(const T& a){return (int)a.size();}
template<typename T> T Div(T a, T b){return (a + b - 1) / b;}
template<typename T> bool chmin(T& a, const T& b){if(a > b){a = b; return true;} return false;}
template<typename T> bool chmax(T& a, const T& b){if(a < b){a = b; return true;} return false;}



signed main(){
    ll n, l;
    cin >> n >> l;

    vector<ll> v(n);
    for(auto&& i : v) cin >> i;

    int c = -1;
    REP(i, n-1){
        if(v[i] + v[i+1] >= l){
            c = i;
            break;
        }
    }

    if(c == -1){
        cout << "Impossible" << endl;
        return 0;
    }

    cout << "Possible" << endl;

    REP(i, c){
        cout << i + 1 << '\n';
    }
    FORR(i, c, n-1){
        cout << i + 1 << '\n';
    }
    return 0;
}


Measured memory_bytes: 1664
#include "bits/stdc++.h"
using namespace std;
#define repr(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repr(i,0,n)
#define reprrev(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define reprev(i,n) reprrev(i,0,n)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define mp make_pair
#define mt make_tuple
#define MOD 1000000007
#define PI 3.1415926535
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> Pi;
typedef pair<ll, ll> Pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<Pi> vPi;
typedef vector<Pll> vPll;
typedef vector<vector<int>> vvi;
typedef vector<vector<bool>> vvb;
typedef vector<vector<ll>> vvll;
typedef vector<vector<char>> vvc;
typedef vector<vector<string>> vvs;
typedef vector<vector<double>> vvd;
typedef vector<vector<Pi>> vvPi;
typedef priority_queue<int, vector<int>, greater<int>> pqli;
typedef priority_queue<ll, vector<ll>, greater<ll>> pqlll;
typedef priority_queue<Pi, vector<Pi>, greater<Pi>> pqlP;
string YN(bool y) { return (y?"YES":"NO"); }
string yn(bool y) { return (y?"Yes":"No"); }
string ON(bool y) { return (y?"OK":"NG"); }
vb f(10001);
//エラトステネスのふるい
void Eratosthenes()
{
	rep(i, 2000) f[i]=false;

	f[0]=true; f[1]=true;

	repr(i, 2, 2000){
		if(!f[i]){
			for(int j=i+i; j<=2000; j+=i){
				f[j]=true;
			}
		}
	}
}
int main(void)
{
	ll n, ans=0, count=0;

	cin>>n;

	Eratosthenes();

	repr(i, 2, 2000){
		if(!f[i]&&i%5==1){
			cout<<i<<" ";
			count++;
		}
		if(count>=n) break;
	}
	cout<<endl;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
  int N;
  long long A, B;
  scanf("%d %lld %lld", &N, &A, &B);
  
  long long ok = 0;
  long long h[N];
  for(int i = 0; i < N; i++){
    scanf("%lld", &h[i]);
    if(ok < h[i]) ok = h[i];
  }
  
  ok = ok / B + 1;
  long long ng = 0ll;
  while(ok - ng > 1){
    long long mid = (ok + ng) / 2ll;
    
    int able;
    long long explode = 0ll;
    for(int i = 0; i < N; i++){
      if(h[i] - mid * B > 0ll){
        explode += (h[i] - mid * B - 1ll) / (A - B) + 1ll;
      }
    }
    if(mid >= explode) able = 1;
    else able = 0;
    
    if(able) ok = mid;
    else ng = mid;
  }
  
  printf("%lld", ok);
  
  return 0;
}

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

using namespace std;


//repetition
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define euc_dis(x, y) sqrt(x*x + y*y)

#define MOD 1e9+7
#define sp ' '


using ll = long long;


ll mod(ll a, ll b){return (a%b+b)%b;}
ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b){return a*b/gcd(a,b);}
void Yes(){cout << "Yes" << endl;}
void No(){cout << "No" << endl;}
void Judge(bool b){b?Yes():No();}
void YES(){cout << "YES" << endl;}
void NO(){cout << "NO" << endl;}
void JUDGE(bool b){b?YES():NO();}
ll powMod(ll b, ll e, ll m){ll r=1;while(e>0){if(e&1)r=(r%m)*(b%m)%m;b=(b%m)*(b%m)%m;e>>=1;}return r;}
double distance(ll x1, ll y1, ll x2, ll y2){return sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));}

template<typename T>
void ppp(T n){cout << n << endl;}

int main(){

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

    int d;
    cin >> d;
    if(d == 25)
        ppp("Christmas");
    else if(d == 24)
        ppp("Christmas Eve");
    else if(d == 23)
        ppp("Christmas Eve Eve");
    else
        ppp("Christmas Eve Eve Eve");
    
        



    return 0;
}


Measured memory_bytes: 256
#include <cstring>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cassert>

#define ios ios_base::sync_with_stdio(0), cout.tie(0), cin.tie(0);
#define S second
#define F first
#define pb push_back
#define nl '\n'
#define mp make_pair
#define NL cout << '\n';
#define EX exit(0)
#define all(s) s.begin(), s.end()
#define FOR(i, start, finish, k) for(int i = start; i <= finish; i += k)

const long long MXN = 1e5 + 1;
const long long MNN = 1e4 + 1;
const long long MOD = 998244353;
const long long INF = 1e18;
const long long OO = 1e9 + 500;

typedef long long llong;
typedef unsigned long long ullong;

using namespace std;

llong n, b[MXN], sum = 0, mx;

llong x, y, l, r;

int main(){
	ios;
	cin >> n >> x >> y >> l >> r;
	for (llong i = 0; i < n; i++) {
		llong sum = i * l - (n - 1 - i) * l;
		if (x + sum < y) {
			if (x + sum + i * (r - l) >= y)
				return cout << "YES", 0;
		}
		if (x + sum > y) {
			if (x + sum + (n - i - 1) * (l - r) <= y)
				return cout << "YES", 0;
		}
	}
	cout << "NO";
	return 0;
}


Measured memory_bytes: 256
import java.io.*;
import java.util.*;
public class Main {
	
	public static void main(String[] args) {
		InputReader in = new InputReader();
		int n = in.nextInt();
		
		int[] arr = new int[n];
		for (int i=0; i<n; i++) {
			arr[i] = in.nextInt();
		}
		
		int res = 0;
		for (int i=1; i<n-1; i++) {
			ArrayList<Integer> list = new ArrayList<>();
			list.add(arr[i]);
			list.add(arr[i-1]);
			list.add(arr[i+1]);
			Collections.sort(list);
			if (list.get(list.size()-2) == arr[i])
				++res;
		}
		
		System.out.println(res);
	}

	static class InputReader {
		public BufferedReader br;
		public StringTokenizer st;
		
		public InputReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
			st = null;
		}
		
		public String next() {
			while (st == null || !st.hasMoreTokens()) {
				try {
					st = new StringTokenizer(br.readLine());
				}
				catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return st.nextToken();
		}
		
		public int nextInt() {
			return Integer.parseInt(next());
		}
	}
}

Measured memory_bytes: 21204
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const ll INF = LLONG_MAX;
 
int main()
{
    string s;
    cin >> s;
    int cnt = 0;
    for (int i = 0; i < s.length(); i++)
    {
        if (i % 2 == 0 && s[i] != '0')
        {
            cnt++;
        }
        else if (i % 2 != 0 && s[i] != '1')
        {
            cnt++;
        }
    }
    int count = 0;
    for (int i = 0; i < s.length(); i++)
    {
        if (i % 2 == 0 && s[i] != '1')
        {
            count++;
        }
        else if (i % 2 != 0 && s[i] != '0')
        {
            count++;
        }
    }
 
    cout << min(cnt, count) << endl;
}

Measured memory_bytes: 512
#include <stdio.h>
int main(){
    int K, A, B, i;
    
    scanf("%d\n", &K);
    scanf("%d %d", &A, &B);
    
    for( i = A; i <= B; i++ ){
        if( i%K == 0 ){
            printf("OK\n");
            break;
        }
    }
    if( i > B ){
        printf("NG\n");
    }

    return 0;
}

Measured memory_bytes: 1616
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <sstream>
#include <cmath>
#include <set>
#include <cstdio>
#include <iomanip>

using namespace std;

#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 REMOVE(Itr,n) (Itr).erase(remove((Itr).begin(),(Itr).end(),n),(Itr).end())
#define PB_VEC(Itr1,Itr2) (Itr1).insert((Itr1).end(),(Itr2).begin(),(Itr2).end())
#define UNIQUE(Itr) sort((Itr).begin(),(Itr).end()); (Itr).erase(unique((Itr).begin(),(Itr).end()),(Itr).end())

typedef long long ll;

int main(){
    
    int N;
    cin>>N;
    
    int ans=0;
    for(int i=1;i<=N;i++)ans+=i;
    
    cout<<ans<<endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
    int a;
    int b;
    char op;
    
    while ( 1 ) {
        scanf("%d %c %d", &a, &op, &b);
        if ( op == '?' ) {
            break;
        }
        switch ( op ) {
            case '+':
                printf("%d\n", a + b);
                break;
            case '-':
                printf("%d\n", a - b);
                break;
            case '*':
                printf("%d\n", a * b);
                break;
            case '/':
                printf("%d\n", a / b);
                break;
        }
    }
    
    return 0;
}


Measured memory_bytes: 2120
/*input
2
ip cc
*/
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define F first
#define S second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define eb emplace_back
#define pb push_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define EL cout<<'\n'
#define BS(a,x) binary_search(ALL(a),x)
template<typename T1,typename T2>
ostream& operator<<(ostream& out,pair<T1,T2> P){
	out<<'('<<P.F<<','<<P.S<<')';
	return out;
}
template<typename T>
ostream& operator<<(ostream& out,vector<T> V){
	REP(i,SZ(V)) out<<V[i]<<((i!=SZ(V)-1)?" ":"");
	return out;
}
//}}}
const ll maxn=300005;
const ll maxlg=20;
const ll INF64=1e18;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const ld PI=acos(-1);
const ld eps=1e-9;
//const ll p=880301;
//const ll P=31;

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


int main(){
	IOS;
	string a[]={"X","SAT","FRI","THU","WED","TUE","MON","SUN"};
	string s;
	cin>>s;
	REP(i,8) if(s==a[i]) cout<<i<<'\n';
	return 0;
}


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

const int MAXN = 16;
const double inf = 1e20;
int n;
int id[MAXN], x[MAXN], num[MAXN];
double dp[1<<MAXN][MAXN];
int prev[1<<MAXN][MAXN];

int main() {
  cin >> n;
  for(int i = 0; i < n; ++i) {
    cin >> id[i] >> x[i] >> num[i];
  }
  fill(dp[0], dp[1<<MAXN], inf);
  for(int i = 0; i < n; ++i) dp[1<<i][i] = 0.0;
  for(int b = 0; b < (1<<n); ++b) {
    for(int i = 0; i < n; ++i) {
      if(dp[b][i] == inf) continue;
      double w = 0;
      for(int j = 0; j < n; ++j) if(b & (1<<j)) w += num[j];
      for(int ni = 0; ni < n; ++ni) {
        if(b & (1<<ni)) continue;
        int nb = b | (1<<ni);
        double dist = abs(x[ni] - x[i]);
        double ncost = dp[b][i] + dist * (70.0 + w) / 2000.0;
        if(dp[nb][ni] > ncost) {
          dp[nb][ni] = ncost;
          prev[nb][ni] = i;
        }
      }
    }
  }
  int k = 0;
  for(int i = 1; i < n; ++i) {
    if(dp[(1<<n)-1][k] > dp[(1<<n)-1][i]) k = i;
  }
  int b = (1<<n)-1;
  vector<int> ans;
  while(b) {
    ans.push_back(k);
    int tmp = k;
    k = prev[b][k];
    b &= ~(1<<tmp);
  }
  reverse(ans.begin(), ans.end());
  for(int i = 0; i < n; ++i) {
    if(i) cout << " ";
    cout << id[ans[i]];
  }
  cout << endl;
  return 0;
}

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

int main(){
	int X,Y,Z;
	cin>>X>>Y>>Z;
	int res;
	for(res=0;;){
		if(X-Z>=Y+Z){
			X-=Y+Z;
			res++;
		}else{
			break;
		}
	}
	cout<<res<<endl;
}


Measured memory_bytes: 256
// #include <iomanip>

#include <bits/stdc++.h>
#include <iostream>

using namespace std;

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

  vector<int> p(n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &p[i]);
  }

  int k = 0;
  for (int i = 0; i < n; i++) {
    if (i + 1 != p[i]) {
      k++;
    }
  }

  if (k <= 2) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std ;
int a[55] ;
int sum = 0 ;
int main() {
    memset(a,0,sizeof(a));
 	int  n ;
     cin >> n ;
     for(int i = 1 ; i <= n ; i++) cin >>a[i] ;
     for(int i = 1 ; i <= n ; i++) {
         for(int j = i + 1 ; j <= n ; j++) {
             sum += a[i] * a[j] ;
         }
     }
     cout << sum << endl ;
	return 0 ;
}

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

int main(){

  int N;
  cin >> N;

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

  int sum_XOR=0;
  for(int i=0;i<N;i++){
    sum_XOR=sum_XOR^a[i];
  }

  int ans;
  for(int i=0;i<N;i++){
    ans=sum_XOR^a[i];
    cout << ans << endl;
  }
}

Measured memory_bytes: 3944
#include <stdio.h>
#define SIZ 1400
#define min(x,y) y ^ ( ( x^y ) & ( x-y >> 31 ) )
#define max(x,y) y ^ ( ( x^y ) & ( y-x >> 31 ) )
int A[SIZ][SIZ];
int m[SIZ][SIZ];
int main(){
	int i,j,k,x,y,r,M=0,t=0,z;
	scanf("%d%d",&y,&x);
	for(j=0;j<y;j++)for(i=0;i<x;i++)scanf("%d",A[j]+i);
	for(j=0;j<y;j++)for(r=i=0;i<x;m[j][i]=r,i++)r=A[j][i]==0?r+1:0;
	for(r=i=0;i<x;i++)for(j=0;j<y;j++)for(M=x,k=j;k<y;k++){
		if(M>m[k][i])M=m[k][i];
		int z=k-j+1;
		if(M<z)break;
		if(r<z)r=z;
	}
	printf("%d\n",r*r);
	return 0;
}

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

class Procon
{
    public Procon() { }
    static void Main(string[] agrs)
    {
        new Procon().Do();
    }

    Scanner cin;

    long[] a;

    public void Do()
    {
        cin = new Scanner();
        int N = cin.nextInt();
        long Z = cin.nextLong();
        long W = cin.nextLong();
        a = cin.arrayLong();

        long ans = Math.Abs(a[N-1] - W);
        if (N>2) {
            ans = Math.Max(ans, Math.Abs(a[N-2] -a[N-1]));
        }

        Console.WriteLine(ans);
    }
}

class Scanner
{
    string[] s;
    int i;
    int max_i;

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

    public string nextString()
    {
        if (i >= s.Length)
        {
            s = Console.ReadLine().Split(' ');
            max_i = s.Length;
            i = 0;
            if (max_i == 0)
            {
                return "";
            }
            return s[i++];
        }
        else
        {
            return s[i++];
        }
    }

    public int nextInt()
    {
        return int.Parse(nextString());
    }


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

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

    public string[] arrayString()
    {
        return Console.ReadLine().Split(' ');
    }

    public int[] arrayInt()
    {
        string[] str = Console.ReadLine().Split(' ');
        int[] array = new int[str.Length];
        for (int i = 0; i < str.Length; i++)
        {
            array[i] = int.Parse(str[i]);
        }
        return array;
    }

    public long[] arrayLong()
    {
        string[] str = Console.ReadLine().Split(' ');
        long[] array = new long[str.Length];
        for (int i = 0; i < str.Length; i++)
        {
            array[i] = long.Parse(str[i]);
        }
        return array;
    }

    public double[] arrayDouble()
    {
        string[] str = Console.ReadLine().Split(' ');
        double[] array = new double[str.Length];
        for (int i = 0; i < str.Length; i++)
        {
            array[i] = double.Parse(str[i]);
        }
        return array;
    }
}


Measured memory_bytes: 13192
#include<iostream>
using namespace std;
int main(){
  bool num[1000000] = {false};
  for(int i=2; i<1000; i++) if(!num[i]) for(int j=i*i; j<1000001; j+=i) num[j] = true;
  num[0] = num[1] = true;
  int n;
  while(cin >>n,n){
    int ans = 0;
    for(int i=2; i<=n/2; i++) if(!num[i] && !num[n-i]) ans++;
    cout <<ans<<endl;
  }
  return 0;
}

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

// clang-format off
template <typename T> T gcd(T a, T b) { return b == 0 ? a : gcd(b, a % b); }
template <typename T> T lcm(T a, T b) { return a * b / gcd(a, b); }
template <typename T> T clamp(T val, T min, T max) { return val < min ? min : (max < val ? max : val); }
char capitalize(char c) { return static_cast<char>(std::toupper(static_cast<unsigned char>(c))); }
// template <typename T> size_t max_index(T begin, T end) { return distance(begin, max_element(begin, end)); }
// template <typename T> size_t min_index(T begin, T end) { return distance(begin, min_element(begin, end)); }
// clang-format on

// #define int long long
#define YES "YES"
#define NO  "NO"

using namespace std;

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

  int num = 0;
  // num = numeric_limits<int>::max();
  // num = numeric_limits<int>::min();
  bool flag = false;
  // flag = true;

  int a, b;
  char op;
  cin >> a >> op >> b;
  cout << (op == '+' ? a + b : a - b) << endl;

  // cout << num << endl;
  // cout << (flag ? "H" : "D") << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>
#include <cmath>
#include <numeric>
#include <tuple>
#include <assert.h>

#define sqr(x) std::pow(x, 2.0)
#define INF 1e10
#define REP(i, n) for (int i = 0; i < n; i++)
#define POS_OR_INF(x) (x > 0 ? x : INF)

using namespace std;

struct Point {
	double x;
	double y;
};

inline istream& operator >> (istream& is, Point& p) {
	return is >> p.x >> p.y;
}

typedef Point Vector;

struct Dog {
	Point  position;
	double speed;
};

inline std::pair<double, double> solve(const Dog& dog, const Point& fp, const Vector& fv) {
	Vector d = { fp.x - dog.position.x, fp.y - dog.position.y };

	double a = fv.x * fv.x + fv.y * fv.y - dog.speed * dog.speed;
	double b = d.x * fv.x + d.y * fv.y;
	double c = d.x * d.x + d.y * d.y;
	double det = b * b - a * c;

	if (det < 0) return make_pair(INF, INF);

	double t1 = (-b + sqrt(det)) / a;
	double t2 = (-b - sqrt(det)) / a;
	double t  = min(POS_OR_INF(t1), POS_OR_INF(t2));

	if (t < 0 || t == INF) return make_pair(INF, INF);

	double rad = atan2(d.y + fv.y * t, d.x + fv.x * t);

	// check
	//double xf = fp.x + fv.x * t; double xd = d.position.x + d.speed * t * cos(rad);
	//double yf = fp.y + fv.y * t; double yd = d.position.y + d.speed * t * sin(rad);

	return make_pair(t, rad);
}


int main(int argc, char** argv) {
	while (1) {
		int N, M;
		cin >> N >> M;

		if (N == 0 && M == 0) break;

		vector<Dog> dogs(N);
		vector<int> frisbees(N);

		REP(i, N)
			cin >> dogs[i].position >> dogs[i].speed;

		REP(i, M) {
			Point fp, fv;
			vector<double> t(N), rad(N);

			cin >> fp >> fv;

			REP(j, N)
				tie(t[j], rad[j]) = solve(dogs[j], fp, fv);

			auto best = min_element(t.begin(), t.end());

			frisbees[best - t.begin()]++;

			// move dogs
			REP(j, N) {
				if (t[j] == INF) continue;
				dogs[j].position.x += dogs[j].speed * cos(rad[j]) * *best;
				dogs[j].position.y += dogs[j].speed * sin(rad[j]) * *best;
			}
		}

		REP(i, N)
			cout << frisbees[i] << (i == N - 1 ? "\n" : " ");
	}
}


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

std::vector<bool> is_prime(1000001, 1);

std::vector<int> Eratosthenes(const int N) {
  std::vector<int> P;
  is_prime[0] = 0;
  is_prime[1] = 0;
  for (int i = 2; i <= N; i++) {
    if (is_prime[i]) {
      for (int j = 2 * i; j <= N; j += i) {
        is_prime[j] = false;
      }
      P.emplace_back(i);
    }
  }
  return P;
}

int main() {
  int N, A, G, P{1};
  vector<int> primes = Eratosthenes(1000000);
  bool b[1000001]{};
  cin >> N;
  cin >> G;

  int g = G;
  for (auto p : primes) {
    while (g % p == 0) {
      b[p] = 1;
      g /= p;
    }
    if (g == 1) break;
  }
  while (cin >> A) {
    G = gcd(G, A);
    if (P) {
      if (is_prime[A]) {
        if (!b[A])
          b[A] = 1;
        else
          P = 0;
      } else {
        for (auto p : primes) {
          if (A % p == 0) {
            if (b[p]) {
              P = 0;
              break;
            } else {
              b[p] = 1;
              while (A % p == 0) A /= p;
            }
          }
          if (A == 1 || !P) break;
        }
      }
    }
  }
  cout << (P ? "pairwise coprime"
             : (G == 1) ? "setwise coprime" : "not coprime")
       << endl;
}


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

using namespace std;

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

  int n;
  cin >> n; 
  for (int i = 0; i < 26; ++i) {
    for (int j = 0; j < 15; ++j) {
      if (i*4 + j*7 == n) {
        cout << "Yes" << endl;
        return 0;
      }
    }
  }
  cout << "No" << endl;

  return 0;
}



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

int n, A[22];

// 入力値の m から選んだ要素を引いていく再帰関数
// 計算量 O(2^n)
int solve(int i, int m) {
  if(m == 0) return 1;
  if(i >= n) return 0;
  int res = solve(i+1, m) || solve(i+1, m-A[i]);
  return res;
}

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

  cin >> n;
  for(int i = 0; i < n; i++) cin >> A[i];
  int q; cin >> q;
  for(int i = 0; i < q; i++) {
    int m; cin >> m;
    cout << (solve(0, m) ? "yes" : "no") << endl;
  }
}



Measured memory_bytes: 3160
#include<bits/stdc++.h>
/*
g++ -std=c++11 -Wall -g -fsanitize=undefined -D_GLIBCXX_DEBUG arc/arc077/c.cpp
*/
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define SZ(x) ((int)(x).size())
#define INF (1e16)
typedef long long ll;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);//おまじないでcin, cout早くする
    int n;
    cin >> n;
    int a[n + 1];
    for(int i = 1; i <= n; i++){
        cin >> a[i];
    }

    if(n % 2 == 0){
        for(int i = n; i >= 2; i--){
            if(i % 2 == 1) continue;
            else cout << a[i] << " ";
        }
        for(int i = 1; i <= n; i++){
            if(i % 2 == 0) continue;
            else cout << a[i] << " ";
        }
    }

    if(n % 2 == 1){
        for(int i = n; i >= 1; i--){
            if(i % 2 == 0) continue;
            else cout << a[i] << " ";
        }
        for(int i = 2; i <= n; i++){
            if(i % 2 == 1) continue;
            else cout << a[i] << " ";
        }
    }

    cout << "\n";
    return 0;
}

Measured memory_bytes: 2944
// Problem : A - Registration
// Contest : AtCoder - AtCoder Beginner Contest 167
// URL : https://atcoder.jp/contests/abc167/tasks/abc167_a
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

 
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
 
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
 
template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;
 
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
 
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy
 
int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);    
	
    //int T; cin >> T;
    //while(T--) 
 	//{
  //    
  //  }
	string str1,str2;
	cin>>str1>>str2;
	F0R(x,sz(str1))
	{
		if(str1[x]!=str2[x])
		{
			cout<<"No"<<endl;
			return 0;
		}
	}
	cout<<"Yes"<<endl;
	return 0;
}
 



Measured memory_bytes: 3656
#include <bits/stdc++.h>
#include <iostream>
#include <string>
#define INF 1e18
#define int long long
#define Rep(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) Rep(i, 0, n)
#define all(a) (a).begin(), (a).end()
using namespace std;
 
main(void){
  
  string today; cin >> today;
  string s,c,r;
  
  s = "Sunny";
  c = "Cloudy";
  r = "Rainy";
  string out;
  
  if (today==r) {out="Sunny";}
  
  if (today==s) {out="Cloudy";}
  
  if (today==c) {out="Rainy";}
  
  cout << out <<endl;
  
  return 0;
}

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

int main() {
    int n;
    cin >> n;
    int a[n];
    int b1=0,b2=0,b4=0;
    for(int i=0;i<n;i++){
        cin >> a[i];
        if(a[i]%2==1)b1++;
        if(a[i]%4==0)b4++;
        if(a[i]%2==0&&a[i]%4!=0)b2++;
    }
    string ans;
    if(b2==0){
        if(b1<=b4+1) ans="Yes";
        else ans="No";
    }
    else if(b2>0){
        if(b1<=b4) ans="Yes";
        else ans="No";
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 640