akhauriyash/Code-Regression huggingface dataset:
// AtCoder.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//

// AtCoder.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//


#define _USE_MATH_DEFINES
#include<math.h>

//#include<cmath>

#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
#include<assert.h>
#include<bitset>
#include<stack>
#include<memory>



//#include "Ants.h"
using namespace std;
typedef long long ll;
#define rad_to_deg(rad) (((rad)/2/M_PI)*360)
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define rep(i,n) for(int i=0;i<n;i++)
#define show(s) cout<<s<<endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define LINF (1000000000000000000ll)
//typedef pair < int, int> P;
ll gcd(ll a, ll b) {//最大公約数を求める///最大公倍数a*b/gcd(a,b)
	if (b == 0) return a;
	return gcd(b, a % b);
}
ll lcd(ll a, ll b) {//最小公倍数を求める　b=0のときaを返す
	if (b == 0) return a;
	return (a / gcd(a, b)) * b;
}
vector<int> divnum(ll num) {
	int dig;
	vector<int>p;
	while (num) {
		dig = num % 10;
		p.push_back(dig);
		num /= 10;
	}
	return p;
}
int digiter(ll num) {
	int dig;
	vector<int>p;
	while (num) {
		dig = num % 10;
		p.push_back(dig);
		num /= 10;
	}
	return p.size();
}
vector<int> convert(string s) {
	vector<int> d;
	ll n = s.size();
	rep(i, n) {
		d.push_back(s[i] - '0');
	}
	return d;
}

int X, Y, A, B, C;

int main()
{
	cin >> X >> Y >> A >> B >> C;
	vector<int>p(A), q(B), r(C);
	rep(i, A) cin >> p[i];
	rep(i, B)cin >> q[i];
	rep(i, C)cin >> r[i];
	sort(p.rbegin(), p.rend()); sort(q.rbegin(), q.rend()); //sort(r, r + C);
	rep(i, X) r.push_back(p[i]);
	rep(i, Y)r.push_back(q[i]);
	sort(r.rbegin(), r.rend());
	ll ans = 0;
	rep(i, X + Y) {
		ans += r[i];
	}
	cout << ans << endl;
	

	
}


Measured memory_bytes: 2552
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  ll n, m, d;
  cin >> n >> m >> d;
  cout << 1.0 * (m - 1) * (d ? (n - d) * 2 : n) / (n * n) << endl;

  return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cstdio>

using namespace std;

#define LEN 100005

typedef struct Poj{
    char name[100];
    int time;
}poj;

poj Q[LEN];
int head, tail, n;

void enqueue(poj x){
    Q[tail] = x;
    tail = (tail+1) % LEN;
}

poj dequeue(){
    poj tmp = Q[head];
    head = (head+1) % LEN;
    return tmp;
}

int main(){
    int elapse = 0, q = 0;
    poj cur;
    scanf("%d %d",&n,&q);

    for(int i = 0; i < n; i++){
        scanf("%s",Q[i].name);
        scanf("%d",&Q[i].time);
    }
    head = 0;
    tail = n;

    while(head != tail){
        cur = dequeue();
        elapse += min(q,cur.time);
        cur.time -= min(q,cur.time);
        if(cur.time > 0)
            enqueue(cur);
        else
            printf("%s %d\n",cur.name,elapse);
    }
}


Measured memory_bytes: 13292
k,a,b = map(int,input().split())
# first
cost = 0
# 2回でb-a枚ふやせる
if b-a <= 2 or k < a-1:
    print(k+1)
else:
    res = a
    k -= a-1
    if k%2 == 1:
        res += 1
        k -=1
    res += (b-a)*(k//2)
    print(res)


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

using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
#define rep(i,n) for(ll i = 0;i < (ll)n;i++)
#define ALL(x) (x).begin(),(x).end()
#define MOD 1000000007



int main(){
  
  string s;
  cin >> s;
  bool is = true;
  if(s[0] != 'A')is = false;
  int cnt_ = 0;
  for(int i = 2;i < s.size()-1;i++)if(s[i] == 'C')cnt_++;
  if(cnt_ != 1)is = false;
  int cnt = 0;
  rep(i,s.size())if(s[i] < 'a')cnt++;
  if(cnt > 2)is =false;
  is ? cout << "AC" << endl : cout << "WA" << endl;




  

  return 0;
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
)

func main() {
	N := nextInt()
	var As []int
	for i := 0; N > i; i++ {
		As = append(As, nextInt())
	}

	result := As[0]
	for i := 1; len(As)-1 >= i; i++ {
		result = gcd(result, As[i])
	}

	fmt.Println(result)
}

func gcd(a, b int) int {
	for b != 0 {
		a, b = b, a%b
	}

	return a
}

// Input. ----------

var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Buffer([]byte{}, math.MaxInt64)
	sc.Split(bufio.ScanWords)
}

func nextInt() int {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}

	return i
}

func nextString() string {
	sc.Scan()
	if err := sc.Err(); err != nil {
		panic(err)
	}

	return sc.Text()
}

// ---------- Input.

// Util. ----------

func min(x, y int) int {
	return int(math.Min(float64(x), float64(y)))
}

func max(x, y int) int {
	return int(math.Max(float64(x), float64(y)))
}

// ---------- Util.


Measured memory_bytes: 5888
#include<cstdio>
#include<cstring>
#include<algorithm>
#define clr(x) memset(x,0,sizeof(x))
#define ll long long
#define MN 5003
#define MM 203
using namespace std;
inline ll in(){
    ll x=0;bool f=0;char c;
    for (;(c=getchar())<'0'||c>'9';f=c=='-');
    for (x=c-'0';(c=getchar())>='0'&&c<='9';x=(x<<3)+(x<<1)+c-'0');
    return f?-x:x;
}
ll f[MN][MN],b[MN][MM],d[MN],res;
int q[MN],p[MN],n,m;
int main()
{
	n=in();m=in();
	for (int i=2;i<=n;++i) d[i]=d[i-1]+in();
	for (int i=1;i<=n;++i)
	for (int j=1;j<=m;++j) b[i][j]=in();
	for (int j=1;j<=m;++j){
		int top=0;clr(p);clr(q);
		for (int i=1;i<=n;++i){
			while (top&&b[q[top]][j]<=b[i][j]){
				f[p[q[top]]][i]-=b[q[top]][j];f[q[top]+1][i]+=b[q[top]][j];--top;
			}p[i]=q[top]+1;f[p[i]][i]+=b[i][j];f[i+1][i]-=b[i][j];q[++top]=i;
		}
	}
	for (int i=1;i<=n;++i)
	for (int j=1;j<=n;++j){
		f[i][j]+=f[i-1][j]+f[i][j-1]-f[i-1][j-1];
		if (i<=j) res=max(res,f[i][j]-d[j]+d[i]);
	}printf("%lld",res);return 0;
}

Measured memory_bytes: 203648
#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <utility>
using namespace std;
using ll = long long;
 
int main() {
	int n,a;
	cin >> n >> a;
	cout << n *n -a << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <string>

#define rep(i, a, b) for ( int i = (a); i < (b); i++ )
#define per(i, a, b) for ( int i = (b)-1; i >= (a); i--)
#define pb push_back
#define mp make_pair
#define bg begin()
#define en end()
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define sz(v) (int)(v).size()

using namespace std;

typedef long long ll;
typedef long double ld;

using P = pair<int, int>;

static const long long MOD = 1000000007;
static const long long LINF = (ll)(1e18+99);
static const int INF = 1e9+99;

int ans = INF;

int A[85][85], B[85][85], C[85][85], dp[85][85][25000];

int main(void) {
    int H, W;
    cin >> H >> W;
    rep(i, 0, H) rep(j, 0, W) cin >> A[i][j];
    rep(i, 0, H) rep(j, 0, W) cin >> B[i][j];

    rep(i, 0, H) rep(j, 0, W) C[i][j] = abs(A[i][j]-B[i][j]);

    dp[0][0][12500+C[0][0]] =  dp[0][0][12500-C[0][0]] = 1;

    rep(i, 0, H) rep(j, 0, W) {
        if (i-1>=0) {
            int x = C[i][j];
            for(int k=0; k<25000; k++) {
                if (k-x>=0) dp[i][j][k] |= dp[i-1][j][k-x];
                if (k+x<25000) dp[i][j][k] |= dp[i-1][j][k+x];
            }
        }

        if (j-1>=0) {
            int x = C[i][j];
            for(int k=0; k<25000; k++) {
                if (k-x>=0) dp[i][j][k] |= dp[i][j-1][k-x];
                if (k+x<25000) dp[i][j][k] |= dp[i][j-1][k+x];
            }
        }
    }

    rep(i, 0, 25000) if (dp[H-1][W-1][i]) ans = min(ans, abs(i-12500));
    
  
    cout << ans << "\n";
    return 0;
}



Measured memory_bytes: 629432
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <limits.h>
int main(){
    char s[100010][5]={};
    int n,i,c[5]={};
    scanf("%d",&n);
    for(i=0; i<n; i++){
        scanf("%s",s[i]);
        if(s[i][0]=='A')c[0]++;
        if(s[i][0]=='W')c[1]++;
        if(s[i][0]=='T')c[2]++;
        if(s[i][0]=='R')c[3]++;
    }
    printf("AC x %d\n",c[0]);
    printf("WA x %d\n",c[1]);
    printf("TLE x %d\n",c[2]);
    printf("RE x %d\n",c[3]);
    return 0;
}

Measured memory_bytes: 2640
n,m = map(int,input().split())
a = list(map(int,input().split()))
import heapq
heapq.heapify(a)
BC=[list(map(int,input().split())) for _ in range(m)]
BC.sort(reverse=True,key=lambda x:x[1])
for i in range(m):
    while BC[i][0]>0:
        if BC[i][1] > a[0]:
            minA = heapq.heappop(a)
            heapq.heappush(a,BC[i][1])
            BC[i][0] -=1
        else:
            break
print(sum(a))

Measured memory_bytes: 32976
using System;
using System.Linq;
using System.Collections.Generic;
using System.Numerics;
using static System.Console;

class Program {
    static Scanner cin = new Scanner();

    internal static void Main(string[] args) {
        char X, Y;
        X = cin.next().ToCharArray().First();
        Y = cin.next().ToCharArray().First();

        if (X > Y) {
            WriteLine(">");
        } else if (X < Y) {
            WriteLine("<");
        } else {
            WriteLine("=");
        }
    }
}




class Scanner {
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner() {
        s = new string[0];
        i = 0;
    }

    public string next() {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt() {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0) {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++) {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong() {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0) {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++) {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble() {
        return double.Parse(next());
    }

    public double[] ArrayDouble(int N, double add = 0) {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++) {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}

Measured memory_bytes: 11220
#include<iostream>
#include<cstdio>
using namespace std;
int n,x,y;
int num[2000+50];
int ABS(int x)
{
    return x<0 ? 0-x:x;
}
int main()
{
    scanf("%d %d %d",&n,&x,&y);
    for(int i=1;i<=n;i++)
        for(int j=i+1;j<=n;j++)
        {
            int dis=min(j-i,ABS(x-i)+1+ABS(j-y));
            dis=min(dis,ABS(y-i)+1+ABS(j-x));
            num[dis]++;
        }
    for(int i=1;i<n;i++)
    {
        printf("%d\n",num[i]);
    }
}

Measured memory_bytes: 764
import java.util.*;

public class Main{
    
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        
        int N = sc.nextInt();
        String s1 = sc.next();
        String s2 = sc.next();
        sc.close();
        int mod = (int)Math.pow(10, 9)+7;

        long sum = 1;
        int left = 0; //左のドミノの状態 1なら1種類―1なら2種類

        int i = 0;
        while(i < N){
            if(i==0){
                if(s1.charAt(i) == s2.charAt(i)){
                    sum *= 3;
                    left = 1;
                    i++;
                } else {
                    sum *= 6;
                    left = -1;
                    i = i+2;
                }
            } else {
                if(s1.charAt(i) == s2.charAt(i)){
                    if(left == 1){
                        sum = sum*2%mod;
                        left = 1;
                        i++;
                    } else {
                        sum *= 1;
                        left = 1;
                        i++;
                    }
                } else {
                    if(left == 1){
                        sum = sum*2%mod;
                        left = -1;
                        i=i+2;
                    } else {
                        sum = sum*3%mod;
                        left = -1;
                        i = i+2;
                    }
                }
            }

        }
        System.out.println(sum);
        
    }
}

Measured memory_bytes: 23764
a,b,m = map(int,input().split())
l = list(map(int,input().split()))
d = list(map(int,input().split()))
ans = min(l)+min(d)
for i in range(m):
  x,y,c = map(int,input().split())
  p = l[x-1]+d[y-1]-c
  if p < ans:
    ans = p
print(ans)

Measured memory_bytes: 18776
#include<bits/stdc++.h>
using namespace std;
 
int main() {
  int A,B,i;
  cin>>A>>B;
  int cnt = 0;
 
  for (i=A;i<=B;i++){
    if(i/10000 == i%10){
      if((i/1000)%10 == (i/10)%10){
        cnt++;
      }
    }
  }
  cout << cnt << endl;
}

Measured memory_bytes: 3640
#include <iostream>

using namespace std;
using ll = long long;
using ld = long double;

#define ALL(x) begin(x), end(x)
#define REP(i, n) for (size_t i = 0, i##_len = (n); i < i##_len; ++i)

const string YES = "Yes";
const string NO = "No";

void solve(ll A, ll B) {
  bool pred = (A*B)%2;
  cout << (pred ? YES : NO) << endl;
}

int main() {
  ll A;
  cin >> A;
  ll B;
  cin >> B;
  solve(A, B);
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep2(i, a, n) for(ll i = a; i < (ll)(n); i++)
#define memi cout << endl
#define kono(n) cout << fixed << setprecision(n)
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define hina cout << ' '
#define in(n) cin >> n
#define in2(n, m) cin >> n >> m
#define in3(n, m, l) cin >> n >> m >> l
#define out(n) cout << n
const ll mei = (ll)1e9 + 7;

int main(){
  ll n;
  in(n);
  if(n <= 111)
    out(111);
  else if(n <= 222)
    out(222);
  else if(n <= 333)
    out(333);
  else if(n <= 444)
    out(444);
  else if(n <= 555)
    out(555);
  else if(n <= 666)
    out(666);
  else if(n <= 777)
    out(777);
  else if(n <= 888)
    out(888);
  else
    out(999);
  memi;
}

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

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
	int i,j,k,l,n,m,a,b,c,d,min,max;
	while(scanf("%d%d%d%d",&a,&b,&c,&d)!=EOF)
	{
		if(b<=d)
		min=b;
		else
		min=d;
		if(a<=c)
		max=c;
		else
		max=a;
		if(max>min)
		printf("0\n");
		else
		printf("%d\n",min-max);
	}
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i = a; i < b; ++i)
#define all(c) c.begin(), c.end()
#define gmax(x,y) x=max(x,y)
#define gmin(x,y) x=min(x,y)
#define gadd(x,y) x=add(x,y)
#define gmul(x,y) x=mul(x,y)
using namespace std;

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

const int N = 2e5 + 5;
ll c[N], d[N];
vi g[N];

void dfs(int u = 1, int p = -1){
	c[u]	+= d[u];
	for(int v:g[u]){
		if(v == p)continue;
		d[v]	+= d[u];
		dfs(v,u);
	}
}

int main(){
	cin.tie(0);
	cout.tie(0);
	ios_base::sync_with_stdio(0);
	int n,q;
	cin >> n >> q;
	rep(i,0,n-1){
		int x,y;
		cin >> x >> y;
		g[x].push_back(y);
		g[y].push_back(x);
	}
	rep(i,0,q){
		ll x,v;
		cin >> x >> v;
		d[x] += v;
	}
	dfs();
	rep(i,1,n+1){
		cout << c[i] << ' ';
	}
	cout << '\n';
}


Measured memory_bytes: 25856
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF (2e9)

int main() {
  ll ans = 0;
  ll n, p; cin >> n >> p;
  string s; cin >> s;

  if(10 % p == 0) {
    for(int i = s.length() - 1; i >= 0; i--) {
      if((s[i]-'0') % p == 0) ans += i + 1;
    }
    cout << ans << endl;
    return 0;
  }

  vector<ll> sum(n+1);
  ll ten = 1;
  for(int i = n - 1; i >= 0; i--) {
    ll a = (s[i]-'0') * ten % p;
    sum[i] = (sum[i+1] + a) % p;
    ten *= 10; ten %= p;
  }
  vector<ll> cnt(p);
  for(int i = n; i >= 0; i--) {
    ans += cnt[sum[i]];
    cnt[sum[i]]++;
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 2180
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <map>
#include <cmath>
 
#define rep(i,n) for(int i = 0;i < (n);i++)
#define all(x) (x).begin(),(x).end()
#define pb(x) push_back(x)
#define mp(a,b) make_pair(a,b)

using namespace std;

typedef long long int ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<pair<int, int> > vpi;
typedef vector<pair<ll, ll> > vpl;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
  string s;
  cin >> s;
	cout << s[0] << (int)s.size()-2 << s[s.size()-1] << endl;
	return 0;
}


Measured memory_bytes: 256
'use strict'

function Main(input) {
  const N = Number(input.split(" ")[0])
  const L = Number(input.split(" ")[1])
  let ans = 0

  const list = []
  for(let i=1; i<=N; i++) {
    list.push(i+L-1)
  } 
  
  let minimum = 1000
  let plus = true
  let total = 0
  for(const num of list) {
    if(minimum > Math.abs(num)) {
      minimum = Math.abs(num)
      if(num > 0) {
        plus = true
      } else {
        plus = false
      }
    }
    total += num
  }

  if(plus) {
    console.log(total - minimum)
  } else {
    console.log(total + minimum)
  }

}
Main(require("fs").readFileSync("/dev/stdin", "utf8").trim())

Measured memory_bytes: 11468
import sys
def input():return sys.stdin.readline()[:-1]
def N(): return int(input())
def NM():return map(int,input().split())
def L():return list(NM())
def LN(n):return [N() for i in range(n)]
def LL(n):return [L() for i in range(n)]
a=input()
if a.upper()==a:
    print("A")
else:
    print("a")


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

#define FOR(i,a,b) for(int (i) = (a);(i) < (b);i++)
#define REP(i,n) FOR(i,0,n)
typedef long long ll;


int N,T;
int dp[3010][3010] = {0};
int prev_a[3010][3010] = {0};

/*ll rec(int i,int t){
    if(dp[i][t] >= 0){
        return dp[i][t];
    }
    int res;
    if(i == N){
        res = 0;
    }else if(t < a[i]){
        res = rec(i+1,t);
    }else{
        res = max(rec(i+1,t),rec(i+1,t-a[i])+b[i]);
    }
    return dp[i][t] = res;
}*/


int main(){
    cin >> N >> T;
    vector<int> a(N);
    vector<int> b(N);
    REP(i,N) cin >> a[i] >> b[i];
    
    for(int i = 0;i < N;i++){
        for(int j = 0;j <= T;j++){
            if(j >= a[i]){
                if(dp[i+1][j] < dp[i][j-a[i]] + b[i]){
                    dp[i+1][j] = dp[i][j-a[i]] + b[i];
                    prev_a[i+1][j] = j - a[i];
                }
            }
            if(dp[i+1][j] < dp[i][j]){
                dp[i+1][j] = dp[i][j];
                prev_a[i+1][j] = j;
            }
        }
    }
    int ans;
    ans = dp[N][T-1];
    int res = dp[N][T];
    int cur_a = T-1;
    for(int i = N-1;i >= 0;i--){
        if(prev_a[i+1][cur_a] == cur_a - a[i]){
            b[i] = 0;
        }
        cur_a = prev_a[i+1][cur_a];
    }
    sort(b.begin(),b.end(),greater<int>());
    cout << max(ans + b[0],res) << endl;
    //cin >> N;
}

Measured memory_bytes: 70912
n,m = gets.split.map(&:to_i)
h = gets.split.map(&:to_i)
ans = Array.new(n,0);
m.times do |i|
    a,b = gets.split.map(&:to_i)
    if h[a-1] <= h[b-1]
        ans[a-1] = 1
    end
    if h[a-1] >= h[b-1]
        ans[b-1] = 1
    end
end
ans.delete(1)
puts ans.length

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

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define rep(i,n) for(int i=0;i<n;i++)
#define rept(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define all(v) v.bigin(),v.end()
#define MAX(a,b) a=a>b?a:b
#define MIN(a,b) a=a<b?a:b
#define FAST ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int main(){
    FAST;
    ll x;
    cin>>x;
    if(x<30){
        cout<<"No";
    }
    else{
        cout<<"Yes";
    }
}



Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
  ll a,b,k;
  cin>>a>>b>>k;
  ll x = min(k,a);
  k-=x;
  a-=x;
  ll y=min(k,b);
  b-=y;
  cout << a << ' ' << b;
}


Measured memory_bytes: 256
#include <stdio.h>
#include<string.h>
int main(int argc, char const *argv[])
{
  int x;
  int a=0,b=0;
  scanf("%d",&x);
  a=x/500;
  b=x%500;
  b=b/5;
  x=a*1000+b*5;
  printf("%d",x);
  return 0;
}

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

using namespace std;

typedef unsigned int uint;
typedef unsigned long long ull;
typedef long long ll;
typedef pair<uint, uint> Pos;

static const uint m_max = 500;
static const uint mod = 1000000007;

// bool m[m_max+2][m_max+2];
// uint c[m_max+2][m_max+2];

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

ll v[2][100001];

int main(int, char**)
{
	int n, W;
	cin >> n >> W;

	int i;
	for (i = 0; i < n; i++) {
		int w,v1;
		cin >> w >> v1;
		for (int j = 0; j <= W; j++) {
			if (j < w)
				v[i%2][j] = v[(i+1)%2][j];
			else {
				v[i%2][j] = max(v[(i+1)%2][j], v[(i+1)%2][j-w]+v1);
			}
		}

	}

	cout << v[(n-1)%2][W] << endl;

	return 0;
}



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

int main(){
  int n,res=0,ans=0;
  string s;
  cin>>n>>s;
  for(int i=0; i<n; i++) {
    if(s[i]=='I') res++;
    else res--;
    ans = max(res,ans);
  }
  cout<<max(res,ans);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
using LL = long long;
const LL LINF = 1e18;
const double EPS = 1e-10;
using namespace std;
class Edge{
public:
    int from,to,value;
    Edge(LL a,LL b,LL c){
        from = a;
        to = b;
        value = c;
    }
    Edge(LL a,LL b){
        from = a;
        to = b;
    }
};

int main(){
    int n,m,p;
    while(cin >> n >> m >> p){
        if(n == 0 && m == 0 && p == 0)return 0;
        vector<int> v;
        for(int i = 0;i < n;i++){
            int b;cin >> b;
            v.push_back(b);
        }
        int sum = accumulate(v.begin(),v.end(), 0) * 100;
        sum -= sum * p / 100;
        //cout<<sum<<endl;
        if(v.at(m-1) == 0){
            cout<<0<<endl;
        }else{
            cout<<sum/v.at(m-1)<<endl;
        }
    }
}



Measured memory_bytes: 3012
process.stdin.resume();
process.stdin.setEncoding('utf8');

process.stdin.on('data', function (chunk) {
    const n = chunk.toString();
    const r = n.split("\n");
    sp(r[1]);
});

function sp(ans){
    const r = ans.split(" ");
    r.reverse();
    const c = r.join(" ");
    return console.log(`${c}`);
}


Measured memory_bytes: 15256
{-# LANGUAGE BangPatterns #-}

import qualified Data.Vector.Unboxed as VU
import Data.Bits
import qualified Data.ByteString.Char8 as BS
import qualified Data.ByteString.Lazy.Char8 as BSL
import Data.List


-- 1 <= damageOther < damageTarget <= 10^9
isPossibleWith :: VU.Vector Int -> Int -> Int -> Int -> Bool
isPossibleWith !hps !damageTarget !damageOther !numMagics
  = (<= numMagics) $ VU.sum $ VU.filter (> 0)
    $ VU.map (\hp -> (hp - damageMin + damageDiff - 1) `div` damageDiff)
    $ hps
  where
    !damageMin = damageOther * numMagics
    !damageDiff = damageTarget - damageOther

query :: VU.Vector Int -> Int -> Int -> Int
query !hps !damageTarget !damageOther = binSearch 0 (10 ^ 9)
  where
    binSearch !ng !ok
      | ok - ng <= 1 = ok
      | isPossibleWith hps damageTarget damageOther mid = binSearch ng mid
      | otherwise = binSearch mid ok
      where
        !mid = (ng + ok) `shiftR` 1

main :: IO ()
main = do
  [n, damageTarget, damageOther]
    <- unfoldr (BS.readInt . BS.dropWhile (==' ')) <$> BS.getLine
  hps <- VU.unfoldrN n (BSL.readInt . BSL.dropWhile (< '-'))
         <$> BSL.getContents
  print $ query hps damageTarget damageOther


Measured memory_bytes: 2684
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val x = sc.nextInt()
    val a = sc.nextInt()
    val b = sc.nextInt()
    println(problem087a(x, a, b))
}

fun problem087a(x: Int, a: Int, b: Int): Int {
    val tmp = x - a
    return tmp % b
}

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

#define ll long long

int main() {
    int n,m;
    cin >> n >> m;

    int sum = 0;
    for (int i=0; i<m; i++) {
        int x;
        cin >> x;

        sum +=x;
    }

    if (sum>n) {
        cout << -1;
    } else {
        cout << n-sum;
    }
    return 0;
}

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

int main(){
    int ans, N;
    cin >> N;
    vector<int> a(N), b(N-1);

    for(int i=0; i<N-1; i++)
	cin >> b[i];

    a[0]=b[0];
    a[N-1]=b[N-2];
    for(int i=1; i<N-1; i++){
	a[i] = min(b[i-1], b[i]);
    }
    ans = accumulate(a.begin(), a.end(), 0);
    cout << ans << endl;    
}


Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int room[4][3][10]={{{0}}};
  int n,b,f,r,v,i,j,k;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d %d %d %d",&b,&f,&r,&v);
    room[b-1][f-1][r-1]+=v;
  }
  for(i=0;i<4;i++){
    for(j=0;j<3;j++){
      for(k=0;k<10;k++){
        printf(" %d",room[i][j][k]);
      }
      printf("\n");
    }
    if(i==3){
      break;
    }else{
    printf("####################\n");
    }
  }
  return 0;
}


Measured memory_bytes: 2140
n = gets.to_i
arr = gets.split(" ").map(&:to_i)
count = 0
for i in 0...n
  mini = i
  for j in i...n
    if arr[j] < arr[mini]
      mini = j
    end
  end
  if i != mini
    arr[i], arr[mini] = arr[mini], arr[i]
    count += 1
  end
end
puts arr.join(" "), count

Measured memory_bytes: 6108
using System;
using System.Collections.Generic;
using System.Linq;
using BitArray = System.Collections.BitArray;
using BigInteger = System.Numerics.BigInteger;

namespace AtCoderProject
{
    public class Program
    {
        public object Calc()
        {
            var line = consoleReader.SplitInt();
            var N = line[0];
            var K = line[1]-1;
            var x = consoleReader.SplitInt();

            if (K == 0)
            {
                return x.Min(Math.Abs);
            }

            var min = int.MaxValue;
            for (int i = 0; i < N - K; i++)
            {
                if (x[i + K] <= 0)
                {
                    min = Math.Min(min, -x[i]);
                }
                else if (x[i] >= 0)
                {
                    min = Math.Min(min, x[i + K]);
                    break;
                }
                else
                {
                    min = Math.Min(min, x[i + K] - x[i] + Math.Min(x[i + K], -x[i]));
                }
            }
            return min;
        }

        public const int mod = 1000000007;
        #region いつもの
        private readonly ConsoleReader consoleReader;
        public Program() : this(new ConsoleReader()) { }
        public Program(ConsoleReader consoleReader) { this.consoleReader = consoleReader; }
        static void Main() => Console.WriteLine(new Program().Calc()); static string MultiLine<T>(IEnumerable<T> source) => string.Join("\n", source);
        #endregion
    }

    #region Console
    public class ConsoleReader { public virtual string String() => Console.ReadLine(); public int Int() => int.Parse(String()); public long Long() => long.Parse(String()); public ulong ULong() => ulong.Parse(String()); public double Double() => double.Parse(String()); public string[] Split() => String().Split().ToArray(); public int[] SplitInt() => String().Split().Select(int.Parse).ToArray(); public long[] SplitLong() => String().Split().Select(long.Parse).ToArray(); public ulong[] SplitULong() => String().Split().Select(ulong.Parse).ToArray(); public double[] SplitDouble() => String().Split().Select(double.Parse).ToArray(); public IEnumerable<string> Repeat(int count) { for (int i = 0; i < count; i++) yield return String(); } public IEnumerable<int> RepeatInt(int count) { for (int i = 0; i < count; i++) yield return Int(); } public IEnumerable<long> RepeatLong(int count) { for (int i = 0; i < count; i++) yield return Long(); } public IEnumerable<string[]> RepeatSplit(int count) { for (int i = 0; i < count; i++) yield return Split(); } public IEnumerable<int[]> RepeatSplitInt(int count) { for (int i = 0; i < count; i++) yield return SplitInt(); } }
    #endregion
}

Measured memory_bytes: 21344
#include <stdio.h>
 
int main(void){
  
  int n, a, b, c, f;
  
  scanf("%d", &n);
  
  a = n%10;
  b = ((n-a)%100)/10;
  c = ((n-a-b*10)%1000)/100;
  
  if((a==7) || (b==7) || (c==7)){
    printf("Yes");
  }else{
    printf("No");
  }
  return 0;
 
}

Measured memory_bytes: 1676
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
LL a[3][1005];
int main(){
	int n, m;
	scanf("%d%d", &n, &m);
	for(int i=1;i<=n;i++){
		scanf("%lld%lld%lld", &a[0][i], &a[1][i], &a[2][i]);
	}
	LL ans = -1e18;
	for(int i=0;i<8;i++){
		vector<LL> res;
		for(int j=1;j<=n;j++){
			LL cost = 0;
			for(int k=0;k<3;k++){
				if((i>>k)&1) cost += a[k][j];
				else cost -= a[k][j];
			}
			res.push_back(cost);
		}
		sort(res.begin(), res.end());
		reverse(res.begin(), res.end());
		LL tmp = 0;
		for(int j=0;j<m;j++){
			tmp += res[j];
		}
		ans = max(ans, tmp);
	}

	printf("%lld\n", ans);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FI first
#define SE second
#define EPS 1e-9
#define ALL(a) a.begin(),a.end()
#define SZ(a) int((a).size())
#define MS(s, n) memset(s, n, sizeof(s))
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORE(i,a,b) for (int i = (a); i >= (b); i--)
#define FORALL(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
#define WHATIS(x) cout << #x << " is " << x << endl;
#define ERROR(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
//__builtin_ffs(x) return 1 + index of least significant 1-bit of x
//__builtin_clz(x) return number of leading zeros of x
//__builtin_ctz(x) return number of trailing zeros of x

using namespace std;
using ll = long long;
using ld = double;
typedef pair<int, int> II;
typedef pair<ll, II> III;
typedef complex<ld> cd;
typedef vector<cd> vcd;

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cout << *it << " = " << a << endl;
    err(++it, args...);
}

const ll MODBASE = 1000000007LL;
const int MAXN = 100010;
const int MAXM = 110;
const int MAXK = 510;

int n, q, f[MAXN], sum[MAXN];
string s;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    cin >> n >> q;
    cin >> s;
    s = " " + s;
    FOR(i,1,n-1)
        if (s[i] == 'A' && s[i+1] == 'C') f[i] = 1;
    FOR(i,2,n) sum[i] = sum[i-1] + f[i-1];
    //FOR(i,1,n) cout << sum[i] << ' ';
    //cout << endl;
    while (q--) {
        int l, r;
        cin >> l >> r;
        cout << sum[r] - sum[l] << "\n";
    }
    return 0;
}

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

int main(){
    int H,W;
    
    while(1){
        cin >> H >> W;
        if( H==0 && W==0 ) break;
        
        for( int i=0; i < H; i++ ){
            for( int j=0; j < W; j++ ){
                if((i+j)%2==0){
                    cout << "#";
                }else{
                    cout << ".";
                }
            }
            cout << endl;
        }
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 3068
parseInt(x)=parse(Int,x)
parseMap(x::Array{SubString{String},1})=map(parseInt,x)

function main()
	n = readline() |> parseInt
	s = chomp(readline())
	d = Dict{Char,Int}()
	for i in 1:n
		if haskey(d,s[i])
			d[s[i]] += 1
		else
			d[s[i]] = 1
		end
	end
	t = 1
	mod = 1000000007
	for i in keys(d)
		t = t*(d[i]+1)%mod
	end
	println(t-1)
end
main()

Measured memory_bytes: 172624
#include<bits/stdc++.h>
#define INF 2147483647
#define SYOU(x) setprecision(x)
using namespace std;
long long i[10000][10000];
long long u[1111111];
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int a,b,c,d=0,e=1,f=0;
  string s;
  cin >>s;
  if(s[0]=='Y'&&s[1]=='A'&&s[2]=='K'&&s[3]=='I') cout <<"Yes\n";
  else cout <<"No\n";
  return (0);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(ll i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  ll n;
  cin >> n;
  vl x(n), y(n), p(n);
  rep(i, n) cin >> x[i] >> y[i] >> p[i];
  vector<vl> dx(1 << n, vl(n)), dy(1 << n, vl(n));
  vl ans(n + 1, 1e18);
  rep(i, 1 << n) {
    rep(j, n) dx[i][j] = abs(x[j]);
    rep(j, n) dy[i][j] = abs(y[j]);
    vl v;
    rep(j, n) if(i >> j & 1) v.push_back(j);
    for(auto u : v) {
      rep(j, n) {
        dx[i][j] = min(dx[i][j], abs(x[u] - x[j]));
        dy[i][j] = min(dy[i][j], abs(y[u] - y[j]));
      }
    }
  }
  ll m = pow(3, n);
  rep(i, m) {
    ll ii = i, ax = 0, ay = 0, cnt = 0;
    rep(j, n) {
      ll r = ii % 3;
      ii /= 3;
      if(r == 1)
        ax += 1 << j;
      else if(r == 2)
        ay += 1 << j;
      if(r) cnt++;
    }
    ll now = 0;
    rep(j, n) now += min(dx[ax][j], dy[ay][j]) * p[j];
    ans[cnt] = min(ans[cnt], now);
  }
  rep(i, n + 1) cout << ans[i] << '\n';
}

Measured memory_bytes: 13096
#include<iostream>
using namespace std;
int main() {
  string a,b,c; cin >> a >> b;
  c = a+b;
  int d = stoi(c);
  //cout << c << endl;
  bool flag = false;
  for(int i=1;i*i<=d;i++){
    if(i*i==d){
      flag = true;
      break;
    }
  }
  if(flag) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
class UnionFind(n:Int){
    val n = n
    var dat = Array(n, {i -> -1})
    fun unionSet(x:Int, y:Int):Boolean{
        var rx = root(x)  
        var ry = root(y)  
        if(rx != ry){
            if(dat[ry] < dat[rx]) {
                val tmp = rx
                rx = ry
                ry = tmp 
            }
            dat[rx] += dat[ry]
            dat[ry] = rx
        }
        return rx != ry
    }
    fun findSet(x:Int, y:Int):Boolean{
        return root(x) == root(y)
    }
    fun root(x:Int):Int{
        if(dat[x] >= 0) {
            dat[x] = root(dat[x])
            return dat[x]
        }
        return x
    }
    fun size(x:Int):Int{
        return -dat[root(x)]
    }
}


fun main(args: Array<String>) {
    val (n, m) = readLine()!!.split(" ").map(String::toInt)
    var uf = UnionFind(n)
    var a = Array(m, {0}) 
    var b = Array(m, {0}) 
    for(i in 0 until m){
        var (s, t) = readLine()!!.split(" ").map(String::toInt)
        s--
        t--
        a[i] = s
        b[i] = t
    }
    var ans = Array(m, {0.toLong()})
    var tmp = (n.toLong()*(n.toLong()-1))/2.toLong()
    ans[m-1] = tmp
    for(i in m-1 downTo 1){
        if(uf.findSet(a[i], b[i])){
            ans[i-1] = tmp
        }else{
            val sa = uf.size(a[i]).toLong() 
            val sb = uf.size(b[i]).toLong()
            uf.unionSet(a[i], b[i])
            tmp -= sa*sb
            ans[i-1] = tmp
        }
    }
    for(i in 0 until m){
        println(ans[i])
    }
}

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

#define REP(i,n) for(decltype(n) i=0; i<(n); ++i)
#define ALL(c) (c).begin(), (c).end()
#define st first
#define nd second
#define pb push_back

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

void solve(){
    ll N;
    cin>>N;
    for(int h=1;h<=3500;++h)
        for(int n=1;n<=3500;++n){
            ll d = 4*h*n;
            d -= N*(h+n);
            if(d<=0) continue;
            ll nom = N*h*n;
            if(nom%d != 0) continue;
            cout<<h<<' '<<n<<' '<<nom/d<<'\n';
            return;
        }
}

int main(){
#ifdef ONLINE_JUDGE
    ios_base::sync_with_stdio(0);
    cin.tie(0);
#endif
    solve();
    return 0;
}


Measured memory_bytes: 256
N = int(input())
ans = ['R' for i in range(N << 1)]


def ask(arr):
    query = "?"
    for e in arr:
        query += " " + str(e)
    print(query, flush=True)
    return input()


arr = [i for i in range(1, N+1)]
color = ask(arr)
another = 'Red' if (color == 'Blue') else 'Blue'
l = 1
r = N
res = -1
while l <= r:
    mid = (l+r) >> 1
    arr = [i for i in range(mid, mid+N)]
    tmp_color = ask(arr)
    if(tmp_color == color):
        res = mid
        l = mid+1
    else:
        r = mid-1

l = res - 1
r = res + N - 1

ans[l] = color
ans[r] = another

for i in range(N << 1):
    if(i == l or i == r):
        continue
    arr = []
    if i > l and i < r:
        arr += [j for j in range(1, l+1)]
        arr += [j for j in range(r+2, N*2 + 1)]
        arr.append(i+1)
        ans[i] = ask(arr)
    else:
        arr = [j for j in range(l+2, r+1)]
        arr.append(i+1)
        ans[i] = ask(arr)
res = "! "
for i in range(N << 1):
    res += ans[i][0]
print(res, flush=True)


Measured memory_bytes: 3532
while line = gets do
  break if line.chomp == "0"

  n = line.chomp.to_i
  is_na = true

  h = {}
  h.default = 0

  n.times do
    l = gets.chomp.split(' ')
    i = l[0]
    p = l[1]
    q = l[2]

    h[i] = h[i].to_i + (p.to_i * q.to_i)
  end

  h.each do |k,v|
    if v.to_i >= 1000000 then
      puts k + "\n"
      is_na = false
    end
  end

  puts "NA" if is_na == true

end

Measured memory_bytes: 6108
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


#define NUM 3005

struct Point{
	int x,y;
};

struct Info{
	Info(double arg_slope,double arg_segment){
		slope = arg_slope;
		segment = arg_segment;
	}
	bool operator<(const struct Info &arg) const{
		if(fabs(slope-arg.slope) > EPS){
			return slope < arg.slope;
		}else{
			return segment < arg.segment;
		}
	}
	double slope,segment;
};

int N,K;
int table[10005];
Point point[NUM];
vector<Info> V;

int main(){

	for(int i = 0; i <= 10000; i++){
		table[i] = 0;
	}

	scanf("%d %d",&N,&K);

	for(int i = 0; i < N; i++){

		scanf("%d %d",&point[i].x,&point[i].y);
	}

	int maximum = 0;
	int need_num = (K*(K-1))/2;
	double tmp_slope,tmp_segment;

	//傾きを全通り作成
	for(int i = 0; i < N-1; i++){
		for(int k = i+1; k < N; k++){
			if(point[k].x == point[i].x){ //y軸に平行な直線
				table[point[k].x]++;
				maximum = max(maximum,table[point[k].x]);
			}else{
				tmp_slope = (double)(point[k].y-point[i].y)/(double)(point[k].x-point[i].x);
				tmp_segment = (double)point[k].y-tmp_slope*(double)point[k].x;
				V.push_back(Info(tmp_slope,tmp_segment));
			}
		}
	}

	if(maximum >= need_num){
		printf("1\n");
		return 0;
	}

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

	int limit = (int)V.size();

	for(int i = 0; i+need_num <= limit; i++){

		//同一直線上にK個以上の点があれば、KC2個以上、同じ直線が現れるはず
		if(fabs(V[i+need_num-1].slope-V[i].slope) < EPS && fabs(V[i+need_num-1].segment-V[i].segment) < EPS){
			printf("1\n");
			return 0;
		}
	}

	printf("0\n");

	return 0;
}



Measured memory_bytes: 134104
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <map>
#include <set>
#include <functional>
#include <cmath>
#define SIZE 500005
#define MOD 1000000007

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

struct BIT
{
	int bit[SIZE];
	
	void init()
	{
		memset(bit,0,sizeof(bit));
	}
	void add(int k,int x)
	{
		while(k<SIZE)
		{
			bit[k]+=x;
			k+=k&-k;
		}
	}
	int get(int k)
	{
		int ret=0;
		while(k>0)
		{
			ret+=bit[k];
			k-=k&-k;
		}
		return ret;
	}
	int get(int s,int t)
	{
		return get(t)-get(s-1);
	}
};
BIT bit;
ll inv[SIZE],fac[SIZE],finv[SIZE];
void make()
{
	fac[0]=fac[1]=1;
	finv[0]=finv[1]=1;
	inv[1]=1;
	for(int i=2;i<SIZE;i++)
	{
		inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
		fac[i]=fac[i-1]*(ll) i%MOD;
		finv[i]=finv[i-1]*inv[i]%MOD;
	}
}
ll C(int a,int b)
{
	if(a<b) return 0;
	return fac[a]*(finv[b]*finv[a-b]%MOD)%MOD;
}
int A[SIZE];
ll sum[SIZE];
bool use[SIZE];

int main()
{
	make();
	int n;
	scanf("%d",&n);
	int cnt=0;
	for(int i=0;i<n;i++)
	{
		scanf("%d",&A[i]);
		if(A[i]>=1) use[A[i]]=true;
	}
	vector <int> zan;
	for(int i=1;i<=n;i++) if(!use[i]) zan.push_back(i);
	int now=0;
	ll st=0;
	ll ret=fac[zan.size()];
	bit.init();
	for(int i=n-1;i>=0;i--)
	{
		if(A[i]==0)
		{
			now++;
			ll way=C(zan.size(),now)*C(now,2)%MOD*fac[now-1]%MOD*fac[zan.size()-now]%MOD;
			way+=st*fac[zan.size()-1]%MOD;
			if(way>=MOD) way-=MOD;
			sum[i]=way;
		}
		else
		{
			int pos=lower_bound(zan.begin(),zan.end(),A[i])-zan.begin();
			st+=zan.size()-pos;
			if(now>=1)
			{
				sum[i]=(ll) pos*C(zan.size()-1,now-1)%MOD*fac[zan.size()-now]%MOD*fac[now]%MOD;
			}
			sum[i]+=(ll) bit.get(A[i])*(ll) fac[zan.size()]%MOD;
			if(sum[i]>=MOD) sum[i]-=MOD;
			bit.add(A[i],1);
			st%=MOD;
		}
		ret+=sum[i]*fac[n-i-1]%MOD;
		if(ret>=MOD) ret-=MOD;
		//printf("%lld\n",sum[i]);
	}
	printf("%lld\n",ret);
	return 0;
}


Measured memory_bytes: 22128
#include <iostream>
#include <vector>
using namespace std;
int main(){//全探索
  long long int n,k,b,c,ans=0;
  cin >> n>>k;
  vector<long long> v(k,0);//k個の v,0で初期化
  for(int i=1;i<=n;i++) v[i%k]++;//kで割った余りで1~nを分けて数える
  for(int i=0;i<k;i++){
    if(i==0) {
      b=i;c=i;
    }
    else{
    b=k-i;
    c=k-i;
  }
    if((b+c)%k!=0) continue;
    ans+=v[i]*v[b]*v[c];
  }
  cout << ans<<endl;
}


Measured memory_bytes: 1792
#include <iostream>
#include <stdio.h>
#include <set>
#define llint long long

using namespace std;

llint a, b;
set<llint> S;
bool prime[1000005];

void calc(llint x)
{
	for(llint i = 2; i <= 1000000; i++){
		if(prime[i]) continue;
		while(x % i == 0){
			S.insert(i);
			x /= i;
		}
	}
	if(x > 1) S.insert(x);
}

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

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	for(int i = 2; i <= 1005; i++){
		if(prime[i]) continue;
		for(int j = 2*i; j < 1000005; j+=i) prime[j] = true;
	}
	
	cin >> a >> b;
	calc(gcd(a, b));
	cout << (llint)S.size() + 1 << endl;
	
	return 0;
}

Measured memory_bytes: 1280
from collections import deque
s = list(input())
queue = deque()
res = 0
count = 0
for c in s:
    queue.append(c)
    count += 1
    if count >= 2:
        if "0" == queue[-1] and "1" == queue[-2] or "0" == queue[-2] and "1" == queue[-1]:
             res += 2
             count -= 2
             queue.pop()
             queue.pop()
print(res)


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

int main() {
  int N,K,num;
  num = 1;
  cin >> N >> K;
  for (int i=0;i<N;i++){
    if(num <= K){
      num *= 2;
    }else{
      num += K;
    }
  }
  cout << num <<endl;
}

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

int main() {
    int n,m; cin >> n >> m;
    string s; cin >> s;

    vector<int> dp(n + 1,INF);
    dp[n] = 0;
    queue<int> q;
    q.push(0);
    for (int i = n - 1;i >= 0; i --) {
        while (1) {
            if (q.size() == 0) {
                puts("-1");
                return 0;
            }
            if (q.front() != INF && q.size() <= m) break;
            q.pop();
        }
        if (s[i] == '0') dp[i] = q.front() + 1;
        q.push(dp[i]);
    }

    vector<int> ans;
    int x = 0;
    int res = dp[0];
    while (x < n) {
        res --;
        int i = 1;
        while (dp[x + i] != res) i ++;
        ans.push_back(i);
        x += i;
    }
    rep(i,ans.size()) {
        cout << ans[i] << ' ';
    }
    cout << '\n';
    return 0;
}

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

int main() {
    string s;
    cin >> s;
    int32_t l = s.length();
    stack<char> st;

    for (int32_t i = 0; i < l; i++) {
        if (!st.empty() && st.top() == 'S' && s[i] == 'T') {
            st.pop();
        } else {
            st.push(s[i]);
        }
    }
    cout << st.size() << endl;

    return 0;
}


Measured memory_bytes: 644
def base2_number(n):
    result = ""
    while True:
        rem = n % 2
        if rem:
            n -= 1
        n = n // -2
        result += str(abs(rem))
        if n == 0:
            break
    return int(result[::-1])
n = int(input())
print(base2_number(n))


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
 
const int64_t MOD=1e9+7;
 
int64_t modpow(int64_t a,int64_t n){
  int64_t res=1;
  if(n==0) return res;
  while(n>0){
    if(n&1) res=(res*a)%MOD;
    a=(a*a)%MOD;
    n >>= 1;
  }
  return res;
}
 
int main(){
  int64_t N,K;
  cin>>N>>K;
  int64_t ans=0;
 
  
  //i|gcdなるような総数mod[i]
  vector<int64_t> mod(K+1,0);
  for(int i=1;i<=K;++i){
    mod[i]=modpow(K/i,N);
  }
  
  //i==gcdなるような総数dp[i]
  vector<int64_t> dp(K+1,0);
  for(int64_t i=K;i>=1;--i){
    dp[i]=mod[i];
    for(int64_t j=2;i*j<=K;++j){
      dp[i] += MOD-dp[i*j];
    }
    dp[i] %= MOD;
    ans += i*dp[i];
    ans %= MOD;
  }
 
  cout<<ans<<endl;
}

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

#define NEW(p,n){p=malloc((n)*sizeof(p[0]));if(p==NULL){printf("not enough memory\n");exit(1);};}
//pの型の変数n個の要素分のメモリを確保し、そのアドレスをpに代入するマクロ

#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define SWAP(type, x, y) do { type tmp = x; x = y; y = tmp; } while (0)

#define MOD 1000000007 

int main(void){
    int N,M;
    scanf("%d%d",&N,&M);

    long ans=1;
    if(abs(N-M)==0){
        for(int i=1;i<=N;i++) ans=(ans*i)%MOD;
        for(int i=1;i<=M;i++) ans=(ans*i)%MOD;
        ans=(ans*2)%MOD;
    }
    else if(abs(N-M)==1){
        for(int i=1;i<=N;i++) ans=(ans*i)%MOD;
        for(int i=1;i<=M;i++) ans=(ans*i)%MOD;
    }
    else ans=0;
    printf("%ld\n",ans);

    return 0;
}

Measured memory_bytes: 128
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <iostream>
#include <algorithm>
#define MAXN 500001

int n, m, a[MAXN], ans[MAXN];
int sqrn, num[MAXN], ba[MAXN];
struct query {
	int x, y, id;
	friend bool operator < (query q1, query q2) {
		if (num[q1.x] == num[q2.x]) return num[q1.y] < num[q2.y];
		return num[q1.x] < num[q2.x];
	}
}q[MAXN];

int main() {
	scanf("%d %d", &n, &m), sqrn = sqrt(n);
	for (int i = 1; i <= n; ++i) {
		scanf("%d", &a[i]);
		num[i] = (i - 1) / sqrn + 1;
	}
	for (int i = 1; i <= m; ++i) {
		scanf("%d %d", &q[i].x, &q[i].y);
		q[i].id = i;
	}
	std::sort(q + 1, q + m +1);
	int l = 1, r = 1, now = 1;
	ba[a[l]] = 1;
	for (int i = 1; i <= m; ++i) {
		while(l > q[i].x) {
			++ba[a[--l]];
			if (ba[a[l]] == 1) ++now;
		}
		while(r < q[i].y) {
			++ba[a[++r]];
			if (ba[a[r]] == 1) ++now;
		}
		while(l < q[i].x) {
			if (ba[a[l]] == 1) --now;
			--ba[a[l++]];
		}
		while(r > q[i].y) {
			if (ba[a[r]] == 1) --now;
			--ba[a[r--]];
		}
		ans[q[i].id] = now;
	}
	for (int i = 1; i <= m; ++i) printf("%d\n", ans[i]);
	return 0;
}

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

int numlist[100001];
int main() {
    int n;
    cin >> n;
    ll sum = 0;
    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;
        sum += a;
        numlist[a]++;
    }
    int q;
    cin >> q;
    int b[q], c[q];
    for (int i = 0; i < q; i++) {
        cin >> b[i] >> c[i];
    }
    for (int i = 0; i < q; i++) {
        sum += (c[i] - b[i]) * numlist[b[i]];
        cout << sum << endl;
        numlist[c[i]] += numlist[b[i]];
        numlist[b[i]] = 0;
    }
    return 0;
}

Measured memory_bytes: 4656
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
	ll n;
	cin>>n;
	ll count=1,ans=0;
	if(n==1){
		cout<<1<<endl;
		return 0;
	}
	
	while(n!=1){
		count*=2;
		n/=2;
		if(n==1){
			break;
		}
	}
	
	count+=(count-1);
	cout<<count<<endl;
}

Measured memory_bytes: 256
try:
    while True:
        a,b,c,d,e,f=[int(i) for i in input().split(" ")]
        x=(e*c-b*f)/(a*e-b*d)
        y=(a*f-c*d)/(a*e-b*d)
        if x==0:
            x=0
        if y==0:
            y=0
        print("%.3f %.3f"%(x,y))
except EOFError:
    pass



Measured memory_bytes: 5616