akhauriyash/Code-Regression huggingface dataset:
def main():
    from builtins import int, map, list, print
    import sys
    sys.setrecursionlimit(10 ** 6)

    input = (lambda: (sys.stdin.readline()).rstrip())
    input_list = (lambda: input().split())
    input_number = (lambda: int(input()))
    input_number_list = (lambda: list(map(int, input_list())))

    A, B = input_number_list()
    print("YNeos"[A * B % 2 == 0::2])


if __name__ == '__main__':
    main()


Measured memory_bytes: 9116
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <string>
#include <queue>
#include <numeric>
#include <ctype.h>
#include <limits>
#include <iomanip>

#define rep(i,n) for (int i = 0; i < n; i++)
#define all(x) (x).begin(),(x).end()
using namespace std;

typedef long long ll;

int main()
{
	string s;
	cin >> s;
	rep(i, 3)cout << s[i];

	return 0;
}

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

int main() {
  int K, A, B; string ans = "NG";
  cin >> K >> A >> B;
  for (int i = 0; i <= 1000; i++) {
    if (K * i >= A && K * i <= B) {
      ans = "OK";
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  vector<int> vec(N);
  for(int i = 0;i<N;i++){
   cin >> vec.at(i); 
  }
  int index = 1;
  int num = 0;
  for(int i = 0;i<N;i++){
   if(index == 2){
     cout << num << endl;
     break;
   }else if( i == N-1){
     cout << -1 << endl;
     break;
   }
    index = vec.at(--index);
    num++;
  }
}

Measured memory_bytes: 640
//Name: A First Grader
//Level: 2
//Category: DP,動的計画法
//Note:

/*
 * 先頭からi項目までを使ってsumを作る方法dp[i][sum]は，
 * i-1項目まででsum-terms[i]を作ってterms[i]を足すか，i-1項目まででsum+terms[i]を作ってterms[i]を引くかのどっちか．
 * この式でDPすればよい．
 */
#include <iostream>
#include <vector>

using namespace std;

typedef unsigned long long ULL;
ULL dp[100][21];
int main() {
    int N;
    cin >> N;
    vector<int> terms(N-1);
    for(int i = 0; i < N-1; ++i) {
        cin >> terms[i];
    }
    int RHS;
    cin >> RHS;
    dp[0][terms[0]] = 1;
    for(int i = 1; i < N-1; ++i) {
        for(int sum = 0; sum <= 20; ++sum) {
            if(sum-terms[i] >= 0) {
                dp[i][sum] += dp[i-1][sum-terms[i]];
            }
            if(sum+terms[i] <= 20) {
                dp[i][sum] += dp[i-1][sum+terms[i]];
            }
        }
    }
    cout << dp[N-2][RHS] << endl;
    return 0;
}

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

typedef long long ll;
using namespace std;

int pot (ll q, ll w){
	ll qw = q;
	q = 1;
	for (int i = 0; i<w; i++)
		q*= qw;
	return q;
}

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

ll a,b,c;

cin >> a >> b >> c;
cout << c <<" "<< a<< " " << b;




return 0;
}



Measured memory_bytes: 256
while (n=gets.to_i)!=0
  h=Hash.new
  n.times do
    id,val,amo=gets.split.map(&:to_i)
    h.key?(id) ? h[id]+=(val*amo) : h.store(id,val*amo)
  end
  ans=h.select{|k,v| v>=1000000}
  puts ans.empty? ? "NA" : ans.keys
end

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

typedef pair<int,int> PII;

char s[100007];
bool yes;
int x,y,n,i,j,nyan,sumhori,sumverti;
vector<int> hori,verti,sisaverti,sisahori;
map<PII,int> mem1,mem2;

inline int DP1(int pos, int haha) {
	if (pos == hori.size()) {
		if (haha == x) return 2;
		return 1;
	}
	if (abs(haha-x) > sisahori[pos]) return 1;
	if (mem1[PII(pos,haha)] != 0) return mem1[PII(pos,haha)];
	return mem1[PII(pos,haha)] = max(DP1(pos+1,haha-hori[pos]),DP1(pos+1,haha+hori[pos]));
}

inline int DP2(int pos, int haha) {
	if (pos == verti.size()) {
		if (haha == y) return 2;
		return 1;
	}
	if (abs(haha-y) > sisaverti[pos]) return 1;
	if (mem2[PII(pos,haha)] != 0) return mem2[PII(pos,haha)];
	return mem2[PII(pos,haha)] = max(DP2(pos+1,haha-verti[pos]),DP2(pos+1,haha+verti[pos]));
}

int main() {
	scanf("%s",&s);
	scanf("%d%d",&x,&y);
	n = strlen(s);
	
	yes = true;
	for (i=0 ; i<n ; i++) {
		if (s[i] == 'T') {
			if (yes) {
				hori.push_back(nyan);
				sumhori += nyan;
			} else {
				verti.push_back(nyan);
				sumverti += nyan;
			}
			yes = (!yes);
			nyan = 0;
		} else {
			nyan++;
		}
	}
	if (yes) {
		hori.push_back(nyan);
		sumhori += nyan;
	} else {
		verti.push_back(nyan);
		sumverti += nyan;
	}
	
	int mama = sumhori;
	for (i=0 ; i<hori.size() ; i++) {
		sisahori.push_back(sumhori);
		sumhori -= hori[i];
	}
	sumhori = mama;
	mama = sumverti;
	for (i=0 ; i<verti.size() ; i++) {
		sisaverti.push_back(sumverti);
		sumverti -= verti[i];
	}
	sumverti = mama;
	
	if (abs(sumhori) < abs(x) || abs(sumverti) < abs(y)) {
		printf("No\n");
		return 0;
	}
	
	if (DP1(1,hori[0]) == 1) {
		printf("No\n");
		return 0;
	}
	
	if (DP2(0,0) == 1) {
		printf("No\n");
		return 0;
	}
	
	printf("Yes\n");
}


Measured memory_bytes: 99712
#include<iostream>
#include<cmath>
#include<vector>
#include<algorithm>
#include<sstream>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;

string itos(int n){
	stringstream ss;
	ss<<n;
	return ss.str();
}

bool fizzbuzz(int i,string s){
	if(i%15==0){
		if(s=="FizzBuzz")return true;
	}else if(i%3==0){
		if(s=="Fizz")return true;
	}else if(i%5==0){
		if(s=="Buzz")return true;
	}else{
		if(s==itos(i))return true;
	}
	return false;
}

int main(){
	int m,n;
	while(cin>>m>>n,m||n){
		bool person[m+1];
		rep(i,m+1)person[i]=true;
		person[0]=false;
		string s;
		int now=1;
		loop(i,1,n+1){
			cin>>s;
			int check=0;
			if(!person[now])for(int j=0;j<m && !person[now];j++){now++;if(now>m)now-=m;}
			loop(j,1,m+1)if(person[j])check++;
			if(check==1)continue;
			if(!fizzbuzz(i,s)){
				person[now]=false;
			}
			now++;
			if(now>m)now-=m;
		}
		vector<int> vec;
		loop(i,1,m+1)if(person[i])vec.push_back(i);
		if(vec.size()==1)cout<<vec[0]<<endl;
		else{
			cout<<vec[0];
			loop(i,1,vec.size())cout<<" "<<vec[i];
			cout<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1264
def calc(y,z):
    flag=0
    LL=0
    for i in range(D):
        LL +=(y[i] - z[i])**2
    L =LL**0.5
    if L == int(L) :
        flag=1
    return(flag)


N,D=[int(x) for x in input().split()]
X=[]

for i in range(N):
    X+=[[int(x) for x in input().split()]]

    cnt=0
for i in range(N-1):
        for j in range(i+1,N):
                cnt += calc(X[i],X[j])
                
print(cnt)

Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>

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

using namespace std;
#define int long long
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repr(i,n) for(ll i=n;i>=0;i--)
#define P pair<ll, ll>
#define sz(x) (ll)x.size()
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define VE vector<ll>
#define COUT(x) cout<<(x)<<endl
#define MA map<ll,ll>
#define SE set<ll>
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,VE,greater<ll>>
#define COUT(x) cout<<(x)<<endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define EPS (1e-10)
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
bool prime(ll n) {
	for (ll i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}


const long long MOD = 1000000007;
const long long INF = 1LL << 60;


const int MAX_N = 100010;

signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n, x; cin >> n >> x;
	int ans = 0;
	rep(i, n) {
		int a; cin >> a;
		ans = gcd(ans, abs(a - x));
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
fun main() {
    val n = readLine()!!.toInt()
    val s = readLine()!!.toList()

    val rgb = s.filter { it == 'R' }.size.toLong() * s.filter { it == 'G' }.size.toLong() * s.filter { it == 'B' }.size.toLong()

    val exclude = (0..n-3).sumBy { l ->
        (1..n).count { w ->
            val c = l + w
            val r = c + w
            r < n && s[l] != s[c] && s[c] != s[r] && s[r] != s[l]
        }
    }

    println(rgb - exclude)
}

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

int main(){

   int n;
   cin >> n;
   vector<int> L(n);
   rep(i,n) cin >> L[i];
   sort(L.begin(),L.end());
   int ans = 0;
   rep(i,n)for(int k=i+1;k<n;k++){
      int ab=L[i]+L[k];
      int t;
      for(t=k+1;L[t]<ab&&t<n;t++);
      if(t!=k+1) ans+=t-k-1;
   }

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


Measured memory_bytes: 256
use std::io::stdin;

fn main() {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();
    let r_c: Vec<usize> = buf
        .trim()
        .split_whitespace()
        .map(|iter| iter.parse::<usize>().unwrap())
        .collect();

    let mut input: Vec<Vec<i32>> = Vec::new();
    for _ in 0..r_c[0] {
        let mut buf = String::new();
        stdin().read_line(&mut buf).unwrap();
        let mut split = buf.trim().split_whitespace();

        input.push(
            (0..r_c[1])
                .map(|_| split.next().unwrap().parse::<i32>().unwrap())
                .collect::<Vec<i32>>(),
        );
    }

    print!("{}", solve(r_c[0], r_c[1], input));
}

fn solve(r: usize, c: usize, mut input: Vec<Vec<i32>>) -> String {
    for iter in input.iter_mut() {
        let sum = iter.iter().sum();
        iter.push(sum);
    }
    let mut last_line: Vec<i32> = Vec::new();
    for c in 0..c + 1 {
        let mut element = 0;
        for r in 0..r {
            element += input[r][c];
        }
        last_line.push(element);
    }
    input.push(last_line);
    let mut result = String::new();
    for iter in input {
        for iter in iter {
            result.push_str(&format!("{} ", iter));
        }
        result = result[0..result.len() - 1].to_string();
        result.push_str("\n");
    }
    result
}



Measured memory_bytes: 5052
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    return divisors


n = int(input())

c = 0
for i in range(1,n+1,2):
    if len(make_divisors(i)) == 8:
        c += 1

print(c)

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


ll n, K, temp, ans;
int v[51];
vector<int> pq_v;
int main() {
    cin >> n >> K;
    for (int i=0;i<n;i++) {
        cin >> v[i];
    }

    ans = 0;
    for (int i=1;i<=min(n,K);i++) {
        for (int j=0;j<=i;j++) {
            priority_queue<int, vector<int>, greater<int>> pq;
            for (int k=0;k<j;k++) pq.push(v[k]);
            for (int k=(i-j);k<n && k>0;k--) pq.push(v[n-k]);
            for (int k=0;k<K-i;k++) if (!pq.empty() && pq.top() < 0) pq.pop();

            temp = 0;
            while(pq.size()) {
                temp += pq.top();
                pq.pop();
            }
            // cout <<j << " " << i-j << " " << K-i << " " << temp << endl;
            ans = max(ans,temp);
        }

    }
    cout << ans << endl;
}

// i個とる
// 左からj個, 右からi-j個とる
// 小さい順に,負ならばK-i個戻す
// 価値が大きければ更新，そうでなければ更新しない
// i=1~Kまでする
// i=0では0

Measured memory_bytes: 256
program main
implicit None
character*200000::s
integer(8)::k,t,i,n
integer(8),allocatable::a(:)

read *,s
k = len_trim(s)
t = 0

do i = k,1,-1
	if(s(i:i) == "B")then
	t = t + 1
	endif
enddo

if(t == 0)then
	print 101,t
	stop
endif

allocate(a(t))

n = 1
do i = k,1,-1
	if(s(i:i) == "B")then
		a(n) = i
		n = n + 1
	endif
enddo

n = 0
do i = 1,t
	n  = n + k - (a(i)) -(i -1)
enddo

print 101,n
deallocate(a)

101 format(i0)
end program main

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

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

  int n; cin >> n;
  vector<int> a(n);
  int sum2 = 0;
  int res = 1e9;
  for(int i=0; i<n; i++) {
    cin >> a[i];
    sum2 += a[i];
  }

  int sum1 = 0;
  for(int i=0; i<n; i++) {
    sum1 += a[i];
    sum2 -= a[i];

    res = min(res, abs(sum1-sum2));
  }

  cout << res << endl;

  return 0;
}


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

int main(){
 
  int H,A;
  cin >> H >> A;
  
  if(H%A==0){
   cout << H/A << endl;
  }
  
  else if (H%A!=0){
   cout << H/A+1 << endl; 
  }
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<long long> vll;
typedef vector<pair<int, int>> vpi;
typedef vector<pair<long long, long long>> vpl;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
#define INF (int)(1e9)
#define MAXX 1.1529215e+18
#define inf 999999
#define EPS (1e-7)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i <= (int)(n); i++)
#define FOR(i, k, n) for (int i = (k); i < (int)(n); i++)
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.begin(), a.end(), greater<int>()
#define ROT(a) a.begin(), a.begin() + 1, a.end()
#define RROT(a) a.begin(), a.end() - 1, a.end()
#define PB push_back
#define MP make_pair
#define PI acos(-1.0)
#define sz(a) a.size()
const ll MOD = 1e9 + 7;
const int MAX = 10000000;
template <typename T1, typename T2>
inline bool chmin(T1& a, T2 b)
{
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T1, typename T2>
inline bool chmax(T1& a, T2 b)
{
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T>
T gcd(T a, T b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}
//cout << 'H' << endl;
/*--------------------------------------------*/

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

    int N, M;
    cin >> N >> M;
    ll X;
    cin >> X;

    vector<vector<ll>> a(N, vector<ll>(M, 0));
    vector<ll> c(N);
    rep(i, N)
    {
        cin >> c[i];
        rep(j, M)
        {
            cin >> a[i][j];
        }
    }


    ll ans = INF;
    for (ll bit = 0; bit < (1 << N); bit++) {
        ll tmp = 0;
        vector<ll> cost(M);
        for (int i = 0; i < N; ++i) {
            if (bit & (1 << i)) {  // 列挙に i が含まれるか
                tmp += c[i];
                rep(j, M)
                {
                    cost[j] += a[i][j];
                }
            }
        }

        bool flag = true;
        rep(j, M)
        {
            if (cost[j] < X) {
                flag = false;
            }
        }

        if (flag) {
            chmin(ans, tmp);
        }
    }
    if (ans == INF) {
        ans = -1;
    }

    cout << ans << endl;
}


Measured memory_bytes: 3660
use std::io;

fn read_line()  -> String {
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).expect("Couldn't read standard input");
    buf.trim().to_owned()
}

fn main() {
    let input: Vec<i32> = read_line()
        .split_whitespace()
        .map(|n| n.parse().unwrap())
        .collect();
    let (a, b, c, d) = (input[0], input[1], input[2], input[3]);
    if (a - c).abs() <= d || ((a - b).abs() <= d && (b - c).abs() <= d) {
        println!("Yes");
    } else {
        println!("No");
    }
}


Measured memory_bytes: 4352
import java.util.Scanner;

public class Main{
	public static void main(String args[]) {
		Scanner scn = new Scanner(System.in);
		int a2, delta = 0;
		int N = scn.nextInt(), M = scn.nextInt(), T = scn.nextInt(),a1 = scn.nextInt();
		for (int i = 0; i < N; i++) {
			a2 = i == N-1?T+M:scn.nextInt();
			delta += 2 * M > a2 - a1 ? 2 * M + a1 - a2 : 0;
			a1 = a2;
		}
		scn.close();
		System.out.println(T + delta - 2*M*N);
	}
}


Measured memory_bytes: 26380
import java.io.*;
import java.util.Arrays;

public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    
    int[] antenna = new int[5];
    for (int i = 0; i < 5; i++){
      antenna[i] = Integer.parseInt(br.readLine());
    }
    int k = Integer.parseInt(br.readLine());
    Arrays.sort(antenna);
    String result = "Yay!";
    if (antenna[4] - antenna[0] > k){
      result = ":(";
    }
    System.out.println(result);
  }
}


Measured memory_bytes: 22612
using System;
using System.Linq;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = int.Parse(Console.ReadLine());
            var output = "No";
            foreach (var a in Enumerable.Range(1, 9))
            {
                if (input % a == 0 && isInRange(input / a))
                {
                    output = "Yes";
                    break;
                }
            }
            Console.WriteLine(output);
        }

        private static bool isInRange(int num)
        {
            return num >= 1 && num <= 9;
        }
    }
}


Measured memory_bytes: 11220
import java.util.Scanner

import scala.annotation.tailrec

object Main extends App {
  val sc = new Scanner(System.in)
  val t = System.currentTimeMillis

  val n  = sc.nextInt
  val av = Seq.fill(n)(sc.nextInt)

  @tailrec
  def loop( vec: Seq[Int], target: Int = 1 ): Int = {
    val (_, fa) = vec.span(_ != target)
    (target, fa.isEmpty) match {
      case (1, true) => -1
      case (_, true) => target
      case _ => loop(fa.tail, target + 1 )
    }
  }

  val target = loop(av)
  val res = if(target == -1) -1 else n - target + 1

  println(res)

}

Measured memory_bytes: 79528
#include<stdio.h>

int main(void)
{
    int a,b,t,i;
    scanf("%d %d",&a,&b);
    t = 10*b;
    for(i = t ; i <= 100*a/8+10 ; i++)
    {
        if(8*i/100 == a && i /10 == b)
        {
            printf("%d\n",i);
            return 0;
        }
    }
    printf("-1");
    return 0;

}

Measured memory_bytes: 1736
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
# define mod 1000000007
/* ちゃんと考えてわかって実装 */

const int MAX_V = 50;
const int MAX_S = 50 * MAX_V + 5;
const ll INF = 1e18;

struct Edge{
    int to, a, b;
    // これを書いたらerrorが取れた。どうして必要なのｫぉ
    Edge(int to, int a, int b):to(to),a(a),b(b) {}
};

struct State{
    int v, s; // state = (頂点, 所持金)
    ll x; // その状態までの経過時間

    // これを書いたらerrorが取れた。どうして必要なのｫぉ
    State(int v, int s, ll x):v(v),s(s),x(x) {}

    bool operator<(const State& a) const {
        return x > a.x; // (x < a.x だとちゃんと動かねぇ)
    }
};

vector<Edge> g[MAX_V]; // 各頂点から伸びている辺の集合として保持。
ll min_time[MAX_V][MAX_S+5]; // 状態(v, s)までの最小の時間を記録。


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

    for(int i=0; i<m; i++){
        int u, v, a, b;
        cin >> u >> v >> a >> b;
        u--; v--;
        g[u].emplace_back(v, a, b);
        g[v].emplace_back(u, a, b);
    }

    for(int i=0; i<n; i++){
        for(int j=0; j<MAX_S+5; j++){
            min_time[i][j] = INF;
            // たどり着けない状態はINFのまま。
            // 以下では、たどり着ける状態についてその時間の最小値を探索する。
        }
    }

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

    s = min(s, MAX_S); // 十分な値で切り捨てる。
    priority_queue<State> pq;

    // pqに状態(v, s, x)を emplace するときに、
    // min_time[v][s]の値を x に更新する。(xが最小じゃないなら更新しない。)
    auto push = [&](int v, int s, ll x){
        if(s < 0) return;
        if(min_time[v][s] <= x) return;
        min_time[v][s] = x;
        pq.emplace(v, s, x);
    };

    // 初期状態は(0, s, 0)
    push(0, s, 0);
    while(!pq.empty()){
        State now = pq.top(); pq.pop();
        int v = now.v, s = now.s;
        ll x = now.x;

        // if(min_time[v][s] != x) continue; // なぜ?????(消しても通る)
        
        // 遷移その1 : 換金
        int next_s = min(s+c[v], MAX_S);
        push(v, next_s, x+d[v]);
        

        // 遷移その2 : 電車に乗る
        // そこから伸びている辺を全てみる
        for(Edge e : g[v]){
            push(e.to, s-e.a, x+e.b);
        }
    }

    // 答えの出力(min_timeのなかにある)
    for(int i=1; i<n; i++){
        ll ans = INF;
        for(int j=0; j<MAX_S+5; j++){
            ans = min(ans, min_time[i][j]);
        }
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 6140
//AUTHOR - NAVEEN KUMAR(@naveen19991124)
#include<bits/stdc++.h>
//#include<boost/multiprecision/cpp_int.hpp>
//#inlcude<boost/multiprecision/cpp_dec_float.hpp>
#define ll long long
#define pb push_back
#define f(a) for(ll i = 0;i<a;i++)
#define rep(i,a,b) for(ll i = a;i<b;i++)
#define rrep(i,a,b) for(ll i = a;i>b;i--)
#define v vector<ll>
#define mp make_pair
#define fir first
#define sec second
#define _fast_ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
//using boost :: multiprecision :: cpp_int;
//using boost :: multiprecision :: cpp_dec_float_50;
//using boost :: multiprecision :: cpp_dec_float_100;
ll power(ll a, ll n) {ll p = 1;while (n > 0) {if(n%2) {p = p * a;} n >>= 1; a *= a;} return p;}

ll power(ll a, ll n, ll mod) {ll p = 1;while (n > 0) {if(n%2) {p = p * a; p %= mod;} n >>= 1;
a *= a; a %= mod;} return p % mod;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a * (b / gcd(a, b)); }
int main()
{
    _fast_
    ll t = 1;
   // cin>>t;
    while(t--){
    ll n,a,b;
    cin>>n>>b>>a;
    ll ans ;
    ans = n/(a+b);
    ans = ans*b;
    ll val = n%(a+b);
    if(val>=b)
    {
        ans += b;
    }
    else
    {
        ans += val;
    }
    
    cout<<ans<<"\n";
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <string>
#include <map>
#include <stack>
#define ll long long
#define pii pair<int, int>
using namespace std;
int n,m;
int a1[200004],a2[200004];
int main()
{
    cin>>n>>m;int f=0;
    memset(a1,-1,sizeof(a1));
    for(int i=0;i<m;i++)
    {
        int x,y;
        cin>>x>>y;
        if(x==1 )
        {
            a1[y]=1;
        }
        else if(y == 1)
        {
            a1[x]=1;
        }
        else if (y==n)
        {
            a2[x]=1;
        }
        else if( x == n)
        {
            a2[y] = 1;
        }

    }
    for(int i = 2; i < n;i++){
        if(a1[i] == 1 && a2[i] == 1){
            cout<<"POSSIBLE" << endl;
            return 0;
        }
    }

  if(a2[1] || a1[n] == 1){
      cout<<"POSSIBLE" << endl;
            return 0;
       
  }
 cout<<"IMPOSSIBLE"<<endl;

    return 0;
}

Measured memory_bytes: 1792
'use strict'

const main = input => {
	const args = input.split('\n').map(arg => arg.split(' '))
	const N = parseInt(args[0][0], 10)
	const S = args[1][0]
	let prev = null
	let ans = 0

	for (let i = 0; i < N; i++) {
		if (prev !== S[i]) ans++
		prev = S[i]
	}

	console.log(ans)
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'))


Measured memory_bytes: 21064
q,h,s,d,n=map(int,open(0).read().split())
a=0
if d<min(s*2,h*4,q*8):
  a+=n//2*d
  n%=2
if s<min(h*2,q*4):
  a+=n*s
  n=0
if h<q*2:
  a+=n*2*h
  n=0
print(a+n*4*q)

Measured memory_bytes: 3064
int_list = list(map(int,input().split()))
tes = list(map(int,str(int_list[0])))
res = 0
for i  in range(1,int_list[0] + 1):
    tes = list(map(int,str(i)))
    
    if (sum(tes) >= int_list[1])&(sum(tes) <= int_list[2]):
        res += i
        
print(res)    

Measured memory_bytes: 74612
#include <iostream>
#include <vector>
#include <queue>
using namespace std;

#define INF (1 << 30)

struct Vertex {
    vector<pair<int, int> > link;
    int distance;
};

class Tree {
private:
    int n;
    vector<Vertex> graph;

public:
    Tree() {}

    Tree(int n)
    {
        this->n = n;
        graph.resize(n);
        int s, t, w;
        for (int e = 0; e < n - 1; e++)
        {
            cin >> s >> t >> w;
            graph[s].link.push_back(make_pair(t, w));
            graph[t].link.push_back(make_pair(s, w));
        }
    }

    void bfs(int root)
    {
        for(int i = 0; i < n; i++)
            graph[i].distance = INF;
        queue<int> Q;
        Q.push(root);
        graph[root].distance = 0;

        while(!Q.empty())
        {
            int u = Q.front();
            Q.pop();

            for(auto adj : graph[u].link)
            {
                int v = adj.first;
                if(graph[v].distance == INF)
                {
                    graph[v].distance = graph[u].distance + adj.second;
                    Q.push(v);
                }
            }
        }
    }

    void solve()
    {
        bfs(0);

        int tgt = 0;
        int max_d = 0;
        int dist_i;
        for(int i = 0 ; i < n; i++)
        {
            dist_i = graph[i].distance;
            if(dist_i == INF)
                continue;
            if(max_d < dist_i)
            {
                max_d = dist_i;
                tgt = i;
            }
        }

        max_d = 0;
        bfs(tgt);
        for(int i = 0 ; i < n; i++)
        {
            dist_i = graph[i].distance;
            if(dist_i == INF)
                continue;
            max_d = max(max_d, dist_i);
        }

        cout << max_d << endl;
    }
};

int main()
{
    int n;
    cin >> n;
    Tree tree(n);
    tree.solve();
}



Measured memory_bytes: 10080
#include <cstdio>

int vls[9];
int main() {
	for(int i=0;i<3;i++) {
		int A,B;
		scanf("%d%d",&A,&B);
		vls[A]++;
		vls[B]++;
		if(vls[A]==3) {
			printf("NO\n");
			return 0;
		}
		if(vls[B]==3) {
			printf("NO\n");
			return 0;
		}
	}
	printf("YES\n");
	return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cassert>
#include<cmath>
#define y1 DEEP_DARK_FANTASY
#define y2 VAN_YOU_SEE
#define ll long long
const double pi=acos(-1.0);
using namespace std;
inline ll read(){
	ll re=0,flag=1;char ch=getchar();
	while(!isdigit(ch)){
		if(ch=='-') flag=-1;
		ch=getchar();
	}
	while(isdigit(ch)) re=(re<<1)+(re<<3)+ch-'0',ch=getchar();
	return re*flag;
}
ll x1,x2,y1,y2,n,x[200010],y[200010],rk[200010],dp[200010];
inline bool cmp(ll l,ll r){
	if(x[l]!=x[r]) return x[l]<x[r];
	else return y[l]<y[r];
}
int main(){
//	freopen("in.in","r",stdin);
	x1=read();y1=read();x2=read();y2=read();n=read();
	ll i,j,t1,t2;
	for(i=1;i<=n;i++) x[i]=read(),y[i]=read(),rk[i]=i,dp[i]=1e9;
	if(x1>x2){
		swap(x1,x2);swap(y1,y2);
	}
	if(y1>y2){
		y1=1e8-y1;
		y2=1e8-y2;
		for(i=1;i<=n;i++) y[i]=1e8-y[i];
	}
	x[++n]=x1;
	y[n]=y1;rk[n]=n;dp[n]=1e9;
	x[++n]=x2;
	y[n]=y2;rk[n]=n;dp[n]=1e9;
	sort(rk+1,rk+n+1,cmp);
	t1=1;t2=1;
	while(x[rk[t1]]!=x1||y[rk[t1]]!=y1) t1++;
	while(x[rk[t2]]!=x2||y[rk[t2]]!=y2) t2++;
	dp[1]=y[rk[t1]];dp[0]=-1;
//	for(i=1;i<=n;i++) cout<<i<<' '<<rk[i]<<' '<<x[rk[i]]<<' '<<y[rk[i]]<<'\n';
	ll pos;
	for(i=t1+1;i<t2;i++){
//		cout<<i<<' '<<y[rk[i]]<<' '<<y[rk[t1]]<<' '<<y[rk[t2]]<<'\n';
		if(y[rk[i]]<y[rk[t1]]||y[rk[i]]>y[rk[t2]]) continue; 
		pos=upper_bound(dp,dp+n+1,y[rk[i]])-dp;
//		cout<<i<<' '<<pos<<'\n';
		dp[pos]=y[rk[i]];
	}
	ll len=upper_bound(dp,dp+n+1,y[rk[i]])-dp-2;
	double ans=100.0*(y2-y1+x2-x1);
	ans+=(pi-4.0)*5.0*len;
//	cout<<"check "<<len<<' '<<dp[len]<<' '<<t1<<' '<<t2<<'\n';
	if(len==(min(y2-y1,x2-x1)+1ll)) ans+=pi*5.0;
	printf("%.12lf\n",ans);
}
/*
0 1 1 0
1
0 0

*/

Measured memory_bytes: 6528
package main

import "fmt"

// 全探索
// https://onlinejudge.u-aizu.ac.jp/problems/ALDS1_5_A

var n int
var a [50]int

func solve(i, m int) bool{
	if m == 0 {return true}
	if i >= n {return false}
	return solve(i + 1, m) || solve(i + 1,  m - a[i])
}

func main() {
	//var n int
	fmt.Scan(&n)
	// a := make([]int,n)
	for i := 0; i < n; i++ {
		fmt.Scan(&a[i])
	}

	var q int
	fmt.Scan(&q)
	for i := 0; i < q; i++ {
		var m int
		fmt.Scan(&m)
		if solve(0, m) {
			fmt.Println("yes")
		} else {
			fmt.Println("no")
		}
	}
}



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

#include <math.h>
#include <stdlib.h>


#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;

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

//INT_MAX	2,147,483,647 = 2*1.0e9

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    string S, T;
    cin >> S >> T;

    string T2 = T + T;

    for(int i = 0; i < S.length();i++){
        bool ans = true;
        for(int j = 0; j < S.length(); j++){
            if(S[j] != T2[i+j]){
                ans = false;
                continue;
            } 
        }
        if(ans){
            cout << "Yes" << endl;
            return 0;
        }
    }

    cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
import java.io.*;
import java.math.*;
import java.util.*;

class MyScanner {
    private final InputStream in = System.in;
    private final byte[] buf = new byte[1024];
    private int p = 0;
    private int len = 0;
    private boolean hasNextByte() {
        if (p >= len) {
            p = 0;
            try {
                len = in.read(buf);
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return len >= 1;
    }
    private boolean isPrintableChar(int c) { return 33 <= c && c <= 126; }
    public boolean hasNext() {
        while (hasNextByte() && !isPrintableChar(buf[p])) p++;
        return hasNextByte();
    }
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        while (hasNextByte() && isPrintableChar(buf[p])) sb.appendCodePoint(buf[p++]);
        return sb.toString();
    }
    public BigDecimal nextBigDecimal() { return new BigDecimal(next()); }
    public BigInteger nextBigInteger() { return new BigInteger(next()); }
    public BigInteger nextBigInteger(int radix) { return new BigInteger(next(), radix); }
    public double nextDouble() { return Double.parseDouble(next()); }
    public int nextInt() { return Integer.parseInt(next()); }
    public int nextInt(int radix) { return Integer.parseInt(next(), radix); }
    public long nextLong() { return Long.parseLong(next()); }
    public long nextLong(int radix) { return Long.parseLong(next(), radix); }
}

public class Main {
    public static void main(String[] args){
        MyScanner sc = new MyScanner();
        PrintWriter out = new PrintWriter(System.out);
        int n = sc.nextInt();
        long k = sc.nextLong();
        Integer[][] a = new Integer[62][n + 1];
        int t = 1;
        for (int i = 1; i <= n; i++) a[0][i] = sc.nextInt();
        for (int i = 0; i < 61; i++) {
            for (int j = 1; j <= n; j++) {
                a[i + 1][j] = a[i][a[i][j]];
            }
            if ((k >> i & 1) == 1) t = a[i][t];
        }
        out.println(t);
        out.flush();
    }
}

Measured memory_bytes: 104500
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pairSS
#define int long long
#define MOD 1000000007
int gcd(int a,int b){
  if(a==0){
    return b;
  }
  return gcd(b%a,a);
}
int lcm(int a,int b){
  return a*b/gcd(a,b);
}
int keta(int a){
  int count = 0;
  while(a!=0){
    a = a/10;
    count++;
  }
  return count;
}
signed main(){
  int k,x;
  cin >> k >> x;
  for(int i=x-k+1;i<k+x;i++){
    if(i==k+x-1){
      cout << i << endl;
      break;
    }
    cout << i << " ";
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,s,e) for(int i=(s); i<(e);i++)
#define rep(i,n) REP(i,0,n)
#define rep1(i,n) REP(i,1,n)
#define repe(i,n) for(auto &&i:n)
#define all(v) (v).begin(),(v).end()
#define decimal fixed<<setprecision(20)
#define fastcin() cin.tie(0);ios::sync_with_stdio(false)
using namespace std;
using LL = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = 1e9;
const LL LLINF = 1e16;

int main(){
    int a, b;
    cin >> a >> b;
    cout << max({a+b, a-b, a*b}) << endl;
}

Measured memory_bytes: 256
//Utkarsh.25dec
#include <bits/stdc++.h>
#define ll long long int 
#define ull unsigned long long int
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define rep(i,n) for(ll i=0;i<n;i++)
#define loop(i,a,b) for(ll i=a;i<=b;i++)
#define vi vector <int>
#define vs vector <string>
#define vc vector <char>
#define vl vector <ll>
#define all(c) (c).begin(),(c).end()
#define max3(a,b,c) max(max(a,b),c)
#define min3(a,b,c) min(min(a,b),c)
using namespace std;
const int N=500023;
bool vis[N];
vector <int> adj[N];
void solve()
{
    ll n, k;
    cin>>n>>k;
    vl v;
    rep(i,n)
    {
        ll c;
        cin>>c;
        v.pb(c);
    }
    ll dp[n+2]={0};
    dp[0]=0;
    dp[1]=abs(v[0]-v[1]);
    for(int i=2;i<n;i++)
    {
        ll temp=LONG_MAX;
        for(int j=i-k; j<i;j++){
            if(j<0)
                continue;
            ll temp1=dp[j]+abs(v[j]-v[i]);
            temp=min(temp1,temp);
        }
        dp[i]=temp;
    }
    // for(int i=0;i<n;i++)
    //     cout<<dp[i]<<'\n';
    cout<<dp[n-1]<<'\n';
}
int main()
{
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
    int T=1;
    // cin>>T;
    int t=0;
    while(t++<T)
    {
        //cout<<"Case #"<<t<<":"<<' ';
        solve();
        //cout<<'\n';
    }
}

Measured memory_bytes: 13684
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N; cin >> N;
  long long ans=1;
  for (int i=0; i<N; i++) {
    long long T; cin >> T;
    ans = ans/__gcd(ans,T)*T;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
n=int(input())
flg=True
se=set()
for i in range(n):
  s=input()
  if s in se:
    flg=False
  se.add(s)
  if not i:
    f,b=s[0],s[-1]
  else:
    if s[0]!=b:
      flg=False
    f,b=s[0],s[-1]
if flg:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 3064
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<vector>
#include<cmath>
#include<complex>
#include<utility>
using namespace std;
#define REP(i,b,n) for(int i=b;i<n;i++)
#define rep(i,n)   REP(i,0,n)
#define ALL(C)     (C).begin(),(C).end()
#define mp         make_pair
#define pb         push_back
#define fir first
#define sec second

const int N = 10010;

typedef pair<short,short> pii;

short  isexist[N]={0};
short testcase=0;
int x[N];
vector<pii> inx[N];

int req[N];

void makedata(int n,int *x1,int *x2,int *y1,int *y2,
	      int &px,int *xd,vector<pii> *IN){
  testcase++;
  rep(i,n){
    isexist[x1[i]]=testcase;
    isexist[x2[i]]=testcase;
  }
  rep(i,N)if (isexist[i]==testcase)x[px]=i,IN[px++].clear();

  rep(i,n){
    int j=lower_bound(xd,xd+px,x1[i])-xd;
    while(j < px && xd[j] < x2[i]){
      bool isin=false;
      rep(k,IN[j].size()){
	short Y1 = y1[i],Y2=y2[i];
	short &Y3=IN[j][k].fir;
	short &Y4=IN[j][k].sec;
	if (Y4 <= Y1 || Y2 <= Y3)continue;
	isin=true;
	Y3=min(Y1,Y3);
	Y4=max(Y2,Y4);
	break;
      }
      if (!isin)IN[j].pb(mp(y1[i],y2[i]));
      j++;
    }
  }
}

pair<int,int> solve(int n,vector<pii> *in,int *c){
  int area=0;
  int len=0;
  rep(i,n-1){
    sort(in[i].begin(),in[i].end());
    short l=-1,h=-1;
    short width;
    width=c[i+1]-c[i];
    rep(j,in[i].size()){
      short &nowl=in[i][j].fir,&nowh=in[i][j].sec;
      if (nowl > h){
	len+=2*width;
	area+=(nowh-nowl)*width;
      }else if (nowl == h){
	area+=(nowh-nowl)*width;
      }else if (nowh > h){
	area+=(nowh-h)*width;
      }
      l=nowl;
      h=max(h,nowh);
    }
  }
  return mp(area,len);
}

main(){
  int n,q;
  static int x1[N],y1[N],x2[N],y2[N];
  while(cin>>n>>q && n){
    rep(i,n){
      cin>>x1[i]>>y1[i]>>x2[i]>>y2[i];
    }
    int px=0,py=0;
    makedata(n,x1,x2,y1,y2,px,x,inx);
    pair<int,int> ansx=solve(px,inx,x);

    cout << ansx.first << endl;
    if (q == 2){
      px=0;
      makedata(n,y1,y2,x1,x2,px,x,inx);
      pair<int,int> ansy= solve(px,inx,x);      
      cout << ansx.second+ansy.second << endl;
    }
    rep(i,px)inx[i].clear();
  }
  return false;
}

Measured memory_bytes: 1476
#include <stdio.h>
#include <math.h>
#define N 100010
int main()
{
    int n, m, x, c[15], a[15][15], ans = -1;

    scanf("%d %d %d", &n, &m, &x);
    for (int i = 0; i < n; i++)
    {
        scanf("%d", &c[i]);
        for (int j = 0; j < m; j++)
            scanf("%d", &a[i][j]);
    }

    for (int i = 0; i < pow(2, n); i++)
    {
        int total = 0, check[15] = {0}, k = i, flag = 1;
        for (int j = 0; j < n; j++)
        {
            for (int l = 0; l < m; l++)
                check[l] += a[j][l] * (k % 2);

            total += c[j] * (k % 2);
            k /= 2;
        }

        for (int l = 0; l < m; l++)
        {
            // printf("%d ", check[l]);
            if (check[l] < x)
                flag = 0;
        }
        // printf("\n");

        if (flag && (ans > total || ans == -1))
            ans = total;
        // printf("%d", i);
    }

    printf("%d", ans);

    // for (int i = 0; i < n; i++)
    // {
    //     printf("%d", c[i]);
    //     for (int j = 0; j < m; j++)
    //         printf("%d", a[i][j]);

    //     printf("\n");
    // }

    return 0;
}

Measured memory_bytes: 2600
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

typedef long long ll;
typedef uint64_t ull;
typedef pair<int, int> P;
constexpr double PI = 3.1415926535897932;   // acos(-1)
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)

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

    int n;
    cin >> n;
    vector<int> a(n);
    vector<int> pre(n);
    map<int, int> mp;
    for(int i = 0; i < n; ++i){
        cin >> a[i];
        ++mp[i - a[i]];
        pre[i] = i - a[i];
    }
    ll ans = 0;
    for(int i = 0; i + 1 < n; ++i){
        --mp[pre[i]];
        ans += mp[a[i] + i];
    }

    cout << ans << endl;
}

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

using namespace std;

long long maxi,n,W,i,P,j,gr,p[101],w[101],d[101][100010];

int main()
{
    cin>>n>>W;
    for(i=1; i<=n; i++)
    {
        cin>>w[i]>>p[i];
        P+=p[i];
    }


    for(i=1;i<=n;i++)
        for(j=1;j<=P;j++)
        d[i][j]=INT_MAX/2;

    d[1][p[1]]=w[1];

    for(i=2; i<=n; i++)
    {
        for(j=0; j<=P; j++)
        {


            d[i][j]=d[i-1][j];
            if(j-p[i]>=0)d[i][j]=min(d[i][j],d[i-1][j-p[i]]+w[i]);

        }
    }

    for(i=P; i>=1; i--)
        if(d[n][i]<=W)
        {
            cout<<i;
            return 0;
        }
    return 0;
}


Measured memory_bytes: 78336
#include <stdio.h>
#include <stdlib.h>
#include <memory.h>

int get_uint() {
    int n = 0;
    int c = getchar_unlocked();
    if(c < 48 || 57 < c) return c;
    while(47 < c && c < 58) {
        n = 10 * n + (c & 0xf);
        c = getchar_unlocked();
    }
    return n;
}
long long merge_sort(int *first, int *last) {
    const int N = (int)(last - first);
    if(N < 2) return 0;
    int *mid = first + N / 2;
    const int N1 = (int)(mid - first);
    const int N2 = (int)(last - mid);
    int *left = malloc(sizeof(int) * (N1 + 1));
    int *right = malloc(sizeof(int) * (N2 + 1));
    memcpy(left, first, sizeof(int) * (N1 + 1));
    memcpy(right, mid, sizeof(int) * (N2 + 1));
    left[N1] = right[N2] = 1 << 30;

    long long cnt = 0;
    cnt += merge_sort(left, left + N1);
    cnt += merge_sort(right, right + N2);

    for(int *it = first, i = 0, j = 0; it != last; ++it) {
        if(left[i] <= right[j]) *it = left[i++];
        else *it = right[j++], cnt += N / 2 - i;
    }
    return cnt;
}
int main(int argc, char **argv) {
    int n = get_uint();
    int a[200001];
    for(int i = 0; i < n; ++i) a[i] = get_uint();
    printf("%lld\n", merge_sort(a, a + n));
    return 0;
}



Measured memory_bytes: 25948
A,B = map(int,input().split())

d = {}
for i in range(50):
    d[i] = ["."]*100
for i in range(50,100):
    d[i] = ["#"]*100
a = 1
b = 1

for i in range(10):
    if a == B:
        break
    for j in range(50):
        if a == B:
            break
        else:
            d[i*2][j*2] = "#"
            a += 1
    
        
        
for i in range(10):
    if b == A:
        break
    for j in range(50):
        if b == A:
            break
        else:
            d[i*2+51][j*2] = "."
            b += 1
    

print("100 100")
def l_to_str(l):
    s = ""
    for x in l:
        s+=x
    return s
for i in range(100):
    print(l_to_str(d[i]))

Measured memory_bytes: 3316
#include<algorithm>
#include<iostream>
#include<stdio.h>
#include<string.h>

int a, b, c, d, e;
int cnt[13];

int main()
{
	while( scanf( "%d,%d,%d,%d,%d", &a, &b, &c, &d, &e ) != EOF )
	{
		memset( cnt, 0, sizeof( cnt ) );
		cnt[a-1]++, cnt[b-1]++, cnt[c-1]++, cnt[d-1]++, cnt[e-1]++;

		if( std::find( cnt, cnt + 13, 4 ) != cnt + 13 )
			std::cout << "four card" << std::endl;
		else if( std::find( cnt, cnt + 13, 3 ) != cnt + 13 && std::find( cnt, cnt + 13, 2 ) != cnt + 13 )
			std::cout << "full house" << std::endl;
		else if( std::find( cnt, cnt + 13, 3 ) != cnt + 13 )
			std::cout << "three card" << std::endl;
		else if( std::count( cnt, cnt + 13, 2 ) == 2 )
			std::cout << "two pair" << std::endl;
		else if( std::count( cnt, cnt + 13, 2 ) == 1 )
			std::cout << "one pair" << std::endl;
		else
		{
			bool f = false;

			for( int i = 0; i < 10; i++ )
			{
				if( cnt[i] && cnt[i+1] && cnt[i+2] && cnt[i+3] && cnt[(i+4)%13] )
				{
					std::cout << "straight" << std::endl;
					f = true;
				}
			}
					
			if( !f )
				std::cout << "null" << std::endl;
	 	}
	}

	return 0;
}

Measured memory_bytes: 1204
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
#include <map>
#include <set>

using namespace std;

int main() {
    int A[3][3];
    for (int i = 0; i < 3; i++) {
        for (int j = 0; j < 3; j++)
            cin >> A[i][j];
    }

    int n;  cin >> n;
    int *b = new int[n];
    for (int i = 0; i < n; i++)
        cin >> b[i];

    sort(b, b+n);


    bool c[3][3] = {false};

    for (int i = 0; i < 3; i++) {
        for (int j = 0; j < 3; j++) {
            if (binary_search(b, b+n, A[i][j]))
                c[i][j] = true;
        }
    }

    bool can = false;
    for (int i = 0; i < 3; i++) {
        if (c[i][1] && c[i][0] && c[i][2])
            can = true;
    }

    for (int i = 0; i < 3; i++) {
        if (c[0][i] && c[1][i] && c[2][i])
            can = true;
    }

    if (c[0][0] && c[1][1] && c[2][2])
        can = true;

    if (c[0][2] && c[1][1] && c[2][0])
        can = true;

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

    return 0;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define chmin(a, b) ((a)=min((a), (b)))
#define chmax(a, b) ((a)=max((a), (b)))
#define fs first
#define sc second
#define eb emplace_back
using namespace std;

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

const ll MOD=1e9+7;
const ll INF=1e18;

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

int main(){
    int n; cin>>n;
    vector<P> point(n);

    for(int i=0; i<n; i++) point[i].sc=i;

    for(int i=0; i<n*(n-1)/2; i++){
        int a, b, ap, bp; cin>>a>>b>>ap>>bp;
        a--, b--;
        if(ap>bp){
            point[a].fs+=3;
        }
        else if(ap<bp){
            point[b].fs+=3;
        }
        else{
            point[a].fs++;
            point[b].fs++;
        }
    }

    sort(point.begin(), point.end(), greater<P>());

    vector<int> ans(n);
    ans[point[0].sc]=1;
    for(int i=1; i<n; i++){
        if(point[i].fs==point[i-1].fs){
            ans[point[i].sc]=ans[point[i-1].sc];
        }
        else{
            ans[point[i].sc]=i+1;
        }
    }

    for(int i=0; i<n; i++){
        cout << ans[i] << endl;
    }
}


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

#define PI 3.1415926535897932
#define MOD 1000000007
#define INF 1e9

#define REP(i, n) for(int i = 0; i < (n); i++)
#define REP1(i, n) for(int i = 1; i <= (n); i++)
#define FOR(i, start, end) for(int i = (start); i < (end); i++)
#define ALL(v) (v).begin(), (v).end()

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef vector<bool> vb;


void solve()
{
    int A, B; cin >> A >> B;
    if(A*B % 2 == 1) cout << "Yes" << endl;
    else cout << "No" << endl;
}

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

    solve();

    return 0;
}

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

#define ull unsigned long long
#define ul unsigned long
#define ll long long
#define size_t unsigned long long

using namespace std;

ll modular_pow(ll base, ll exponent, int modulus)
{
    ll result = 1;
    while (exponent > 0)
    {
        if (exponent % 2 == 1)
            result = (result * base) % modulus;
        exponent = exponent >> 1;
        base = (base * base) % modulus;
    }
    return result;
}

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

  int H,W,A,B;
  std::cin >> H >> W >> A >> B;

  ll mod = pow(10,9) + 7;
  ll ans = 0;

  ll cnt = 200001;
  vector<ll> fact(cnt,0);
  vector<ll> rfact(cnt, 0);
  fact[0] = 1;
  for (size_t i = 1; i < cnt; i++) {
    fact[i] = (i * fact[i-1]) % mod;
  }

  rfact[cnt - 1] = modular_pow(fact[cnt-1],mod-2,mod);
  for (size_t i = cnt - 2; i > 0; i--) {
    rfact[i] = (rfact[i+1] * (i+1)) % mod;
  }
  rfact[0] = 1;

  for (size_t i = B; i < W; i++) {
    ans = (ans + ((((fact[H-A-1+i] * rfact[H-A-1]) % mod) * rfact[i]) % mod ) * ((((fact[A-1+W-1-i] * rfact[A-1]) % mod) * rfact[W-1-i]) % mod)) % mod;
  }

  std::cout << ans << '\n';

  return 0;
}


Measured memory_bytes: 3456
#include<iostream>
#include<string>

using namespace std;

int main()
{
	int n,m;
	int i,j;
	char ch[100];
	string str;
	
	for(;;)
	{
		cin >> m >> n  ;
		if(n==0 && m==0)
			break;
		
		int ans[1024]={0};
		for(i=0;i<m;i++)
			ans[i]=i+1;
		
		j=0;
		int flag=m;
		for(i=1;i<=n;i++)
		{
			cin >> str ;
			
			sprintf(ch,"%d",i);
			if(flag>1)
			{
				if(i%3==0 && i%5==0)
				{
					if(str!="FizzBuzz")
					{
						ans[j]=0;
						flag--;
					}
				}
				else if(i%3==0)
				{
					if(str!="Fizz")
					{
						ans[j]=0;
						flag--;
					}
				}
				else if(i%5==0)
				{
					if(str!="Buzz")
					{
						ans[j]=0;
						flag--;
					}
				}
				else
				{
					if(str!=ch)
					{
						ans[j]=0;
						flag--;
					}
				}
				j++;
				int c;
				for(c=j;ans[c]==0;)
				{
					c++;
					if(c>m-1)
						c=0;
				}
				j=c;
			}
		}
		int las;
		for(i=0;i<m;i++)
			if(ans[i]!=0)
				las=i;
		
		for(i=0;i<m;i++)
		{
			if(ans[i]!=0)
			{
				cout << ans[i] ;
				if(i<las)
					cout << " " ;
			}
		}
		cout << endl;
	}
}

Measured memory_bytes: 964