akhauriyash/Code-Regression huggingface dataset:
N, K = map(int, input().split())
if K %2 == 0:
    c = 0 #(純粋な倍数)
    d = 0 #(二倍すれば倍数)
    for i in range(1,N +1):
        if i %K == 0:
            c+=1
        elif (i*2) %K ==0:
            d +=1
    print(c ** 3 + d ** 3)
else:
    l = N // K
    print(l ** 3)


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

#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define read()          freopen("in.txt","r",stdin)
#define write()         freopen("out.txt","w",stdout)
#define sf(n)           scanf("%d",&n)
#define sfd(n)          scanf("%lf",&n)
#define sl(x)           scanf("%I64d",&x)
#define sfl(n)          scanf("%lld", &n)
#define sfc(n)          scanf(" %c",&n)
#define sful(n)         scanf("%llu",&n)
#define ull             unsigned long long
#define endll           pf("\n")
#define pf              printf
#define PI              acos(-1.0)
#define eps             1e-12
#define mem(a,b)        memset(a,b,sizeof(a))
#define pb              push_back
#define xx              first
#define yy              second
#define pii             pair<int, int>
#define pll             pair<ll, ll>
#define MP make_pair
#define ll              long long
#define uniq(a)      a.erase(unique(a.begin(), a.end()), a.end())
#define cnd tree[idx]
#define lnd tree[idx<<1]
#define rnd tree[(idx<<1)+1]
#define lndp (idx<<1),(b),((b+e)>>1)
#define rndp ((idx<<1)+1),(((b+e)>>1)+1),(e)
#define inf 1999999999
#define MOD  1000000007
#define mod1 1000000009
#define var    int i,j,c=0,t,l,r,mid,z=0,k,x,y
#define aloc(n,t) ((t*)malloc((n)*sizeof(t)))

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

ll n,m;
int main()
{
    ll a,b;
    sfl(a);sfl(b);sfl(n);
    ll sz = (n)/b;
    ll ans = 0;

    ll x = sz*b+b-1;
    x = min(x,n);
    x = (a*x) / b ;
    x = (x*b)/a + ((x*b)%a!=0);
    x = min(x,n);
    x = (a*x)/b - a*(x/b);
    ans =max(ans,x);

    sz--;
    if(sz<0)sz=0;
    x = sz*b+b-1;
    x = min(x,n);
    x = (a*x) / b ;
    x = (x*b)/a + ((x*b)%a!=0);
    x = min(x,n);
    x = (a*x)/b - a*(x/b);
    ans = max(ans,x);

    x = n;
    x = (a*x) / b ;
    x = (x*b)/a + ((x*b)%a!=0);
    x = min(x,n);
    x = (a*x)/b - a*(x/b);
    ans =max(ans,x);
    ans = max(ans,0LL);


    pf("%lld\n",ans);
}


Measured memory_bytes: 3824
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        // 標準入力からデータを読み込む準備
        Scanner sc = new Scanner(System.in);
        // 最初の文字の固まりを整数値と想定して読み込む
        for (int i = 1;; i++) {
            int x = sc.nextInt();
            // xが0の時を考慮した上で、 Case i: x の形式で出力しよう！
            // ...
            if (x == 0) {
                break;
            } else {
                System.out.println("Case "+i+": "+x);
            }
        }
    }
}


Measured memory_bytes: 41340
#include <bits/stdc++.h>
using namespace std;
#define int long long   // <-----!!!!!!!!!!!!!!!!!!!

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep2(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()

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

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

    int n;
    cin >> n;
    while (n--) {
        int y, m, d;
        cin >> y >> m >> d;
        int ans = 0;
        while (y < 1000) {
            while (m <= 10) {
                int dlim = 20 - (y % 3 != 0 && m % 2 == 0);
                while (d <= dlim) {
                    ans++;
                    d++;
                }
                m++;
                d = 1;
            }
            y++;
            m = 1;
            d = 1;
        }
        cout << ans << endl;
    }

}

Measured memory_bytes: 3136
program diverta_city
  integer :: n, i, j
  integer(8), dimension(10) :: a = (/0,1,2,4,7,12,20,29,38,52/), f = 0
  read(*,*) n
  f(3) = 1
  do i = 4, n
    f(i) = f(i-1)*(a(i-1)+a(i-2)+1)
  end do
  do i = 1, n
    do j = 1, n
      if (i == j) then
        write(*,'(i0,x)',advance='no') 0
        cycle
      end if
      write(*,'(i0,x)',advance='no') f(max(i,j))*a(min(i,j)+1)+1
    end do
    write(*,*)
  end do
end program diverta_city

Measured memory_bytes: 256
MOD = 10 ** 9 + 7
INF = 10 ** 11
import sys
sys.setrecursionlimit(100000000)

n,m,q = map(int,input().split())
cond = [[] for _ in range(n)]
abcd = [tuple(map(int,input().split())) for _ in range(q)]
for a,b,c,d in abcd:
    a -= 1
    b -= 1
    cond[b].append((a,c,d))       

ans = 0
def dfs(i,before,score):
    global ans
    if i == n - 1:
        ans = max(ans,score)
        return
    for num in range(before[i],m + 1):
        point = 0
        for a,c,d in cond[i + 1]:
            if num - before[a] == c:
                point += d
        if point > 0:
            before[i + 1] = num
            dfs(i + 1,before,score + point)
    before[i + 1] = before[i]
    dfs(i + 1,before,score) 

dfs(0,[1] + [-1]*(n - 1),0)
print(ans)  

Measured memory_bytes: 69116
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout<< (x) << " "

int main(){
    int n;cin>>n;
    string s;
    map<string, int> mp;
    int mx = -1;
    rep(i,n){cin>>s;mp[s]++;mx=max(mx,mp[s]);}
    for(auto i = mp.begin();i!=mp.end();i++){
        if(mx == i->second)co(i->first);
    }

}

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

#include <math.h>

int main(){

	int n=0;
	double syakkin = 100000.0;

	cin >> n;


	for (int i = 0; i < n; i++){
		syakkin = syakkin * 1.05;
		if (long(syakkin) % 1000 != 0){
			syakkin = syakkin - double(long(syakkin) % 1000) + 1000.0;
		}
		//cout << syakkin << endl;
	}
	
	cout << long(syakkin) << endl;

	return 0;
}

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

int main()
{
    long int x,y,z,a,b,c;
    cin>>x>>y>>z;
    a=x;
    b=y;
    c=z;
    swap(a,b);
    swap(a,c);
    cout<<a<<" "<<b<<" "<<c;
}




Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define db double
#define pb push_back
#define rep(i,a,b)  for(ll i=a;i<=b;i++)
#define all(a) a.begin(),a.end()
using namespace std;

 ll mod=1e9 +7;
const ll M=500006;
ll f[M],inv[M];
ll expo(ll base,ll exponent){
    ll ans=1;
    while(exponent!=0){
        if(exponent&1) ans=(1LL*ans*base)%mod;
        base=(1LL*base*base)%mod;
        exponent>>=1;
    }
    return ans%mod;
}
void compute(){
    f[0]=1;
    rep(i,1,M-1){
        f[i]=(1LL*i*f[i-1])%mod;
    }
    inv[M-1]=expo(f[M-1],mod-2);
    for(ll i=M-2;i>=0;i--){
        inv[i]=(1LL*(i+1)*inv[i+1])%mod;
    }
}
ll C(ll n,ll r){
    return (1LL*((1LL*f[n]*inv[r])%mod)*inv[n-r])%mod;
}

vector<bool>  prime(1000002,true);
void Sieve() 
{ 
   
    for (int p=2; p*p<=1000001; p++) 
    { 
        // If prime[p] is not changed, then it is a prime 
        if (prime[p] == true) 
        { 
            for (int i=p*p; i<=1000001; i += p) 
                prime[i] = false; 
        } 
    } 
}

ll bit[2000000]={0};
void update(ll id,ll val,ll n)
{
	for(;id<n;id |=id+1)
		bit[id]+=val;
}
ll query(ll id,ll n)
{
	ll res=0;
	for(;id>=0;id=(id & (id+1))-1)
	{
		res+=bit[id];
	}
	return res;
}

int main()
{
	// #ifndef ONLINE_JUDGE
 //    // for getting input from input.txt
    // freopen("alchemy_input.txt", "r", stdin);
 //    // for writing output to output.txt
    // freopen("output.txt", "w", stdout);
 //    #endif
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    // compute();
    ll tests=1,t=1;
   // cin>>tests;
    while(tests--)
    {
    	ll i,j,n,q;
    	cin>>n>>q;
    	vector<ll>c(n);
    	rep(i,0,n-1) cin>>c[i];
    	map<ll,ll>mp;
    	i=0;j=0;
    	vector<pair<ll,ll>>v,v2;
    	while(q--)
    	{
    		set<ll>st;
    		ll l,r;
    		cin>>l>>r;
    		l--;r--;
    		v.pb({r,l});
    	}
    	v2=v;
    	map<pair<ll,ll>,ll>ans;
    	sort(all(v));
    	vector<ll>last_visit(n+1,-1);
    	ll cntr=0;
    	for(i=0;i<n;i++)
    	{
    		if(last_visit[c[i]]!=-1)
    			update(last_visit[c[i]],-1,n);
    		last_visit[c[i]]=i;
    		update(i,1,n);
    		while(cntr<v.size() && v[cntr].first==i)
    		{
    			ll l=v[cntr].second,r=v[cntr].first;
    			ans[{r,l}]=query(r,n)-query(l-1,n);
    			cntr++;
    		}
    	}

    	for(auto x:v2)
    	{
    		cout<<ans[x]<<"\n";
    	}
    }

	return 0;
}

Measured memory_bytes: 62596
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCorder
{
	public class Program
	{
		static void Main(string[] args)
		{
			var cin = new Scanner2();
			int n = cin.Int();
			int m = cin.Int();
			string s = cin.Next();

			Stack<int> steps = new Stack<int>();
			int now = n;
			while (now > 0) {
				bool ok = false;
				for (int i = 0; i < m; i++) {
					int index = now - m + i;
					if (index < 0) {
						index = 0;
					}

					if (s[index] == '0') {
						ok = true;
						steps.Push(now - index);
						now = index;
						break;
					}
				}

				if (ok == false) {
					Console.WriteLine(-1);
					return;
				}
			}

			var sb = new StringBuilder();
			while (steps.Count > 0) {
				int step = steps.Pop();
				sb.Append($"{step} ");
			}

			Console.WriteLine(sb.ToString());
		}
	}

	public class Edge
	{
		public int From {get; set;}
		public int To { get; set; }
	}

	public class ToColor
	{
		public int To { get; set; }
		public int Color { get; set; }
	}


	public class Scanner2
	{
		private readonly char[] delimiter_ = new char[] { ' ' };
		private readonly string filePath_;
		private string[] buf_;
		private int index_;
		Func<string> reader_;

		public Scanner2(string file = "")
		{
			if (string.IsNullOrWhiteSpace(file)) {
				reader_ = Console.ReadLine;
			} else {
				filePath_ = file;
				var fs = new StreamReader(file);
				reader_ = fs.ReadLine;
			}
			buf_ = new string[0];
			index_ = 0;
		}

		public string Next()
		{
			if (index_ < buf_.Length) {
				return buf_[index_++];
			}

			string st = reader_();
			while (st == "") {
				st = reader_();
			}

			buf_ = st.Split(delimiter_, StringSplitOptions.RemoveEmptyEntries);
			if (buf_.Length == 0) {
				return Next();
			}

			index_ = 0;
			return buf_[index_++];
		}

		public int Int() => int.Parse(Next());
		public long Long() => long.Parse(Next());
		public double Double() => double.Parse(Next());

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

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

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

		public void Save(string text)
		{
			if (string.IsNullOrWhiteSpace(filePath_)) {
				return;
			}

			File.WriteAllText(filePath_ + "_output.txt", text);
		}
	}
}

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

int main() {

  int a,b,c,d,e,f;

  cin >> a>>b;
  
  if(a%2==1&&b%2==1) {
    cout<<"Yes"<<endl;
  }
          else{
          cout<<"No"<<endl;
}
}

Measured memory_bytes: 256
n,q = map(int,input().split())
s = input()
cnt = [0]*n
for i in range(1,n):
    cnt[i] += cnt[i-1]
    if s[i-1:i+1] == "AC":
        cnt[i]+=1
for i in range(q):
    l,r = map(int,input().split())
    print(cnt[r-1]-cnt[l-1])

Measured memory_bytes: 12952
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define inf 10e17
#define rep(i,n) for(long long i=0; i<n; i++)
#define repr(i,n,m) for(long long i=m; i<n; i++)
#define mod 1000000007
#define sorti(x) sort(x.begin(), x.end())
#define sortd(x) sort(x.begin(), x.end(), std::greater<long long>())
#define debug(x) std::cerr << (x) << std::endl;
#define roll(x) for (auto&& itr : x) { cerr << (itr) << " "; }

template <class T> inline void chmax(T &ans, T t) { if (t > ans) ans = t;}
template <class T> inline void chmin(T &ans, T t) { if (t < ans) ans = t;}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int n;
  cin >> n;
  string s;
  cin >> s;
  
  char pre = s[0];
  int ans = 1;
  for (int i = 0; i < n; ++i) {
    if (pre != s[i]) {
      pre = s[i];
      ans += 1;
    }
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 3756
#include <iostream>
using namespace std;
int paper[10][10]={0};

int drop(int y, int x){
	if (0<=x && x<10 && 0<=y && y<10) paper[y][x]++;
	return 0;
}

int ink(int y, int x, int size){
	drop(y,x);
	drop(y-1,x);
	drop(y+1,x);
	drop(y,x-1);
	drop(y,x+1);
	if (size==1) return 0;
	drop(y-1,x-1);
	drop(y-1,x+1);
	drop(y+1,x-1);
	drop(y+1,x+1);
	if (size==2) return 0;
	drop(y-2,x);
	drop(y+2,x);
	drop(y,x-2);
	drop(y,x+2);
	return 0;
}

int main(void){
	
	while (true){
		int x,y,size;
		char c;
		cin>>x>>c>>y>>c>>size;
		if (cin.eof()) break;
		ink(y, x, size);
	}

	int n=10, c1=0, c2=0;
	for (int i=0; i<n; i++){
		for (int j=0; j<n; j++){
			int tmp = paper[j][i];
			if (tmp==0) c1++;
			if (tmp>c2) c2=tmp;
		}
	}
	cout<<c1<<endl;
	cout<<c2<<endl;
	return 0;
}

Measured memory_bytes: 1160
#include<iostream>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int main(){
  int N;
  cin >> N;
  ll a[N];
  rep(i, N){
    cin >> a[i]; a[i] = -a[i];
  }
  ll dp[N] = {}; rep(i, N)dp[i]=inf;
  rep(i, N){
    *upper_bound(dp, dp+N, a[i]) = a[i];
  }
  cout << lower_bound(dp, dp+N, inf) - dp << endl;
}

Measured memory_bytes: 1792
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
  private static class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;

    public FastScanner(InputStream in) {
      reader = new BufferedReader(new InputStreamReader(in));
      tokenizer = null;
    }

    public String next() {
      if (tokenizer == null || !tokenizer.hasMoreTokens()) {
        try {
          tokenizer = new StringTokenizer(reader.readLine());
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
      }
      return tokenizer.nextToken();
    }

    public String nextLine() {
      if (tokenizer == null || !tokenizer.hasMoreTokens()) {
        try {
          return reader.readLine();
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
      }

      return tokenizer.nextToken("\n");
    }

    public long nextLong() {
      return Long.parseLong(next());
    }

    public int nextInt() {
      return Integer.parseInt(next());
    }

    public double nextDouble() {
      return Double.parseDouble(next());
    }

    public int[] nextIntArray(int n) {
      int[] a = new int[n];
      for (int i = 0; i < n; i++)
        a[i] = nextInt();
      return a;
    }

    public long[] nextLongArray(int n) {
      long[] a = new long[n];
      for (int i = 0; i < n; i++)
        a[i] = nextLong();
      return a;
    }
  }

  public static void main(String[] args) {
    FastScanner sc = new FastScanner(System.in);
    int n = sc.nextInt();
    int[] a = sc.nextIntArray(n + 1);
    int[] b = sc.nextIntArray(n);
    long count = 0;
    for (int i = 0; i < n; i++) {
      int ai = Math.min(a[i], b[i]);
      count += ai;
      b[i] -= ai;
      if (b[i] == 0) continue;
      ai = Math.min(a[i + 1], b[i]);
      count += ai;
      a[i + 1] -= ai;
    }
    System.out.println(count);
  }
}

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

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

int n;

int main() {
	cin >> n;
	for (int i = 31; i <= 55555; i += 30) {
		if (isprime(i) == true) {
			if (i != 31) cout << " ";
			cout << i; n--;
		}
		if (n == 0) break;
	}
	cout << endl;
	return 0;
}


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

int main(){
	
	int x, y;
	
 	std::cin >> x >> y;

	if(x>y){
		std::cout  << "a > b" << std::endl;
	}else if(x<y){
		std::cout  << "a < b" << std::endl;
	}else{
		std::cout  << "a == b" << std::endl;
	}
}

Measured memory_bytes: 1156
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int MOD = 1e9+7;

int mod(int n, int m = MOD){
    n %= m;
    return n < 0 ? n+m : n;
}

signed main(){
    int n, k, ans = 1;
    cin>>n>>k;
    vector<int> arr(n);

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

    sort(arr.begin(), arr.end());

    if(arr[0]>=0){
        for(int i=0; i<k; i++) ans = mod(arr[n-1-i]*ans);
        return cout<<ans<<endl, 0;
    } else if(arr[n-1] <= 0){
        for(int i=0; i<k; i++) ans = mod(ans * arr[(k % 2 ? n - 1 - i : i)]);
        return cout<<ans<<endl, 0;
    }

    int l=0, r=n-1, xl, xr;
    if(k%2){
        ans = mod(ans*arr[r]);
        r--, k--;
    }

    while(k > 0){
        xl = arr[l] * arr[l+1];
        xr = arr[r] * arr[r-1];

        if(xl >= xr){
            ans = mod(ans * mod(xl));
            l+=2;
        } else{
            ans = mod(ans * mod(xr));
            r-=2;
        }
        k-=2;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 4776
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  int a[200000];
  cin >> n;
  for(int i=0;i<n;i++) cin >> a[i];
  for(int i=n-1;i>=0;i-=2) cout << a[i] << " ";
  for(int i=((n-1)%2==0?1:0);i<n;i+=2) cout << a[i] << " ";
  cout << endl;
}

Measured memory_bytes: 2944
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES

#include "bits/stdc++.h"
#include <random>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define rep2(i,a,b) for(int i=(a);i<(b);++i)
#define rrep(i,n) for(int i=(n)-1;i>=0;--i)
#define rrep2(i,a,b) for(int i=(a)-1;i>=b;--i)
#define range(i,a,b,c) for(int i=a;\
                    c>0?i<b:\
                    i>b;\
                    i+=c)
#define chmax(a, b) (a = (a) < (b) ? (b) : (a))
#define chmin(a, b) (a = (a) > (b) ? (b) : (a))
using ll = long long;
using ull = unsigned long long;
using ld = long double;
#define all(a) begin(a),end(a)
#define ifnot(a) if(not (a))
#define dump(x)  cerr << #x << " = " << (x) << endl
#define int long long
#ifdef _MSC_VER
const bool test = true;
#else 
const bool test = false;
#endif

int dx[] = { 1,0,-1,0 };
int dy[] = { 0,1,0,-1 };
const int INF = 1 << 28;
const ll INFL = (ll)1 << 58;
ll mod = (int)1e9 + 7;
const double eps = 1e-10;
typedef long double Real;
// return -1, 0, 1
int sgn(const Real& r) { return (r > eps) - (r < -eps); }
int sgn(const Real& a, const Real &b) { return sgn(a - b); }

//.....................
const int MAX = (int)2e5 + 5;

vector<string> split(const string &str, char sep) {
	vector<string> v;
	stringstream ss(str);
	string buffer;
	while (getline(ss, buffer, sep)) {
		v.push_back(buffer);
	}
	return v;
}

template<class InputIterator>
int sum(InputIterator begin, InputIterator end) {
	return accumulate(begin, end, 0ll);
}

string reverse_str(string s) {
	reverse(all(s));
	return s;
}

//double dist(double a, double b) {
//	while (ans < 0) ans += 360;
//	while (ans > 360) ans -= 360;
//
//	while (ans < 0) ans += 360;
//	while (ans > 360) ans -= 360;
//}

string s;

int eval(int a[], int x) {
	int val = 0;
	rrep(i, 10) {
		val = val * x + a[i];
	}
	return val;
}

vector<int> find_ans(int a[]) {
	vector<int> ans;
	rrep2(i, 10000, -10000) {
		if (eval(a, i) == 0) ans.push_back(i);
	}
	return ans;
}

void solve() {
	int a[10] = {};
	cin >> s;
	s.insert(s.begin(), '+');
	// dump(atoi("-10"));
	rep(i, s.size()) {
		int v = 1;
		if (s[i] == '+' || s[i] == '-' || isdigit(s[i])) {
			//dump(s.c_str() + i);
			if (s[i + 1] == 'x') {
				if (s[i] == '+') v = 1;
				else v = -1;
			}
			else v = atoi(s.c_str() + i);
			while (s[i] == '+' || s[i] == '-' || isdigit(s[i])) i++;
		}
		if (s[i] != 'x') {
			a[0] += v;
			continue;
		}
		i++;
		if (s[i] != '^') {
			a[1] += v;
			i--;
			continue;
		}
		i++;
		a[s[i] - '0'] += v;
	}
	//if (test) {
	//	rrep(i, 10) {
	//		cout << a[i] << " ";
	//	}
	//	cout << endl;
	//}
	//dump(eval(a, -1));
	//dump(eval(a, -2));
	//dump(eval(a, 1));
	//dump(eval(a, 2));
	vector<int> ans = find_ans(a);
	rep(i, ans.size()) {
		char op = ans[i] > 0 ? '-' : '+';
		cout << "(x" << op << abs(ans[i]) << ")";
	}
	cout << endl;
}

signed main() {
	srand(time(NULL));
	int T = (int)1e15;
	solve();
	cout << fixed << setprecision(15);
	rep(i, T) {
		char s[MAX];
		if (scanf("%s", s) == EOF) break;
		int n = strlen(s);
		for (int i = n - 1; i > -1; i--) {
			ungetc(s[i], stdin);
		}
		solve();
	}
	return 0;
}

Measured memory_bytes: 3216
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T> V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> > Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T> mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }

/*
 <url:>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */

ll solve(){
    ll res = 0;
    ll A,B,C,D,E; cin >> A >> B >> C >> D >> E;
    if(A < 0){
        res = abs(A)*C+D+E*B;
    }else{
        res = E*(B-A);
    }
    return res;
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    cout << solve() << endl;
    return 0;
}



Measured memory_bytes: 3100
def prime_factor(n):
    arr = []
    temp = n
    for i in range(2, 3):
        if temp % i == 0:
            cnt = 0
            while temp % i == 0:
                cnt += 1
                temp //= i
            arr.append([i, cnt])

    if temp != 1:
        arr.append([temp, 1])
    if arr == []:
        arr.append([n, 1])
    return arr


try:
    from math import gcd
except ImportError:
    from fractions import gcd

n, m = [int(_) for _ in input().split()]
A = [int(_) for _ in input().split()]

n = 1
c = prime_factor(A[0])[0][1]
for a in A:
    if c != prime_factor(a)[0][1]:
        print(0)
        exit()
    n = (n*a)//gcd(n, a)

n //= 2

if n > m:
    ans = 0
else:
    ans = m//n
    ans = (ans+1)//2

print(ans)


Measured memory_bytes: 16280
#include<iostream>
#include<cstdio>
#define maxn 100005
#define nil -1
using namespace std;
int n,root; 

struct node
{
	int parent;
	int left;
	int right;
	node():parent(nil),left(nil),right(nil){}
};
node t[maxn];

void build()
{
	for(int i=0;i<n;++i)
	{
		int num,l,r;
		scanf("%d%d%d",&num,&l,&r);
		t[num].left=l;
		t[num].right=r;
		if(l!=nil) t[l].parent=num;
		if(r!=nil) t[r].parent=num;
	}
	return;
}

void find_root()
{
	for(int i=0;i<n;++i)
	  if(t[i].parent==nil)
	  {
	  	root=i;
	  	break;
	  }
	return ;
}

void preorder(int num)
{
	printf(" %d",num);
	if(t[num].left!=nil) preorder(t[num].left);
	if(t[num].right!=nil) preorder(t[num].right);
	return ;
}

void inorder(int num)
{
	if(t[num].left!=nil) inorder(t[num].left);
	printf(" %d",num);
	if(t[num].right!=nil) inorder(t[num].right);
	return ;
}

void postorder(int num)
{
	if(t[num].left!=nil) postorder(t[num].left);
	if(t[num].right!=nil) postorder(t[num].right);
	printf(" %d",num);
	return ;
}

int main()
{
//	freopen("out.txt","w",stdout);
	scanf("%d",&n);
	build();
	find_root();
	printf("Preorder\n");
	preorder(root); 
	printf("\nInorder\n");
	inorder(root);
	printf("\nPostorder\n");
	postorder(root);
	printf("\n");
	return 0;
} 

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

int main()
{
	string S, T;

	cin >> S >> T;

	int s;
	s = S.size();

	int t = S[0];

	for (int j = 0; j < s; j++) {
		if (S[0] == T[j]) {
			int ok = 1;
			
			for (int k = j+1, m = 1; m < s; k++, m++) {
				if (k >= s)k = 0;
				if (S[m] != T[k]) {
					ok = 0;
					break;
				}
				
			}
			if (ok) {
				cout << "Yes" << endl;
				return 0;
			}
		}
	}

	cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 256
a, b = map(int, input().split())

if a <= 0 and b >= 0:
    ans = 'Zero'
elif a < 0 and b < 0:
    if (abs(a) - abs(b) + 1) % 2 == 0:
        ans = 'Positive'
    else:
        ans = 'Negative'
elif a > 0 and b > 0:
    ans = 'Positive'
    
print(ans)

Measured memory_bytes: 3060
import java.util.Scanner;

public class Main {

	static int max = 250;
	static int s[] = new int[max + 1];
	static int top;

	static void initialize() {
		top = 0;
	}

	static boolean isEmpty() {
		return top == 0;
	}

	static boolean isFull() {
		return top >= max;
	}

	static void push(int x) {
		if(! isFull()){
			top++;
			s[top] = x;
		}
	}

	static int pop() {
		if(! isEmpty()) {
			top--;
			return s[top+1];
		}else {
			return -1;
		}
	}

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		initialize();
		String a = sc.nextLine();
		String[] tt = a.split(" ");
		for(int i=0;i<tt.length;i++){
			String t = tt[i];
			if(t.equals("+")) {
				int x = pop();
				int y = pop();
				push(x + y);
			}else if(t.equals("-")){
				int x = pop();
				int y = pop();
				push(y - x);
			}else if(t.equals("*")) {
				int x = pop();
				int y = pop();
				push(x*y);
			}else {
				int x = Integer.parseInt(t);
				push(x);
			}
		}
		System.out.println(pop());
	 }
}



Measured memory_bytes: 26296
macro_rules! scan_sub {
    ( $itr:ident, $t:ty ) => {
        let mut buf = String::new();
        let $itr = {
            while buf.trim().len() == 0 {
                buf = String::new();
                std::io::stdin().read_line(&mut buf).unwrap();
            }
            buf.split_whitespace().map(|n| n.parse::<$t>().unwrap())
        };
    };
}

macro_rules! scan {
    ( $x:ident; Vec<$t:ty> ) => {
        scan_sub!(itr, $t);
        let $x = itr.collect::<Vec<_>>();
    };
    ( $( $x:ident ),*; $t:ty ) => {
        scan_sub!(itr, $t);
        let mut itr = itr;
        $(
            let $x = itr.next().unwrap();
        )*
    };
}

use std::collections::HashMap;

fn f(hm: &mut HashMap<u64, usize>, v: &Vec<usize>, n: u32, index: &mut usize, acc: u64) {
    if v.is_empty() {
        hm.insert(acc, *index);
        *index += 1;
        return;
    }

    for &t in v.iter() {
        let next_v = v.iter()
            .filter(|&&s| s != t)
            .map(|&s| s).collect::<Vec<_>>();
        f(hm, &next_v, n-1, index, acc+(t as u64 * 10_u64.pow(n-1)));
    }
}

fn main() {
    scan!(n; usize);
    scan!(p; Vec<u64>);
    scan!(q; Vec<u64>);

    let mut n_fact = 1;
    for i in 1..n+1 { n_fact *= i; }
    let mut dict = HashMap::with_capacity(n_fact);
    let v = (1..n+1).collect::<Vec<_>>();
    let mut index = 0;

    f(&mut dict, &v, n as u32, &mut index, 0);

    let mut p_num = 0;
    let mut q_num = 0;
    for i in 0..n {
        p_num += p[i] * 10_u64.pow((n-i-1) as u32);
        q_num += q[i] * 10_u64.pow((n-i-1) as u32);
    }

    let a = dict[&p_num];
    let b = dict[&q_num];

    let (a, b) = if a > b { (a, b) } else { (b, a) };
    println!("{}", a-b);
}


Measured memory_bytes: 4352
'use strict'

function Main(input) {
  let isIncluded = false;
  input.split('').map(c => {
    if (c == 9) {
      if (!isIncluded) {
        console.log('Yes');
        isIncluded = true;
        return;
      }
    }
  });
  if (!isIncluded) {
    console.log('No');
  }
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 7372
from collections import defaultdict

def getlist():
	return list(map(int, input().split()))

n = int(input())
v = getlist()

D1 = defaultdict(int)
D2 = defaultdict(int)
for i in range(n):
	if i % 2 == 0:
		D1[v[i]] += 1
	else:
		D2[v[i]] += 1

v1 = []
v2 = []
for i in D1:
	v1.append([D1[i], i])
for i in D2:
	v2.append([D2[i], i])

v1 = sorted(v1)
v2 = sorted(v2)

if len(v1) >= 2 and len(v2) >= 2:
	if v1[-1][1] != v2[-1][1]:
		print(n - v1[-1][0] - v2[-1][0])
	else:
		print(min(n - v1[-2][0] - v2[-1][0], n - v1[-1][0] - v2[-2][0]))
else:
	if len(v1) == 1 and len(v2) >= 2:
		if v1[-1][1] != v2[-1][1]:
			print(n // 2 - v2[-1][0])
		else:
			print(n // 2 - v2[-2][0])
	elif len(v1) >= 2 and len(v2) == 1:
		if v1[-1][1] != v2[-1][1]:
			print(n // 2 - v1[-1][0])
		else:
			print(n // 2 - v1[-2][0])
	else:
		if v1[-1][1] != v2[-1][1]:
			print(0)
		else:
			print(n // 2)

Measured memory_bytes: 24476
#include<cstdio>
#include<cstring>
#include<algorithm>

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

using namespace std;

struct piece{
	int h,w; // 大きさ
	char B[20][21]; // ピースの形
	int y0,x0; // 空きじゃない一番左上のマス
	bool operator==(const piece &P)const{
		if(h!=P.h || w!=P.w) return false;
		rep(y,h) rep(x,w) if(B[y][x]!=P.B[y][x]) return false;
		return true;
	}
};

void find_upperleft(piece &P,char c){
	rep(y,P.h) rep(x,P.w) if(P.B[y][x]==c) {
		P.y0=y;
		P.x0=x;
		return;
	}
}

piece W; // 枠

int n,n2[10]; // n2[i] := ( ピース i の、回転で一致しないパターンの個数 )
piece P[10][4]; // ピースの情報 ( 回転 4 パターン )

int m;
int choice[10]; // プレイヤーが選ぶピースの番号 ( 選んだら -1 )

bool dfs(){
	if(count(choice,choice+m,-1)==m) return true;

	find_upperleft(W,'.');
	int y0=W.y0,x0=W.x0; // 再帰した先で W.y0, W.x0 の値が変わるのでローカルにもっておく
	rep(i,m) if(choice[i]!=-1) {
		int &u=choice[i];
		rep(k,n2[u]){
			int tmp;
			const piece &Q=P[u][k];

			bool ok=false;
			// ピース Q をはめこむ
			rep(y,Q.h) rep(x,Q.w) {
				int yy=y+y0-Q.y0,xx=x+x0-Q.x0; // 枠における座標
				if(0<=yy && yy<W.h && 0<=xx && xx<W.w){
					if(Q.B[y][x]=='#'){
						if(W.B[yy][xx]=='.'){
							W.B[yy][xx]='A'+i;
						}
						else goto CANNOT_SET;
					}
				}
				else{
					if(Q.B[y][x]=='#') goto CANNOT_SET;
				}
			}

			// ピース Q をはめたので次のピースへ
			tmp=u;
			u=-1;
			ok=dfs();
			u=tmp;

			CANNOT_SET:
			// ピース Q を抜く
			rep(y,Q.h) rep(x,Q.w) {
				int yy=y+y0-Q.y0,xx=x+x0-Q.x0;
				if(0<=yy && yy<W.h && 0<=xx && xx<W.w && W.B[yy][xx]=='A'+i) W.B[yy][xx]='.';
			}

			if(ok) return true;
		}
	}

	return false;
}

int main(){
	for(;scanf("%d%d",&W.h,&W.w),W.h;){
		rep(i,W.h) scanf("%s",W.B[i]);
		int W_sz=0;
		rep(i,W.h) rep(j,W.w) if(W.B[i][j]=='.') W_sz++;

		scanf("%d",&n);
		int P_sz[10]={};
		rep(i,n){
			scanf("%d%d",&P[i][0].h,&P[i][0].w);
			rep(y,P[i][0].h) scanf("%s",P[i][0].B[y]);
			rep(k,3){
				P[i][k+1].h=P[i][k].w;
				P[i][k+1].w=P[i][k].h;
				rep(y,P[i][k].h) rep(x,P[i][k].w) {
					P[i][k+1].B[x][P[i][k].h-y-1]=P[i][k].B[y][x];
				}
			}
			rep(k,4) find_upperleft(P[i][k],'#');

			rep(y,P[i][0].h) rep(x,P[i][0].w) if(P[i][0].B[y][x]=='#') P_sz[i]++;
		}

		// 回転で一致するものを削除することで高速化
		rep(i,n){
			n2[i]=4;
			rep(k,n2[i]){
				bool b=false;
				rep(l,k) if(P[i][k]==P[i][l]) b=true;
				if(b){
					memcpy(&P[i][k],&P[i][n2[i]-1],sizeof(piece));
					n2[i]--;
					k--;
				}
			}
		}

		int q; scanf("%d",&q);
		while(q--){
			scanf("%d",&m);
			rep(i,m) scanf("%d",choice+i), choice[i]--;

			int dif=W_sz;
			rep(i,m) dif-=P_sz[choice[i]];
			puts(dif==0&&dfs()?"YES":"NO");
		}
	}

	return 0;
}

Measured memory_bytes: 752
//#include <bits/stdc++.h>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <fstream>
#include <string.h>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <queue>
#include <math.h>
#include <assert.h>
#define ff first
#define ss second
#define ll long long
#define mod 998244353
using namespace std;
ll n;
vector<pair<ll, ll> > v;
int main () {
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    cin>>n;
    for(ll i=-3500;i<=3500;i++) {
        ll cur = i * i * i * i * i;
        v.push_back({cur, i});
    }
    for(int i=0;i<v.size();i++) {
        for(int j=i+1;j<v.size();j++) {
            ll x = v[i].ff, y = v[j].ff;
            if(y - x == n) {
                cout<<v[j].ss<<" "<<v[i].ss;
                return 0;
            }
        }
    }
}
/*
 2
 1 1
 1 0
 1 1
 1 1
 */


Measured memory_bytes: 3784
from collections import namedtuple, deque


def bfs():
    while queue:
        u = queue.popleft()
        i = 1
        for e in adj[u]:
            if e.t == u:
                continue
            if parent[u] == i:
                i += 1
            parent[e.t] = i
            ans[e.id] = i
            queue.append(e.t)
            i += 1


Edge = namedtuple('Edge', ('t', 'id'))

n = int(input())

adj = [[] for _ in range(n)]
for i in range(n - 1):
    s, t = (int(v) - 1 for v in input().split())
    edge = Edge(t, i)
    adj[s].append(edge)
    adj[t].append(edge)

k = len(max(adj, key=lambda x: len(x)))

queue = deque([0])
parent = [-1] * n
ans = [0] * (n - 1)
bfs()

print(k)
print(*ans, sep='\n')

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

count = 0
odd_count = 0
for i in range(1, n+1):
    if i % 2 != 0:
        for j in range(1, i+1):
            if i % j  == 0:
                odd_count += 1
        if odd_count == 8:
            count += 1
        odd_count = 0

print(count)


Measured memory_bytes: 2940
#include <iostream>
#include <cstdlib>
#include <vector>

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

int main()
{
	vector<int> a = {0, 0, 0, 0};
	vector<int> b = {1, 9, 7, 4};
	for(int i=0; i<4; i++) cin >> a[i];

	bool crit = true;
	for(int i=0; i<4; i++){
		auto result = find(a.begin(), a.end(), b[i]);
		if(result == a.end())
			crit = false;
	}

	if(crit) cout << "YES" << endl;
	else cout << "NO" << endl;

	return 0;
}

Measured memory_bytes: 256
import numpy as np

grid = []
#for i in range(1):
array = list(map(int,input().strip().split()))
#    grid.append(array)
#print(array)
n = array[0]
a = array[1]
b = array[2]
if a == 0:
    print(0)
else:
    kaisuu = int(n/(a+b))
    nokori = n%(a+b)
    if nokori < a:
        print(kaisuu*a+nokori)
    else:
        print(kaisuu*a+a)

Measured memory_bytes: 14412
#include<iostream>
#include<string>
#include<vector>
#include<math.h>
#include<algorithm>
#include<cstdio>
#include<stdio.h>
#include<stack>
#include<sstream>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<list>
#include<numeric>
typedef long long ll;

#define pi 3.14159265358979323846
#define VI vector<int>
#define VLL vector<long long>
#define MAX max_element
#define MIN min_element
#define all(v) v.begin(), v.end()
const ll MOD = 1e9 + 7;
using namespace std;
template<typename T>
T gcd(T a, T b) {
	return b ? gcd(b, a % b) : a;
}
template<typename T>
T lcm(T a, T b) {
	return a * b / gcd(a, b);
}

template<typename T>
T binarysearch(vector<T> A, T key) {
	ll left = 0;ll right = 4;ll mid;
	while (left < right) {
		mid = (left + right) / 2;
		if (key == A[mid]) return 1;
		if (key > A[mid]) left = mid + 1;
		else if (key < A[mid]) right = mid;
	}
	return 0;
}

template<typename T>
T finder(vector<T> vec, T number) {
	auto itr = find(vec.begin(), vec.end(), number);
	size_t index = distance(vec.begin(), itr);
	if (index != vec.size()) { // 発見できたとき
		return 1;
	}
	else { // 発見できなかったとき
		return 0;
	}
}
ll frac(ll n)//階乗
{
	if (n == 0) {
		return 1;
	}
	return (n * frac(n - 1)) % MOD;
}

template<typename T>
T keta(T a) {
	ll kazu = 1;
	while (1) {
		if (a / 10 != 0) { a /= 10;kazu++; }
		else break;
	}
	return kazu;
}//桁数


template<typename T>
T nCr(ll n, T r) {
	ll 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;
}
/*char r[4];
int yaju[4];
char op[3];
int sum = 0;
scanf("%s", r);
for (int i = 0;i < 4;i++) {
	yaju[i] = r[i] - '0';
}
*/
int main() {
	string S;
	ll Q; cin >> S;
	cin>> Q;
	ll q, b; string s;
	ll sum = 0;
	for (int i = 0;i < Q;i++) {
		cin >> q;
		if (q == 2) {
			cin >> b >> s;
			if (sum % 2 == 0) {
				if (b == 1)S.insert(0, s);
				if (b == 2)S += s;
			}
			else {
				if (b == 2)S.insert(0, s);
				if (b == 1)S += s;
			}
		}
		else sum++;
		//else reverse(S.begin(), S.end());
	}
	if(sum%2==1)reverse(S.begin(), S.end());
		cout << S << endl;
}

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

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout.precision(12);
    cout.setf(ios_base::fixed, ios_base::floatfield);
    
    int a[3];
    cin >> a[0] >> a[1] >> a[2];
    sort(a,a+3);

    if(a[0] == a[2]) cout << "Yes" << endl;
    else cout << "No" << endl;
    
    return 0;
}

Measured memory_bytes: 256
#print#!/usr/bin/env python3
#%% for atcoder uniittest use
import sys
input= lambda: sys.stdin.readline().rstrip()
sys.setrecursionlimit(10**9)
def pin(type=int):return map(type,input().split())
def tupin(t=int):return tuple(pin(t))
def lispin(t=int):return list(pin(t))
#%%code

#なお、任意の整数 M に対して M の −2 進数表現が一意に定まることが証明できます。
#2桁ごとに見るとよかった（もう実験したよ）
def resolve():
    N,=pin()
    K,=pin()
    X=tupin()
    ans=0
    for x in X:
        ans+=min(abs(x),abs(K-x))*2
    print(ans) 
#%%submit!
resolve()

Measured memory_bytes: 38384
#include <iostream>
#include <string>
#include <stdio.h>
using namespace std;
 
int main()
{
  double a, b;
  cin >> a >> b;
    for (int i = 0; i < 1100; ++i) {
        if(int(0.08 * i) == a && int(0.10 * i) == b) {
      		cout << i << endl;
            return 0;
        }
    }
    cout << -1 << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <variant>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/adaptor/indexed.hpp>
#define FOR(i,k,n)  for(int i = (k);i < (n);++i)
#define REP(i,n)    FOR(i,0,n)
#define ALL(x) begin(x),end(x)

using namespace std;
using namespace boost::adaptors;
using namespace std::string_literals;
using ll = int64_t;
using vecint = vector<int>;
using vecll = vector<ll>;
using boost::irange;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  vecint a(5);
  for(auto&&e:a)cin>>e;
  REP(i,5) {
    if(a[i]==0) cout<<(i+1)<<endl;
  }
  return 0;
}


Measured memory_bytes: 3644
#include<bits/stdc++.h>
using namespace std;
int n,m,ans,cnt,now;
struct V {
	int a,b;
	bool operator <(const V& q)const {
		return a>q.a;
	}
} A[100005];
multiset<int>S;
multiset<int>::iterator fo;
int main() {
	scanf("%d %d",&n,&m);
	for(int i=1; i<=n; i++)
		scanf("%d %d",&A[i].a,&A[i].b);
	sort(A+1,A+n+1),now=1;
	while(A[now].a>m)now++;
	S.clear();
	for(int i=m; i; i--) {
		while(A[now].a==i&&now<=n) S.insert(A[now].b),now++;
		cnt=m-i+1;
		while((int)S.size()>cnt) {
			fo=S.begin();
			S.erase(fo);
		}
	}
	fo=S.begin();
	while(fo!=S.end())ans+=*fo,fo++;
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 5760
#include <iostream>
#include <string>
#include <array>

using namespace std;

int main() {
    int n, i, x, y;
    cin >> n;

    array<string, 500> s;
    for(i = 0; i < n; i++) cin >> s[i];

    int ans = 0, xx, yy;
    for(i = 0; i < n; i++) {
        for(x = 0; x < n; x++) {
            for(y = 0; y < n; y++) {
                xx = y - i < 0 ? n + y - i : y - i;
                yy = x + i >= n ? x + i - n : x + i;
                if(s[x][y] != s[xx][yy]) goto XX;
            }
        }
    ans += 1;
  XX:
    continue;
    }

    cout << ans * n << endl;
}

Measured memory_bytes: 888
//
//  main.cpp
//  A
//
//  Created by 耿英俊 on 2020/1/10.
//  Copyright © 2020 耿英俊. All rights reserved.
//
#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <string.h>
#include <stdio.h>
using namespace std;
int main(int argc, const char * argv[]) {
    int m;
    cin>>m;
    string N1;
    getline(cin,N1);
    string N;
    getline(cin,N);
    char n[m];
    strcpy(n,N.c_str());
    int flag=0;
    for(int i=0;i<m;i++){
        if(n[i]=='A')
            if(n[i+1]=='B')
                if(n[i+2]=='C')
                    flag++;
    }
    cout<<flag;
}


Measured memory_bytes: 256
import java.util.*;

class Main{
	public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int[] N = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
        int K = sc.nextInt() - 1;

        System.out.println(N[K]);
	}

}

Measured memory_bytes: 20820
l = input().split()

[n,a,b] = [int(x) for x in l]

if a==b and a==0:
    print(0)
else:
    x = a+b
    y = n//x

    if a == 0:
        print(0)
    else:
        if b == 0:
            print(n)
        else:
            t = n - y*x
            if t > a:
                print(y*a+a)
            else:
                print(y*a+t)

Measured memory_bytes: 38384
// Template from https://techracho.bpsinc.jp/jhonda/2019_08_05/78537

// input macro for competive-programming from https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };

    ($iter:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, bytes) => {
        read_value!($iter, String).into_bytes()
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    use std::io::Read;
    let mut s = String::new();
    std::io::stdin().read_to_string(&mut s).unwrap();

    println!("{}", solve(&s));
}

macro_rules! test {
    ($($input:expr => $output:expr),* $(,)*) => {
        #[test]
        fn solve_test() {
            $(
                assert_eq!(solve($input), $output);
            )*
        }
    };
}

test! {
r#"1 1"# => r#"Draw"#,
r#"1 2"# => r#"Alice"#,
r#"2 1"# => r#"Bob"#,
r#"13 3"# => r#"Alice"#,
r#"3 13"# => r#"Bob"#,
}

fn solve(src: &str) -> String {
    input! {
        source = src,
        a: usize,
        b: usize,
    }

    if a == b {
        "Draw"
    } else if b == 2 || a == 1 {
        "Alice"
    } else if a == 2 || b == 1 {
        "Bob"
    } else if a > b {
        "Alice"
    } else {
        "Bob"
    }.to_string()
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
using ll = long long;
using ull = unsigned long long;
using P = pair<int,int>;
using PP = pair<int,pair<int,int>>;
using T = tuple<string,int,int>;
const ll INF = 1LL<<60;

int main(){
  ull a; cin >> a;
  double b; cin >> b;
  ull bb = b*100+0.5;
  ull ans = a*bb;
  ans /= 100;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3680
#include<bits/stdc++.h>
using namespace std;
long long cnt[30], x, ans, sum;
char ss[300000];
int main()
{
	scanf("%s", ss);
	x = strlen(ss);
	for (int i = 0; i < x; i++)
	{
		cnt[ss[i]-'a']++;
	}
	ans = (x*(x-1))/2;
	for (int i = 0; i < 26; i++)
	{
		if (cnt[i]>1) sum += (cnt[i]*(cnt[i]-1))/2;
	}
	printf("%lld\n", 1+ans-sum);
}

Measured memory_bytes: 384
w = int(raw_input().rstrip())

l=[]
for i in range(w+1):
  l.append(i) 

n = int(raw_input().rstrip())

for i in range(n):
  a, b = raw_input().rstrip().split(",")
  l[int(a)], l[int(b)] = l[int(b)], l[int(a)]


for i in range(w):
  print l[i+1]

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

int main()
{
    int H, W;
    cin >> H >> W;
    vector<string> S(H);
    for (int i = 0; i < H; i++) {
        cin >> S.at(i);
    }

    const vector<int> dx = { 1, 0, -1, 0 };
    const vector<int> dy = { 0, 1, 0, -1 };

    string answer = "Yes";
    bool finished = false;
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            if (S.at(i).at(j) == '.')
                continue;

            bool isolated = true;
            for (int d = 0; d < 4; d++) {
                const int ni = i + dy[d];
                const int nj = j + dx[d];

                if (ni < 0 or ni >= H)
                    continue;
                if (nj < 0 or nj >= W)
                    continue;

                if (S.at(ni).at(nj) == '#') {
                    isolated = false;
                    break;
                }
            }
            if (isolated) {
                answer = "No";
                finished = true;
                break;
            }
        }
        if (finished)
            break;
    }

    cout << answer << endl;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 9)
MOD = 10 ** 9 + 7

N = int(input())
lst1 = [[0, i] for i in range(10 ** 5  +10)]
lst2 = [[0, i] for i in range(10 ** 5 + 10)]

V = tuple(map(int, input().split()))

for i in range(N):
    if i % 2 == 0:
        lst1[V[i]][0] += 1
    else:
        lst2[V[i]][0] += 1

lst1.sort(key = lambda x: x[0],reverse = True)
lst2.sort(key = lambda x: x[0],reverse = True)

if lst1[0][1] != lst2[0][1]:
    print (N - lst1[0][0] - lst2[0][0])
else:
    print (N - max(lst1[0][0] + lst2[1][0], lst1[1][0] + lst2[0][0]))

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

int main(){
    
    int N,M,P,num_wa=0,num_ac=0; cin >> N >> M;
    string S;
    int num[N];
    map<int,string> mp{};
    for(int i=0;i<N;i++) num[i] = 0;
    
    for(int i=0;i<M;i++){
        cin >> P >> S;
        if(mp.count(P) == 0){mp[P] = S; if(S == "WA"){num[P-1]++;}else if(S == "AC"){num_ac++;}}
        else if(mp[P] == "WA" && S == "AC"){mp[P] = S; num_ac++; num_wa+=num[P-1];}
        else if( mp[P] == "WA" && S == "WA"){num[P-1]++;}
    }
   cout << num_ac << " " << num_wa << endl;
}

Measured memory_bytes: 11800