akhauriyash/Code-Regression huggingface dataset:
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Jaynil
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        DChristmas solver = new DChristmas();
        solver.solve(1, in, out);
        out.close();
    }

    static class DChristmas {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            long x = in.nextLong();
            long ans = 0;
            long t[] = new long[51];
            long p[] = new long[51];
            long b[] = new long[51];
            p[0] = 1;
            t[0] = 1;
            for (int i = 1; i <= 50; i++) {
                p[i] = 2 * p[i - 1] + 1;
                b[i] = 2 * b[i - 1] + 2;
                t[i] = p[i] + b[i];
            }
            boolean patty = true;
            while (n > 0 && x > 0) {
                x--;
                if (x >= t[n - 1]) {
                    if (x >= t[n - 1] + 1) {
                        x -= t[n - 1] + 1;
                        ans += p[n - 1];
                        if (patty) {
                            ans++;
                            patty = false;
                        } else {
                            patty = true;
                        }
                        x++;
                        continue;
                    } else if (x == t[n - 1]) {
                        x -= t[n - 1];
                        ans += p[n - 1];
                        break;
                    }

                } else {
                    n--;
                    patty = true;
                }
            }
            out.println(ans);

        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

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

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

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

    }
}



Measured memory_bytes: 23380
import java.util.Scanner;

class Main {
  private static final int mod = 2019;
  private static void solve(long l, long r) {
    if (r - l >= 2018) {
      System.out.println(0);
      return;
    }
    Long min = null;
    for (long i = l; i <= r; i++) {
      for (long j = i + 1; j <= r; j++) {
        long m = (i * j) % mod;
        if (min == null || min > m) min = m;
      }
    }
    System.out.println(min);
  }
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    long l = sc.nextLong();
    long r = sc.nextLong();
    solve(l, r);
  }
}

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

word_L = []
for val in range(n):
    new_word = input()
    word_L.append(new_word)

if len(word_L) != len(set(word_L)):
    print("No")
    exit()

for val in range(1,n):

    if word_L[val-1][-1] != word_L[val][0]:
        print("No")
        exit()
    #print(word_L[val-1][-1],word_L[val][0])

print("Yes") 

Measured memory_bytes: 38384
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
using namespace std;
#define REP(i, j) for(int i = 0; i < (int)(j); ++i)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
#define X real()
#define Y imag()
const double EPS = 1e-8;
const double INF = 1e12;
typedef complex<double> P;
namespace std {
  bool operator < (const P& a, const P& b) {
    return real(a) != real(b) ? real(a) < real(b) : imag(a) < imag(b);
  }
}

//外積
double cross(const P& a, const P& b) {
  return imag(conj(a)*b);
}

//内積
double dot(const P& a, const P& b) {
  return real(conj(a)*b);
}

//線 (線分)
struct L : public vector<P> {
  L(const P &a, const P &b) {
    push_back(a); push_back(b);
  }
};

//交点
P crosspoint(const L &l, const L &m) {
  double A = cross(l[1] - l[0], m[1] - m[0]);
  double B = cross(l[1] - l[0], l[1] - m[0]);
  if (abs(A) < EPS && abs(B) < EPS) return m[0]; // same line
  if (abs(A) < EPS) exit(1); // !!!PRECONDITION NOT SATISFIED!!!
  return m[0] + B / A * (m[1] - m[0]);
}

int main() {
  int Q; cin >>Q;
  REP(q, Q){
    int x0, y0, x1, y1, x2, y2, x3, y3;
    scanf("%d %d %d %d %d %d %d %d", &x0, &y0, &x1, &y1, &x2, &y2, &x3, &y3);
    L l1 = L(P(x0, y0), P(x1, y1)), l2 = L(P(x2, y2), P(x3, y3));
    P ans = crosspoint(l1, l2);
    printf("%.10lf %.10lf\n", ans.X, ans.Y);
  }
  
  return 0;
}

Measured memory_bytes: 1272
n,x,y=map(int, input().split())
cnts=[0]*n
for i in range(1,n+1):
    for j in range(1,i):
        mn=min(abs(i-j),abs(i-x)+abs(j-y)+1,abs(i-y)+abs(j-x)+1)
        cnts[mn]+=1
for ci in cnts[1:]:
    print(ci)


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

int main(void){
    int ans=0;
    char s[4],t[4];
    cin >> s >> t;
    for (int i=0; i<3; i++){
        if (s[i]==t[i]){
            ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ft first
#define sc second
#define pt(sth) cout << sth << "\n"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
template<class T>bool chmax(T &a, const T &b) {if(a<b) {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;}
static const ll INF=1e18;
static const ll MAX=101010;
static const ll MOD=1e9+7;

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


ll N, a, b, c, d;
map<ll, ll> mem;

ll rec(ll n) {
  if(n==1) return d;
  if(mem[n]!=0) return mem[n];
  
  ll res=INF;
  
  if(n*d>0) res=n*d;
  
  for(ll k=n-1; k<=n+1; k++) {
    if(k<=0) continue;
    if(k%2==0) chmin(res, rec(k/2)+a+abs(k-n)*d);
  }
  for(ll k=n-2; k<=n+2; k++) {
    if(k<=0) continue;
    if(k%3==0) chmin(res, rec(k/3)+b+abs(k-n)*d);
  }
  for(ll k=n-4; k<=n+4; k++) {
    if(k<=0) continue;
    if(k%5==0) chmin(res, rec(k/5)+c+abs(k-n)*d);
  }
  
  
  return mem[n]=res;
  
}


int main(void) {
  ll i, j, k;
  
  ll T;
  cin >> T;
  
  
  for(i=0; i<T; i++) {
    mem.clear();
    cin >> N >> a >> b >> c >> d;
    pt(rec(N));
  }
  
  
  
  
  
}
 
 




Measured memory_bytes: 4424
import java.util.*;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc=new Scanner(System.in);
		String s=sc.next();
		int count=0;
		for(int i=0;i<3;i++) {
			if(s.charAt(i)=='1') {
				count++;
			}
		}
		System.out.println(count);

	}

}


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

int main() {
  
  int a, b, c;
  cin >> a >> b >> c;
 
  if (a == b && a != c) cout << "Yes";
  else if (b == c && b != a) cout << "Yes";
  else if (c == a && c != b) cout << "Yes";
  else cout << "No";
  
}


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

int A[100005], B[100005];

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

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

    for(int i=1; i<=N; i++)
        cin >> B[i];
    
    long long ans = 0;

    for(int i=1; i<=N; i++)
    {
        if(B[i] <= A[i])
            ans += B[i];
        else
        {
            ans += A[i];
            B[i] -= A[i];
            ans += min(B[i], A[i+1]);
            A[i+1] -= min(B[i], A[i+1]);
        }
    }

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


Measured memory_bytes: 1024
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <ios>
#include <iomanip>
#include <numeric>

#define all(x) (x).begin(),(x).end()
typedef long long ll;
using namespace std;
const long long LINF =1e18;
const int INF = 1e9;


int main() {
    int n;
    int x;
    cin>>n>>x;
    int ans = 0;

    int d_last = 0;
    if(d_last < x) ans++;
    for (int i = 0; i < n; ++i) {
        int l;
        cin>>l;
        int d = d_last + l;
        if(d <= x) ans ++;
        d_last = d;
    }

    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp setprecision
#define pb(x) push_back(x)
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<ld, ld> pdd;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const int inf = 1e8;
const ll INF = 1e16;
const string alpha = "abcdefghijklmnopqrstuvwxyz";

int R, C;

int judge(pii p){
    int x = p.first, y = p.second;
    if(x == 0) return y;
    if(y == C) return C+x;
    if(x == R) return R+2*C-y;
    if(y == 0) return 2*(R+C)-x;
    return -1;
}

int main(){
    int N;
    cin >> R >> C >> N;
    map<int, int> mp;
    vector<int> vec;
    rep(i, N){
        pii a, b;
        cin >> a.first >> a.second >> b.first >> b.second;
        int A = judge(a), B = judge(b);
        if(A == -1 || B == -1) continue;
        mp[A] = B, mp[B] = A;
        vec.pb(A), vec.pb(B);
    }
    sort(vec.begin(), vec.end());
    bool ans = true;
    priority_queue<int, vector<int>, greater<int> > que;
    for(auto &e: vec){
        if(mp[e] < e) que.pop();
        else{
            if(que.empty()){
                que.push(mp[e]);
            }
            else{
                if(mp[e] > que.top()){
                    ans = false;
                    break;
                }
                que.push(mp[e]);
            }
        }
    }
    if(ans) cout << "YES" << endl;
    else cout << "NO" << endl;
}

Measured memory_bytes: 10868
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<algorithm>
#include<cmath>
#include<set>
using namespace std;
typedef pair<int,int> P;


int main(){
    int N;
    cin>>N;
    int x[501];
    int res[250001]={};
    P dat[500];
    for(int i=1;i<=N;i++){
        cin>>x[i];
        dat[i-1]=P(x[i],i);
        res[x[i]]=i;
    }
    sort(dat,dat+N);
    int j=0;
    bool flag=true;
    for(int i=0;i<N;i++){
        int pos = dat[i].first;
        int num = dat[i].second;
        for(int s=1;s<=num-1;s++){
            if(res[j+1]==0){
                res[j+1]=num;
                j++;
            }else{
                j++;
                s--;
            }
        }
        if(j>pos){
            flag = false;
            break;
        }
    }
    j=N*N+1;
    for(int i=N-1;i>=0;i--){
        int pos = dat[i].first;
        int num = dat[i].second;
        for(int s=num+1;s<=N;s++){
            if(res[j-1]==0){
                res[j-1]=num;
                j--;
            }else{
                j--;
                s--;
            }
        }
        if(j<pos){
            flag = false;
            break;
        }
    }
    if(flag){
        cout<<"Yes"<<endl;
        for(int i=1;i<=N*N;i++){
            cout<<res[i]<<endl;
        }
    }else{
        cout<<"No"<<endl;
    }
    
    
    
    
    return 0;
}


Measured memory_bytes: 2304
#include<iostream>
#include<map>
#include<vector>
using namespace std;

long long int parent[300002], size[300002];
long long int  find(long long int v)
{
	if(v == parent[v])
	return v;
	return parent[v] = find(parent[v]);
}
void uni(long long int a, long long int b)
{
	long long int s = find(a), s1 = find(b);
	if(s!=s1)
	{
	if(size[s1]>size[s])
     {
     	parent[s] = s1; 
     	size[s1]+=size[s];
	 }
	 else
	 {
	 	parent[s1] = s;
	 	size[s]+=size[s1];
	 }
	 }
}
main()
{
	long long int n, m, m1;
	cin >> n >> m >> m1; 
	long long int i;
	map<long long int, long long int>blocks, fr;
	vector<long long int>v[n+3];
	for(i=0;i<=n;i++)
	{
		size[i] = 1;
	parent[i] = i;
	}
	for(i=0;i<m;i++)
	{
		long long int a, b;
		cin >> a >> b;
		fr[a]++;
		fr[b]++;
		uni(a, b);
	}
	for(i=0;i<m1;i++)
	{
	long long int a, b;
	cin >> a >> b;
	 v[a].push_back(b);
	 v[b].push_back(a);
	}
	
	for(i=1;i<=n;i++)
	{
		long long int p = find(i);
		long long int sz = size[p];
 	long long int ans = sz-fr[i];
	 for(long long int j=0;j<v[i].size();j++)
 	{
 		long long int par = find(v[i][j]);
 		if(p==par)
 		ans--;
	 }
	 cout << ans-1 << " ";
}
 	
	
	return 0;
}

Measured memory_bytes: 15744
#include <iostream>

 

using namespace std;

 

int main() 
{
    int i, x;
    for(i=1; i<=10000; i++)
    {
        cin >> x;
        cout << "Case "<< i << ": " << x << endl; 
        if( x==0 )
        {
            break;
        }

    }
    return 0;
}


Measured memory_bytes: 3068
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace ABC114A
{
    class Program
    {
        static void Main(string[] args)
		{
			int x = int.Parse(Console.ReadLine());
 
			if ((x == 3) || (x == 5) || (x == 7))
				Console.WriteLine("YES");
			else Console.WriteLine("NO");
 
			Console.ReadKey();
        }
    }
}

Measured memory_bytes: 11092
import sys

sys.setrecursionlimit(10 ** 8)
ini = lambda: int(sys.stdin.readline())
inm = lambda: map(int, sys.stdin.readline().split())
inl = lambda: list(inm())
ins = lambda: sys.stdin.readline().rstrip()
debug = lambda *a, **kw: print("\033[33m", *a, "\033[0m", **dict(file=sys.stderr, **kw))

X, Y = inm()
INF = 1 << 50


def solve():
    ans = INF
    for x, y, c in [(X, Y, 0), (-X, Y, 1), (X, -Y, 1), (-X, -Y, 2)]:
        if y < x:
            continue
        ans = min(ans, c + y - x)
    return ans


print(solve())


Measured memory_bytes: 9220
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>

using namespace std;

#define rep(i,j) REP((i), 0, (j))
#define REP(i,j,k) for(int i=(j);(i)<(k);++i)
#define BW(a,x,b) ((a)<=(x)&&(x)<=(b))
#define ALL(v) (v).begin(), (v).end()
#define LENGTHOF(x) (sizeof(x) / sizeof(*(x)))
#define AFILL(a, b) fill((int*)a, (int*)(a + LENGTHOF(a)), b)
#define MP make_pair
#define PB push_back
#define F first
#define S second
#define INF 1 << 30
#define EPS 1e-10

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

int n, f[201];

int main(){
  while(scanf("%d", &n) && n){
    memset(f, 0, sizeof(f));
    vi t, h;
    int a;
    rep(i, n){
      scanf("%d", &a);
      f[a] = 1;
    }
    REP(i, 1, 2*n+1){
      if(f[i]) t.PB(i);
      else h.PB(i);
    }

    int field = 0;
    while(!t.empty() && !h.empty()){
      rep(i, t.size()){
	if(t[i] <= field) continue;
	field = t[i];
	t.erase(t.begin()+i);
	goto jamp;
      }
      field = 0;
    jamp:
      if(t.empty()) break;

      rep(i, h.size()){
	if(h[i] <= field) continue;
	field = h[i];
	h.erase(h.begin()+i);
	goto hanako;
      }
      field = 0;
    hanako:
      if(h.empty()) break;
    }
    printf("%d\n%d\n", (int)h.size(), (int)t.size());
  }
  return 0;
}

Measured memory_bytes: 1212
//0-1 Knapsack Problem

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

long long knapsack(long value[],long weight[],int W,int n)
{
long long dp[n+1][W+1];
memset(dp,0,sizeof(dp));

for(int i=0;i<=n;i++)
{
    for(int j=0;j<W+1;j++)
    {
        if(i==0||j==0)
            dp[i][j]=0;

    else  if(weight[i-1]<=j)
        dp[i][j]=max(value[i-1]+dp[i-1][j-weight[i-1]],dp[i-1][j]);
    else dp[i][j]=dp[i-1][j];
    }
}
return dp[n][W];
}
int main()
{
  int n,W;cin>>n>>W;
  long val[n],weight[n];

  for(int i=0;i<n;i++)
  {
    cin>>weight[i]>>val[i];
  }
cout<<knapsack(val,weight,W,n);
}
/*
int main()
{
int value[]={60,100,120};
int weight[]={10,20,30};
int W=50;
int n=sizeof(value)/sizeof(value[0]);
int m=sizeof(weight)/sizeof(weight[0]);
cout<<knapsack(value,weight,W,n);
}
*/





Measured memory_bytes: 79104
#!/usr/bin/env python3
import sys


def solve(N: int):
    if N % 2 == 0:              # 偶数
        tot = N+1
    else:
        tot = N
    ans = []
    for i in range(1, N):
        for j in range(i+1, N+1):
            if i + j == tot:
                continue
            ans.append([i, j])
    print(len(ans))
    for a in ans:
        print(*a, sep=" ")

    return


# Generated by 1.1.3 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    solve(N)


if __name__ == '__main__':
    main()


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

using namespace std;
#define sf(n) scanf("%d", &n)
#define pd(n) printf("%.12lf", n)
#define pf(n) printf("%d", n)
#define p() printf("\n")
#define ps() printf(" ")
#define ll long long
#define ull unsigned long long
#define MAX 1e9
#define mod 1000 * 1000 * 1000 + 7
#define pi 3.1415926536
#define ex 1e18
#define dbl 2e09
#define qu(q) queue<int> q
#define pqu(q) priority_queue<int> q
#define len(s) s.length()
#define sz(x) int(x.size())
#define pb(x) push_back(x)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define fir first
#define sec second

const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;

int x[100005], y[100005];
int main()
{
    int n, ans = 0;
    cin >> n;
    for (int i = 0; i < n; ++i)
        cin >> x[i];
    for (int i = 0; i < n; ++i)
        cin >> y[i];
    for (int i = 0; i < n; ++i)
        if (x[i] > y[i])
            ans += x[i] - y[i];

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define maxn 110
typedef long long ll;
typedef long double ld;
const int MINI INT_MIN;
const ll MINL LLONG_MIN;
int dd[maxn],n,k,d[maxn],ans=0,a[maxn];
int main(){
    ios_base::sync_with_stdio(0);
    cin>>n>>k;
    for (int i=1;i<=k;i++){
        cin>>d[i];
        for (int j=1;j<=d[i];j++){
            cin>>a[i];
            dd[a[i]]++;
        }
    }
    for (int i=1;i<=n;i++){
        if (dd[i]==0) ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3656
x, k, d = list(map(int,input().split()))
x =abs(x)
d =abs(d)
ans = 0
if x >= k * d:
  ans = x - k * d
else:
  ans = x - (x // d) * d
  if (k - x // d) % 2 == 1:
    ans = ans - d
print(abs(ans))

Measured memory_bytes: 9188
#include <bits/stdc++.h>
#define N 2005
using namespace std;
int n,l[N];
long long ans;
int main(){
	cin>>n;
	for(int i=1;i<=n;i++)cin>>l[i];
	sort(l+1,l+n+1);
	for(int i=1;i<=n-2;i++)
		for(int j=i+1;j<=n-1;j++)
			ans+=(lower_bound(l+j+1,l+n+1,l[i]+l[j])-l)-j-1;
	cout<<ans<<endl;
	return 0;
} 

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

using namespace std;

#define int long long
#define vi vector <int>
#define all(v) v.begin(), v.end()
#define pii pair <int, int>
#define mp(a, b) make_pair(a, b)
#define forn(i, from, n) for (int i = (int)(from); i < (int)(n); ++i)

const int INF = 1e9 + 9;

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

#ifdef LOCAL
    freopen("in", "r", stdin);
    freopen("out", "w", stdout);
#endif

    int n;
    cin >> n;
    vector <vi> v(n, vi(3));
    forn(i, 0, n)
        forn(j, 0, 3)
            cin >> v[i][j];
    vector <vi> dp(n, vi(3, 0));
    dp[0][0] = v[0][0];
    dp[0][1] = v[0][1];
    dp[0][2] = v[0][2];
    forn(i, 1, n){
        forn(j, 0, 3){
            forn(k, 0, 3)
                if (j != k)
                    dp[i][j] = max(dp[i][j], dp[i - 1][k] + v[i][j]);
        }
    }
    cout << max({dp[n - 1][0], dp[n - 1][1], dp[n - 1][2]});
    return 0;
}

Measured memory_bytes: 11264
import random
import math
N=int(input())
A=[int(i) for i in input().split()]
isPrime=[1 for i in range(10**6+1)]
isPrime[0]=0;isPrime[1]=0
Pfact=[[] for i in range(10**6+1)]
for i in range(10**6+1):
    if isPrime[i]==0:
        continue
    Pfact[i].append(i)
    for j in range(2*i,10**6+1,i):
        isPrime[j]=0
        Pfact[j].append(i)

Prime=[]
for i in range(10**6+1):
    if isPrime[i]:
        Prime.append(i)
def ispairwisecoprime():
    X=set()
    t=0
    for i in range(N):
        for j in Pfact[A[i]]:
            if j in X:
                return False
                exit()
            else:
                X.add(j)
    return True
if ispairwisecoprime():
    print("pairwise coprime")
else:
    G=A[0]
    for i in range(1,N):
        G=math.gcd(G,A[i])
    if G==1:
        print("setwise coprime")
    else:
        print("not coprime")


Measured memory_bytes: 277524
#include <iostream>
#include <math.h>
#include <string>
#include <vector>
#include <algorithm>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define INF 1000000;

using ll = long long;
using namespace std;

int digits_sum(int n){
    int sum=0;
    while(n>0){
        sum += n%10;
        n /= 10;
    }
    return sum;
}
int main(){
    int n;
    cin >> n;
    int b, d_sum, min_sum=INF;
    for(int a=1; a<n; a++){
        b = n-a;
        d_sum = digits_sum(a)+ digits_sum(b);
        if(d_sum<min_sum) min_sum = d_sum;
    }
    cout << min_sum << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=600010;
const int mod=924844033;
struct node{
	int v,nxt;
}e[N<<1];
int n,cnt=0,head[N],siz[N],cn[N],jc[N],inv[N];
int a[N],b[N],lim=1,l=0,r[N];
void add(int u,int v){
	e[++cnt].v=v;
	e[cnt].nxt=head[u];
	head[u]=cnt;
}
ll poww(ll x,int y){
	ll ans=1;
	while(y){
		if(y&1){
			ans=ans*x%mod;
		}
		x=x*x%mod;
		y>>=1;
	}
	return ans;
}
void dfs(int s,int fa){
	siz[s]=1;
	for(int i=head[s];i;i=e[i].nxt){
		int v=e[i].v;
		if(v==fa) continue;
		dfs(v,s);
		siz[s]+=siz[v];
		++cn[siz[v]];
	}
	++cn[n-siz[s]];
}
int C(int n,int m){
	return 1ll*jc[n]*inv[m]%mod*inv[n-m]%mod;
}
void ntt(int *a,int f){
	for(int i=0;i<lim;i++){
		if(i<r[i]) swap(a[i],a[r[i]]);
	}
	for(int i=1;i<lim;i<<=1){
		int wn=poww(f==1?5:554906420,(mod-1)/(i<<1));
		for(int j=0;j<lim;j+=(i<<1)){
			ll w=1;
			for(int k=0;k<i;k++,w=1ll*w*wn%mod){
				ll x=a[j+k],y=1ll*w*a[j+i+k]%mod;
				a[j+k]=(x+y)%mod;
				a[j+i+k]=(x-y+mod)%mod;
			}
		}
	}
	if(f==-1){
		ll inv=poww(lim,mod-2);
		for(int i=0;i<lim;i++){
			a[i]=1ll*a[i]*inv%mod;
		} 
	}
}
int main(){
//	freopen("k.in","r",stdin);
//	freopen("k.out","w",stdout);
	scanf("%d",&n);
	for(int i=1,x,y;i<n;i++){
		scanf("%d%d",&x,&y);
		add(x,y);add(y,x);
	}
	dfs(1,0);
	jc[0]=1;
	for(int i=1;i<=n;i++){
		jc[i]=1ll*jc[i-1]*i%mod;
	}
	inv[n]=poww(jc[n],mod-2);
	for(int i=n-1;i>=0;i--){
		inv[i]=1ll*inv[i+1]*(i+1)%mod;
	}
	for(int i=0;i<=n;i++){
		a[i]=1ll*cn[i]*jc[i]%mod;
		b[i]=inv[i];
	}
	reverse(a,a+n+1);
	while(lim<=(n<<1)){
		lim<<=1;
		l++;
	}
	for(int i=0;i<lim;i++){
		r[i]=(r[i>>1]>>1)|((i&1)<<(l-1));
	} 
	ntt(a,1);
	ntt(b,1);
	for(int i=0;i<lim;i++){
		a[i]=1ll*a[i]*b[i]%mod;
	}
	ntt(a,-1);
	reverse(a,a+n+1);
	for(int i=1;i<=n;i++){
		printf("%lld\n",(1ll*n*C(n,i)%mod-1ll*inv[i]*a[i]%mod+mod)%mod);
	}
}

Measured memory_bytes: 30136
#include <bits/stdc++.h>
using namespace std;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define all(v) v.begin(),v.end()
#define SZ(v) ((int)v.size())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)
#define bit(n) (1LL<<(n))
#define bit_exist(x, n) ((x >> n) & 1)
#define Ans(f, y, n) if(f) cout << y << endl; else cout << n << endl;
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v) cout << #v << "=" << endl; REP(i, v.size()){ cout << v[i] << ","; } cout << endl;
#define mdebug(m) cout << #m << "=" << endl; REP(i, m.size()){ REP(j, m[i].size()){ cout << m[i][j] << ","; } cout << endl;}
#define pb push_back
#define f first
#define s second
#define int long long
#define INF 1000000000000000000

using vec = vector<int>;
using mat = vector<vec>;
using Pii = pair<int, int>;
using PiP = pair<int, Pii>;
using PPi = pair<Pii, int>;
using bools = vector<bool>;
using pairs = vector<Pii>;

template<typename T> void readv(vector<T> &a){ REP(i, a.size()) cin >> a[i]; }
void readv_m1(vector<int> &a){ REP(i, a.size()){cin >> a[i]; a[i]--;} }

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

int mod = 1000000007;
//int mod = 998244353;
#define Add(x, y) x = (x + (y)) % mod
#define Mult(x, y) x = (x * (y)) % mod



signed main(){

    string S; cin >> S;
    int ans1 = 0, ans2 = 0;
    REP(i, SZ(S)){
        if(S[i] - '0' == i % 2) ans1++;
        else ans2++;
    }
    cout << min(ans1, ans2) << endl;

    return 0;
}


Measured memory_bytes: 640
def pfact(n):
    d = {}
    while n % 2 == 0:
        d[2] = 1 if 2 not in d else d[2] + 1
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            d[f] = 1 if f not in d else d[f] + 1
            n //= f
        else:
            f += 2
    if n != 1:
        d[n] = 1 if n not in d else d[n] + 1
    return d

n = int(input())
MOD = 10 ** 9 + 7
d = {}
for i in range(1, n+1):
    for k, v in pfact(i).items():
        d[k] = v if k not in d else d[k] + v
ans = 1
for k, v in d.items():
    ans *= v + 1
    ans %= MOD
print(ans)


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

struct UnionFind{
	vector<int> rnk,par;

	UnionFind(int sz) : rnk(sz,0),par(sz){
		for(int i = 0;i < sz;i++) par[i] = i;
	}

	int find(int x){
		if(par[x] == x) return x;
		return par[x] = find(par[x]);
	}

	void unite(int x,int y){
		x = find(x);
		y = find(y);
		if(x == y) return;
		if(rnk[x] < rnk[y]) swap(x,y);
		par[y] = x;
		if(rnk[x] == rnk[y]) rnk[x]++;
	}
	
	bool same(int x,int y){
		return (find(x) == find(y));
	}
};

template<class T>
struct Edge{
	int from,to,id;
	T cost;
	Edge(int to,T cost,int id) : to(to),cost(cost),id(id){}
	Edge(int from,int to,T cost,int id) : from(from),to(to),cost(cost),id(id){}
};

template<class T>
using WeightedGraph = vector<vector<Edge<T>>>;
using Graph = vector<vector<int>>;
template<class T>
using Matrix = vector<vector<T>>;

template <class T>
T kruskal(int n,vector<Edge<T>> &edges){
	T ret = 0;
	sort(edges.begin(),edges.end(),[](const Edge<T> &e1,const Edge<T> &e2){
		return e1.cost < e2.cost;
	});
	UnionFind uf(n);
	for(const Edge<T> &e : edges){
		if(!uf.same(e.from,e.to)){
			ret += e.cost;
			uf.unite(e.from,e.to);
		}
	}
	return ret;
}

signed main(){
	int n,m;
	cin >> n >> m;
	vector<Edge<int>> edges;
	for(int i = 0;i < m;i++){
		int s,d,c;
		cin >> s >> d >> c; s--;d--;
		edges.emplace_back(s,d,c,i);
	}
	sort(edges.begin(),edges.end(),[](const Edge<int> &e1,const Edge<int> &e2){
		return e1.cost < e2.cost;
	});
	int mstCost = 0;
	UnionFind uf(n);
	vector<Edge<int>> candEdge;
	for(const auto &e : edges){
		if(!uf.same(e.from,e.to)){
			mstCost += e.cost;
			uf.unite(e.from,e.to);
			candEdge.push_back(e);
		}
	}
	int num = 0,sum = 0;
	for(const auto &c : candEdge){
		UnionFind uf2(n);
		int cost = 0;
		bool isAllConnected = true;
		for(const auto &e : edges){
			if(e.id != c.id && !uf2.same(e.from,e.to)){
				cost += e.cost;
				uf2.unite(e.from,e.to);
			}
		}
		for(int i = 0;i < n - 1;i++){
			if(!uf2.same(i,i + 1)) isAllConnected = false;
		}
		if(!isAllConnected || cost != mstCost){
			num++;
			sum += c.cost;
		}
	}
	cout << num << " " << sum << endl;
}


Measured memory_bytes: 4932
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define zero_pad(num) setfill('0') << std::right << setw(num)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;

int main() {
    string s;
    cin >> s;
    int ans = 0;
    rep(i, 3) if(s[i] == '1') ans++;
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <assert.h>
#include <memory.h>
#include <queue>
#include <string.h>
using namespace std;

#define N 1005
#define BIT (1<<12)
#define INF 2000000000
int dp[2][BIT];
void solve() {
  int n,m;scanf(" %d %d ",&n,&m);
  int lim = (1<<n),pos = 0;
  for(int i=1;i<lim;++i) {
    dp[pos][i] = INF;
  }
  for(int i=0,npos = pos^1;i<m;++i,pos^=1,npos^=1) {
    for(int bit=0;bit<lim;++bit) {
      dp[npos][bit] = INF;
    }
    int cost,num;scanf("%d %d ",&cost,&num);
    int g = 0;
    for(int j=0;j<num;++j) {
      int x;scanf("%d ", &x);
      g |= (1<<(x-1));
    }
    for(int bit=0;bit<lim;++bit) {
      dp[npos][bit] = min(dp[npos][bit],dp[pos][bit]);
      dp[npos][bit|g] = min(dp[npos][bit|g], dp[pos][bit] + cost);
    }
  }
  if(dp[pos][lim-1]==INF) {
    dp[pos][lim-1] = -1;
  }
  printf("%d\n", dp[pos][lim-1]);
}

int main() {
  //freopen("input.txt","r",stdin);
  solve();
  return 0;
}


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

typedef long long ll;
#define INF (1ll<<60)

bool dp[8010][16001];
vector<int> a,b;
int x,y,fx=8000,fy=8000;

bool solve(){
	int i,j,n;
	x += 8000;
	fill(dp[0],dp[8010],false);
	dp[0][fx]=true;
	n = a.size();
	for(i=0; i<n; i++){
		for(j=0; j<=16000; j++){
			if((j+a[i])<=16000 && dp[i][j]){
				dp[i+1][j+a[i]]=true;
			}
			if((j-a[i])>=0 && dp[i][j]){
				dp[i+1][j-a[i]]=true;
			}
		}
	}
	if(!dp[n][x]){
		return false;
	}
	y += 8000;
	fill(dp[0],dp[8010],false);
	dp[0][fy]=true;
	n = b.size();
	for(i=0; i<n; i++){
		for(j=0; j<=16000; j++){
			if((j+b[i])<=16000 && dp[i][j]){
				dp[i+1][j+b[i]]=true;
			}
			if((j-b[i])>=0 && dp[i][j]){
				dp[i+1][j-b[i]]=true;
			}
		}
	}
	if(!dp[n][y]){
		return false;
	}
	return true;
}

int main(void){
	char s[8010];
	int i,n,cnt=0;
	bool now=false,first=true;
	cin >> s;
	cin >> x >> y;
	n = strlen(s);
	s[n] = 'T';
	for(i=0; i<=n; i++){
		if(s[i]=='F'){
			cnt++;
		}else{
			if(first){
				fx += cnt;
				cnt = 0;
				first = false;
			}else if(now){
				if(cnt!=0){
					a.push_back(cnt);
				}
				cnt = 0;
				now = false;
			}else{
				if(cnt!=0){
					b.push_back(cnt);
				}
				cnt = 0;
				now = true;
			}
		}
	}
	if(solve()){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 125440
import java.util.*;
class Main {
    public static void main(String[] args) {
	Scanner sc = new Scanner(System.in);
	int x = sc.nextInt();
	int y = sc.nextInt();
	int ans = 0;
	if(Math.abs(x)==Math.abs(y)) {
	    ans = 1;
    }else if(Math.abs(x)<Math.abs(y)) {
	    ans = Math.abs(y)-Math.abs(x) + (y<0?1:0) + (x<0?1:0);
	}else {
	    ans= Math.abs(x)- Math.abs(y) + (y>0?1:0) + (x>0?1:0);
	}
	
	System.out.println(ans);

    }
}

Measured memory_bytes: 21972
#include<stdio.h>
#define MOD 1000000007
int main(void){
  long long int n,k,ans=0;
  scanf("%lld %lld",&n,&k);
  for(long long int i=k;i<=n+1;i++){
    ans=(ans+(n-i+1)*i+1)%MOD;
  }
  printf("%lld\n",ans);
}

Measured memory_bytes: 1684
import collections
import sys
input = sys.stdin.readline
N, M = [int(_) for _ in input().split()]
A = [int(_) for _ in input().split()]
BC = [[int(_) for _ in input().split()] for _ in range(M)]
count = collections.defaultdict(int)
for a in A:
    count[a] += 1
for b, c in BC:
    count[c] += b
ans = 0
for k in sorted(count.keys(), key=lambda xs: -xs):
    ans += k * min([N, count[k]])
    N -= count[k]
    if N <= 0:
        break
print(ans)


Measured memory_bytes: 52232
#include<stdio.h>
int a[100000]; 
int main() 
{
	int n,t;
while(	scanf("%d",&n)!=EOF){
	

	int i;
	for(i=0;i<n;i++)
	scanf("%d",&a[i]);
	  int  tot=0; 
	  for(i=0;i<n;i++)
	  {
	  	if(a[i]==i+1){t=a[i];a[i]=a[i+1];a[i+1]=t;tot++;} 
	  
	  } 
			printf("%d\n",tot); 
	
} }

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

int main() {
  // ここにプログラムを追記
  int a, b, c, d;
  
  cin >> a;
  
  b = a / 100;
  c = (a - b * 100) / 10;
  d = a - (b * 100) - (c * 10);
  
  cout << b + c + d << endl;
}

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

#define N 36

typedef struct{
  char c;
  int num;
} pair;

int n;

int judgment(pair *, pair *);

int main(){
  int i, j, ask, minimum; 
  char *judge[2] = {"Stable", "Not stable"};
  pair a[N], b[N], temp1, temp2;

  scanf("%d", &n);

  for(i = 0; i < n; i++){
    scanf(" %c", &a[i].c);
    scanf("%d", &a[i].num);
    b[i] = a[i];
  }

  for(i = 0; i < n; i++){
    for(j = n - 1; j > i; j--){
      if(a[j].num < a[j - 1].num){
	temp1 = a[j];
	temp2 = a[j - 1];

	a[j] = temp2;
	a[j - 1] = temp1;
      }
    }
  }

  for(i = 0; i < n; i++){
    minimum = i;
    
    for(j = i; j < n; j++){
      if(b[j].num < b[minimum].num)
	minimum = j;
    }
    if(minimum != i){
      temp1 = b[minimum];
      temp2 = b[i];
      b[minimum] = temp2;
      b[i] = temp1;
    }
  }
    
  ask = judgment(a, b);
  
  for(i = 0; i < n; i++){
    if(i != n - 1)
      printf("%c%d ", a[i].c, a[i].num);
    else
      printf("%c%d", a[i].c, a[i].num);
  }
  printf("\n%s\n", judge[0]);
    
  for(i = 0; i < n; i++){
    if(i != n - 1)
    printf("%c%d ", b[i].c, b[i].num);
    else
      printf("%c%d", b[i].c, b[i].num);
  }
  
  printf("\n");
  if(ask == 1)
    printf("%s\n", judge[0]);
  else
    printf("%s\n", judge[1]);
      

  return 0;
}

int judgment(pair *a, pair *b){
  int i;

  for(i = 0; i < n; i++){
    if(a[i].c != b[i].c)
      return 0;
  }

  return 1;
}



Measured memory_bytes: 2144
//   _/                _/                 _/_/_/   _/
//_/_/_/_/   _/_/   _/_/_/_/   _/_/    _/       _/_/
// _/     _/    _/   _/     _/    _/  _/_/_/     _/
//_/     _/    _/   _/     _/    _/  _/    _/   _/
// _/_/   _/_/       _/_/   _/_/      _/_/     _/
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<queue>
#include<vector>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const double pi=acos(-1);
const int inf=1e9;
int main() {
  cin.tie(0),cout.tie(0);
  ios::sync_with_stdio(false);
  string s;
  cin >> s;
  int ans=0;
  for(int i=0; i<s.size()/2; i++) {
    if(s[i]!=s[s.size()-i-1]) {
      ans++;
    }
  }
  cout << ans << endl;
}

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

bool isAll7(ll nextVal) {
  bool ret = true;
  while (nextVal!=0) {
    if (nextVal%10 != 7) {
      ret = false;
      break;
    }
    nextVal /= 10;
  }
  return ret;
}

ll nextMulti( ll val, ll k) {
  ll check = 7 - (val%10);
  if (check < 0) check += 10;
	
  
  for (ll i = 0; i<=9; i++){
    if ((k*i)%10==check) {
      return i;
    }
  }
  return -1;
}

ll scale(ll val) {
  ll count = 0;
  val /= 10;
  while (val!=0){
    count++;
    val/=10;
  }
  return count;
} 

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

  ll nextVal = 0;
  map<ll, int> already; 
  ll ans = 0;
  do {
	nextVal/=10;
    ll multi = nextMulti(nextVal, K);
    if (multi==-1){
      cout << -1 << endl;
      return 0;
    }
    if (already[nextVal]>0){
      cout << -1 << endl;
      return 0;
    }
    nextVal += K*multi;
    ans ++;
    
  }while(!isAll7(nextVal));

  cout << ans+scale(nextVal) << endl;
  return 0;
}

Measured memory_bytes: 66104
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;
#define int long long


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

    int n,k; cin >> n >> k;

    int bs = 0,hbs = 0;

    bs = n / k;

    if(k % 2 == 0) hbs = (n + k / 2) / k;

    int ans = 0;

    ans += bs;
    
    ans += bs * (bs - 1) * 3;

    ans += bs * (bs - 1) * (bs - 2);

    if(k % 2 == 1){
        cout << ans << endl;
        return 0;
    }

    ans += hbs;

    ans += hbs * (hbs - 1) * 3;

    ans += hbs * (hbs - 1) * (hbs - 2);

    cout << ans << endl;


}

Measured memory_bytes: 256
#include<iostream>
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<limits>
#include<set>
#include<queue>
using namespace std;
#define int long  long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }

signed main()
{
	int P, Q, R;
	cin >> P >> Q >> R;
	cout << P + Q + R - max({ P,Q,R });
}

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

int main(){
  int A, B;
  cin >> A >> B;
  
  if(A == 1)A += 13;
  if(B == 1)B += 13;
  if(A > B)cout << "Alice" << endl;
 else if(A < B)cout << "Bob" << endl;
  else cout << "Draw" << endl;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>


int main()
{
	char c;
	scanf("%c",&c);
	if((c=='a')||(c=='i')||(c=='u')||(c=='e')||(c=='o')){
		printf("vowel");
	}else{
		printf("consonant");
	}
    return 0;
}
 

Measured memory_bytes: 128
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;
//
#define int long long
#define ALL(x) (x).begin(), (x).end()
#define UNIQUE(v) (v).erase(unique((v).begin(), (v).end()), (v).end());
#define m0(x) memset((x), 0, sizeof(x))
#define mm(x) memset((x), -1, sizeof(x))
// bit_macro
#define bit(n) (1LL << (n))
#define bitset(a, b) (a) |= (1 << (b))
#define bitunset(a, b) (a) |= ~(1 << (b))
#define bitcheck(a, b) ((a) >> (b)) & 1
#define bitcount(a) __builtin_popcountll((a))
//
typedef long long lint;
typedef pair<int, int> P;
typedef tuple<int, int, int> TP;
typedef vector<int> vec;
typedef vector<vec> mat;
//
const int INF = (int)1e18;
const int MOD = (int)1e9 + 7;
const double EPS = (double)1e-10;
const int dx[] = {-1, 0, 0, 1};
const int dy[] = {0, -1, 1, 0};
//
template <typename T> void chmax(T &a, T b) { a = max(a, b); }
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
//
struct Accelerate_Cin {
  Accelerate_Cin() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(20);
  };
};

signed main() {
  int H, W;
  cin >> H >> W;

  if (H % 3 == 0 || W % 3 == 0) {
    cout << 0 << endl;
    return 0;
  }

  int ans = min(H, W);

  for (int i = 1; i < H; i++) {
    int s1 = W * i;
    int s2 = ((W + 1) / 2) * (H - i);
    int s3 = (W / 2) * (H - i);
    int temp = max({s1, s2, s3}) - min({s1, s2, s3});
    chmin(ans, temp);
  }
  for (int i = 1; i < W; i++) {
    int s1 = H * i;
    int s2 = ((H + 1) / 2) * (W - i);
    int s3 = (H / 2) * (W - i);
    int temp = max({s1, s2, s3}) - min({s1, s2, s3});
    chmin(ans, temp);
  }

  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
use proconio::input;

static MOD: i64 = 1000000007;
fn helper(n:i64, a: i64) -> i64 {
  let mut numerator = 1;
  let mut denominator = 1;
  for i in 0..a {
    numerator = numerator * (n-i) % MOD;
    denominator = denominator * (i + 1) % MOD;
  }
  return numerator * (mod_pow(denominator, MOD - 2) % MOD) % MOD;
}

fn mod_pow(mut a: i64, mut n: i64) -> i64 {
  let mut res = 1;
  while 0 < n {
    if n & 1 == 1 {
      res = res * a % MOD;
    }
    a = a * a % MOD;
    n >>= 1;
  }
  res
}

fn main() {
  input! {
    n: i64,
    a: i64,
    b: i64,
  }
  let mut result = mod_pow(2, n);
  result = (result - 1) % MOD;
  result = (result + MOD - helper(n, a)) % MOD;
  result = (result + MOD - helper(n, b)) % MOD;
  
  println!("{}", result);
}

Measured memory_bytes: 2160
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
using namespace std;

long n;
int m, p[11];
string s;

int odd, even;
long dp[10][12];

long rec(int a, int b){ //a個目の*について考え,現在の合計のmod10はb
	if(dp[a][b]>=0) return dp[a][b];
	
	long ret=0;
	
	if(a==odd+even){
		if(b==0) ret=1;
		else ret=0;	
	}
	else{
		if(a<odd){
			for(int i=0; i<m; ++i) ret+=rec(a+1, (b+p[i])%10);	
		}
		else{
			for(int i=0; i<m; ++i){
				int v=2*p[i];
				if(v>9) v=1+(v%10);
				ret+=rec(a+1, (b+v)%10);	
			}
		}
		
	}
	
	return dp[a][b]=ret;
}

int main(){
	while(cin >> n){
		cin >> s >> m;
		for(int i=0; i<m; ++i) cin >> p[i];
		
		int sum=0;
		odd=0;
		even=0;
		int now=n-1;
		int ct=0;
		
		while(now>=0){
			if(s[now]=='*'){
				//printf("%d\n", now);
				if(ct%2==0) odd++;	
				else even++;
			}
			else if('0'<=s[now] && s[now]<='9'){
				if(ct%2==0) sum+=s[now]-'0';
				else{
					int v=2*(s[now]-'0');
					if(v>9){
						v=1+(v%10);	
					}
					sum+=v;
				}
				sum%=10;			
			}
			--now;
			++ct;	
		}
		
		//printf("odd=%d, even=%d\n", odd, even);
		
		memset(dp, -1, sizeof(dp));
		printf("%ld\n", rec(0,sum));
	}
}

Measured memory_bytes: 1336
#include<bits/stdc++.h>
#include<iomanip>
using namespace std;
#define ll long long
#define ld long double
#define vpll vector<pair<ll,ll> >
#define vpii vector<pair<int,int> >
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mem(a,b) memset(a , b , sizeof a );
#define M 1000000007
#define bs(a,b,x) binary_search(a,b,x)
template<typename T>
T fact(T n)
{
    // to find factorial
    return (n==1 || n==0) ? 1: n * fact(n - 1);
}
bool sortbysec(const pair<int,int> &a, const pair<int,int> &b)
{
    return (a.second < b.second);
}
int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
     int k;
     cin>>k;
     string str = "";
     for(int i=0;i<k;i++) str = str + "ACL";
     cout<<str<<endl;
    
    return 0;
}

Measured memory_bytes: 3604
def getlist():
	return list(map(int, input().split()))
H, W, A, B = getlist()
H -= 1
W -= 1
N = H + W + 2

const = 10 ** 9 + 7
fac = [0] * (N + 1)
inv = [0] * (N + 1)
finv = [0] * (N + 1)
fac[0], fac[1] = 1, 1
inv[1] = 1
finv[0], finv[1] = 1, 1

for i in range(2, N + 1):
	fac[i] = fac[i - 1] * i % const
	inv[i] = inv[const % i] * (const - (const // i)) % const
	finv[i] = finv[i - 1] * inv[i] % const

ans = 0
i = 0
while H - A - i > 0 and W - B - i > 0:
	ans += fac[H - A + B] * finv[B + i] * finv[H - A - i] * fac[W - B + A] * finv[A + i] * finv[W - B - i]
	ans %= const
	i += 1

if H - A - i == 0:
	ans += fac[W - B + A] * finv[A + i] * finv[W - B - i]
else:
	ans += fac[H - A + B] * finv[B + i] * finv[H - A - i]

ans %= const
print(ans)

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

int main() {
  int n; cin>>n;
  vector<char> s(n),t(n);
  for (int i=0; i<n; i++) cin>>s[i];
  for (int i=0; i<n; i++) cin>>t[i];

  int ans=2*n;
  for (int i=0; i<n; i++) {
    bool frag=true;
    for (int j=0; j<n; j++) {
      if (i+j>=n) break;
      if (s[i+j]!=t[j]) frag=false;
    }
    if (frag) {
      ans=i+n;
      break;
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <numeric>
#define rep(i, n) for(ll i=0; i < n; i++)
#define reps(i, n) for(ll i=1; i <= n; i++)
#define INF 1e9
#define ALL(v) v.begin(), v.end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)

using namespace std;
using ll=long long;
int n;

int main() {
  int n; cin >> n;
  double val[n];
  rep(i,n)cin >> val[i];
  sort(val,val+n);

  double ans=(val[0]+val[1])/2;
  if(n>2){rep(i,n-2){
      ans = (ans+val[i+2])/2;
    }}
  cout << ans;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < (int)(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++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
typedef long long ll;
typedef pair<int, int> pint;
typedef vector<int> vint;

int main(){
      int N,ans=1; cin >> N;

        REP(i,3){
            ans *= N;

        }
      cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b)  for(int i=(a),i##formax=(b);i< i##formax;i++)
#define FORR(i,a,b) for(int i=(a),i##formin=(b);i>=i##formin;i--)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define pcnt __builtin_popcount
#define sz(x) (int)(x).size()
#define maxs(x,y) x=max((x),(y))
#define mins(x,y) x=min((x),(y))
#define show(x) cout<<#x<<" = "<<(x)<<endl;
#define all(a) ((a).begin()),((a).end())
#define each(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define bit(n) (1LL<<(n))
typedef long long ll;
typedef __int128_t lll;
template<class T>using V=vector<T>;
template<class T>using VV=V<V<T>>;
template<class T,class Y>using P=pair<T,Y>;
template<class T,class Y>ostream& operator<<(ostream&o,P<T,Y>&p){return o<<"("<<p.fi<<","<<p.se<<")";}
template<class T>ostream& operator<<(ostream&o,V<T>&v){for(T&t:v)o<<t<<",";return o;}
template<class T>void uniq(V<T>&v){sort(all(v));v.erase(unique(all(v)), v.end());}
template<class A,size_t N,class T>void Fill(A(&a)[N],const T&v){fill((T*)a,(T*)(a+N),v);}

const int MOD = 1e9+7; //998244353;

lll gcd(lll a,lll b,lll&x,lll&y){if(!b){x=1;y=0;return a;}lll d=gcd(b,a%b,y,x);y-=a/b*x;return d;}
ll modInv(ll a,ll m=MOD){lll x,y;gcd(a,m,x,y);return(x%m+m)%m;}
ll modPow(lll a,lll n,ll m=MOD){lll p=1;for(;n;n>>=1,a=a*a%m)if(n&1)p=p*a%m;return p;}
//V<ll>Fac,Rac;void setF(int n,int m=MOD){Fac=Rac=V<ll>(++n);Fac[0]=1;FOR(i,1,n)Fac[i]=Fac[i-1]*i%m;Rac[n-1]=modInv(Fac[n-1],m);FORR(i,n-1,1)Rac[i-1]=Rac[i]*i%m;}
//ll comb(int a,int b,int m=MOD){return a<b||b<0?0:Fac[a]*Rac[b]%m*Rac[a-b]%m;}

const int IINF = 1e9+6;
const ll LINF = 1e18;
const int N = 10000; 
string s;
int n, p, c[N], x, t=1;
ll ans;
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n >> p >> s;
  if(p==2 || p==5){
    FOR(i, 0, n) if((s[i]-'0')%p==0) ans += i+1;
    cout << ans << endl;
    return 0;
  }
  c[0] = 1;
  FORR(i, n-1, 0){
    x = (x+t*(s[i]-'0'))%p;
    ans += c[x]++;
    t = t*10%p;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3768