akhauriyash/Code-Regression huggingface dataset:
#include<iostream>

void exchange(int A[],int a,int b){
  int copy=A[a];
  A[a]=A[b];
  A[b]=copy;
}
int partion(int A[],int s,int e){
  int position=s;
  for(int i=s;i<e;i++){
    if(A[i]<=A[e]){
      exchange(A,position,i);
      position++;
    }
  }
  exchange(A,position,e);
  return position;
}

int main(){
  int n;
  std::cin>>n;
  int A[n];
  for(int i=0;i<n;i++){
    std::cin>>A[i];
  }
  //入力終わり
  int x=partion(A,0,n-1);
  //出力
  for(int i=0;i<n;i++){
    if(i==x){
      std::cout<<"["<<A[i]<<"]";
    }else{
      std::cout<<A[i];
    }
    if(i!=n-1){
      std::cout<<" ";
    }
  }
  std::cout<<std::endl;
  return 0;
}



Measured memory_bytes: 3472
#include <algorithm>
#include <iostream>
#include <numeric>
#include <vector>

using namespace std;

int main()
{
    int a;
    string s;
    cin>>a>>s;
    if(a>=3200)
    {
        cout<<s<<endl;
    }
    else
    {
        cout<<"red"<<endl;
    }
}

Measured memory_bytes: 256
while True:
    a, op, b = input().split()
    a = int(a)
    b = int(b)
   
    if op == '?':
        break
   
    if op == '+':
        print(a + b)
   
    if op == '-':
        print(a - b)
   
    if op == '*':
        print(a *b)
   
    if op == '/':
        print(a // b)

Measured memory_bytes: 7648
n = 40
k = 5
 
print n
a = [[] for i in range(n)]
for i in range(n):
  for j in range(n):
    if i == j:
      a[i].append("N")
      continue
 
    if i < k:
      if j >= k:
        a[i].append("Y")
      else:
        a[i].append("Y")
    else:
      if j >= k:
        a[i].append("N")
      else:
        a[i].append("Y")
 
for i in range(n):
  print "".join(a[i])

Measured memory_bytes: 4228
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ll;
#define MS(a) memset(a,0,sizeof(a))
#define MP make_pair
#define PB push_back
const int INF = 0x3f3f3f3f;
const ll INFLL = 0x3f3f3f3f3f3f3f3fLL;
inline ll read(){
    ll x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
//////////////////////////////////////////////////////////////////////////
const int maxn = 1e5+10;

int main(){
	ll a,b,c,ans=0;
	cin >> a >> b >> c;
	if(a%2 || b%2 || c%2) {
		puts("0");
		return 0;
	}
	if(a==b && b==c) {
		puts("-1");
	}else{
		while(1){
			if(a%2 || b%2 || c%2) {
				cout << ans << endl;
				break;
			}
			ll t1,t2,t3;
			t1 = a/2;
			t2 = b/2;
			t3 = c/2;
			a = t2+t3;
			b = t1+t3;
			c = t1+t2;
			ans++;
		}
	}

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	int N;cin>>N;
	vector<pair<pair<string,int>,int>> vec(N);
	string s;int a;
	for(int i=0;i<N;i++){
		cin>>s>>a;
		vec[i].first.first=s;
		vec[i].first.second=-a;
        vec[i].second=i+1;
	}sort(vec.begin(),vec.end());
	for(int i=0;i<N;i++){
		cout<<vec[i].second<<endl;
	}
}

Measured memory_bytes: 256
n=gets.to_i
arr=gets.split.map(&:to_i)
arr2=[]
arr=[0]+arr+[0]
i=0
(n+1).times{
   arr2<<(arr[i+1]-arr[i]).abs
   i+=1
}



key=arr2.inject(:+)



i=0
n.times{
   puts key-arr2[i+1]-arr2[i]+(arr[i+2]-arr[i]).abs
   
    
   i+=1 
}









Measured memory_bytes: 13316
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pli = pair<ll, int>;
using pil = pair<int, ll>;
using uint = unsigned int;
template <typename T>
using Graph = vector<vector<T>>;
const int MOD = 1e9 + 7;
const ld PI = acosl(-1);

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

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

    vector<vector<ll>> dp(N, vector<ll>(2, -1e18));
    dp[0][0] = 0;
    for (int i = 0; i < N - 1; ++i) {
        dp[i + 1][0] = max(dp[i][0] + A[i], dp[i][1] - A[i]);
        dp[i + 1][1] = max(dp[i][0] - A[i], dp[i][1] + A[i]);
    }

    ll ans = max(dp[N - 1][0] + A[N - 1], dp[N - 1][1] - A[N - 1]);
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 9004
n = int(input())

s_cnt = {}
for _ in range(n):
    s = input()
    if s in s_cnt.keys():
        s_cnt[s] += 1
    else:
        s_cnt[s] = 1

data = sorted(s_cnt.items(),
              key=lambda item: (-item[1], item[0]), reverse=True)

val = data[-1][1]
for item in reversed(data):
    if item[1] != val:
        break
    print(item[0])


Measured memory_bytes: 59228
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<utility>
#include<iomanip>
#include<map>
#include<cmath>
#include<cstdio>
#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(){
    int cnt=0,CNT=0;
    string n;
    string ans="AC";
    cin >> n;
    if(n[0]!='A')
        ans="WA";
    for(int i=2;i<n.length()-1;i++){
        if(n[i]=='C')
            CNT++;
    }
    for(int i=1;i<n.length();i++){
        if('a'<=n[i] && 'z'>=n[i])
            cnt++;
        else if (n[i]=='C' && 2<=i && i<n.length()-1)
            cnt++;
    }
    if(cnt!=n.length()-1 || CNT!=1)
        ans="WA";
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <cassert>
#include <random>

#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;
typedef long long int ll;
const ll INF = 1e18;
const double PI = acos(-1);
const int mod = 1000000007;

int main()
{
    int n;
    cin >> n;
    vector<int> a(n + 1);
    vector<int> b(n);
    rep(i, n + 1) cin >> a[i];
    rep(i, n) cin >> b[i];

    ll ans = 0;
    rep(i, n) {
        int c = min(a[i], b[i]);
        b[i] -= c;
        int d = min(a[i + 1], b[i]);
        a[i + 1] -= d;
        ans += c + d;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3988
#include <bits/stdc++.h>
#define LL long long
using namespace std;
int n;
LL a[500+5],b[500+5];
int main(){
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a[i];
        b[i]=a[i];
    }
    sort(b,b+n);
    int now[2],nowl=0;
    for(int i=0;i<n;i++)
        if(a[i]!=b[i]){
            if(nowl==2){
                cout<<"NO\n";
                return 0;
            }
            now[nowl++]=i;
    }
    
    if(nowl==0||(nowl==2&&a[now[0]]==b[now[1]]&&a[now[1]]==b[now[0]]))
        printf("YES\n");
    else
        printf("NO\n");

}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iomanip>
#include <numeric>
#include <queue>
#include <cmath>
using namespace std;

const int mod = 1e9 + 7;
long long int mypow(long long int a, long long int b) {
	if (b == 0) return 1;
	if (b == 1) return a;
	long long int res = mypow(a, b / 2);
	res = res * res % mod;
	if (b % 2 == 1) res = res * a % mod;
	return res;
}

long long int range_product(long long int a, long long int b) {
	long long int res = 1;
	for (int i = a; i <= b; i++) {
		res *= i;
		res %= mod;
	}
	return res;
}

long long int myc(long long int a, long long int b) {
	long long int r1 = range_product(a - b + 1, a);
	long long int r2 = range_product(1, b);
	return r1 * mypow(r2, mod - 2) % mod;
}

int main() {
	int n;
	cin >> n;
	int a, b;
	cin >> a >> b;
	long long int res = mypow(2, n) - 1;
	res -= myc(n, a);
	res -= myc(n, b);
	
	res %= mod;
	res += mod;
	res %= mod;
	cout << res << endl;
}


Measured memory_bytes: 3572
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define repF(i,a,n) for(int i = (a); i <= (n); ++i)
#define repB(i,a,n) for(int i = (a); i >= (n); --i)
#define umii unordered_map<int,int>
#define umll unordered_map<ll,ll>
#define mii map<int,int>
#define mll map<ll,ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vi vector<int>
#define vl vector<ll>
#define F first
#define S second
#define seti set<int>
#define setl set<ll>
#define pb push_back
#define db1(x) cout<<#x<<"="<<x<<'\n'
#define db2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<'\n'
#define db3(x,y,z) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<'\n'
#define dbV(arr) cout << #arr << "=[ "; \
for(auto i:arr) cout << i << " "; cout << "]\n";
#define MOD 1000000007
#define all(z) z.begin(),z.end()
using namespace std;
using ll = long long;
vector<vi> tree;
//vi dp;
/*int solve(vi &arr, int n) {
	if (n == 1) {
		return dp[n] = 0;
	}
	if (n == 2) {
		return dp[n] = abs(arr[n] - arr[n - 1]);
	}
	//Look up
	if (dp[n] != -1) return dp[n];
	return dp[n] = min(abs(arr[n] - arr[n - 1]) + solve(arr, n - 1),
	                   abs(arr[n] - arr[n - 2]) + solve(arr, n - 2));
}*/
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int n; cin >> n;
	//dp.assign(n + 1, -1);
	vi arr(n + 1); repF(i, 1, n) cin >> arr[i];
	//dp[n] = min(abs(arr[n]-arr[n-1])+dp[n-1], abs(arr[n]-arr[n-2])+dp[n-2]);

	//cout << solve(arr, n) << endl;
	vi dp(n + 1, 0);
	dp[1] = 0; dp[2] = abs(arr[1] - arr[2]);
	repF(i, 3, n) {
		dp[i] = min(abs(arr[i] - arr[i - 1]) + dp[i - 1],
		            abs(arr[i] - arr[i - 2]) + dp[i - 2]);
	}
	cout << dp[n] << endl;
	return 0;
}

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

using namespace std;

struct mint {
    static constexpr long MOD = 1000000007;
    long value;

    constexpr mint(long value = 0) noexcept : value((value % MOD + MOD) % MOD) {}
    constexpr mint operator-() const noexcept {
        return mint(-value);
    }
    constexpr mint& operator+=(const mint& rhs) noexcept {
        if ((value += rhs.value) >= MOD) value -= MOD;
        return *this;
    }
    constexpr mint& operator-=(const mint& rhs) noexcept {
        if ((value += MOD - rhs.value) >= MOD) value -= MOD;
        return *this;
    }
    constexpr mint& operator*=(const mint& rhs) noexcept {
        (value *= rhs.value) %= MOD;
        return *this;
    }
    constexpr mint operator+(const mint& rhs) const noexcept {
        mint res(*this);
        return res += rhs;
    }
    constexpr mint operator-(const mint& rhs) const noexcept {
        mint res(*this);
        return res -= rhs;
    }
    constexpr mint operator*(const mint& rhs) const noexcept {
        mint res(*this);
        return res *= rhs;
    }
    constexpr mint pow(long e) const noexcept {
        if (e == 0) return 1;
        mint a = pow(e >> 1);
        a *= a;
        if (e % 2 == 1) a *= *this;
        return a;
    }
    constexpr mint inv() const noexcept {
        return pow(MOD - 2);
    }
    constexpr mint& operator/=(const mint& rhs) noexcept {
        return *this *= rhs.inv();
    }
    constexpr mint operator/(const mint& rhs) const noexcept {
        mint res(*this);
        return res /= rhs;
    }
    friend constexpr mint pow(const mint& a, const long& b) noexcept {
        return a.pow(b);
    }
    friend ostream& operator<<(ostream& os, const mint& n) noexcept {
        os << n.value;
        return os;
    }
};

int main(void) {
    int n, m;
    cin >> n >> m;

    map<int, bool> skip;
    for (int i = 0; i < n; i++) skip[i] = false;
    for (int i = 0; i < m; i++) {
        int j;
        cin >> j;
        skip[j] = true;
    }

    vector<mint> a(n + 1);
    a[0] = 1;
    a[1] = skip[1] ? 0 : 1;
    for (int i = 2; i <= n; i++) {
        a[i] = skip[i] ? 0 : (a[i - 1] + a[i - 2]);
    }

    cout << a[n] << endl;

    return 0;
}


Measured memory_bytes: 5760
nums = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]
N, M = map(int, input().split())
A = list(map(int, input().split()))

# 使うマッチ棒の本数が等しい場合は大きい数だけ考えれば良い
A.sort(reverse=True)
s = set()
candidates = [] # [a, nums[a]]
for a in A:
  if nums[a] in s:
    continue
  s.add(nums[a])
  candidates.append([a, nums[a]])


dp = [-1] * (N+1)
dp[0] = 0
for i in range(N+1):
  for a, n in candidates:
    if i >= n and dp[i-n]>=0:
      dp[i] = max(dp[i], dp[i-n]+1)

ans = ''
idx = N
digit = dp[N]
while digit:
  for a, n in candidates:
    if idx - n >= 0 and dp[idx-n] == dp[idx]-1:
      ans += str(a)
      digit -= 1
      idx -= n
      break

print(int(ans))

Measured memory_bytes: 3420
# include <bits/stdc++.h>
# define INF 1e9 + 1
using namespace std;

int main(){

  long int N, M, L;
  cin >> N >> M >> L;
  long int d[N][N];
  for(int i=0; i<N; i++) for(int j=0; j<N; j++) d[i][j] = INF;
  for(int i=0; i<N; i++) d[i][i] = 0;
  for(int i=0; i<M; i++){
    long int a, b, c;
    cin >> a >> b >> c;
    if (c <= L){
      d[a-1][b-1] = c;
      d[b-1][a-1] = c;
    }
  }

  for(int k=0; k<N; k++){
    for(int i=0; i<N; i++){
      for(int j=0; j<N; j++){
        long int v = d[i][k]+d[k][j];
        d[i][j] = min(d[i][j], v);
      }
    }
  }

  int gas[N][N];
  for(int i=0; i<N; i++) for(int j=0; j<N; j++) gas[i][j] = -1;
  for(int i=0; i<N; i++){
    vector<int> cur = {i};
    int cnt = 0;
    gas[i][i] = cnt;
    while(cur.size() > 0){
      vector<int> temp = {};
      for(int j=0; j<cur.size(); j++){
        for(int k=0; k<N; k++){
          if(d[cur[j]][k]<= L && gas[i][k] == -1){
            gas[i][k] = cnt;
            temp.push_back(k);
          }
        }
      }
      cur = temp;
      cnt++;
    }
  }

  // for(int i=0; i<N; i++){
  //   for(int j=0; j<N; j++){
  //     cout << gas[i][j] << endl;
  //   }
  // }

  int Q;
  cin >> Q;
  for(int i=0; i<Q; i++){
    int s, t;
    cin >> s >> t;
    cout << gas[s-1][t-1] << endl;
  }

}

Measured memory_bytes: 1536
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>

using namespace std;

void solve()
{
	int D, E;
	while (cin >> D >> E, D || E)
	{
		double minv = 1e9;
		for (int i = 0; i <= D; ++i)
		{
			double diff = fabs(double(sqrt(i * i + (D - i) * (D - i)) - E));
			minv = min(minv, diff);
		}
		printf("%.10f\n", minv);
	}
}

int main()
{
	solve();
	return(0);
}

Measured memory_bytes: 1196
import sys
input = sys.stdin.readline

n = int(input())
*a, = map(int, input().split())

from fractions import gcd
from functools import reduce
import numpy as np

new_gcd = np.frompyfunc(gcd, 2, 1)

a = np.array(a)
left = new_gcd.accumulate(a, dtype=np.object).astype(np.int)
right = new_gcd.accumulate(a[::-1], dtype=np.object).astype(np.int)[::-1]
left = np.append([0], left[:-1])
right = np.append(right[1:], 0)

ans = 0
for i in range(n):
    ans = max(ans, gcd(left[i], right[i]))
print(ans)

Measured memory_bytes: 19644
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define INF (1LL<<50)
#define MOD 1000000007

ll popcount2(ll x) {  
    ll ret = 0;  
    while (x) {  
        x &= x-1;  
        ++ret;  
    }  
    return ret;  
} 

int main(){
    int N;
    cin >> N;
    string S;
    cin >> S;
    ll cnt = 0;
    for(int i=0;i<N;i++){
        if(S[i]=='1') cnt++;
    }
    if(cnt==0){
        rep(i,N) cout << 1 << endl;
        return 0;
    }
    vector<ll> amari_p(N),amari_m(N);
    ll num_p=1;
    ll num_m=1;
    ll cntp = cnt+1;
    ll cntm = cnt-1;
    for(int i=0;i<N;i++){
        amari_p[i] = num_p%cntp;
        num_p = (num_p%cntp)*2;
        if(cntm<=0) continue;
        amari_m[i] = num_m%cntm;
        num_m = (num_m%cntm)*2;
    }
    reverse(amari_p.begin(),amari_p.end());
    reverse(amari_m.begin(),amari_m.end());
    // rep(i,N) cout << amari_p[i] << "-" << amari_m[i] << endl;
    // 元の数を割った余りを出しておく
    ll ori_p,ori_m;
    ll tmp_p=0,tmp_m=0;
    rep(i,N){
        if(S[i]=='1'){
            tmp_p += amari_p[i];
            tmp_m += amari_m[i];
            tmp_p%=cntp;
            if(cntm<=0) continue;
            tmp_m%=cntm;
        }
    }
    ori_p = tmp_p;
    ori_m = tmp_m;
    //cout << ori_p << "--" << ori_m << endl;
    
    for(int i=0;i<N;i++){
        ll ans = 0;
        string G = S;
        ll cnt2 = cnt;
        ll num;
        ll t_p = ori_p;
        ll t_m = ori_m;
        if(G[i]=='0'){
            t_p += amari_p[i];
            t_p %= cntp;
            num = t_p;
            ans++;
        }else{
            if(cnt==1){
                cout << 0 << endl;
                continue;
            }
            t_m -= amari_m[i];
            t_m += cntm;
            t_m %= cntm;
            num = t_m;
            ans++;
        }
        cnt2 = popcount2(num);
        while(num>0){
            num=num%cnt2;
            cnt2 = popcount2(num);
            ans++;
        }
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 6864
def main():
	N, M = [int(n) for n in input().split(" ")]
	lights_def = [[0] * (N + 1) for i in range(M)]
	# lights_def[i] = List, i-th light (i = 0 ~ M)
	# lights_def[i][j] = 1 / 0, j-th switch is related (j = 1 ~ N)
	for i in range(M):
		tmp = [int(t) for t in input().split(" ")]
		for j in tmp[1:]:
			lights_def[i][j] = 1
	p = [int(x) for x in input().split(" ")]
	for i in range(len(p)):
		lights_def[i][0] = p[i]

	cnt = 0
	for i in range(2 ** N):
		switch_bit = list(pad_zero(format(i, 'b'), N))
		for j in range(len(lights_def)):
			light = lights_def[j]
			if sum([light[k + 1] for k in range(len(switch_bit)) if switch_bit[k] == "1"]) % 2 != light[0]:
				break
		else:
			cnt += 1

	print(cnt)

def pad_zero(s, n):
	s = str(s)
	return (("0" * n) + s)[-n:]

main()

Measured memory_bytes: 9200
#include <iostream>
#include <complex>
#include <cstdio>
#include <utility>
#include <vector>
using namespace std;
typedef complex<double> P;
typedef pair<P,P> L;
typedef pair<P,double> C;
typedef vector<P> Poly;
#define X real()
#define Y imag()
#define EPS (1e-10)
#define INF (1e15)

//2D version
namespace std{
  bool operator < (const P& a, const P& b){
    return a.X != b.X ? a.X < b.X : a.Y < b.Y;
  }
  bool cmp_y(const P &a, const P &b){
    return a.Y != b.Y ? a.Y < b.Y : a.X < b.X;
  }
  bool operator == (const P& a, const P& b){
    return abs(a-b) < EPS;
  }
}

double dot(P a, P b){
  return a.X * b.X + a.Y * b.Y;
}
double cross(P a, P b){
  return a.X * b.Y - a.Y * b.X;
}

int ccw(P a, P b, P c) {
  b -= a; c -= a;
  if( cross(b,c) > EPS ) return +1;
  if( cross(b,c) < -EPS ) return -1;
  if( dot(b,c) < 0 ) return +2;
  if( abs(b) + EPS < abs(c) ) return -2;
  return 0;
}

P intersection(L a, L b){
  //直線aと直線bの交点
  return a.first + cross(b.second-b.first,a.first-b.first)/(-cross(b.second-b.first,a.second-b.first)+cross(b.second-b.first,a.first-b.first))*(a.second-a.first);
}

Poly convex_cut(Poly p, L l){
  Poly ret;
  int n = p.size();
  for(int i = 0; i < n; ++i){
    if(ccw(l.first, l.second, p[i]) != -1) ret.push_back(p[i]);
    if(ccw(l.first, l.second, p[i]) != -1 ^ ccw(l.first, l.second, p[(i+1)%n]) != -1) ret.push_back(intersection(L(p[i], p[(i+1)%n]), l));
  }
  return ret;
}

double area(Poly p){
  double ret = 0;
  int n = p.size();
  for(int i = 0; i < n; ++i){
    ret += cross(p[i], p[(i+1)%n])/2;
  }
  return ret;
}

int main(){
  int N, M;
  while(cin >> N >> M, N||M){
    Poly I;
    for(int i = 0; i < N; ++i){
      double x, y;
      cin >> x >> y;
      I.push_back(P(x,y));
    }
    Poly p;
    for(int j = 0; j < M; ++j){
      double x, y;
      cin >> x >> y;
      p.push_back(P(x,y));
    }
    for(int i = 0; i < M; ++i){
      Poly q = I;
      for(int j = 0; j < M; ++j){
        if(i == j) continue;
        L bisector = L((p[i]+p[j])/2.0, (p[i]+p[j])/2.0 + (p[j]-p[i])*P(0,1));
        q = convex_cut(q, bisector);
      }
      printf("%.12lf\n", area(q));
    }
  }
  return 0;
}



Measured memory_bytes: 3280
#include<iostream>
#include<string>

using namespace std;

typedef long long ll;

ll N;

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

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

	int ans = 0;
	for (int i = 1; i <= K; i++) {
		for (int j = 1; j <= K; j++) {
			for (int k = 1; k <= K; k++) {
				int tmp = gcd(i, j);
				tmp = gcd(tmp, k);
				ans += tmp;
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3632
IDENTIFICATION DIVISION.
PROGRAM-ID. PROGRAM_ID.

DATA DIVISION.
WORKING-STORAGE SECTION.
01 ln             PIC X(43).
01 A              PIC 9(10).
01 B              PIC 9(10).
01 C              PIC 9(10).
01 K              PIC 9(10).
01 ans            PIC S9(10).
01 zs             PIC Z(9)9.

PROCEDURE DIVISION.
  ACCEPT ln.
  UNSTRING ln DELIMITED BY SPACE INTO A B C K.
  IF K <= A
      COMPUTE ans = K
  ELSE
      IF K <= A + B
          COMPUTE ans = A
      ELSE
          COMPUTE ans = A - (K - A - B)
      END-IF
  END-IF.
  MOVE ans TO zs.
  IF ZERO <= ans 
      DISPLAY FUNCTION TRIM(zs)
  ELSE
      DISPLAY "-" FUNCTION TRIM(zs)
  END-IF.
  STOP RUN.


Measured memory_bytes: 3900
import java.io.*;
import java.util.*;
public class Main
{
	final long mod=(long)(1e9+7);
	private void solve()throws IOException
	{
		int n=nextInt();
		int a[]=new int[n];
		for(int i=1;i<=n;i++)
			a[nextInt()]++;
		long ans=1;
		for(int i=n-1;i>=1;i-=2)
		{
			if(a[i]!=2)
			{
				out.println(0);
				return;
			}
			ans=(ans*2)%mod;
		}
		out.println(ans);
	}

	 
	///////////////////////////////////////////////////////////

	public void run()throws IOException
	{
		br=new BufferedReader(new InputStreamReader(System.in));
		st=null;
		out=new PrintWriter(System.out);

		solve();
		
		br.close();
		out.close();
	}
	public static void main(String args[])throws IOException{
		new Main().run();
	}
	BufferedReader br;
	StringTokenizer st;
	PrintWriter out;
	String nextToken()throws IOException{
		while(st==null || !st.hasMoreTokens())
		st=new StringTokenizer(br.readLine());
		return st.nextToken();
	}
	String nextLine()throws IOException{
		return br.readLine();
	}
	int nextInt()throws IOException{
		return Integer.parseInt(nextToken());
	}
	long nextLong()throws IOException{
		return Long.parseLong(nextToken());
	}
	double nextDouble()throws IOException{
		return Double.parseDouble(nextToken());
	}
}

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

using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
const int N = 310;
const ll inf = 1e15;
ll f[N][N];int n, k, h[N];
void mnm(ll &a, ll b) { a = min(a, b); }
int aug(int l, int r) {
	if (l >= r) return 0;
	return r - l;
}
int main() {
	//Read
	cin >> n >> k; for (int i = 1; i <= n; ++i) cin >> h[i];
	h[0] = h[n + 1] = 0;
	//Algo
	for (int i = 0; i <= n+1; ++i)
		fill(f[i] + 0, f[i] + k + 1, inf);
	f[0][0] = 0;
	for (int i=0; i<=n; ++i)
		for (int j=0; j<=k; ++j)
			if (f[i][j] < inf) {
				//mnm(f[i + 1][j], f[i][j] + aug(h[i], h[i + 1]));
				for (int bian = 0; i + bian + 1 <= n + 1 && j + bian <= k; ++bian) {
					mnm(f[i + bian + 1][j+bian], f[i][j] + aug(h[i], h[i + bian + 1]));
				}
			}
	ll ans = inf;
	for (int j = 0; j <= k; ++j)
		mnm(ans, f[n + 1][j]);
	cout << ans << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define fastIO                        \
	ios_base::sync_with_stdio(false); \
	cin.tie(NULL);                    \
	cout.tie(NULL);
// g++ -std=c++11 -O2 -Wall *.cpp -o *
#define eps 1e-9
#define MAX 1e12 + 10
#define MOD 1000000007
#define PI 3.14159265358979323846
#define Fi first
#define Se second
#define PB push_back
#define MP make_pair
#define all(a) a.begin(), a.end()
#define maxof(a) *max_element(all(a))
#define rep(i, n) for (i = 0; i < n; ++i)
#define REP(i, k, n) for (i = k; i < n; ++i)
#define REPR(i, k, n) for (i = k; i > n; --i)
typedef long long ll;
typedef pair<int, int> pr_int;


int main()
{
	// freopen("input.txt", "r", stdin);
	// freopen("output.out", "w", stdout);
	// fastIO

	int a;
	cin >> a;
	cout << a + a * a + a * a * a;

	printf("\n");
}


Measured memory_bytes: 3564
#include<bits/stdc++.h>
using namespace std;
int64_t dp[2005][2005];
static const int64_t mod=998244353;
int64_t f(int64_t x,int64_t y){
if(y==0)
  return 1;
  else if(y%2==0)
    return (f(x,y/2)*f(x,y/2))%mod;
  else
    return (x*((f(x,y/2)*f(x,y/2))%mod))%mod;
}
int main(){
 string s;cin>>s;int N=s.size();
  vector<int64_t>A(N);
  for(int i=0;i<N;i++){
    int64_t a=s.at(i)-'0';
    A.at(i)=a;
  }dp[0][0]=1;
  for(int i=1;i<=N;i++)
    for(int j=0;j<=i;j++){
    int64_t d=0;int64_t a=A.at(i-1);
      if(0<=j-a)
        d+=dp[i-1][j-a];
      if(0<=j-a+1)
        d+=dp[i-1][j-a+1];
      dp[i][j]=d%mod;
    }int64_t ans=0;int64_t com=1;
  for(int j=0;j<=N+1;j++){
  ans=(ans+dp[N][j]*com)%mod;
    com=(com*(N-j))%mod;
    com=(com*f(j+1,mod-2))%mod;
  }cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 26268
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A,B;
  int Sum=0;
  cin>>A>>B;
  for(int i=A;i<=B;i++){
    int a;
    a=i%10;
    if(i/10000==a&&(i-10000*a)/1000==((i-a)%100)/10)
      Sum++;
  }
  cout<<Sum<<endl;
}

Measured memory_bytes: 256
N,M=map(int,input().split())
mylist=[]
for i in range(N):
    A,B=map(int,input().split())
    temp=[A,B]
    mylist.append(temp)
    
#print(mylist)

mylist.sort()
#print(mylist)

drink_sum=0
i=0
fee=0
while drink_sum<M and i<=N-1:
    if drink_sum+mylist[i][1]>=M:
        #print("/////")
        #print(drink_sum)
        #print(mylist[i][0]*(M-drink_sum))
        fee+=mylist[i][0]*(M-drink_sum)
        drink_sum+=M-drink_sum
        #print("before")
        #print(drink_sum)
    else:
        fee+=mylist[i][0]*mylist[i][1]
        drink_sum+=mylist[i][1]
        #print("test")
        #print(drink_sum)
        
    i+=1
    
print(fee)

Measured memory_bytes: 20072
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <climits>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <complex>

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

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

	int n, k;
	cin >> n >> k;
	string s1;
	cin >> s1;
	string s2 = s1;
	int kk = k;
	bool check = false;
	for (int i = 0; i < n; i++) {
		if (s1[i] == 'R') {
			if (kk == 0) break;
			check = false;
		}
		else {
			if (!check) {
				kk -= 1;
				check = true;
			}
			s1[i] = 'R';
		}
	}
	kk = k;
	check = false;
	for (int i = 0; i < n; i++) {
		if (s2[i] == 'L') {
			if (kk == 0) break;
			check = false;
		}
		else {
			if (!check) {
				kk -= 1;
				check = true;
			}
			s2[i] = 'L';
		}
	}

	int ans1 = n;
	int ans2 = n;

	if (s1[0] == 'L') ans1 -= 1;
	if (s1.back() == 'R') ans1 -= 1;
	if (s2[0] == 'L') ans2 -= 1;
	if (s2.back() == 'R') ans2 -= 1;
	for (int i = 0; i < n - 1; i++) {
		if (s1[i] == 'R' && s1[i + 1] == 'L') ans1 -= 2;
		if (s2[i] == 'R' && s2[i + 1] == 'L') ans2 -= 2;
	}
	cout << max(ans1, ans2);

	return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef long long LL;
typedef vector<int> VI;
typedef pair<int,int> PII;
typedef pair<double,double> PDD;
const double eps=1e-6;
const int inf=0x3f3f3f3f;
const double pi=acos(-1.0);
const int mod=1e9+7;
//LL powmod(LL a,LL b) {LL res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
int p[200010],v[200010],c[200010],a[200010];
VI g[200010],e[200010];
int dfs(int x){
    for(auto i:g[x]){
        if(c[i]) continue;
        e[x].pb(dfs(i));
    }
    sort(all(e[x]));
    a[x]=-1;
    for(auto i:e[x]){
        if(i>a[x]+1) break;
        a[x]=i;
    }
    return ++a[x];
}
int main(){
//    freopen("out.txt","r",stdin);
//    freopen("outt.txt","w",stdout);
    int n;
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>p[i];
        g[p[i]].pb(i);
    }
    int r=1;
    while(!v[r]){
        v[r]=1;
        r=p[r];
    }
    while(!c[r]){
        c[r]=1;
        r=p[r];
    }
    for(int i=1;i<=n;i++){
        if(c[i]) dfs(i);
    }
    int f=0,cnt=0;
    while(c[r]){
        c[r]=0;
        if(a[r]!=a[p[r]]) f=1;
        r=p[r];
        cnt++;
    }
    puts((f||cnt%2==0)?"POSSIBLE" : "IMPOSSIBLE");
    return 0;
}


Measured memory_bytes: 18816
#include<bits/stdc++.h>
using namespace std;
#define N 300005
#define pii pair<int,int>
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define ll long long 
#define mod 1000000007
#define barn cin.sync_with_stdio(0);cin.tie(0)
int a[N];
int main()
{
  barn;
  //freopen("inputf.in","r",stdin);
  //freopen("outputf.in","w",stdout);
  int n,i,l;
  ll ans=0;
  cin>>n;
  for(i=1;i<=3*n;i++)
    cin>>a[i];
  sort(a+1,a+3*n+1);
  l=3*n-1;
  for(i=1;i<=n;i++)
  {
    ans+=a[l];
    l-=2;
  }
  cout<<ans<<"\n";
  return 0;
}

Measured memory_bytes: 1408
import sys
from collections import deque
input = sys.stdin.readline

s = deque(input().strip())
q=int(input())
count = 0
for i in range(q):
    L = list(input().rstrip().split())    
    if L[0]=='1':
        count += 1
    else:
        a,b,c = L
        b = int(b)
        if count&1==1:
            b=3-b
        if b==2:
            s.append(c)
        else:
            s.appendleft(c)
if count&1==1:
    print("".join(list(s)[::-1])) 
else:
    print("".join(s))

            
            



Measured memory_bytes: 95468
import java.util.*;
import static java.lang.Math.*;
import java.math.BigInteger;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		// 入力
		int h = sc.nextInt();
		int w = sc.nextInt();
		String[] s = new String[h];
		for(int i = 0; i < h; i++){
		    s[i] = sc.next();
		}
		// 計算
		int result = 0;
		int[][] l = new int[h][w];
		int[][] r = new int[h][w];
		int[][] u = new int[h][w];
		int[][] d = new int[h][w];
		for(int i = 0; i < h; i++){
		    for(int j = 0; j < w; j++){
		        if(s[i].charAt(j) == '.'){
		            if(i == 0){
		                u[i][j] = 1;
		            }else{
		                u[i][j] = u[i-1][j] + 1;
		            }
		            if(j == 0){
		                l[i][j] = 1;
		            }else{
		                l[i][j] = l[i][j-1] + 1;
		            }
		        }
		    }
		}
		for(int i = h - 1; i >= 0; i--){
		    for(int j = w - 1; j >= 0; j--){
		        if(s[i].charAt(j) == '.'){
		            if(i == h - 1){
		                d[i][j] = 1;
		            }else{
		                d[i][j] = d[i+1][j] + 1;
		            }
		            if(j == w - 1){
		                r[i][j] = 1;
		            }else{
		                r[i][j] = r[i][j+1] + 1;
		            }
		        }
		    }
		}
		for(int i = 0; i < h; i++){
		    for(int j = 0; j < w; j++){
		        int temp = u[i][j] + d[i][j] + l[i][j] + r[i][j] - 3;
		        result = max(result, temp);
		    }
		}
		// 出力
		System.out.println(result);
		
	}
}


Measured memory_bytes: 118548
#include <algorithm>
#define _USE_MATH_DEFINES
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include<list>
#include<map>
#include<utility>
#include<tuple>
#include<numeric>
#include<set>
#include<limits>
#include<type_traits>

#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(a) (a).begin(),a.end()
using namespace std;

int gcd(int a, int b) {
	if (a < b)gcd(b, a);
	int r;
	while ((r = a % b)) {
		a = b;
		b = r;
	}
	return b;
}

int main() {
	string s;

	long long int k;
	cin >> s >> k;

	for (int i = 0;i < k;i++) {
		if (s[i] != '1') { cout << s[i] << endl;return 0; }
	}
	cout << '1'<< endl;
}

Measured memory_bytes: 256
n=int(input())
a=list(map(int,input().split()))
a.sort(reverse=True)

tmp1=a[0]
for i in range(n-1):
    l,s= 0,0
    if tmp1 == a[i+1]:
        idx = i+1
        l = tmp1 #lを確定させる
        #break
        tmp2=a[idx+1]
        for j in range(idx+1,n-1):
            if tmp2==a[j+1]:
                s = tmp2
                print(l*s)
                exit()
            else:
                tmp2 = a[j+1]
    else:
        idx=i
        tmp1=a[i+1]
        
print(0)

Measured memory_bytes: 62704
#include<bits/stdc++.h>
using namespace std;
auto ____ = [] () {ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); };
int a,b;
int main(){
    ____();
    cin >> a >> b;
    cout << max(a-b-b,0) << endl; 
    return 0;
}

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

using namespace std;

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

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

ll calc(ll n) {
    ll m = n;
    ll b = 0;
    while (n > 0) {
        ll p = 1LL;
        while (p * 2LL <= n) {
            p <<= 1LL;
        }
        n = n & (~p);
        if (n % 2 == 0)
            b |= p;
    }
    if ((m - 2) > 0 && (m - 2) % 4 == 0)
        b++;
    if ((m + 1) % 4 == 0)
        b--;
    return b;
}

int main() {
    ll A, B;
    cin >> A >> B;
    if (A == 0)
        cout << calc(B) << endl;
    else
        cout << (calc(B) ^ calc(A - 1)) << endl;
    return 0;
}


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

int main() {

    int N;
    cin >> N;
    vector<int> numbers(N);
    int max_number = 0;
    int max_index = 0;
    int n;
    for(int i=0;i<N;i++){
        cin >> numbers.at(i);
        if(max_number < numbers.at(i)){
            max_number = numbers.at(i);
            max_index = i;
        }
    }
    for(int i=0;i<N;i++){
        if(i == max_index){
            int m = 0;
            int m_index = 0;
            for(int j=0;j<N;j++){
                if(i==j){
                    continue;
                }
                if(m < numbers.at(j)){
                    m = numbers.at(j);
                    m_index = j;
                }
            }
            cout << m << endl;
        }else{
            cout << max_number << endl;
        }
    }
}

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

//宣言
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;

//数値
#define MOD 1000000007
#define INF (1<<20)
const double EPS = 1e-10;
const double PI = acos(-1.0);

//操作
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define REP(i,n) FOR(i,0,n)
#define REPB(i,n) for(int i=n;i>=0;i--)
#define SORT(A) sort(A,A+sizeof(A)/sizeof(A[0]))
#define VSORT(A) sort(A.begin(),A.end())
#define EXIST(s,e) (s.find(e)!=s.end())
#define PB push_back
#define MP make_pair

//DEBUG
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

int main() {
	int n, k;
	cin >> n >>k;
	int a[200001] = { 0 };
	int b[200001] = { 0 };
	int tmp;
	REP(i, n) {
		cin >> tmp;
		a[tmp]=1;
		b[tmp]++;
	}
	int sum = 0;
	REP(i, 200000) {
		sum += a[i];
		if (b[i] == 0) b[i] = 200001;
	}

	sort(b,b+200000);

	if (sum <= k) 
	{ cout << 0 << endl; 
	}else {
		int ans = 0;
		for (int i = 0;i < sum - k;i++) ans += b[i];
		cout << ans << endl;
	}

}


Measured memory_bytes: 1792
#include <iostream>
#include <cstring>
#include <cmath>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <set>
#include <map>
#include <iterator>
#include <stack>
#include <string.h>
#include <cstdlib>
#include <queue>
#include <list>

using namespace std;

int main()
{
    int  n;
    string s;
    long long a[3] = {0};
    
    cin >> n;
    cin >> s;
    
    for (int i = 0;i < n;i++){
        if (s[i] == 'R'){
            a[0]++;
        }
        else if (s[i] == 'G'){
            a[1]++;
        }
        else {
            a[2]++;
        }
    }
    
    long long sum = 0;
    for (int i = 0;i <= n-3;i++){
        for (int j = i+1;2*j-i < n;j++){
            if (s[i] != s[j] && s[j] != s[2*j-i] && s[2*j-i] != s[i]){
                sum++;
            }
        }
    }
    
    if (s[0] == 0 || s[1] == 0 || s[2] == 0){
        cout << "0" << endl;
    }
    else {
        cout << a[0]*a[1]*a[2]-sum << endl;
    }
}


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

int main() {
	int n;
	cin >> n;
	cout << n/3 << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bits/stdc++.h>
#include<iostream>
#include<string>
using namespace std;
#define rep(i, n) for (int i = 0; i <(int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define ll long long
const ll MOD=100000007;
const ll INF=1000000101001;
int main(){
int n;cin>>n;
cout << n*n*n << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define LL long long
#define INF 0x3f3f3f3f
using namespace std;

template<class T> inline
void read(T& x) {
	int f = 1; x = 0;
	char ch = getchar();
	while (ch < '0' || ch > '9')   {if (ch == '-') f = -1; ch = getchar();}
	while (ch >= '0' && ch <= '9') {x = x * 10 + ch - '0'; ch = getchar();}
	x *= f;
}

/*============ Header Template ============*/

const int N = 1000000 + 5;
const int mo = 1000000007;

LL n, m, q;
LL f[N], s[N];

int main() {
	read(n);
	f[0] = 1;
	f[1] = n;
	f[2] = n * n % mo;
	s[0] = 1;
	s[1] = s[0] + f[1];
	s[2] = s[1] + f[2];
	for (int i = 3; i <= n; i++) {
		f[i] = s[i - 1] - f[i - 2];
		(f[i] += (n - 1) * (n - 1) % mo) %= mo;
		(f[i] += n - (i - 1)) %= mo;
		s[i] = (s[i - 1] + f[i]) % mo;
	}
	// for (int i = 1; i <= n; i++) printf("f[%d] = %lld\n", i, f[i]);
	printf("%lld\n", (f[n] + mo) % mo);
	return 0;
}

Measured memory_bytes: 15872
#include <iostream>
#include <iomanip>
#include <string>
#include <string.h>
#include <math.h>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <algorithm>
#include <utility>
#include <deque>
#include <queue>

#define rep(i, n) for(int i = 0; i < n; ++i)
#define REP(i, m, n) for(int i = m; i < n; ++i)
#define rrep(i,n) for(int i = n; i >= 0; --i)
#define RREP(i, m, n) for(int i = n; i >= m; --i)
#define llrep(i, n) for(ll i = 0; i < n; ++i)
#define llREP(i, m, n) for(ll i = m; i < n; ++i)
#define llrrep(i,n) for(ll i = n; i >= 0; --i)
#define llRREP(i, m, n) for(ll i = n; i >= m; --i)

using ll = long long;
using ull = unsigned long long;
using pii = std::pair<int, int>;
using pll = std::pair<long long, long long>;

using namespace std;

const long long _MOD = 1000000007;
const long long MOD = 998244353;

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

	int n, k, c;
	string s;
	cin >> n >> k >> c >> s;

	deque<int> que_front, que_back;
	rep(i, n) {
		if (s[i] != 'x') {
			if (que_front.empty()) que_front.push_back(i);
			else if (que_front.back() + c < i) que_front.push_back(i);
		}

		if (s[n - 1 - i] != 'x') {
			if (que_back.empty()) que_back.push_front(n - 1 - i);
			else if (que_back.front() - c > (n-1-i)) que_back.push_front(n - 1 - i);
		}
	}

	if (que_front.size() != que_back.size() || que_front.size() > k) {
		return 0;
	}
	else {
		auto p = que_front.begin();
		auto q = que_back.begin();

		while (!que_front.empty()) {
			if (que_front.front() == que_back.front()) cout << que_front.front() + 1 << "\n";

			que_front.pop_front();
			que_back.pop_front();
		}
	}

	return 0;
}


Measured memory_bytes: 3348
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <iterator>
#include <cmath>

using namespace std;

int cnt[26];

int main()
{
    //freopen("in", "r", stdin);
    //freopen("out", "w", stdout);

    int n, m, i;
    scanf("%d%d", &n, &m);
    for(i = 0; i < n*m; i++)
    {
        char c;
        scanf(" %c", &c);
        cnt[c - 'a']++;
    }

    int x = 0, y = 0;
    for(i = 0; i < 26; i++)
    {
        if(cnt[i] % 2 == 1)
        {
            y++;
            cnt[i]--;
        }

        if(cnt[i] % 4 == 2)
            x++;
    }

    if(n % 2 == 1 && m % 2 == 1)
    {
        if(y != 1 || x > n / 2 + m / 2)
            printf("No\n");
        else
            printf("Yes\n");
        return 0;
    }

    if(y > 0 || n % 2 == 1 && x > m / 2 || m % 2 == 1 && x > n / 2 || n % 2 == 0 && m % 2 == 0 && x > 0)
        printf("No\n");
    else
        printf("Yes\n");
    return 0;
}

Measured memory_bytes: 256
y = [True for i in range(250001)]
y[0] = y[1] = False
for i in range(2, 500):
    if y[i]:
        for j in range(2, 250000 // i + 1):
            y[i * j] = False
while True:
    n = int(input())
    if n == 0:
        break
    print(y[n + 1 : n * 2 + 1].count(True))


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

int main(){
 while(1){
 int H, W;
 cin >> H >> W;
 if(H == 0 && W == 0) break;

 for(int j = 0; j < W; j ++){
      cout << "#";
    }
 cout << endl;

 for ( int i = 1; i < H-1; i++ ){
    for ( int j = 0; j < W; j++ ){
        if(j == 0 || j == W-1){
            cout << "#";
        } else {
            cout << ".";
        }
    }
   
    cout << endl;
  }
 for(int j = 0; j < W; j ++){
      cout << "#";
    }
 cout << endl;
 cout << endl;
 }
return 0;
} 


Measured memory_bytes: 3080
//Bismillahir Rahmanir Rahim
#include <bits/stdc++.h>
using namespace std;

typedef long long              ll;
typedef long double            ld;
typedef pair<int, int>         pi;
typedef vector<int>            vi;
typedef vector<pair<int, int>> vpi;

#define pb       push_back
#define all(x)   begin(x), end(x)
#define sz(x)    (int)(x).size()
#define ff       first
#define ss       second
#define mp       make_pair
#define lb       lower_bound
#define ub       upper_bound
#define tcase()  int t; cin >> t; while(t--)

const int MOD = 1e9 + 7; // 998244353;
const int MX  = 2e5 + 5;
const ll  INF = 1e18;
const ld  PI  = acos((ld) -1);

void setIO(string name = "") {
    ios_base::sync_with_stdio(0); cin.tie(0);
    if(sz(name)){
        freopen((name+".in").c_str(), "r", stdin);
        freopen((name+".out").c_str(), "w", stdout);
    }
}

int main(){

    setIO();

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

    vector<ll> arr(n);
    vector<ll> brr(m);

    ll sum = 0, best = 0, curr;

    bool got = true;

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

        if(i) arr[i] += arr[i - 1];

        if(arr[i] > k && got) best = i, got = false;
        else if(arr[i] == k) best = i + 1;
    }

    for(int i = 0; i < m; i++){
        cin >> brr[i];

        sum += brr[i];

        if(sum > k) break;

        auto it = ub(all(arr), k - sum);

        curr = it - arr.begin();

        best = max(best, curr + i + 1);
    }

    cout << best;
}


Measured memory_bytes: 6348
#include <bits/stdc++.h>
#define DEBUG fprintf(stderr, "Passing [%s] line %d\n", __FUNCTION__, __LINE__)

using namespace std;

typedef long long LL;
typedef pair <int, int> PII;
typedef pair <int, PII> PIII;

inline int gi()
{
	int f = 1, x = 0; char c = getchar();
	while (c < '0' || c > '9') {if (c == '-') f = -1; c = getchar();}
	while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return f * x;
}

inline LL gl()
{
	LL f = 1, x = 0; char c = getchar();
	while (c < '0' || c > '9') {if (c == '-') f = -1; c = getchar();}
	while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return f * x;
}

int n, m, a, b;
LL ans;

const int mod = 1000000007;

inline LL qpow(LL a, LL b)
{
	LL res = 1;
	while (b)
	{
		if (b & 1) res = (res * a) % mod;
		a = a * a % mod, b >>= 1;
	}
	return res % mod;
}

LL work(int x)
{
    LL s,c;
    s=c=1;
    for(int i=1;i<=x;i+=1)s=(s*i)%mod;
    for(int i=n-x+1;i<=n;i++)c=(c*i)%mod;
    return (c*qpow(s,mod-2))%mod;
}

int main()
{
	//freopen(".in", "r", stdin);
	//freopen(".out", "w", stdout);
	cin >> n >> a >> b;
	ans = (((qpow(2, n) - 1) % mod - work(a) % mod - work(b) % mod) % mod + mod) % mod;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 998244353;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-11;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
typedef pair<ld, ld> LDP;
typedef unsigned long long ul;
int n, m;
int c[1 << 17];
vector<int> G[1 << 17];
int ans[1 << 17];
int main() {
	cin >> n >> m;
	rep(i, n-1 + m) {
		int a, b; cin >> a >> b; a--; b--;
		c[b]++;
		G[a].push_back(b);
	}
	queue<int> q;
	rep(i, n) {
		if (c[i] == 0) {
			ans[i] = 0;
			q.push(i);
		}
	}
	while (!q.empty()) {
		int v = q.front(); q.pop();
		rep(j, G[v].size()) {
			int to = G[v][j];
			c[to]--;
			if (c[to] == 0) {
				ans[to] = v + 1;
				q.push(to);
			}
		}
	}
	rep(i, n) {
		cout << ans[i] << endl;
	}
	//stop
	return 0;
}


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

int main(){
  int a,b,c,x,y; cin>>a >>b >>c >>x >>y;
  int ans=INT_MAX;
  for(int i=0;i<=100000;i++){
    int money=i*2*c+max(0,x-i)*a+max(0,y-i)*b;
    ans=min(ans,money);
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
/*
 * author :Sadik Hassan(_sad_)
 *
*/
#include "bits/stdc++.h"
using namespace std;
using   ll       =    long long;
using   ld       =    long double;
#define nl            "\n"
#define pb            push_back
#define fi            first
#define se            second
#define MP            make_pair
#define PI            (acos(-1.0))
#define rep1(i,n)     for(int i=1;i<=n;i++)
#define rep(i,n)      for(int i=0;i<n;i++)
#define SZ(s)         (int)s.size()
#define all(x)        (x).begin(), (x).end()
#define rall(x)       (x).rbegin(), (x).rend()
#define w(t)          int t;cin>>t;while(t--)
#define TSU(s)        transform(s.begin(),s.end(),s.begin(),::toupper);
#define TSL(s)        transform(s.begin(),s.end(),s.begin(),::tolower);
#define _SAD()     	  ios::sync_with_stdio(0),cin.tie(0),cout.tie(0),cout<<fixed<<setprecision(15);

typedef vector<int> vi;
typedef vector<ll> vii;
typedef set<int> si;
typedef set<ll> sii;
/*---------------------------------------------------------------------*/

const int N = (int)1e6+1;
const int MOD =(int)1e9+7;
const ll INF = (ll)1e18+5;

int main()
{
    _SAD()
    int n;
    cin>>n;
    vii a(5,0);
    while(n--)
    {
        string s;
        cin>>s;
        if(s=="AC")a[0]++;
        else if(s=="WA")a[1]++;
        else if(s=="TLE")a[2]++;
        else if(s=="RE")a[3]++;
    }
    cout<<"AC x "<<a[0]<<nl;
    cout<<"WA x "<<a[1]<<nl;
    cout<<"TLE x "<<a[2]<<nl;
    cout<<"RE x "<<a[3]<<nl;
    return 0;
}


Measured memory_bytes: 3640