akhauriyash/Code-Regression huggingface dataset:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# FileName: 	B
# CreatedDate:  2020-09-19 20:49:20 +0900
# LastModified: 2020-09-19 21:05:01 +0900
#


import os
import sys
# import numpy as np
# import pandas as pd


def main():
    N = int(input())
    deme = []
    for _ in range(N):
        D = list(map(int, input().split()))
        deme.append(D)
    for i in range(N-2):
        if deme[i][0] == deme[i][1] and \
           deme[i+1][0] == deme[i+1][1] and \
           deme[i+2][0] == deme[i+2][1]:
               print('Yes')
               return
    print('No')


if __name__ == "__main__":
    main()


Measured memory_bytes: 9200
how_many = input()
a = []
a = list(map(int, input().split()))
st = set(a)

c = 0
for i in a:
    p = str(i)
    c += len(p)
if (0 in st):
    print(0)
    quit()

max = 1
for i in a:
    max = max * i
    if(1000000000000000000 < max):
        print('-1')
        quit()
    
print(max)


Measured memory_bytes: 21740
import sys
a = list(sys.stdin.read().split())
t = list(zip(*[[int(n[:-1] or 0), int(n[-1])] for n in a]))
print((sum(t[0]) + len((u := sorted(filter(lambda n: n > 0, t[1])))[:0:-1])) * 10 + (u and u[0] or 0))

Measured memory_bytes: 8932
S = input()
MM = ["01","02","03","04","05","06","07","08","09","10","11","12"]

if S[:2] in MM and S[2:] in MM:
  print("AMBIGUOUS")
elif S[:2] in MM:
  print("MMYY")
elif S[2:] in MM:
  print("YYMM")
else:
  print("NA")

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

typedef long long int ll;
ll powk(ll a, ll n = 2){
    ll r = 1;
    for(ll i = 0;i < n;i++){
        r *= a;
    }

    return r;
}


int main()
{
    ll a, bi;
    string b;
    cin >> a >> b;

    b = b[0];
    b += b[2];
    b += b[3];

    bi = stoi(b);

    cout << a * bi / 100;

    return 0;
}

Measured memory_bytes: 3636
#include <algorithm>
#include <iostream>
#include <string>

using namespace std;

std::string Itoa(const int v, int base)
{
    static const char table[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    string ret;
    static numeric_limits<int> t;
    int n = v;
    if (t.is_signed) {
        if (v < 0) n *= -1;
    }

    while (n >= base) {
        ret += table[n%base];
        n /= base;
    }
    ret += table[n];
    if (t.is_signed) {
        if (v < 0 && base == 10) ret += '-';
    }
    // 文字列の順番を逆にする
    std::reverse(ret.begin(), ret.end());

    return ret;
}

int main(void){
    // Your code here!
    int n,k;
    cin >> n >> k;
    std::string s = Itoa(n, k);
    cout << s.size() << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main{
	
	public static void main(String[] args) {
		try(Scanner sc = new Scanner(System.in)) {
			boolean[] p = new boolean[104730];
			int[] s = new int[10001];
			int j = 0;
			s[j++] = 0;
			Arrays.fill(p, true);
			for(int i=2; i<104730; i++) {
				if(p[i]) {
					s[j] = s[j-1] + i;
					j++;
					for(int k=i*2; k<104730; k+=i) p[k] = false;
				}
			}
			
			while(true) {
				int n = sc.nextInt();
				if(n == 0) break;
				System.out.println(s[n]);
			}
		}
	}
}



Measured memory_bytes: 26660
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

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

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

int main() {
  int n;
  cin >> n;
  int a[n];
  REP(i, n) cin >> a[i];
  vector<int> cnt(n + 1);
  REP(i, n) cnt[a[i]]++;
  vector<int> cnt2(n + 1);
  REP1(i, n) cnt2[cnt[i]]++;
  vector<ll> sum1(n + 1), sum2(n + 1);
  REP1(i, n) {
    sum1[i] = sum1[i - 1] + i * cnt2[i];
    sum2[i] = sum2[i - 1] + cnt2[i];
  }
  REP1(k, n) {
    int ok = 0, ng = n + 1;
    while (1 < abs(ok - ng)) {
      int x = (ok + ng) / 2;
      ll sum = sum1[x] + x * (sum2[n] - sum2[x]);
      if (k <= sum / x) {
        ok = x;
      } else {
        ng = x;
      }
    }
    cout << ok << endl;
  }
  return 0;
}

Measured memory_bytes: 9088
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin>>n;
    int a[n];
    for(int i = 0; i <n; i++) cin>>a[i];
    int sum = 0;
    sort(a, a+n);
    for(int i = 0; i<n; i++){
        if(i%2==0) sum+=a[i];
        else sum-=a[i];
    }
    cout<<abs(sum);
    return 0;
}


Measured memory_bytes: 256
N=int(input())
Set=set()
List=[]
Data=list(map(int,input().split()))

for i in range(N):
    if Data[i] not in Set:
        Set.add(Data[i])
    else:
        Set.remove(Data[i])
        List.append(Data[i])
if len(List)<2:print("0")
else:
    List=sorted(List)
    print(List[-1]*List[-2])

Measured memory_bytes: 14224
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>

using namespace std;

class range {
private:
  struct Iterator {
    int val;
    int operator*() {return val;}
    bool operator!=(Iterator& itr) {return val < itr.val;}
    void operator++() {++val;}
  };
  Iterator i, n;
public:
  range(int n) : i({0}), n({n}) {}
  range(int i, int n) : i({i}), n({n}) {}
  Iterator& begin() {return i;}
  Iterator& end() {return n;}
};

template<class T> inline T at(const vector<T> &v, int i) {return v[(i % (int)v.size() + v.size()) % v.size()];}

template<class T> inline bool is_max(T &a, const T &b) {return a < b ? a = b, true : false;}
template<class T> inline bool is_min(T &a, const T &b) {return a > b ? a = b, true : false;}

int main() {
  int t;
  cin >> t;
  for (int _ : range(t)) {
    int n;
    string s, s1, s2;
    cin >> n >> s;
    s1 = "N" + s.substr(0, n * 2) + "N";
    s2 = "N" + s.substr(n * 2) + "N";
    n = n + 1;
    int res = n + 1;
    for (int i : range(n)) {
      if (s1[2 * i] == 'Y' || s1[2 * i + 1] == 'Y') ++res;
      if (s2[2 * i] == 'Y' || s2[2 * i + 1] == 'Y') ++res;
    }
    for (int i : range(n)) {
      if (s1[2 * i] == 'Y' || s1[2 * i + 1] == 'Y') {
        --res;
        break;
      }
      if (s2[2 * i] == 'Y' || s2[2 * i + 1] == 'Y') break;
    }
    reverse(s1.begin(), s1.end());
    reverse(s2.begin(), s2.end());
    for (int i : range(n)) {
      if (s1[2 * i] == 'Y' || s1[2 * i + 1] == 'Y') {
        --res;
        break;
      }
      if (s2[2 * i] == 'Y' || s2[2 * i + 1] == 'Y') break;
    }
    cout << res << endl;
  }
}

Measured memory_bytes: 1328
inp = input()

strw, strh, strx, stry, strr = inp.split()

w = int(strw)
h = int(strh)
x = int(strx)
y = int(stry)
r = int(strr)

if x > 0 and y > 0 and w - x >= r and h - y >= r:
  print("Yes")
else:
  print("No")



Measured memory_bytes: 5596
import math
N = int(input())
l = []
for i in range(N):
  l.append(list(map(int,input().split())))
c = 0
for i in range(N):
  for j in range(i+1,N):
    c +=((l[i][0]-l[j][0])**2 + (l[i][1]-l[j][1])**2)**(1/2)
print(2*c/N)

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

#define int long long

signed main(void) {
  int num; // num
  num = 0; // count, result
  // num = numeric_limits<int>::min(); // max
  // num = numeric_limits<int>::max(); // min
  int N;
  // int M;
  // array<int, 1000000> A;;
  // string S;
  // string T;

  cin >> N;
  cout << (N / 2) * (N / 2 + N % 2) << endl;
  
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.nextLine());
        String s = sc.nextLine();

        char before = s.charAt(0);
        int ans = 1;
        for (int i = 1; i < n; i++) {
            if (s.charAt(i) != before) {
                before = s.charAt(i);
                ans++;
            }
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 26196
#include <iostream>
#include <string>
#include <math.h>
#include <algorithm>
#include <stdlib.h>
#include <vector>
#include <map>
typedef long long ll;
using namespace std;

int main()
{
	ll n,k;
	cin >> n >> k;
	n=n-k*(n/k);
	while (abs(n-k)<n)
		n=abs(n-k);
	cout << n;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

int main()
{
    int n;
    while(cin >>n,n)
    {
        vector<char> c(n);
        rep(i,n) cin >>c[i];

        int v[26]={};
        bool determined = false;
        char x;
        int y;
        rep(i,n)
        {
            ++v[c[i]-'A'];
            int r = n-1-i;

            int win[26]={};
            rep(j,26)
            {
                v[j] += r;

                int m = 0;
                rep(k,26) m = max(m,v[k]);

                int ct = 0, idx = 0;
                rep(k,26)
                {
                    if(v[k]==m)
                    {
                        ++ct;
                        idx=k;
                    }
                }
                if(ct==1) ++win[idx];

                v[j] -= r;
            }

            rep(j,26)
            {
                if(win[j]==26)
                {
                    determined = true;
                    x = 'A'+j;
                    y = i+1;
                }
            }
            if(determined) break;
        }

        if(determined) printf("%c %d\n",x,y);
        else printf("TIE\n");
    }
    return 0;
}

Measured memory_bytes: 3192
#include <iostream>
using namespace std;
long long ans, x, pre_x, n;
int main(){
    cin >> n >> pre_x;
    for(int i = 1; i < n; i++){
        cin >> x;
        if(x < pre_x){
            ans += pre_x - x;
        }
        else pre_x = x;
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 3552
#include "bits/stdc++.h"
using namespace std;
using ll=long long;
#define print(n) cout<<n<<endl
#define rep(i,a,n) for(int i=a;i<n;i++)
#define ALL(s) s.begin(),s.end()
#define P pair<ll,ll>
#define vl vector<ll>
#define vi vector<int>
#define vvl vector<vector<ll>>
#define vvi vector<vector<int>>
const int M=200111;
const int inf=1000000007;
const long long INF=1e18;
int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};
int ddx[8]={1,-1,0,0,1,-1,-1,1},ddy[8]={0,0,1,-1,1,-1,1,-1};


struct UnionFind {
	vector<int> par;
	UnionFind(int n) : par(n, -1) { }

	int root(int x) {
		if (par[x] < 0) return x;
		else return par[x] = root(par[x]);
	}

	bool same(int x, int y) {
		return root(x) == root(y);
	}

	bool merge(int x, int y) {
		x = root(x); y = root(y);
		if (x == y) return false;
		if (par[x] > par[y]) swap(x, y); // merge technique
		par[x] += par[y];
		par[y] = x;
		return true;
	}

	int size(int x) {
		return -par[root(x)];
	}
};

vvl comb(int n, int r) {
	vvl v(n + 1,vl(n + 1, 0));
	for (int i = 0; i < v.size(); i++) {
		v[i][0] = 1;
		v[i][i] = 1;
	}
	for (int j = 1; j < v.size(); j++) {
		for (int k = 1; k < j; k++) {
			v[j][k] = (v[j - 1][k - 1] + v[j - 1][k]);
		}
	}
	return v;
}

void sosu(ll x,bool f[]){
	ll y=x;
	for(ll i=2;i<=sqrt(y);i++){
		if(x%i==0){
			x/=i;
			f[i]=true;
			i--;
		}
	}
}

ll __gcd(ll x,ll y){
	if(x<y)swap(x,y);
	while(1){
		ll tmp=x%y;
		x=y;
		y=tmp;
		if(y==0)break;
	}
	return x;
}

int keta(ll a){
	int ke=1;
	while(a/=10)ke++;
	return ke;
}


int main() {
	int n,l[M];ll ans=0;
	cin>>n;rep(i,0,n)cin>>l[i];
	sort(l,l+n);
	rep(i,0,n-2)rep(j,i+1,n-1){
		rep(k,j+1,n){
			if(l[i]+l[j]<=l[k])break;
			ans++;
		}
	}
	print(ans);
}


Measured memory_bytes: 256
// Math = ♥️

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;

#define ll long long
#define ld long double
typedef pair<ll, ll> ii;
typedef vector<ll> vi;
typedef vector<bool> vb;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<vii> vvii;
#define pq priority_queue
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(), (c).end()
#define sz(c) ((ll)c.size())
#define ordered_set                            \
    tree<ll, null_type, less<ll>, rb_tree_tag, \
         tree_order_statistics_node_update>

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

    ll n;
    cin >> n;
    vi arr(n + 1);
    for (auto &it : arr) {
        cin >> it;
    }

    if (n == 0) {
        if (arr[0] == 1) {
            cout << "1\n";
            return 0;
        } else {
            cout << "-1\n";
            return 0;
        }
    }

    if (arr[0] != 0) {
        cout << "-1\n";
        return 0;
    }

    if (n == 1 && arr[0] == 0 && arr[1] == 1) {
        cout << "2\n";
        return 0;
    }

    vi pre(n + 1);
    pre[n] = 0;
    for (int i = n - 1; i >= 0; i--) {
        pre[i] = pre[i + 1] + arr[i + 1];
    }

    ll ans = 1, curr = 2;
    for (int i = 1; i <= n; i++) {
        if (curr < arr[i]) {
            cout << "-1\n";
            return 0;
        }
        ans += arr[i];
        curr -= arr[i];
        ans += curr;
        curr = min(curr * 2, pre[i]);
    }

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


Measured memory_bytes: 4716
import sys
stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

n = ni()
m = 10**7
a = 1
i = 1

while a <= m:
    if a >= n:
        break
    i+=1
    a+=i

ans = [j for j in range(1,i+1) if j != a-n]

print(*ans,sep="\n")

Measured memory_bytes: 3572
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll GCD(ll x,ll y){
    if(y == 0) return x;
    else return GCD(y,x%y);
}
const int MOD = 1000000007;

int main() {
    int n; cin >> n;
    int a = n;
    int total = 0;
    while(a % 10 != 0){
        total += a % 10;
        a /= 10;
    }
    if(n % total == 0){
        cout << "Yes";
    }else{
        cout << "No";
    }
}




Measured memory_bytes: 256
#ifndef ONLINE_JUDGE
    #include "debug.cpp"
#endif

#include <bits/stdc++.h>

using namespace std;

#define int long long
#define ar array

const int mxN = 2e5;
vector<int> adj[mxN];
vector<int> vis(mxN,0);

int  cdp(int u){
	if(!vis[u]){
		for(auto e : adj[u]){
			vis[u] = max(cdp(e), vis[u]);
		}
		++vis[u];
	}
	return vis[u];
}

void solve(){
	int n, m;
	cin >> n >> m;
	while(m--){
		int u, v;
		cin >> u >> v;
		--u;--v;
		adj[u].emplace_back(v);
	} 
	int ans = 0;
	for(int i = 0;i < n; i++){
		ans = max(ans, cdp(i));
	}
	cout << --ans << "\n";
}

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

    int TC = 1;
    while(TC--)
        solve();

    return 0;
}



Measured memory_bytes: 14448
#include <algorithm>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for(int i = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int i = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define MP make_pair
#define pb push_back
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1 << 30;
const ll LINF = 1LL << 61;
const int MOD = 1e9 + 7;

int main() {
    int W, H, N;
    cin >> W >> H >> N;
    int x1 = 0, x2 = W, y1 = 0, y2 = H;
    rep(i, N) {
        int x, y, a;
        cin >> x >> y >> a;
        if(a == 1) {
            x1 = max(x1, x);
        } else if(a == 2) {
            x2 = min(x2, x);
        } else if(a == 3) {
            y1 = max(y1, y);
        } else {
            y2 = min(y2, y);
        }
    }
    if((x2 - x1) <= 0 || (y2 - y1) <= 0) {
        cout << 0 << endl;
    } else
        cout << (x2 - x1) * (y2 - y1) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define fo(i,n) for(i=0;i<n;i++)
#define Fo(i,k,n) for(i=k;i<n;i++)
#define ll long long
 
#define pi pair < ll , ll >
#define pb push_back
#define mp make_pair
#define F first
#define S second
 
#define fastIO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
 
#define debug(x) cout<<#x<<" :: "<<x<<"\n";
#define debug2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\n";
#define debug3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<"\n";
using namespace std;

const ll mod = 1e9 + 7;

void solve() {
    double x, y;
    ll i, j, pp;
    cin>>j;
    Fo(i,1,j+100) {
        x = i;
        x = x * 108;
        x /= 100;
        pp = x;
        if(pp==j){cout<<i;return;}
    }
    cout<<":(";
}

int main()
{
    fastIO;ll t=1;
    //cin>>t;
    while(t--)solve();
}

Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var n, y int
	fmt.Scan(&n, &y)

	var ans = []int{-1, -1, -1}
	for i := 0; i <= n; i++ {
		for j := 0; j <= n-i; j++ {
			for k := 0; k <= n-i-j; k++ {
				if i+j+k == n && i*10000+j*5000+k*1000 == y {
					ans[0] = i
					ans[1] = j
					ans[2] = k
				}
			}
		}
	}
	for _, v := range ans {
		fmt.Printf("%v ", v)
	}
	fmt.Println()
}


Measured memory_bytes: 512
#include <iostream>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <tuple>
#include <queue>
#include <set>
#include <cstdio>
#include <climits>
#include <cmath>
#include <array>
#include <functional>
#include <list>
#include <iomanip>
#include <set>
const int MOD=1000000007;
const int INF=1000000000;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
const double eps=1e-9;
const int inf=1e9;
typedef pair<int,int> P;

int dp[505][505];
string s;
typedef pair<int,int> P;
#define T 1
#define F 0

bool dfs(int l,int r)
{
  int &ret=dp[l][r];
  if(ret>=0) return ret;
  if(r-l==0) return ret=T;
  if(s[l]!='m' || s[r-1]!= 'w') return ret=F;
  ret=F;
  for(int m=l+1;m<r-1;m++)
    {
      if(s[m]=='e')
	{
	  if(dfs(l+1,m) && dfs(m+1,r-1))
	    {
	      return ret=T;
	    }
	}
    }
  return ret;
}
int main(int argc,char const* argv[])
{
  cin >> s;
  memset(dp,-1,sizeof(dp));
  if(dfs(0,s.size())) cout << "Cat" << endl;
  else cout << "Rabbit" << endl;
  return 0;
}



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

#define LL long long
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ALL(x) (x).begin(),(x).end()
const int IINF = 1e9;
const LL LINF = 1e18;
const LL mod = 1e9+7;

int main() {
    int N;
    cin >> N;
    int m2 = 0;
    int m4 = 0;
    REP(i, N) {
        int a;
        cin >> a;
        if(a%2 == 0) {
            m2++;
        }
        if(a%4 == 0) {
            m4++;
        }
    }
    if(N - m2 <= m4) {
        cout << "Yes" << endl;
    }else if(N - m2 + m4 == N && N - m2 - m4 == 1){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}



Measured memory_bytes: 256
import sys

def solve():
    s = input()
    t = input()
    x = len(s)
    for i in range(x):
        s = s[x - 1] + s[:x - 1]
        if s == t:
            print("Yes")
            break
    else: print("No")

    return 0

if __name__ == "__main__":
    solve()

Measured memory_bytes: 3064
#include<cstdio>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
long long int N,M;
long long int A[200000];
int main(){
    cin>>N>>M;
    for(int i=0;i<N;i++)cin>>A[i];
    sort(A,A+N);
    int l=0,r=300000,mid;
    for(int i=0;i<20;i++){
        mid=(l+r)/2;
        long long int cou=0;
        for(int j=0;j<N;j++){
            int ll=0,rr=N,midmid;
            for(int k=0;k<20;k++){
                midmid=(ll+rr)/2;
                if(mid<=A[j]+A[midmid])rr=midmid;
                else ll=midmid;
            }
            if(midmid==N-1&&A[j]+A[midmid]<mid){}
            else if(midmid==N-1)cou++;
            else{
                if(A[j]+A[midmid]<mid)midmid++;
                cou+=N-midmid;
            }

        }
        if(M<=cou){
            l=mid;
        }
        else{
            r=mid;
        }
    }
    //cout<<mid<<endl;

    long long int ans=0;
    long long int rui[100003];
    rui[0]=A[0];
    for(int i=1;i<N;i++)rui[i]=rui[i-1]+A[i];

    long long int cou=0;
    for(int j=0;j<N;j++){
        int ll=0,rr=N,midmid;
        for(int k=0;k<20;k++){
            midmid=(ll+rr)/2;
            if(mid<=A[j]+A[midmid])rr=midmid;
            else ll=midmid;
        }
        if(midmid==N-1&&A[j]+A[midmid]<mid){}
        else if(midmid==N-1){
            cou++;
            ans+=A[j]+A[midmid];
        }
        else{
            if(A[j]+A[midmid]<mid)midmid++;
            cou+=N-midmid;
            if(midmid!=0){
                ans+=A[j]*(N-midmid)+(rui[N-1]-rui[midmid-1]);
            }
            else {
                ans+=A[j]*(N-midmid)+rui[N-1];
            }
        }

        //printf("[%lld][%lld][%lld]\n",cou,ans,midmid);


    }

    if(M<=cou){
        ans-=mid*(cou-M);
    }

/*
    for(int i=0;i<N;i++){
        printf("[%lld]",A[i]);
    }
    puts("");
*/
    cout<<ans<<endl;



    return 0;
}


Measured memory_bytes: 1792
#!/usr/bin/env ruby

def mergesort lst
  _mergesort_ lst.dup
end

def _mergesort_ lst
  return lst if (len = lst.size) <= 1
  lst2 = lst.pop(len >> 1)

  _merge_(_mergesort_(lst), _mergesort_(lst2))
end

def _merge_ lst1, lst2
  len1, len2 = lst1.size, lst2.size
  result = Array.new(len1 + len2)
  a, b = lst1[0], lst2[0]
  i, j, k = 0, 0, 0
  loop do
    @cnt += 1
    if a <= b
      result[i] = a
      i += 1
      j += 1
      break unless j < len1
      a = lst1[j]
    else
      result[i] = b
      i += 1
      k += 1
      break unless k < len2
      b = lst2[k]
    end
  end
  while j < len1
    result[i] = lst1[j]
    i += 1
    j += 1
    @cnt += 1
  end
  while k < len2
    result[i] = lst2[k]
    i += 1
    k += 1
    @cnt += 1
  end
  result
end

gets
a = gets.split.map(&:to_i)

@cnt = 0
puts mergesort(a).join(' ')
puts @cnt

Measured memory_bytes: 74016
P = 998244353
N = int(input())
A = [int(a) for a in input().split()]
V = 1000001
X = [0] * V
for a in A: X[a] += 1
W = [1] + [pow(i, P-2, P) for i in range(1, V)]
for k in range(1, V):
    for i in range(k*2, V, k):
        W[i] = (W[i] - W[k]) % P

ans = 0
for k in range(1, V):
    s1 = s2 = 0
    for i in range(k, V, k):
        s1 += i * X[i]
        s2 += i * i * X[i]
    ans = (ans + (s1*s1-s2) * W[k]) % P

print(ans * 499122177 % P)

Measured memory_bytes: 118136
#include<stdio.h>
int main(){
	int a,b,c;

	scanf("%d %d %d",&a,&b,&c);

	if (a > c && c > b){
		printf("Yes");
	}else if (b > c && c > a){
		printf("Yes");
	}else {
		printf("No");
	}

	return 0;
}

Measured memory_bytes: 128
void main(){
	int n = _scan();
	if(n>81){
		writeln("No");
		return;
	}
	foreach(i; 1..81+1){
		if(i<=9 && n/i<=9 && n%i==0){
			writeln("Yes");
			return;
		}
	}
	writeln("No");
}

import std.stdio, std.conv, std.algorithm, std.numeric, std.string, std.math;

// 1要素のみの入力
T _scan(T= int)(){
	return to!(T)( readln().chomp() );
}

// 1行に同一型の複数入力
T[] _scanln(T = int)(){
	T[] ln;
	foreach(string elm; readln().chomp().split()){
		ln ~= elm.to!T();
	}
	return ln;
}


Measured memory_bytes: 2656
import Control.Monad
import Data.List
import qualified Data.Set as S

main=do
    [a,b,c]<-sort.map read.words<$>getLine::IO[Int]
    print $ sol 0 S.empty (a,b,c)

sol::Int->S.Set (Int,Int,Int)->(Int,Int,Int)->Int
sol n s abc@(a,b,c)
    | any odd [a,b,c] = n
    | S.member abc s = -1
    | otherwise = sol (n+1) (S.insert abc s) (fn abc)

fn::(Int,Int,Int)->(Int,Int,Int)
fn (a,b,c) = (u,v,w)
    where
        a2 = a `div` 2
        b2 = b `div` 2
        c2 = c `div` 2
        a' = b2+c2
        b' = a2+c2
        c' = a2+b2
        (u:v:w:_) = sort [a',b',c']

Measured memory_bytes: 508
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce


sys.setrecursionlimit(2147483647)
INF = 10 ** 13
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().rstrip().split()
def S(): return sys.stdin.readline().rstrip()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 998244353


x = I()
if x >= 30:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 76748
n = gets.to_i
s = gets.chomp

ar = ['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z''A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z''A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z''A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z''A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z''A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z''A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z''A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z''A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z''A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z''A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z']

ans = ""

t = s.length

t.times do |i|
	j = ar.index(s[i]).to_i
	a = ar[j+n].to_s
	ans = ans + a
end

puts ans

Measured memory_bytes: 20860
import java.util.Scanner;
 
class Main{
  public static void main(String[] args){
    Scanner s = new Scanner(System.in);
    int n = s.nextInt();
    int sum = 0;
    int max = -1;
    for(int i = 0; i < n; i++){
      int input = s.nextInt();
      sum = sum + input;
      if(input > max){
        max = input;
      }
    }
    if(sum - max > max){
      System.out.println("Yes");
    }else{
      System.out.println("No");
    }
  }
}

Measured memory_bytes: 23120
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author cherrypi59
 */

#pragma GCC optimize ("O2")
#pragma GCC optimize ("tree-vectorize")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define FFOR(i, a, b) FOR(i, a, b+1)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) FOR(i, 1, n+1)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define LEN(x) (int)(x).size()
#define DUMP(x) cerr<<__LINE__<<' '<<#x<<"="<<(x)<<endl;
#define popcnt(x) __builtin_popcount(x)
#define popcntll(x) __builtin_popcountll(x)
#define pb push_back
#define eb emplace_back
#define mp make_pair

using namespace std;
using lint = long long;
using pii =  pair<int, int>;
using pll =  pair<lint, lint>;
template <typename T> using vc = vector<T>;
template <typename T> using vvc = vector<vector<T>>;
template <typename T> inline bool chmax(T &a, T b){if(a<b){a = b; return true;} return false;}
template <typename T> inline bool chmin(T &a, T b){if(a>b){a = b; return true;} return false;}

constexpr lint ten(int n) {return n==0 ? 1 : ten(n-1)*10;}
constexpr double EPS = 1e-12;

class FEncloseAll {
public:
    void solve(std::istream& in, std::ostream& out){
        ios_base::sync_with_stdio(false);
        in.tie(nullptr), out.tie(nullptr);
        int N;
        in>>N;
        vc<complex<double>> P(N);
        for(auto& p : P){
            int re, im;
            in>>re>>im;
            p.real(re);
            p.imag(im);
        }
        auto check = [&](double r){
            vc<complex<double>> ips;
            REP(i, N) FOR(j, i+1, N){
                if(abs(P[i]-P[j])>2*r) return false;
                double alpha = arg(P[j]-P[i]);
                double beta = acos(abs(P[j]-P[i])/(2*r));
                ips.pb(P[i]+polar(r, alpha+beta));
                ips.pb(P[i]+polar(r, alpha-beta));
            }
            for(auto& ip : ips){
                bool ok = true;
                for(auto& p : P){
                    double d = abs(ip-p);
                    if(d>r and abs(r-d)>EPS) ok = false;
                }
                if(ok) return true;
            }
            return false;
        };
        double left = 0, right = 1000;
        REP(_, 100){
            double mid = (left+right) / 2;
            if(check(mid)) right = mid;
            else left = mid;
        }
        out<<fixed<<setprecision(12)<<right<<'\n';
    }
};


int main() {
	FEncloseAll solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 4572
#include<iostream>
#include<vector>
#include<cmath>
#include<algorithm>

using namespace std;

using P = pair<double, double>;

const double EPS = 0.0000000001;
const double INF = 1000000000000;


double a[100];
double b[100];
int n;

P cross(double a1, double b1, double a2, double b2) {
    if (abs(a1 - a2) < EPS) return make_pair(-1000, -1000);
    if (a1 == INF) return cross(a2, b2, a1, b1);
    if (a2 == INF) return make_pair(b2, a1 * b2 + b1);
    double x = (b1 - b2) / (a2 - a1);
    return make_pair(x, a1 * x + b1);
};


int main() {
    //P p = cross(INF, 2, INF, 4);
    //cout << p.first << ", " << p.second << endl;

    while(1) {
        cin >> n;
        if (n == 0) break;
        for (int i = 0; i < n; ++i) {
            int x1, y1, x2, y2;
            cin >> x1 >> y1 >> x2 >> y2;
            if (x1 == x2) {
                a[i] = INF;
                b[i] = x1;
            } else {
                a[i] = ((double) y1 - y2) / (x1 - x2);
                b[i] = (y1 - a[i] * x1);
            }
            //cout << a[i] << ", " << b[i] << endl;
        }

        vector<P> points;
        int ans = 1;
        for (int i = 0; i < n; ++i) {
            points.clear();
            for (int j = 0; j < i; ++j) {
                //cout << "detect " <<  i  << ", " << j << endl;
                P p = cross(a[i], b[i], a[j], b[j]);
                // cout << "cross at " << p.first << ", " << p.second << endl;
                double x = p.first;
                double y = p.second;
                if (x <= EPS - 100 || x >= 100 - EPS || y <= EPS - 100 || y >= 100 - EPS) continue;
                points.push_back(p);
            }

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


            // for (P p : points) {
            //     cout << p.first << ", " << p.second << endl;
            // }
            int count = 0;
            if (!points.empty()) {
                P last = points[0];
                count++;

                for (int i = 1; i < (int)points.size(); ++i) {
                    double dx = last.first - points[i].first;
                    double dy = last.second - points[i].second;

                    if (dx * dx + dy * dy >= EPS * EPS) {
                        count++;
                    }
                    last = points[i];
                }
            }
            ans += (count + 1);
        }

        cout << ans << endl;
    }
}



Measured memory_bytes: 3104
n, k = list(map(int,input().split()))
a = list(map(int,input().split()))
 
position = 1
exp1 = [0] * n
exp1[0] = 1
exp = [1]
count = 0
 
if n >= k:
  for i in range(k):
    position = a[position - 1]
  print(position)
else:
  for i in range(k):
    position = a[position - 1]
    count += 1
    if exp1[position - 1] == 0:
      exp.append(position)
      exp1[position - 1] += 1
    else:
      break
  init = exp.index(position)
  res = (k - init) % (count - init)
  print(exp[init + res])

Measured memory_bytes: 32244
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include <math.h>
#include <stdbool.h>

int ASC( void *a,  void *b) {
	return strcmp(*(const char **)a, *(const char **)b);//降順
}
int GCD(int a, int b) {	//最大公約数
	if (b == 0) return a;
	else return GCD(b, a % b);
}
int min(int a, int b ) {
	if (a < b) {
		return a;
	}
	else
		return b;
}
int max(int a, int b) {
	if (a < b)
		return b;
	else
		return a;
}
long long a[1000000];
int main(void)
{
	for (int i = 0; i < 1000000; i++) {
		a[i] = 0;
	}
	long long k, count = 0, mod, ans = 0;
	scanf("%lld",&k);
	mod = 7;
	while (1) {
		if (ans == 0) {
			mod %= k;
			a[mod] = 1;
		}
		else {
			mod = 7 + mod * 10;
			mod %= k;
			a[mod]++;
			if (a[mod] == 2) {
				printf("-1");
				return 0;
			}
		}
		ans++;
		if (mod == 0)
			break;
	}
	printf("%lld",ans);
	return 0;
}


Measured memory_bytes: 9540
using System;
using System.Collections.Generic;
using System.Linq;

public class AtCoderB
{
    static void Main()
    {
        long n;
        long a;
        long b;
        {
            var line = Console.ReadLine();
            var words = line.Split(' ');
            n = long.Parse(words[0]);
            a = long.Parse(words[1]);
            b = long.Parse(words[2]);
        }

        long answer = 0;
        answer += (n / (a + b)) * a;
        answer += Math.Min((n % (a + b)), a);

        Console.WriteLine(answer);
    }
}

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

public class Main {
  private static void execute(ContestReader reader, PrintWriter out) {
    char x = reader.next().toCharArray()[0];
    char y = reader.next().toCharArray()[0];
    if (x < y) {
      out.println("<");
    } else if (x > y) {
      out.println(">");
    } else {
      out.println("=");
    }
  }
  
  public static void main(String[] args) {
    ContestReader reader = new ContestReader(System.in);
    PrintWriter out = new PrintWriter(System.out);
    execute(reader, out);
    out.flush();
  }
}

class ContestReader {
  private BufferedReader reader;
  private StringTokenizer tokenizer;
  
  ContestReader(InputStream in) {
    reader = new BufferedReader(new InputStreamReader(in));
  }
  
  public String next() {
    while (tokenizer == null || !tokenizer.hasMoreTokens()) {
      try {
        tokenizer = new java.util.StringTokenizer(reader.readLine());
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
    return tokenizer.nextToken();
  }
  
  public int nextInt() {
    return Integer.parseInt(next());
  }
  
  public long nextLong() {
    return Long.parseLong(next());
  }
  
  public double nextDouble() {
    return Double.parseDouble(next());
  }
  
  public String[] nextArray(int n) {
    String[] array = new String[n];
    for (int i = 0; i < n; i++) {
      array[i] = next();
    }
    return array;
  }
  
  public int[] nextIntArray(int n) {
    int[] array = new int[n];
    for (int i = 0; i < n; i++) {
      array[i] = nextInt();
    }
    return array;
  }
  
  public long[] nextLongArray(int n) {
    long[] array = new long[n];
    for (int i = 0; i < n; i++) {
      array[i] = nextLong();
    }
    return array;
  }
  
  public double[] nextDoubleArray(int n) {
    double[] array = new double[n];
    for (int i = 0; i < n; i++) {
      array[i] = nextDouble();
    }
    return array;
  }
  
  public int[][] nextIntMatrix(int n, int m) {
    int[][] matrix = new int[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        matrix[i][j] = nextInt();
      }
    }
    return matrix;
  }
  
  public long[][] nextLongMatrix(int n, int m) {
    long[][] matrix = new long[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        matrix[i][j] = nextLong();
      }
    }
    return matrix;
  }
  
  public double[][] nextDoubleMatrix(int n, int m) {
    double[][] matrix = new double[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        matrix[i][j] = nextDouble();
      }
    }
    return matrix;
  }
}


Measured memory_bytes: 21204
a, v = gets.split.map &:to_i
b, w = gets.split.map &:to_i
t = gets.to_i

able = true
if a < b
  able = a + v * t >= b + w * t
elsif a > b
  able = a - v * t <= b - w * t
else
  able = true
end

if able
  puts "YES"
else
  puts "NO"
end


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

#define rep(i, n) for(int (i)=0; (i)<(n); (i)++)
#define FILL0(x) memset(x,0,sizeof(x))

using namespace std;

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

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; }
 
const ll MOD = ll(1e9)+7;
const int MAX = 670000;
ll fac[MAX], finv[MAX], inv[MAX];

void comInit()
{
    fac[0]=fac[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;

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

ll com(int n, int r)
{
    if(n<r)
        return 0;
    if(n<0 || r<0)
        return 0;
    
    return fac[n]*(finv[r]*finv[n-r]%MOD)%MOD;
}


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

 
    comInit();

    int X, Y;
    cin >> X >> Y;

    ll up, right;
    up=right=0;
    while(X>0&&Y>0)
    {
        if(X>Y)
        {
            X-=2;
            Y-=1;
            right++;
        }
        else
        {
            X-=1;
            Y-=2;
            up++;
        }
    }

    if(X!=0||Y!=0)
    {
        cout << 0 << endl;
        return 0;
    }

    cout << com(up+right, up)%MOD << endl;




 

 

    return 0;
}
 

//cout << setprecision(13);
//next_permutation();
//__gcd();
//reverse();
//set ,tuple ,pair;
//bitset
//vector.find



Measured memory_bytes: 16000
s = input()
odd = ['R', 'U', 'D']
even = ['L', 'U', 'D']

for i in range(len(s)):
    if i % 2 == 0:
        if s[i] in odd:
            continue
        else:
            print('No')
            exit()
    else:
        if s[i] in even:
            continue
        else:
            print('No')
            exit()
print('Yes')


Measured memory_bytes: 38256
import java.util.*;

public class Main{
	private static final Scanner scan = new Scanner(System.in);

	public static void main(String[] args){
		List<Integer> list = new ArrayList<Integer>();
		while(scan.hasNext()){
			int cnt = 0;
			int n = scan.nextInt();
			for(int i = 0; i <= 9; i++){
				for(int j = 0; j <= 9; j++){
					for(int k = 0; k <= 9; k++){
						for(int l = 0; l <= 9; l++){
							if(i + j + k + l == n){
								cnt++;
							}
						}
					}
				}
			}
			list.add(cnt);
		}
		for(int n : list){
			System.out.printf("%d\n", n);
		}
	}
}

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

int main() {
  int N;
  cin >> N;
  vector<vector<int>> graph(N);
  vector<pair<int, int>> vp;
  for (int i = 1; i < N; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    graph.at(a).push_back(b);
    graph.at(b).push_back(a);
    vp.emplace_back(a, b);
  }

  // 各エッジの色
  map<pair<int, int>, int> edges_color;
  // 親を持つ場合、親に割り当てられた色
  vector<int> assigned_color(N, 0);

  vector<int> seen(N, 0);
  queue<int> que;

  seen.at(0) = 1;
  que.push(0);
  while (!que.empty()) {
    int v = que.front();
    que.pop();
    int cur = 1;
    for (auto u : graph.at(v)) {
      // 探索済みの頂点はスルー
      if (seen.at(u)) continue;
      // 親となる頂点に割り当てられた色は使用しない
      if (cur == assigned_color.at(v)) cur++;
      // 割り当てる色で無向グラフの辺の色を更新
      assigned_color.at(u) = cur;
      edges_color[make_pair(u, v)] = cur;
      edges_color[make_pair(v, u)] = cur;
      cur++;
      seen.at(u) = 1;
      que.push(u);
    }
  }

  int K = 0;
  for (int i = 0; i < N; i++) K = max(K, (int)graph.at(i).size());
  cout << K << endl;
  for (auto p : vp) cout << edges_color[p] << endl;
  return 0;
}


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

const int MOD = 1000000007;

int main()
{
  long long int H;
  cin >> H;
  long long int cnt = 0;
  while (H > 0)
  {
    H /= 2;
    cnt++;
  }
  long long ans = (long long)pow(2, cnt) - 1;
  cout << ans << endl;
}


Measured memory_bytes: 384
#include<iostream>
#include<vector>
#include<algorithm>
#define ep emplace
#define eb emplace_back
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define semicolon ;
#define ryan bear
using namespace std;
typedef long long ll;
typedef pair<int,int>pi;
typedef pair<ll,ll>pl;
const int inf=1e9+7;
const ll INF=1e18;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    ll n,a,b;
    cin>>n>>a>>b;
    if(a>b)
        swap(a,b);
    if(b-a&1)
        cout<<min(a+(b-a-1)/2,n-b+1+(n-(a+n-b+1))/2)<<endl;
    else
        cout<<(b-a)/2<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define fi first
#define se second
typedef pair<ll,ll> P;
using VP = vector<P>; using VVP = vector<VP>;
using VI = vector<ll>; using VVI = vector<VI>; using VVVI = vector<VVI>;
#define INF 1ll<<59

ll Mod;

ll modinv(ll a) {
    ll m=Mod;
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}



int main(){
   ll i,j;
   ll p;
   cin>>p;
   Mod=p;
   ll pow[3030];
   pow[1]=1;
   for(i=2;i<3030;i++){
      pow[i]=(pow[i-1]*i)%p;
   }

   ll c[p];
   ll a[p];
   for(i=0;i<p;i++) cin>>a[i];

   c[0]=a[0];
   for(i=1;i<p;i++){
      ll x=a[i];
      for(j=0;j<i;j++){
         x=(x+p-c[j])%p;
         x*=modinv(i-j);
         x%=p;
      }
      c[i]=x;
   }

   ll b[p];
   for(i=0;i<p;i++) b[i]=0;

   vector<ll> v(p,0);
   v[0]=1;
   b[0]=c[0];

   for(i=1;i<p;i++){
      vector<ll> v2(p,0);
      for(j=0;j<p;j++){
         v2[(j+1)%p]+=v[j];
         v2[(j+1)%p]%=p;
         v2[j]+=(p+1-i)*v[j];
         v2[j]%=p;
      }
      for(j=0;j<p;j++) v[j]=v2[j];

      for(j=0;j<p;j++){
         b[j]+=c[i]*v[j];
         b[j]%=p;
      }

   }
   for(i=0;i<p;i++){
      if(i==0) cout<<b[0];
      else cout<<" "<<b[i];
   }

   cout<<endl;
   
   return 0;
}


Measured memory_bytes: 512
import sys
def input(): return sys.stdin.readline().strip()
k,s=map(int,input().split())
c=0
for x in range(k+1):
    if x + 2 * k < s:
        continue
    for y in range(k+1):
        if x + y > s:
            continue
        if x + y + k < s:
            continue
        c += 1
print(c)

Measured memory_bytes: 2940
<?php

$input = explode(' ', trim(fgets(STDIN)));
$n = (int)$input[0];
$m = (int)$input[1];
$infinit = 10001;

$shortest = [];
for ($i=1; $i <= $n; $i++) { 
	for ($j=1; $j <= $n; $j++) { 
		if ($i === $j) {
			$shortest[$i][$j] = 0;
		}else{
			$shortest[$i][$j] = $infinit;
		}
	}
}
$path = [];
for ($i=0; $i < $m; $i++) { 
	$input = explode(' ', trim(fgets(STDIN)));
	$fr = (int)$input[0];
	$to = (int)$input[1];
	$dist = (int)$input[2];
	$path[] = [$fr, $to, $dist];
	$shortest[$fr][$to] = $dist;
	$shortest[$to][$fr] = $dist;
}


for ($a=1; $a <= $n; $a++) { 
	for ($b=1; $b <= $n; $b++) { 
		for ($c=1; $c <= $n; $c++) { 
			$shortest[$b][$c] = min($shortest[$b][$c], $shortest[$a][$b]+$shortest[$a][$c]);
		}
	}
}

$count = 0;
foreach ($path as $v) {
	if ($shortest[$v[0]][$v[1]] < $v[2]) {
		++$count;
	}
}
echo $count;

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

string join(const vector<string>& v, char c) {
	string s;
  for (auto p = begin(v); p != end(v); ++p) {
    s += *p;
    if (p != v.end() - 1) s += c;
  }
	return s;
}

int main() {
  for (int M, T, P, R; cin >> M >> T >> P >> R, M;) {
    vector<vector<int>> cnt(T, vector<int>(P, 0));
    vector<TR> sc(T);
    REP(i, T) sc[i] = TR(0, 0, -i);
    REP(i, R) {
      int m, t, p, j;
      cin >> m >> t >> p >> j, t--, p--;
      if (j) {
        cnt[t][p]++;
        continue;
      }
      int ps, ms, tmp;
      tie(ps, ms, tmp) = sc[t];
      sc[t] = TR(ps - 1, ms + m + 20 * cnt[t][p], -t);
    }
    sort(begin(sc), end(sc));
    vector<vector<string>> ans_vv;
    int ps, ms, t;
    tie(ps, ms, t) = sc[0];
    ans_vv.push_back({to_string(-t + 1)});
    REP(i, T - 1) {
      int pc, mc, tc;
      tie(pc, mc, tc) = sc[i];
      int pn, mn, tn;
      tie(pn, mn, tn) = sc[i + 1];
      if (pc == pn && mc == mn) {
        ans_vv.back().push_back(to_string(-tn + 1));
      } else {
        ans_vv.push_back({to_string(-tn + 1)});
      }
    }
    vector<string> ans_v(ans_vv.size());
    REP(i, ans_vv.size()) ans_v[i] = join(ans_vv[i], '=');
    string ans = join(ans_v, ',');
    cout << ans << endl;
  }
}



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

#define rep(i,n) for(long long int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(long long int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(long long int i=(a);i>(b);i--)
#define all(v) (v).begin(), (v).end()
#define pb(q) push_back(q)
#define P pair<int,int>
#define Abs(a,b) max(a,b)-min(a,b)
#define YES(condition) if(condition){cout << "YES" << endl;}else{cout << "NO" << endl;}
#define Yes(condition) if(condition){cout << "Yes" << endl;}else{cout << "No" << endl;}
#define Cout(x) cout<<(x)<<endl

typedef long long ll;

using namespace std;

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

//while(x!=0){
            //sum+=x%10;
           // x/=10;
        //}
        //各桁の和

//pair<int,int> p[100000];
//P r[100000];
//cin >> tmp;
//p[i]=make_pair(tmp,i);
//cout << p[i].second+1 << endl;//ペアの右側つまりiを出力

//s.find(w[i])==string::npos
//findの使い方

//for(int i=0;i<n;i++){
   // b[i]=x%2;
    //x/=2;
  //}二進数

long long int n=1,cnt=0,ans=0,a[1000000],b,c,cmp,data,m,h=0,x,y,xcmp=0,ycmp=0,sum=0;

string s,w;

vector<int> z;

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

       cin >> n;
      rep(i,n){
          cin >> a[i];
          if(a[i]%4==0){
              cnt++;
          }
          else if(a[i]%2==0){
              h++;
          }
      }
      h/=2;
      n/=2;
      Yes(n<=h+cnt);
      
return 0;
}


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

#ifdef BTK
#define DEBUG if(1)
#else
#define DEBUG if(0)
#define CIN_ONLY if(1)
struct cww{cww(){
    CIN_ONLY{
        ios::sync_with_stdio(false);cin.tie(0);
    }
}}star;
#endif

#define FOR(i,bg,ed) for(int i=(bg);i<(ed);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
#define pb push_back
#define REC(ret, ...) std::function<ret (__VA_ARGS__)>
template <typename T>inline bool chmin(T &l,T r){bool a=l>r;if(a)l=r;return a;}
template <typename T>inline bool chmax(T &l,T r){bool a=l<r;if(a)l=r;return a;}
template <typename T>istream& operator>>(istream &is,vector<T> &v){for(auto &it:v)is>>it;return is;}

constexpr char ln = '\n';
constexpr int mod = 1e9+7;
const string ok = "Yes";
const string ng = "No";


int main(){
    LL N,M;
    cin>>N>>M;
    cout<<((1800*M+100*N)<<M)<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
    #include <string>
    #include <algorithm>
    #include <cassert>
    #include <set>
    #include <vector>
    #include <cmath>
    #include <bitset>
    #include <functional>
    #include <limits>
    #include <map>
    using namespace std;

    typedef long long ll;
    #define rep1(i, n) for(ll i = 1; i <=(ll)(n); i++)
    #define rep0(i, n) for(ll i = 0; i <=(ll)(n); i++)

    ll pow(ll a, ll n) { //compute a^n with o(logn)
        ll res = 1;
        while (n > 0) {
            if (n & 1) res = res * a;
            a = a * a;
            n >>= 1;
        }
        return res;
    }

    ll pow(ll a, ll n, ll mod) { //compute a^n (mod mod) with o(logn)
        ll res = 1;
        while (n > 0) {
            if (n & 1) res = res * a % mod;
            a = a * a % mod;
            n >>= 1;
        }
        return res;
    }

    int main(){
        ll a;
        cin >> a;
        cout << a + a*a + a*a*a<<endl;
        return 0;
    }

Measured memory_bytes: 3160