akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>

int main (int argc, char* argv[]) {
  int n;
  scanf("%d", &n);

  int p[n];
  for (int i = 0; i < n; i++) {
    scanf("%d", &p[i]);

  }

  int cnt = 0;
  for (int i = 0; i < n - 2; i++) {
    if (p[i] < p[i+1] && p[i+1] < p[i+2]) {
      cnt++;
    } else if (p[i] > p[i+1] && p[i+1] > p[i+2]) {
      cnt++;
    }
  }

  printf("%d\n", cnt);
  return 0;
}


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

# 入力を整数に変換して受け取る
def input_int():
    return int(input())


# マイナス1した値を返却
def int1(x):
    return int(x) - 1


# 半角スペース区切り入力をIntに変換してMapで受け取る
def input_to_int_map():
    return map(int, input().split())


# 半角スペース区切り入力をIntに変換して受け取る
def input_to_int_tuple():
    return tuple(map(int, input().split()))


# 半角スペース区切り入力をIntに変換してマイナス1した値を受け取る
def input_to_int_tuple_minus1():
    return tuple(map(int1, input().split()))


def main():
    n, m = input_to_int_map()
    ab = [input_to_int_tuple() for i in range(m)]

    from collections import defaultdict
    room = defaultdict(set)
    for a, b in ab:
        room[a].add(b)
        room[b].add(a)


    from collections import deque
    root = deque()
    root.append(1)
    moved = [-1] * n
    moved[0] = 0
    while root:
        room_no = root.popleft()
        for move_room_no in room[room_no]:
            if moved[move_room_no - 1] != -1:
                continue

            root.append(move_room_no)
            moved[move_room_no - 1] = room_no

    if min(moved) == -1:
        print("No")
    else:
        print("Yes")
        for i in moved[1:]:
            print(i)


if __name__ == "__main__":
    main()


Measured memory_bytes: 144896
n,t=map(int,input().split())
a=list(map(int,input().split()))
v=[[a[0],a[0]+t]]
for i in a[1:]:
  if i<=v[-1][1]:v[-1][1]=i+t
  else:v.append([i,i+t])
print(sum(j-i for i,j in v))

Measured memory_bytes: 25200
#include<bits/stdc++.h>
typedef long long i64;
const int N=3e5+10,mod=998244353;
int n,ans,p[N],cnt[N],vis[N];
int length(int u){vis[u]=1;return vis[p[u]]?1:length(p[u])+1;}
inline int fpow(int a,int b){int s=1;for(;b;b>>=1,a=(i64)a*a%mod)if(b&1)s=(i64)s*a%mod;return s;}
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%d",&p[i]);
	for(int i=1;i<=n;i++)if(!vis[i])cnt[length(i)]++;
	if(!cnt[1]&&!cnt[2]){puts("0"); return 0;}
	if(!cnt[1])for(int i=1;i<=n;i+=2)if(cnt[i]){puts("0"); return 0;}
	for(int i=1,j,w;i<=n;i++)if(cnt[i]){
		if(i==1)ans=cnt[i]==1?1:fpow(cnt[i],cnt[i]-2);
		else if(i==2&&!cnt[1])ans=(i64)fpow(cnt[i],cnt[i]-1)*fpow(i,cnt[i]-1)%mod;
		else{
			for(w=0,j=1;j*j<=i;j++)if(!(i%j))w=(w+(i64)j*cnt[j])%mod;
			for(j=2;j*j<i;j++)if(!(i%j))w=(w+(i64)(i/j)*cnt[i/j])%mod;
			ans=(i64)ans*w%mod*fpow((w+(i64)i*cnt[i])%mod,cnt[i]-1)%mod;
		}
	}
	printf("%d\n",ans);
}


Measured memory_bytes: 5592
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i = (a); i <= (b); i++)
#define rng(a) a.begin(), a.end()
#define ina(n,a) cin >> n; for(int i = 1; i <= n; i++) cin >> a[i]
#define sz(x) (int)(x).size()
#define se second
#define fi first
#define prev            coyhhhhhhyoc    
#define next          sdNNNmNNNNNNNmds  
#define y0           hNNNNy_yNNNNNN_sNh
#define y1          mNNNNNdtdNNNNNNtsNNm
#define yn          mNNNNNNNNy___smNNNms
#define tm            oooooosyysooooot 
#define read               tyhyt        
#define rank              ytmNmo         
#define index              yyy
#define pb push_back
#define pcnt __builtin_popcountll
#define rrep(i,a,b) for(int i = (b); i >= (a); i--)
#define rall(x,a) for(auto x : a)
#define MOD 1000000007
#define endl "\n"
typedef long long ll;
using namespace std;

struct Pt {
    int x, y, cross;
};
bool operator<(const Pt& p, const Pt& q) {
    return p.y < q.y;
}

const int N = 111;
Pt pts[N << 1];
int n;

bool comp(const Pt& p, const Pt& q) {
    return p.x < q.x;
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> n;
    rep(i, 1, n) {
        cin >> pts[i].x >> pts[i].y;
        pts[i].cross = false;
    }
    rep(i, n + 1, 2 * n) {
        cin >> pts[i].x >> pts[i].y;
        pts[i].cross = true;
    }
    n *= 2;
    sort(pts + 1, pts + n + 1, comp);
    int ans = 0;
    set<int> st;
    rep(i, 1, n) {
        if(pts[i].cross) {
            set<int>::iterator it = st.lower_bound(pts[i].y);
            if(it != st.begin()) {
                --it;
                ans++;
                st.erase(it);
            }
        } else {
            st.insert(pts[i].y);
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
const int INF=2000000000;
const int MAX_V=100;
int V,E;
int G[MAX_V][MAX_V];
int dp[MAX_V][MAX_V];
int min(int a,int b){
  if(a>b)return b;
  else return a;
}
void warshall_floyd(){
  for(int k=0;k<V;k++){
    for(int j=0;j<V;j++){
      for(int i=0;i<V;i++){
	if(dp[i][k]!=INF && dp[k][j]!=INF)dp[i][j]=min(dp[i][j] , dp[i][k]+dp[k][j]);
      }
    }
  }
}

int main(){
  scanf("%d %d",&V,&E);
  
  fill(dp[0],dp[0]+10000,INF);
  for(int i=0;i<E;i++){
    int s,t,c;
    scanf("%d %d %d",&s,&t,&c);
    dp[s][t]=c;
  }
  for(int i=0;i<V;i++)dp[i][i]=0;
  warshall_floyd();
  for(int i=0;i<V;i++){
    if(dp[i][i]<0){printf("NEGATIVE CYCLE\n");
      return 0;
    }
  }
  for(int i=0;i<V;i++){
    for(int j=0;j<V;j++){
      if(dp[i][j]==INF)printf("INF");
      else printf("%d",dp[i][j]);
      if(j<V-1)printf(" ");
    }
    printf("\n");
  }
  return 0;
}

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

int main()
{
  int n, max=0, max2=-1;
  cin>>n;
  int a[n];
  for(int i=0; i<n; i++)
    cin>>a[i];
  max=a[0];
  if(a[1]>a[0])
  {
    max2=max;
    max=a[1];
  }
  else
  {
    max2=a[1];
  }
  for(int i=2; i<n; i++)
  {
    if(a[i]>=max)
    {
      max2=max;
      max=a[i];
    }
    else if(a[i]>max2)
    {
      max2=a[i];
    }
  }
  for(int i=0; i<n; i++)
  {
    if(a[i]<max) cout<<max<<endl;
    else cout<<max2<<endl;
  }
  return 0;
}

Measured memory_bytes: 2432
#!/usr/bin/python

import sys

def sum_digit(number):
    s = 0
    for digit in str(number):
        s += int(digit)
    return s

def main(argv):
    line = sys.stdin.readline()
    while line:
        N, A, B = map(lambda x: int(x), line.rstrip("\n").split(" "))

        s = 0
        for i in xrange(N + 1):
            s_d = sum_digit(i)
            if s_d >= A and s_d <= B:
                s += i
        print s

        line = sys.stdin.readline()

if __name__ == "__main__":
    main(sys.argv)

Measured memory_bytes: 2568
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define MOD 1000000007
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
using P = pair<int,int>;

int main()
{
  int a,b,c,d,e;
  cin >> a >> b >> c >> d >> e;
  if(a==0){
    cout << 1 << endl;
  }
  if(b==0){
    cout << 2 << endl;
  }
  if(c==0){
    cout << 3 << endl;
  }
  if(d==0){
    cout << 4 << endl;
  }
  if(e==0){
    cout << 5 << endl;
  }
}

Measured memory_bytes: 3524
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int l = sc.nextInt();
		int r = sc.nextInt();
		int d = sc.nextInt();
		
		int cnt = 0;
		for (int i = l; i <= r; i++) {
			if (i % d == 0) cnt++;
		}
		
		System.out.println(cnt);
		
		sc.close();
	}
	
}



Measured memory_bytes: 26904
from itertools import combinations

begin_with = list('MARCH')
num_of_begin_with = [0] * 5

n = int(input())
for _ in range(n):
    s = input()
    if s[0] in begin_with:
        num_of_begin_with[begin_with.index(s[0])] += 1

num_of_begin_with = [i for i in num_of_begin_with if i != 0]
cnt = 0
for a, b, c in combinations(num_of_begin_with, 3):
    cnt += a * b * c

print(cnt)


Measured memory_bytes: 3060
n=int(input())
a=list(map(int,input().split()))
q=int(input())
bc=[list(map(int,input().split())) for _ in range(q)]
ans=sum(a)
from collections import Counter
ca=Counter(a)
for b,c in bc:
  if b in ca:
    ca[c]+=ca[b]
    ans+=(c-b)*ca[b]
    ca[b]=0
    print(ans)
  else:
    print(ans)


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

int main(){
	int n,k;
	cin>>n>>k;
	int h[n];
	for(int i=0;i<n;i++){
		cin>>h[i];
	}
	int dp[n];
	for(int i=0;i<n;i++){
		dp[i] = INT_MAX;
	}
	dp[0] = 0;
	dp[1] = abs(h[1]-h[0]);
	for(int i=2;i<n;i++){
		for(int j=1;j<=k;j++){
			if(i-j>=0){
				dp[i] = min(dp[i],dp[i-j]+abs(h[i]-h[i-j]));
			}
		}
	}
	cout<<dp[n-1]<<"\n";
	return 0;
}

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

void solve()
{
    int n,k;
    cin>>n>>k;

    vector<int> s(n),dp(k+1);
    for(int i=0;i<n;i++)cin>>s[i];

    for(int i=0;i<=k;i++){
        for(auto x:s){
            if(i>=x && !dp[i-x])dp[i]=1;
        }
    }

    cout<<(dp.back()?"First":"Second")<<endl;
}

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

    // while(n--)
    solve();

    return 0;
}

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

int main(){

  string S;
  cin >> S;

  for(int i = 0;i < (1 << 3);i++){

    int sum = stoi(S.substr(0,1));//ABCDのうちAを入れる.
    string s = "";

    for(int j = 0;j < 3;j++){
      if((i >> j) & 1){//1 → "+"

        s += "+";
        sum += stoi(S.substr(j+1,1));

      }
      else{//0 → "-"

        s += "-";
        sum -= stoi(S.substr(j+1,1));

      }
    }

    if(sum == 7){
      cout << S[0] << s[0] << S[1] << s[1] << S[2] << s[2] << S[3] << "=7" << endl;
      break;
    }

  }

}

Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using static MyIO;


public class A
{
	public static void Main()
	{
		string S1 = GetString().ToUpper();
		string S2 = GetString().ToUpper();
		string S3 = GetString().ToUpper();

		Console.WriteLine("{0}{1}{2}", S1[0], S2[0], S3[0]);
	}
}


public static class MyIO
{
	private static string[] args = null;
	private static int num = -1;
	private static int used = -1;

	private static string getArg()
	{
		if(used == num)
		{
			args = Console.ReadLine().Split(' ');
			num = args.Length;
			used = 0;
		}
		return args[used++];
	}

	public static int GetInt(){ return int.Parse(getArg()); }
	public static long GetLong(){ return long.Parse(getArg()); }
	public static double GetDouble(){ return double.Parse(getArg()); }
	public static string GetString(){ return getArg(); }
}

Measured memory_bytes: 13140
#include <iostream>
#include <math.h>
#include <numeric>
#include <vector>
#include <map>
#include <algorithm>

using namespace std;
#define n_max 10000
#define INF 10001000

#define rep(i,n) for(int i = 0; i < (n); i++)
#define rep2(i,a,n) for(int i = a; i < (n); i++)
#define in(a) cin >> a
#define out(a) cout << a << endl
typedef long long ll; 

bool light[10];
int ans = 0;
int k[10];
int p[10];
int s[10][10];
int m, n;

void print() {
    rep(i,m) { 
        if(light[i]) { cout << 1; }
        else         { cout << 0; }
    }
    cout << endl;
}

int solve() {

    int denkyu = 0;

    rep(i,m){
        int on = 0;
        rep(j, k[i]) {
            if(light[s[i][j]-1]) on++;
        }
        if(on%2 == p[i]) {denkyu++; }
    }

    if(denkyu == m) { ans++; }

    return 0;
}

int dp(int n){
    
    if(n < 0) { 
        //print(); 
        solve();
        return 0; 
    }
    light[n] = true;
    dp(n-1);
    light[n] = false;
    dp(n-1);
    return 0;
}


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

    rep(i,m) {
        cin >> k[i];
        rep(j,k[i]) {
            cin >> s[i][j];
        }
    }
    rep(i,m) { cin >> p[i]; } 

    dp(n-1);
    cout << ans << endl;
    return 0;
}


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

int main(void) {
    int64_t N,K;
    int64_t sum =0;
    cin >> N >> K;

    vector<int64_t> H(N);
    for(int i=0;i<N;i++) {
        cin >> H[i];
    }
    
    sort(H.begin(),H.end());
    for(int i=0;i<N-K;i++) {
        sum += H[i];
    }

    cout << sum << "\n";
    return 0;
}


Measured memory_bytes: 1792
from collections import Counter
from collections import deque
from functools import reduce
from pprint import pprint
import bisect
import copy
import fractions
import itertools
import math
import queue
import random
import sys
import time
from operator import mul
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def MI(): return map(int, sys.stdin.readline().split())
def II(): return int(sys.stdin.readline())
def IS(): return input()
def C(x): return Counter(x)
def GCD_LIST(numbers): return reduce(fractions.gcd, numbers)
def LCM_LIST(numbers): return reduce(LCM, numbers)
def LCM(m, n): return (m * n // fractions.gcd(m, n))
def COMBINATION(n, r):
    if n < 0 or r < 0 or n < r:
        return 0
    r = min(n-r, r)
    if r == 0:
        return 1
    o = reduce(mul, range(n, n - r, -1))
    u = reduce(mul, range(1, r + 1))
    return o // u
class UnionFind():

    def __init__(self, n):
        self.n = n
        self.node = [i for i in range(n)]
        self.size = [1 for _ in range(n)]

    def same(self, x, y):
        return bool(self.root(x) == self.root(y))

    def root(self, x):
        if self.node[x] == x:
            return x
        else:
            self.node[x] = self.root(self.node[x])  # 経路圧縮
            return self.node[x]

    def unite(self, x, y):
        x, y = self.root(x), self.root(y)
        if x == y:
            return  # 結合不要
        if self.size[x] < self.size[y]:
            x, y = y, x
        self.node[y] = x
        self.size[x] += self.size[y]

    def return_size(self, x):
        return self.size[self.root(x)]


n, k = MI()
for i in range(1, k + 1):
    print(COMBINATION(n-k+1, i) * COMBINATION(k-1, i-1) % MOD)


Measured memory_bytes: 75480
import bisect,sys
import math
from collections import deque

def sRaw():
    return input().rstrip("\r")


def iRaw():
    return int(input())


def ssRaw():
    return input().split()


def isRaw():
    return list(map(int, ssRaw()))

INF = 1 << 29

DIV = (10**9) + 7

def mod_inv_prime(a, mod=DIV):
    return pow(a, mod-2, mod)


def mod_inv(a, b):
    r = a
    w = b
    u = 1
    v = 0
    while w != 0:
        t = r//w
        r -= t*w
        r, w = w, r
        u -= t*v
        u, v = v, u
    return (u % b+b) % b


def CONV_TBL(max, mod=DIV):
    fac, finv, inv = [0]*max, [0]*max, [0]*max
    fac[0] = fac[1] = 1
    finv[0] = finv[1] = 1
    inv[1] = 1
    for i in range(2, max):
        fac[i] = fac[i-1]*i % mod
        inv[i] = mod - inv[mod % i] * (mod//i) % mod
        finv[i] = finv[i-1]*inv[i] % mod

    class CONV:
        def __init__(self):
            self.fac =fac
            self.finv = finv
            pass

        def ncr(self, n, k):
            if(n < k):
                return 0
            if(n < 0 or k < 0):
                return 0
            return fac[n]*(finv[k]*finv[n-k] % DIV) % DIV
        
    return CONV()



sys.setrecursionlimit(200005)


def main():
    N,M,Q = isRaw()
    abcds = [isRaw() for m in range(Q)]
    def dfs(As):
        if len(As)==N:
            cur = 0
            for abcd in abcds:
                a,b,c,d = abcd
                if As[b-1]-As[a-1] == c:
                    cur+=d
            return cur 
        tmp = 0
        for a in range(As[-1],M+1):
            tmp = max(dfs(As+[a]),tmp)
        return tmp
    return dfs([1])
    
if __name__ == "__main__":
    print(main())


Measured memory_bytes: 74148
#include <stdio.h>

int main(){
	int n=0;
	char str[10000];
	scanf("%d", &n);
	scanf("%s", &str);
	
	for(int i=0;str[i]!='\0';i++){
			str[i]+=n;
		if(str[i]>'Z'){
			str[i]-=26;
		}
		printf("%c", str[i]);
	}
	
	
	return 0;
}

Measured memory_bytes: 1668
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
ll p[30][50];

int main(){
	ll n;cin>>n;
	for(ll a=0;a<n;++a){
		string s;cin>>s;
		for(char ss:s)++p[ss-'a'][a];
	}
	for(ll a=0;a<26;++a){
		ll b=*min_element(p[a],p[a]+n);
		for(ll c=0;c<b;++c)printf("%c",a+'a');
	}
	return 0;
}


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

std::string S;

bool solve();

int main()
{
	std::cin >> S;
	if (solve()) puts("Yes");
	else puts("No");

	return 0;
}

bool solve()
{
	for (int i{}; i < (int)S.size(); i += 2)
		if (S[i] == 'L')
			return false;
	for (int i{1}; i < (int)S.size(); i += 2)
		if (S[i] == 'R')
			return false;
	return true;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define FRU freopen("out.txt","w",stdout)
#define FRO freopen("in.txt","r",stdin)
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define mem(ara,n) memset(ara,n,sizeof ara)
#define loop(i,j,n) for(i=j;i<n;i++)
#define rloop(i,j,n) for(i=n;i>=j;i--)
#define INF 2147483647
#define ll long long
#define pii pair<int,int>
#define eps 1e-9
#define mii map<int,int>
#define vi vector<int>
#define all(n) n.begin(),n.end()
#define inf INF
#define INFLL 9223372036854775807
using namespace std;
int main()
{
    int n,m,cnt=0,i,j,k;
    string s="-",s1;
    int a,b,c,d;
    cin>>n>>a>>b>>c>>d;
    cin>>s1;
    s+=s1;
    int ara[200005]={0};
    if(c>d)
    {
        int flag=0,flag1=0;
        for(i=a;i<=c;i++)
        {
            if(s[i]=='#'&& s[i-1]=='#')flag1=1;
        }
        if(s[b-1]=='.')ara[b-1]=1;
        for(i=b;i<=d;i++)
        {
            if(s[i]=='.')ara[i]=ara[i-1]+1;
            if(ara[i]>=3)flag=1;
        }
        if(s[d+1]=='.'&& ara[d]>1)flag=1;
        if(flag&& !flag1)cout<<"Yes\n";
        else cout<<"No\n";
    }
    else
    {
        int flag=0;
        for(i=a;i<=c;i++)
        {
            if(s[i]=='#'&& s[i-1]=='#')flag=1;
        }
        for(i=b;i<=d;i++)
        {
            if(s[i]=='#'&& s[i-1]=='#')flag=1;
        }
        /*if(c>b&& c<d)
        {
            if(s[c-1]=='#'|| s[c+1]=='#')flag=1;
        }*/
        if(!flag)cout<<"Yes\n";
        else cout<<"No\n";
    }

}


Measured memory_bytes: 1668
import java.util.Scanner;

public class Main {
	static int n;
	static String name;
	static String b[];
	static int cnt;

	public static boolean check(int i, int j, int k) {
		for (int l = 0; l < name.length(); l++) {
			if (b[i].length() <= j + k * l || name.charAt(l) != b[i].charAt(j + k * l)) {
				return false;
			}
		}
		return true;
	}

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		n = sc.nextInt();
		name = sc.next();
		b = new String[n];
		for (int i = 0; i < n; i++) {
			b[i] = sc.next();
		}
		cnt = 0;

		L1: for (int i = 0; i < n; i++) {
			for (int j = 0; j < b[i].length(); j++) {
				for (int k = 1; k < b[i].length(); k++) {
					if (check(i, j, k)) {
						cnt++;
						continue L1;
					}
				}
			}
		}
		
		System.out.println(cnt);
	}
}

Measured memory_bytes: 21568
List = [input() for _ in range(5)]

import math

unitsPlace = []
for i in range(5):
    if int(List[i][-1])!=0:
        unitsPlace.append(int(List[i][-1]))

if unitsPlace==[]:
    res = sum([int(List[i]) for i in range(5)])
    print(res)
else:
    minUnitsPlace = min(unitsPlace)
    
    ceilList = [math.ceil(int(List[j])/10)*10 for j in range(5)]
    res = sum(ceilList) + minUnitsPlace - 10
    
    print(res)

Measured memory_bytes: 3064
n = parse(Int, readline())
hs = [parse(Int, x) for x in split(readline(), " ")]

function watchable(hs)
    if length(hs) == 1
        return true
    end
    for i = 1:length(hs)-1
        if hs[i] > hs[end]
            return false
        end
    end
    true
end

count = 0
for i = 1:n
    if watchable(hs[1:i])
        count += 1
    end
end

print(count)

Measured memory_bytes: 164892
listA = [int(input()) for _ in range(5)]
listB = [(10 - (_ % 10)) % 10 for _ in listA]

idx = listB.index(max(listB))
time = 0

for i, data in enumerate(listA):
    if i == idx:
        continue
    else:
        if data % 10 == 0:
            time += data
        else:
            time += ((data // 10) + 1) * 10

time += listA[idx]
print(time)

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

inline std::complex<double> f(std::complex<double> a, std::complex<double> b, std::complex<double> c) {
  double eAB = abs(b - a);
  double eBC = abs(c - b);
  double eCA = abs(a - c);
  double aCAB = acos((eCA * eCA + eAB * eAB - eBC * eBC) / (2 * eCA * eAB));
  double aABC = acos((eAB * eAB + eBC * eBC - eCA * eCA) / (2 * eAB * eBC));
  double aBCA = acos((eBC * eBC + eCA * eCA - eAB * eAB) / (2 * eBC * eCA));
  double A = sin(2 * aCAB);
  double B = sin(2 * aABC);
  double C = sin(2 * aBCA);
  std::complex<double> ans;
  ans.real((A * a.real() + B * b.real() + C * c.real()) / (A + B + C));
  ans.imag((A * a.imag() + B * b.imag() + C * c.imag()) / (A + B + C));
  return ans;
}

int main() {
  int n;
  cin >> n;
  vector<double> x(n), y(n);
  for (int i = 0; i < n; i++) cin >> x[i] >> y[i];

  double r = 1e9;
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      double px = (x[i] + x[j]) / 2.0, py = (y[i] + y[j]) / 2.0;
      cerr << px << ' ' << py << endl;
      double t = 0;
      for (int l = 0; l < n; l++) {
        double tt = pow(x[l] - px, 2) + pow(y[l] - py, 2);
        if (tt > t) t = tt;
      }
      r = min(r, t);
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      for (int k = j + 1; k < n; k++) {
        auto p = f({x[i], y[i]}, {x[j], y[j]}, {x[k], y[k]});
        double px = p.real(), py = p.imag();
        // cerr << px << ' ' << py << endl;
        double t = 0;
        for (int l = 0; l < n; l++) {
          double tt = pow(x[l] - px, 2) + pow(y[l] - py, 2);
          if (tt > t) t = tt;
        }
        if (t == 0) continue;
        r = min(r, t);
      }
    }
  }

  cout << fixed << setprecision(9);
  cout << sqrt(r) << endl;
}


Measured memory_bytes: 512
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int n = Integer.parseInt(sc.next());
		int k = Integer.parseInt(sc.next());
		StringBuilder s = new StringBuilder(sc.next());
		s.insert(0, "X");
		s.insert(n + 1, "X");
		int cnt = 0;
		for (int i = 1; i <= n; i++) {
			if (s.substring(i, i + 1).equals("L")) {
				if (s.substring(i - 1, i).equals("L")) {
					cnt++;
				}
			} else {
				if (s.substring(i, i + 1).equals("R")) {
					if (s.substring(i + 1, i + 2).equals("R")) {
						cnt++;
					}
				}
			}
		}

		System.out.println(Math.min(cnt + (k * 2), n - 1));
		sc.close();
	}
}

Measured memory_bytes: 38240
#include<bits/stdc++.h>
using namespace std;
#define REP(i,n) for((i)=0;(i)<(int)(n);(i)++)
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;



int main(){
    int n, y;
    cin >> n >> y;
    int i, j, k;
    REP(i, n + 1)REP(j, n - i + 1){
        k = n - (i + j);
        if (10000 * i + 5000 * j + 1000 * k == y){
            cout << i << " " << j << " " << k << endl;
            return 0;
        }
    }

    cout << -1 << " " << -1 << " " << -1 << endl;
    
    return 0;
}

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

class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String S = sc.next();
    String T = sc.next();
    
    int count = 0;
    for (int i = 0; i < S.length(); i++) {
      if (S.charAt(i) == T.charAt(i)) {
        count++;
      }
    }
    
    System.out.println(count);
  }
}

Measured memory_bytes: 21716
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,b) for(int i=(a); i<(b); i++)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
typedef long long ll;
const int mod = 1e9+7;

struct mint {
  ll x;
  mint(ll x=0):x(x%mod){}
  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 {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=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 {
    mint res(*this);
    return res/=a;
  }
};

struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
} comb(100005);
 
mint f(int n, int k) {
  if (n < 0) return 0;
  // nPk = nCk * k!
  mint res = comb(n,k);
  res *= comb.fact[k];
  return res;
}
 
int k;
mint ans;
vector<int> g[100005];
void dfs(int v, int p = -1){
    for(int u : g[v]){
        if(u == p) continue;
        dfs(u,v);
    }
    int nk = (p == -1)? k : k-2;
    int c = (p == -1)? g[v].size()+1 : g[v].size()-1;
    ans *= f(nk, c);
}
int main(){
    int n; cin >> n >> k;
    rep(i,n-1){
        int a,b; cin >> a >> b; a--; b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    ans = 1;
    dfs(0);
    cout << ans.x << endl;
}


Measured memory_bytes: 10752
#include<stdio.h>
#include<string.h>
void main()
{
  long int i,a,count=0;
  char s[200001],t[200001];
  scanf("%s %s",s,t);
  a=strlen(s);
  for(i=0;i<a;i++)
  {
    if(s[i]!=t[i])
      count++;
  }
  printf("%ld",count);
}

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

int main() {
    int k;
    string s;
    cin >> k >> s;

    if (s.size() <= k) {
        cout << s << endl;
        return 0;
    }

    for (int i = 0; i < k; i++) {
        cout << s.at(i);
    }

    cout << "..." << endl;

}

Measured memory_bytes: 3628
#!/usr/bin/env python

from collections import deque, defaultdict
import itertools as ite
import sys
import math
from decimal import *

sys.setrecursionlimit(1000000)

INF = 10 ** 18
MOD = 10 ** 9 + 7

N = input()
P = map(int, raw_input().split())
cur = N + 1
ans = 0
for num in P:
    if num < cur:
        ans += 1
        cur = num
print ans

Measured memory_bytes: 21308
#include <stdio.h>
#include <string.h>

int  H, W, dp[2000][2000][4];
char S[2000][2000];

int rec(int y, int x, int dir) {
	if (x < 0 || y < 0 || x >= W || y >= H) {
		return 0;
	}
	else if (dp[y][x][dir] != -1) {
		return dp[y][x][dir];
	}
	else if (S[y][x] == '#') {
		return dp[y][x][dir] = 0;
	}
	else {
		switch (dir){
		case 0:
			return dp[y][x][dir] = 1 + rec(y, x - 1, dir);
			break;
		case 1:
			return dp[y][x][dir] = 1 + rec(y + 1, x, dir);
			break;
		case 2:
			return dp[y][x][dir] = 1 + rec(y, x + 1, dir);
			break;
		case 3:
			return dp[y][x][dir] = 1 + rec(y - 1, x, dir);
			break;
		}
	}
}

int main() {
	int i, j, k, max = 0, cnt;

	memset(dp, -1, sizeof(dp));
	scanf("%d %d", &H, &W);
	for (i = 0; i < H; i++) {
		scanf("%s", S[i]);
	}

	for (i = 0; i < H; i++) {
		for (j = 0; j < W; j++) {
			if (S[i][j] != '#') {
				cnt = 1;
				for (k = 0; k < 4; k++) {
					cnt = cnt + rec(i, j, k) - 1;
				}
				if (cnt > max) {
					max = cnt;
				}
			}
		}
	}

	printf("%d\n", max);

	return 0;
}

Measured memory_bytes: 66688
#include<bits/stdc++.h>
using namespace std;
using p = pair<int,long long>;
using ll = long long;
int main(){
  ll d,n;
  cin >> d >> n;

  ll s = pow(100,d);

  if(n==100){
    cout << s*101;
  }else{
    cout << s*n;
  }
  

}

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

#define N 4
#define N2 16

static const int dx[4] = {0, -1, 0, 1};
static const int dy[4] = {1, 0, -1, 0};
static const char dir[4] = {'r', 'u', 'l', 'd'};
int MDT[N2][N2];

struct Puzzle
{
  int f[N2], space, MD;
  int cost;

  bool operator<(const Puzzle &p) const
  {
    for (int i = 0; i < N2; i++)
    {
      if (f[i] == p.f[i])
      {
        continue;
      }
      return f[i] < p.f[i];
    }
    return false;
  }
};

struct State
{
  Puzzle puzzle;
  int estimated;
  bool operator<(const State &s) const
  {
    return estimated > s.estimated;
  }
};

int getAllMD(Puzzle pz)
{
  int sum = 0;
  for (int i = 0; i < N2; i++)
  {
    if (pz.f[i] == N2)
    {
      continue;
    }
    sum += MDT[i][pz.f[i] - 1];
  }

  return sum;
}

int astar(Puzzle s)
{
  priority_queue<State> PQ;
  s.MD = getAllMD(s);
  s.cost = 0;
  map<Puzzle, bool> V;
  Puzzle u, v;
  State initial;
  initial.puzzle = s;
  initial.estimated = getAllMD(s);
  PQ.push(initial);

  while (!PQ.empty())
  {
    State st = PQ.top();
    PQ.pop();
    u = st.puzzle;

    if (u.MD == 0)
    {
      return u.cost;
    }
    V[u] = true;

    int sx = u.space / N;
    int sy = u.space % N;

    for (int r = 0; r < 4; r++)
    {
      int tx = sx + dx[r];
      int ty = sy + dy[r];
      if (tx < 0 || ty < 0 || tx >= N || ty >= N)
      {
        continue;
      }
      v = u;

      v.MD -= MDT[tx * N + ty][v.f[tx * N + ty] - 1];
      v.MD += MDT[sx * N + sy][v.f[tx * N + ty] - 1];

      swap(v.f[sx * N + sy], v.f[tx * N + ty]);
      v.space = tx * N + ty;
      if (!V[v])
      {
        v.cost++;
        State news;
        news.puzzle = v;
        news.estimated = v.cost + v.MD;
        PQ.push(news);
      }
    }
  }
  return -1;
}

int main()
{
  for (int i = 0; i < N2; i++)
  {
    for (int j = 0; j < N2; j++)
    {
      MDT[i][j] = abs(i / N - j / N) + abs(i % N - j % N);
    }
  }

  Puzzle in;

  for (int i = 0; i < N2; i++)
  {
    cin >> in.f[i];
    if (in.f[i] == 0)
    {
      in.f[i] = N2;
      in.space = i;
    }
  }

  cout << astar(in) << endl;

  return 0;
}


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


Measured memory_bytes: 2004
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>
#include <complex>
static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

using ld = double;
using P = complex<ld>;
using G = vector<P>;
const ld pi = acos(-1);
const ld eps = 1e-10;
const ld inf = 1e12;

ld cross(const P& a, const P& b) { return a.real()*b.imag() - a.imag()*b.real(); }
ld dot(const P& a, const P& b) { return a.real()*b.real() + a.imag()*b.imag(); }

using C = pair<ld, P>;
#define rad first
#define pnt second

C smallest_enclosing_disc(vector<P> ps) {
    auto c3 = [](const P &a, const P &b, const P &c) {
        ld A = norm(b - c);
        ld B = norm(c - a);
        ld C = norm(a - b);
        ld S = abs(cross(b - a, c - a));
        P p = (A * (B + C - A) * a + B * (C + A - B) * b + C * (A + B - C) * c) / (4 * S * S);
        ld r = abs(p - a);
        return make_pair(r, p);
    };

    auto c2 = [](const P &a, const P &b) {
        P c = (a + b) / (ld) 2;
        ld r = abs(a - c);
        return make_pair(r, c);
    };

    auto in_circle = [](const P &a, const C &c) {
        return norm(a - c.pnt) <= c.rad * c.rad + eps;
    };

    int n = ps.size();
    random_shuffle(ps.begin(), ps.end());
    C c = c2(ps[0], ps[1]);
    for (int i = 2; i < n; ++i) {
        if (!in_circle(ps[i], c)) {
            c = c2(ps[0], ps[i]);
            for (int j = 1; j < i; ++j) {
                if (!in_circle(ps[j], c)) {
                    c = c2(ps[j], ps[i]);
                    for (int k = 0; k < j; ++k) {
                        if (!in_circle(ps[k], c)) {
                            c = c3(ps[i], ps[j], ps[k]);
                        }
                    }
                }
            }
        }
    }
    return c;
}
int main() {
    int n;
    cin >> n;
    vector<P> v(n);
    for (int i = 0; i < n; ++i) {
        double a, b;
        cin >> a >> b;
        v[i] = {a, b};
    }
    auto x = smallest_enclosing_disc(v);
    printf("%.15lf\n", x.first);
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.nextLine();
        System.out.println(invertCase(s));
    }

    private static String invertCase(String str) {
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < str.length(); i++) {
            if (Character.isUpperCase(str.charAt(i))) {
                sb.append(Character.toLowerCase(str.charAt(i)));
            } else {
                sb.append(Character.toUpperCase(str.charAt(i)));
            }
        }
        return sb.toString();
    }
}

Measured memory_bytes: 26076
fun main(args: Array<String>) {
    tenka1_2017c()
}

fun tenka1_2017c() {
    val N = readLine()!!.toLong()

    (1..3500L).forEach { h ->
        (1..3500L).forEach { n ->
            val m = (4 * h * n - N * (n + h))
            if (m > 0) {
                val w = (N * h * n) / (4 * h * n - N * (n + h))
                if (w > 0) {
                    if (4 * h * n * w == N * (n * w + h * w + h * n)) return println("$h $n $w")
                }
            }
        }
    }
}


Measured memory_bytes: 33696
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.Deque;

public class Main {

  public static void main(String[] args) {
    new Main().run();
  }

  public void run() {

    try(BufferedReader in = new BufferedReader(new InputStreamReader(System.in))) {


      String[] lines = in.readLine().split(" ");
      int[] arr = new int[lines.length];
      int k=0;
      for (String s : lines) {
        arr[k++] = Integer.parseInt(s); 
      }
      Arrays.sort(arr);
      int step=0;
      if(arr[2] - arr[1] > 2) {
        for(; arr[1]+2 < arr[2]; step++) {
          arr[1] += 2;
        }
      }
      if(arr[1] - arr[0] > 2) {
        for(; arr[0]+2 < arr[1]; step++) {
          arr[0] += 2;
        }
      }

      Tuple3 t = new Tuple3(arr[0], arr[1], arr[2]);
      t.step = step;

      System.out.println( bfs(t) );
    }
    catch(IOException e) {
      System.err.println(e);
    }
  }

  private int bfs(Tuple3 t) {
    Deque<Tuple3> que = new ArrayDeque<>();

    int ret=0;
    que.offer(t);

    Tuple3 cur;
    while(!que.isEmpty()) {
      cur = que.poll();

      if(cur.isEq()) {
        ret = cur.step;
        break;
      }

      if(cur.e[0] < cur.e[1] && cur.e[0] < cur.e[2]) {
        que.offer(new Tuple3(cur.e[0]+2, cur.e[1], cur.e[2]));
        que.peekLast().step = cur.step + 1;
      } else if(cur.e[1] < cur.e[2]) {
        que.offer(new Tuple3(cur.e[0], cur.e[1]+2, cur.e[2]));
        que.peekLast().step = cur.step + 1;
      } else {
        que.offer(new Tuple3(cur.e[0], cur.e[1], cur.e[2]+2));
        que.peekLast().step = cur.step + 1;
      }

      if(cur.e[0] < cur.e[2] && cur.e[1] < cur.e[2]) {
        que.offer(new Tuple3(cur.e[0]+1, cur.e[1]+1, cur.e[2]));
        que.peekLast().step = cur.step + 1;
      } else if(cur.e[1] < cur.e[0] && cur.e[2] < cur.e[0]) {
        que.offer(new Tuple3(cur.e[0], cur.e[1]+1, cur.e[2]+1));
        que.peekLast().step = cur.step + 1;
      } else {
        que.offer(new Tuple3(cur.e[0]+1, cur.e[1], cur.e[2]+1));
        que.peekLast().step = cur.step + 1;
      }
      
    }

    return ret;
  }

  class Tuple3 {
    int[] e;
    int step;

    public Tuple3(int a, int b, int c) {
      e = new int[3];
      e[0] = a;
      e[1] = b;
      e[2] = c;
      step = 0;
    }

    public boolean isEq() {
      return (e[0] == e[1]) && (e[1] == e[2]);
    }
  }
}

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

int main(){
  int x[4];
  cin >> x[0] >> x[1];
  x[2] = x[0] - 1; x[3] = x[1] - 1;
  sort(x, x+4, greater<int>());
  cout << x[0] + x[1] << endl;
  return 0;
}

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

M, S = 10 ** 9 + 7, H + W - 2
fact_n = [0 for i in range(S+1)]
fact_inv = [0 for j in range(S+1)]


def combination(n, r):
    if n == 0 and r == 0:
        return 1
    elif n < r or n < 0:
        return 0

    res = fact_n[n] * fact_inv[r] % M
    return res * fact_inv[n-r] % M


def main():
    fact_n[0] = fact_inv[0] = 1
    for i in range(1, S+1):
        fact_n[i] = fact_n[i-1] * i % M

    fact_inv[S] = pow(fact_n[S], M-2, M)
    for i in range(S-1, 0, -1):
        fact_inv[i] = fact_inv[i+1] * (i+1) % M

    com, bef = combination(S, H-1), 0
    for i in range(B):
        c1, c2 = combination(H-A+i, H-A), combination(S-H+A-i, A-1)
        tmp = (c1-bef) * c2 % M
        bef += c1 - bef
        com -= tmp
        if com < 0:
            com += M

    print(com)


if __name__ == '__main__':
    main()


Measured memory_bytes: 18968
#include<cstdio>
using namespace std;

int main(){
  int x1,x2,y1,y2;
  scanf("%d %d %d %d",&x1,&y1,&x2,&y2);
  //if(x1-x2==0)
    printf("%d %d %d %d\n",x2+(y1-y2),y2-(x1-x2),x1+(y1-y2),y1-(x1-x2));
  /*else if(y1-y2==0)
    printf("%d %d %d %d\n",x2,y2-(x1-x2),x1,y1-(x1-x2));*/
  
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define maxN 102
using namespace std;

int n, m;

double p, P;

double ans;

int main()
{
    scanf("%d %d", &n, &m);
    p = 1; P = 1;
    for (int i = 1; i <= m; ++ i)
        p = 0.5 * p;
    P = p;
    for (int nrTry = 1; ; ++ nrTry)
    {
        ans += P * 1900 * m * nrTry + 100 * (n - m) * nrTry * P;
        if (P * 1900 * m * nrTry < 0.00001)
            break;
        P = P * (1.0 - p);
    }
    printf("%d\n", (int)(ans + 0.01));
    return 0;
}


Measured memory_bytes: 256
import sys
from collections import deque
import bisect
import copy
import heapq
import itertools
import math
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
mod = 10 ** 9 + 7

def read_values(): return map(int, input().split())
def read_index(): return map(lambda x: int(x) - 1, input().split())
def read_list(): return list(read_values())
def read_lists(N): return [read_list() for n in range(N)]


def main():
    N = int(input())
    A = read_list()
    B = read_list()
    S = [10 ** 9] * N
    T = [1] * N

    r = 0
    for i ,a in enumerate(A):
        S[i] = min(S[i], a)
        if r < a:
            T[i] = max(T[i], a)
        r = a
    
    r = 0
    for j, b in enumerate(B[::-1]):
        i = N - 1 - j
        S[i] = min(S[i], b)
        if r < b:
            T[i] = max(T[i], b)
        r = b

    res = 1
    for s, t in zip(S, T):
        res *= max(0, s - t + 1)
        res %= mod
    print(res)


if __name__ == "__main__":
    main()


Measured memory_bytes: 96672
#include <iostream>
#include <cstdint>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <algorithm>
#include <iomanip>
#include <sstream>

int main(void)
{
    uint64_t A, B, C;

    std::cin >> A >> B >> C;

    int64_t count = 0;

    if (A == B) count++;
    if (A == C) count++;
    if (B == C) count++;

    std::cout << ((count == 1) ? "Yes" : "No") << std::endl;

    return 0;
}

Measured memory_bytes: 256
let s = cin.str
print(s == "ABC" ? "ARC" : "ABC")

// MARK: #### 以下、ライブラリ ####

import Foundation
#if os(Linux)
    import Glibc
#else
    import Darwin.C
#endif

enum cin {
    // 123
    static var int: Int { Int(readLine()!)! }
    // 12 23
    static var pair: (Int, Int) { let line = readLine()!.components(separatedBy: " "); return (Int(line[0])!, Int(line[1])!) }
    // 12 23 34
    static var triple: (Int, Int, Int) { let line = readLine()!.components(separatedBy: " "); return (Int(line[0])!, Int(line[1])!, Int(line[2])!) }
    // AtCoder
    static var str: String { readLine()! }
    // At Coder
    static var arrayStr: [String] { str.components(separatedBy: " ") }
    // 1 2 3 4
    static var array: [Int] { str.components(separatedBy: " ").map { Int($0)! } }
    // 1
    // 2
    // 3
    static func v_array(count: Int) -> [Int] { (0..<count).map { _ in int } }
}

extension Int {
    // 123 -> [1, 2, 3]
    var digits: [Int] { Array(String(self)).map { Int(String($0))! } }
}

extension Array where Element == Int {
    // [2, 1, 3, 2] -> 8
    var sum: Int { self.reduce(0, +) }
    // [2, 1, 3, 2] -> [1, 2, 2, 3]
    var orderBy: [Int] { sorted() }
    // [2, 1, 3, 2] -> [3, 2, 2, 1]
    var orderByDesc: [Int] { sorted(by: { $0 > $1 }) }
    // [2, 1, 3, 2] -> [2, 1, 3]
    var distinct: [Int] { Array(Set(self)) }
}

precedencegroup PowerPrecedence { higherThan: MultiplicationPrecedence }
infix operator ^^ : PowerPrecedence
func ^^ (radix: Int, power: Int) -> Int {
    return Int(pow(Double(radix), Double(power)))
}

extension String {
    // e.g. cin.line.regex(match: "^(dream|dreamer|erase|eraser)*$")
    func regex(match pattern: String) -> Bool {
        let regex = try! NSRegularExpression(pattern: pattern)
        return regex.firstMatch(in: self, range: NSRange(location: 0, length: self.count)) != nil
    }
    // "ABC"[1] -> "B"
    subscript(i: Int) -> Character {
        get {
            self[index(at: i)]
        }
        set(char) {
            var characters = Array(self)
            characters[i] = char
            self = String(characters)
        }
    }
    func index(at offset: Int) -> String.Index { index(startIndex, offsetBy: offset) }
    // "ABC".swapAt(0, 1) -> "BAC"
    mutating func swapAt(_ index1: Int, _ index2: Int) {
        var characters = Array(self)
        characters.swapAt(index1, index2)
        self = String(characters)
    }
}


Measured memory_bytes: 12808
#include <bits/stdc++.h>
using namespace std;
int main() {
	int n;
	cin >> n;
	vector<pair<int, int>> d(n);
	for (int i = 0; i < n; i++) {
		cin >> d[i].first >> d[i].second;
	}
	for (int i = 0; i < n - 2; i++) {
		bool isOK = true;
		for (int j = 0; j < 3; j++) {
			if (d[i + j].first != d[i + j].second) {
				isOK = false;
			}
		}
		if (isOK) {
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	ios_base::sync_with_stdio(0); 
    cin.tie(0);   
	ll n,a[200009],m,k,ans=0,fl=0;
	string s;
	cin>>n>>m>>k;
	ll temp=n/(m+k);
	ll p=min(n%(m+k),m);
	cout<<(temp*m)+p<<endl;
	return 0;
}

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

//type
#define ll long long
typedef pair<int, int> P;
//定数
#define INF 1000000000000 //10^12:∞
#define MOD 1000000007    //10^9+7:合同式の法
#define MAXR 100000       //10^5:配列の最大のrange
//略記
#define PB push_back //挿入
#define MP make_pair //pairのコンストラクタ
#define F first      //pairの一つ目の要素
#define S second     //pairの二つ目の要素
#define Z class
// OTHER
// xの二乗を返す (関数テンプレート版)
template <typename T>
T square(T x) { return x * x; }
template <class T>
T GCD(T a, T b)
{
    T r;
    while (a)
        r = b, b = a, a = r % a;
    return b;
}
template <class T>
T LCM(T a, T b) { return a / GCD(a, b) * b; }

#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))
// loop
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repd(i, n) for (ll i = n; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i <= (b); i++)
#define FORD(i, a, b) for (ll i = a; i >= (b); i--)
#define FORA(i, I) for (const auto &i : I)

// vector
#define ALL(x) x.begin(), x.end()
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vi> vvi;
typedef vector<ll> vl;
#define ERASE(x) x.erase(unique(ALL(x)), x.end()); // erase same elements
#define VEC(type, c, n)     \
    std::vector<type> c(n); \
    for (auto &i : c)       \
        std::cin >> i;

// input
#define INIT                          \
    std::ios::sync_with_stdio(false); \
    std::cin.tie(0);
#define VAR(type, ...) \
    type __VA_ARGS__;  \
    MACRO_VAR_Scan(__VA_ARGS__);

// output
template <typename T>
void MACRO_OUT(const T t) { std::cout << t; }

#define OUT(...) MACRO_OUT(__VA_ARGS__);
#define SP std::cout << " ";
#define TAB std::cout << "\t";
#define BR std::cout << "\n";
#define ENDL std::cout << std::endl;

#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define isYES(x) printf("%s\n", (x) ? "YES" : "NO")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define ln cout << '\n'
template <Z A>
void pr(A a)
{
    cout << a;
    ln;
}
template <Z A, Z B>
void pr(A a, B b)
{
    cout << a << ' ';
}

int ans = 0;
bool check = 0;
string s, t;
int N = 3;
vector<int> v(N);
int a, b, c, d, n;
int x, y;
int sum;
char ch;

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
// cout << (conditon ? (result:  == 1 ): (==0)) << endl; <- output result of if
// long long 型が表せる値の上限はおよそ 9 × 10＾18 です．
int main()
{

    int H, W;
    cin >> H >> W;
    for (int i = 0; i < H; i++)
    {
        cin >> s;
        cout << s << endl
             << s << endl;
    }
    return 0;
}


Measured memory_bytes: 3600
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <iomanip>
#include <array>
#include <numeric>
#include <regex>
#include <bitset>
#include <deque>

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

const int INF = 1e9;
const double PI = acos(-1.0);
const ll MOD = 1e9 + 7;

int n, x;
int city[100010];

int gcd(int a, int b) {//最大公約数
	if (a%b == 0)return b;
	else gcd(b, a%b);
}

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

	rep(i, n) {
		int t; cin >> t;
		city[i] = t - x;
	}
	if (n == 1) {
		cout << abs(city[0]) << endl;
		return 0;
	}

	ll res = gcd(city[0], city[1]);

	rep(i, n) {
		res = gcd(res, city[i]);
	}

	cout << abs(res) << endl;

	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
using Graph = vector<vector<int>>;
int main() {
    int N, Q; cin >> N >> Q;
    Graph G(N);
    vector<Int> add(N), ans(N);
    for (int i = 0; i < N-1; i++) {
        int a, b; cin >> a >> b; a--, b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    for (int i = 0; i < Q; i++) {
        int p, x; cin >> p >> x; p--;
        add[p] += x;
    }
    stack<tuple<int, int, Int>> S;
    S.emplace(0, -1, 0);
    while (!S.empty()) {
        int node, prev; Int value;
        tie(node, prev, value) = S.top();
        S.pop();
        value += add[node];
        ans[node] = value;
        for (auto n : G[node]) if (n != prev) {
            S.emplace(n, node, value);
        }
    }
    for (int i = 0; i < N; i++) {
        cout << ans[i] << " \n"[i == N-1];
    }
    return 0;
}

Measured memory_bytes: 19512
# -*- coding: utf-8 -*-
# D
'''
4 1 3
'''

import math
DIVISOR = 10**9 + 7


def comb(n, r):
    res1 = 1
    # 分子
    for i in range(r):
        res1 = (res1 * (n-i)) % DIVISOR

    # 分母
    res2 = 1
    for i in range(r):
        res2 = (res2 * (i+1)) % DIVISOR
    res2 = power_mod(res2, DIVISOR - 2, DIVISOR)
    return (res1 * res2) % DIVISOR


def power_mod(n, k, m):
    if k == 0:
        return 1
    elif k % 2 == 1:
        return power_mod(n, k-1, m) * (n % m) % m
    elif k % 2 == 0:
        temp = power_mod(n, k/2, m)
        return (temp % m) * (temp % m) % m


n, a, b = map(int, input().split())

S = 2 * power_mod(2, n-1, DIVISOR)
S = (S - 1) % DIVISOR
# print(S)

# print(comb(n, a))
# print(comb(n, b))

S = S - comb(n, a) - comb(n, b)

print(S % DIVISOR)


Measured memory_bytes: 38740