akhauriyash/Code-Regression huggingface dataset:
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
ans=b[a[0]-1]
for i in range(1,n):
    ans+=b[a[i]-1]
    if a[i]-a[i-1]==1:
        ans+=c[a[i-1]-1]
print(ans)


Measured memory_bytes: 38256
#include<bits/stdc++.h>
using namespace std;
void comb(vector<vector <long long int> > &v){
  for(int i = 0;i <v.size(); i++){
    v[i][0]=1;
    v[i][i]=1;
  }
  for(int k = 1;k <v.size();k++){
    for(int j = 1;j<k;j++){
      v[k][j]=(v[k-1][j-1]+v[k-1][j])%1000000007;
    }
  }
}
int main(){
  int n,k;cin>>n>>k;
  vector<vector<long long>>v(n+1,vector<long long>(n+1));
  comb(v);
  for(int i=1;i<=k;i++){
    if(n-k>=i-1)cout<<v[k-1][i-1]*v[n-k+1][i]%1000000007<<endl;
    else cout<<0<<endl;
  }
}

Measured memory_bytes: 31616
for i in range(100):
    m,f,r = map(int,input().split())
    if m == -1 and f == -1 and r == -1:
        break
    else:
        if m == -1 or f == -1:
            print("F")
        else:
            if m+f >= 80:
                print("A")
            elif 65<=m+f<80:
                print("B")
            elif 50<=m+f<65:
                print("C")
            elif 30<=m+f<50:
                if r >= 50:
                    print("C")
                else:
                    print("D")
            elif m+f < 30:
                print("F")


Measured memory_bytes: 5592
a, b, c, d, e, f = map(int,input().split())
bs, bw = 0, 1
cansugar, canwater = [False]*(f+1), [False]*(31)
for ta in range(0,(30//a)+1):
    for tb in range(0,(30//b)+1):
        if a*ta + b*tb <= 30:
            canwater[a*ta+b*tb] = True
for tc in range(0,(3000//c)+1):
    for td in range(0,(3000//d)+1):
        if c*tc + d*td <= f:
            cansugar[c*tc+d*td] = True
for ab in range(1,31):
    for cd in range(0,f+1):
        if canwater[ab] and cansugar[cd]:
            w = 100*ab
            s = cd
            if w+s <= f and s/(w+s) >= bs/(bw+bs) and s <= ab*e:
                bw = w
                bs = s
print(bw+bs, bs)

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

int main(){
    ll N;
    cin >> N;
    vector<ll> A(N+1, 1);
    A[0] = 0;


    for(ll i = 1; i <= N / 2 + 1; i++){
        ll num = 2;
        while(num * i <= N){
            A[num * i]++;
            num++;
        }
    }

    ll ans = 0;

    for(ll K = 1; K <= N; K++){
        ans += K * A[K];
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 81388
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;

//constexpr long long int MOD = 1000000007;
//constexpr int MOD = 1000000007;
//constexpr int MOD = 998244353;
constexpr long long int MOD = 998244353;
constexpr double EPS = 1e-9;

//int N, M, K, H, W, L, R;
long long int N, M, K, H, W, L, R;


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

	cin >> N;
	vector<long long int>v(N);
	for (auto &i : v)cin >> i;
	sort(v.rbegin(), v.rend());
	long long int ans = 0;
	for (int i = 1; i < N; i++) {
		ans += v[i / 2];
	}
	cout << ans << endl;
}

Measured memory_bytes: 4780
"""
for i in range(201):
    if i % 2 == 0:
        continue
    cnt = 0
    for j in range(1, i+1):
        if i % j == 0:
            cnt += 1
    if cnt == 8:
        print(i)
        
出力
105
135
165
189
195
"""
n = int(input())
if n < 105:
    print(0)
elif n < 135:
    print(1)
elif n < 165:
    print(2)
elif n < 189:
    print(3)
elif n < 195:
    print(4)
else:
    print(5)

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

int main(){
    int n; cin >> n;
    vector<string> v(n);
    rep(i,n){
        cin >> v[i];
        sort(v[i].begin(),v[i].end());
    }
    sort(v.begin(),v.end());
    string now="";
    ll count=0;
    ll ans=0;
    rep(i,n){
        if(v[i]==now){
            count++;
        }else {
            ans+=count*(count-1)/2;
            count=1;
            now=v[i];
        }
    }
    ans+=count*(count-1)/2;
    cout << ans << endl;
}

Measured memory_bytes: 8704
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define REPS(i,n) FOR(i,1,n+1)
#define RFOR(i,l,r) for(long long i=(l);i>=(r);--i)
#define RREP(i,n) RFOR(i,n-1,0)
#define RREPS(i,n) RFOR(i,n,1)
#define int long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
const int INF=1e18;
const int MOD=1e9+7;

signed main(){
    int w,h;cin>>w>>h;
    vector<pair<int,int>>a(w+h);
    REP(i,w){
        int p;cin>>p;
        a[i]={p,0};
    }
    REP(i,h){
        int p;cin>>p;
        a[i+w]={p,1};
    }
    sort(all(a));
    int wp=w+1;int hp=h+1;
    int ans=0;
    for(int i=0;wp>1||hp>1;i++){
        if(a[i].second==0){
            ans+=a[i].first*hp;
            wp--;
        }
        if(a[i].second==1){
            ans+=a[i].first*wp;
            hp--;
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3328
#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;

int main() {
  int N, M;
  cin >> N >> M;
  vector<bool> flag(N, true);
  int l, r, lmax = 1, rmin = N;
  for (int i = 0; i < M; i++) {
    cin >> l >> r;
    lmax = max(lmax, l);
    rmin = min(rmin, r);
  }
  int ret = max(rmin - lmax + 1, 0);
  cout << ret << endl;
}


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

using namespace std;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> a(n), b(n), c(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < n; i++) {
    cin >> b[i];
  }
  for (int i = 0; i < n; i++) {
    cin >> c[i];
  }
  sort(a.rbegin(), a.rend());
  sort(b.rbegin(), b.rend());
  sort(c.rbegin(), c.rend());
  vector<long long> numb(n), sum(n + 1);
  for (int i = 0, j = 0; i < n; i++) {
    while (j < n && b[i] < c[j]) j++;
    numb[i] = j;
  }
  for (int i = 0; i < n; i++) {
    sum[i + 1] = sum[i] + numb[i];
  }
  long long res = 0;
  for (int i = 0, j = 0; i < n; i++) {
    while (j < n && a[i] < b[j]) j++;
    res += sum[j];
  }
  cout << res << '\n';
  return 0;
}

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

#define forn(i, n) for (int i = 0; i < int(n); ++i)
#define for1(i, n) for (int i = 1; i <= int(n); ++i)
#define ms(a, x) memset(a, x, sizeof(a))
#define F first
#define S second
#define all(x) (x).begin(),(x).end()

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 0x3f3f3f3f;
mt19937 gen(random_device{}());
template<typename... Args> void write(Args... args) { ((cout << args << " "), ...); cout<<endl;}

template <int MOD>
struct ModInt {
    int val;
    // constructor
    ModInt(ll v = 0) : val(int(v % MOD)) {
        if (val < 0) val += MOD;
    };
    // unary operator
    ModInt operator+() const { return ModInt(val); }
    ModInt operator-() const { return ModInt(MOD - val); }
    ModInt inv() const { return this->pow(MOD - 2); }
    // arithmetic
    ModInt operator+(const ModInt& x) const { return ModInt(*this) += x; }
    ModInt operator-(const ModInt& x) const { return ModInt(*this) -= x; }
    ModInt operator*(const ModInt& x) const { return ModInt(*this) *= x; }
    ModInt operator/(const ModInt& x) const { return ModInt(*this) /= x; }
    ModInt pow(ll n) const {
        auto x = ModInt(1);
        auto b = *this;
        while (n > 0) {
            if (n & 1) x *= b;
            n >>= 1;
            b *= b;
        }
        return x;
    }
    // compound assignment
    ModInt& operator+=(const ModInt& x) {
        if ((val += x.val) >= MOD) val -= MOD;
        return *this;
    }
    ModInt& operator-=(const ModInt& x) {
        if ((val -= x.val) < 0) val += MOD;
        return *this;
    }
    ModInt& operator*=(const ModInt& x) {
        val = int(ll(val) * x.val % MOD);
        return *this;
    }
    ModInt& operator/=(const ModInt& x) { return *this *= x.inv(); }
    // compare
    bool operator==(const ModInt& b) const { return val == b.val; }
    bool operator!=(const ModInt& b) const { return val != b.val; }
    // I/O
    friend std::istream& operator>>(std::istream& is, ModInt& x) noexcept { return is >> x.val; }
    friend std::ostream& operator<<(std::ostream& os, const ModInt& x) noexcept { return os << x.val; }
};
 
constexpr int MOD = 1e9 + 7;
using mint = ModInt<MOD>;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n,k;
    cin>>n>>k;
    mint ans=0;
    vector<mint> dp(k+1);
    for(int g=k;g>=1;--g){
        dp[g]=mint(k/g).pow(n);
        for(int p=g*2;p<=k;p+=g){
            dp[g]-=dp[p];
        }
        ans+=dp[g]*g;
    }
    cout<<ans;
            
    return 0;
}



Measured memory_bytes: 3704
judge :: Bool -> (String,String) -> String
judge f (ts,fs) = case f of
  True -> ts
  False -> fs

func :: Int -> [Int] -> Bool
func _ [] = True
func n (x:xs)
  | n > x = False
  | n < x = func (x-1) xs
  | otherwise = func x xs

main = do
  _ <- getLine
  line <- getLine
  let
    vals = map read $ words line :: [Int]
    ret = func (vals!!0) vals
  putStrLn $ judge ret ("Yes","No")


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

using namespace std;


int main() {
	int n,ans=0;
	cin >> n;
	vector<int> d(n);

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

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

	ans = d[n / 2] - d[(n / 2) - 1];
	

	cout << ans;

	return 0;
}

Measured memory_bytes: 640
#include <stdio.h>

int main(int argc, char *args[])
{
	int h,w;
	int i,j;

	while(1) {

		scanf("%d %d", &h, &w);

		if( h==0 && w==0 ) break;

		for( i=0; i < h; i++ ) {

			for( j=0;  j < w; j++ ) {
				if( (i+j)%2 == 0 ) {
					printf("#");
				}
				else {
					printf(".");
				}
			}
			printf("\n");

		}
		printf("\n");
	}

	return 0;

}

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

using namespace std;

#define ll long long
#define ull unsigned long long
#define PI acos(-1.0)
#define eps 1e-12
#define fi first
#define se second
#define MEM(a,b) memset((a),(b),sizeof(a))
#define mod(x) ((x)%MOD)
#define pii pair<int,int>
#define wz cout<<"-----"<<endl;
const int INF_INT = 2147483647;
const ll INF_LL = 9223372036854775807LL;
const ull INF_ULL = 18446744073709551615Ull;
const ll P = 92540646808111039LL;

const ll maxn = 2e5 + 10, MOD = 1e9 + 7;
const int Move[4][2] = {-1,0,1,0,0,1,0,-1};
const int Move_[8][2] = {-1,-1,-1,0,-1,1,0,-1,0,1,1,-1,1,0,1,1};

inline int read(){
    int 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;
}
int n;
ll a[maxn];

ll sb(ll it) {
    return it > 0 ? it : -it;
}


ll get(ll x) {
    ll res = 0;
    for (int i = 1;  i <= n; i++) {
        res += sb(a[i] - (x + i));
    } return res;
}

int main(){
     cin>>n;
    for (int i = 1; i <= n; i++) cin>>a[i];
    ll l = -INF_INT,r = INF_INT;
    ll mid,mmid;
    ll res;
    while (l < r) {
        mid = l + r >> 1;
        mmid = mid + r >> 1;
        ll s1 = get(mid);
        ll s2 = get(mmid);
        if (s1 < s2) {
            r = mmid;
        } else l = mid;
        if (r - l == 1) break;
    }
    cout<<min(get(l), get(r))<<endl;
    return 0;
}



Measured memory_bytes: 1792
import sys
I = lambda:map(int,sys.stdin.readline().split())
pr = lambda x:sys.stdout.write(f'{x}\n')
sys.setrecursionlimit(2000000001)

mn = lambda w,x,y,z: min(abs(w)+x,abs(y)+z)
n = ar = dp = 0

def solve(x):
	global n,ar,dp
	if x>=n-2: return dp[x]
	if dp[x] != -1: return dp[x]
	dp[x] = mn(ar[x]-ar[x+1], solve(x+1), ar[x]-ar[x+2], solve(x+2))
	# pr(f'{x} => {dp[x]}')
	return dp[x]

def main():
	global n,ar,dp
	n, ar = *I(), [*I()]
	dp = [-1]*(n-2) + [abs(ar[-2]-ar[-1]),0]
	# pr((n,ar,dp))
	pr(solve(0))

main()

Measured memory_bytes: 99108
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<int,int> P;
const LL mod=998244353;
const LL LINF=1LL<<62;
const LL INF=1<<28;



int main(){
    int b;
    while(cin >> b){
        if(!b) break;
        for (int k = (int)sqrt(2*b); k > 0 ;k--) {
            if((2*b-k*k+k)%(2*k)==0){
                cout << (2*b-k*k+k)/2/k << " " << k << endl;
                break;
            }
        }
    }
    return 0;
}




Measured memory_bytes: 3076
#include<bits/stdc++.h>                   
using namespace std;
int a,n;
string b[105];
int main()
{
	cin>>a>>n;
	for(int s=0;s<a;s++)
	{
		cin>>b[s];
	}
	sort(b,b+a);
	for(int s=0;s<a;s++)
	cout<<b[s];
	cout<<endl;	
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

N, K = map(int, input().split())
V = list(map(int, input().split()))

ans = 0  # 何もしないと0なので、ansの初期値は0


# pick->取り出す操作をする回数(listより多く取り出さないように注意)
for pick in range(min(K+1, N+1)):
    # 右から取り出す数
    for right in range(pick+1):
        left = pick-right  # 左から取り出す数
        pick_list = V[:right]+V[N-left:]

        # queueに戻す操作
        pick_list = sorted(pick_list)
        tmp_ans = sum(pick_list)  # 戻す前の合計値
        rem = min(K-pick, len(pick_list))  # 戻す操作をできる回数
        for i in range(rem):  # 負の値のものをできるだけ戻す
            if pick_list[i] < 0:
                tmp_ans -= pick_list[i]
            else:
                break
        ans = max(tmp_ans, ans)
print(ans)


Measured memory_bytes: 3064
#include <stdio.h>
#define MAX 105
int g[MAX][MAX],d[MAX],f[MAX],t=1;

void dfs(int);

int main(){
  int n,i,j,u,k;
  scanf("%d",&n);
  for(i=1;i<=n;i++){
    scanf("%d%d",&u,&k);
    for(j=1;j<=k;j++) scanf("%d",&g[i][j]);
    g[i][j]=-1;
  }
  for(i=1;i<=n;i++) dfs(i);
  for(i=1;i<=n;i++) printf("%d %d %d\n",i,d[i],f[i]);
  return 0;
}

void dfs(int i){
  int j;
  if(d[i]==0){
    d[i]=t;
    t++;
    for(j=1;g[i][j]!=-1;j++) if(d[g[i][j]]==0) dfs(g[i][j]);
    f[i]=t;
    t++;
  }
}


Measured memory_bytes: 2108
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);

		while(true) {

			String text = sc.next();

			if(text.equals("-")) break;

			int m = sc.nextInt();
			int h[] = new int[m];
			char c[] = text.toCharArray();
			char temp;

			for(int i = 0; i < m; i++) {
				h[i] = sc.nextInt();
			}

			for(int i = 0; i < m; i++) {
				for(int j = 0; j < h[i]; j++) {
					temp = c[0];
					for(int k = 0; k < c.length-1; k++) {
						c[k] = c[k+1];
					}
					c[c.length - 1] = temp;
				}
			}
			System.out.println(c);
		}
	}

}



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

int main()
{
    int a, b; cin >> a >> b;
    int r = 0;

    for(int i = a; i <= b; i++)
    {
        int s = i % 10, t = i / 10000 % 10;
        int u = i / 10 % 10, v = i / 1000 % 10;
        if(s == t && u == v){
            r++;
        }
    }
    cout << r << endl;
}

Measured memory_bytes: 256
d, g = map(int, input().split())
p = []
c = []
ans = 1000000

for i in range(d):
    a, b = map(int, input().split())
    p.append(a)
    c.append(b)

for i in range(1 << d):
    select = []
    for j in range(d):
        if ((i >> j) & 1) == 1:
            select.append(j)

    tans = 0
    npoint = g

    for j in select:
        tans += p[j]
        npoint -= c[j]
        npoint -= (j + 1) * 100 * p[j]

    slv = 0
    slvj = 0
    # selectに入っていない問題の中で得点が最も大きいものを求める
    for j in range(d - 1, -1, -1):
        if j in select:
            continue
        slvj = j
        break

    while npoint > 0:  # 必要なポイントを獲得するまで
        # 1問ずつとく
        slv += 1
        npoint -= (slvj + 1) * 100

    # 存在する100*j点問題の数より解いた問題が多いことになっているとき、
    # この組み合わせはあり得ない
    if slv > p[slvj]:
        continue

    tans += slv
    ans = min(ans, tans)
print(ans)


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

#define rep(i,x,y) for(int (i)=(x);(i)<(y);(i)++)

int main()
{
  while(true){
    int a,l;
    cin>>a>>l;
    if(a==0&&l==0){
      break;
    }

    vector<int> an;
    an.push_back(a);

    string s=to_string(a);
    rep(i,s.size(),l){
      s="0"+s;
    }

    bool flag=false;
    while(flag==false){
      sort(s.rbegin(),s.rend());
      int maxs=stoi(s);
      sort(s.begin(),s.end());
      int mins=stoi(s);

      int ans=maxs-mins;
      rep(i,0,an.size()){
        if(ans==an[i]){
          cout<<i<<" "<<an[i]<<" "<<an.size()-i<<endl;
          flag=true;
          break;
        }
      }
      an.push_back(ans);
      s=to_string(ans);
      rep(i,s.size(),l){
        s="0"+s;
      }
    }
  }

  return 0;
}

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

using namespace std;

void Main() {
    int sx, sy, tx, ty;
    cin >> sx >> sy >> tx >> ty;

    string path = "";
    for (int i = 0; i < tx - sx; ++i) {
        path += "R";
    }
    for (int i = 0; i < ty - sy; ++i) {
        path += "U";
    }
    for (int i = 0; i < tx - sx; ++i) {
        path += "L";
    }
    for (int i = 0; i < ty - sy; ++i) {
        path += "D";
    }
    path += "D";
    for (int i = 0; i < tx - sx + 1; ++i) {
        path += "R";
    }
    for (int i = 0; i < ty - sy + 1; ++i) {
        path += "U";
    }
    path += "L";
    path += "U";
    for (int i = 0; i < tx - sx + 1; ++i) {
        path += "L";
    }
    for (int i = 0; i < ty - sy + 1; ++i) {
        path += "D";
    }
    path += "R";

    cout << path << endl;
}

int main() {
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 3620
a, b, k=map(int, input().split())
L = b - a + 1
if L <= 2 * k:
    for i in range(a, b+1):
        print(i)
else:
    for i in range(a, a + k):
        print(i)
    for i in range(b-k+1, b+1):
        print(i)

Measured memory_bytes: 3060
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AOJ
{
	class Program
	{
		static void Main(string[] args)
		{
			var s = "";
			while ((s = Console.ReadLine()) != null)
			{
				var c = s.Split(' ').Select(d => int.Parse(d)).ToArray();
				int r = 0;
				for (int i = 0; i <= 10; i++)
				{
					if ((c[0] != i && c[1] != i && c[2] != i))
					{
						if (c[0] + c[1] + i < 20)
							r++;
					}
				}
				Console.WriteLine(r > 3 ? "YES" : "NO");
			}
		}
	}
}

Measured memory_bytes: 5644
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Main {

    public static void main(String[] args) throws Exception {

        try {

            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

            String[] weights = br.readLine().split(" ");

            int leftWeight = Integer.parseInt(weights[0]) + Integer.parseInt(weights[1]);
            int rightWeight = Integer.parseInt(weights[2]) + Integer.parseInt(weights[3]);

            String result = "Right";

            if (leftWeight > rightWeight) {
                result = "Left";
            } else if (leftWeight == rightWeight) {
                result = "Balanced";
            }

            System.out.println(result);
        } catch (IOException | NumberFormatException e) {
            e.printStackTrace();
            System.exit(0);
        } catch (final Exception e) {
            e.printStackTrace();
            System.exit(0);
        }
    }
}

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

int main() {
    const int MAX = 1000000;
    bool isPrime[MAX];
    fill_n(isPrime, MAX, true);
    isPrime[0] = isPrime[1] = false;
    for (int i = 4; i < MAX; i += 2) {
        isPrime[i] = false;
    }
    for (int i = 3; i * i <= MAX; i += 2) {
        if (isPrime[i]) {
            for (int j = 2 * i; j < MAX; j += i) {
                isPrime[j] = false;
            }
        }
    }
    while (true) {
        int a, d, n;
        cin >> a >> d >> n;
        if ((a | d | n) == 0) {
            break;
        }
        int count = 0, res = a - d;
        while (count < n) {
            res += d;
            if (isPrime[res]) {
                count++;
            }
        }
        cout << res << endl;
    }
}

Measured memory_bytes: 0
s = input()
MOD = 998244353
cnt_r = []
cnt_b = []
for i in s:
    cnt_r.append(2-int(i))
    cnt_b.append(int(i))
cursum_cnt_r = [0]*(len(s)+1)
cursum_cnt_b = [0]*(len(s)+1)
for i in range(len(s)):
    cursum_cnt_r[i+1] = cursum_cnt_r[i] + cnt_r[i]
    cursum_cnt_b[i+1] = cursum_cnt_b[i] + cnt_b[i]
cursum_cnt_r = cursum_cnt_r + [cursum_cnt_r[-1]]*len(s)
cursum_cnt_b = cursum_cnt_b + [cursum_cnt_b[-1]]*len(s)

#dp[ni][ri]:nこのボールを並べたときに赤色のボールがri個含まれるときの並べ方総数
dp = [[0]*(2*len(s)+1) for i in range(2*len(s)+1)]
dp[0][0] = 1
for ni in range(1,2*len(s)+1):
    for ri in range(0,ni+1):
        if ri == 0:
            if 0 <= ni <= cursum_cnt_b[ni]:
                #青色を選ぶ
                dp[ni][ri] = dp[ni-1][ri]
        elif ri == ni:
            if 0 <= ri <= cursum_cnt_r[ni]:
                #赤色を選ぶ
                dp[ni][ri] = dp[ni-1][ri-1]
        else:
            if 0 <= ri <= cursum_cnt_r[ni] and 0 <= ni-ri <= cursum_cnt_b[ni]:
                dp[ni][ri] += dp[ni-1][ri]
                dp[ni][ri] += dp[ni-1][ri-1]
        dp[ni][ri] %= MOD 

print(max(dp[2*len(s)]))

Measured memory_bytes: 166620
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iostream>
#include <istream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <tuple>
#include <iomanip>
#include <climits>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
//typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define revrep(i, n) for(ll i = (n)-1; i >= 0; i--)
#define pb push_back
#define f first
#define s second
#define chmin(x, y) x = min(x, y);
#define chmax(x, y) x = max(x, y);

//const ll INFL = LLONG_MAX;//10^18 = 2^60
const ll INFL = 1LL<<60;
//const int INF = INT_MAX;
const ll INF = 1 << 30;//10^9
ll MOD = 1000000007;
//ll MOD = 998244353;

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

void pres(double A, ll x = 10){cout << fixed << setprecision(x) << A << endl;}
void BinarySay(ll x, ll y = 60){rep(i, y) cout << (x>>(y-1-i) & 1); cout << endl;}
ll cnt_bit(ll x){return __builtin_popcountll(x);}

ll pow_long(ll x, ll k){
  ll res = 1;
  while(k > 0){
    if(k % 2) res *= x;
    x *= x; k /= 2;
  }
  return res;
}

ll pow_mod(ll x, ll k){
  ll res = 1;
  while(k > 0){
    if(k % 2){
      res *= x; res %= MOD;
    }
    x *= x; x %= MOD;
    k /= 2;
  }
  return res;
}

ll inverse(ll x){return pow_mod(x, MOD - 2);};

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

ll lcm(ll x, ll y){return x / gcd(x, y) * y;};

//コンビネーション
const int MAXcomb = 200010;
ll fac[MAXcomb], finv[MAXcomb], inv[MAXcomb];
//facはn!,finvは1/n!
//invは逆元
void COMinit(){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for(int i = 2; i < MAXcomb; i++){
        fac[i] = fac[i-1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD/i) % MOD;
        finv[i] = finv[i-1] * inv[i] % MOD;
    }
}
ll comb(int n, int k){
    if(n < k) return 0;
    if(n < 0 || k < 0) return 0;
    return fac[n] * finv[k] % MOD * finv[n-k] % MOD;
}

void solve(){
  ll N;
  cin >> N;
  vector<ll> A(N), B(N);
  rep(i, N) cin >> A[i];
  rep(i, N) cin >> B[i];
  rep(i, N){
    A[i]--;
    B[i]--;
  }
  vector<ll> v;
  rep(i, N) v.pb(i);
  ll a, b;
  ll cnt = 0;
  do {
    bool la = 1, lb = 1;
    rep(i, N) if(v[i] != A[i]) la = 0;
    rep(i, N) if(v[i] != B[i]) lb = 0;
    if(la) a = cnt;
    if(lb) b = cnt;
    cnt++;
  } while (std::next_permutation(v.begin(), v.end()));
  cout << abs(a - b) << endl;
}


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


Measured memory_bytes: 256
package main

import "fmt"

var n, a, b int
var ans int

func main() {
	fmt.Scan(&n, &a, &b)
	ans = n/(a+b)*a + min(a, n%(a+b))

	fmt.Println(ans)
}

func min(nums ...int) int {
	ret := nums[0]
	for _, num := range nums {
		if ret > num {
			ret = num
		}
	}
	return ret

}
func max(nums ...int) int {
	ret := nums[0]
	for _, num := range nums {
		if ret < num {
			ret = num
		}
	}
	return ret
}


Measured memory_bytes: 512
#include <iostream>
using namespace std;
int main(){
    long long int i,j;
    cin>>i>>j;
    if(i>0){
      cout<<"Positive" ;return 0; 
    } 
    if(i==0||j==0){
        cout<<"Zero";return 0;
    }
    if(i<0&&j>0){
        cout<<"Zero";return 0;
    }
    if(j==i) cout<<"Negative";
    int k=j-i;
    if(k%2==1) cout<<"Positive";
    else cout<<"Negative";
}

Measured memory_bytes: 256
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
#[allow(unused_imports)]
use std::io::{BufWriter, Write};

// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

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

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

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

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

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

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

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

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

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

fn is_prime(x: i32) -> bool {
    for i in 2..x {
        if i*i > x {
            break;
        }

        if x % i == 0 {
            return false;
        }
    }

    true
}

fn solve() {
    input!(
        x: i32,
    );

    let mut x = x;

    loop {
        if is_prime(x) {
            println!("{}", x);
            return;
        }
        x += 1;
    }
}

fn main() {
    let stack_size = 1 << 28;
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}

Measured memory_bytes: 8572
#include <bits/stdc++.h>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <limits>
#include <string>
#include <vector>

using namespace std;

const long long INF = 1LL << 60;

//各桁の和を出力
long long Sum(long long n) {
  long long m = 0;
  while (n) {
    m += n % 10;
    n /= 10;
  }
  return m;
}

const int MAX = 510000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

void Comuse() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++) {
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}

#define comuse Comuse()
// nCk(comuseを使え)
long long combi(int n, int k) {
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
// pCk(comuseを使え)
long long perm(int n, int k) {
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] % MOD) % MOD;
}

//最小公倍数(aとbの)
long long lcm(long long a, long long b) {
  long long n;
  n = a / __gcd(a, b) * b;
  return n;
}

// auto A = div(n)
vector<long long> div(long long n) {
  vector<long long> ret;
  for (long long i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n) {
        ret.push_back(n / i);
      }
    }
  }
  sort(ret.begin(), ret.end());
  return ret;
}

//(aのn乗をmodで割ったあまり)
long long modpow(long long a, long long n, long long mod) {
  long long ans = 1;
  while (n > 0) {
    if (n & 1) {
      ans = ans * a % mod;
    }

    a = a * a % mod;

    n >>= 1;
  }

  return ans;
}

void solve();

const int MAX_N = 131072;
// segment tree
int NN;
int seg[MAX_N * 2 - 1];
void seguse() {
  for (int i = 0; i < 2 * NN - 1; i++) {
    seg[i] = INT_MAX;
  }
}

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(20) << fixed;
  solve();
}

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

int K;
int N;
vector<int> A(2000000);
void solve() {
  cin >> K >> N;
  for(int i = 0; i < N; i++){
    cin >> A.at(i);
  }
  int Max = A.at(0) + (K - A.at(N-1));
  for(int i = 0; i < N-1; i++){
    if(A.at(i + 1) - A.at(i) > Max){
      Max = A.at(i + 1) - A.at(i);
    }
  }
  cout << K - Max <<endl;
}

Measured memory_bytes: 8064
#include<stdio.h>
int main(void)
{
	int sheet[101][101];
	int r,c;
	int i,j,k,temp = 0;
	scanf("%d %d",&r,&c);
	for(i = 0;i < r;i++){
		for(j = 0;j < c;j++){
			scanf("%d",&sheet[i][j]);
		}
	}
	for(i = 0;i < r;i++){
		for(j = 0;j < c;j++){
			printf("%d ",sheet[i][j]);
			temp += sheet[i][j];
		}
		printf("%d\n",temp);
		temp = 0;
	}
	for(i = 0;i < c;i++){
		for(j = 0;j < r;j++){
			temp += sheet[j][i];
		}
		printf("%d ",temp);
		temp = 0;
	}
	for(i = 0;i < c;i++){
		for(j = 0;j < r;j++){
			temp += sheet[j][i];
		}
	}
	printf("%d\n",temp);
	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main( void )
{
	int n;
	cin >> n;
	for ( int i = 0; i < n; i++ )
	{
		string train;
		cin >> train;

		string kotae = "";
		int c = 1;
		kotae += train[0];

		while ( c < train.size() )
		{
			if ( train[c] == '-' )
			{
				if ( kotae.find( train[c+2] ) == string::npos )
				{
					kotae += train[c+2];
				}
			}
			else if ( train[c] == '<' )
			{
				if ( kotae.find( train[c+2] ) == string::npos )
				{
					kotae = train[c+2] + kotae;
				}
			}
			c += 3;
		}
		cout << kotae << endl;
	}
	return 0;
}

Measured memory_bytes: 0
from collections import Counter
import sys
input = sys.stdin.readline

N = int(input())
As = list(map(int, input().split()))
Q = int(input())
BCs = [tuple(map(int, input().split())) for _ in range(Q)]

cnt = Counter(As)
ans = sum(As)

anss = []
for B, C in BCs:
    num = cnt[B]
    diff = num * (C-B)
    ans += diff
    anss.append(ans)
    cnt[B] -= num
    cnt[C] += num

print('\n'.join(map(str, anss)))


Measured memory_bytes: 45660
#include "iostream"
#include "vector"
using namespace std;

int main()
{
	int security_code = 0;
	cin >> security_code;
	int temp = security_code;

	vector<int> v;
	int den = 1000;
	for (auto i = 0; i < 4; ++i)
	{
		auto res = temp / den;
		temp -= (res * den);
		den /= 10;
		v.push_back(res);
	}

	for (auto i = 1; i < 4; ++i)
	{
		if (v[i - 1] == v[i])
		{
			cout << "Bad";
			return 0;
		}
	}
	cout << "Good";
    return 0;
}


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

int main() {
  int N, D, X;
  cin >> N >> D >> X;
  vector<int> A(N);
  for (int i=0; i<N; i++) cin >> A.at(i);
  int choco = 0;
  for (int i=0; i<N; i++)
    choco += (D-1) / A.at(i) + 1;
  cout << choco + X << endl;
}

Measured memory_bytes: 256
s=gets.chop
p=gets.chop
def bubun(s,p)
    p.size.times do
        if s.include?(p)
            return true
        end
        s=s.split("").rotate.join
    end
    return false
end
if bubun(s,p)
    puts "Yes"
else
    puts "No"
end


Measured memory_bytes: 6916
import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws Exception {
        int inputANum;
        int inputBNum;
        int inputCNum;

        Scanner scanner = new Scanner(System.in);
        String inputData = scanner.nextLine();
        scanner.close();

        String[] editInputData = inputData.split(" ");

        inputANum = Integer.parseInt(editInputData[0]);
        inputBNum = Integer.parseInt(editInputData[1]);
        inputCNum = Integer.parseInt(editInputData[2]);

        if ((inputANum == inputBNum && inputBNum == inputCNum) || (inputANum != inputBNum && inputBNum != inputCNum && inputANum != inputCNum)) {
            System.out.println("No");
        } else {
            System.out.println("Yes");
        }

    }
}

Measured memory_bytes: 24020
H,W=map(int,input().split())
N = int(input())
a = list(map(int,input().split()))
hoge=[]
for i in range(N):
        hoge.extend([i+1]*a[i])
c=[hoge[j:j+W] for j in range(0,H*W+1,W)]
for k in range(H):
    if k%2==0:
        print(' '.join(map(str,c[k])))
    else:
        print(' '.join(map(str,c[k][::-1])))

Measured memory_bytes: 3572
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
using namespace std;

using ll = long long;
using P = pair<int, int>;

const int INF = 1e9;
const int MOD = 1e9 + 7;

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

int main() {
  // 入力
  string s, t;
  cin >> s >> t;

  sort(s.begin(), s.end());
  sort(t.begin(), t.end());
  reverse(t.begin(), t.end());

  // 解答
  cout << (s < t ? "Yes" : "No") << endl;

  return 0;
}


Measured memory_bytes: 256
N = int(input())
P = list(map(int, input().split()))
cnt = 0
for i in range(2, len(P)):
    P0 = P[i-2]
    P1 = P[i-1]
    P2 = P[i]
    if P0 < P1 < P2 or P2 < P1 < P0:
        cnt += 1

print(cnt)

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <tuple>
using namespace std;

int main() {
    int out1 = 0; // 0 for '0'
    int out2 = 0; // 0 for '1'
    string s;
    cin >> s;
    for ( int i = 0; i < s.length(); i++ ) {
        if ( i % 2 == 0 ) {
            if ( s[i] == '1' ) {
                out1++;
            } else {
                out2++;
            }
        } else {
            if ( s[i] == '1' ) {
                out2++;
            } else {
                out1++;
            }
        }
    }
    cout << (out1 > out2 ? out2 : out1) << endl;
    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } }
#define INF 2e9
#define MOD 1000000007
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<string> vs;
typedef pair<int, int> p;
typedef priority_queue<p> pq;
typedef priority_queue<p, vector<p>, greater<p>> gpq;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int a, b, c, k;
    cin >> a >> b >> c >> k;

    int maxv = max(a, max(b, c));
    int ans = a + b + c - maxv;

    REP(i, k)
    {
        maxv *= 2;
    }

    cout << ans + maxv << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <string>
#include <vector>
/* 変数i を n回繰り返すマクロ */
#define rep(i,n) for (int i = 0;i < (n);i++)
typedef long long ll;
using namespace std;
using Graph = vector<vector<int>>;
/* map_for : mapでfor文を回す */
/* gcd_lcm : 最大公倍数 & 最小公約数 */
int main()
{
    cout << fixed << setprecision(10);//小数点以下10桁出力
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    while(1){
        c -= b;
        if(c <= 0){
            cout << "Yes" << endl;
            break;
        }
        a -= d;
        if(a <= 0){
            cout << "No" << endl;
            break;
        }
    }
    return 0;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define rep(i, n) for(ll i=0;i<n;i++)
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (b>a) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
//const long long INF = 2LL << 60;

using ll = long long;
using P = pair<ll, ll>;

int main(int argc, char const *argv[]){
    ll n;
    cin >> n;
    vector<ll> a(n), b(n);
    rep(i,n){
        cin >> a[i] >> b[i];
    }
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    if(n%2==1){
        // 奇数
        ll c=n/2;
        cout << b[c]-a[c]+1 << endl;
        return 0;
    }else{
        // 偶数
        ll c=n/2-1;
        ll b1, b2, e1, e2;
        b1=a[c]*2;
        b2=a[c+1]*2;
        e1=b[c+1]*2;
        e2=b[c]*2;
        cout << ((e1+e2)/2) - ((b1+b2)/2)+1 << endl;
        return 0;
    }
    return 0;
}




Measured memory_bytes: 6424
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define all(v) v.begin(), v.end()
#define ll long long
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<long long>;
using vvll = vector<vll>;

//snippets:tmp,cl,cvl,cs,co,coy,con,cov

int main(){
    ll n;
    cin >> n;
    vll d(n,0);
    ll a;
    rep(i,n-1){
        cin>>a;
        d[a-1]++;
    }
    rep(i,n){
        cout<<d[i]<<endl;
    }
}

Measured memory_bytes: 4840
use std::io::*;
use std::str::FromStr;

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let r = read::<i64>();
    let d = read::<i64>();
    let mut x = read::<i64>();
    for _i in 0..10 {
        x = r * x - d;
        println!("{}", x);
    }
}


Measured memory_bytes: 4352
import sys
from math import gcd

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


class Eratosthenes:
    def __init__(self, n):
        self.n = n
        self.min_factor = [-1] * (n + 1)
        self.min_factor[0], self.min_factor[1] = 0, 1

    def get_primes(self):
        primes = []
        is_prime = [True] * (self.n + 1)
        is_prime[0] = is_prime[1] = False
        for i in range(2, self.n + 1):
            if not is_prime[i]:
                continue
            primes.append(i)
            self.min_factor[i] = i
            for j in range(i * 2, self.n + 1, i):
                is_prime[j] = False
                if self.min_factor[j] == -1:
                    self.min_factor[j] = i
        return primes

    def prime_factorization(self, n):
        res = []
        while n != 1:
            prime = self.min_factor[n]
            exp = 0
            while self.min_factor[n] == prime:
                exp += 1
                n //= prime
            res.append([prime, exp])
        return res


def resolve():
    n = int(input())
    A = list(map(int, input().split()))
    MAX = max(A)
    tot_gcd = A[0]
    for a in A:
        tot_gcd = gcd(tot_gcd, a)

    if tot_gcd != 1:
        print("not coprime")
    else:
        er = Eratosthenes(MAX)
        er.get_primes()
        check = [False] * (MAX + 1)
        for a in A:
            for p, _ in er.prime_factorization(a):
                if not check[p]:
                    check[p] = True
                else:
                    print("setwise coprime")
                    exit()
        print("pairwise coprime")


if __name__ == '__main__':
    resolve()


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

int main(){
	ll H, W; cin >> H >> W;
	if(H == 1 || W == 1){ cout << 1 << endl; return 0; }
	if(H * W % 2 == 0) cout << H*W/2 << endl;
	else cout << (H*W)/2 + 1 << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef pair<int, int> Pint;
typedef pair<int64_t, int64_t> Pll;

int main() {
    int N;
    cin >> N;
    for (int i = 0; i < N; i++){
        int a;
        cin >> a;
        if (a % 2 == 0){
            if (a % 3 != 0 && a % 5 != 0){
                cout << "DENIED" << endl;
                return 0;
            }
        }
    }
    cout << "APPROVED" << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define endl "\n"
#define pb push_back
#define ll long long
#define d1(x)  cerr << #x << "--> " << x << endl
#define d2(x, y)  cerr << #x << "--> " << x << " | " << #y << "--> " << y <<endl
#define d3(x, y,z)  cerr << #x << "--> " << x << " | " << #y << "--> " << y <<" | " << #z << "--> "<< z<< endl
#define vpll vector<pair<ll,ll>>
#define F first
#define S second
#define T ll tt; cin>>tt; while(tt--)
using namespace std;

ll mode=pow(10,9)+7;
bool cmp(pair<ll,ll> x, pair<ll, ll> y){
    return x.S<y.S;
}
//ll n,k,m;


int main(){ 
    
  //  #ifndef ONLINE_JUDGE
//    freopen("input.txt", "r", stdin);
  //  #endif
    
    ios::sync_with_stdio(0);
    cin.tie(0);
	
	ll a,b;
	cin>>a>>b;
	ll c=__gcd(a,b);
	ll d=a*b;
	d=d/c;
	cout<<d<<endl;	
    return 0;
}

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

int main() {
    int S;
    cin >> S;
    
     int h=S/(60*60);
     
     int x=S-h*3600;
     
     int m=x/60;
     
     int s=x-m*60;
     
     cout << h << ":"<< m << ":" << s << endl;
     
     
    }



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

const int N = 1e5+5;
int n, a[N], i;

int main()
{
    //freopen("a.inp","r",stdin);

    scanf("%d",&n);
    for( i=1; i<=n; ++i) scanf("%d",a+i);
    for( i=n-1; i>=1; --i) if (a[i] > a[i+1])
        if (--a[i] > a[i+1]) break;
    if (i == 0) puts("Yes"); else puts("No");
}


Measured memory_bytes: 640
import sys
from itertools import accumulate
N, M, Q = map(int, sys.stdin.readline().split())
 
LR = [[0 for _ in range(N-i)] for i in range(N)]
for i in range(M):
  L, R = map(int, sys.stdin.readline().split())
  LR[L-1][R-L] += 1
 
for i in range(N-2,-1,-1):
  acc = accumulate(LR[i])
  next(acc)
  for j in range(1, N-i):
    LR[i][j] = next(acc) + LR[i+1][j-1]
 
for i in range(Q):
  p, q = map(int, sys.stdin.readline().split())
  sys.stdout.write(str(LR[p-1][q-p])+"\n")


Measured memory_bytes: 8668
n,m = map(int,input().split())
ans = 0
for i in range(1,int(m**0.5)+1):
  if m % i == 0 and m // i >= n:
    ans = max(ans,i)
  if m % i == 0 and i >= n:
    ans = max(ans,m//i)
print(ans)

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

const int dx[2] = {1, 0};
const int dy[2] = {0, 1};

int main() {
    int H, W;
    cin >> H >> W;
    vector<string> field(H);
    rep(i, H) cin >> field[i];

    //dp[i][j] := i+1行j+1列のマスに到達するまでに白黒が入れ替わる最小回数 
    vector<vector<int>> dp(H, vector<int>(W, INT_MAX));
    if(field[0][0] == '#') dp[0][0] = 1;
    else dp[0][0] = 0;

    rep(i, H){
        rep(j, W){
            //縦方向
            if(i > 0){
                if(field[i-1][j] != field[i][j]){
                    dp[i][j] = min(dp[i][j], dp[i-1][j]+1);
                }else{
                    dp[i][j] = min(dp[i][j], dp[i-1][j]);
                }
            }
            //横方向
            if(j > 0){
                if(field[i][j-1] != field[i][j]){
                    dp[i][j] = min(dp[i][j], dp[i][j-1]+1);
                }else{
                    dp[i][j] = min(dp[i][j], dp[i][j-1]);
                }
            }       
        }
    }
    //答えは (白黒入れ替わりの回数)/2 の切り上げ
    cout << (dp[H-1][W-1]+1)/2 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define SZ(x) (int)(x.size())
#define REP(i, n) for(int i=0;i<(n);++i)
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define RREP(i, n) for(int i=(int)(n)-1;i>=0;--i)
#define RFOR(i, a, b) for(int i=(int)(b)-1;i>=(a);--i)
#define ALL(a) a.begin(),a.end()
#define DUMP(x) cerr<<#x<<" = "<<(x)<<endl
#define DEBUG(x) cerr<<#x<<" = "<<(x)<<" (L"<<__LINE__<<")"<< endl;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using P = pair<int, int>;
const double eps = 1e-8;
const ll MOD = 1000000007;
const int INF = INT_MAX / 2;
const ll LINF = LLONG_MAX / 2;
template <typename T1, typename T2>
bool chmax(T1 &a, const T2 &b) {
    if (a < b) { a = b; return true; }
    return false;
}
template <typename T1, typename T2>
bool chmin(T1 &a, const T2 &b) {
    if (a > b) { a = b; return true; }
    return false;
}
template<typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
    os << "[";
    REP(i, SZ(v)) {
        if (i) os << ", ";
        os << v[i];
    }
    return os << "]";
}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const map<T1, T2> &mp) {
    os << "{";
    int a = 0;
    for (auto &tp : mp) {
        if (a) os << ", "; a = 1;
        os << tp;
    }
    return os << "}";
}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) {
    os << p.first << ":" << p.second;
    return os;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    for (;;) {
        char trump; cin >> trump;
        if (trump == '#') break;
        vector<vector<string>> cards(4, vector<string>(13));
        REP(i, 4) REP(j, 13) cin >> cards[i][j];

        map<char,int> ord;
        FOR(i, 2, 10) ord[i + '0'] = i;
        ord['T'] = 10;
        ord['J'] = 11;
        ord['Q'] = 12;
        ord['K'] = 13;
        ord['A'] = 14;

        vi win(4);

        int leader = 0;
        REP(j, 13) {
            bool playedTrump = 0;
            REP(i, 4) if (cards[i][j][1] == trump) playedTrump = 1;
            int ma = 0, maxI = -1;
            char suit = cards[leader][j][1];
            FOR(i, 0, 4) {
                int id = (i + leader) % 4;
                if (playedTrump and cards[id][j][1] != trump or !playedTrump and cards[id][j][1] != suit) continue;
                if (chmax(ma, ord[cards[id][j][0]])) maxI = id;
            }
            ++win[maxI];
            leader = maxI;
        }
        if (win[0] + win[2] > win[1] + win[3]) cout << "NS " << win[0] + win[2] - 6 << endl;
        else cout << "EW " << win[1] + win[3] - 6 << endl;
    }

    return 0;

}



Measured memory_bytes: 3044