akhauriyash/Code-Regression huggingface dataset:
package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
    sc.Split(bufio.ScanWords)
    a, b := nextInt(), nextInt()

    ans := -1
    for i := 1; i <= 1009; i++ {
        za := i * 8 / 100;
        zb := i * 10 / 100;
        if za == a && zb == b{
            ans = i
            break
        }
    }

    fmt.Println(ans)
}




//===========================
//
// Library
//
//===========================

func max(a, b int) int {
    if a > b {
        return a
    }
    return b
}

func min(a, b int) int {
    if a < b {
        return a
    }
    return b
}

func gcd(x, y int) int {
    if y == 0 {
        return x
    }

    return gcd(y, x%y)
}

//====================
//  var q Queue
//  q.Enqueue(n)
//  n := q.Dequeue()
//====================
type Queue struct {
    data []int
}

func (q *Queue) Enqueue(n int) {
    q.data = append(q.data, n)
}

func (q *Queue) Dequeue() int {
    tmp := q.data[0]
    q.data = q.data[1:]
    return tmp
}

func nextLine() string {
    sc.Scan()
    return sc.Text()
}

func nextInt() int {
    sc.Scan()
    i, _ := strconv.Atoi(sc.Text())
    return i
}

func nextIntArr(n int) []int {
    var a []int
    for i := 0; i < n; i++ {
        a = append(a, nextInt())
    }
    return a
}

// 数値を桁区切りのスライスにする
func digit(n int, list []int) []int {
   if n > 0 {
       return digit(n/10, append(list, n%10))
   }
   return list
}

func sortIntsRev(list []int) {
    sort.Sort(sort.Reverse(sort.IntSlice(list)))
}

func strReverse(s string) string {
    runes := []rune(s)
    for i := 0; i < len(s)/2; i++ {
        runes[i], runes[len(s)-1-i] = runes[len(s)-1-i], runes[i]
    }
    return string(runes)
}



Measured memory_bytes: 640
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
const double PI = acos(-1);
const double EPS = 1e-9;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }
int len = 500000;
vector<int>L(len / 2), R(len / 2);
int cnt(0);
void merge(vector<int>&a, int l, int r) {
	int mid = (l + r) / 2;
	int n1 = (mid - l), n2 = (r - mid);
	rep(i, 0, n1)L[i] = a[l + i];
	L[n1] = INF;
	rep(i, 0, n2)R[i] = a[mid + i];
	R[n2] = INF;
	int i(0), j(0);
	rep(k, l, r) {
		cnt++;
		if (L[i] < R[j])a[k] = L[i++];
		else a[k] = R[j++];
	}
}
void mergesort(vector<int>&a, int l, int r) {
	if (r - l > 1) {
		int mid = (l + r) / 2;
		mergesort(a, l, mid);
		mergesort(a, mid, r);
		merge(a, l, r);
	}
}
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N; cin >> N;
	vector<int> v(N); rep(i, 0, N) { cin >> v[i]; }
	mergesort(v, 0, N);
	rep(i, 0, N)cout << v[i] << (i == N - 1 ? '\n' : ' ');
	cout << cnt << endl;
	return 0;
}

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

int main() {
    int h, w, k; cin >> h >> w >> k; char grid[h][w]; int ans = 0;
    for (int i = 0; i < h; i ++) for (int j = 0; j < w; j ++) cin >> grid[i][j];
    for (int i = 0; i < (1<<h); i ++) {
        for (int j = 0; j < (1<<w); j ++) {
            char newgrid[h][w]; for (int a = 0; a < h; a ++) for (int b = 0; b < w; b ++) newgrid[a][b] = grid[a][b];
            for (int a = 0; a < h; a ++) {
                if ((1<<a)&i) for (int b = 0; b < w; b ++) newgrid[a][b] = '?';
            } for (int a = 0; a < w; a ++) {
                if ((1<<a)&j) for (int b = 0; b < h; b ++) newgrid[b][a] = '?';
            } int cnt = 0; for (int a = 0; a < h; a ++) for (int b = 0; b < w; b ++) if (newgrid[a][b] == '#') cnt++;
            if (cnt == k) ans++;
        }
    } cout << ans << endl;
}

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

int main(int argc, char const *argv[])
{
	int n;
	cin>>n;
	int a[n];
	for (int i = 0; i < n; ++i)
	{
		cin>>a[i];
	}
	double ans=.0;
	for (int i = 0; i < n; ++i)
	{
		ans+=(double)1.0/a[i];
	}
	printf("%.6f\n", 1.0/ans);
	return 0;
}


Measured memory_bytes: 256
c = Array.new(3)
c[0] = gets.split(/\s+/).map(&:to_i)
c[1] = gets.split(/\s+/).map(&:to_i)
c[2] = gets.split(/\s+/).map(&:to_i)

bd = Array.new(3)
ad = Array.new(3)

result = true

(0...3).each do |j|
  d1 = c[0][j] - c[0][(j + 1) % 3] 
  d2 = c[1][j] - c[1][(j + 1) % 3]
  d3 = c[2][j] - c[2][(j + 1) % 3]
  if d1 == d2 && d2 == d3
    bd[j] = d1
  else
    result = false
  end
end

(0...3).each do |i|
  d1 = c[i][0] - c[(i + 1) % 3][0]
  d2 = c[i][1] - c[(i + 1) % 3][1]
  d3 = c[i][2] - c[(i + 1) % 3][2]
  if d1 == d2 && d2 == d3
    ad[i] = d1
  else
    result = false
  end
end

if result
  if bd[0] + bd[1] + bd[2] == 0 && ad[0] + ad[1] + ad[2] == 0
    puts("Yes")
  else
    puts("No")
  end
else
  puts("No")
end

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

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

using namespace std;

int main(){
  int n;
  string s;
  cin>>n;
  cin>>s;
  
  rep(i,s.size()){
    cout<<(char)((((s.at(i)-'A'+n))%26)+'A');
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define test() ull t;cin>>t;while(t--)
#define pb push_back
#define mkp make_pair
#define nl cout<<endl
#define MOD 1000000007
#define loop(i,start,end) for(ull i=start;i<end;i++)
#define N 100001
#define all(v) v.begin(),v.end()
#define oa(a,n) for(int i=0;i<n;i++)cout<<a[i]<<" ";nl
#define ov(a) for(int i=0;i<a.size();i++)cout<<a[i]<<" ";nl
int main() 
{
    fastio();

  ll n,k;cin>>n>>k;
  vector<ll>v(n),dp(n+1,0);
  loop(i,0,n)cin>>v[i];

  for(int i = 1;i<n;i++)
  {
    dp[i] = dp[i-1]+abs(v[i]-v[i-1]);
    for(int j = 2;i>=j && j<=k;j++)
      dp[i] =min(dp[i],dp[i-j]+abs(v[i]-v[i-j]));
  }
  cout<<dp[n-1];


  return 0;
}

Measured memory_bytes: 1792
import java.util.*;

class Main{

    public static void main(String[] args){

	Scanner sc = new Scanner(System.in);

	int N = sc.nextInt();

	int K = sc.nextInt();

	int Q = sc.nextInt();

	int[] A = new int[Q];

	int[] M = new int[N];

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

	A[i] = sc.nextInt();	

  }
  
	for(int i=0; i<N; i++){
		
	M[i] = K-Q;
	
	}
	
	for(int i=0; i<Q; i++){

	M[A[i]-1]++; 

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

	if(M[i]>0){

	System.out.println("Yes");

   }

	else{

	System.out.println("No");

   }

  }

 }
}


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

#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vd = vector<double>;
using vs = vector<string>;

typedef tree<
ll,
null_type,
less<ll>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
// ordered_set X;
// *X.find_by_order(i) = ith largest element (counting from zero)
// X.order_of_key(k) = number of items in X < k (strict lt)

ll nsum(ll n) {
    return (n*(n+1))/2;
}

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

    vll A(N);
    for (int i=0;i<N;i++) cin >> A[i];

    ll ns = nsum(N);
    ll total = 0;
    for (ll a : A) total += a;

    if (total % ns != 0) {
        cout << "NO" << endl;
        return 0;
    }

    ll M = total / ns;

    vll diffs(N);
    diffs[0] = A[0] - A[N-1];
    for (int i=1;i<N;i++) {
        diffs[i] = A[i] - A[i-1];
    }

    for (int i=0;i<N;i++) {
        if ((M-diffs[i]) % N != 0 || (M - diffs[i]) < 0) {
            cout << "NO" << endl;
            return 0;
        } 
    }

    cout << "YES" << endl;
}


Measured memory_bytes: 1920
#include <stdio.h>
#include <string>
#include <vector>
#include <array>
#include <memory>
#include <iostream>
#include <algorithm>

using namespace std;
int memo[5][5][5][5][2];//最後が０なら磯野から
bool GetAns(vector<int> b) {
	if (b[0] >= 5) { b[0] = 0; }
	if (b[1] >= 5) { b[1] = 0; }
	if (b[2] >= 5) { b[2] = 0; }
	if (b[3] >= 5) { b[3] = 0; }
	if (b[0] == 0 && b[1] == 0)return false;
	else if (b[2] == 0 && b[3] == 0)return true;
	
		bool ans;
		if (b[4] == 0) {
			ans = false;
			if (b[0] != 0) {
				vector<int> c;
				for (int i = 0; i < 5; ++i) {
					c.push_back( b[i]);
				}
				c[4] = 1 - b[4];
				if (c[2] != 0) {
					c[2] += c[0];
					ans = ans || GetAns(c);
				}
				c.clear();
				for (int i = 0; i < 5; ++i) {
					c.push_back(b[i]);
				}
				c[4] = 1 - b[4];
				if (c[3] != 0) {
					c[3] += c[0];
					ans = ans || GetAns(c);
				}
			}
			if (b[1] != 0) {
				vector<int> c;
				for (int i = 0; i < 5; ++i) {
					c.push_back(b[i]);
				}
				c[4] = 1 - b[4];
				if (c[2] != 0) {
					c[2] += c[1];
					ans = ans || GetAns(c);
				}
				c.clear();
				for (int i = 0; i < 5; ++i) {
					c.push_back(b[i]);
				}
				c[4] = 1 - b[4];
				if (c[3] != 0) {
					c[3] += c[1];
					ans = ans || GetAns(c);
				}
			}
		}
		else {
			ans = true;
			if (b[2] != 0) {
				vector<int> c;
				for (int i = 0; i < 5; ++i) {
					c.push_back(b[i]);
				}
				c[4] = 1 - b[4];
				if (c[0] != 0) {
					c[0] += c[2];
					ans = ans && GetAns(c);
				}
				c.clear();
				for (int i = 0; i < 5; ++i) {
					c.push_back(b[i]);
				}
				c[4] = 1 - b[4];
				if (c[1] != 0) {
					c[1] += c[2];
					ans = ans && GetAns(c);
				}
			}
			if (b[3] != 0) {
				vector<int> c;
				for (int i = 0; i < 5; ++i) {
					c.push_back(b[i]);
				}
				c[4] = 1 - b[4];
				if (c[0] != 0) {
					c[0] += c[3];
					ans = ans && GetAns(c);
				}
				c.clear();
				for (int i = 0; i < 5; ++i) {
					c.push_back(b[i]);
				}
				c[4] = 1 - b[4];
				if (c[1] != 0) {
					c[1] += c[3];
					ans = ans && GetAns(c);
				}
			}
		}
	
	return ans;
}
int main(void) {
	//for (int i = 0; i < 4; ++i) {
	//	for (int j = 0; j < 4; ++j) {
	//		for (int k = 0; k < 4; ++k) {
	//			for (int l = 0; l < 4; ++l) {
	//				memo[i][j][k][l] = -1;
	//			}
	//		}
	//	}
	//}

	int a[5];
	cin >> a[0] >> a[1] >> a[2] >> a[3];
	a[4] = 0;
	vector<int> aa;
	for (int i = 0; i < 5; ++i) {
		aa.push_back(a[i]);
	}
	
	int c=GetAns(aa);
	if (c) {
		cout << "ISONO";
	}
	else {
		cout << "NAKAJIMA";
	}
	cout << endl;
	return 0;

}

Measured memory_bytes: 1212
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using vs=vector<string>;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define range(i,a,n) for(ll i=(a);i<(n);i++)
#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI 3.1415926535897932384

int dx[]={1,0,-1,0,1,-1,-1,1},dy[]={0,1,0,-1,1,1,-1,-1};
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<s;a=0;} return os;}
template<class S>void tf(bool b,S t,S f){cout<<(b?t:f)<<endl;}
void OUT(bool b){tf(b,"YES","NO");}
void Out(bool b){tf(b,"Yes","No");}
void out(bool b){tf(b,"yes","no");}
template<class T>void puta(T&&t){cout<<t<<endl;}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}

int popcnt(int x){return __builtin_popcount(x);}
int popcnt(ll x){return __builtin_popcountll(x);}
int bsr(int x){return 31 - __builtin_clz(x);}
int bsr(ll x){return 63 - __builtin_clzll(x);}
int bsf(int x){return __builtin_ctz(x);}
int bsf(ll x){return __builtin_ctzll(x);}
template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}

/*他のライブラリを入れる場所*/

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin>>n;
	vl a(n),b(n);
	rep(i,n){
		cin>>a[i]>>b[i];
	}
	vl c(n);
	iota(all(c),0);
	sort(all(c),[&](ll x,ll y){return abs(a[x]+b[x])>abs(a[y]+b[y]);});
	ll ans=0;
	rep(i,n){
		if(i%2==0)ans+=a[c[i]];
		else ans-=b[c[i]];
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 2560
#
# Written by NoKnowledgeGG @YlePhan
# ('ω')
#
#import math
#mod = 10**9+7
#import itertools
#import fractions
#import numpy as np
#mod = 10**4 + 7
"""def kiri(n,m):
  r_ = n / m
  if (r_ - (n // m)) > 0:
    return (n//m) + 1
  else:
    return (n//m)"""

""" n! mod m 階乗
mod = 1e9 + 7
N = 10000000
fac = [0] * N
def ini():
  fac[0] = 1 % mod
  for i in range(1,N):
    fac[i] = fac[i-1] * i % mod"""

"""mod = 1e9+7
N = 10000000
pw = [0] * N
def ini(c):
  pw[0] = 1 % mod
  for i in range(1,N):
    pw[i] = pw[i-1] * c % mod"""

"""
def YEILD():
  yield 'one'
  yield 'two'
  yield 'three'
generator = YEILD()
print(next(generator))
print(next(generator))
print(next(generator))
"""
"""def gcd_(a,b):
  if b == 0:#結局はc,0の最大公約数はcなのに
    return a
  return gcd_(a,a % b) # a = p * b + q"""
"""def extgcd(a,b,x,y):
  d = a
  if b!=0:
    d = extgcd(b,a%b,y,x)
    y -= (a//b) * x
    print(x,y)
  else:
    x = 1
    y = 0
  return d"""


def readInts():
  return list(map(int,input().split()))
mod = 10**9 + 7
def main():
  n,m = readInts()
  print(min(m//2,(2*n+m)//4))
  
if __name__ == '__main__':
  main()

Measured memory_bytes: 3060
from collections import deque
while True:
    n = int(input())
    if n == 0:break
    q1 = deque(sorted(map(int, input().split())))
    q2 = deque(sorted(map(int, input().split())))
    cnt = 0
    for k in range(1, n):
        top1 = q1.pop()
        top2 = q2.pop()
        if top1 > top2:
            cnt += 1
            q2.append(top2)
            q2.popleft()
            if cnt * 2 > k:
                print(k)
                break
    else:
        print("NA")


Measured memory_bytes: 13956
import math

# inputList=[]
# for i in range(6):
#     inputNum = input()
#     inputList.append(inputNum)
inputa = input().split()
# inputb = input().split()

a = int(inputa[0])
b = int(inputa[1])
# c = int(inputa[2])

# x = int(inputb[0])
# y = int(inputb[1])

print(float(a)/float(b))

Measured memory_bytes: 38256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int t = sc.nextInt();
        int cost = 0;

        for(int i = 0; i < n; i++){
            int tempcost = sc.nextInt();
            int temptime = sc.nextInt();
            if(t >= temptime){
                if(cost > tempcost || cost == 0) {
                    cost = tempcost;
                }
            }
        }

        if(cost == 0){
            System.out.println("TLE");
        }
        else {
            System.out.println(cost);
        }
    }
}


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

typedef long long int lli;

vector<int> a;
lli n,x,k,res;
    
    
lli min(lli a,lli b){
    return (a > b) ? b : a;
}

//k : tukaeru x : kazu

lli memo[2000][2000] = {};

lli solve(lli k,lli x){
    if(memo[k][x]) return memo[k][x];
    if(k==0) return memo[k][x] = a[x-k];
    
    if(x-k < 0) return memo[k][x] = min(solve(k-1,x),a[n+x-k]);
    return memo[k][x] = min(solve(k-1,x),a[x-k]);
}

lli f(lli k, lli x){
    lli res = 0;
    for(int i = 0; i < x; i++){
        res += solve(k,i);
        //cout << i  << " " << k << ":" << res << endl;
    }
    
    return res;
}



int main(void){
    // Here your code !
    
    cin >> n >> x;
    res = n*x*1000000000;
    
    a = vector<int>(n);
    for(int i = 0; i < n; i++)cin >> a[i];
    
    for(k = 0; k < n ; k++){
        res = min(res,k*x+f(k,n));
        //cout << res << endl;
    }
    cout << res << endl;
}


Measured memory_bytes: 31488
{-# LANGUAGE OverloadedStrings #-}
module Main where

import           Data.List
import           Control.Monad
import           Debug.Trace
import qualified Data.ByteString.Char8         as BC
import           Data.Maybe                     ( fromJust )
import qualified Data.Set                      as S
import qualified Data.IntMap.Strict            as IM
import qualified Data.Map.Strict               as M
import           Data.Char
import Data.Bits


readTuple2 :: IO (Int, Int)
readTuple2 = do
    [a, b] <- map (fst . fromJust . BC.readInt) . BC.words <$> BC.getLine
    return (a, b)

readTuple3 :: IO (Int, Int, Int)
readTuple3 = do
    [a, b, c] <- map (fst . fromJust . BC.readInt) . BC.words <$> BC.getLine
    return (a, b, c)

readInt :: IO Int
readInt = fst . fromJust . BC.readInt <$> BC.getLine

readInts :: IO [Int]
readInts = map (fst . fromJust . BC.readInt) . BC.words <$> BC.getLine

split :: (a -> Bool) -> [a] -> [[a]]
split f [] = []
split f as =
    let (fo, la) = span f as
        las      = case la of
            [] -> []
            xs -> split f $ tail xs
    in  case fo of
            [] -> las
            xs -> xs : las

solve :: Int -> [Int] -> Int
solve n as = 
    let 
        amap = IM.fromList $ zip [1..] as
        findRight total right
            | right > n = (total, right)
            | newTotal /= newXor = (total, right)
            | otherwise = findRight newTotal $ right + 1
            where
                newVal = amap IM.! right
                newTotal = total + newVal
                newXor = total `xor` newVal

        go (right, total, ans) left =
            let
                (newTotal, newRight) = findRight total right
                newNum = newRight - left
            in
                (newRight, newTotal - amap IM.! left, ans + newNum)
        (_, _, ans) = foldl' go (1, 0, 0) [1..n]
    in 
    ans

comb 0 xs = [[]]
comb _ [] = []
comb n (x:xs) = [x:y | y <- comb (n-1) xs] ++ comb n xs

main = do
    [l, r] <- readInts
    print $ if r - l >=2019 then 0 else minimum $ do
        [a, b] <- comb 2 [l..r]
        pure $ a *b `mod` 2019





Measured memory_bytes: 2428
// デバッグ実行：Ctrl+F5

using System;

class Program
{
    static void Main(string[] args)
    {
        String line;
        line = Console.ReadLine();
        String[] words = line.Split(' ');
        int A, B, C;
        int result;
        A = int.Parse(words[0]);
        B = int.Parse(words[1]);
        C = int.Parse(words[2]);
        if (A > B && A > C)
        {
            result = A * 10 + B + C;
        }
        else if (B > C)
        {
            result = B * 10 + A + C;
        }
        else result = C * 10 + A + B;


        Console.WriteLine(result);
    }
}

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

int main(){
    int N,K;cin>>N>>K;
    bool array[N]={0};
    for(int i=0;i<K;i++){
        int d;cin>>d;
        for(int j=0;j<d;j++){
            int a;cin>>a;
            array[a-1]=1;
        }
    }
    int ans=0;
    for(int i=0;i<N;i++){
        if(!array[i])ans++;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3624
// 復習
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int MOD = 1e9 + 7;

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

    int n, m; cin >> n >> m;
    vector<bool> safe(n+1, true);
    for (int i = 0; i < m; ++i) {
        int a; cin >> a;
        safe[a] = false;
    }

    vector<ll> dp(n+1);
    dp[0] = 1;
    dp[1] = safe[1];
    for (int i = 2; i <= n; ++i) {
        dp[i] = (dp[i-1] % MOD + dp[i-2] % MOD) * safe[i];
    }

    cout << dp[n] % MOD << endl;
    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const ll mod=1e9+7;
ll n,a[200010],ans=1,sum;
char s[200010];
ll fact(ll n)
{
	ll ans=1;
	for(register ll i=1;i<=n;++i)
		ans=ans*i%mod;
	return ans;
}
int main()
{
    ios::sync_with_stdio(0);
    cin>>n>>s+1;
    for(register ll i=1;i<=2*n;++i)
	{
		a[i]=(s[i]=='B');
		if((i&1)==0)a[i]=!a[i];
		sum+=(a[i]?1:-1);
		if(sum<0)
		{
			cout<<0<<endl;
			return 0;
		}
	}
	if(sum)
	{
		cout<<0<<endl;
		return 0;
	}
	for(register ll i=2*n;i>=1;--i)
	{
		if(a[i])ans=ans*sum%mod,sum--;
		else sum++;
	}
	cout<<ans*fact(n)%mod<<endl;
	return 0;
}

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

using ll = long long;
#define rep(i, n) for (long long i = 0; i < (n); ++i)
#define repr(i, a, b) for (auto i = (a); i < (b); ++i)
#define itr(x) for (auto&& v : (x))
#define updatemax(t, v) ((t) = std::max((t), (v)))
#define updatemin(t, v) ((t) = std::min((t), (v)))

ll a[200100], asum[200100], val[200100];
int main() {
  ll n, k;
  cin >> n >> k;
  rep(i, n) cin >> a[i];
  rep(i, n) asum[i + 1] = asum[i] + a[i];
  rep(i, n + 1) val[i] = (asum[i] - i) % k;
  // multiset<ll> s;
  map<ll, ll> m;
  ll res = 0;
  rep(i, n + 1) {
    // if (i - k >= 0) s.erase(s.find(val[i - k]));
    // res += s.count(val[i]);
    // s.insert(val[i]);
    if (i - k >= 0) --m[val[i - k]];
    res += m[val[i]];
    ++m[val[i]];
  }
  cout << res << endl;
}


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

int main() {
    ios::sync_with_stdio(0); cin.tie(0);
    int a, b;
    cin >> a >> b;
    int act = 1;
    int ans = 0;
    while(act < b) {
        act -= 1;
        act += a;
        ans ++;
    }
    cout << ans << endl;
}


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

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

using namespace std;

template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

int main(){
    int n, w; cin >> n >> w;
    vector<ll> dp[n];
    vector<ll> tmp(w+1, -1);
    rep(i, n) {
        dp[i] = tmp;
    }
    vector<ll> values(n);
    vector<ll> weights(n);
    rep(i, n) {
        cin >> values[i] >> weights[i];
    }
    rep(i, n) {
        rep(j, w+1) {
            if(i == 0) {
                if(j < weights[i]) {
                    dp[i][j] = 0;
                } else {
                    dp[i][j] = dp[i][j-weights[i]] + values[i];
                }
            } else {
                if(j < weights[i]) {
                    dp[i][j] = dp[i-1][j];
                } else {
                    dp[i][j] = max(dp[i-1][j], dp[i][j-weights[i]] + values[i]);
                }
            }
        }
    }
    cout << dp[n-1][w] << endl;
}



Measured memory_bytes: 10888
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <vector>
#include <cmath>
#include <algorithm>
using namespace std;
#define INF (2e9)
const int maxv=1000+10;
const int maxe=2000+10;
int V,E,S;
struct Edge
{
    int from, to,cost;
};
int d[maxv];
Edge es[maxe];

bool bellman_ford(int s)
{
    for(int i=0; i<V; i++) d[i]=INF;
    bool bUpdate=true;
    d[s]=0;
    for(int j=0; j<V; j++)
    {
        for(int i=0; i<E; i++)
        {
            Edge &e=es[i];
            if(d[e.from]!=INF&&d[e.to]>d[e.from]+e.cost)
            {
                d[e.to]=d[e.from]+e.cost;
            }
        }
    }
    int cnt=0;
    for(int i=0;i<V;i++)
    {
        if(d[i]==INF) cnt++;
    }
    if(cnt==V-1) return false;
    bool flag=false;
    for(int i=0; i<E; i++)
    {
        Edge &e=es[i];
        if(d[e.from]!=INF&&d[e.to]>d[e.from]+e.cost)
        {
            flag=true;
            break;
        }
    }
    return flag;

}
int main()
{
//    freopen("in.txt","r",stdin);
    scanf("%d%d%d",&V,&E,&S);
    int u,v,dd;
    for(int i=0; i<E; i++)
    {
        scanf("%d%d%d",&u,&v,&dd);
        es[i].from=u;
        es[i].to=v;
        es[i].cost=dd;
    }
    if(bellman_ford(S))
    {
        printf("NEGATIVE CYCLE\n");
        return 0;
    }

    for(int i=0; i<V; i++)
    {
        if(d[i]!=INF)  printf("%d\n",d[i]);
        else printf("INF\n");


    }

    return 0;
}

Measured memory_bytes: 3228
import numpy as np

N,D = [int(i) for i in input().split()]
cor = [[int(i) for i in input().split()] for i in range(N)]

count = 0
for i in range(N):
  for j in range(N):
    a = np.array(cor[i])
    b = np.array(cor[j])
    u = b-a
    leng = np.linalg.norm(u)
    
    if leng!=0:
      if leng.is_integer() == True:
      	count += 1
print(count//2)

Measured memory_bytes: 21552
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <cmath>
#include <complex>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cassert>
#include <iomanip>
using namespace std;

#define Rep(b, e, i) for(int i = b; i <= e; i++)
#define Repr(e, b, i) for(int i = e; i >= b; i--)
#define rep(n, i) Rep(0, n-1, i)
#define repr(n, i) Repr(n-1, 0, i)
#define all(v) (v).begin(), (v).end()
#define pb(v) push_back(v)
#define uniq(v) (v).erase(unique(all(v)),(v).end())
#define bitcnt(x) __builtin_popcount(x)
#define fst first
#define snd second
#define Pqaz(T) priority_queue<T,vector<T>,greater<T>>
#define Pqza(T) priority_queue<T>
#define put(x) cout << x;
#define putsp(x) cout << x << ' ';
#define putbd cout << "---------------------------------------------" << endl;
#define putln(x) cout << x << endl;
#define debug(x) cerr << #x << "=" << x << endl;
#define ENJYU std::ios::sync_with_stdio(false);std::cin.tie(0);

typedef long long ll;
typedef pair<ll, ll> llP;
typedef pair<int, int> intP;
typedef complex<double> comp;
typedef vector <int> vec;
typedef vector <ll> vecll;
typedef vector <double> vecd;
typedef vector <vec> mat;
typedef vector <vecll> matll;
typedef vector <vecd> matd;

//vector の中身を出力
template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}

const int MAX = 200020;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<29;
const ll INFL = 1e18;
const ll MOD = 1e9+7;

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

//********************************template END****************************************//

ll gcd(ll x, ll y) {return (x == 0 ? y : gcd(y%x, x));}

void solve(void){

	ll n, m;
	cin >> n >> m;
	string S,T;
	cin >> S >> T;
	ll g = gcd(n, m), l = n * m / g;
	rep(g, i)
	{
		if (S[i*l/m] != T[i*l/n])
		{
			cout << -1 << endl;
			return;
		}
	}

	cout << l << endl;

}

int main(void){
	solve();
	//cout << "yui(*-v・)yui" << endl;
	return 0;
}


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

int main() {
  int n;
  cin >> n;
  ll zero=0;
  vector<ll> x(n);
  vector<ll> l(n);
  for(int i=0;i<n;i++) {
    cin >> x[i] >> l[i];
  }
  vector<pair<ll,ll>> be(n);
  for(int i=0;i<n;i++) {
    be[i]=pair<ll,ll> (x[i]+l[i],-1*max(zero,x[i]-l[i]+1));
  }
  sort(be.begin(),be.end());
  int count=0;
  int tempe=-1;
  for(int i=0;i<n;i++) {
    if(tempe<be[i].first) {
      if(tempe<-1*be[i].second) {
        tempe=be[i].first;
        count++;
      }
    }
  }
  cout << count << endl;
}

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

using namespace std;

int N, M, E[100]; string S[100], T;

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

		if (N == 0 && M == 0) break;

		for (int i = 0; i < N; i++) cin >> S[i] >> E[i];

		int ret = 0;

		for (int i = 0; i < M; i++)
		{
			cin >> T;

			for (int j = 0; j < N; j++)
			{
				bool flag = true;

				for (int k = 0; k < 8; k++)
				{
					if (S[j][k] != '*' && S[j][k] != T[k])
					{
						flag = false;
					}
				}

				if (flag) ret += E[j];
			}
		}

		printf("%d\n", ret);
	}

	return 0;
}

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

int min3(int a,int b,int c) {
	
	if (a + b <= b + c&&a + b <= c + a)return a + b;
	else if (b + c <= c + a&&b + c <= a + b)return b + c;
	else return c + a;

}
int main() {

	int a, b, c;
	cin >> a >> b >> c;

	cout << min3(a, b, c) << endl;

	return 0;
}

Measured memory_bytes: 256
// author-Shivam gupta

#include <bits/stdc++.h>


using namespace std;

#define MEM(a, b) memset(a, (b), sizeof(a))

#define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++)

#define IN(A, B, C) assert( B <= A && A <= C)

#define MP make_pair
#define FOR(i,a) for(int i=0;i<a;i++)

#define FOR1(i,j,a) for(int i=j;i<a;i++)

#define EB emplace_back

#define INF (int)1e9

#define EPS 1e-9

#define PI 3.1415926535897932384626433832795

#define MOD 1000000007

#define read(type) readInt<type>()
#define max1 1000008
#define out(x) cout<<x<<'\n'
#define out1(x) cout<<x<<" "
#define END cout<<'\n'
typedef long int li;

typedef unsigned long int uli;

typedef long long int ll;

typedef unsigned long long int  ull;


void fast(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}

int main() {
   string s;
   cin>>s;
   int a[26];
   FOR(i,26){a[i]=0;}
   FOR(i,s.length()){
   a[s[i]-'a']++;}
   FOR(i,26){
   if(a[i]&1){out("No");return 0;}
}
out("Yes");

}



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

int main() {
	while (true) {
		char s1[200], s2[200];
		cin >> s1;
		if (s1[0] == '.' && s1[1] == '\0') {
			break;
		}
		cin >> s2;
		bool isClose = false, isDifferent = false;
		bool isInsideBlock = false;
		int s1Offset = 0, s2Offset = 0;
		for (int i = 0; i < 200; i++) {
			if (s1[i + s1Offset] == '\0' && s2[i + s2Offset] == '\0') {
				break;
			}
			if (!isInsideBlock) {
				if (s1[i + s1Offset] != s2[i + s2Offset]) {
					isDifferent = true;
					break;
				} else if (s1[i + s1Offset] == '\"') {
					isInsideBlock = true;
				}
			} else {
				if (s1[i + s1Offset] != s2[i + s2Offset]) {
					if (isClose) {
						isDifferent = true;
						break;
					} else {
						isClose = true;
						while (s1[i + s1Offset] != '\"') {
							s1Offset++;
						}
						while (s2[i + s2Offset] != '\"') {
							s2Offset++;
						}
						isInsideBlock = false;
					}
				} else if (s1[i + s1Offset] == '\"') {
					isInsideBlock = false;
				}
			}

		}

		if (isDifferent) {
			cout << "DIFFERENT" << endl;
		} else if (isClose) {
			cout << "CLOSE" << endl;
		} else {
			cout << "IDENTICAL" << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 3048
n = int(input())
s = input()
import copy
ss = copy.deepcopy(s)
import heapq

aa = []
bb = []
a,b,c = 0,0,0
for i in range(n):
    if s[i] == ")":
        c += 1
    
    if s[i] == "(":
        a += 1
        for j in range(i+1,n):
            if s[j] == ")":
                b += 1
                s = s[:j] + "-" + s[j+1:]
                break
            
ans = "("*c + ss + ")"*(a-b)
print(ans)

Measured memory_bytes: 38640
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<iomanip>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
#define LINF (long long)4e18

using ll = long long;



int main(){
    int N; cin >> N;
    vector<int> A(N);
    ll ans1 = 1;
    ll ans2 = 1;
    rep(i,N){
      cin >> A[i];
      ans1 *= 3;
      if(A[i] % 2 == 0) ans2 *= 2;
    }
    cout << ans1 - ans2 << endl;



}


Measured memory_bytes: 256
from math import cos, pi, sqrt

a, b, h, m = map(float, input().split())
x = 30 * (h + m / 60)
y = 360 * m / 60
z = abs(x - y)
z = min(z, 360 - z)
print(sqrt(a * a + b * b - 2 * a * b * cos(pi * z / 180)))


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

#define rep(i,n) for(int i=0;i<n;i++)
#define srep(i,s,e) for(ll i=s;i<=e;i++)
#define rrep(i,n) for(ll i=n-1;i>=0;i--)
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define MAX (int)1e9 + 99
#define vi vector<int>
#define vb vector<bool>
#define ll long long
#define ull unsigned long long
#define vll vector<ll>
#define pa pair<int, int>
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define MOD 998244353
#define bitcnt(x) __builtin_popcount(x)
#define gcd(a,b) __gcd(a,b)
#define all(x) (x).begin(),(x).end()
#define ts(x) to_string(x)
#define set0(x) memset(x, 0, sizeof(x))

ll fastPowMod(ll a, ll p,ll mod){ if(p==0) return 1; ll z = fastPowMod(a,p/2,mod); z = (z*z)%mod; if(p%2) z = (z*a)%mod; return z; }
template<class T> istream &operator>>(istream &is, vector<T> &v) { for (T &x : v) is >> x; return is;}
template<class T> ostream &operator<<(ostream &os, const vector<T> &v) {if (!v.empty()) {os << v.front();for (int i = 1; i < v.size(); ++i) os << ' ' << v[i];} return os;}


void solve()
{
    ll n,W,V=0;
    cin>>n>>W;
    vi w(n+1,0), v(n+1,0);

    srep(i,1,n) 
    {
        cin>>w[i]>>v[i];
        V += v[i];
    }

    

    vll dp(V+1,(ll)1e11);

    dp[0] = 0;

    for(int i=1; i<=n; i++)
    {
        for(int j=V; j>=v[i]; j--)
        {
            dp[j] = min(dp[j],dp[j-v[i]]+w[i]);
            
        }
        
    }

    for(int i = V;i>=0;i--)
    {
        if(dp[i]<=W) 
        {
            cout<<i;
            return;
        }
    }


}

int main()
{
    fastio;
    /*int t;
    cin>>t;
    
    rep(i,t)
    {*/
        solve();
        cout<<"\n";
    //}
    return 0;
}

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

int main(){
    string s;
    while(true){
        cin >> s;
        if(s == "0")
            break;
        
        int sum = 0;
//        for(int i=0; i<s.length(); i++)
//            sum += (s[i]-'0');
        
        for(auto &c: s)
            sum += c-'0';
        
        cout << sum << endl;
    }
    
    return 0;
}



Measured memory_bytes: 3092
#include<bits/stdc++.h>
using namespace std;
 
#define ll          int
#define ld          long double
#define pb          push_back
#define mp          make_pair
#define ff          first
#define se          second
#define endl        '\n'
#define fd(n)       fixed<<setprecision(n)
#define MAX         100000000000000000
#define MAXN        200005
#define mod         1000000007 
 
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string s,s1="",s2="";
    cin>>s;
    ll n=s.size(),i,flag=0;
    for(i=0;i<(n-1)/2;i++){
        s1+=s[i];
    }
    for(i=(n+1)/2;i<n;i++){
        s2+=s[i];
    }
    for(i=0;i<s1.size()/2;i++){
        if(s1[i]!=s1[s1.size()-1-i]){
            flag=1;
        }
    }
    for(i=0;i<s2.size()/2;i++){
        if(s2[i]!=s2[s2.size()-1-i]){
            flag=1;
        }
    }
    for(i=0;i<s.size()/2;i++){
        if(s[i]!=s[s.size()-1-i]){
            flag=1;
        }
    }
    if(flag==1){
        cout<<"No";
    }
    else{
        cout<<"Yes";
    }
    // cout<<s1<<" "<<s2;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
#define cl(x, y) memset(x, y, sizeof(x))
using namespace std;
const int maxn = 100000 + 5;

bool vis[maxn];
int a[maxn];

int main() {
	int n;
	cin >> n;
	for(int i=1; i<=n; i++) scanf("%d", &a[i]);
	cl(vis, false);
	int ans = 0;
	int cur = 1;
	vis[cur] = true;
	while(cur != 2) {
		cur = a[cur];
		ans ++;
		if(vis[cur]) {
			puts("-1"); return 0;
		} else vis[cur] = true;
	}
	printf("%d\n", ans);
}

Measured memory_bytes: 768
#include <iostream>
#include <cmath>

using namespace std;

int main(int argc, char* argv[]) {
  int N;
  cin >> N;

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

  int cur_x = 0;
  int cur_y = 0;
  int cur_t = 0;
  for (int i = 0; i < N; ++i) {
    int d = abs(cur_x - x[i]) + abs(cur_y - y[i]);
    int t_d = t[i] - cur_t;
    if (d > t_d || (t_d % 2 == 0 && d % 2 == 1) || (t_d % 2 == 1 && d % 2 == 0)) {
      cout << "No" << endl;
      return 0;
    }

    cur_x = x[i];
    cur_y = y[i];
    cur_t = t[i];
  }

  cout << "Yes" << endl;

  return 0;
}

Measured memory_bytes: 1408
#include<iostream>
using namespace std;
int main() {
	int a, b, c;
	cin >> a >> b >> c;
	if ((a == 1 && b == 1 && c == 0) || (a == 0 && b == 0 && c == 1)) cout << "Open" << endl;
	else cout << "Close" << endl;
}

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

int main()
{
  string S;
  cin >> S;
  
  int ans = 0;
  int a = 0;
  for (int i = 0; i < S.size(); i++)
  {
    if (S.at(i) == 'A' || S.at(i) == 'T'
        || S.at(i) == 'G' || S.at(i) == 'C') a++;
    else a = 0;
    if (ans < a) ans = a;
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int H = sc.nextInt(),W=sc.nextInt();
		String[][] arrayIn = new String[H][W];
		String[][] arrayOut = new String[H*2][W];
		String s;
		int k=0;
		for(int i=0;i<H;i++) {
			s = sc.next();
			for(int j=0;j<W;j++) {
				arrayIn[i][j] = String.valueOf(s.charAt(j));
			}
		}

		for(int i=0;i<H;i++) {
			for(int j=0;j<W;j++) {
				arrayOut[k][j] = arrayIn[i][j];
				arrayOut[k+1][j] = arrayIn[i][j];
			}
			k+=2;
		}

		for(String[] out:arrayOut) {
			for(String str:out) {
				System.out.print(str);
			}
			System.out.println();
		}


	}
	public static int sample(int n) {
		return n;
	}

}


Measured memory_bytes: 27712
#include <iostream>
#include <string>
#include <algorithm>
#include <list>
#include <set>
#define foreach(t,p) for(t::iterator it=p.begin();it!=p.end();++it)
#define rforeach(t,p) for(t::reverse_iterator it=p.rbegin();it!=p.rend();++it)
using namespace std;
#define REP(n) for(int i=0;i<n;i++)
#define N 1000001
#define POL 180
int pol[POL];
int pol2[POL];
int dp1[N];
int dp2[N];
int num;

void solve1() {
    REP(N) dp1[i] = N;
    dp1[0] = 0;
        for(int k=0;k<N;k++) {
                for(int j=0;j<POL;j++) 
                    if(k+pol[j] <=N)
                        dp1[k+pol[j] ] = min(dp1[k+pol[j]],dp1[k]+1);
        }
}

void solve2() {
    REP(N) dp2[i] = N;
    dp2[0] = 0;
    for(int i=0;i<N;i++) {
          //                cout << i << " "  << " " << dp2[i] << endl;
            for(int j=0;j<num;j++) {
                if(i+pol2[j] <= N) {
                    dp2[i+pol2[j] ] = min(dp2[i+pol2[j]],dp2[i]+1);
                }
            }
    }
}

int main() {
    num = 0;
    REP(POL){
        pol[i] = (i+1)*(i+2)*(i+3)/6;
        if(pol[i]%2 == 1) pol2[num++] = pol[i];
    }
    solve1();
    solve2();
//    REP(30) cout << dp1[i];
    int q;
    while(cin >> q && q) {
        cout << dp1[q] << " " << dp2[q] << endl;
    }

    return 0;
}

Measured memory_bytes: 8564
#include <stdio.h>
#include <stdlib.h>

int max(int a,int b){
  if(a > b){
    return a;
  }
  return b;
}

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

  int x[N],y[N],h[N];
  for(int i = 0;i < N;i++) scanf("%d%d%d",&x[i],&y[i],&h[i]);

  int H;
  for(int i = 0;i < N;i++){
    if(h[i] == 0) continue;
    for(int cx = 0;cx <= 100;cx++){
      for(int cy = 0;cy <= 100;cy++){
        H = h[i]+llabs(cx-x[i])+llabs(cy-y[i]);
        for(int j = 0;j < N;j++){
          if(h[j] != max(H-llabs(cx-x[j])-llabs(cy-y[j]),0)) break;
          if(j == N-1){
            printf("%d %d %d\n",cx,cy,H);
            return 0;
          }
        }
      }
    }
  }

  return 0;
}

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

using  namespace std;

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

    int n, k;
    cin >> n >> k;
    vector<int> h(n);
    for(auto&& i : h){
        cin >> i;
    }
    sort(begin(h), end(h));
    int ans = 1e9;
    for(int i = 0; i + k <= n; i++){
        ans = min(ans, h[i + k - 1] - h[i]);
    }
    cout << ans << "\n";
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
using P = pair<ll, int>;
 
const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

#define INF 1001001001
#define MAX 1000000

int main() {
  int n;
  cin >> n;
  vector<ll> a(n);
  rep(i,n) cin >> a[i];
  mint sum = 0, p = 0;
  rep(i,n) { sum+=a[i]; p+=a[i]*a[i]; }
  cout << (sum*sum-p)/2 << endl;

  return 0;
}

Measured memory_bytes: 4840
use std::io;

fn main() {
    let mut first = String::new();

    io::stdin().read_line(&mut first);
    let mut fitr = first.split_whitespace();
    let n = fitr.next().unwrap().parse::<i32>().unwrap();
    let m = fitr.next().unwrap().parse::<i32>().unwrap();

    let mut num = vec![0; n as usize];
    for i in 0..m {
        let mut line = String::new();
        io::stdin().read_line(&mut line);
        let mut itr = line.split_whitespace();
        let src = itr.next().unwrap().parse::<i32>().unwrap() - 1;
        let dst = itr.next().unwrap().parse::<i32>().unwrap() - 1;

        num[src as usize] += 1;
        num[dst as usize] += 1;
    }

    for i in 0..n {
        println!("{}", num[i as usize]);
    }
}

Measured memory_bytes: 4352
#include<stdio.h>
#include<algorithm>
#include<functional>
#include<cmath>
#include<numeric>
#include<queue>
#include<string>
#include<vector>
#define ll long long
#define rep(i,n) for(int i=0;i<n;i++)
ll mod = 1000000007;
using namespace std;
priority_queue<ll int>A;//きゅー
int gcd(int a, int b)
{
	if (a < b) {
		a ^= b;
		b ^= a;
		a ^= b;
	}

	return b ? gcd(b, a % b) : a;
}
int main(void)
{
	int N;
	ll int A[100010];
	scanf("%d", &N);
	int ans = 0;
	for (int i = 0; i < N; i++) {
		scanf("%lld", &A[i]);
		ans++;
	}
	int count = 0;
	sort(A, A + N);
	for (int i = 0; i < N-1; i++) {
		if (A[i] == A[i + 1]) {
			count++;
			if (i == N - 2) {
				if (count % 2 == 1) {
					ans -= count + 1;
					count = 0;
				}
				else {
					ans -= count;
					count = 0;
				}
			}
		}
		else {
			if (count % 2 == 1) {
				ans -= count + 1;
				count = 0;
			}
			else {
				ans -= count;
				count = 0;
			}
		}
	}
	printf("%d", ans);
	return 0;
}

Measured memory_bytes: 1024
#!/usr/bin/env python3
import sys


def solve(N: int, M: int):
    t = N + M
    return t * (t - 1) // 2 - N * M


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    print(solve(N, M))

def test():
    import doctest
    doctest.testmod()

if __name__ == '__main__':
    #test()
    main()


Measured memory_bytes: 3060
using System;
 
namespace aizu
{
    class OnlineJudge
    {
        static void Main()
        {
            int count;
            while((count = int.Parse(Console.ReadLine())) != 0) {
                var value = new int[7];
                for(int i = 0; i < count; ++i) {
                    ++value[Math.Min(int.Parse(Console.ReadLine()) / 10, 6)];
                }
                Array.ForEach(value, Console.WriteLine);
            }
        }
    }
}

Measured memory_bytes: 5792
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<string>

using namespace std;
int main(){
    int N;
    cin >>N;
    long long L[90];
     L[0]=2;
     L[1]=1;

     for(int i=2;i<=N;i++){
         L[i]=L[i-1]+L[i-2];
     }
cout << L[N]<<endl;
 return 0;


}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const double eps = 1e-10;
const ll MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;
template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}
template<typename T1, typename T2>
ostream& operator<<(ostream &os, const pair<T1, T2> p) {
  os << p.first << ":" << p.second;
  return os;
}
struct In {
  string s1, s2;
  int d;
};
struct Edge {
  int from, to, d;
};
void solve(int n, int m, int cap) {
  cap *= 10;
  string ssrc, sdest; cin >> ssrc >> sdest;
  vector<In> sv(n);
  map<string ,int> mp;
  int id = 1;
  for(int i=0;i<n;++i) {
    string s1, s2; int d; cin >> s1 >> s2 >> d;
    sv[i] = {s1, s2, d};
    if(mp[s1] == 0) {
      mp[s1] = id;
      id++;
    }
    if(mp[s2] == 0) {
      mp[s2] = id;
      id++;
    }
  }
  int src = mp[ssrc]-1, dest = mp[sdest]-1;
  vector<vector<Edge>> v(id);
  for(int i=0;i<n;++i) {
    v[mp[sv[i].s1]-1].push_back({mp[sv[i].s1]-1, mp[sv[i].s2]-1, sv[i].d});
    v[mp[sv[i].s2]-1].push_back({mp[sv[i].s2]-1, mp[sv[i].s1]-1, sv[i].d});
  }
  map<int, bool> gas;
  for(int i=0;i<m;++i) {
    string s; cin >> s;
    gas[mp[s]-1] = true;
  }
  vll dist(id * (cap+1), INF);
  priority_queue<P, vector<P>, greater<P>> pq;
  dist[src * (cap+1) + cap] = 0;
  pq.push({0, src * (cap+1) + cap});
  while(!pq.empty()) {
    auto now = pq.top(); pq.pop();
    int val = now.first, idx = now.second / (cap+1), nowcap = now.second % (cap+1);
    if(dist[idx * (cap + 1) + nowcap] < val) continue;
    for(int i=0;i<(int)(v[idx].size());++i) {
      int nxt = v[idx][i].to, cost = v[idx][i].d;
      if(nowcap < cost) continue;
      if(gas[nxt] && dist[nxt * (cap + 1) + cap] > val + cost) {
        dist[nxt * (cap + 1) + cap] = val + cost;
        pq.push({val + cost, nxt * (cap+1) + cap});
      } else if(!gas[nxt] && dist[nxt * (cap + 1) + (nowcap - cost)] > val + cost) {
        dist[nxt * (cap + 1) + (nowcap - cost)] = val + cost;
        pq.push({val + cost, nxt * (cap+1) + (nowcap - cost)});
      }
    }
  }
  ll ans = INF;
  for(int i=0;i<=cap;++i) {
    ans = min(ans, dist[dest * (cap+1) + i]);
  }
  cout << (ans == INF ? -1 : ans) << endl;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  while(1) {
    int n, m, cap; cin >> n >> m >> cap;
    if(n == 0 && m == 0) break;
    solve(n, m, cap);
  }
}



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

using namespace std;
using int64 = long long;

constexpr int DEBUG = 0;

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

  int n;
  cin >> n;
  vector<int64> xs(n);
  int64 sum = 0;
  for (int i = 0; i < n; i++) {
    cin >> xs[i];
    sum += xs[i];
  }

  sort(xs.begin(), xs.end());
  for (int i = 0; i + 1 < n; i += 2) {
    int64 y = xs[i] + xs[i + 1];
    if (y < 0) sum += -2 * y; 
  }
  cout << sum << endl;
}

Measured memory_bytes: 1024
#![allow(dead_code)]
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>().split_whitespace()
        .map(|e| e.parse().ok().unwrap()).collect()
}
fn read_vec2<T: std::str::FromStr>(n: usize) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}
fn main() {
    let x: i32 = read();
    println!("{}", if x >= 30 {"Yes"} else {"No"});
}

Measured memory_bytes: 2128