akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
#include<queue>
#include<algorithm>
#include<map>
#include<set>
#include<vector>
#include<math.h>
#include<time.h>

using namespace std;

#define INF 1000000007
#define LINF (1LL << 62)

typedef long long i64;
typedef pair<i64,i64> P;


int n, m, a[101010], d[101010], b[101010];

int main(){
	cin >> n >> m;
	for(int i = 0; i < n; i++){
		cin >> a[i];
		d[a[i]%m]++;
		b[a[i]]++;
	}
	sort(a,a+n);
	a[n] = INF;
	
	int ans = 0;
	ans += d[0]/2;
	for(int i = 1; i < m/2+m%2; i++){
		ans += min(d[i], d[m-i]);
		int cnt1 = 0, cnt2 = 0, b1 = 0 , b2 = 0;
		for(int j = i; j < 101010; j+=m){
			cnt1 += b[j] / 2;
			b1 += b[j] % 2;
		}
		for(int j = m-i; j < 101010; j+=m){
			cnt2 += b[j] / 2;
			b2 += b[j] % 2;
		}
		ans += min(cnt1, (cnt1*2+b1 - min(d[i], d[m-i]))/2);
		ans += min(cnt2, (cnt2*2+b2 - min(d[i], d[m-i]))/2);
	}
	if(m%2 == 0){
		ans += d[m/2]/2;
	}
	
	cout << ans << endl;
	
	return 0;
}

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

const double pi  = 2 * acos(0.0);
const double eps = 1e-8;

#define REP(i,a,b) for(int i=(a); i<(b);++i)
#define rep(i,n) REP(i,0,n)
#define INF (1<<29)
#define INFLL (1LL<<62)

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

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

int main(void) {
  ios_base::sync_with_stdio(false); cin.tie(0);
  ll N, W; cin >> N >> W;
  vector<vector<int>> w(4, vector<int>());

  ll base = 0;
  int ww, v;
  rep(i, N) {
    cin >> ww >> v;
    if (i == 0)
      base = ww;
    w[ww-base].push_back(v);
  }

  sort(w[0].begin(), w[0].end(), greater<int>());
  sort(w[1].begin(), w[1].end(), greater<int>());
  sort(w[2].begin(), w[2].end(), greater<int>());
  sort(w[3].begin(), w[3].end(), greater<int>());

  int ans = 0;
  rep(i, w[0].size() + 1) {
    int n0 = accumulate(w[0].begin(), w[0].begin() + i, 0);
    rep(j, w[1].size() + 1) {
      int n1 = accumulate(w[1].begin(), w[1].begin() + j, 0);
      rep(k, w[2].size() + 1) {
        int n2 = accumulate(w[2].begin(), w[2].begin() + k, 0);
        rep(l, w[3].size() + 1) {
          int n3 = accumulate(w[3].begin(), w[3].begin() + l, 0);

          int sumv = n0 + n1 + n2 + n3;
          ll sumw = base * i + (base + 1) * j + (base + 2) * k + (base + 3) * l;

          if (sumw > W)
            continue;

          ans = max(sumv, ans);
        }
      }
    }
  }

  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;

int main()
{
    string s;
    string ans;
    cin >> s;
    if(s[2]==s[3] and s[4]==s[5]){
        ans = "Yes";
    }
    else{
        ans = "No";
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#define debug_interval ','
#define dump_interval ' '
#define debug_toggle 1
//{
#include<bits/stdc++.h>
using namespace std;
#define hi cout<<"hi"<<endl;
#define int long long
#define INT_MAX LLONG_MAX
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define fi first
#define se second
#define mp make_pair
#define rev reverse
#define dans dump(ans)
#define MOD 1000000007
#define amp(v,n) (v).count(n)?v[n]++:v[n]=1;

//{
inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}
template<class...A> inline void dump(){cout<<endl;}
template<class...A> inline void dump_rest() {cout<<endl;}
template<class T, class...A> inline void dump_rest(const T& first, const A&... rest){cout<<dump_interval<<first;dump_rest(rest...);}
template<class T,class...A> inline void dump(const T&first,const A&...rest){cout<<first;dump_rest(rest...);}
template<class...A> inline void debug(){cerr<<endl;}
template<class...A> inline void debug_rest() {cerr<<endl;}
template<class T, class...A> inline void debug_rest(const T& first, const A&... rest){cerr<<debug_interval<<first;debug_rest(rest...);}
template<class T,class...A> inline void debug(const T&first,const A&...rest){if(debug_toggle)cerr<<first,debug_rest(rest...);}
//}

typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}
template<int m>class mint{private:int i;public:mint() : i(0){}mint(int i): i((i%m+m)%m){}mint operator+(const mint& o){return o.i+i;}mint operator*(const mint& o){return o.i*i;}mint operator-(){return -i;}operator int() {return i;}};

int ans;
string s;
bool cf,ff;

main(){
    cin>>s;
    rep(i,s.size()-8){
        cout<<s[i];
    }
    cout<<endl;
}



Measured memory_bytes: 256
/* C - Ubiquity */

#include <bits/stdc++.h>
using namespace std;

static int mod = 1000000007;

int pow_rev(int x, int n){
  if(n == 0) return 1;
  long long a = x;
  for(int i = 1; i < n; i++){
    a *= x;
    a %= mod;
  }
  return a;
}

/*
int pow_rev(int x, int n){
  if(n == 0) return 1;
  else if(n == 1) return x;
  else if(n % 2 == 0) return pow_rev(x * x, n / 2) % mod;
  else return x * pow_rev(x, n - 1) % mod;
}
*/

int main(){
  int N, ans = 0;
  cin >> N;
  ans += pow_rev(10, N);
  ans %= mod;
  ans += pow_rev(8, N);
  ans %= mod;
  ans -= pow_rev(9, N);
  if(ans < 0) ans += mod;
  ans -= pow_rev(9, N);
  if(ans < 0) ans += mod;
  cout << ans << endl;
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,s,n) for(int i=(s); i<(n); i++)
#define all(v) v.begin(),v.end()
#define outve(v) for(auto i : v) cout << i << " ";cout << endl
#define in(n,v) for(int i=0; i<(n); i++){cin >> v[i];}
#define out(n) cout << (n) << endl
#define fi first
#define se second
#define ve vector
#define pq priority_queue
#define vi vector<int>
#define vl vector<long long>
#define vii vector<vector<int>>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll mod = 1000000007;



template <typename T> bool chmax(T &a, T b) {if(a < b) {a = b;return 1;}return 0;}
template <typename T> bool chmin(T &a, T b) {if(a > b) {a = b;return 1;}return 0;}




int main()
{
    int n,k,r,s,p;
    cin >> n >> k >> r >> s >> p;
    string t;
    cin >> t;
    vi dp(n+1,-1);
    dp[0] = 0;
    reps(i,1,n+1){
        if(dp[i] < 0) {
            if(t[i-1] == 'r'){
                if(dp[i] != -4) {
                    dp[i] = dp[i-1] + p;
                    if(i+k <= n) dp[i+k] = -4;
                }else dp[i] = dp[i-1];
                
                
            }else if(t[i-1] == 's'){
                if(dp[i] != -2) {
                    dp[i] = dp[i-1] + r;
                    if(i+k <= n) dp[i+k] = -2;
                }else dp[i] = dp[i-1];
                
            }else if(t[i-1] == 'p'){
                if(dp[i] != -3) {
                    dp[i] = dp[i-1] + s;
                    if(i+k <= n) dp[i+k] = -3;
                }else dp[i] = dp[i-1];
                
            }
        }
        else dp[i] = dp[i-1];
    }
    out(dp[n]);


    return 0;
}


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

typedef long long ll;

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

int main() {
  int n, k;
  cin >> n >> k;
  vector<ll> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a.rbegin(), a.rend());
  ll g = gcd(a[0], a[1]);
  for (int i = 0; i < n; i++) {
    g = gcd(g, a[i]);
  }
  if (k%g == 0 && k <= a[0]) {
    cout << "POSSIBLE" << endl;
  }
  else {
    cout << "IMPOSSIBLE" << endl;
  }
  return 0;
}

Measured memory_bytes: 1024
//
//  main.cpp
//  C - Fennec vs Monster
//
//  Created by Hashizo on 2020/01/26.
//  Copyright © 2020 Hashizo. All rights reserved.
//

#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <regex>
#include <cmath>

using namespace std;
 
#undef LONG_MAX
#undef LONG_MIN
 
#define LONG_MAX    9223372036854775807
#define LONG_MIN    (-LONG_MAX  -1)
 
#define ll long long
 
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
 
#define SORT(c) sort((c).begin(), (c).end())
#define REVERSE(v) reverse((v).begin(), (v).end())


int main(int argc, const char * argv[]) {
	ll ans = 0;

	ll n,k;
	cin >> n >> k;

	vector<ll> mons(n);
	REP(i, n) {
		cin >> mons[i];
	}

	SORT(mons);
	REVERSE(mons);
	
	
	REP(i, n) {
		if (i >= k) {
			ans += mons[i];
		}
	}
	
	
	
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 1792
input()
P1 = []
P2 = []
P3 = []
for a, b in zip(map(int, input().split()), map(int, input().split())):
    t = abs(a - b)
    P1.append(t)
    P2.append(t ** 2)
    P3.append(t ** 3)
print("{:f}".format(sum(P1)))
print(sum(P2) ** (1 / 2))
print(sum(P3) ** (1 / 3))
print("{:f}".format(max(P1)))


Measured memory_bytes: 5648
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define mod 1000000007 //10^9+7
#define INF 1000000000000 //10^12
#define P pair<int,int>
#define rep(i,n) for(int i=0;i<n;i++)
string s[]={"SUN","MON","TUE","WED","THU","FRI","SAT",};
string t;
int ans;
signed main(){
    cin>>t;
    rep(i,7){
        if(t==s[i])ans=7-i;
    }
    cout<<ans<<endl;
    return 0;
}


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

#define lli long long int
#define REP(i,s,l) for(lli i=s;i<l;i++)
#define DEBUG 0
#define INF (1LL<<50)
#define MOD 1000000007

int main(){
    int n;
    string s;

    cin >> n;
    cin >> s;
    int ans = 0;
    for(int i=1; i<n; i++){
        int cnt = 0;
        for(char c='a'; c<='z'; c++){
            bool left=false, right=false;
            for(int j=0; j<i; j++){
                if(s[j]==c) left = true;
            }
            for(int j=i; j<n; j++){
                if(s[j]==c) right = true;
            }
            if(left&&right) cnt++;
        }
        if(ans<cnt) ans=cnt;
    }
    cout << ans << endl;
    return 0;
}

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

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

    arry = []
    for _ in range(m):
        arry += list(map(int, input().split()))
    for i in range(1, n+1):
        print(arry.count(i))

if __name__ == '__main__':
    main()

Measured memory_bytes: 2940
import java.util.Scanner;
import java.util.Collections;
import java.util.ArrayList;
import java.util.Queue;
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.PriorityQueue;

public class Main {
 	public static void main(String[] args){
		Scanner scanner = new Scanner(System.in);
		int H = scanner.nextInt();
		int W = scanner.nextInt();
		int N = scanner.nextInt();
		String[] s = new String[H];
		for(int i = 0; i < H; i++){
			s[i] = scanner.next();
		}
		char[][] map = new char[H][W];
		for(int i = 0; i < H; i++){
			for(int j = 0; j < W; j++){
				map[i][j] = s[i].charAt(j);
				if(map[i][j] == 'S'){
					map[i][j] = '0';
				}
			}
		}
		//1,2,3,4,5,6,7,8,9のそれぞれの座標
		int[] xplace = new int[N+1];
		int[] yplace = new int[N+1];
		for(int k = 0; k <= N; k++){
			for(int i = 0; i < H; i++){
				for(int j = 0; j < W; j++){
					if(map[i][j] == (char)(k + '0')){
 						xplace[k] = j;
						yplace[k] = i;
					}
				}
			}
		}
		int ans = 0;
		Queue<Point> q = new ArrayDeque<Point>();
		int[][] dist = new int[H][W];
		int[] dx = {-1,0,1,0};
		int[] dy = {0,1,0,-1};
		for(int count = 0; count < N; count++){
			q.add(new Point(yplace[count],xplace[count]));
			for(int i = 0; i < H; i++){
				for(int j = 0; j < W; j++){
					dist[i][j] = -1;
				}
			}
			dist[yplace[count]][xplace[count]] = 0;
			while(!q.isEmpty()){
				Point now = q.poll();
				for(int i = 0; i < 4; i++){
					Point next = new Point(now.y+dy[i], now.x+dx[i]);
					if(next.y < 0 || next.y >= H || next.x < 0 || next.x >= W) continue;
					if(map[next.y][next.x] == 'X') continue;
					if(dist[next.y][next.x] != -1) continue;
					dist[next.y][next.x] = dist[now.y][now.x] + 1;
					q.add(new Point(next.y, next.x));
				}
			}
			ans += dist[yplace[count+1]][xplace[count+1]];
		}
		System.out.println(ans);
	}
	static class Point{
		int y;
		int x;
		Point(int y, int x){
			this.y = y;
			this.x = x;
		}
	}
}



Measured memory_bytes: 106396
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
#include<math.h>
#include<string>
#include <iomanip>
#include<deque>
#include<queue>
#include<stack>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;
const ll LINF = 1e18;
const int INF = 1e8;

//マクロ定義
#define vvint(vec,n,m,l) vector<vector<int>> vec(n, vector<int>(m,l));	// lで初期化
#define vvll(vec,n,m,l) vector<vector<ll>> vec(n,vector<ll>(m,l));
#define vint vector<int>
#define pint pair<int,int>
#define rep(i,a) for(int i=0;i<(a);i++)
#define all(x) (x).begin(),(x).end()
#define debug system("pause")				//デバッグ用

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

	string s;
	cin >> s;
	if (s == "Sunny")
	{
		cout << "Cloudy";
	}
	else if (s == "Cloudy")
	{
		cout << "Rainy";
	}
	else
	{
		cout << "Sunny";
	}
	cout << endl;


}

Measured memory_bytes: 256
using System;

namespace AtCoder.Abc
{
    public class QuestionA
    {
        public static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            long n = int.Parse(Console.ReadLine());

            var m = n % 10;
            string result = "";
            switch (m)
            {
                case 2:
                case 4:
                case 5:
                case 7:
                case 9:
                    result = "hon";
                    break;
                case 0:
                case 1:
                case 6:
                case 8:
                    result = "pon";
                    break;
                default:
                    result = "bon";
                    break;

            }

            Console.WriteLine(result);

            Console.Out.Flush();
        }
    }
}


Measured memory_bytes: 27468
#include <bits/stdc++.h> 
#define PB push_back
using namespace std;

int main(){
	int n;
	cin>>n;
	int s=0,f=0;
	for(int i=0;i<n;i++){
		int a,b;
		cin>>a>>b;
		if(a==b){
			s++;
		}
		else{
			s=0;
		}
		if(s>=3){
			f++;
		}
	}
	cout<<(f==0?"No":"Yes")<<endl;
}


Measured memory_bytes: 3592
#include <algorithm>
#include <vector>
#include <complex>
using namespace std;
//---------------------------------------------------------------
using Point = complex<double>;
const double eps = 1e-10;
double cross(const Point &a, const Point &b) { return imag(conj(a) * b); }
//---------------------------------------------------------------

#include <iostream>
int main() {
    int n; cin >> n;
    while (n--) {
        vector<double> x(4), y(4);
        for (int i = 0; i < 4; i++) {
            cin >> x[i] >> y[i];
        }
        Point v[2] = {
            Point(x[0], y[0]) - Point(x[1], y[1]),
            Point(x[2], y[2]) - Point(x[3], y[3])
        };
        double res = cross(v[0], v[1]);
        cout << (abs(res) < eps ? "YES" : "NO") << endl;
    }
    return 0;
}


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

using namespace std;

const long long MOD = (long long)1e9 + 7;
int n;

vector<vector<long long>> matrix_mul(vector<vector<long long>> a, vector<vector<long long>> b){
    vector<vector<long long>> res(n, vector<long long>(n));
    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++){
            for(int k = 0; k < n; k++){
                res[i][j] += a[i][k] * b[k][j];
                res[i][j] %= MOD;
            }
        }
    }
    return res;
}

vector<vector<long long>> matrix_pow(vector<vector<long long>> a, long long k){
    vector<vector<long long>> res(n, vector<long long>(n));
    if(k == 0){
        for(int i = 0; i < n; i++){
            res[i][i] = 1;
        }
        return res;
    }
    res = matrix_pow(matrix_mul(a, a), k >> 1);
    if(k & 1) res = matrix_mul(a, res);
    return res;
}

int main(){
    long long k;
    cin >> n >> k;
    vector<vector<long long>> a(n, vector<long long>(n));
    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++){
            cin >> a[i][j];
        }
    }
    a = matrix_pow(a, k);
    long long ans = 0;
    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++){
            ans += a[i][j];
            ans %= MOD;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 5504
// 挿入ソート
#include<iostream>
#include<algorithm>
using namespace std;

//static const int MAX_N = 100;
static const int MAX_ELE = 1000;

void insertionSort(int A[], int n);

int main(void)
{

    int N;
    int ary_sequence[MAX_ELE];

    cin >> N;

    for(int i = 0; i < N; i++)
    {
        cin >> ary_sequence[i];
    }

    for(int i = 0; i < N - 1; i++)
    {
        cout << ary_sequence[i] << ' ';
    }

    cout << ary_sequence[N - 1] << endl;

    // 挿入ソートの実施
    insertionSort(&ary_sequence[0], N);

    return 0;
}

// 挿入ソートを実施する関数
void insertionSort(int A[], int n)
{
    int v, j;

    for(int i = 1; i < n; i++)
    {

        v = A[i];
        j = i - 1;

        while( j >= 0 && A[j] > v )
        {
            A[j + 1] = A[j];
            j--;
        }

        A[j + 1] = v;

        // 結果表示用
        for(int k = 0; k < n - 1; k++)
        {
        		cout << A[k] << ' ';
        }

        cout << A[n - 1] << endl;

    }
}



Measured memory_bytes: 3060
from collections import defaultdict

N=int(input())
a=list(map(int,input().split()))

count=defaultdict(int)
count3200=0
for i in range(N):
  if a[i] < 3200:
    count[a[i] // 400] += 1
  else:
    count3200 += 1
    
print(max(len(count),1),len(count)+count3200)

Measured memory_bytes: 9404
#include <iostream>
#include <algorithm>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <string>
#include <cstring>
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ROF(i,a,b) for(int i=b-1;i>=a;i--)
#define FI first
#define SE second
#define SI size()
#define MA(i,j) make_pair(i,j)
#define PA pair<int,int>
#define PF push_front
#define PB push_back
#define VE vector<int>
#define VP vector<PA>
#define LL long long
#define YES(i) cout<<(i?"YES":"NO")<<endl
#define Yes(i) cout<<(i?"Yes":"No")<<endl
using namespace std;
//
const int MOD=1e9+7;
const int INF=1e9+7;
//
int main(){
  int N;
  int A[100];
  cin>>N;
  FOR(i,0,N){
    cin>>A[i];
  }
  sort(A,A+N,greater<int>());
  int ans=0,bob=0;
  FOR(i,0,N){
    if(i%2==0){
      ans+=A[i];
    }else{
      bob+=A[i];
    }
  }
  cout<<ans-bob<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
using namespace std;

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

	if (N % 2 == 1) {
		cout << "No" << endl;
	}
	else {
		string s1, s2;
		s1 = s.substr(0, N / 2);
		s2 = s.substr(N / 2 , N / 2);

		if (s1 == s2) {
			cout << "Yes" << endl;
		}
		else {
			cout << "No" << endl;
		}
	}
}

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

int main() {
    string s;
    cin >> s;
    bool a = false, b = false;
    for(char c : s) {
        a |= (c == 'A');
        b |= (c == 'B');
    }
    cout << (a && b ? "Yes\n" : "No\n");
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define FOR(i, a, b) for(ll i = (ll)a; i <= (ll)b; i++)
#define DEC(i, a, b) for(ll i = (ll)a; i >= (ll)b; i--)
typedef pair<ll, ll> pi;
typedef pair<ll, pi> pii;
typedef pair<pi, pi> pipi;
#define f first
#define s second
typedef vector<ll> vi;
typedef vector<pi> vpi;
typedef vector<pii> vpii;
#define pb push_back
#define pf push_front
#define all(v) v.begin(), v.end()
#define disc(v) sort(all(v)); v.resize(unique(all(v)) - v.begin());
#define INF (ll) 1e9 + 100
#define LLINF (ll) 1e18
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());    //can be used by calling rng() or shuffle(A, A+n, rng)
inline ll rand(ll x, ll y) { ++y; return (rng() % (y-x)) + x; } //inclusivesss

ll x, k, d;

int main() {
	fastio; cin >> x >> k >> d;
	x = llabs(x);
	if (x/d > k) {
		cout << x - k*d;
		return 0;
	}
	k -= x/d; x %= d;
	if (k % 2) cout << d-x;
	else cout << x;
}


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

int main()
{
	int n;

	while( cin >> n ){
		for( int i = 0; i < n; ++i ){
			int s;
			cin >> s;
			cout << "Case " << i + 1 << ":" << endl;
			for( int j = 0; j < 10; ++j ){
				s *= s;
				int d[ 4 ];
				s /= 100;
				for( int k = 0; k < 4; ++k ){
					d[ k ] = s % 10;
					s /= 10;
				}
				s = 0;
				for( int k = 0; k < 4; ++k ){
					s *= 10;
					s += d[ 4 - 1 - k ];
				}
				cout << s << endl;
			}
		}
	}

	return 0;
}

Measured memory_bytes: 1160
#ifdef LOCAL
#define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define reps(i,a,b) for(int i=a;i<b;++i)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#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>;
template<typename T> inline bool chmax(T &a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T> inline bool chmin(T &a,T b){if(b<a){a=b;return 1;}return 0;}
template<typename T> vector<T> make_vec(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_vec(size_t a,Ts... ts){return vector<decltype(make_vec<T>(ts...))>(a,make_vec<T>(ts...));}
template<typename T,typename U,typename... V>
typename enable_if<is_same<T,U>::value>::type fill_v(U &u,const V... v){u=U(v...);}
template<typename T,typename U,typename... V>
typename enable_if<!is_same<T,U>::value>::type fill_v(U &u,const V... v){for(auto &e:u)fill_v<T>(e,v...);}

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

    size_t a, b;
    cin >> a >> b;
    bitset<32> bs1(a), bs2(b);
    cout << (bs1 & bs2) << endl;
    cout << (bs1 | bs2) << endl;
    cout << (bs1 ^ bs2) << endl;
}



Measured memory_bytes: 3232
#include <iostream>
#include <vector>

using namespace std;

vector<int> colour;
vector<vector<int> > e;

bool dfs(int v, int prev_col) {
    // cout <<"v, prev_col = " << v << ", " << prev_col << endl;
    if(colour[v]==0) {
        if(prev_col==1) {
            colour[v]=-1;
            for(int vi=0; vi<e[v].size(); vi++) {
                if(dfs(e[v][vi], -1)) {
                    continue;
                } else {
                    return false;
                }
            }
            return true;
        } else {
            colour[v]=1;
            for(int vi=0; vi<e[v].size(); vi++) {
                if(dfs(e[v][vi], 1)) {
                    continue;
                } else {
                    return false;
                }
            }
            return true;
        }
    } else if(colour[v]!=prev_col) {
        return true;
    } else {
        return false;
    }
}

int main() {
    int N, M;
    cin >> N >> M;
    colour = vector<int> (N, 0);
    
    e = vector<vector<int> >(N);
    for(int m=0; m<M; m++) {
        int A, B;
        cin >> A >> B;
        e[A-1].push_back(B-1);
        e[B-1].push_back(A-1);
    }
    
    bool is2g=false;
    // for(int v=0; v<N; v++) {
    //     if(colour[v]!=-1) {
    //         continue;
    //     }
    //     if(dfs(v, 1)) {
    //         is2g = true;
    //     }
    // }
    if(dfs(0, 1)) {
        is2g = true;
    }

    // for(int i=0; i<N; i++) {
    //     cout << colour[i] << endl;
    // }
    int B=0;
    for(int i=0; i<N; i++) {
        if(colour[i]==1) B++;
    }
    
    if(is2g) {
        // cout << "aaaa" << endl;
        cout << ((long long int)B)*((long long int)N-(long long int)B) - (long long int)M << endl;
    } else {
        cout << (long long int)N*(long long int)(N-1)/2 - M << endl;
    }

    return 0;
    
}

Measured memory_bytes: 6400
#include <bits/stdc++.h>
using namespace std;
//ask the right questions.		

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

	int dp[n];
	dp[0]=0;        //to reach first stone

	for(int i=1;i<n;i++)
	{
		//last jump made is either 1 or 2.
		dp[i] = min(dp[i-2]+abs(a[i]-a[i-2]), dp[i-1]+abs(a[i]-a[i-1]) );
	}
	cout << dp[n-1];
	
	return 0;
	
}

Measured memory_bytes: 4404
#abc156 c
n=int(input())
x=list(map(int,input().split()))

s=min(x)
b=max(x)

ans=100100100

for i in range(s,b+1):
    hp=0
    for j in x:
        hp+=(i-j)**2
    if hp<ans:
        ans=hp
print(ans)

Measured memory_bytes: 3060
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define rep(i,n) for(i=0;i<n;i++)
#define loop(i,a,n) for(i=a;i<n;i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

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

int i,j;
int a[105][105];
int used[105][105];
int h,w;

void search(int y,int x,int c){
  if(x<0 || y<0 || y>=h || x>=w || a[y][x]!=c)return;
  if(used[y][x])return;
  used[y][x]++;
  int i;
  int dx[4]={-1,0,1,0};
  int dy[4]={0,-1,0,1};
  rep(i,4)
    search(y+dy[i],x+dx[i],c);
  return;
}

int main(void) {
  while(1){
    cin>>w>>h;
    if(h==0 && w==0)break;
    rep(i,h)rep(j,w)used[i][j]=0;
    int xs,ys,xg,yg,n;
    cin>>xs>>ys;
    xs--;ys--;
    cin>>xg>>yg;
    xg--;yg--;
    cin>>n;
    rep(i,n){
      int c,d,x,y;
      cin>>c>>d>>x>>y;
      x--;y--;
      int p[8]={0,0,0,0,1,1,1,1};
      int q[8]={0,1,2,3,0,1,2,3};
      if(d)
	rep(j,8)
	  a[y+q[j]][x+p[j]]=c;
      else
	rep(j,8)
	  a[y+p[j]][x+q[j]]=c;
    }  
    if(a[ys][xs]==0){
      cout<<"NG"<<endl;
      continue;
    } 
    search(ys,xs,a[ys][xs]);//dfs
    if(used[yg][xg])
      cout<<"OK"<<endl;
    else
      cout<<"NG"<<endl;
  }
  return 0;
}

Measured memory_bytes: 3164
package main

import (
	"fmt"
)

func main() {
	L := [6]int{}
	for i := 0; i < 6; i++ {
		fmt.Scan(&L[i])
	}

	W := make([]int, 0)
	for i := 0; i <= 30; i++ {
		for j := 0; j <= 30; j++ {
			w := (L[0]*i + L[1]*j) * 100
			if w == 0 {
				continue
			}
			if w > L[5] {
				break
			}
			W = append(W, w)
		}
	}

	S := make([]int, 0)
	for i := 0; i <= 3000; i++ {
		for j := 0; j <= 3000; j++ {
			s := L[2]*i + L[3]*j
			if s > L[5] {
				break
			}
			S = append(S, s)
		}
	}

	d := 0.0
	ans1, ans2 := W[0], 0
	for _, a := range W {
		for _, b := range S {
			if (a+b) > L[5] || b*100 > L[4]*a {
				continue
			}
			tmp := float64(100*b) / float64(a+b)
			if tmp > d {
				d = tmp
				ans1, ans2 = a+b, b
			}
		}
	}

	fmt.Println(ans1, ans2)
}


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

int		main(void)
{
	map<char, int> a;
	string	tm;
	cin >> tm;
	for (int i = 0; i < tm.size(); i++)
	{
		if (a.count(tm.at(i)))
			a.at(tm.at(i))++;
		else
			a[tm.at(i)] = 1;
	}
	for (auto &i : a)
	{
		if (i.second % 2)
		{
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
}

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

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin>>n;
    int c=0, s=1, a=2;
    if(n%2==0)
        cout<<n/2-1;
    else
        cout<<n/2;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<cstring>

#define INF 99999999

using namespace std;

struct edge{
	int to,cap,rev; 
};

const int MAX_V = 205;

vector<edge> G[MAX_V];
bool used[MAX_V];

void add_edge(int from,int to,int cap){		//??°???????????\???
	G[from].push_back((edge){to,cap,G[to].size()});
	G[to].push_back((edge){from,0,G[from].size()-1});
}

int dfs(int v,int t,int f){
	if(v == t)	return f;
	used[v] = true;
	for(int i=0;i<G[v].size();i++){
		edge &e = G[v][i];	//?????§?????°??¨????????????(?????????????????£??\???????????????????????????)
		if(!used[e.to] && e.cap > 0){
			int d = dfs(e.to,t,min(f,e.cap));
			if(d > 0){
				e.cap -= d;	//e???G[v][i]?????¨????????¢?????§???????????????????????????G[v][i]??????????????????????????¨??????
				G[e.to][e.rev].cap += d;
				return d;
			}
		}
	}
	return 0;
}

int max_flow(int s,int t){
	int flow = 0;
	for(;;){
		memset(used,0,sizeof(used));
		int f = dfs(s,t,INF);
		if(f == 0)	return flow;
		flow += f;
	}
}

int main(){
	int m,result,x,y;
	cin >> x >> y >> m;
	for(int i=0;i<m;i++){
		int from,to,cap;
		cin >> from;
		cin >> to;
		add_edge(from,x+to,INF);
	}
	for(int i=0;i<x;i++){
		add_edge(x+y,i,1);
	}
	for(int i=0;i<y;i++){
		add_edge(x+i,x+y+1,1);
	}
	result = max_flow(x+y,x+y+1);
	cout << result << "\n";
}

Measured memory_bytes: 3336
N = int(input())
A = list(map(int, input().split()))

X = [0]*N
# 全体の和 - 偶数の和*2 = 一番目の値
# もしくは、(x/2)+(y/2)=A, ..B,..C -> x+y+z = A+B+C
X[0] = sum(A) - sum(A[1::2])*2

#最初の値から順番にダムの値を引けば答え
for i in range(1, N):
  X[i] = A[i-1]*2 - X[i-1]
  
print(*X)  

Measured memory_bytes: 14092
#include<bits/stdc++.h>
using namespace std;
int n,p[200005],ans=1,x;
int main(){
    cin>>n;
    for(int i=1;i<=n;i++) cin>>p[i];
    x=p[1];
    for(int i=2;i<=n;i++)
        if(p[i]<x) ans++,x=p[i];
    cout<<ans;
	return 0;
}

Measured memory_bytes: 1024
a,b,m=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
XYC=[list(map(int,input().split())) for _ in range(m)]

ans=[]
for x,y,c in XYC:
  x,y=x-1,y-1
  ans.append(A[x]+B[y]-c)
A.sort()
B.sort()
ans.append(A[0]+B[0])
ans.sort()
print(ans[0])

Measured memory_bytes: 42796
#include <bits/stdc++.h>
using namespace std;
vector<string> tyouhuku(vector<string> v){
  sort(v.begin(),v.end());
  int i = 1;
  while(i < v.size()){
    while(v[i] == v[i-1])v.erase(v.begin() + i);
    i++;
  }
  return v;
}

int main() {
  int N;
  cin >> N;
  string s;
  vector<string> M,A,R,C,H;
  for(int i = 0;i < N;i++){
    cin >> s;
    if(s[0] == 'M')M.push_back(s);
    if(s[0] == 'A')A.push_back(s);
    if(s[0] == 'R')R.push_back(s);
    if(s[0] == 'C')C.push_back(s);
    if(s[0] == 'H')H.push_back(s);
  }
  tyouhuku(M);
  tyouhuku(A);
  tyouhuku(R);
  tyouhuku(C);
  tyouhuku(H);
  long int ans = 0;
  ans += M.size()*A.size()*R.size();
  ans += M.size()*A.size()*C.size();
  ans += M.size()*A.size()*H.size();
  ans += M.size()*R.size()*C.size();
  ans += M.size()*R.size()*H.size();
  ans += M.size()*C.size()*H.size();
  ans += A.size()*R.size()*C.size();
  ans += A.size()*R.size()*H.size();
  ans += A.size()*C.size()*H.size();
  ans += R.size()*C.size()*H.size();
  cout << ans << endl;
}


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

string a;
typedef long long ll;
ll n, M = 1e9 + 7, u, s[100005][15];
void f(ll p, ll q) {
	ll i;
	for (i = 0; i < 13; i++) {
		s[p][(i + q) % 13] = (s[p][(i + q) % 13] + s[p + 1][i]) % M;
	}
}
int main()
{
	ll i, j;
	cin >> a;
	n = a.size();
	s[n][0] = 1;
	u = 1;
	for (i = a.size() - 1; i >= 0; i--) {
		if (a[i] == '?') {
			for (j = 0; j <= 9; j++) f(i, u * j);
		} else {
			f(i, u * (a[i] - '0'));
		}
		u = (u * 10) % 13;
	}
	cout << s[0][5];
    return 0;
}


Measured memory_bytes: 12160
S = input()
words = ['A', 'C', 'G', 'T']
longest = 0
now_length = 0
for c in S:
    if c in words:
        now_length += 1
    else:
        longest = max(longest, now_length)
        now_length = 0
longest = max(longest, now_length)
print(longest)

Measured memory_bytes: 3060
arr = gets.split(' ')
msg = "No"
if arr[0].to_i < arr[1].to_i && arr[1].to_i > arr[2].to_i && arr[2].to_i > arr[0].to_i
  msg = "Yes"
end

if arr[0].to_i > arr[1].to_i && arr[1].to_i < arr[2].to_i && arr[2].to_i < arr[0].to_i
  msg = "Yes"
end

puts msg

Measured memory_bytes: 1788
def gcd(x, y):
    for i in range(min(x, y), 1, -1):
        if x % i == 0 and y % i == 0:
            return i


def lcm(x, y):
    return x/gcd(x, y)*y


i = list(map(int, input().split()))
g = gcd(i[0],i[1])
if g != None:
    print(int(lcm(i[0],i[1])))
else :
    print(i[0] * i[1])

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

int main(void) {
    int a, b;
    int d, r;
    double f;
    
    cin >> a >> b;
    
    d = a / b;
    r = a % b;
    f = (double)a / b;
    
    printf("%d %d %.6lf", d, r, f);
    cout << endl;
    return 0;
}



Measured memory_bytes: 3216
#include <bits/stdc++.h>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

vector<string> split(const string &s, char delim) {
  vector<string> elems;
  string item;
  for (char ch: s) {
    if (ch == delim) {
      if (!item.empty()) {
        elems.push_back(item);
      }
      item.clear();
    }
    else {
      item += ch;
    }
  }
  if (!item.empty()) {
    elems.push_back(item);
  }
  return elems;
}

string to_str_with_zero(int i, int w) {
  ostringstream sout;
  sout << std::setfill('0') << std::setw(w) << i;
  string s = sout.str();
  return s;
}

int letter_to_int(char c) {
  return tolower(c) - 'a';
}

int compare_array(vector<int> a1, vector<int>a2) {
  if (a1.size() != a2.size()) {
    return a1.size() - a2.size();
  }
  for (int i=0; i<a1.size(); i++) {
    if (a1.at(i) != a2.at(i)) {
      return a1.at(i) - a2.at(i);
    }
  }
  return 0;
}

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

char int_to_char(int a) {
  if (a == -1) {
    return 'z';
  }
  else {
    return 'a' + a;
  }
}

long nCr(int n, int r) {
    long ans = 1;
    for (int i = n; i > n - r; --i) {
        ans = ans*i;
    }
    for (int i = 1 ; i < r + 1; ++i) {
        ans = ans / i;
    }
    return ans;
}

long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m; 
    if (u < 0) u += m;
    return u;
}

int divide_count(int a, int divider) {
  int r = 0;
  while(a % divider == 0) {
    a /= divider;
    r++;
  }
  return r;
}

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

vector<vector<int>> all_comb(int n, int k) {
  vector<vector<int>> combs(nCr(n, k), vector<int>(k));
  for(int i=0; i<k; i++) {
    combs[0][i] = i;
    combs[1][i] = i;
  }
  
  for(long i=1; i<nCr(n, k); i++) {
    int p = 1;
    while(combs[i][k - p] == n - p) {
      p++;
      if(p > k) {
        break;
      }
    }
    combs[i][k - p]++;
    int q = combs[i][k - p];
    for(int j=1; j<p; j++) {
      combs[i][k - p + j] = q + j;
    }

    if(i < nCr(n, k) - 1) {
      for(int j=0; j<k; j++) {
        combs[i + 1][j] = combs[i][j];
      }
    }
  }

  return combs;
}

int main() {
  std::cout << std::setprecision(9);
  int n;
  cin >> n;

  vector<int> l(n);
  for(int i=0; i<n; i++) {
    cin >> l[i];
  }
  sort(l.begin(), l.end());

  long ans = 0;
  for(int i=0; i<n; i++) {
    int max_where = i + 1;
    for(int j=i + 1; j<n; j++) {
      while(l[max_where] < l[i] + l[j] && max_where < n) {
        max_where++;
      }
      ans += max_where - j - 1;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3556
import io.{StdIn => in}

object Main extends App {
  val Array(w, h, n) = in.readLine.split(" ").map(_.toInt)
  val table = Array.ofDim[Boolean](h, w)
  Iterator.continually(in.readLine.split(" ").map(_.toInt))
    .take(n)
    .foreach(a => {
      val xi = a(0)
      val yi = a(1)
      a(2) match {
        case 1 => table.foreach(t => (0 until xi).foreach(i => t(i) = true))
        case 2 => table.foreach(t => (xi until w).foreach(i => t(i) = true))
        case 3 => table.take(yi)foreach(t => (0 until w).foreach(i => t(i) = true))
        case 4 => table.drop(yi)foreach(t => (0 until w).foreach(i => t(i) = true))
      }
    })

  val ans = table./:(0)((acc, e) => acc + e.count(_ == false))
  println(ans)
}

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

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

  if(N<10){
    if(N == 3){
      cout << "bon" << endl;
    }
    else if(N == 1||N == 6||N == 8){
      cout << "pon" << endl;
    }
    else{
      cout << "hon" << endl;
    }
  }
  else if(9<N && N<100){
    N %= 10;
    if(N == 3){
      cout << "bon" << endl;
    }
    else if(N == 0||N == 1||N == 6||N == 8){
      cout << "pon" << endl;
    }
    else{
      cout << "hon" << endl;
    }
  }
  else{
    N %= 100;
    N %= 10;
    if(N == 3){
      cout << "bon" << endl;
    }
    else if(N == 0||N == 1||N == 6||N == 8){
      cout << "pon" << endl;
    }
    else{
      cout << "hon" << endl;
    }
  }
}


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

int main() {
    ll n, a, b;
    cin >> n >> a >> b;
    
    ll ans, divi, mod;
    divi = n / (a + b);
    mod = n % (a + b);
    if (mod >= a) mod = a;
    ans = divi * a + mod;
    
    cout << ans << endl;
}

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

int main()
{
    int n, m, ki, aij, fav[30] = { 0 };
    cin >> n >> m;

    for(int i = 0; i < n; i++){
        cin >> ki;
        for(int j = 0; j < ki; j++){
            cin >> aij;
            fav[aij - 1]++;
        }
    }

    int ans = 0;
    for(int i = 0; i < m; i++)
        if(fav[i] == n) ans++;
    cout << ans << endl;
    return 0;
}

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

int main() {
    int n;
    cin >> n;
    int a[n];
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    sort(a, a+n);
    reverse(a, a+n);
    int alice = 0;
    int bob = 0;
    for (int i = 0; i < n; i++) {
        if (i%2 == 0) {
            alice += a[i];
        } else {
            bob += a[i];
        }
    }
    cout << alice - bob;
    return 0;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {
	a := getInt()
	b := getInt()
	c := getInt()

	fmt.Println(max(c-(a-b), 0))
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

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

var sc = bufio.NewScanner(os.Stdin)

func init() {
	// tmp := 200001
	// sc.Buffer(make([]byte, tmp), tmp)
	sc.Split(bufio.ScanWords)
}

func getInt() int {
	i, err := strconv.Atoi(getString())
	if err != nil {
		panic(err)
	}
	return i
}

func getString() string {
	sc.Scan()
	s := sc.Text()
	return s
}


Measured memory_bytes: 640
#include<iostream>
#define REP(i,n) for(int i=0;i<n;i++)
using namespace std;
int n,k,x[105];
int sum=0;
int mi(int i,int n)
{
	if(i<n)
	return i;
	return n;
}
int ad(int i,int q)
{
	return i+q;
}
int main()
{
	cin>>n>>k;
	REP(i,n)
	{
		cin>>x[i];
		sum=ad(mi(x[i],k-x[i])*2,sum);
	}
	cout<<sum<<endl;
	return 0;
}

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

using namespace std;

int main(){
  int n,a,b;
  cin >>n>>a>>b;
  char s[100005];
  cin >> s;
  int p=0,q=0;
  for(int i=0;i<n;i++){
    if(s[i]=='a'){
      if(p<a+b){
        cout << "Yes"<<endl;
        p++;
      }else{
        cout<<"No"<<endl;
      }
    }else if(s[i]=='b'){
      if(p<a+b&&q<b){
        cout << "Yes"<<endl;
        p++;
        q++;
      }else{
        cout<<"No"<<endl;
      }
    }else{
      cout<<"No"<<endl;
    }
  }
}

Measured memory_bytes: 768
/*----------------------
h28i13 織海斗
------------------------*/
#include <iostream>
using namespace std;

int main(){
	bool is_prime[1000000];
	is_prime[0]=is_prime[1]=false;
	for(int i=2;i<1000000;i++){
		is_prime[i]=true;
	}
	for(int i=2;i*i<1000000;i++){
		if(is_prime[i]){
			for(int j=i*i;j<1000000;j+=i){
				is_prime[j]=false;
			}
		}
	}

	int n[10000],num[10000];
	int j=0;
	for(int i=0;i<10000;i++){
		num[i]=0;
	}
	while(true){
		cin>>n[j];
		if(n[j]==0)
			break;
		for(int i=2;i<n[j]/2+1;i++){
			if(is_prime[i]==true){
				if(is_prime[n[j]-i]==true){
					num[j]+=1;
				}
			}
		}
		j++;
	}
	for(int i=0;i<j;i++)
		cout<<num[i]<<endl;
	return 0;
}


Measured memory_bytes: 4148
import java.util.*;

class Main {
	Scanner sc = new Scanner(System.in);

	public void run() {
		while(true){
			int n=sc.nextInt();
			if(n==0)break;
			int[][] map=new int[n][n];
			int px=n/2,py=n/2+1;

			map[px][py]=1;
			for(int i=2;i<=n*n;i++){
				px=(px+1)%n;py=(py+1)%n;
				while(map[px][py]!=0){
					px=(px-1+n)%n;py=(py+1)%n;
				}
				map[px][py]=i;
			}
			for(int y=0;y<n;y++){
				for(int x=0;x<n;x++){
					pr(String.format("% 4d",map[x][y]));
				}
				ln();
			}
		}
	}

	public static void main(String[] args) {
		new Main().run();
	}

	public static void pr(Object o) {
		System.out.print(o);
	}

	public static void ln(Object o) {
		System.out.println(o);
	}

	public static void ln() {
		System.out.println();
	}
}

Measured memory_bytes: 12000
import java.io.BufferedReader;
import java.io.PrintWriter;
import java.util.HashSet;
import java.util.Scanner;
import java.util.StringTokenizer;


public class Main {
	static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) throws Exception {
		int n = sc.nextInt();
		long[]a = input(n);
		long[] dp = new long[n];
		for(int i =1 ; i < n ;i++) {
			long temp = Math.abs(a[i]-a[i-1]) + dp[i-1];
			if(i>1)temp = Math.min(temp, Math.abs(a[i] - a[i-2] )+ dp[i-2]);
			dp[i]=temp  ;
		}
		System.out.println(dp[n-1]);
	}
	public static long[] input(int n) throws Exception {

		long[] arr = new long[n];
		for (int i = 0; i < n; i++) {
			arr[i] = sc.nextLong();
		}
		return arr;
	}

}


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

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

    string s;
    cin >> s;
    ll n = s.size();
    ll w = 0;
    for (ll i = 0; i < n; i++){
        if (s[i] == 'W'){
            w++;
        }
    }
    ll ans = 0;
    ll c = 0;
    for (ll i = 0; i < n; i++){
        if (s[i] == 'W'){
            ans += (i-c);
            c++;
        }
    }

cout << ans << endl;
}

Measured memory_bytes: 3760
using System;
using System.Collections.Generic;
using System.Windows;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Atcoder
{
    public class Program
    {
        static void Main(string[] args)
        {
            var r = ReadSplit();
            var n = r[0].Int();
            var m = r[1].Int();
            var l = new List<Tuple<long, int>>();
            var r2 = ReadSplit();
            for (int i = 0; i < n; i++)
            {
                l.Add(new Tuple<long, int>(r2[i].Long(), 1));
            }
            for (int i = 0; i < m; i++)
            {
                var r3 = ReadSplit();
                var b = r3[0].Int();
                var c = r3[1].Long();
                l.Add(new Tuple<long, int>(c, b));
            }
            var ans = 0L;
            var count = 0;
            foreach (var item in l.OrderByDescending(x => x.Item1))
            {
                if (n <= count + item.Item2)
                {
                    ans += item.Item1 * (n - count);
                    break;
                }
                else
                {
                    ans += item.Item1 * item.Item2;
                }
                count += item.Item2;
            }
            WriteRead(ans);
        }

        public static string Read()
        {
            return Console.ReadLine();
        }

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

        public static void WriteRead(object str)
        {
            Console.WriteLine(str);
            Read();
        }

        public static void Write(object str)
        {
            Console.WriteLine(str);
        }

        private static bool ChangeMin<T>(ref T a, T b) where T : IComparable
        {
            if (a.CompareTo(b) > 0)
            {
                a = b;
                return true;
            }
            return false;
        }

        private static bool ChangekMax<T>(ref T a, T b) where T : IComparable
        {
            if (b.CompareTo(a) > 0)
            {
                a = b;
                return true;
            }
            return false;
        }
    }
}


public static class Extentions
{
    public static int Int(this object obj)
    {
        return int.Parse(obj.ToString());
    }

    public static long Long(this object obj)
    {
        return long.Parse(obj.ToString());
    }

    public static decimal Decimal(this object obj)
    {
        return decimal.Parse(obj.ToString());
    }

    public static double Double(this object obj)
    {
        return double.Parse(obj.ToString());
    }

    public static T2 GetValueZero<T1, T2>(this Dictionary<T1, T2> d, T1 key) where T2 : struct
    {
        T2 value;
        if (d.TryGetValue(key, out value))
        {
            return value;
        }
        return new T2();
    }
}



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

signed main(){
	ll n; cin >> n;
	string s;
	while(n > 0){
		int x = n % 26;
		n = (n-1)/26;
		if(x == 0) s.push_back('z');
		else s.push_back(x - 1 + 'a');
	}
	reverse(s.begin(), s.end());
	cout << s << endl;
}

Measured memory_bytes: 3628
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().split_whitespace().map(|e| e.parse().ok().unwrap()).collect()
}

fn main(){
    //W,H,x,y,r
    let mut i:Vec<i32> = read_vec();
    let W = i[0];
    let H = i[1];
    let x = i[2];
    let y = i[3];
    let r = i[4];

    if x - r < 0 || y - r < 0  || x + r > W || y + r > H {
        println!("No");
    } else {
        println!("Yes");
    }


}


Measured memory_bytes: 5028
#include <bits/stdc++.h>
using namespace std;
 
int w, h;
int r[10][10];
int Count;
 
int dy[] = {0, 1, 0, -1};
int dx[] = {1, 0, -1, 0};
 
int ty[] = {0, 1, 0, -1};
int tx[] = {1, 0, -1, 0};
 
int v[10][10], u[10][10];
 
 
bool dfs(int ax, int ay, int bx, int by)
{
  v[ay][ax]++;
  u[by][bx]++;
  Count -= v[ay][ax] == 1;
  Count -= u[by][bx] == 1;
  if(Count == 0) return(true);
 
  for(int i = 0; i < 4; i++) {
    int ny = ay + dy[i], nx = ax + dx[i];
    int my = by + ty[i], mx = bx + tx[i];
    if(ny < 0 || nx < 0 || ny >= h || nx >= w) continue;
    if(my < 0 || mx < 0 || my >= h || mx >= w) continue;
    if(ny == my && nx == mx) continue;
    if(r[ny][nx] == 0 || r[my][mx] == 0) continue;
    if(v[ny][nx] == 1 || u[my][mx] == 1) continue;
    if(u[ny][nx] > 0 || v[my][mx] > 0) continue;
    if(dfs(nx, ny, mx, my)) return(true);
  }
  return(false);
}
 
bool Calc()
{
  if(Count % 2 == 1) return(false);
  int prev = Count;
  for(int n = 0; n < 2; n++) {
 
    for(int i = 0; i < h; i++) {
      for(int j = 0; j < w; j++) {
        if(!r[i][j]) continue;
        for(int k = 0; k < h; k++) {
          for(int l = 0; l < w; l++) {
            if(!r[k][l] || (i == k && j == l)) continue;
            for(int m = 0; m < 4; m++) {
              rotate(tx, tx + 1, tx + 4);
              rotate(ty, ty + 1, ty + 4);
              Count = prev;
              fill_n(*v, 10 * 10, 0);
              fill_n(*u, 10 * 10, 0);
              if(dfs(j, i, l, k)) return(true);
            }
          }
        }
      }
    } 
    swap(ty[1], ty[3]);
    swap(tx[1], tx[3]);
  }
  return(false);
}
 
int main()
{
 
  while(cin >> w >> h, w) {
    Count = 0;
    for(int i = 0; i < h; i++) {
      for(int j = 0; j < w; j++) {
        cin >> r[i][j];
        Count += r[i][j];
      }
    }
    if(Calc()) cout << "YES" << endl;
    else cout << "NO" << endl;
  }
}

Measured memory_bytes: 1172