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

#define MP make_pair
#define PB push_back
#define ALL(x)      (x).begin(),(x).end()
#define REP(i,n)    for(int i=0;i<(n);i++)
#define REP1(i,n)   for(int i=1;i<(n);i++)
#define REP2(i,d,n) for(int i=(d);i<(n);i++)
#define RREP(i,n)   for(int i=(n);i>=0;i--)
#define CLR(a)      memset((a),0,sizeof(a))
#define MCLR(a)     memset((a),-1,sizeof(a))
#define RANGE(x,y,maxX,maxY) (0 <= (x) && 0 <= (y) && (x) < (maxX) && (y) < (maxY))
 
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<VI > VVI;
typedef vector<string> VS;
typedef vector<LL> VLL;
typedef pair<int,int> PII;
 
const int INF = 0x3f3f3f3f;
const LL INFL = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-9;
 
const int DX[]={1,0,-1,0},DY[]={0,-1,0,1};

void solve(long long N, long long M, std::vector<long long> A, std::vector<long long> B){
    vector<pair<LL,LL>> memo;
    REP(i, N) memo.PB(MP(A[i], B[i]));
    sort(ALL(memo));

    LL ans = 0;
    int idx = 0;
    while(M != 0){
        pair<LL, LL> now = memo[idx];
        if(now.second < M) {
            M -= now.second;
            ans += now.first * now.second;
        }else {
            ans += now.first * M;
            M =0;
        }
        idx++;
    }

    cout << ans << endl;
}

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


Measured memory_bytes: 3956
import itertools

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

c = [i for i in range(2, n + 1)]
b = []
for x in itertools.permutations(c):
  b.append([1] + list(x))
  
cnt = 0
for x in b:
  exist = True
  for i in range(n-1):
    if not sorted(x[i:i+2]) in a:
      exist = False
      break
  if exist:
    cnt += 1

print(cnt)

Measured memory_bytes: 9504
#include<iostream>
#include<algorithm>
using namespace std;
#define INF ( 1 << 30 )
int N,mas[16][17],dp[1<<16];
int rec(int bit){
  if(dp[bit]) return dp[bit];
  if(!bit) return 0;
  int ret = INF;
  for(int i = 0 ; i < N ; i++ ){
    if(!(bit & (1 << i))) continue;
    int min_cost = mas[i][0];
    for(int j = 0 ; j < N ; j++ ){
      if(!(bit & (1 << j))) min_cost = min( min_cost, mas[i][j+1]);
    }
    ret = min( ret, min_cost + rec(bit&~(1 << i)));
  }
  return dp[bit] = ret;
}
int main(){
  while(cin >> N , N ){
    fill_n( dp, 1<<16, 0);
    for(int i = 0 ; i < N ; i++ ){
      for(int j = 0 ; j <= N ; j++ ){
        cin >> mas[i][j];
      }
    }
    cout << rec((1 << N)-1) << endl;
  }
}

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

int main(){
	int A,B,M;
	int a[100000];
	int b[100000];
	int x;
	int y;
	int c;
	int mina=10000000;
	int minb=10000000;
	int mins=0;
	cin>>A>>B>>M;
	int i=0;
	for(i=0;i<A;i++){
		cin>>a[i];
		if(a[i]<mina) mina=a[i];
		
	}
	for(i=0;i<B;i++){
		cin>>b[i];
		if(b[i]<minb) minb=b[i];
	}
	mins=mina+minb;
	for(i=0;i<M;i++){
		cin>>x>>y>>c;
		if(a[x-1]+b[y-1]-c<mins) mins=a[x-1]+b[y-1]-c;
	}
	cout<<mins ;
}

Measured memory_bytes: 1024
package main

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

var sc = bufio.NewScanner(os.Stdin)

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

func main() {
	stack := make([]int, 0)
	s := nextLine()

	ss := strings.Split(s, " ")

	for _, v := range ss {
		i, err := strconv.Atoi(v)
		if err != nil {
			var a, b int
			stack, a, b = stack[:len(stack)-2], stack[len(stack)-2], stack[len(stack)-1]

			var c int
			switch v {
			case "+":
				c = a + b
			case "-":
				c = a - b
			case "*":
				c = a * b
			case "/":
				c = a / b
			}
			stack = append(stack, c)
		} else {
			stack = append(stack, i)
		}
	}

	fmt.Println(stack[0])
}



Measured memory_bytes: 1092
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
int main(void){
    // Your code here!
    int n;
    cin >> n;
    vector <ll> a(n);
    int cnt =0;
    for(int i = 0; i < n; i++){
        cin >> a[i];
        if(a[i] % 2 != 0) {
            cout << cnt << endl;
            return 0;
        }else {
            a[i] /= 2;
        }
    }
    cnt++;
    
    for(int j = 0; j < 35; j++){
        for(int i = 0; i < n; i++){
            if(a[i] % 2 != 0 || a[i] == 0){
                cout << cnt << endl;
                return 0;
            }else {
                a[i] /= 2;
            }
        }
        cnt++;
    }
    cout << cnt << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int H, W;
  cin >> H >> W;
  vector<vector<char>> s(H, vector<char>(W));
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      cin >> s.at(i).at(j);
    }
  }
  vector<vector<int>> w(H, vector<int>(W));
  for (int i = 0; i < H; i++) {
  int k = 0;
  while (k < W) {
    int count = 0;
    int j = k;
    while (s.at(i).at(j) == '.') {
      count++;
      j++;
      if (j == W) {
        break;
      }
    }
    int x = count;
    while (count > 0) {
      w.at(i).at(k) = x;
      count--;
      k++;
    }
    if (j == W) {
      break;
    }
    while (s.at(i).at(j) == '#') {
      w.at(i).at(j) = 0;
      j++;
      if (j == W) {
        break;
      }
    }
    k = j;
  }
  }
  vector<vector<int>> h(H, vector<int>(W));
  for (int j = 0; j < W; j++) {
  int k = 0;
  while (k < H) {
    int count = 0;
    int i = k;
    while (s.at(i).at(j) == '.') {
      count++;
      i++;
      if (i == H) {
        break;
      }
    }
    int x = count;
    while (count > 0) {
      h.at(k).at(j) = x;
      count--;
      k++;
    }
    if (i == H) {
      break;
    }
    while (s.at(i).at(j) == '#') {
      h.at(i).at(j) = 0;
      i++;
      if (i == H) {
        break;
      }
    }
    k = i;
  }
  }
  priority_queue<int> q;
  for (int i = 0; i< H; i++) {
    for (int j = 0; j < W; j++) {
      q.push(w.at(i).at(j) + h.at(i).at(j) - 1);
    }
  }
  cout << q.top() << endl;
}


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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define MOD 1000000007

typedef long long int ll;

const ll INF=(ll)1e18;

int main(){
  int N;
  cin >> N;
  REP(i,10)FOR(j,i,10){
    if(i*j==N){
      cout << "Yes" << endl;
      exit(0);
    }
  }
  cout << "No" << endl;
}



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

int main()
{
    int n;
    cin >> n;
    
    map<int, int> cnt;
    while (n--){
        int d;
        cin >> d;
        ++cnt[d];
    }
    
    int m;
    cin >> m;
    while (m--){
        int t;
        cin >> t;
        if (!cnt[t]){
            puts("NO");
            return 0;
        }
        --cnt[t];
    }
    puts("YES");
    
    return 0;
}


Measured memory_bytes: 9600
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, n) for(int i = 0; i < (n); i++)
#define MEM(a, x) memset(a, x, sizeof(a))
#define ALL(a) a.begin(), a.end()
#define UNIQUE(a) a.erase(unique(ALL(a)), a.end())
typedef long long ll;

string s;

int main(int argc, char const *argv[]) {
	ios_base::sync_with_stdio(false);
	cin >> s;
	cout << s.substr(0, (int)s.size()-8);
	return 0;
}

Measured memory_bytes: 256
H, W = map(int, input().split())

a = [input() for w in range(H)]

for i in range(H)[::-1]:
    if '#' not in a[i]:
        del a[i]
        H -= 1

n = []

for j in range(W)[::-1]:
    m = [''.join([t[j] for t in a])]
    if '#' in m[0]:
        n += m

for k in range(H):
    print(''.join(u[k] for u in n[::-1]))

Measured memory_bytes: 3064
import java.io.BufferedReader;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Map;
import java.util.Map.Entry;

import java.util.PriorityQueue;
import java.util.Set;
import java.util.StringTokenizer;
import java.util.TreeSet;
 
public class Main {
	
	public static final long MOD = 1000000007;
	
	public static long[][] mat_mut(final int N, long[][] mat1, long[][] mat2){
		long[][] ret = new long[N][N];
		
		for(int i = 0; i < N; i++) {
			for(int j = 0; j < N; j++) {
				for(int k = 0; k < N; k++) {
					ret[i][j] += mat1[i][k] * mat2[k][j];
					ret[i][j] %= MOD;
				}
			}
		}
		
		return ret;
	}
	
	public static long[][] mat_fact(final int N, long[][] mat, final long K){
		if(K == 1) {
			return mat;
		}else if(K % 2 == 1) {
			return mat_mut(N, mat, mat_fact(N, mat, K - 1));
		}else {
			final long[][] ret = mat_fact(N, mat, K / 2);
			return mat_mut(N, ret, ret);
		}
	}
	
	public static void main(String[] args) throws IOException {
		try(final Scanner sc = new Scanner(System.in)){
			final int N = sc.nextInt();
			final int H = sc.nextInt();
			final int W = sc.nextInt();
			
			System.out.println((N - H + 1) * (N - W + 1));
		}
	}
 
	public static class Scanner implements Closeable {
		private BufferedReader br;
		private StringTokenizer tok;
 
		public Scanner(InputStream is) throws IOException {
			br = new BufferedReader(new InputStreamReader(is));
		}
 
		private void getLine() throws IOException {
			while(!hasNext()){
				tok = new StringTokenizer(br.readLine());
			}
		}
 
		private boolean hasNext() {
			return tok != null && tok.hasMoreTokens();
		}
 
		public String next() throws IOException {
			getLine();
			return tok.nextToken();
		}
 
		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}
 
		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}
 
		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}
 
		public int[] nextIntArray(int n) throws IOException {
			final int[] ret = new int[n];
			for(int i = 0; i < n; i++){
				ret[i] = this.nextInt();
			}
			return ret;
		}
 
		public long[] nextLongArray(int n) throws IOException {
			final long[] ret = new long[n];
			for(int i = 0; i < n; i++){
				ret[i] = this.nextLong();
			}
			return ret;
		}
 
		public void close() throws IOException {
			br.close();
		}
	}
}

Measured memory_bytes: 21332
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		
		// String型からchar型へ変換する為のtoCharArray()メソッド
		char[] list = sc.nextLine().toCharArray();
		
		for (char a : list) {
			
			// もしも、変数「a」の中身に小文字があった場合は
			if (Character.isLowerCase(a)) {
				
				// 変数「a」の中にある小文字を大文字に変換して出力する
				System.out.print(Character.toUpperCase(a));
				
			} else {	// それ以外の場合は
				
				// 変数「a」の中にある大文字を小文字に変換して出力する
				System.out.print(Character.toLowerCase(a));
				
			}
			
		}
		System.out.println();

	}

}



Measured memory_bytes: 26812
#include <iostream>
#include <cstring>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <cstdio>
#include <map>
#include <set>
#include <cmath>
#include <vector>
#include <ctime>
#include <queue>
#include <sstream>
#include <utility>
#include <bitset>

using namespace std;

#define MP make_pair 
#define PB push_back 
#define INF (1000000007) 
#define eps 1e-8

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

ll n,a,b,c,d;
ll low,hi;

inline void r(bool f)
{
	if(f) cout<<"YES";
	else cout<<"NO";
	exit(0);
}

int main()
{
	cin>>n>>a>>b>>c>>d;
	for(ll i=0;i<n;i++)
	{
		low=hi=a;
		ll j=n-1-i;
		low+=c*i-d*j;
		hi+=d*i-c*j;
		if(low<=b&&hi>=b) r(1);
	}
	r(0);
	return 0;
}

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

#define M_PI       3.14159265358979323846   // pi

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> VI;
typedef pair<ll, ll> P;

#define rep(a,n) for(int a = 0;a < n;a++)
#define repi(a,b,n) for(int a = b;a < n;a++)

const ull mod = 1000000007;

struct UnionFind {
public:
	vector <ll> par; // 
	vector <ll> siz; // 

	UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL) {
		for (ll i = 0; i < sz_; ++i) par[i] = i;
	}
	void init(ll sz_) {
		par.resize(sz_);
		siz.assign(sz_, 1LL);
		for (ll i = 0; i < sz_; ++i) par[i] = i;
	}

	ll root(ll x) {
		while (par[x] != x) {
			x = par[x] = par[par[x]];
		}
		return x;
	}

	bool merge(ll x, ll y) {
		x = root(x);
		y = root(y);
		if (x == y) return false;
		if (siz[x] < siz[y]) swap(x, y);
		siz[x] += siz[y];
		par[y] = x;
		return true;
	}

	bool issame(ll x, ll y) {
		return root(x) == root(y);
	}

	ll size(ll x) {
		return siz[root(x)];
	}
};
int main(void)
{
	ll n, m;
	cin >> n >> m;
	UnionFind uf(n);
	rep(i, m) {
		int x, y, z;
		cin >> x >> y >> z;
		x--; y--;
		uf.merge(x, y);
	}
	vector<int> p(n,0);
	rep(i, n) {
		p[uf.root(i)] = 1;
	}
	ll sum = 0;
	rep(i, n) {
		if (p[i]) sum++;
	}
	cout << sum << endl;
	return 0;
}


Measured memory_bytes: 2176
def g;gets.split.map &:to_i;end
r=1..n=gets.to_i
w=[0]+r.map{[0]+[1e9]*n}
r.map{f,_,*t=g;t.map{|i|w[f][i]=1}}
r.each{|k|r.each{|i|r.each{|j|(a=w[i][k]+w[k][j])<w[i][j]&&w[i][j]=a}}}
gets.to_i.times{s,d,v=g;c=w[s][d]+1;puts c>v ?:NA:c}

Measured memory_bytes: 6276
s = gets.chomp.split.map(&:to_i).first

def func1(integer)
  return integer/2 if integer % 2 == 0
  return 3*integer + 1
end

count = 2
a = [s]

loop do
  s = func1(s)
  a << s
  break if a.count(s) == 2
  count += 1
end

puts count



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

using i64 = int64_t;

double calc_dist(pair<double, double> x, pair<double, double> y){
  return sqrt((x.first-y.first)*(x.first-y.first) + (x.second-y.second)*(x.second-y.second));
}

int main(){
  int n;
  cin >> n;
  vector<pair<double, double>> v;
  vector<int> idx(n);
  iota(idx.begin(), idx.end(), 0);
  for(int i=0;i<n;++i){
    double x, y;
    cin >> x >> y;
    v.emplace_back(x, y);
  }
  
  double ans = 0;
  do{
    double sum = 0;
    for(int i=0;i<n-1;++i){
      sum += calc_dist(v[idx[i]], v[idx[i+1]]);
    }
    ans += sum;
  }while(next_permutation(idx.begin(), idx.end()));
  i64 fact = 1;
  for(i64 i=2;i<=n;++i)fact *= i;
  ans /= (double)fact;
  
  printf("%.10f\n", ans);
  
  return 0;
}

Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn gcd(x: u64, y: u64) -> u64 {
    let mut a: u64;
    let mut b: u64;

    if x < y {
        a = y;
        b = x;
    } else {
        a = x;
        b = y;
    }

    while b > 0 {
        let r = a % b;
        a = b;
        b = r;
    }

    return a;
}

fn main() {
    let x: u64 = read();
    let y: u64 = read();
    println!("{}", gcd(x, y));
}



Measured memory_bytes: 5032
# B
N = int(input())
A = [int(i) for i in input().split()]
if 0 in A:
    print(0)
else:
    result = 1
    for i in range(len(A)):
        result = result * A[i]
        if result > 1000000000000000000:
            result = -1
            break
    print(result)

Measured memory_bytes: 21784
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
import functools
def s(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7
cnt = 0
ans = 0
inf = float("inf")

n = k()
a = l()
for i in range(n):
    if (i+1) % 2 == 1 and a[i] % 2 == 1:
        cnt += 1

print(cnt)


Measured memory_bytes: 10144
#C問題
N = int(input())
A = list(map(int,input().split()))
if N%2 == 0:
    front = []
    back = []
    for i in range(N):
        if i%2 == 1:
            front.append(A[i])
        else:
            back.append(A[i])
    front = front[::-1]
    for i in range(N//2):
        print(front[i],end=" ")
    for i in range(N//2):
        print(back[i],end=" ")
        
else:
    front = []
    back = []
    for i in range(N):
        if i%2 == 0:
            front.append(A[i])
        else:
            back.append(A[i])
    front = front[::-1]
    for i in range(N//2 + 1):
        print(front[i],end=" ")
    for i in range(N//2):
        print(back[i],end=" ")


Measured memory_bytes: 25744
import io, sys, atexit, os

import math as ma
from sys import exit
from decimal import Decimal as dec
from itertools import permutations


def li ():
	return list (map (int, input ().split ()))


def num ():
	return map (int, input ().split ())


def nu ():
	return int (input ())


def find_gcd ( x, y ):
	while (y):
		x, y = y, x % y
	return x


mm = 1000000007



def solve ():
	t = 1
	for it in range (t):
		a,b=num()
		c,d=num()
		ff=c*b+a*d-(c*d)
		print(a*b-ff)





if __name__ == "__main__":
	solve ()

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

int main() {
	int n;
	cin >> n;
	vector<pair<int, int>> tmp1(100000), tmp2(100000);
	for (int i = 0; i < 100000; ++i) {
		tmp1[i].first = i + 1;
		tmp2[i].first = i + 1;
	}
	for (int i = 0; i < n; ++i) {
		int v;
		cin >> v;
		if (i % 2) ++tmp1[v - 1].second;
		else ++tmp2[v - 1].second;
	}
	sort(tmp1.begin(), tmp1.end(), [](pair<int, int>& a, pair<int, int>& b)->bool { return a.second > b.second; });
	sort(tmp2.begin(), tmp2.end(), [](pair<int, int>& a, pair<int, int>& b)->bool { return a.second > b.second; });
	if (tmp1[0].first == tmp2[0].first) {
		if (tmp1[0].second + tmp2[1].second < tmp1[1].second + tmp2[0].second) cout << n - tmp1[1].second - tmp2[0].second;
		else cout << n - tmp1[0].second - tmp2[1].second;
	}
	else cout << n - tmp1[0].second - tmp2[0].second;
}

Measured memory_bytes: 1792
S=input()
N=len(S)
#「連続する区間」についての問題では、”累積和的なもの”をとるのが定石である。
#Sの連続する区間が、右からa文字分から、右からb文字分を取り除いたものであるとき
#その区間の整数が2019の倍数になるということは、s[a]とs[b]を2019で割ったあまりが等しい
#十分条件であることは分かったが、必要条件であるのか
#結論として必要条件でもある
#なぜなら2019と10は互いに素であるからである。

T=[]
T.append(0)
tmp=""
d=[0 for _ in range(2019)]
d[0]=1
r=0
t=1
for i in range(N):
    s=S[N-1-i]
    r+=int(s)*t
    r%=2019
    t*=10
    t%=2019 
    d[r]+=1

ans=0

print(sum(i*(i-1)//2 for i in d))

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

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair<int, int>  pii;
typedef pair<ll, ll>    pll;

#define sync std::ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define loopi(n) for(int i=0;i<n;i++)
#define loopj(n) for(int j=0;j<n;j++)
#define loop(a,b,c) for(int i=a;i<=b;i=i+c)

#define     deb(x)      cout<<#x<<"="<<x<<endl
#define     all(x)      (x).begin(),(x).end()
#define     reset(a)    memset(a,0,sizeof(a))
#define     sz(x)       ((int)(x.size()))
#define     pb          push_back
#define     pf          push_front
#define     pob	        pop_back
#define     pof         pop_front
#define     ins         insert
#define     F           first
#define     S           second
#define     mkp         make_pair
#define     mkt         make_tuple
#define     bitcount(x) __builtin_popcountll(x)
#define     gcd(a,b)    (__gcd(a,b))
#define     lcm(a,b)    ((a*b)/gcd(a,b))
#define PI 3.1415926535897932384626
 
const int mod = 1e9+7;

//============================================//

void solve()
{
	int d,s,t;
	cin>>d>>s>>t;
	
	int x=s*t;
	cout<<(d<=x?"Yes":"No");
}
int main() 
{
	sync;

	int t=1;
	//cin>>t;
	while(t--)
	{
		solve();
		cout<<endl;
	}
}

Measured memory_bytes: 3636
#include<stdio.h>
int main()
{int A,P,S,Z;
    scanf("%d %d",&A,&P);
    if(A>=0&&P<=100)
      {S=A*3+P;
       Z=S/2;
       if(Z>0)
       printf("%d\n",Z);
       else
       printf("0\n");
      }
    return 0;
 }

Measured memory_bytes: 128
# coding: utf-8

N = int(input())
S = input()

ans = [None] * len(S)

# Z = 90
for i, s in enumerate(S):
    n = ord(s)
    ans[i] = chr(n + N) if n+N <= 90 else chr(64 + (n+N-90))

print("".join(ans))


Measured memory_bytes: 3060
from operator import itemgetter

N,M = map(int,input().split())
PY = []
for _ in range(M):
    P,Y = map(int,input().split())
    PY.append([_,P,Y])

s_PY = sorted(PY,key=itemgetter(1,2))

kenL = [0] * N
shiL = [''] * M

for i,p,y in s_PY:
    kenL[p-1] += 1
    shiL[i] = str(p).zfill(6) + str(kenL[p-1]).zfill(6)

for j in shiL:
    print(j)
   

Measured memory_bytes: 33056
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
    vector<int>V(5);
    while(cin>>V[0],V[0]){
         vector<int>cnt(3,0);
         cnt[--V[0]]++;
         for(int i=1;i<5;i++){
            cin>>V[i];
            cnt[--V[i]]++;
         }
         bool flag=false;
         if(cnt[0]==5||cnt[1]==5||cnt[2]==5)flag=true;
         else if(cnt[0]&&cnt[1]&&cnt[2])flag=true;

         if(flag)for(int i=0;i<5;i++)cout<<3<<endl;
         else for(int i=0;i<5;i++)cout<<((cnt[V[i]]&&cnt[(V[i]+1)%3])?1:2)<<endl;
    }
    return 0;
}

Measured memory_bytes: 1192
#include<iostream>
using namespace std;
int nums(int n){
	return to_string(n).length();
}
int main(){
	//ios::sync_with_stdio(false);cin.tie(0); cout << fixed << setprecision(7);
////////////////////////////////////////////
	int n;
	cin >> n;
	int ans=0;
	while(n>0){
		if(nums(n)%2==1){
			ans++;
		}
		n--;
	}
	cout << ans << endl;
///////////////////////////////////////////
}


Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <functional>
#include <queue>
#include <vector>

const int N = 100000;

int a[N], deg[N], depth[N];
std::vector<int> child[N];

int main()
{
#ifdef LOCAL_JUDGE
    freopen("B.in", "r", stdin);
#endif
    int n;
    while (scanf("%d", &n) == 1) {
        memset(deg, 0, sizeof(deg));
        for (int i = 0; i < n; ++ i) {
            child[i].clear();
        }
        for (int i = 1; i < n; ++ i) {
            scanf("%d", a + i);
            -- a[i];
            deg[a[i]] ++;
            child[a[i]].push_back(i);
        }
        std::queue<int> queue;
        for (int i = 0; i < n; ++ i) {
            if (!deg[i]) {
                depth[i] = 0;
                deg[a[i]] --;
                if (!deg[a[i]]) {
                    queue.push(a[i]);
                }
            }
        }
        while (!queue.empty()) {
            int u = queue.front();
            queue.pop();
            std::vector<int> tmp;
            for (auto&& v : child[u]) {
                tmp.push_back(depth[v]);
            }
            std::sort(tmp.begin(), tmp.end(), std::greater<int>());
            depth[u] = 0;
            for (int j = 0; j < (int)tmp.size(); ++ j) {
                depth[u] = std::max(depth[u], tmp[j] + j + 1);
            }
            if (u) {
                deg[a[u]] --;
                if (!deg[a[u]]) {
                    queue.push(a[u]);
                }
            }
        }
        printf("%d\n", depth[0]);
    }
}

Measured memory_bytes: 6912
#include<bits/stdc++.h>
using namespace std;
long long int F(long long int a,long long int b)
{
	int ta=0,tb=0;
	while(a>0)
	{
		a/=10;
		ta++;
	}
	while(b>0)
	{
		b/=10;
		tb++;
	}
	return ta>ta ? ta : tb;
}
int main()
{
	long long int n;
	cin>>n;
	long long int a,b,min=0x7fffffff;
	for(int i=1;i<=sqrt(n);i++)
	{
		if(n%i!=0)
		{
			continue;
		}
		a=i;
		b=n/i;
		if(F(a,b)<min)
		{
			min=F(a,b);
		}
	}
	cout<<min;
	return 0;
}

Measured memory_bytes: 256
using System;

public class Hello
{
    public static void Main()
    {
        string[] line = Console.ReadLine().Trim().Split(' ');
        var n = int.Parse(line[0]);
        var c = int.Parse(line[1]);
        var cmap = new int[c, c];
        for (int i = 0; i < c; i++)
        {
            line = Console.ReadLine().Trim().Split(' ');
            for (int j = 0; j < c; j++)
                cmap[i, j] = int.Parse(line[j]);
        }
        var map = new int[3, c];
        for (int i = 0; i < n; i++)
        {
            line = Console.ReadLine().Trim().Split(' ');
            for (int j = 0; j < n; j++)
            {
                var w = int.Parse(line[j]) - 1;
                map[(i + j + 2) % 3, w]++;
            }
        }
        Console.WriteLine(getAns(cmap, map));
    }
    public static int getAns(int[,] cmap, int[,] map)
    {
        var c = cmap.GetLength(0);
        var ret = 999999999; int cost;
        for (int i = 0; i < c; i++)
            for (int j = 0; j < c; j++)
                for (int k = 0; k < c; k++)
                    if (i != j && j != k && k != i)
                    {
                        cost = 0;
                        for (int L = 0; L < c; L++)
                            cost += map[0, L] * cmap[L, i] + map[1, L] * cmap[L, j] + map[2, L] * cmap[L, k];
                        ret = Math.Min(ret, cost);
                    }
        return ret;
    }
}


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

#define PI 3.141592653589793238462643383279502L

int main() {
  int a, b, h, m;
  cin >> a >> b >> h >> m;

  // double h_angle = (360.0 / 12.0 * h) + (360.0 / 12.0 * m / 60.0);
  // double m_angle = 360.0 / 60.0 * m;
  // double angle = abs(h_angle - m_angle);
  // double radian = angle * PI / 180.0;

  // double c_squared = pow(a, 2) + pow(b, 2) - 2 * a * b * cosl(radian);
  // double c = sqrt(c_squared);

  long double rad = PI * 2 * (
      (long double)h / 12.0 + ((long double)(m / 60.0)  / 12.0) - (long double)m / 60.0
    );
  long double rsq = (long double)(a * a + b * b) - (long double)(2 * a * b * cosl(rad));
  long double ans = sqrtl(rsq);

  // cout << "M_PI      : " << M_PI << endl;
  // cout << "h_angle   : " << h_angle << endl;
  // cout << "m_angle   : " << m_angle << endl;
  // cout << "angle     : " << angle << endl;
  // cout << "radian    : " << radian << endl;
  // cout << "c_squared : " << c_squared << endl;
  cout.precision(20);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 4144
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define SORT(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
int main()
{
	while(1)
	{
		int n,k;
		cin >> n >> k;
		if(n==0&&k==0)break;
		int ans=0;
		set<string> st;
		vector<string> vec;
		for(int i=0;i<n;i++)
		{
			string s;
			cin >> s;
			vec.pb(s);
		}
		int comb=(1<<k)-1;
		while(comb<(1<<n))
		{
			string str;
			vector<int> num;
			for(int i=0;i<n;i++)
			{
				if((comb>>i)&1)
				{
					num.pb(i);
				}
			}
			do
			{
				str.clear();
				for(int i=0;i<num.size();i++)
				{
					str+=vec[num[i]];
				}
				if(st.find(str)==st.end())
				{
					st.insert(str);
					ans++;
				}
			}while(next_permutation(num.begin(),num.end()));
			int x=comb&-comb,y=comb+x;
			comb=((comb&~y)/x>>1)|y;
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 1484
alpha = {'A': 10,
         'B': 11,
         'C': 12,
         'D': 13,
         'E': 14,
         'F': 15
         }
S = input().split()
X, Y = S[0], S[1]
if alpha[X] < alpha[Y]:
    print('<')
elif alpha[X] > alpha[Y]:
    print('>')
else:
    print('=')


Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<iomanip>
#define sqr(x) (x)*(x)
using namespace std;
int n,m,i,j,k,dp[5005][5005],num[5005],ans,l,r,mid,pre[5005];
//vector<int> can[5005];
bool check(int x)
{
	if (x<=0) return 1;
	if (x>n) return 0;
	int i;
	for (i=0;i<m;i++)
	{
		if (dp[n-x][i]&&i+pre[n]-pre[n-x]>=m)
		{
			return 0;
		}
	}
	return 1;
}
int main()
{
	cin>>n>>m;
	for (i=1;i<=n;i++)
	{
		cin>>num[i];
		if (num[i]>=m)
		{
			i--;
			n--;
		}
	}
	/*dp[0][0][0]=1;
	for (i=1;i<=n;i++)
	{
		for (j=1;j<=m;j++) dp[i][j][0]=dp[i-1][j][0];
		for (j=num[i];j<=m;j++)
		{
			dp[i][j][0]=dp[i][j][0]||dp[i-1][j-num[i]][0];
		}
	}
	dp[n+1][0][1]=1;
	for (i=n;i>=1;i--)
	{
		for (j=1;j<=m;j++) dp[i][j][1]=dp[i+1][j][1];
		for (j=num[i];j<=m;j++)
		{
			dp[i][j][1]=dp[i][j][1]||dp[i+1][j-num[i]][1];
		}
		//for (j=1;j<=m;j++) if (dp[i][j][1]) can[i].push_back(j);
	}
	bool ok;
	for (i=1;i<=n;i++)
	{
		ok=0;
		for (j=1;j<=m;j++)
		{
			if (!dp[i-1][j][0]) continue;
			for (k=m-num[i]-j;k<=m-j;k++)
			{
				if (!dp[i+1][k][1]) continue;
				if (j+k<m&&j+k+num[i]>=m)
				{
					ok=1;
					break;
				}
			}
			if (ok) break;
		}
		ans+=!ok;
	}*/
	sort(num+1,num+n+1);
	reverse(num+1,num+n+1);
	for (i=1;i<=n;i++) pre[i]=pre[i-1]+num[i];
	dp[0][0]=1;
	for (i=1;i<=n;i++)
	{
		for (j=0;j<=m;j++) dp[i][j]=dp[i-1][j];
		for (j=num[i];j<=m;j++)
		{
			dp[i][j]=dp[i][j]||dp[i-1][j-num[i]];
		}
	}
	l=-1;r=n+1;
	while (l<r)
	{
		mid=(l+r)/2;
		if (check(mid))
		{
			ans=mid;
			l=mid+1;
		}
		else r=mid;
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 98176
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int k,a,b,fl=0;
  cin>>k>>a>>b;

  for(int i=a; i<=b; i++){
    if(i%k==0)fl=1;
  }

  if(fl==1)cout<<"OK"<<'\n';
  else cout<<"NG"<<'\n';

  return 0;
}


Measured memory_bytes: 3632
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const long double EPS=1e-9;
const long double PI=acos(-1.0);
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}
long double ABS(long double a){return max(a,-a);}
char in[110000];
long long pw(long long a,long long b){
	long long ret=1;
	while(b){
		if(b%2)ret=ret*a%mod;
		a=a*a%mod;
		b/=2;
	}
	return ret;
}
int main(){
	scanf("%s",in);
	long long ret=0;
	int n=strlen(in);
	int cnt=0;
	for(int i=0;i<n;i++)cnt+=in[i]-'0';
	long long ks=1;
	for(int i=0;i<n;i++){
		cnt-=in[i]-'0';
		if(in[i]=='1'){
			
			ret=(ret+ks*pw(3,n-i-1))%mod;
			ks=ks*2%mod;
		}
	}
	ret=(ret+ks)%mod;

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

Measured memory_bytes: 256
#include "bits/stdc++.h"
#include <sys/timeb.h>
#include <fstream>

using namespace std;

#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define replrev(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define reprev(i,n) replrev(i,0,n)
#define repi(itr,ds) for(auto itr = ds.begin(); itr != ds.end(); ++itr)
#define mp make_pair
#define INF 2000000000
#define INFL 2000000000000000000LL
#define EPS 1e-9
#define MOD 1000000007
#define PI 3.1415926536
#define RMAX 4294967295
typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<double> vd;
typedef vector<P> vP;
typedef vector<vector<int> > vvi;
typedef vector<vector<ll> > vvll;
typedef vector<vector<char> > vvc;
typedef vector<vector<P> > vvP;
typedef priority_queue<int, vector<int>, greater<int> > pqli;
typedef priority_queue<P, vector<P>, greater<P> > pqlP;
typedef pair<int, pair<int, int> > Edge;

int main() {
	int x;
	cin >> x;
	if (x < 0)x = -x;
	ll num = 0;
	repl(i, max(0, (int)sqrt((ll)2*x) - 10), x + 1) {
		num = (ll)i * (i + 1) / 2;
		if (num >= x) {
			cout << i << endl;
			return 0;
		}
	}

	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <vector>
#include <utility>
using namespace std;
typedef pair<int, int> ii;
int main() {
	int N, A, x, y, trueans = 0;
	scanf("%d", &N);
	vector<ii> testimony[N];
	for (int i = 0; i < N; ++i) {
		scanf("%d", &A);
		for (int j = 0; j < A; ++j) {
			scanf("%d %d", &x, &y);
			testimony[i].push_back(ii(x - 1, y));
		}
	}
	for (int i = 0; i < (1 << N); ++i) {
		bool itworks = true;
		int ans = 0;
		for (int j = 0; j < N; ++j) {
			if (i & (1 << j)) {
				++ans;
				for (ii k: testimony[j]) {
					if ((bool) (i & (1 << k.first)) != (bool) k.second) itworks = false;
				}
			}
		}
		if (itworks) trueans = max(trueans, ans);
	}
	printf("%d", trueans);
	return 0;
}


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

int main() {
	int N;
  int a, b, c, d;
  
	cin >> N;
  a = N/1000;
  b = (N-1000*a)/100;
  c = (N-1000*a - 100*b)/10;
  d = N-1000*a - 100*b - 10*c;
  
  if ((a == b && b == c) || (b == c && c ==d))
	cout << "Yes" << endl;
  else 
    cout << "No" << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define ll long long
#define all(a) a.begin(),a.end()
#define endl '\n'
#define int ll

using namespace std;

const int N = 3e5 + 3;
const int inf = 1e9 + 3;
const int md = 1e9 + 7;

string s;

bool pal(int l, int r) {
    for(int i = 0; i <= r - l; ++i) {
        if(s[l + i] != s[r - i]) return false;
    }
    return true;
}

bool f(string s) {
    int len = s.size();
    return pal(0, s.size() - 1) && pal(0, (len - 1) / 2 - 1) && pal((len + 3) / 2 - 1, s.size() - 1);
}

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

    double s;
    cin >> s;
    s /= 3;
    cout << fixed;
    cout << setprecision(10);
    cout << s * s * s;

}


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

using namespace std;

long long n, h[100010], dp[100010];

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	cin >> n;
	for(long long i = 1; i <= n; i++) {
		cin >> h[i];
	}
	dp[1] = 0;
	dp[2] = abs(h[2] - h[1]);
	for(long long i = 3; i <= n; i++) {
		dp[i] = min(dp[i-1] + abs(h[i] - h[i-1]), dp[i-2] + abs(h[i] - h[i-2]));
	}
	cout << dp[n] << endl;
}


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

int main() {
	int n;
	cin>>n;
	int a[n];
	map<int,int> mp1,mp2;
	for(int i=0;i<n;i++)
	{
		int x;
		cin>>x;
		mp1[x]=i;
		a[i]=x;
	}
	sort(a,a+n);
	for(int i=0;i<n;i++)
	{
		mp2[a[i]]=i;
	}
	int c=0;
	for(auto it1=mp1.begin(),it2=mp2.begin();it1!=mp1.end() && it2!=mp2.end();it1++,it2++)
	{
		if(it1->second%2==0 && it2->second%2==1)
		{
			c++;
		}
	}
	cout<<c<<endl;
	return 0;
}

Measured memory_bytes: 9984
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<ll>>;

template<class T>
void chmax(T &a, T b)
{
	if (a < b) a = b;
}

Graph G;
ll N, M;
vector<ll> x, y;
ll dp[100010];

ll solve(ll v)
{
	if (dp[v] != -1) return dp[v];

	ll res{0};
	for (auto &nv : G[v])
	{
		chmax(res, solve(nv)+1);
	}
	return dp[v] = res;
}

int main(int argc, char **argv)
{
	cin >> N >> M;
	x.resize(M), y.resize(M);

	G.resize(N, vector<ll>());
	for (ll i = 0; i < M; ++i)
	{
		ll a, b; cin >> a >> b; --a, --b;
		G[a].push_back(b);
	}

	for (ll i = 0; i < N; ++i) dp[i] = -1;

	ll res{0};
	for (ll i = 0; i < N; ++i) chmax(res, solve(i));
	std::cout << res << std::endl;
}



Measured memory_bytes: 10112
import java.io.IOException;
import java.util.ArrayList;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {
		Scanner sc = new Scanner(System.in);
		while (true) {
			int n = sc.nextInt();
			if (n == 0) {
				sc.close();
				break;
			}
			int l = sc.nextInt();

			char[] dir = new char[n];
			int[] place = new int[n];
			for (int i = 0; i < n; i++) {
				dir[i] = sc.next().charAt(0);
				place[i] = sc.nextInt();
			}

			int time = 0;
			while (true) {
				time++;
				for (int i = 0; i < n; i++) {
					if (place[i] < 1 && place[i] >= l) {
						continue;
					}
					if (dir[i] == 'R') {
						place[i]++;
					} else {
						place[i]--;
					}
				}

				ArrayList<Integer> inside = new ArrayList<Integer>();
				for (int p = 1; p < l; p++) {
					ArrayList<Integer> list = new ArrayList<Integer>();
					for (int ant = 0; ant < n; ant++) {
						if (place[ant] == p) {
							list.add(ant);
							inside.add(ant);
						}
					}

					// ぶつかった奴は向きを変える
					if (list.size() >= 2) {
						for (Integer ant : list) {
							if (dir[ant] == 'R') {
								dir[ant] = 'L';
							} else {
								dir[ant] = 'R';
							}
						}
					}
				}

				if (inside.size() == 1) {
					// 最後に残っているアリが1匹いた場合
					int ant = inside.get(0);
					if (dir[ant] == 'R') {
						// 右向きならtimeにplace[ant]がlになるまでの時間を足す
						int rest = l - place[ant];
						System.out.println((time + rest) + " " + (ant + 1));
					} else {
						// 左向きならtimeにplace[ant]が0になるまでの時間を足す
						System.out.println((time + place[ant]) + " "
								+ (ant + 1));
					}
					break;
				} else if (inside.size() == 2) {
					int antL = inside.get(0);
					int antR = inside.get(1);

					if (dir[antL] == 'L' && place[antL] == 1
							&& dir[antR] == 'R' && place[antR] == l - 1) {
						// 2匹同時退出の場合、左側のアリを出力
						System.out.println((time + 1) + " " + (antL + 1));
						break;
					}
				}

			}

		}

	}
}

Measured memory_bytes: 43572
<?php
    $max = 0;
    $count = 0;
    $rec = [];

    $rec = str_split(fgets(STDIN));

    foreach ($rec as $k => $v){
        if ($v == "R")
            $count++;
        else
            $count = 0;
        if ($count > $max)
            $max = $count;
    }
    printf("$max");
?>


Measured memory_bytes: 16256
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include<iostream>
#include<cstdint>
#include<vector>
#include<cstdlib>
#include<algorithm>
#include<cassert>
using namespace std;
using i32 = int_fast32_t;
using i64 = int_fast64_t;
#define rep(i, n) for (i32 i = 0; i < (i32)(n); i++)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
using P = pair<i64,i64>;
using i64 = int_fast64_t;
constexpr i64 MAX = 10000000;
constexpr i64 MOD = 1000000007;
i64 fac[MAX], finv[MAX], inv[MAX];
template <i64 modulus>
class modcal
{

public:
  i64 a;

  constexpr modcal(const i64 x = 0) noexcept : a(x % modulus) {}
  constexpr i64 &value() noexcept { return a; }
  constexpr const i64 &value() const noexcept { return a; }
  constexpr modcal operator+(const modcal rhs) const noexcept
  {
    return modcal(*this) += rhs;
  }
  constexpr modcal operator-(const modcal rhs) const noexcept
  {
    return modcal(*this) -= rhs;
  }
  constexpr modcal operator*(const modcal rhs) const noexcept
  {
    return modcal(*this) *= rhs;
  }
  constexpr modcal operator/(const modcal rhs) noexcept
  {
    return modcal(*this) /= rhs;
  }
  constexpr modcal &operator+=(const modcal rhs) noexcept
  {
    a += rhs.a;
    if (a >= modulus)
    {
      a -= modulus;
    }
    return *this;
  }
  constexpr modcal &operator-=(const modcal rhs) noexcept
  {
    if (a < rhs.a)
    {
      a += modulus;
    }
    a -= rhs.a;
    return *this;
  }
  constexpr modcal &operator*=(const modcal rhs) noexcept
  {
    a = a * rhs.a % modulus;
    return *this;
  }
  constexpr modcal &operator/=(modcal rhs) noexcept
  {
    i64 exp = modulus - 2;
    while (exp)
    {
      if (exp % 2)
      {
        *this *= rhs;
      }
      rhs *= rhs;
      exp /= 2;
    }
    return *this;
  }

  void COMninit()
  {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++)
    {
      fac[i] = fac[i - 1] * i % modulus;
      inv[i] = MOD - inv[modulus % i] * (modulus / i) % modulus;
      finv[i] = finv[i - 1] * inv[i] % modulus;
    }
  }
  i64 COMn(i64 n, i64 k)
  {
    if (n < k)
      return 0;
    if (n < 0 || k < 0)
      return 0;
    return fac[n] * (finv[k] * finv[n - k] % modulus) % modulus;
  }
  constexpr modcal<1000000007> modpow(const modcal<1000000007> &a, i64 n)
  {
    if (n == 0)
      return 1;
    auto t = modpow(a, n / 2);
    t = t * t;
    if (n & 1)
      t = t * a;
    return t;
  }
};
using modc = modcal<1000000007>;

int main(){
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    i32 n, k;
    cin >> n >> k;
    vector<i32> a(n);
    rep(i, n) {
        cin >> a[i];
    }
    sort(all(a));
    modc ans = 0;
    ans.COMninit();
    rep(i,n){
        modc now = ans.COMn(i,k - 1);
        ans += now * a[i];
    }
    sort(rall(a));
    rep(i,n){
        modc now = ans.COMn(i,k - 1);
        now = now;
        ans += now * -a[i];
    }
    cout << ans.a << endl;
}

Measured memory_bytes: 238396
#include <cstdio>
#include <algorithm>

using namespace std;

int v[100010];

int gcd(int a,int b)
{
    int r=a%b;
    while(r)
    {
        a=b;b=r;
        r=a%b;
    }
    return b;
}

int main()
{
    //freopen("file.in", "r" ,stdin);
    //freopen("file.out", "w", stdout);
    int n,k,maxx=0;
    scanf("%d%d",&n,&k);
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&v[i]);
        maxx=max(maxx,v[i]);
    }
    int a=v[1];
    for(int i=2;i<=n;i++) a=gcd(a,v[i]);
    if(k%a==0 && k<=maxx) printf("POSSIBLE");
    else printf("IMPOSSIBLE");
    return 0;
}


Measured memory_bytes: 512
lines = []
while line = gets
  lines << line.chomp.split(' ').map(&:to_i)
end

# pp lines

peoples = lines[0][0]
snacks = lines[0][1]

has_snack = []

lines.each_with_index do |l, index|
  next if index == 0

  if index % 2 == 0
    l.each do |l_2|
      has_snack << l_2
    end
  end
end

has_snack.uniq!

i = 1
result = []
peoples.times do
  if !has_snack.include?(i)
    result << i
  end
  i += 1
end

puts result.length

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


int main() {
    int k,n; cin >> k >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    int ans = k - a[n - 1] + a[0];
    rep(i,n - 1) ans = max(ans,a[i + 1] - a[i]);
    ans = k - ans;
    cout <<  ans << endl;
}

Measured memory_bytes: 1024
#include <stdio.h>
#include <string.h>
#include <math.h>
int main(void){
  int i,n;
  long int b;
  scanf("%d",&n);
  long int a[n];
  long int sum=0;
  for(i=0;i<n;i++){
    scanf("%ld",&b);
    a[i]=b;
  }
  for(i=1;i<n;i++){
    if(a[i]<a[i-1]){
      sum=sum+(a[i-1]-a[i]);
      a[i]=a[i-1];
    }
  } 

  printf("%ld",sum);
}

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

int main()
{
    long long l[2] = {2, 1};
    int n;
    scanf("%d", &n);
    for (int i = 2; i <= n; i++)
        l[i & 1] = l[i & 1] + l[!(i & 1)];
    printf("%lld\n", l[n  & 1]);

    return 0;
}

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

int main()
{
	int64_t n;
	cin >> n;

	int64_t ans = (1LL << 60);

	for (int64_t i = 1; i * i <= n; i++)
	{
		if (n % i == 0)
		{
			ans = min(ans, (i - 1) + (n / i - 1));
		}
	}

	cout << ans << endl;

	return 0;
}

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

int main(){
	int n;
	cin >> n;
	if(n==1) {cout << "Yes"; return 0;}
	vector<int> v(n);
	for(int i=0;i<n;i++){
		cin >> v[i];
	}
	for(int i = n-1;i>0;i--){
		if(v[i]<v[i-1]) v[i-1]--;
	}
	for(int i=0;i<n-1;i++){
		if(v[i]>v[i+1]) {cout << "No"; return 0;}
	}
	cout << "Yes";
 }


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = ll(A); I < ll(B); ++I)
#define FORR(I,A,B) for(ll I = ll((B)-1); I >= ll(A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //xi>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //xi>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd_(ll a,ll b){if(a%b==0)return b;return gcd_(b,a%b);}
ll lcm_(ll a,ll b){ll c=gcd_(a,b);return ((a/c)*(b/c)*c);}
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=ll(1e16)+ll(7);
const ll MOD=1000000007LL;
#define out(a) cout<<fixed<<setprecision((a))
//tie(a,b,c) = make_tuple(10,9,87);
#define pop_(a) __builtin_popcount((a))
ll keta(ll a){ll r=0;while(a){a/=10;r++;}return r;}
ll ketawa(ll a){ll r=0;while(a){r+=a%10;a/=10;}return r;}




int main(){

  int N;
  cin >> N;

  vector<int> dp(10010,0);

  dp[0] = 1;

  FOR(i,0,N){
    vector<int> t(10010,0);
    int s;
    cin >> s;
    FOR(j,0,10001){
      t[j] += dp[j];
      if(j+s<=10000) t[j+s] += dp[j];
    }
    dp = t;
  }

  int ans = 0;
  FOR(i,0,10001){
    if(i%10!=0 && dp[i])ans=max(ans,(int)i);
  }

  cout << ans << endl;

}


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

int main() {
 int N;
 cin >> N;
  vector<int> h(N);
  for(int i= 0;i<N;i++){
    cin >> h[i];
  }
  int res = 0;
  while(true){
    if(*max_element(h.begin(),h.end()) == 0)break;
    
    int i= 0;
    while(i<N){
      if(h[i] == 0) i++;
      else{
        res++;
        while(i<N && h[i]>0){
          h[i]--;
          i++;
        }
      }
    }
  }
   cout << res << endl; 
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
  int a,b,c;
  while(cin >> a >> b >> c && a!=-1||b!=-1||c!=-1){
    if(a==-1||b==-1)cout<<"F"<<endl;
    else if(a+b>=80)cout<<"A"<<endl;
    else if(a+b>=65)cout<<"B"<<endl;
    else if((a+b>=50)||(a+b>=30&&c>=50))cout<<"C"<<endl;
    else if(a+b>=30)cout<<"D"<<endl;
    else cout << "F" << endl;
  }
}


Measured memory_bytes: 3112
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class Program
{
    static void Main(string[] args)
    {
            // 入力
            string sS = Console.ReadLine().Trim();

            System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
            sw.Start();

            // 解析
            string sOut = "";
            for (int i = 0; i < sS.Length; i++)
            {
                string sO = sS.Substring(i, 1);
                switch (sO)
                {
                    case "0":
                    case "1":
                        sOut += sO;
                        break;
                    case "B":
                        if (sOut.Length > 0) { sOut = sOut.Substring(0, sOut.Length - 1); }
                        break;
                }
            }

            // 出力
            Console.WriteLine("{0}", sOut.ToString());

            sw.Stop();
#if DEBUG
            Console.WriteLine();
            Console.WriteLine("{0}", sw.Elapsed.ToString());
            Console.WriteLine("続行するには何かキーを押してください．．．");
            Console.ReadKey();
#endif
    }
}


Measured memory_bytes: 13268
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <queue>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <climits>
//#include "h.h"
using namespace std;

#define ll long long
#define pint pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define mp make_pair
#define pm(first, second) pb(mp(first, second))
#define SPACE " "
#define fpf first.first
#define fps first.second
#define spf second.first
#define sps second.second

#define all(X) (X).begin(), (X).end()

int main(){

	int N;
	cin >> N;
	vector<string> S(N);
	//vector<bool> lb(N), ra(N), lbra(N);
	int lb = 0, ra = 0, lbra = 0;
	int cnt = 0;
	for(int i = 0; i < N; i ++){
		cin >> S[i];
		//lb[i] = (S[i][0] == 'B' && S[i][S[i].size() - 1] != 'A');
		if(S[i][0] == 'B' && S[i][S[i].size() - 1] != 'A')lb ++;
		//ra[i] = (S[i][0] != 'B' && S[i][S[i].size() - 1] == 'A');
		if(S[i][0] != 'B' && S[i][S[i].size() - 1] == 'A')ra ++;
		//lbra[i] = (S[i][0] == 'B' && S[i][S[i].size() - 1] == 'A');
		if(S[i][0] == 'B' && S[i][S[i].size() - 1] == 'A')lbra ++;
		for(int j = 0; j < S[i].size() - 1; j ++){
			if(S[i][j] == 'A' && S[i][j + 1] == 'B')cnt ++;
		}
	}
	cnt += max(0, lbra - 1);
	//cout << lb << " " << ra << endl;
	if(lbra > 0 && lb > 0){
		lb --;
		cnt ++;
	}
	if(lbra > 0 && ra > 0){
		ra --;
		cnt ++;
	}
	cnt += max(0, min(lb, ra));
	cout << cnt << endl;

	return 0;
}

Measured memory_bytes: 768