akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

#define IOS             ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define read            freopen("in.txt","r",stdin)
#define write           freopen("out.txt","w",stdout)
#define loop(i,a,b)     for (ll i = a; i <= b; i++)
#define rloop(i,a,b)    for (ll i = a; i >= b; i--)
#define ms(a,x)         memset(a,x,sizeof a)
#define ll              long long int
#define ff              first
#define ss              second
#define all(a)          a.begin(),a.end()
#define rall(a)         a.rbegin(),a.rend()
#define pb              push_back
#define nl              cout<<"\n"
#define gcd(a,b)        __gcd((a),(b))
#define lcm(a,b)        ((a)*(b))/(gcd(a,b))
#define sq(a)           (a)*(a)
#define sz(a)           a.size()
#define mod             1000000007
#define PI              2*acos(0.0)

int main()
{
    IOS
    int T=1;
    //cin>>T;
    while(T--)
    {
        double d,t,s;
        cin>>d>>t>>s;
        if(d/s>t) cout<<"No";
        else cout<<"Yes";


    }
    return 0;
}


Measured memory_bytes: 3736
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main () {
	int count5 = 0;
	int count7 = 0;
	for (int i = 0; i < 3; i++){
		int num;
		cin >> num;
		if (num == 5) count5++;
		else if (num == 7) count7++;
	}
	if(count5 == 2 && count7 == 1) cout <<"YES" << endl;
	else cout << "NO" << endl;

	return 0;
}

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

using namespace std;

int main(void){
    int n;
    cin >> n;
    
    int t[n],x[n],y[n];
    t[0] = x[0] = y[0] = 0;
    for(int i=1;i<n+1;i++) cin >> t[i] >> x[i] >> y[i];
    
    bool can = true;
    
    for(int i=0;i<n;i++){
        int dt = t[i+1] -t[i];
        int dist = abs(x[i+1] - x[i]) + abs(y[i+1] - y[i]);
        if(dt < dist || dt%2 != dist%2) can = false;
    }
    
    if(can) cout << "Yes" << endl;
    else cout << "No" << endl;
}


Measured memory_bytes: 1408
#include<set>
#include<map>
#include<stack>
#include<cmath>
#include<ctime>
#include<queue>
#include<cstdio>
#include<vector>
#include<climits>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
#define LL long long
int read(){
    int f=1,x=0;char c=getchar();
    while(c<'0'||'9'<c){if(c=='-')f=-1;c=getchar();}
    while('0'<=c&&c<='9') x=(x<<3)+(x<<1)+c-'0',c=getchar();
	x*=f;
    return x;
}
#define MAXN 100000
#define INF 0x3f3f3f3f
#define Mod int(1e9+7)
LL cnt[30];
char S[MAXN+5];
int main(){
	LL ans=0;
	int n=read(),k=0;
	scanf("%s",S+1);
	for(int i=1;i<=n;i++){
		LL tmp=1;
		for(int j=0;j<26;j++)
			if(S[i]-'a'!=j)
				tmp=tmp*(cnt[j]+1)%Mod;
		ans=(ans+tmp)%Mod;
		if(!cnt[S[i]-'a'])
			k++;
		cnt[S[i]-'a']++;
	}
	printf("%lld\n",ans);
    return 0;
}

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

using namespace std;
using ll=long long ;

struct Sieve {
    int sz;
    vector<bool> is;
    vector<int> prime;
    Sieve(int n = 45000):sz(n) {
        prime.reserve(n/6);
        is.assign(n+1, true);
        is[0] = is[1] = false;
        for (int p = 2; (int64_t)p*p <= n; p++) {
            if (is[p]) {
                for (int i = p*p; i <= n; i += p) {
                    is[i] = false;
                }
            }
        }
        for (int i = 2; i <= n; i++) {
            if (is[i])
                prime.emplace_back(i);
        }
    }
    // prime divisors
    vector<int> p_divs(int x) {
        assert(x > 0 && (int64_t)sz*sz >= x);
        vector<int> res;
        for (const int& p: prime) {
            if ((int64_t)p*p > x) break;
            if (x % p == 0) {
                while (x % p == 0) {
                    x /= p;
                }
                res.emplace_back(p);
            }
        }
        if (x != 1)
            res.emplace_back(x);
        return res;
    }
    // euler phi, [1..=x] coprime to x
    ll phi(ll x) {
        assert(x > 0);
        if (x == 1) return 1;
        int res = x;
        for (auto& p: p_divs(x)) {
            (res/=p)*=(p-1);
        }
        return res;
    }

} s(1e6);

template <typename T>
T mpow(T x, int64_t e, ll mod) {
    T res = 1;
    for (; e; e >>= 1) {
        if (e & 1) res *= x, res %= mod;
        x *= x, x %= mod;
    }
    return res;
}

ll a;
ll calc(ll m) {
    if (m == 1) return 1;
    ll p = s.phi(m);
    ll l = m*p/__gcd(p,m);
    ll y = calc(p);
    return l + mpow<__int128>(a, y, l);
}

void solve() {
    ll m;
    cin >> a >> m;
    ll y = calc(m);
    assert(mpow<__int128>(a,y,m) == y%m);
    cout << y << "\n";
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t; cin >> t;
    while(t--)solve();
    cout << endl;
}


Measured memory_bytes: 640
import heapq

n=int(input())
pts=[list(map(int,input().split())) for _ in range(n)]

x=sorted([(i,pts[i][0]) for i in range(n)],key=lambda x:x[1])
y=sorted([(i,pts[i][1]) for i in range(n)],key=lambda x:x[1])

invx=[0]*n
invy=[0]*n

for i in range(n):
    invx[x[i][0]]=i
    invy[y[i][0]]=i

q=[(0,0)]

visit=[0]*n
ans=0

while q:
    cnt,i=heapq.heappop(q)

    if visit[i]==1:
        continue

    visit[i]=1
    ans+=cnt

    xi=invx[i]
    yi=invy[i]

    for delta in [-1,1]:
        nx=xi+delta
        ny=yi+delta
        if 0<=nx<n and visit[x[nx][0]]==0:
            heapq.heappush(q,(abs(x[nx][1]-x[xi][1]),x[nx][0]))
        if 0<=ny<n and visit[y[ny][0]]==0:
            heapq.heappush(q,(abs(y[ny][1]-y[yi][1]),y[ny][0]))

print(ans)

Measured memory_bytes: 120256
#include<cmath>
#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
using namespace std;

const int inf = 0x3f3f3f3f;
typedef long long ll;
const double pi=4*atan(1.0);
int sum[200005];
int main()
{
    int n;
    cin>>n;
    for(int i=0; i<n-1; i++)
    {
        int a;
        scanf("%d",&a);
        sum[a]++;
    }
    for(int i=1; i<=n; i++)
        printf("%d\n",sum[i]);
    return 0;
}

Measured memory_bytes: 4036
#include <iostream>
using namespace std;
int main(){
    int x,i,a,b,m,n,k;
    string s;
    cin >> s;
    k=s.length();
    a=k;
    b=0;
    x=0;
    for(i=0;i<k;i++){
        if(s[i]=='A'&&i<a)
            a=i;
        if(s[i]=='Z'&&i>b)
            b=i;
    }
    x=b-a+1;
    cout << x << endl;
    return 0;
}

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

int main(){
  string s;
  cin >> s;
  int ans = 0;
  for(int i = 0; i < 3; i++){
    if(s.at(i) == '1'){
      ans++;
    }
  }
  cout << ans << endl;
}
    


Measured memory_bytes: 3600
#include<iostream>
using namespace std;
int main(){
  bool h=false;
  int n,ans=0,a[200];
  cin>>n;
  for(int i=0;i<n;i++)cin>>a[i];
  while(1){
    for(int i=0;i<n;i++){
      if(a[i]%2==0)a[i]/=2;
      else {h=true;break;}
    }
    if(h)break;
    ans++;
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#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;
}
int n,m,k,a[1000002],ans;
char s[1000002];
signed main(){
	scanf("%s",s+1);
	n=strlen(s+1);
	if(s[n]=='s')s[++n]='e',s[++n]='s';
	else s[++n]='s';
	printf("%s",s+1);
}

Measured memory_bytes: 3828
// 基本テンプレート

#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
using namespace std;

#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define int long long int

template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}

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

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
constexpr ll INF = 1001001001001001LL;
constexpr ll MOD = 1000000007LL;

signed main() {
    int I, O, T, J, L, S, Z;
    cin >> I >> O >> T >> J >> L >> S >> Z;
    int ans = 0;

    // use
    if(I && J && L) {
        int ni = I-1, nj = J-1, nl = L-1;
        int temp = 0;
        temp += ni / 2;
        temp += nj / 2;
        temp += nl / 2;
        chmax(ans, temp * 2 + 3);
    }

    // do not use
    int temp = 0;
    temp += I / 2;
    temp += L / 2;
    temp += J / 2;
    chmax(ans, temp * 2);

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

Measured memory_bytes: 256
#include <iostream>
#include <climits>
#include <set>
#include <string>
#include <algorithm>
#include <vector>
#define MAX 1000000007


using namespace std;
#define ll long long
#define dbg if(0)
#define ISRANGE(val,lo,hi) ((lo<=val)&&(val<hi))



int main(){
    ll ans,n,a,b;
    cin>>n>>a>>b;
    if(abs(a-b)%2==0){//卓差が偶数なら
        ans=abs(a-b)/2+abs(a-b)%2;//間の数だけ埋めれば良い
    }else{//そうでないときは近い方の端に向かって互いが勝敗を重ねる
        ans=min(min((a-1),(b-1)),min(n-a,n-b))+abs(a-b)/2+abs(a-b)%2;
    }

    cout <<ans<<endl;

    return 0;

}

Measured memory_bytes: 256
from math import floor
alphabets = ["_","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"]
n=int(input())
res = ""
i=10
while i>-1:
    divres = floor(n/(26**i))
    res += alphabets[divres]
    n-= divres * (26 ** i)
    i-=1
while res[0]=="_":
    res = res[1:]
#print(res)

i=len(res)-1
while i>-1:
    if res[i] == "_":
        j=0
        while res[i-j] == "_":
            j+=1
        if i == 0:
            res = res[1:]
        else:
            res = res[:i-j] + alphabets[alphabets.index(res[i-j])-1] + "y"*(j-1) + "z" + res[i+1:]
    i-=1
print(res)

Measured memory_bytes: 9172
#![allow(unused_imports, non_snake_case, dead_code)]
use proconio::{
    input, fastout,
    marker::{Chars, Bytes, Usize1}
};

const MODULO: u64 = 1_000_000_007;

struct Combination {
    MOD: u64,
    size: usize,
    fact: Vec<u64>,
    inv_fact: Vec<u64>,
}
impl Combination {
    fn new(size: usize, MOD: u64) -> Self {
        let mut fact = vec![1; size + 1];
        let mut inv_fact = vec![1; size + 1];
        for i in 1..size + 1 {
            fact[i] = fact[i - 1] * i as u64 % MOD;
        }
        inv_fact[size] = Self::modpow(fact[size], MOD - 2, MOD);
        for i in (1..size + 1).rev() {
            inv_fact[i - 1] = inv_fact[i] * i as u64 % MOD;
        }
        Combination {
            MOD,
            size,
            fact,
            inv_fact,
        }
    }
    fn modpow(mut x: u64, mut y: u64, m: u64) -> u64 {
        let mut res: u64 = 1;
        while y > 0 {
            if y & 1 > 0 {
                res = res * x % m;
            }
            x = x * x % m;
            y >>= 1;
        }
        res
    }
    fn modinv(x: u64, m: u64) -> u64 {
        Self::modpow(x, m - 2, m)
    }
    fn nPr(&self, n: usize, r: usize) -> u64 {
        if n < r {
            return 0;
        };
        self.fact[n] * self.inv_fact[n - r] % self.MOD
    }
    fn nCr(&self, n: usize, r: usize) -> u64 {
        if n < r {
            return 0;
        };
        self.fact[n] * self.inv_fact[r] % self.MOD * self.inv_fact[n - r] % self.MOD
    }
}

#[fastout]
fn main() {
    input!{
        N: usize
    }
    let ncr = Combination::new(N * 2, MODULO);
    let mut ans = 0;
    for i in 1..N/3+1 {
        ans = (ans + ncr.nCr(N-i*3+i-1, i-1)) % MODULO;
    }
    println!("{}", ans);

}


Measured memory_bytes: 2240
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

int main()
{
    int n, t, a[100010];

    cin >> n >> t;

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

    sort(a, a+t);

    cout << max(a[t-1]-1-(n-a[t-1]),0) << endl;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {

  public static void main (String[] args) {

    Scanner sc = new Scanner(System.in);

    int H = sc.nextInt();
    int W = sc.nextInt();
    String[][] s = new String[H][W];
    
    for (int i = 0; i < H; i++) {
      String s_ = sc.next();
      s[i] = s_.split("");
    }

    sc.close(); 

    int[] p = {-1,1};

    for (int i = 0; i < H; i++) {
      for (int j = 0; j < W; j++) {

        if (s[i][j].equals("#")) {

          String result = "No";

          for (int k = 0; k < 2; k++){
            if (0 <= j + p[k] && j + p[k] < W) {
              if (s[i][j+p[k]].equals("#")) {
                result = "Yes";
              }
            }
            if (0 <= i + p[k] && i + p[k] < H) {
              if (s[i+p[k]][j].equals("#")) {
                result = "Yes";
              }
            }
          }

          if (result == "No") {
            System.out.println("No");
            return;
          } 

        }

      }
    }

    System.out.println("Yes");
  
  }

}

Measured memory_bytes: 22736
#include<stdio.h>
int main(){
    int n,k,i,j,tmp,ans=0;
    int p[100000];
    
    scanf("%d %d",&n,&k);
    for(i = 0; i < n; i++) scanf("%d",&p[i]);
    
    for(i = 0; i < n-1; i++){
        for(j = i+1; j < n; j++){
            if(p[i] > p[j]){
                tmp = p[i];
                p[i] = p[j];
                p[j] = tmp;
            }
        }
    }
    for(i = 0; i < k; i++) ans += p[i];
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 1748
(defun solve (N M Q)
  (loop with arr = (make-array N :initial-element 1)  
        with lst = (loop repeat Q 
                         collect (list (1- (read)) (1- (read)) (read) (read)))
        
        maximize (loop for x in lst 
                       sum (destructuring-bind (a b c d) x
                             (if (= c (- (aref arr b) (aref arr a))) d 0)))
        
        while (loop for i from (1- N) downto 0 
                    if (/= #1=(aref arr i) M)
                    return (prog1 t
                             (incf #1#)
                             (loop for j from (1+ i) to (1- N) do
                                   (setf (aref arr j) #1#))))))

(princ (solve (read) (read) (read)))

Measured memory_bytes: 24476
s = input()
if s == 'SAT':
    print(1)
if s == 'FRI':
    print(2)
if s == 'THU':
    print(3)
if s == 'WED':
    print(4)
if s == 'TUE':
    print(5)
if s == 'MON':
    print(6)
if s == 'SUN':
    print(7)


Measured memory_bytes: 8928
# -*- coding: utf-8 -*-

import sys

def small_inc(x, y, cells):
    cells[x][y] += 1
    if y > 0:
        cells[x][y-1] += 1
    if x > 0:
        cells[x-1][y] += 1
    if x < MAPSIZE-1:
        cells[x+1][y] += 1
    if y < MAPSIZE-1:
        cells[x][y+1] += 1

def medium_inc(x, y, cells):
    if y > 0:
        cells[x][y-1] += 1
        if x > 0:
            cells[x-1][y-1] += 1
        if x < MAPSIZE-1:
            cells[x+1][y-1] += 1
    cells[x][y] += 1
    if x > 0:
        cells[x-1][y] += 1
    if x < MAPSIZE-1:
        cells[x+1][y] += 1
    if y < MAPSIZE-1:
        cells[x][y+1] += 1
        if x > 0:
            cells[x-1][y+1] += 1
        if x < MAPSIZE-1:
            cells[x+1][y+1] += 1

def large_inc(x, y, cells):
    if y > 1:
        cells[x][y-2] += 1
    if y > 0:
        cells[x][y-1] += 1
        if x > 0:
            cells[x-1][y-1] += 1
        if x < MAPSIZE-1:
            cells[x+1][y-1] += 1
    cells[x][y] += 1
    if x > 1:
        cells[x-2][y] += 1
    if x > 0:
        cells[x-1][y] += 1
    if x < MAPSIZE-1:
        cells[x+1][y] += 1
    if x < MAPSIZE-2:
        cells[x+2][y] += 1
    if y < MAPSIZE-1:
        cells[x][y+1] += 1
        if x > 0:
            cells[x-1][y+1] += 1
        if x < MAPSIZE-1:
            cells[x+1][y+1] += 1
    if y < MAPSIZE-2:
        cells[x][y+2] += 1

SMALL = 1
MEDIUM = 2
LARGE = 3
MAPSIZE = 10

cells = [[0 for i in range(MAPSIZE)] for j in range(MAPSIZE)]
for line in sys.stdin:
    x , y, size = map(int, line.split(','))
    if size == SMALL:
        small_inc(x, y, cells)
    elif size == MEDIUM:
        medium_inc(x, y, cells)
    elif size == LARGE:
        large_inc(x, y, cells)
count = max_d = 0
for i in range(MAPSIZE):
    for j in range(MAPSIZE):
        if cells[i][j] == 0:
            count += 1
        else:
            max_d = max(max_d, cells[i][j])
print count
print max_d

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

int main()
{
	int i,count=0;
	string ss;


	while(1)
	{
		cin >> ss;

		if(ss=="0") break;
	

		for(i=0;i<(int)ss.size();i++)
		{
			count = count + (int)ss[i]-48;
		}

		cout << count << endl ;
		count = 0;

	}




	return 0;
}

Measured memory_bytes: 1188
#include <bits/stdc++.h>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <iostream>
#include <numeric>
#define rep(i,n) for (int i = 0;i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define chmax(x,y) x = max(x,y)
int INF = 1e9;


int main(){
	int a,b,c;cin >> a >> b >> c;
	int m = max(max(a,b),c);
	if(a+b+c ==2*m) cout << "Yes" << endl;
	else cout << "No" << endl;
} 


Measured memory_bytes: 3588
#include <bits/stdc++.h>
#define inf 1000000007
#define mod 1000000007
//#pragma GCC optimize(2)
//#define int long long
using namespace std;
template <typename T> void read(T &x){
	x=0;char ch=getchar();int fh=1;
	while (ch<'0'||ch>'9'){if (ch=='-')fh=-1;ch=getchar();}
	while (ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();
	x*=fh;
}
template <typename T> void write(T x) {
	if (x<0) x=-x,putchar('-');
	if (x>9) write(x/10);
	putchar(x%10+'0');
}
template <typename T> void writeln(T x) {
	write(x);
	puts("");
}
int k;
signed main()
{
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin>>k;
	int sum=0;
	for(int a=1;a<=k;a++)
		for(int b=1;b<=k;b++)
			for(int c=1;c<=k;c++)
				sum+=__gcd(__gcd(a,b),c);
	cout<<sum<<endl;
	return 0;
}


Measured memory_bytes: 3652
import java.util.*;

public class Main{
    void solve(){
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int k = scan.nextInt();
        int[] h = new int[n];
        for(int i = 0; i < n; i++) h[i] = scan.nextInt();
        int[] dp = new int[n];
        dp[1] = Math.abs(h[1] - h[0]);
        for(int i = 2; i < n; i++){
            int min = Integer.MAX_VALUE;
            for(int j = i - 1; j >= Math.max(0, i - k); j--){
                min = Math.min(min, Math.abs(h[i] - h[j]) + dp[j]);
            }
            dp[i] = min;
        }
        System.out.println(dp[n - 1]);
    }
    
    public static void main(String[] args){
        new Main().solve();
    }
}


Measured memory_bytes: 59912
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees#, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7
#from decimal import *

N = sorted(LIST())
print("YES" if N == [1, 4, 7, 9] else "NO")

Measured memory_bytes: 5148
#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <algorithm>

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

using namespace std;
typedef long long int ll;
typedef pair<int,int> pii;

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 (a>b) { a=b; return 1; } return 0; }

template<class A, size_t N, class T> void Fill(A (&a)[N], const T &v){ fill( (T*)a, (T*)(a+N), v ); }

const int INF = 0x3fffffff;


int main(){
	int H, W;
	char A[10][10];

	cin >> H >> W;
	rep(i,H) rep(j,W) cin >> A[i][j];
	
	int dp[10][10]={};
	dp[0][0] = 1;
	rep(i,H) rep(j,W) if( A[i][j] == '#' ){
		dp[i+1][j] += dp[i][j];
		dp[i][j+1] += dp[i][j];
	}
	bool ans = true;
	rep(i,H) rep(j,W) if( A[i][j] == '#' ){
		if( dp[i][j] != 1 ) ans = false;
	}

	rep(i,10) rep(j,10) dp[i][j] = 0;
	dp[H][W] = 1;
	rrep(i,H) rrep(j,W) if( A[i][j] == '#' ){
		dp[i+1][j] += dp[i+1][j+1];
		dp[i][j+1] += dp[i+1][j+1];
	}
	rep(i,H) rep(j,W) if( A[i][j] == '#' ){
		if( dp[i+1][j+1] != 1 ) ans = false;
	}

	cout << (ans?"Possible":"Impossible") << endl;

	return 0;
}


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

bool compare(const int &x, const int &y)
{
	return x > y;
}

int main()
{
	int count[200010] = { 0 };
	
	int n, k;
	std::cin >> n >> k;
	
	for (int i = 0; i < n; ++i)
	{
		int x;
		std::cin >> x;
		
		++count[x];
	}
	
	std::sort(count, count + 200005, compare);
	int sum = 0;
	
	for (int i = 0; i < n; ++i)
	{
		if (i == k)
		{
			std::cout << n - sum;
			return 0;
		}
		else
			sum += count[i];
	}
	
	std::cout << 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define MOD 1000000007
#define INF 1145141919
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(int (i)=(n-1);(i)>=0;(i)--)
#define Flag(x) (1<<(x))
#define Flagcount(x) __builtin_popcount(bit)

using namespace std;

int main(void){
  string S;
  cin >> S;
  int A=S[0]-'0',B=S[1]-'0',C=S[2]-'0',D=S[3]-'0',ans;
  rep(i,Flag(3)){
    ans=A;
    if(i&Flag(0)) ans+=B;
    else ans-=B;
    if(i&Flag(1)) ans+=C;
    else ans-=C;
    if(i&Flag(2)) ans+=D;
    else ans-=D;
    if(ans==7){
      cout << A;
      if(i&Flag(0)) cout << "+";
      else cout << "-";
      cout << B;
      if(i&Flag(1)) cout << "+";
      else cout << "-";
      cout << C;
      if(i&Flag(2)) cout << "+";
      else cout << "-";
      cout << D << "=7" << endl;
      break;
    }
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define fi first
#define se second
#define mp make_pair
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,K,Q,A,B,L,R;
string S,T;
const ll MOD = (1e+9) + 7;
const ll INF = 1LL << 60;
typedef pair<ll,ll> P;

typedef vector<P> vp;
typedef vector<vp> matP;

int main(){
    cin>>N>>K;
    cout<<(N%K != 0)<<endl;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

int main(void){
	ll n,a,b,ans;
	cin >> n >> a >> b;
	if(b){
		ans = (n/(a+b))*a+min(n%(a+b),a);
	}else{
		ans = n;
	}
	cout << ans << endl;
	return 0;
}


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

using namespace std;
using ll = long long;

int main() {
  ll N, M;
  cin >> N >> M;
  vector<pair<ll, ll>> AB(N);
  for (int i = 0; i < N; ++i) {
    ll a, b;
    cin >> a >> b;
    AB[i] = make_pair(a, b);
  }
  sort(AB.begin(), AB.end(), [](auto l, auto r){return l.first < r.first;});
  ll s = 0;
  ll i = 0;
  ll ret = 0;
  while(s < M){
    if(s+AB[i].second < M){
      ret += AB[i].first*AB[i].second;
      s+=AB[i].second;
    }else{
      ret += AB[i].first*(M-s);
      s+=M-s;
    }
    ++i;
  }
  cout << ret << endl;
}


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

#define ll long long
#define endl '\n'
#define REP(i, a, n) for(int i=a; i<n; ++i)
#define pb push_back
#define sz(x) (int)((x).size())
#define all(x) (x).begin(), (x).end()

typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

const double PI = 3.141592653589793238460;
const ll mod = 1e9 + 7;

void FAST(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
}

int main(){
  FAST();

  int n, i;
  cin >> n;
  vi W(n);
  REP(i, 0, n)  cin >> W[i];

  vi prefix(n, 0);
  REP(i, 0, n)
    prefix[i] = (i == 0) ? (W[i]) : (prefix[i - 1] + W[i]);

  int ans = INT_MAX;
  REP(i, 0, n){
    int difference = abs((prefix[n - 1] - prefix[i]) - prefix[i]);
    ans = min(ans, difference);
  }

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


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>
#include<iomanip>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

typedef long long ll;
//typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;
typedef vector<vector<int>> mat;
//typedef unsigned int uint;

template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

int dp[3010][3010];
string s, t;

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

	cin >> s >> t;

	rep(i, 0, SZ(s))rep(j, 0, SZ(t))
	{
		if (s[i] == t[j])
		{
			dp[i + 1][j + 1] = dp[i][j] + 1;
		}
		else
		{
			dp[i + 1][j + 1] = max(dp[i][j + 1], dp[i + 1][j]);
		}
	}

	string ans;

	int i = SZ(s), j = SZ(t);

	while (i > 0 && j > 0)
	{
		if (s[i - 1] == t[j - 1])
		{
			ans.push_back(s[i - 1]);
			i--;
			j--;
		}
		else
		{
			if (dp[i - 1][j] > dp[i][j - 1])
			{
				i--;
			}
			else
			{
				j--;
			}
		}
	}

	reverse(all(ans));

	cout << ans << endl;

	return 0;
}

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

const int MAXN = 1e5+5;
const ll p = 1e9+7;

int n, k, a[MAXN], d[MAXN], tot;
vector<int> c[MAXN];

int dfs(int u) {
	int m = 0;
	for (int i : c[u]) {
		m = max(m, dfs(i));
	}
	if (m >= k-1) {
		if (a[u] != 0)
		    tot++;
		m = -1;
	}
	return m+1;
}

void comp(int x) {
	if (x == 0 || d[x] != 0)
		return;
	comp(a[x]);
	d[x] = d[a[x]]+1;
}

int main() {
	cin >> n >> k;
	for (int i = 0; i < n; ++i) {
		cin >> a[i]; a[i]--;
		if (i != 0)
			c[a[i]].push_back(i);
	}
	for (int i = 0; i < n; ++i)
		comp(i);
	d[0] = d[a[0]]+1;
	bool y = true;
	if (d[0] != 1)
		y = 0;
	for (int i = 0; i < n; ++i)
		if (d[i] > k)
			y = 0;
	if (y) {
		cout << "0\n"; return 0;
	}

	tot += (d[0] != 1);
	a[0] = 0;
	dfs(0);
	cout << tot << endl;
}

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

namespace Algorithm
{
    class Program
    {
        static void Main(string[] args)
        {
            var l = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int N = l[0], M = l[1];
            var p = Console.ReadLine().Split().Select(int.Parse).ToArray();
            var uf = new UnionFind(N + 1);

            for (var i = 0; i < M; i++)
            {
                var tmp = Console.ReadLine().Split().Select(int.Parse).ToArray();
                uf.Merge(tmp[0], tmp[1]);
            }

            var count = p.Select((z, i) => uf.IsSame(z, i + 1)).Count(z => z);
            Console.WriteLine(count);
        }
    }

    class UnionFind
    {
        List<int> par;

        public UnionFind(int n)
        {
            par = Enumerable.Repeat(-1, n).ToList();
        }

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

        public bool IsSame(int x, int y)
        {
            return Root(x) == Root(y);
        }

        public bool Merge(int x, int y)
        {
            x = Root(x);
            y = Root(y);

            if (x == y) return false;
            if (par[x] > par[y]) Swap(ref x, ref y);

            par[x] += par[y];
            par[y] = x;

            return true;
        }

        public int Size(int x)
        {
            return -par[Root(x)];
        }

        public void Swap(ref int a, ref int b)
        {
            var tmp = a;
            a = b;
            b = tmp;
        }
    }
}


Measured memory_bytes: 24412
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline


class SegmentTree():
    '''
    非再帰
    segment tree
    '''

    def __init__(self, _n, func, init=float('inf')):
        '''
        _n->配列の長さ
        func:func(a,b)->val,　func=minだとRMQになる
        木の高さhとすると,
        n:h-1までのノード数。h段目のノードにアクセスするために使う。
        data:ノード。
        parent:k->child k*2+1とk*2+2
        '''
        self.n = 2**(_n-1).bit_length()
        self.inf = init
        self.data = [init]*(2*self.n)
        self.func = func

    def set(self, k, v):
        '''
        あたいの初期化
        '''
        self.data[k+self.n-1] = v

    def build(self):
        '''
        setの後に一斉更新
        '''
        for k in reversed(range(self.n-1)):
            self.data[k] = self.func(self.data[k*2+1], self.data[k*2+2])

    def update(self, k, a):
        '''
        list[k]=aに更新する。
        更新ぶんをrootまで更新
        '''
        k += self.n-1
        self.data[k] = a

        while k > 0:
            k = (k-1)//2
            self.data[k] = self.func(self.data[k*2+1], self.data[k*2+2])

    def query(self, l, r):
        '''
        [l,r)のfuncを求める
        '''
        L = l+self.n
        R = r+self.n
        ret = self.inf
        while L < R:
            if R & 1:
                R -= 1
                ret = self.func(ret, self.data[R-1])
            if L & 1:
                ret = self.func(ret, self.data[L-1])
                L += 1
            L >>= 1
            R >>= 1
        return ret


N = int(input())
A = [int(input()) for _ in range(N)]

Seg = SegmentTree(N, max, init=0)
for i, a in enumerate(A):
    Seg.set(i, a)

Seg.build()

for i in range(N):
    print(max(Seg.query(0, i), Seg.query(i+1, N)))


Measured memory_bytes: 76624
import sys
import math
from copy import deepcopy
from collections import deque
sys.setrecursionlimit(20000000)


def main():
    N = int(input())
    nums = list(map(int, input().split()))

    ans = [0] * N

    # First mountain
    s = 0
    for i in range(len(nums)):
        if i % 2:
            s += nums[i]
        else:
            s -= nums[i]

    ans[0] = abs(s)

    for i in range(1, len(nums)):
        ans[i] = int((nums[i-1] - (ans[i-1] / 2)) * 2)

    print(*ans, sep=' ')


if __name__ == '__main__':
    main()



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

int main()
{
    int n;
    cin >> n;
    rep(i, 3) {
        if (n % 10 == 7) {
            cout << "Yes" << endl;
            return 0;
        }
        n /= 10;
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3576
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i <= (n); i++)
#define zep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define printa(x,m,n) for(ll i = (m); i <= n; i++){cout << (x[i]) << " ";} cout<<endl;

int main(){
	cin.tie(0); ios::sync_with_stdio(false);
	
	ll n, m;
	cin >> n >> m;
	string ans(n, 'x');
	
	ll s[m], c[m];
	zep(i, 0, m){
		cin >> s[i] >> c[i];
		s[i]--;
		if(n != 1 && s[i] == 0 && c[i] == 0){
			ans = "-1";
			break;
		}
		if(ans[s[i]] == 'x'){
			ans[s[i]] = '0'+c[i];
		}
		else{
			if(ans[s[i]] != '0'+c[i]){
				ans = "-1";
				break;
			}
		}
	}
	if(ans != "-1"){
		zep(i, 0, n){
			if(ans[i] == 'x'){
				ans[i] = (i == 0 && n != 1)? '1' : '0';
			}
		}
	}
	print(ans)
	return 0;
}

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

//highlight color RGB = [70,70,70]
#define asll unsigned long long
#define ll long long
#define ld long double
#define imt ll
#define pii pair<ll,ll>
#define st first
#define nd second
#define kj <<" "<<
#define kjb <<" ";
#define dg <<","<<
#define ml <<endl;
#define co cout<<
#define ter cout<<endl;
#define sibi cout<<"TES"<<endl;
#define tes(x) cout<<"TES "<<x<<endl;
#define psbk(x) push_back(x);
#define For(x,a,b) for(ll x=(a);x<(b);x++)
#define FOR(x,n) for(ll x=0;x<(n);x++)
#define kera(x,m) for( ll i = 0;i < m ; i++ ){ cout<<"x["<< i <<"] =" kj x[i] ml}
#define kpr(x) cout<<"("<<x.st dg x.nd <<")" ml
#define kkor(p) cout<<"("<<p.x dg p.y <<")" ml
#define m_p make_pair
asll M=1e9+7;
ll n;
//ll p,q,r;
ll x[200005],y[200005];
ll p[200005],m[200005];

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);cout.tie(0);
	srand(time(0));
	cin>>n;
	FOR(i,n){
		cin>>x[i]>>y[i];
		p[i]=x[i]+y[i];
		m[i]=y[i]-x[i];
	}
	ll ap=0,ip=1e9+5,am=0,im=1e9+5;
	FOR(i,n){
		if(ap<p[i]){
			ap=p[i];
		}
		if(ip>p[i]){
			ip=p[i];
		}
		if(am<m[i]){
			am=m[i];
		}
		if(im>m[i]){
			im=m[i];
		}
	}
	cout<<max(ap-ip,am-im)<<endl;
}


Measured memory_bytes: 9912
from itertools import permutations

n = int(input())
p = [int(x) for x in input().split()]
q = [int(x) for x in input().split()]
perms = list(permutations(range(1, n + 1)))
for i, perm in enumerate(perms):
    if all(x == y for x, y in zip(p, perm)):
        a = i
    if all(x == y for x, y in zip(q, perm)):
        b = i


print(abs(a - b))

Measured memory_bytes: 8052
//小数点以下　cout << fixed << setprecision(10) << num << endl;
//桁数はlog10(mid)でやれ　log(mid)/log(10)はWA
//long*long<0で判定するな
//開区間と閉区間
//アルファベットが何番目かは x=s[i]-'a'
//bfsはmain()内で　rep(i,h)rep(j,w)rep(i,4)でバグ
//切り上げ：(a+(b-1))/b
//32bit以上は 1ull<<j
// map 初期値0 for(auto itr=mp.begin();itr!=mp.end();++itr) itr->fi itr->se で全探索
// for(auto u:mp) u.fi u.se も可能
//n個のgcd,lcmは一つずつみて更新していく
//大きな数を扱うときは素因数分解した形で持っておく
// (l/a[i]) = l*powmod(a[i],MOD-2)%MOD;
//auto itr=lower_bound(ALL(a),key) a[itr-a.begin()]
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <tuple>
#include <cmath>
#include <iomanip>
#include <map>
#include <stdio.h>
#include <cstring> //memset(dp,0,sizeof(dp))
#include <functional> //operator[]
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
#define ALL(a) (a).begin(),(a).end()
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;

signed main(){
    int n,q; cin >> n >> q;
    vector<pair<int,pair<int,int>>> v;
    rep(i,n){
        int s,t,x; cin >> s >> t >> x;
        v.pb({s-x,{-1,x}});
        v.pb({t-x,{0,x}});
    }
    rep(i,q){
        int d; cin >> d;
        v.pb({d,{1,i}});
    }
    sort(ALL(v));
    vector<int> ans(q);
    multiset<int> st;
    for(auto p:v){
        int y=p.se.fi;
        int z=p.se.se;
        if(y==-1) st.insert(z);
        else if(y==0) st.erase(st.lower_bound(z));
        else{
            if(st.empty()) ans[z]=-1;
            else ans[z]=*(st.begin());
        }
    }
    rep(i,q) cout << ans[i] << endl;
}


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

int main()
{
    string s;
    cin >> s;
    bool f = 0, lc = 1;
    int c = 0;
    if (s[0] == 'A')
        f = 1;
    for (int i = 1; i < (int)s.size(); i++)
    {
        if (s[i] == 'C' && i >= 2 && i != (int)s.size() - 1)
            c++;
        else if (s[i] < 'a')
            lc = 0;
    }
    if ((f && lc) && (c == 1))
        cout << "AC" << endl;
    else
        cout << "WA" << endl;
}

Measured memory_bytes: 256
let () = Scanf.scanf "%d" @@ fun n ->
  Printf.printf "%d\n" @@
    List.length @@
      List.filter (fun x ->
        ( = ) 8 @@
          List.length @@
            List.filter (fun i -> x mod i = 0) @@
              Array.to_list @@
                Array.init x (( + ) 1)) @@
        List.filter (fun x -> x mod 2 = 1) @@
          Array.to_list @@
            Array.init n (( + ) 1)


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

void solve(std::vector<long long> x)
{

    for (ll i = 0; i < 5; i++)
    {
        if (x[i] == 0)
            cout << i + 1 << endl;
    }
}

signed main()
{
    std::vector<long long> x(5);
    for (int i = 0; i < 5; i++)
    {
        scanf("%lld", &x[i]);
    }
    solve(std::move(x));
    return 0;
}


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

int main()
{
    int x,n,i,j,ara[111],ctn,d;
    cin>>n>>x;
    for(i=1; i<=n; i++)
        cin>>ara[i];
    ctn=1;
    d=0;
    for (i=2; i<=n+1; i++)
    {
        j=d+ara[i-1];
        d=j;
        ctn++;
        if (d>=x)
        {
            if(d>x)
                ctn--;
            break;
        }
    }
    cout<<ctn<<endl;

    return 0;
}


Measured memory_bytes: 256
import sys
import copy
import math
import bisect
import pprint
import bisect
from functools import reduce
from copy import deepcopy
from collections import deque
from decimal import *

import numpy as np

import math

if __name__ == '__main__':
    a = [str(i) for i in input().split()]
    b = int(a[0])
    c = Decimal(a[1]) * Decimal(100)
    d = Decimal(a[0]) * Decimal(c) / Decimal(100)
    e = int(d)
    print(e)


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

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl





using ll = long long;

const ll mod = 1e9+7;
const int maxn = 1e6 + 5;





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

    int n, k;
    cin>>n>>k;
    vector<int> a(n);
    for (int i=0; i<n; i++) {
	cin>>a[i];
    }


    for (int i=k; i<n; i++) {
	if (a[i]>a[i-k]) {
	    cout<<"Yes\n";
	} else {
	    cout<<"No\n";
	}
    }
    
    
    return 0;
}


Measured memory_bytes: 3968
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repr(i,n) for(int i = (int)(n); i >= 0; i--)
#define all(v) v.begin(),v.end()
typedef long long ll;

ll moddividing(ll x,ll y){
    vector<ll> vec(30);
    rep(i,30){
        vec[i] = y;
        y = y * y % 1000000007;
    }
    ll c = x;
    c = c * vec[0] % 1000000007;
    c = c * vec[2] % 1000000007;
    c = c * vec[9] % 1000000007;
    c = c * vec[11] % 1000000007;
    c = c * vec[14] % 1000000007;
    c = c * vec[15] % 1000000007;
    c = c * vec[17] % 1000000007;
    c = c * vec[19] % 1000000007;
    c = c * vec[20] % 1000000007;
    c = c * vec[23] % 1000000007;
    c = c * vec[24] % 1000000007;
    c = c * vec[25] % 1000000007;
    c = c * vec[27] % 1000000007;
    c = c * vec[28] % 1000000007;
    c = c * vec[29] % 1000000007;
    return c;
}

int main(){
    vector<ll> factorial(100005);
    factorial[0] = 1;
    rep(i,100004){
        factorial[i + 1] = (factorial[i] * (i + 1)) % 1000000007;
    }
    ll n;
    cin >> n;
    vector<ll> a(n + 1);
    rep(i,n + 1){
        cin >> a[i];
    }
    vector<ll> cnt(n + 1, 0);
    rep(i,n + 1){
        cnt[a[i]]++;
    }
    ll doublecount = 0;
    rep(i,n + 1){
        if (cnt[i] == 2){
            doublecount = i;
        }
    }
    ll left = -1;
    ll right = -1;
    rep(i,n + 1){
        if (a[i] == doublecount && left == -1){
            left = i;
        }
        else if (a[i] == doublecount){
            right = i;
        }
    }
    ll x = n - 1;
    ll r = n - (right - left);
    vector<ll> ans(n + 2, 0);
    ans[1] = n;
    ans[2] = (1 + x * 2 - r + x * (x - 1) / 2) % 1000000007;
    for (ll i = 3; i < n + 2; i++){
        if (x - i >= 0) ans[i] = (ans[i] + moddividing(factorial[x], (factorial[x - i] * factorial[i]) % 1000000007)) % 1000000007;
        ans[i] = (ans[i] + moddividing(factorial[x], (factorial[x - i + 2] * factorial[i - 2]) % 1000000007)) % 1000000007;
        if (i - 1 <= r){
            ans[i] = (ans[i] + (moddividing(factorial[x], (factorial[x - i + 1] * factorial[i - 1]) % 1000000007) * 2) % 1000000007) % 1000000007;
            ans[i] = (ans[i] + 1000000007 - moddividing(factorial[r], (factorial[r - i + 1] * factorial[i - 1]) % 1000000007)) % 1000000007;
        }
        else{
            if (x - i + 1 >= 0) ans[i] = (ans[i] + (moddividing(factorial[x], (factorial[x - i + 1] * factorial[i - 1]) % 1000000007) * 2) % 1000000007) % 1000000007;
        }
    }
    rep(i,n + 1){
        cout << ans[i + 1] << endl;
    }
}

Measured memory_bytes: 6272
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int num = scanner.nextInt();
        int odd = scanner.nextInt();
        long mod = 1_000_000_007;
        long[][][] dp = new long[num + 1][num + 1][odd + 1];
        dp[0][0][0] = 1;
        for (int i = 1; i <= num; i++)
            for (int j = 0; j <= i; j++)
                for (int k = 2 * j; k <= odd; k++) {
                    if (j > 0) {
                        dp[i][j][k] = dp[i - 1][j - 1][k - 2 * j];
                    }
                    dp[i][j][k] += (2 * j + 1) * dp[i - 1][j][k - 2 * j];
                    if (j < num) {
                        dp[i][j][k] += (j + 1) * (j + 1) * dp[i - 1][j + 1][k - 2 * j];
                    }
                    dp[i][j][k] %= mod;
                }
        System.out.println(dp[num][0][odd]);
    }
}

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

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

    long long n, m;
    cin >> n >> m;
    vector<long long> A(n);
    for(int i = 0; i < n; i++){
        cin >> A[i];
    }

    map<long long, long long> mp;
    mp[0] = 1;
    long long tmp = 0;
    for(int i = 0; i < n; i++){
        tmp += A[i];
        mp[tmp % m]++;
    }

    long long ans = 0;
    for(auto x: mp){
        ans += x.second * (x.second - 1) / 2;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 4992
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
using namespace std;
typedef long long int ll;

vector<int> g[200200];
int color[200200];
int ans[200200];
int cnt=0;

void dfs(int s){
	if(color[s]==0)cnt++;
	for(int t:g[s]){
		if(color[t]!=-1)continue;
		color[t]=color[s]^1;
		dfs(t);
	}
}

int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	int n; cin >> n;
	for(int i=1;i<n;i++){
		int x,y; cin >> x >> y;
		x--; y--;
		g[x].push_back(y);
		g[y].push_back(x);
	}
	for(int i=0;i<n;i++){
		color[i]=-1;
	}
	color[0]=0;
	dfs(0);
	if(cnt<=n/3){
		for(int i=0,j=1;i<n;i++){
			if(color[i]==0){
				ans[i]=3*j;
				j++;
			}
		}
	}
	else if((n-cnt)<=n/3){
		for(int i=0,j=1;i<n;i++){
			if(color[i]==1){
				ans[i]=3*j;
				j++;
			}
		}
	}
	else{
		for(int i=0,j=1,k=1;i<n;i++){
			if(color[i]==0&&3*j-2<=n){
				ans[i]=3*j-2;
				j++;
			}
			if(color[i]==1&&3*k-1<=n){
				ans[i]=3*k-1;
				k++;
			}
		}
	}
	set<int> st;
	for(int i=1;i<=n;i++){
		st.insert(i);
	}
	for(int i=0;i<n;i++){
		if(ans[i]){
			st.erase(ans[i]);
		}
	}
	for(int i=0;i<n;i++){
		if(ans[i]==0){
			ans[i]=*st.begin();
			st.erase(st.begin());
		}
	}
	for(int i=0;i<n;i++){
		printf("%d\n",ans[i]);
	}
}


Measured memory_bytes: 23920
n,m = map(int,input().split())
ans=[]
if m%2==1:
  for i in range(m//2):
    print(i+1,m-i)
  for i in range(m//2+1):
    print(m+1+i,2*m+1-i)
else:
  for i in range(m//2):
    print(i+1,m-i+1)
  for i in range(m//2):
    print(m+2+i,2*m+1-i)

Measured memory_bytes: 9144
n=int(input())
a=list(map(int,input().split()))
ans = 'APPROVED'
for i in a:
	if i %2 ==0:
		if i % 3 == 0:
			continue
		elif i % 5 == 0:
			continue
		else:
			ans = 'DENIED'
			break
print(ans)

Measured memory_bytes: 3060
from fractions import gcd
from sys import stdin
N = int(stdin.readline().rstrip())
A = [int(_) for _ in stdin.readline().rstrip().split()]
L=[0]
R=[0]
MAX=0
for i in range(N-1):
    L.append(gcd(L[i],A[i]))
    R.append(gcd(R[i],A[-1-i]))
for i in range(N):
    MAX=max(MAX,gcd(L[i],R[-1-i]))
print(MAX)

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

#include <iostream>
#include <string>
using namespace std;

int main(int argc, char* argv[]){
        char buf[128]={0};
        int flag=0;
        std::string str1;
        std::getline(cin, str1);
        strcpy(buf, str1.c_str());

        if(buf[2]==buf[3] && buf[4]==buf[5]){
                flag = 1;
        }

        if(flag){ printf("Yes\n");}
        else{ printf("No\n");}

        return 0;
}

Measured memory_bytes: 256
program test
implicit none
integer::k,l,m,i,s
integer::ans=1000000
integer,allocatable::a(:),b(:),c(:),x(:),y(:)
read(5,*),k,l,m
allocate(a(k))
allocate(b(l))
allocate(c(m))
allocate(x(m))
allocate(y(m))
 
	read(5,*)(a(i),i=1,k)
	read(5,*)(b(i),i=1,l)
 	read(5,*)(x(i),y(i),c(i),i=1,m)
    
do i=1,m 
    s=a(x(i))+b(y(i))-c(i)
    ans=min(s,ans)
end do 
 
ans=min(minval(a)+minval(b),ans)
print*,ans
end program test

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

int main(){
    int a[5], ans=0;
    for(int i = 0; i < 5; i++)
    {
        cin >> a[i];
        ans+=(a[i]+9)/10*10;
    }
    int tmp=ans;
    for(int i = 0; i < 5; i++)
    {
        if(a[i]%10!=0){
            int m=a[i]%10;
            m += tmp-10;

            ans = min(ans, m);
        }
    }
    
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
struct point{int x;int y;};
int i,j,k,count1=0,count2=0;

int main(){
    string s;
    cin>>s;
    int ans=0;
    ans+=stoi(s.substr(0,1))-1;
    for(i=1;i<s.length();i++){
        if(s[i]=='9')count1++;
    }
    if(count1==s.length()-1)ans++;
    ans+=s.length()*9-9;
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
using namespace std;
int main(){
	double nx=0,ny=0,x,y,ro=90;
	while(true){
		cin>>x;cin.ignore();cin>>y;	
		if(x==0&&y==0)break;
		ny+=x*sin(ro/180*M_PI);
		nx+=x*cos(ro/180*M_PI);
		ro-=y;
		//if(ro<0)ro=360-abs(ro);
		//cout<<nx<<" "<<ny<<endl;
	}
	cout<<(int)nx<<endl<<(int)ny<<endl;
	return 0;
}

Measured memory_bytes: 1224