akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#define H 500000
int parent(int i);
int left(int i);
int right(int i);
void maxHeapify(int A[],int i);
int parent(int i){
  return i/2;
}

int left(int i){
  return 2*i;
}

int right(int i){
  return 2*i+1;
}
int h;
int A[H];
int main(){
  int i;
  scanf("%d",&h);
  for(i = 1; i <= h; i++) scanf("%d",&A[i]);
  for(i=h/2;i>=1;i--) maxHeapify(A,i);
  for(i=1;i<=h;i++) printf(" %d",A[i]);
  printf("\n");
  return 0;
}

void maxHeapify(int A[],int i){
  int l,r,largest,x;
  l = left(i);
  r = right(i);
  if(l<=h && A[l]>A[i]) largest = l;
  
  else largest = i;
  
  if(r <= h && A[r]>A[largest]) largest = r;
 
  if(largest != i){
  x=A[i];
  A[i]=A[largest];
  A[largest]=x;
  maxHeapify(A,largest);
  }
}

Measured memory_bytes: 2552
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        long N = scanner.nextInt(),ans=0,i;
        //N*X -> 7*10^3+7*10^2+7*10^1+7 => 7(10^3+10^2+10^1+1) => 7(1 + 10*(10^2+10+1)) => 7(1+10+ 100*(10^2+10+1))
                                                                //7(1+10(1+10*(1+10*(1+10*())))

        if (N%7==0)
            N/=7;
        if (N%2==0) {
            System.out.println("-1");
            return;
        }

        //factor of 7?
        long cum = 0;
        for (int j = 1; j < N+10; j++) {
            cum = cum*10L+1;
            if (cum>N)
                cum=cum%N;
            if (cum==N || cum==0) {
                System.out.println(j);
                return;
            }
        }
        System.out.println("-1");
        /*
        7(1)
         7 + 10 * 7
            7 + 10 * 7 + 700
                1 + 10 + 100
         **/
        //10^x-1/9 = N*X/7, 10^x = N*X*9/7+1  =>
        //N*X => 0, 7, 7*11 , 7 * 111
        //BigInteger num = new BigInteger("7"), N1 = new BigInteger(N+""), N2 = BigInteger.ONE;
        /*for (i = 1; i <= N&&N%2==1; i++) {
            if (num.mod(N1).equals(BigInteger.ZERO))
                break;
            N2=N2.multiply(BigInteger.TEN).add(BigInteger.ONE);
            num=num.multiply(N2);
        }
        System.out.println((i==N+1||N%2==0)?"-1":i);*/
    }

}


Measured memory_bytes: 27208
#133C
import sys
L, R = map(int, sys.stdin.readline().split())

M =[]
f = False
for i in range(L, R+1):
    tmp = i%2019
    if tmp==0:
        print(0)
        f=True
        break
    M.append(tmp)

ans =2020
if f == False:
    for i in range(len(M)):
        for j in range(i+1, len(M)):
            tmp2 = (M[i]*M[j])%2019
            if ans > tmp2:
                ans = tmp2
    print(ans)

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

using namespace std;

int N;
vector<vector<int>> G;

void dfs(int v, int pv, int dist[]) {
  for (auto nv : G[v]) {
    if (nv == pv) continue;
    dist[nv] = dist[v] + 1;
    dfs(nv, v, dist);
  }
}

int main() {
  cin >> N;
  G.resize(N);
  int a, b;
  for (int i = 0; i < N - 1; i++) {
    cin >> a >> b;
    a--, b--;
    G[a].emplace_back(b);
    G[b].emplace_back(a);
  }

  int f[101010] = {0}, s[101010] = {0};
  dfs(0, -1, f);
  dfs(N - 1, -1, s);
  int fc = 0, sc = 0;
  for (int i = 0; i < N; i++) {
    if (f[i] <= s[i])
      fc++;
    else
      sc++;
  }
  if (fc > sc) {
    cout << "Fennec" << endl;
  } else {
    cout << "Snuke" << endl;
  }

  return 0;
}

Measured memory_bytes: 12800
#include <bits/stdc++.h>
#define f(i,n) for(int i=0;i<n;i++)
#define P pair<int,int>
#define F first
#define S second
#define int long long
#define mod 1000000007
#define mmod 998244353
#define all(v) v.begin(), v.end()
#define INF LLONG_MAX/3
using namespace std;
int mypow(int a, int b, int c) {
	if (b == 0)return 1;
	if (b % 2)return mypow(a, b - 1, c)*a%c;
	int z = mypow(a, b / 2, c);
	return z * z%c;
}
int x[100000], y[100000], z[100000];
priority_queue<int, vector<int>, greater<int>> p;
signed main() {
	int a, b, c, d, e, ans = 0;
	cin >> a >> b >> c >> d >> e;
	f(i, c)cin >> x[i];
	f(i, d)cin >> y[i];
	f(i, e)cin >> z[i];
	sort(x, x + c);
	sort(y, y + d);
	sort(z, z + e);
	for (int i = c - 1; i >= c - a; i--) {
		ans += x[i];
		p.push(x[i]);
	}
	for (int i = d - 1; i >= d - b; i--) {
		ans += y[i];
		p.push(y[i]);
	}
	int vz = e - 1;
	while (p.top() < z[vz]) {
		ans += z[vz] - p.top();
		vz--;
		p.pop();
	}
	cout << ans << endl;
}

Measured memory_bytes: 4724
#include <iostream>
using namespace std;
static const int NIL = -1;
static const int NO = 0;
static const int YES = 1;

int n;
int A[20];
int S[21][2001];

bool solve(int i, int m) {
    if (S[i][m] != NIL) return S[i][m];

    if (m == 0) return S[i][m] = YES;
    if (i >= n) return S[i][m] = NO;
    return S[i][m] = solve(i + 1, m) || solve(i + 1, m - A[i]);
}

int main() {
    for (int i = 0; i < 21; i++) {
        for (int j = 0; j < 2001; j++) {
            S[i][j] = NIL;
        }
    }

    cin >> n;
    for (int i = 0; i < n; i++) cin >> A[i];
    int q;
    cin >> q;
    int m[q];

    for (int i = 0; i < q; i++) {
        cin >> m[i];
        if (solve(0, m[i])) {
            cout << "yes" << endl;
        } else {
            cout << "no" << endl;
        }
    }
}


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

int main() {
  int n;
  string s;
  cin >> n >> s;
  int a = 0, b = 0;
  rep(i,n) if(s[i] == 'R') a++;
  int ans = a;
  rep(i,n){
    if(s[i] == 'R') a--;
    else b++;
    int now = max(a, b);
    ans = min(ans, now);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3724
#include <bits/stdc++.h>
using namespace std;
using pint = pair<int, int>;
using ll = long long;
using pll = pair<ll, ll>;
#define FOR(i, begin, end) for (int i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end) for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define FI first
#define SE second
#define endl "\n"
#define ciosup cin.tie(0);ios::sync_with_stdio(false);
#define eb emplace_back
constexpr ll INF = 1e9 + 7;
constexpr ll MOD = 1e9 + 7;

int main()
{
    ciosup;
    ll x, y, z, k;
    cin >> x >> y >> z >> k;
    ll a[x], b[y], c[z];
    REP(i,x)cin >> a[i];
    REP(i,y)cin >> b[i];
    REP(i,z)cin >> c[i];
    ll d[x * y];
    int lab = 0;
    REP(i,x){
        REP(j,y){
            d[lab++] = a[i] + b[j];
        }
    }
    sort(d, d + x*y, greater<ll>());
    sort(c, c + z, greater<ll>());
    ll e[min(k,x*y)*min(k,z)];
    lab = 0;
    REP(i, min(k, x * y))
    {
        REP(j,min(k,z))
        {
            e[lab++] = d[i] + c[j];
        }
    }
    sort(e, e + lab, greater<ll>());
    REP(i,k)cout << e[i] << endl;
}

Measured memory_bytes: 31616
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <vector>
#define REP(i, n) for (int i = 0; i < (n); i++)
#define ALL(vec) (vec).begin(), (vec).end()
#define SUM(...) accumulate(ALL(__VA_ARGS__),0LL)
#define DSUM(...) accumulate(ALL(__VA_ARGS__),0.0)
using namespace std;
using ll = long long;
using P = pair<int, int>;

// 便利関数
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;}
template<class T> inline auto max(const T& a){ return *max_element(ALL(a)); }
template<class T> inline auto min(const T& a){ return *min_element(ALL(a)); }
inline ll gcd(ll a,ll b){if(b == 0) return a;return  gcd(b,a%b);}
inline ll lcm(ll a,ll b){ll g = gcd(a,b);return a / g * b;}

// 出力
void print() { std::cout << '\n'; }
template <class T>void print(const T &x) {std::cout << x <<'\n';}
template <class T, class... Args>void print(const T &x, const Args &... args) {std::cout << x << " ";print(args...);}

const int INF = 2002002002;

void solve(int H, int W, std::vector<std::string> S){
    vector<vector<int> > map(H, vector<int> (W, 0));
    REP(i, S.size()) REP(j, S[i].size()) {
        if (S[i][j] == '#') {
            for (int x = -1; x <= 1; x++)
                for (int y = -1; y <= 1; y++)
                    if (i + x >= 0 && i + x < H && j + y >= 0 && j + y < W)
                        if (S[i + x][j + y] != '#')
                            map[i + x][j + y]++;
        }
    }

    REP(i, H) {
        REP(j, W) {
            if (S[i][j] == '#') cout << '#';
            else cout << map[i][j];
        }
        cout << '\n';
    }
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int H;
    cin >> H;
    int W;
    cin >> W;
    std::vector<std::string> S(H);
    for(int i = 0 ; i < H ; i++){
        std::cin >> S[i];
    }
    solve(H, W, std::move(S));
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<string.h>
#include<algorithm>
#include<queue>
#include<stack>
#include<math.h>
#include<map>
typedef long long int ll;
using namespace std;
#define maxn 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f3f
const int mm=2e5+100;
ll d[mm];
map<ll,ll> name;
int main()
{
   ll n,m,i,j,t,a,b,c,p,k,kk;
     ll s=0;
	 cin>>n; 
     k=0;
     for(i=0;i<n;i++)
     {
     	cin>>d[i];
     	k=k^d[i];
	 }
	 for(i=0;i<n;i++)
	 {
	 	cout<<(k^d[i])<<' ';
	 }
	 
} 

Measured memory_bytes: 5076
#include <bits/stdc++.h>
#define rep(i, n) for(long long int i = 0; i < n; i++)
#define _rep(i, m, n) for(long long int i = m; i < n; i++)
#define print(n) std::cout << n << std::endl
#define _print(n) std::cout << n
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int N = 1000000;
const ll mod = 1000000007;
using Graph = vector<vector<int>>;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int main(){
    ll n; cin >> n;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];
    ll count = 0;
    
    rep(i, n){
        if(a[i + 1] == a[i]) continue;

        if(a[i + 1] < a[i]){
            while(i < n - 1 && a[i + 1] <= a[i])i++;
        }else if(a[i + 1] > a[i]){
            while(i < n - 1 && a[i + 1] >= a[i])i++;
        }
        count++;
        //cout << count << " " << i << endl;
    }
    cout << count << endl;
}


Measured memory_bytes: 1024
#include<iostream>
#include<string>
using namespace std;
int main(){
    string str,tmp;
    cin>>tmp;
    int cunt=0;                                            
    for(int i=0;i<tmp.size();i++){
        if(tmp[i]>='A'&&tmp[i]<='Z')
            tmp[i]+='a'-'A';
    }   
    while(cin>>str){    
        if(str=="END_OF_TEXT")break;
        for(int i=0;i<str.size();i++){
            if(str[i]>='A'&&str[i]<='Z')
                str[i]+='a'-'A';
        }    
        if(str==tmp)
            cunt++;
    }   
    cout<<cunt<<"\n";;
    return 0;
}



Measured memory_bytes: 3192
import java.io.*;
import java.util.*;

public class Main implements Runnable {

    private void solve() throws IOException {

        int N = nextInt();
        int[] arr = new int[N];
        long s = 0L;
        for(int i = 0; i < N; ++i) {
            arr[i] = nextInt();
            s += arr[i];
        }
        long best = Long.MAX_VALUE;
        long temp = 0L;
        for(int i = 0; i < N - 1; ++i) {
            temp += arr[i];
            best = Math.min(best,Math.abs(temp - (s-temp)));
        }
        writer.println(best);

    }

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

    BufferedReader reader;
    //    BufferedReader reader2;
    StringTokenizer tokenizer;
    PrintWriter writer;
    //    BufferedWriter writer;

    public void run() {
        try {
            reader = new BufferedReader(new InputStreamReader(System.in));
//            reader = new BufferedReader(new FileReader("input.txt"));
            //            reader2 = new BufferedReader(new FileReader("1.in"));
            tokenizer = null;
            writer = new PrintWriter(System.out);
//            writer = new     PrintWriter("output.txt");
//                                                    writer = new BufferedWriter(System.out);
            //                        writer = new BufferedWriter(new OutputStreamWriter(System.out));
            solve();
            reader.close();
            //            reader2.close();
            writer.close();
        } catch (Exception e) {
            e.printStackTrace();
            System.exit(1);
        }
    }

    int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }

    long nextLong() throws IOException {
        return Long.parseLong(nextToken());
    }

    double nextDouble() throws IOException {
        return Double.parseDouble(nextToken());
    }

    short nextShort() throws IOException {
        return Short.parseShort(nextToken());
    }

    String nextToken() throws IOException {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            tokenizer = new StringTokenizer(reader.readLine());
        }

        return tokenizer.nextToken();
    }

}

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

using LL = long long;

#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define FOR(i, a, b) for (int(i) = (a); (i) < (b); ++(i))
#define RFOR(i, a, b) for (int(i) = (a); (i) > (b); --(i))
#define SORT(x) sort(ALL((x)))
#define RSORT(x) sort(RALL((x)))
#define SZ(x) (int)(x).size()
#define debug(x) cerr << #x << " : " << x << '\n'

const int INF = 1e9;
const int MOD = 1e9 + 7;
const LL LINF = 1e18;

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

  LL ans;
  int N;
  cin >> N;
  vector<int> h(N);
  FOR(i, 0, N){
    cin >> h[i];
  }

  vector<LL> cost(N, 0);
  cost[1] = abs(h[1] - h[0]);

  FOR(i, 2, N){
    cost[i] = min(cost[i - 1] + abs(h[i] - h[i - 1]), cost[i - 2] + abs(h[i] - h[i - 2]));
  }

  ans = cost[N - 1];

  cout << ans << '\n';

  return 0;
}

Measured memory_bytes: 4484
n,q=list(map(int,input().split()))
GR=[[] for _ in range(n)]
for i in range(n-1):
  a,b=list(map(int,input().split()))
  GR[a-1].append(b)
  GR[b-1].append(a)

ans=[0 for _ in range(n)]
for i in range(q):
  p,x=list(map(int,input().split()))
  ans[p-1] += x
  
gr=[1]
parent=[0 for _ in range(n)]
while gr:
  po=gr.pop()
  for no in GR[po-1]:
    if no == parent[po-1]:
      continue
    gr.append(no)
    parent[no-1]=po
    ans[no-1] += ans[po-1]
      
print(' '.join(map(str,ans)))

Measured memory_bytes: 74852
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define inf (ll)(1e18)
#define mod 1000000007


int main()
{
    int t=1;
    //cin>>t;
    while( t-- )
    {
        ll m=-1;
        ll ans=0;
        int n;
        cin>>n;
        ll a[n];
        for( int i=0 ; i<n ; i++ )
        {
            cin>>a[i];
            m=max( m,a[i] );
            if( a[i]<m )
                ans+=m-a[i];
        }
        cout<<ans;
    }

    return 0;
}












Measured memory_bytes: 5116
/*
"Won't stop until I'm phenomenal."
- Phenomenal, Eminem
 */
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define ff first
#define Shazam ios_base::sync_with_stdio(false);   cin.tie(NULL); cout.tie(NULL);
#define ss second
#define all(c) c.begin(),c.end()
#define endl "\n"
#define test() int t; cin>>t; while(t--)
#define fl(i,a,b) for(int i = a ; i <b ;i++)
#define get(a) fl(i,0,a.size())  cin>>a[i];
#define pra(a) fl(i,0,a.size()) cout<<a[i]<<" ";	cout<<endl;
#define pr(a,n) fl(i,0,n) cout<<a[i]<<" ";	cout<<endl;
const ll INF = 2e18;
const int inf = 2e9;
const int mod1 = 1e9 + 7;

vector<vector<int>> vis;
vector<string> g;
int ans = 0;
int n,m;
vector<int> xdir = {0,0,-1,1};
vector<int> ydir = {1,-1,0,0};
bool legal(int x, int y){
    if(x<0||y<0||x>=n||y>=m||g[x][y]=='#') return false;
    return true; 
}

void dfs(int i, int j, int &comp){
    vis[i][j] = 1;
    comp++;
    ans = max(ans, comp);
    for(int k = 0; k < 4; k++){
        int x = i + xdir[k];
        int y = j + ydir[k];
        if(legal(x,y)&&!vis[x][y])
            dfs(x,y, comp);
    }
}

int main(){
    Shazam;
    cin>>n>>m;
    g = vector<string>(n);
    for(string &s : g) cin>>s;
    vector<vector<int>> top(n,vector<int> (m)), bot(n,vector<int> (m)), left(n,vector<int> (m)), right(n,vector<int> (m));
    for(int i = 0 ; i < n; i++){
        int last = -1;
        for(int j = 0; j < m; j++){
            if(g[i][j]=='#') last = j;
            left[i][j] = (j-last);
        }
    }
    for(int i = 0 ; i < n; i++){
        int last = m;
        for(int j = m-1; j >=0; j--){
            if(g[i][j]=='#') last = j;
            right[i][j] = (last-j);
        }
    }
    for(int i = 0 ; i < m; i++){
        int last = -1;
        for(int j = 0; j < n; j++){
            if(g[j][i]=='#') last = j;
            top[j][i] = (j-last);
        }
    }
    for(int i = 0 ; i < m; i++){
        int last = n;
        for(int j = n-1; j >=0; j--){
            if(g[j][i]=='#') last = j;
            bot[j][i] = (last-j);
        }
    }
    for(int i = 0 ; i < n; i++){
        for(int j = 0 ; j < m; j++){
            ans = max(ans, left[i][j] + bot[i][j] + right[i][j] + top[i][j] - 3);
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 70200
#include <bits/stdc++.h>
using namespace std;
vector <vector<int>> node;
long long n,x,y;
int getLength(int i, int j){
    // i < j only
    // x < y only
    //cout << "i:"<<i<<" j:"<<j<<endl;
    int ret = 0;
    int ret2 = (j-i);
    int toX = abs(x-i);
    int fromY = abs(j-y);
    ret = toX+fromY+1;

    // while(i!=j){
    //     //cout << i << endl;
    //     if(i==x){
    //         i=y;
    //     }else{
    //         if(i>j){
    //             i--;
    //         }else if(i<j){
    //             i++;
    //         }else{
    //             break;
    //         }
    //     }
    //     ret++;
    // }
    //cout << "ret:"<<ret << endl;
    if(ret > ret2){
        ret = ret2;
    }
    //cout << "ret:"<<ret << endl;
    return ret;
}
int main(){
    cin >> n >> x >> y;
    x--;
    y--;
    // for(int i = 0; i< n; i++){
    //     node.push_back(vector<int>());
    //     if(i==0){
    //         node[i].push_back(i+1);
    //         continue;
    //     }
    //     if(i==(n-1)){
    //         node[i].push_back(i-1);
    //         continue;
    //     }
    //     node[i].push_back(i+1);
    //     node[i].push_back(i-1);
    // }
    // if(abs(x-y)!=1){
    //     node[x].push_back(y);
    //     node[y].push_back(x);
    // }
    vector <int> ans(n-1,0);
    for(int i = 0; i < n ; i++){
        for(int j = i+1; j < n; j++){
            //cout << i << ":" << j << endl;
            int tmp = getLength(i,j);
            //cout <<"tmp:" << tmp << " i:"<<i<<" j:"<<j<< endl;
            if(tmp!=-1){
                tmp--;
                ans[tmp]++;
            }
        }
    }
    for(int i = 0; i<ans.size();i++){
        cout << ans[i] << endl;
    }
    return 0;
}

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

int main() {
  int h, w, k;
  cin >> h >> w >> k;
  vector<string> c(h);
  for(int i = 0;i < h;i++){
    cin >> c[i];
  }
  int count= 0;
  for(int ih = 0;ih < (1 << h);ih++){
    for(int jw = 0;jw < (1 << w);jw++){
      
      int cnt = 0;
      for(int i=0;i < h;i++){
        for(int j=0;j < w;j++){
          if(ih >> i&1)continue;
          if(jw >> j&1)continue;
          if(c[i][j] == '#') cnt++;
        }
      }
      if(cnt == k) count++;
    }
  }
  
  cout << count << endl;
  return 0;
}


Measured memory_bytes: 3624
#include <stdio.h>
#include <stdlib.h>
#define NOT_FOUND 10000000
int binarySearch(int);
int n, q, *S, *T;
int main()
{
  int i, count = 0;

  scanf("%d",&n);
  S = (int *)malloc(n * sizeof(int));
  
  for(i = 0 ; i < n ; i++) scanf("%d",&S[i]);

  scanf("%d",&q);
  T = (int *)malloc(q * sizeof(int));

  for(i = 0 ; i < q ; i++) scanf("%d",&T[i]);

  for(i = 0 ; i < q ; i++){
    if(binarySearch(T[i]) != NOT_FOUND) count++; } 

  printf("%d\n",count);

  return 0;
}

int binarySearch(int key)
{
  int left, right, mid;

  left = 0;
  right = n;

  while(left < right){
    mid = (left + right)/2;
    if(S[mid] == key) return mid;
    else if(key < S[mid]) right = mid;
    else left = mid + 1; }

  return NOT_FOUND;
}



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

int main()
{
    char a[12];
    cin>>a;
    if(a[0]=='Y'&&a[1]=='A'&&a[2]=='K'&&a[3]=='I') cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 256
// </> : towhid1zaman

#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef vector<int> vi;typedef vector<ll> vll;
#define fill(a,b) memset(a, b, sizeof (a))
#define all(v) (v).begin(),(v).end()
#define sp(k) cout<<setprecision(k)<<fixed;
#define rep(i,a) for(int i=0; i<a;i++)
#define rep1(i,a,b) for(int i=(a);i<=(b);++i)
#define irep(i,b,a) for(int i=(b);i>=(a);--i)
#define minv(v) *min_element(all(v))
#define maxv(v) *max_element(all(v))
#define unq(v) sort(all(v)),(v).erase(unique(all(v)),(v).end())
#define _ios ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define sqr(a) ((a)*(a))
#define sz(a) int(a.size())
#define ff first
#define ss second
#define pb push_back

const double pi = acos(-1.0);
const int mod = 1000000007; // (int)1e9+7
const int maxn = 2000100;

int main(){
        _ios;
        sp(20);
        double x; cin >> x;
        cout<<pi*x*2<<endl;


return 0;
}



Measured memory_bytes: 3808
#include <iostream>
#include <vector>
using namespace std;
const int MAX = 51;

int main(){
  int n,k,m,a,p,x,y;
  vector<bool> v(MAX);
  bool bu[MAX][MAX];

  fill(bu[0],bu[MAX],false);

  cin >> n >> k;
  for(int i = 0 ; i < k ; i++){
    cin >> m;
    for(int j = 0 ; j < m ; j++){
      cin >> a;
      bu[i][a] = true;
    }
  }

  cin >> p;
  for(int i = 0 ; i < p ; i++){
    cin >> x >> y;
    for(int j = 0 ; j < k ; j++){
      if(bu[j][x] && bu[j][y]){
	v[x] = v[y] = true;
      }
    }
  }

  int cnt = 0;
  for(int i = 0 ; i < MAX ; i++){
    if(v[i]) cnt++;
  }

  cout << cnt << endl;

  return 0;
}

Measured memory_bytes: 1196
// #define DEBUGGING
#include <bits/stdc++.h>
#define endl '\n'
#define ALL(v) std::begin(v), std::end(v)
#define ALLR(v) std::rbegin(v), std::rend(v)
using ll = std::int64_t;
using ull = std::uint64_t;
using pll = std::pair<ll, ll>;
using tll = std::tuple<ll, ll, ll>;
template <typename T> using vec = std::vector<T>;
template <typename T> using vvec = vec<vec<T>>;
template <typename T> const T& var_min(const T &t) { return t; }
template <typename T> const T& var_max(const T &t) { return t; }
template <typename T, typename... Tail> const T& var_min(const T &t, const Tail&... tail) { return std::min(t, var_min(tail...)); }
template <typename T, typename... Tail> const T& var_max(const T &t, const Tail&... tail) { return std::max(t, var_max(tail...)); }
template <typename T, typename... Tail> void chmin(T &t, const Tail&... tail) { t = var_min(t, tail...); }
template <typename T, typename... Tail> void chmax(T &t, const Tail&... tail) { t = var_max(t, tail...); }
template <typename T> const T& clamp(const T &t, const T &low, const T &high) { return std::max(low, std::min(high, t)); }
template <typename T> void chclamp(T &t, const T &low, const T &high) { return t = clamp(t, low, high); }
namespace init__ { struct InitIO { InitIO() { std::cin.tie(nullptr); std::ios_base::sync_with_stdio(false); std::cout << std::fixed << std::setprecision(30); } } init_io; }
#define mv_rec make_v(init, tail...)
template <typename T> T make_v(T init) { return init; }
template <typename T, typename... Tail> auto make_v(T init, size_t s, Tail... tail) { return vec<decltype(mv_rec)>(s, mv_rec); }
#undef mv_rec

#ifdef DEBUGGING
#else
#define DEBUG(...) 0
#define DEBUG_SEPARATOR_LINE 0
#endif

using namespace std;

const size_t SIZE = 1e6 + 10;
vec<bool> used(SIZE);
vec<ll> primes, counter(SIZE), mul(SIZE, 1);

int main() {
    for (ll i = 2; i < SIZE; i++) {
        if (used[i]) continue;
        primes.push_back(i);
        for (ll j = 1; i * j < SIZE; j++) used[i * j] = true;
    }

    ll l, r;
    cin >> l >> r;
    for (ll p : primes) {
        if (r < p) break;
        for (ll pm = p; pm <= r; pm *= p) {
            ll idx = (l / pm + !!(l % pm)) * pm - l;
            for(; idx <= r - l; idx += pm) {
                counter[idx]++;
                mul[idx] *= p;
            }
        }
    }

    for (ll i = 0; i <= r - l; i++) {
        ll n = i + l;
        if (mul[i] < n) {
            mul[i] = n;
            counter[i]++;
        }
    }

    ll ans = 0;
    for (ll i = 0; i <= r - l; i++) {
        ll n = counter[i];
        DEBUG(i+l, n);
        auto ite = lower_bound(ALL(primes), n);
        ans += (*ite == n);
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 19600
#include <cstdio>
int main() {
    int n, x, y, h, w;
    while (scanf("%d",&n)) {
        if (!n) break;
        int res=0;
        for (int i=0; i<n; i++) {
            scanf("%d%d%d%d",&x,&y,&h,&w);
            int sum=x+y+h;
            if (sum<=60&&w<=2) res+=600;
            else if (sum<=80&&w<=5) res+=800;
            else if (sum<=100&&w<=10) res+=1000;
            else if (sum<=120&&w<=15) res+=1200;
            else if (sum<=140&&w<=20) res+=1400;
            else if (sum<=160&&w<=25) res+=1600;
        }
        printf("%d\n",res);
    }
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
#define re register
using namespace std;
inline int read(){
    re int t=0;
    re char v=getchar();
    while(v<'0')v=getchar();
    while(v>='0'){
        t=(t<<3)+(t<<1)+v-48;
        v=getchar();
    }
    return t;
}
long long a,b,c;
int main(){
    a=read();b=read();c=read();
    if(c<a+b)puts("No");
    else if((c-a-b)*(c-a-b)<=4*a*b)puts("No");
    else puts("Yes");
}

Measured memory_bytes: 256
from sys import stdin
def main():
  from builtins import int, range
  readline = stdin.readline
  n, w = [int(e) for e in readline().split()]
  t = [-1 for i in range(w + 1)]
  t[w] = 0
  for _ in range(n):
    nw, nv = [int(e) for e in readline().split()]
    for i in range(nw, w + 1):
      if t[i] == -1:
        continue
      if t[i - nw] < t[i] + nv:
        t[i - nw] = t[i] + nv
  print(max(t))
main()

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

int maxtime(int x){
  return ((x+9)/10)*10;
}
int retime(int x){
  return maxtime(x) - x;
}
int main(){
  int a, b, c, d, e;
  cin >> a >> b >> c >> d >> e;
  int q[5];
  q[0] = retime(a);
  q[1] = retime(b);
  q[2] = retime(c);
  q[3] = retime(d);
  q[4] = retime(e);

  sort(q, q+5);

  int ans = maxtime(a) + maxtime(b) + maxtime(c) + maxtime(d) + maxtime(e) - q[4];
  cout << ans << endl;
}
  
  
  

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
#define ii pair<int,int>
#define ll long long
#define pll pair<ll,ll>
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
#define iiordered_set tree<pll, null_type,less<pll>, rb_tree_tag,tree_order_statistics_node_update>
using namespace std;
#define MOD (1000*1000*1000+7)
ll power(ll a,ll b, ll m=MOD)
{
    ll res=1;
    while(b>0)
    {
        if(b&1)
            res=(res*a)%MOD;
        a=(a*a)%MOD;
        b>>=1;
    }
    return res;
}
ll inverse(ll a,ll m=MOD)
{
    return power(a,m-2,m);
}
int ceil(int a,int b)
{
    return (a+b-1)/b;
}
#define INFl (1e18+5)
#define vi vector<int>
#define vvi vector<vi>
#define vl vector<long long>
#define vvl vector<vl>
#define vll vector<pll>
#define vii vector<ii>
#define vvii vector<vii>
#define tri pair<int,ii>
#define F first
#define S second
#define forl(i,n) for(int i=0;i<n;i++)
#define fore(i,n) for(int i=1;i<=n;i++)
#define rforl(i,n)  for(int i=n-1;i>=0;i--)
#define rfore(i,n)  for(int i=n;i>=1;i--)
#define CASE(t) cout<<"Case #"<<(t)<<": ";
#define INF 1020000000
#define gcd(a,b) __gcd(a,b)
#define all(x)  x.begin(),x.end()
#define mp make_pair
#define pb push_back
#define print(x)    for(auto it=x.begin();it!=x.end();it++) cout<<*it<<' '; cout<<endl;
#define printii(x)  for(auto it=x.begin();it!=x.end();it++) cout<<it->F<<' '<<it->S<<endl;  
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)

int main()
{
	ll ans=0;
	int n;
	cin>>n;
	vl a(n),cnt(n+1,0);
	forl(i,n)	cin>>a[i],cnt[a[i]]++;
	fore(i,n)
	{
		ll x=cnt[i];
		ans+=x*(x-1)/2;
	}
	forl(i,n)
	{
		cout<<ans-cnt[a[i]]+1<<endl;
	}
}

Measured memory_bytes: 5760
k,a,b=map(int,input().split())
ans=0
if a+1<=k and b>a+2:
  k=k-(a+1)
  ans+=b
  mul,mod=divmod(k,2)
  ans+=(mul)*(b-a)
  ans+=mod
  print(ans)
else:
  print(1+k)


Measured memory_bytes: 3060
#include <iostream>

using namespace std;

int main()
{
  int a[] = {0, 1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  
  short k;
  cin >> k;
  
  cout << a[k];
  
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include <numeric>
#include <queue>
#include <numeric>
#include <iomanip>
#include <sstream>
#include <cmath>
#include <map>
#include <functional>
#include <limits>
#include <set>
#include <stack>
#define rep(i,a,b) for((i)=a;i<(int)(b);i++)
#define max(a,b) ((a) < (b) ? (b) : (a))
#define min(a,b) ((a) > (b) ? (b) : (a))
#define AAA (1000000007)

using namespace std;
typedef long long ll;
typedef unsigned long long ull;



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

ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}



int main() {
	int i, j, k;
	//ll N, M, K;
	int N, M, K;
	int A[3];


	cin >> N >> A[0] >> A[1] >> A[2];
	
	pair<int, int> D[100000];

	int An[3] = { 0 };
	int Ap[3];
	int Am[3];

	rep(i, 0, N) {
		string S;
		cin >> S;
		if (S[0] == 'A')
			D[i].first = 0;
		else if (S[0] == 'B')
			D[i].first = 1;
		else
			D[i].first = 2;

		if (S[1] == 'A')
			D[i].second= 0;
		else if (S[1] == 'B')
			D[i].second = 1;
		else
			D[i].second = 2;

		An[D[i].first]++;
		An[D[i].second]++;

	}

	bool canClear = true;

	vector<int> ans;
	rep(i, 0, N-1) {
	//	printf("%d %d %d\n", A[0], A[1], A[2]);
		if (A[0] < 0 || A[1] < 0 || A[2] < 0)
			canClear = false;
		if (A[D[i].first] <= 0 && A[D[i].second] <= 0 ) {
			canClear = false;
			break;
		}
		if (D[i] == D[i + 1]) {
			if (A[D[i].first] > A[D[i].second]) {
				A[D[i].first] --;
				A[D[i].second] ++;
				ans.push_back(D[i].second);
			}
			else {
				A[D[i].first] ++;
				A[D[i].second] --;
				ans.push_back(D[i].first);
			}
			
		}
		else if (D[i] != D[i + 1]) {
			
			int same;//次の交換のうち、今回触るもの
			int other1;//今回の交換で、sameでないほう
			int other2;//次の交換で、sameでないほう
			if (D[i].first == D[i + 1].first)
				same = D[i].first;
			else if (D[i].first == D[i + 1].second)
				same = D[i].first;
			else if (D[i].second == D[i + 1].first)
				same = D[i].second;
			else if (D[i].second == D[i + 1].second)
				same = D[i].second;
			if (D[i].first == same)
				other1 = D[i].second;

			else
				other1 = D[i].first;
			if (D[i+1].first == same)
				other2 = D[i+1].second;

			else
				other2 = D[i+1].first;

			if (A[same] == 1 && A[other2] == 0) {
				A[other1] --;
				A[same]++;
				ans.push_back(same);
				continue;
			}
			if (A[D[i].first] > A[D[i].second]) {
				A[D[i].first] --;
				A[D[i].second] ++;
				ans.push_back(D[i].second);
			}
			else {
				A[D[i].first] ++;
				A[D[i].second] --;
				ans.push_back(D[i].first);
			}
		}

	}
	if (A[0] < 0 || A[1] < 0 || A[2] < 0)
		canClear = false;

	i = N - 1;
	if (A[D[i].first] <= 0 && A[D[i].second] <= 0) {
		canClear = false;
	}
	else if (A[D[i].first] !=0) {
		ans.push_back(D[i].second);
	}
	else {
		ans.push_back(D[i].first);
	}
	if (!canClear) {
		cout << "No";
	}
	else {
		cout << "Yes\n";
		for (auto x : ans) {
			printf("%c\n", ('A' + x));


		}

	}
	return 0;

}


Measured memory_bytes: 4692
#include <iostream>
#include <algorithm>

using namespace std;
typedef long long ll;

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

    pair<int, int> P[N];

    int a, b;
    for(int i = 0; i < N; i++) {
        cin >> a >> b;
        P[i] = make_pair(b, a);
    }

    sort(P, P + N);

    int t = 0;
    bool flg = true;
    for(int i = 0; i < N; i++) {
        t += P[i].second;
        if(t > P[i].first) {
            flg = false;
            break;
        }
    }

    if(flg) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 1792
x = int(input())
l = []
d = {}
for i in range(1000):
  b = (-1000+i)**5
  d[b] = -1000+i
for i in range(1000):
  a = i**5
  d[a] = i
  if a-x in d:
    b = d[a-x]
    a = i
    break
print(a,b)

Measured memory_bytes: 9276
N, A = [int(x_i) for x_i in input().split()]
x = [int(x_i) - A for x_i in input().split()]

X = max(x + [A])

dp=[[0] * (2*N*X + 1) for _ in range(N + 1)]

for j in range(N+1):
    for t in range(2*N*X):
        if j==0 and t==N*X:
            dp[j][t] = 1
        elif t-x[j-1] < 0 or t-x[j-1] > 2*N*X:
            dp[j][t] = dp[j-1][t]
        elif 0 < t-x[j-1] and t-x[j-1] < 2*N*X:
            dp[j][t] = dp[j-1][t] + dp[j-1][t-x[j-1]]
        else:
            dp[j][t] = 0

print(dp[N][N*X]-1)

Measured memory_bytes: 5228
#include<cstdio>
#include<iostream>
#include<cstring>
#define RG register
using namespace std;
const int N=1e5+10;
int n,m,q,num[N],cnt,sum[N],pos[N],a[N];
bool vis[N];
template<typename I> inline void read(I &ot){
	I ch=getchar(), x=0, f=1;
	while(ch<'0' || ch>'9'){if(ch=='-') f=-1; ch=getchar();	}
	while(ch>='0' && ch<='9'){x=x*10+ch-'0'; ch=getchar();	}
	ot=x*f;}
template<typename I, typename... U> inline void read(I &x,U&... y){read(x); read(y...);}
int main()
{
	//freopen("LRU Puzzle.in","r",stdin);
	read(n,m,q);
	for(RG int i=1;i<=q;i++) read(a[i]);
	for(RG int i=q;i;i--)
	 if(!vis[a[i]])
	 {
		num[++cnt]=a[i];
		pos[a[i]]=cnt;
		vis[a[i]]=1;
	 }
	for(RG int i=1, cnt2=0;i<=m;i++) if(!vis[i]) num[cnt+(++cnt2)]=i;
	sum[0]=n;
	for(RG int i=q;i;i--)
	{
		int tt=pos[a[i]];
		if(sum[tt-1])
		{
			sum[tt-1]--;
			sum[tt]++;
		}
	}
	int st=n;
	for(RG int i=0;i<=cnt && st==n;i++) if(sum[i]) st=i;
	for(RG int i=st+2;i<=m;i++)
	 if(num[i]<num[i-1])
	 {
		printf("No\n");
		return 0;
	 }
	printf("Yes\n");
	return 0;
}

Measured memory_bytes: 1920
#include<bits/stdc++.h>
#include<iostream>
using namespace std;
typedef long long ll;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);

         int n;
         cin>>n;
         int k=1000;
        int ans;
        int i=1;
        while(k<n)
        {
        	k=1000*i;
        	i++;
		}
		ans=k-n;
		cout<<ans;
         
		
		   
}


Measured memory_bytes: 3648
#include<stdio.h>
#include<ctype.h>
int main(void)
{
    char ch,CH;
    while(1){
        scanf("%c",&ch);
        CH = tolower(ch);
        if(ch==CH) CH = toupper(ch);
        printf ("%c",CH);
        if(ch=='\n')break;
    }
    //printf("\n");


    return 0;
}

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


int a[12][12];
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);

    int x,y;
    int ans;
    cin >> x >> y;
    if(x == 1 || y == 1){
        ans = ans | 0b001;
    }
    if(x == 2 || y == 2){
        ans = ans | 0b010;
    }
    if(x == 3 || y == 3){
        ans = ans | 0b100;
    }
    if(!(ans & 0b001)){
        cout << 1 << endl;
    }else if(!(ans & 0b010)){
        cout << 2 << endl;
    }else{
        cout << 3 << endl;
    }


    cout << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
using namespace std;
typedef long long ll;
const int N = 200005;
struct hh {
	string str;
	int ans;
}jj[N];
bool cmp(hh a, hh b) {
	if (a.ans == b.ans) return a.str < b.str;
	else return a.ans > b.ans;
}

int main() {
	string a[N];//
	int p = 1;
	int n;
	cin >> n;
	for (int i = 1; i <= n; i++) { cin >> a[i];}
	sort(a + 1, a + n + 1);
	int pow = 1;
	while (pow <= n) {
		int ans = 1;
		while (pow+1<=n&&a[pow] == a[pow + 1]) { pow++; ans++; }
		jj[p].ans = ans;
		jj[p].str = a[pow];
		pow++; p++;
	}
	sort(jj + 1, jj + p, cmp);
	int ansx = jj[1].ans;
	for (int i = 1; i < p; i++) {
		if (ansx != jj[i].ans) break;
		cout << jj[i].str << endl;
	}

	return 0;
}

Measured memory_bytes: 17408
#include<bits/stdc++.h>
using namespace std;
//Optimisations
#pragma GCC target ("avx2")
#pragma GCC optimization ("unroll-loops")
#pragma GCC optimize("O2")
//shortcuts for functions
#define pb push_back
#define mp make_pair
#define ff first 
#define ss second
#define all(v) v.begin(),v.end()
#define prec(n) fixed<<setprecision(n)
#define n_l '\n'
// make it python 
#define gcd __gcd
#define append push_back
#define str to_string
// utility functions shortcuts
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define sswap(a,b) {a=a^b;b=a^b;a=a^b;}
#define swap(a,b) {auto temp=a; a=b; b=temp;}
#define init(dp) memset(dp,-1,sizeof(dp));
#define set0(dp) memset(dp,0,sizeof(dp));
#define bits(x) __builtin_popcount(x)
#define SORT(v) sort(all(v))
#define endl "\n"
#define forr(i,n) for(ll i=0;i<n;i++)
// declaration shortcuts
typedef long long int ll;
#define int ll
// Constants
constexpr int dx[] = {-1, 0, 1, 0, 1, 1, -1, -1};
constexpr int dy[] = {0, -1, 0, 1, 1, -1, 1, -1};
constexpr ll INF = 1999999999999999997; 
constexpr int inf= INT_MAX;
constexpr int MAXSIZE = int(1e6)+5;
constexpr auto PI  = 3.14159265358979323846L;
constexpr auto oo  = numeric_limits<int>::max() / 2 - 2;
constexpr auto eps = 1e-6;
constexpr auto mod = 1000000007;
constexpr auto MOD = 1000000007;
constexpr auto MOD9 = 1000000009;
constexpr auto maxn = 100006;
//void IOfile(){
//freopen(file_name, reade_mode, stdin);
//freopen(file_name, write_mode, stdout);
//}
void fastio(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
}
int32_t main(){
	fastio();
	int a,b;
	cin >> a >> b;
	(a+ b) % 2 ? cout << "IMPOSSIBLE":cout <<(a+b)/2;
}

Measured memory_bytes: 3600
// clang-format off

#include <bits/stdc++.h>

#define int long long int
#define main signed main()
#define bye return 0
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define each(p, v) for (auto p = (v).begin(); p != (v).end(); p++)
#define all(v) (v).begin(), (v).end()
#define prec(n) fixed << setprecision(n)
#define dump(x) cerr << "(L" << __LINE__ << ") " << #x << " = " << (x) << endl
#define clr(x, a) memset(x, a, sizeof(x))

#define stlice(from, to) substr(from, (to) - (from) + 1)
#define odd(n) ((n) % 2)
#define even(n) (!odd(n))

#define INF 1000000000
#define INFLL 1000000000000000000LL
#define MOD 1000000007
#define PI acos(-1)

#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define vi vector<int>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define pii pair<int, int>

using namespace std;

// clang-format on

main {
  string s;
  cin >> s;
  int c = 0;
  rep(i, 1 << s.size() - 1) {
    string t = s;
    rep(j, s.size() - 1) if (i >> j & 1) t.insert(s.size() - j - 1, "+");
    stringstream ss;
    ss << t << "gomi";
    int n;
    char gomi;
    while (ss >> n >> gomi) {
      c += n;
    }
  }
  cout << c << endl;
  bye;
}


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

#define F first
#define S second
#define nl '\n'
#define gcd __gcd
#define nset __builtin_popcount
#define pb push_back
#define btoe(x) x.begin(), x.end()
#define trim_chains(x) (x).resize(unique(btoe(x)) - (x).begin())
#define remove_dups(x) sort(btoe(x)); trim_chains(x);
#define rep(i, a, b)  for (int i = int(a); i <= int(b); i++)
#define nrep(i, a, b) for (int i = int(a); i >= int(b); i--)
#define FASTIO ios_base::sync_with_stdio(false); cin.tie(NULL)

using ll  = long long;
using ull = unsigned long long;
using vi  = vector<int>;
using vl  = vector<long>;
using vll = vector<ll>;
using vb  = vector<bool>;
using vvb = vector<vb>;
using vvi = vector<vector<int> >;
using ii  = pair<int, int>;
using vii = vector<ii>;
using vs  = vector<string>;
using msi = map<string, int>;
using iss = istringstream;

ll M = 1e9 + 7;

ll mod(ll x, ll M)
{
    ll res = x % M;
    return (res >= 0 ? res : res + M);
}

ll powmod(ll x, ll n, ll M)
{
    if(n == 0) return 1%M;
    ll half = powmod(x, n/2, M);
    if(n % 2 == 0) return (half*half)%M;
    return (((half*half)%M)*x)%M;
}

ll modinv(ll a, ll M)
{
    ll x = a, y = M;
    ll sx = 1, tx = 0;
    ll sy = 0, ty = 1;

    while(y != 0) {
        ll q = x/y;
        ll r = x%y;
        ll nsx = sy;
        ll ntx = ty;
        sy = sx - q*sy;
        ty = tx - q*ty;
        sx = nsx; tx = ntx;
        x = y; y = r;
    }

    if(sx < 0) sx += M;
    return sx;
}

vll ftable(5e5 + 1, 1);
ll fact(ll x, ll M)
{
    if(x <= 1) return 1;
    if(ftable[x] == 1) {
        ftable[x] = (x * fact(x-1, M)) % M;
    }
    return ftable[x];
}

ll combo(ll n, ll r, ll M)
{
    ll num = fact(n, M);
    ll denom = (fact(n - r, M) * fact(r, M))%M;
    ll dinv = modinv(denom, M);

    return (num * dinv) % M;
}

int main()
{
    FASTIO;
    ll n, m;
    cin >> n >> m;
    ll dfor1perm = 0;


    ll p = 1;
    rep(i, 1, n) {
        // cout << combo(m-i, n-i, M) << nl;
        dfor1perm += mod(p*((combo(n, i, M)*combo(m - i, n - i, M))%M*fact(n - i, M)), M);
        dfor1perm = mod(dfor1perm, M);
        // cout << "dfor1perm = " << dfor1perm << nl;
        p *= -1;
    }


    ll afor1perm = mod(combo(m, n, M) * fact(n, M), M);
    afor1perm = mod(afor1perm - dfor1perm, M);
    // cout << "afor1perm = " << afor1perm << nl;

    ll ans = mod((combo(m, n, M) * fact(n, M))%M * afor1perm, M);
    cout << ans << nl;
    return 0;
}


Measured memory_bytes: 22648
import java.util.Scanner;


public class Main {
  public static void main(String[] args) {
    Scanner scan = new Scanner(System.in);
    int n = scan.nextInt();
    if (2 <= n && n <= 1.0e5) {
      int[] sunukenoaho = new int[n];
      for (int i = 0; i < n ; i++) {
        sunukenoaho[i] = scan.nextInt();
      }
      int n4 = 0;
      int nodd = 0;
      int neven = 0;
      for (int i = 0; i < n; i++) {
        if (sunukenoaho[i] % 4 == 0) {
          n4++;
        } else if(sunukenoaho[i] % 2 == 0) {
          neven++;
        } else {
          nodd++;
        }
      }

      if (neven > 0) {
        nodd++;
      }

      if (n4 >= nodd - 1) {
        System.out.println("Yes");
      } else {
        System.out.println("No");
      }
    }
  }
}


Measured memory_bytes: 49776
N, P = map(int, input().split())

if N == 1:
    print(P)
    exit()

div = 2
res = 1
R = P

while div * div <= R and div <= P:
    cnt = 0
    while P % div == 0:
        P /= div
        cnt += 1

        if cnt == N:
            res *= div
            cnt = 0
    div += 1

print(res)


Measured memory_bytes: 3188
use proconio::fastout;
use whiteread::parse_line;

#[fastout]
fn main() {
    let (n, mut k): (usize, usize) = parse_line().unwrap();

    let mut ret = 0;

    if k == 0 {
        for b in 1..=n {
            ret += n / b;
        }

        k += 1;
    }

    for b in (k + 1)..=n {
        ret += ((n - k) / b + 1) * (b - k);
        if (n - k) % b + 1 <= b - k - 1 {
            ret -= b - k - (n - k) % b - 1;
        }
    }
    println!("{}", ret);
}


Measured memory_bytes: 2204
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n,i;
  cin>>n;
  int a[n],b[n],c[n];
  for(i=0;i<n;i++)
  {
    cin>>a[i]>>b[i]>>c[i];
  }
  for(i=1;i<n;i++)
  {
    a[i]+=max(b[i-1],c[i-1]);
    b[i]+=max(a[i-1],c[i-1]);
    c[i]+=max(a[i-1],b[i-1]);
    
  }
  cout<<max({a[n-1],b[n-1],c[n-1]})<<endl;
  
}
  

Measured memory_bytes: 1408
//Compete against Yourself.
#include <bits/stdc++.h>
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long
#define sz(i) (int)(i.size())
#define F first
#define S second
#define L long double
#define P pair<int, int>
const int inf = 0x3f3f3f3f3f3f3f3LL;
const int mod = (int)1e9 + 7;
using namespace std;
#if LOCAL
#include "../../tr.h"
#else
#define tr(...)
#define endl '\n'
#endif
template<class T> void smin(T& a, T val) {if (a > val) a = val;}template<class T> void smax(T& a, T val) {if (a < val) a = val;}
const int N = 5*(int)1e5 + 10;

const int MX = 1e9;
int n, a[N], k, s;

int32_t main(){_
   
   cin>>n>>k>>s;

   vector<int> a;
   if (s != MX){
      
      for (int i = 0; i < k; ++i)
      {
         a.push_back(s);
      }

      for (int i = k; i < n; ++i)
      {
         a.push_back(MX);
      }

   }

   else{
      for (int i = 0; i < k; ++i)
      {
         a.push_back(s);
      }

      for (int i = k; i < n; ++i)
      {
         a.push_back(s-1);
      }

   }


   for(auto it: a)
      cout<<it<<" ";

   return 0;
}

Measured memory_bytes: 2292
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define o(a) cout << a << endl
#define int long long
#define fi first
#define se second
using namespace std;
typedef pair<int, int> P;

signed main(){
    int n, k;
    cin >> n >> k;
    int sum = 0;
    vector<int> a(n);
    rep(i, 0, n){
        cin >> a[i];
        if(a[i] > 0) sum += a[i];
    }
    vector<int> s(n, 0);
    vector<int> s2(n, 0);
    if(a[0] < 0) s[0] = a[0];
    if(a[0] > 0) s2[0] = a[0];
    rep(i, 1, n) s[i] += s[i - 1] + (a[i] < 0 ? a[i] : 0);
    rep(i, 1, n) s2[i] += s2[i - 1] + (a[i] > 0 ? a[i] : 0);
    int MAX = -1e15;
    rep(i, 0, n - k + 1){
        MAX = max(MAX, sum + s[i + k - 1] - (i != 0 ? s[i - 1] : 0));//黒
        MAX = max(MAX, sum - s2[i + k - 1] + (i != 0 ? s2[i - 1] : 0 ));//白
    }
    // cout << MAX << endl;
    int ans = max((int)0, MAX);
    cout << ans << endl;
}

Measured memory_bytes: 2688
s = int(input())
mod = 10 **9 + 7

if s <= 2:
    print(0)
else:
    dp = [1] * (s + 1)
    dp[0:3] = [0] * 3
    dp[3] = 1

    for i in range(4, s + 1):
        count = 0
        for j in range(3, i - 2):
            dp[i] += dp[i - j]
            dp[i] %= mod
    # print(dp)
    print(dp[s])
            


Measured memory_bytes: 9172
#include <stdio.h>

int isprime(int n){
    int i;
    for(i=2;i*i<=n;i++){
        if(n%i==0) return 0;
    }
    return 1;
}

int main(){
    int n,i,max=0,max2;
    while(1){
    scanf("%d",&n);
    for(i=n;i>0;i--){
        if(isprime(i)==1){
            if(isprime(i-2)==1){
                max=i;
                break;
            }
        }
    }
    if(n==0){
        break;
    }
    max2=max-2;
    printf("%d %d\n",max2,max);
    }
    return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
using ll = long long ;
using P = pair<int,int> ;
using pll = pair<long long,long long>;
constexpr int INF = 1e9;
constexpr long long LINF = 1e17;
constexpr int MOD = 1000000007;

int main(){
    ll n,p,q;
    cin >> n >> p >> q;
    vector<int> c(n);
    ll ans = 0;
    rep(i,n){
        cin >> c[i];
        ans += c[i];
    }
    vector<ll> score(n);
    rep(i,n) score[i] = c[i] + p * i;
    sort(score.begin(),score.end());
    rep(i,n) score[i] = 2*p*i + p*q - score[i];
    rep(i,n-1) score[i+1] += score[i];
    ll mx = 0;
    rep(i,n){
        mx = max(mx,score[i]);
    }
    ans += mx;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 8644
let to_list s =
  Str.split (Str.regexp_string " ") s
  |> List.map int_of_string;;

let _ = read_int () and
    s = read_line () |> to_list and
    _ = read_int () and
    t = read_line () |> to_list in
    let count = List.fold_left (fun x y -> x + (if (List.exists (fun i -> if i = y then true else false) s) then 1 else 0) ) 0 t in
    Printf.printf "%d\n" count
;;

Measured memory_bytes: 4088
#include <bits/stdc++.h>
#define rep(i, n) for(int i= 0; i < (n); i++)
using ll= long long int;
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
ll mod= 1e9 + 7;


ll dp[1010][1010]={};

int main() {
  int h,w;
  cin >> h >>w;
  char a[h][w];
  rep(i,h){
    rep(r,w)cin >>a[i][r]; 
  }

  dp[0][0]=1;

  rep(i,h){
    rep(r,w){
      if(a[i+1][r]=='.'){dp[i+1][r]+=dp[i][r],dp[i+1][r]=dp[i+1][r]%mod;}
      if(a[i][r+1]=='.'){dp[i][r+1]+=dp[i][r],dp[i][r+1]=dp[i][r+1]%mod;}
    }
  }
  cout << dp[h-1][w-1] << endl;
}

Measured memory_bytes: 9088