akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
using namespace std;

struct Node;
struct Edge;

struct Node {
    int n;
    vector<Node *> neighbors;
    vector<Edge *> edges;
};

struct Edge {
    Node *a, *b;
    int color;
};

int N;
vector<bool> T;
vector<Node> G;
vector<Edge> E;

void visit(Node &node, int prev_color) {
    T[node.n] = false;
    int color = 1;
    if (color == prev_color) ++color;

    for (int i = 0; i < node.neighbors.size(); ++i) {
        Node *neighbor = node.neighbors[i];
        Edge *edge = node.edges[i];

        if (T[neighbor->n]) {
            edge->color = color;
            visit(*neighbor, color);

            ++color;
            if (color == prev_color) ++color;
        }
    }
}

int main() {
    cin >> N;

    G = vector<Node>(N);

    for (int i = 0; i < N; ++i) {
        G[i].n = i;
    }

    E = vector<Edge>(N - 1);

    for (int i = 0; i < N - 1; ++i) {
        int a, b;
        cin >> a >> b;
        --a;
        --b;
        G[a].neighbors.push_back(&G[b]);
        G[b].neighbors.push_back(&G[a]);
        G[a].edges.push_back(&E[i]);
        G[b].edges.push_back(&E[i]);
        E[i].a = &G[a];
        E[i].b = &G[b];
    }

    int max_color = 0;

    for (int i = 0; i < N; ++i) {
        if (max_color < G[i].neighbors.size()) max_color = G[i].neighbors.size();
    }

    cout << max_color << endl;

    T = vector<bool>(N, true);

    visit(G[0], 0);

    for (int i = 0; i < N - 1; ++i) {
        cout << E[i].color << endl;
    }

    return 0;
}


Measured memory_bytes: 15744
package main

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

func main() {
	sc.Split(bufio.ScanWords)
	s := next()
	cnt := map[byte]int{}
	for i := range s {
		cnt[s[i]]++
	}
	// puts(cnt)

	ok := true
	if cnt['N']*cnt['S'] == 0 && cnt['N']+cnt['S'] > 0 {
		ok = false
	}
	if cnt['W']*cnt['E'] == 0 && cnt['W']+cnt['E'] > 0 {
		ok = false
	}

	if ok {
		puts("Yes")
	} else {
		puts("No")
	}
	wt.Flush()
}

var (
	sc  = bufio.NewScanner(os.Stdin)
	rdr = bufio.NewReaderSize(os.Stdin, 1000000)
	wt  = bufio.NewWriter(os.Stdout)
)

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

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

func nextFloat64() float64 {
	f, _ := strconv.ParseFloat(next(), 64)
	return f
}

func nextInts(n int) []int {
	slice := make([]int, n)
	for i := 0; i < n; i++ {
		slice[i] = nextInt()
	}
	return slice
}

func nextFloat64s(n int) []float64 {
	slice := make([]float64, n)
	for i := 0; i < n; i++ {
		slice[i] = nextFloat64()
	}
	return slice
}

func nextMega() string {
	buf := make([]byte, 0, 1000000)
	for {
		l, p, _ := rdr.ReadLine()
		buf = append(buf, l...)
		if !p {
			break
		}
	}
	return string(buf)
}

func putf(format string, a ...interface{}) {
	fmt.Fprintf(wt, format, a...)
}

func puts(a ...interface{}) {
	fmt.Fprintln(wt, a...)
}


Measured memory_bytes: 640
from collections import Counter
N=int(input())
A=[int(item)for item in input().split()]
c=Counter(A)
full = {i: c[i] * (c[i] - 1) / 2 for i in c.keys()}
#full = [full[item-1] for item in A]
#print(full)
#ichiheri = [c[i]-1 * (c[i]-1) / 2 for i in range(1,1+len(c))]
sumA = sum(full.values())
val = {i:int(sumA-full[i]+(c[i]-2) * (c[i]-1) / 2 )for i in c.keys()}
#print(ichiheri)



for a in A:
    print(val[a])

Measured memory_bytes: 104652
N=int(input())
S=input()
L=[0 if S[i]=="E" else 1 for i in range(N)]
Lmk=0
Rmk=N-1-sum(L[1:])
ans=Rmk
for i in range(1,N):
  Lmk+=1 if L[i-1]==1 else 0
  Rmk-=1 if L[i]==0 else 0
  ans=min(ans,Lmk+Rmk)
print(ans)

Measured memory_bytes: 8352
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <set>
#include <algorithm>
#include <array>
#include <complex>
#include <string>
#include <utility>
#include <map>
#include <queue>
#include <list>
int dx[4] = { -1,0,1,0 };
int dy[4] = { 0,1,0,-1 };
const int INF = 1 << 21;
using pii = std::pair<int, int>;
#define SORT(v) std::sort(v.begin(), v.end())
int main(void) {
	int N;
	std::cin >> N;
	std::vector<int> s(N);
	int ans = 0;
	for (int i =0 ; i < N; ++i) {
		std::cin >> s[i];
		ans += s[i];
	}
	SORT(s);
	int minpoint=1000;
	for (int i = 0; i < N; ++i) {
		if (s[i] % 10 != 0) {
			minpoint =std::min(minpoint, s[i]);
		}
	
	}
	if (ans % 10 != 0) {
		std::cout << ans << std::endl;
	}
	else if (ans % 10 == 0 && minpoint == 1000) {
		std::cout << 0 << std::endl;
	}
	else {
		std::cout << ans-minpoint << std::endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <cassert>
#include <sstream>
#include <fstream>

using namespace std;
typedef long long ll;

const int MAX = 1e3 + 3;
const long long MOD = 1e9 + 7LL;
long long cnt[MAX];

void computeNDivisor(int a) {
  for (int i = 2; i <= a; ++i) {
    if (a <= 1) break;
    while (a % i == 0) {
      cnt[i]++;
      a /= i;
    }
  }
}

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

  if (N == 1) {
    cout << 1 << endl;
    return 0;
  }
  for (int i = 2; i <= N; ++i) {
    computeNDivisor(i);
  }

  long long ans = 1;
  for (int i = 2; i <= N; ++i) {
    if (cnt[i] == 0) continue;
    ans = (ans * (cnt[i] + 1)) % MOD;
  }
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 256
#include <stdio.h>
int main (){
	int a,b,c;
	int x=0;
	scanf("%d %d %d",&a,&b,&c);
	while (a<=b){
		if (a%c==0){
			x=x+1;
		}
		a++;
	
	}	printf("%d",x);
	
	return 0;
}

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

#define rep(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define rng(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define rbf(i, v) for (auto& (i) : (v))
#define All(x) (x).begin(),(x).end()
#define cAll(x) (x).cbegin(),(x).cend()
#define COL(x) cout << x << endl
#define CO(x) cout << x
//#define int long long

typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<PII> VP;

const double PI = 3.141592653589793;
const int MOD = 1000000007;
const LL INF64 = INT64_MAX;
const int INF = INT_MAX;

inline constexpr int sqr(int x) { return (x * x); }
inline void printd(double x) { printf("%.10lf\n", x); }
inline void upsort(VI& x) { sort((x).begin(), (x).end()); }
inline void downsort(VI& x) { sort((x).begin(), (x).end(), greater<int>()); }
inline int absdiff(int a, int b) { return (a - b)*(1|((a - b)>>(8*sizeof(int))));}

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

	LL sum = 0;;
	rng(i, 1, N + 1) {
		if ((i % 3 != 0) && (i % 5 != 0)) {
			sum += i;
		}
	}

	COL(sum);
	
	return 0;
}

Measured memory_bytes: 3620
import java.util.*;
import java.awt.*;
import static java.lang.System.*;
import static java.lang.Math.*;
//Loopで使う文字列の長さは固定！
//intで大丈夫？オーバーフローしない？
//Loop回数は本当に10⁹以内になってる？Loopは回る？？
public class Main {
    public static void main(String[]$){
        Scanner sc = new Scanner(in);
        int n=sc.nextInt();
        int m=sc.nextInt();
        int[] p=new int[m];
        int[] y=new int[m];
        HashMap<Integer,Integer> map=new HashMap<>();
        HashMap<Integer,Integer> YtoM=new HashMap<>();
        TreeMap<Integer,Integer> tm=new TreeMap<>();
        for (int i = 0; i < m; i++) {
            p[i]=sc.nextInt();
            y[i]=sc.nextInt();
            tm.put(y[i],p[i]);
            map.put(p[i],1);
            YtoM.put(y[i],i);
        }
        String[] ans=new String[m];
        for(int k:tm.keySet()){
            String left="";
            String right="";
            left=Integer.toString(tm.get(k));
            int length=left.length();
            for (int i = 0; i <6-length; i++) {
                left="0"+left;
            }
            right=Integer.toString(map.get(tm.get(k)));
            length=right.length();
            for (int i = 0; i <6-length; i++) {
                right="0"+right;
            }
            map.put(tm.get(k),map.get(tm.get(k))+1);
            ans[YtoM.get(k)]=left+right;
        }
        for (int i = 0; i < m; i++) {
            out.println(ans[i]);
        }
    }
}

Measured memory_bytes: 126276
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <vector>
#include <tuple>
#include <algorithm>
#include <iostream>

using namespace std;

int main() {
	long long a, b;
	cin >> a >> b;
	if (a <= 0 && b >= 0) puts("Zero");
	else if (a > 0) puts("Positive");
	else if ((b - a + 1) % 2 == 0) puts("Positive");
	else puts("Negative");
	
	return 0;
}


Measured memory_bytes: 256
def f(n, a, p, r):
    for i in range(1, n):
        t = p + a[i]
        if p < 0 and t <= 0:
            r += 1 - t
            t = 1
        elif p > 0 and t >= 0:
            r += t + 1
            t = -1
        p = t
    return r


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

# 最初がプラス
p = a[0]
r = 0
if p <= 0:
    r += 1 - p
    p = 1
result1 = f(n, a, p, r)

# 最初がマイナス
p = a[0]
r = 0
if p >= 0:
    r += p + 1
    p = -1
result2 = f(n, a, p, r)

print(min(result1, result2))


Measured memory_bytes: 14468
n, r, l = map(int, raw_input().split())
time = [0]*n
score = [0]*n
top_id = 0
d = [map(int, raw_input().split()) for _ in range(r)] + [[1,l,0]]
cur_time = 0
for e in sorted(d, key = lambda x: x[1]):
    cur_id = e[0] - 1
    time[top_id] += e[1] - cur_time
    cur_time = e[1]
    score[cur_id] += e[2]
    if cur_id == top_id and e[2] < 0:
        top_id = score.index(max(score))
    elif score[top_id] < score[cur_id] or (score[top_id] == score[cur_id] and top_id > cur_id):
        top_id = cur_id
print time.index(max(time)) + 1

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

int main(){
int a=0,b=0;
char cha,chb;
cin>>cha>>chb;
//cout<<cha<<chb;
if(cha=='H')
	a=1;
if(chb=='H')
	b=1;
if((a+b)%2)
	cout<<'D'<<endl;
else
	cout<<'H'<<endl;
}

Measured memory_bytes: 256
n, m = [int(x) for x in input().split()]
xn = [int(x) for x in input().split()]

xs = sorted(xn)
ln = []
for i in range(0, m-1):
    ln.append(xs[i+1] - xs[i])

ls = sorted(ln)
if n>=m:
    print(0)
else:
    print(sum(ls[:(m-n)]))


Measured memory_bytes: 13840
import java.util.Scanner;

class Main {
    public static void main (String args[]) {
        int n,m,x,y,l,r;
        Scanner in = new Scanner(System.in);

        n = in.nextInt();
        m = in.nextInt();

        x = y = 0;
        while(m>0) {
            l = in.nextInt();
            r = in.nextInt();

            if(x!=-1 && y!=-1)
            {
                if(x==0 && y==0)
                {
                    x = l;
                    y = r;
                }
                else
                {
                    x = Math.max(x,l);
                    y = Math.min(y,r);

                    if(x>y)
                        x = y = -1;
                }
            }
            m--;
        }
        int cnt = 0;
        if(x==-1 && y==-1)
            cnt = 0;
        else
            cnt = y-x+1;

        System.out.print(cnt);
    }
}


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

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

using namespace std;
#define int long long
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repr(i,n) for(ll i=n;i>=0;i--)
#define P pair<ll, ll>
#define sz(x) (ll)x.size()
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define VE vector<ll>
#define COUT(x) cout<<(x)<<endl
#define MA map<ll,ll>
#define SE set<ll>
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,VE,greater<ll>>
#define COUT(x) cout<<(x)<<endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define EPS (1e-10)


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


long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	unsigned r;
	while ((r = a % b)) {
		a = b;
		b = r;
	}
	return b;
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a * g / b;
}
bool prime(ll n) {
	for (ll i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}




const long double PI = 3.14159265359;
const int MAX_N = 100010;


signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n; cin >> n;
	VE a(n); rep(i, n)cin >> a[i];
	int x = 0, y = 0, z = 0;
	rep(i, n) {
		if (a[i] % 4 == 0)x++;
		else if (a[i] % 2 == 0)y++;
		else z++;
	}
	if (y == 0) {
		if (z <= x + 1) {
			cout << "Yes" << endl;
		}
		else {
			cout << "No" << endl;
		}
	}
	else {
		if (z <= x) {
			cout << "Yes" << endl;
		}
		else {
			cout << "No" << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1024
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line = "";

		boolean[] qwerty = new boolean[127];
		for (int i = 'a'; i <= 'z'; i++) {
			if ("yuiophjklnm".indexOf(i) != -1) {
				qwerty[i] = true;
			}
		}

		while (!(line = br.readLine()).equals("#")) {
			boolean hand = qwerty[line.charAt(0)];
			int sum = 0;
			for (char c : line.substring(1).toCharArray()) {
				if (qwerty[c] != hand) {
					sum++;
					hand = qwerty[c];
				}
			}
			System.out.println(sum);
		}
	}
}

Measured memory_bytes: 17004
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<string.h>
#include<math.h>
#include<map>
#include<iomanip>
#include<queue>

using namespace std;

int main(){
	int n;
	cin >> n;
	vector<long long> a(n);
	for(int i=0;i<n;i++){
		cin >> a[i];
	}
	long long ans=0;
	for(int i=1;i<n;i++){
		if(a[i]>=a[i-1]){
			continue;
		}else{
			ans+=a[i-1]-a[i];
			a[i]+=(a[i-1]-a[i]);
		}
	}
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 4764
def gcd(a, b)
  a, b = b, a if a < b
  if b == 0
    a
  else
    gcd(b, a % b)
  end
end

def lcm(a, b)
  a / gcd(a, b) * b
end

while line = gets
  a, b = line.chomp.split.map(&:to_i)
  puts "#{gcd(a, b)} #{lcm(a, b)}"
end

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

int main(){
 long long N,M,f,g;
  cin>>N;
  string S;
  cin>>S;
 vector<int> W(N+2),E(N+2);
  
  for(int i=0;i<N;i++){
    W[i+1]=W[i];
    E[i+1]=E[i];
    if(S[i]=='W'){
      W[i+1]++;
    }
    else{
      E[i+1]++;
    }
  }
  g=1000000;

    for(int i=0;i<N;i++){
   f=W[i]+E[N]-E[i+1];
      g=min(f,g);
   }
 cout<<g<<endl;
}

Measured memory_bytes: 3076
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;

struct Info{
	double vw,pf,vf,th;
};

int N;
double pw;

Info* flower;

double calc(double water_amount){
	double ret = water_amount*pw;

	for(int i = 0; i < N; i++){
		ret += max(0.0,flower[i].pf*((flower[i].th-water_amount*flower[i].vw)/flower[i].vf));
	}
	return ret;
}

double thirds_search(double left,double right){

	if(fabs(right-left) < EPS){
		return calc((right+left)/2);
	}

	double mid1 = (2.0*left+right)/3.0;
	double mid2 = (1.0*left+2.0*right)/3.0;

	if(calc(mid1) > calc(mid2)){
		return thirds_search(mid1,right);
	}else{
		return thirds_search(left,mid2);
	}
}

void func(){
	scanf("%lf",&pw);

	for(int i = 0; i < N; i++){
		scanf("%lf %lf %lf %lf",&flower[i].vw,&flower[i].pf,&flower[i].vf,&flower[i].th);
	}

	printf("%.10lf\n",thirds_search(0.0,(double)BIG_NUM));
}

int main(){

	flower = (Info*)malloc(sizeof(Info)*100000);

	while(true){
		scanf("%d",&N);
		if(N == 0)break;

		func();
	}

	return 0;
}

Measured memory_bytes: 6268
N = int(input())
X = list(map(int, input().split()))

avg_p = int(sum(X) / N)

cost_l = sum(map(lambda x: (x - avg_p)**2, X))
cost_r = sum(map(lambda x: (x - avg_p - 1)**2, X))

print(min(cost_l, cost_r))

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
 
using namespace std;
 
#define vital first
#define cal second
#define happy first
#define kuso 10001
 
int main(){
    int S, T, U, N, O, D; cin >> S >> T >> U >> N >> O >> D;
    vector<pair<int, int> > train(T);
    vector<pair<int, int> > donut(N);
    vector<vector<int> > dp_VtoC(U+1, vector<int>(S+1));
    int dp_CtoH[kuso];
    vector<int> dp_VtoH(S+1);
    vector<vector<int> > dp(D+1, vector<int>(S+1));
 
    for (int i = 0; i < T; i++) { cin >> train[i].vital >> train[i].cal; }
    for (int i = 0; i < N; i++) { cin >> donut[i].happy >> donut[i].cal; }
 
    for (int i = 0; i < U+1; i++)
        for (int j = 0; j < S+1; j++)
            dp_VtoC[i][j] = -1;
    dp_VtoC[0][0] = 0;
    for (int i = 0; i < T; i++) {
        for (int j = U-1; j >= 0; j--) {
            for (int k = S; k >= 0; k--) {
                if (dp_VtoC[j][k] != -1 && k+train[i].vital <= S) {
                    dp_VtoC[j+1][k+train[i].vital] = max(dp_VtoC[j][k]+train[i].cal, dp_VtoC[j+1][k+train[i].vital]);
                }
            }
        }
    }
    for (int i = 0; i < kuso; i++) dp_CtoH[i] = -1;
    dp_CtoH[0] = 0;
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < kuso; j++) {
            if (dp_CtoH[j] != -1 && j + donut[i].cal < kuso) {
                dp_CtoH[j+donut[i].cal] = max(dp_CtoH[j+donut[i].cal], dp_CtoH[j]+donut[i].happy);
            }
        }
    }
    for (int i = 0; i < S+1; i++) dp_VtoH[i] = -1;
    for (int i = 0; i < S+1; i++) {
        if (dp_VtoC[U][i] != -1) {
            for (int j = dp_VtoC[U][i]; j >= 0; j--) {
                dp_VtoH[i] = max(dp_VtoH[i], dp_CtoH[j]);
            }
        }
    }
 
    for (int i = 0;  i < D+1; i++)
        for (int j = 0; j < S+1; j++)
            dp[i][j] = -1;
    dp[0][S] = 0;
    for (int i = 0; i < D; i++) {
        for (int j = 0; j < S+1; j++) {
            if (dp[i][j] != -1) {
                for (int k = 0; k < S+1; k++) {
                    if (dp_VtoH[k] != -1 && j-k >= 0) {
                        dp[i+1][j-k] = max(dp[i+1][j-k], dp[i][j]+dp_VtoH[k]);
                    }
                }
            }
        }
        for (int j = S; j >= 0; j--) {
            int tmp = min(j+O, S);
            dp[i+1][tmp] = max(dp[i+1][tmp], dp[i+1][j]);
        }
    }
 
    int res = 0;
    for (int i = 0; i < S+1; i++) { res = max(res, dp[D][i]); }
    if (res) {
        cout << res << endl;
    } else {
        cout << "-1" << endl;
    }
 
    return 0;
}

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

using namespace std;

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

    int P, Q, R;
    cin >> P >> Q >> R;
    cout << min(P + Q, min(Q + R, R + P)) << "\n";
    
    return 0;
}

Measured memory_bytes: 256
from sys import stdin
def main():
	readline=stdin.readline
	A,B,M=map(int,readline().split())
	a=list(map(int,readline().split()))
	b=list(map(int,readline().split()))
	xyc=[0]*M
	for i in range(M):
		x=list(map(int,readline().split()))
		xyc[i]=x
	
	res=min(a)+min(b)
	for i in range(M):
		res=min(res,a[xyc[i][0]-1]+b[xyc[i][1]-1]-xyc[i][2])
	print(res)
if __name__=="__main__":
	main()

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

int main(){
  char c;
  cin >> c;
  
  if(c=='a' || c=='i' || c=='u' || c=='e' || c=='o'){
    cout << "vowel" << endl;
  }else{
    cout << "consonant" << endl;
  }
}

Measured memory_bytes: 3564
#include <bits/stdc++.h>
using i64 = long long;
using std::cout;
using std::endl;
using std::cin;

int main() {
	int n; scanf("%d", &n); std::vector<i64> a(n), b(n);
	for(int i = 0; i < n; i++) {
		scanf("%lld", &a[i]);
		
		if(a[i] == 0) continue;
		if(a[i] % 2) b[i] = 1;
		else b[i] = 2;
	}
	
	std::vector<std::vector<i64>> dp(n + 1, std::vector<i64>(5, 1LL << 60));
	for(int i = 0; i < 5; i++) dp[0][i] = 0;
	for(int i = 0; i < n; i++) {
		dp[i + 1][0] = dp[i][0] + a[i];
		dp[i + 1][1] = std::min(dp[i][1], dp[i][0]) + std::abs(b[i] - 2);
		dp[i + 1][2] = std::min({dp[i][2], dp[i][1], dp[i][0]}) + std::abs(b[i] - 1);
		dp[i + 1][3] = std::min({dp[i][3], dp[i][2], dp[i][1], dp[i][0]}) + std::abs(b[i] - 2);
		dp[i + 1][4] = std::min({dp[i][4], dp[i][3], dp[i][2], dp[i][1], dp[i][0]}) + a[i];
	}
	printf("%lld\n", std::min({dp[n][0], dp[n][1], dp[n][2], dp[n][3], dp[n][4]}));
	return 0;
}


Measured memory_bytes: 17408
N = int(input())
ans = 1
cnt_ans = 0

for i in range(1,N+1):
    tmp = i
    cnt = 0
    while tmp % 2 == 0:
        tmp /= 2
        cnt += 1
    if cnt > cnt_ans:
        ans = i
        cnt_ans = cnt
    
print(ans)

Measured memory_bytes: 3060
local N, x = io.read("*n", "*n")
local A = {}
for i = 1, N do
    A[i] = io.read("*n")
end
table.sort(A)

local counter = 0
for i = 1, N do
    if x - A[i] >= 0 then
        if i ~= N then
            x = x - A[i]
            counter = counter + 1
        elseif x - A[i] == 0 then
            counter = counter + 1
        end
    end
end
print(counter)

Measured memory_bytes: 760
#include<stdio.h>
#include<stdlib.h>
#include<stdint.h>
#include<inttypes.h>
#include<string.h>

typedef int32_t i32;

typedef struct directed_edge {
  int32_t vertex;
  int32_t next;
} graph_edge;

typedef struct directedGraph {
  graph_edge *edge;
  int32_t *start;
  int32_t pointer;
  int32_t vertex_num;
  int32_t edge_max_size;
} graph;

graph* new_graph (const int vertex_num) {
  graph *g = (graph *) calloc (1, sizeof (graph));
  g->edge = (graph_edge *) calloc (1, sizeof (graph_edge));
  g->start = (int32_t *) calloc (vertex_num, sizeof (int32_t));
  g->pointer = 0;
  g->vertex_num = vertex_num;
  g->edge_max_size = 1;
  for (int32_t i = 0; i < vertex_num; ++i) {
    g->start[i] = -1;
  }
  return g;
}

void free_graph (graph *g) {
  free (g->edge);
  free (g->start);
  free (g);
  return;
}

void clear_graph (graph *g) {
  g->pointer = 0;
  for (int32_t i = 0; i < g->vertex_num; ++i) {
    g->start[i] = -1;
  }
}

void add_edge (graph *g, int32_t from, int32_t to) {
  if (g->pointer == g->edge_max_size) {
    g->edge_max_size *= 2;
    g->edge = (graph_edge *) realloc (g->edge, sizeof (graph_edge) * g->edge_max_size);
  }
  g->edge[g->pointer] = (graph_edge) {to, g->start[from]};
  g->start[from] = g->pointer++;
}

void BFS_graph (graph *g, int32_t src, i32 *d) {
  int32_t *q = (int32_t *) calloc (g->vertex_num, sizeof (int32_t));
  uint8_t *used = (uint8_t *) calloc (g->vertex_num, sizeof (uint8_t));
  int32_t front = 0;
  int32_t last = 0;
  used[src] = 1;
  q[last++] = src;
  while (front < last) {
    const int32_t v = q[front++];
    for (int32_t p = g->start[v]; p != -1; p = g->edge[p].next) {
      const int32_t u = g->edge[p].vertex;
      if (!used[u]) {
        used[u] = 1;
        q[last++] = u;
        d[u] = d[v] + 1;
      }
    }
  }
  free(q);
  free(used);
}

#define ALLOC(size,type) ((type*)calloc((size),sizeof(type)))

void run (void) {
  i32 n, m;
  scanf ("%" SCNi32 "%" SCNi32, &n, &m);
  graph *g = new_graph (3 * n);
  while (m--) {
    i32 a, b;
    scanf ("%" SCNi32 "%" SCNi32, &a, &b);
    a--;
    b--;
    for (i32 i = 0; i < 3; ++i) {
      add_edge (g, a + i * n, (b + (i + 1) * n) % (3 * n));
    }
  }
  i32 s, t;
  scanf ("%" SCNi32 "%" SCNi32, &s, &t);
  s--;
  t--;
  i32 *d = ALLOC (3 * n, i32);
  BFS_graph (g, s, d);
  if (d[t] == 0) {
    puts ("-1");
  } else {
    printf ("%" PRIi32 "\n", d[t] / 3);
  }
}

int main (void) {
  run();
  return 0;
}


Measured memory_bytes: 6400
#include <bits/stdc++.h>
#include <boost/dynamic_bitset.hpp>
using namespace std;
using u32 = uint32_t;
using u64 = uint64_t;
using s64 = int64_t;

int main() {
	u32 N, K, C;
	cin >> N >> K >> C;
	
	boost::dynamic_bitset<> days(N);
	
	for(u64 i=0; i<N; i++) {
		char c;
		cin >> c;
		days[i] = (c == 'o');
	}
	
	vector<u64> L(K, N);
	for(u64 i=0, l=0; i<N && l<K;) {
		if(days[i]) {
			L[l] = i;
			i += C + 1;
			l++;
		} else {
			i++;
		}
	}
	
	vector<u64> R(K, N+1);
	for(s64 i=N-1, r=K-1; i>=0 && r>=0;) {
		if(days[i]) {
			R[r] = i;
			i -= (C + 1);
			r--;
		} else {
			i--;
		}
	}
	
	for(u64 i=0; i<K; i++) {
		//cout << L[i] << " " << R[i] << endl;
		if(L[i] == R[i]) {
			cout << L[i] + 1 << endl;
		}
	}
	
	return 0;
}

Measured memory_bytes: 4608
fun main(args: Array<String>) {
    val (n, h) = readLine()!!.split(" ").map(String::toInt)
    val aArray = Array(n, {0})
    val bArray = Array(n, {0})
    for (i in 0 until n) {
        val(a, b) = readLine()!!.split(" ").map(String::toInt)
        aArray[i] = a
        bArray[i] = b
    }
    val aMax = aArray.max()!!
    val filteredBArray = bArray.filter { it > aMax }.sortedDescending()

    var ans = 0
    var acc = 0
    for (b in filteredBArray) {
        acc += b
        ans += 1
        if (acc >= h) {
            println(ans)
            return
        }
    }
    println(ans + (h - acc + aMax - 1) / aMax)
}

Measured memory_bytes: 59820
#include <bits/stdc++.h>
#define fast ios::sync_with_stdio(0);cin.tie(0);
using namespace std;

/*void solve(){
  int n,q;cin>>n>>q;
  unordered_map<char,int>cnt;
  string s;cin>>s;
  int ma=0;
  for(int i=0;i<s.size();i++)
  {
    cnt[s[i]]++;
    if(cnt[s[i]]>ma)ma=cnt[s[i]];
  }
    int dp[ma+1]={0};
 for(auto u:cnt)
 {
     int x=u.second;
     for(int i=1;i<=x;i++)
        dp[i]++;
 }
 for(int i=1;i<ma;i++)dp[i]+=dp[i-1];
while(q--)
{
    int c;cin>>c;
    if(c>=ma)cout<<"0"<<endl;
    else cout<<n-dp[c]<<endl;
}
return;
}*/

int main(){
    fast
 int k,a,b;cin>>k>>a>>b;
if(b/k>(a-1)/k)cout<<"OK";
else cout<<"NG";
return 0;
}


Measured memory_bytes: 3604
#if __has_include("noamoa_atcoder_lib.h")
#include "noamoa_atcoder_lib.h"
#else
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define endl '\n'
#define all(x) (x).begin(),(x).end()
namespace atcoder {
	using namespace std;
	using ll = long long;
	using intv = vector<int>;
	using charv = vector<char>;
	using boolv = vector<bool>;
	using floatv = vector<float>;
	using doublev = vector<double>;
	using stringv = vector<string>;

	constexpr ll MOD  = 1000000007;
    constexpr ll MOD9 = 1000000009;

	template<typename T>
	void sort(vector<T>& v){
		sort(all(v));
	}
	template<typename T>
	void sortInv(vector<T>& v){
		sort(all(v), greater<T>());
	}

	template<typename T>
	T sum(const vector<T>& v){
		T ret = 0;
		for(const auto& e : v) ret += e;
		return ret;
	}

	template<typename T>
	inline vector<T>& operator+=(vector<T>& v, const T& e){
		v.push_back(e);
		return v;
	}

	template<typename T>
	void in(vector<T>& v){
		for(auto& e : v) cin >> e;
	}

	template<typename T>
	istream& operator>>(istream &stream, vector<T>& v){
		for(auto& e : v) stream >> e;
		return stream;
	}

	template<typename T>
	void out(const vector<T>& v){
		for(const auto& e : v) cout << e << ' ';
		cout << endl;
	}

	template<typename T>
	void outln(const vector<T>& v){
		for(const auto& e : v) cout << e << endl;
	}

	void init(){
		cin.tie(nullptr);
		ios::sync_with_stdio(false);
		cout << fixed << setprecision(15);
	}
}
using namespace atcoder;
#endif

int main(){
	init();

	int s,w;cin>>s>>w;
	cout<<(w>=s?"unsafe":"safe");
}

Measured memory_bytes: 3648
main :: IO ()
main = do
  ss <- map read . words <$> getLine :: IO [Double]
  let (ans, i) = solve ss
  putStr $ show ans
  putStr " "
  putStrLn $ show i

solve :: [Double] -> (Double, Int)
solve (w:h:x:y:_) = (w * h / 2.0, i)
  where
    i = if w / 2.0 == x && h / 2.0 == y
        then 1
        else 0

Measured memory_bytes: 508
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int P = 1e9 + 7;
int h, w, cnt, s1, s2, f1, f2, k;
char s[2050][2050];
struct Maxtir {
	int a[10][10], n;
	void init(int _n, int x) {n = _n; memset(a, 0, sizeof a); for(int i = 1; i <= n; ++i) a[i][i] = x;}
	Maxtir operator *(const Maxtir &b) const {
		Maxtir c; c.init(n, 0);
		for(int i = 1; i <= n; ++i)
			for(int j = 1; j <= n; ++j)
				for(int k = 1; k <= n; ++k)
					c.a[i][j] = (c.a[i][j] + 1ll * a[i][k] * b.a[k][j] % P) % P;
		return c;
	}
};
int pint(int a, int b) {
	int res = 1;
	for(; b; a = 1ll*a*a%P, b>>=1) if(b&1) res=1ll*res*a%P;
	return res;
}
Maxtir pmax(Maxtir a, int b) {
	Maxtir res; res.init(a.n, 1);
	for(; b; a = a * a, b >>= 1) if(b&1) res = res * a;
	return res;
}
signed main() {
	scanf("%lld%lld%lld", &h, &w, &k);
	for(int i = 1; i <= h; ++i) {
		for(int j = 1; j <= w; ++j) {
			while(s[i][j] = getchar(), s[i][j] != '#' && s[i][j] != '.');
			cnt += (s[i][j] == '#');
			s1 += (s[i][j] == '#' && s[i][j-1] == '#');
			s2 += (s[i][j] == '#' && s[i-1][j] == '#');
		}
		f1 += (s[i][1] == '#' && s[i][w] == '#');
	}
	for(int i = 1; i <= w; ++i) f2 += (s[1][i] == '#' && s[h][i] == '#');
	if(f1 && f2) {puts("1"); return 0;}
	if(!f1 && !f2) {printf("%lld\n", pint(cnt, k-1)); return 0;}
	if(!f1) swap(f1, f2), swap(s1, s2);
	Maxtir ori; ori.init(2, 0);
	ori.a[1][1]	= cnt; ori.a[2][1] = s1; ori.a[2][2] = f1;
	ori = pmax(ori, k-1);
	printf("%lld\n", (ori.a[1][1] - ori.a[2][1] + P) % P);
} 

Measured memory_bytes: 2304
// インクルード(GCC only)
#include <bits/stdc++.h>

// 長い型名
using namespace std;
typedef long long LL;

// 省略記法
#define INF 1e9
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define rrep(i,n) for(int i##_len=(n), i=(i##_len-1); i>=0; ++i)
#define FOR(i,m,n) for(int i=(m), i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define sizei(x) ((int)(x).size())
#define fill(x,y) memset(x,y,sizeof(x))
#define printvector(x) rep(i,sizei(x)){cout << x[i] << endl;}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

// mod付き四則演算(mod関数のオーバーヘッドが重いかも)
// TODO: 二項係数、離散対数、平方剰余の実装
#define MOD 1000000007
inline LL mod(LL const &a) { return (a % MOD + MOD) % MOD; }
inline LL madd(LL const &a, LL const &b) { return mod(mod(a) + mod(b)); }
inline LL msub(LL const &a, LL const &b) { return mod(mod(a) - mod(b)); }
inline LL mmul(LL const &a, LL const &b) { return mod(mod(a) * mod(b)); }
inline LL mpow(LL a, LL b) {
  LL r = 1;
  for (; b > 0; b >>= 1) {
    if (b & 1) (r *= a) %= MOD;
    (a *= a) %= MOD;
  }
  return r;
}
inline LL minv(LL const &a) { return mpow(a, MOD-2); }
inline LL mdiv(LL const &a, LL const &b) { return mod(mod(a) * minv(b)); }


// デバッグ用
#ifdef LOCAL
    #define eprint(...) fprintf(stderr, __VA_ARGS__)
    #define eprintvector(x) printvector(x)
#else
    #define eprint(...) 42
    #define eprintvector(x) 42
#endif

/**************** 便利な関数 ****************/
// 文字列の分割
vector<string> split_impl(string &&s, regex &&r) { return { sregex_token_iterator{s.begin(), s.end(), r, -1}, sregex_token_iterator{} }; }
auto split(string s, string pattern) { return split_impl(move(s), regex{pattern}); }


int main(void)
{
    int N, K;
    string S;

    cin >> N >> S >> K;

    rep(i, N) {
        if (S[i] != S[K-1]) {
            S[i] = '*';
        }
    }

    cout << S << endl;

    return 0;
}


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

using namespace std;

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

	string result;
	if(N % 10 == 3) {
		result = "bon";
	} else if(N % 10 == 0
		|| N % 10 == 1
		|| N % 10 == 6
		|| N % 10 == 8) {
		result = "pon";
	} else {
		result = "hon";
	}

	cout << result << endl;

	return 0;
}


Measured memory_bytes: 3576
#include<bits/stdc++.h>
#define ll long long
#define re register
#define ull unsigned ll
using namespace std;
inline int read(){
	int s=0,t=1;
	char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')t=-1;ch=getchar();}
	while(ch>='0'&&ch<='9')s=(s<<3)+(s<<1)+(ch^48),ch=getchar();
	return s*t;
}
const int P=1e9+7;
const int N=2e5+5;
int H,W,A,B,Ans,fac[N],inv[N];
int Mod(int x){return x>=P?x-P:x;}
int ksm(int x,int k){
	int res=1;
	while(k){
		if(k&1)res=1ll*res*x%P;
		x=1ll*x*x%P,k>>=1;
	}return res;
}
void Pre(int n){
	fac[0]=1;for(int i=1;i<=n;i++)fac[i]=1ll*fac[i-1]*i%P;
	inv[n]=ksm(fac[n],P-2);for(int i=n;i>=1;i--)inv[i-1]=1ll*inv[i]*i%P;
}
int C(int n,int m){return (n<m||m<0||n<0)?0:1ll*fac[n]*inv[m]%P*inv[n-m]%P;}
int F(int n,int m){return C(n+m-2,n-1);}
int main(){
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	H=read(),W=read(),A=read(),B=read(),Pre(2e5);
	for(int i=B+1;i<=W;i++)Ans=Mod(Ans+1ll*F(H-A,i)*F(A,W-i+1)%P);
	printf("%d",Ans);
	return 0;
}


Measured memory_bytes: 5308
def main():
    n,m=list(map(int,input().split(' ')))
    l_max=0
    r_min=n
    for i in range(m):
        l,r=list(map(int,input().split(' ')))
        if l>l_max:
            l_max=l
        if r < r_min:
            r_min=r
    if r_min>=l_max:
        print(r_min-l_max+1)
    else:
        print(0)
if __name__=='__main__':
    main()

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

typedef pair<int, int> pii;
typedef long long ll;
template<class T> using V = vector<T>;
template<class T> using VV = V<V<T>>;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()

#ifdef LOCAL
#define dump(x) cerr << __LINE__ << " " << #x << " = " << (x) << endl
#else 
#define dump(x) true
#endif

constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }

template<class T, class U> void chmin(T& t, const U& u) { if (t > u) t = u; }
template<class T, class U> void chmax(T& t, const U& u) { if (t < u) t = u; }

template<class T, class U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
	os<<"("<<p.first<<","<<p.second<<")";
	return os;
}

template<class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
	os<<"{";
	rep(i, v.size()) {
		if (i) os<<",";
		os<<v[i];
	}
	os<<"}";
	return os;
}

const int maxn = 100010;
const int L = TEN(9);

V<pii> g[maxn];

int main() {
	int N, M; cin >> N >> M;
	V<int> D(N); rep(i, N) cin >> D[i];
	V<pii> es(M);

	rep(i, M) {
		int a, b;
		cin >> a >> b;
		--a; --b;
		g[a].eb(b, i);
		g[b].eb(a, i);
	}

	V<pii> vec;
	rep(i, N) vec.eb(mp(D[i], i));
	sort(ALL(vec));

	V<int> ans(M, L);
	V<int> col(N, -1);

	rep(i, N) {
		int v = vec[i].se;
		dump(v);
		if (col[v] != -1) {
			continue;
		}

		bool fd = 0;

		for (auto e : g[v]) {
			if (col[e.fi] != -1) {
				if (D[e.fi] == D[v]) {
					col[v] = col[e.fi] ^ 1;
					dump(mp(v,e.fi));
					dump(D[v]);
					ans[e.se] = D[v];
				} else {
					col[v] = col[e.fi];
					ans[e.se] = D[v] - D[e.fi];
					dump(mp(v,e.fi));
					dump(D[v]-D[e.fi]);					
				}
				fd = 1;
				break;
			} else {
				if (D[v] == D[e.fi]) {
					col[e.fi] = 0;
					col[v] = 1;
					ans[e.se] = D[v];
					dump(e.se);
					dump(D[v]);
					fd = 1;
					break;
				}
			}
		}
		if (!fd) {
			puts("-1");
			return 0;
		}
		dump(ans);
	}

	string s(N, '?');
	rep(i, N) {
		if (col[i] == 1) s[i] = 'B';
		else s[i] = 'W';
	}
	cout << s << endl;

	rep(i, M) {
		cout << ans[i] << "\n";
	}

	return 0;
}

Measured memory_bytes: 14328
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;

int k;
int n;
int a[2000005];

int main(){
	cin>>k>>n;
	int dis=0;
	for (int i=1;i<=n;i++){
		scanf("%d",&a[i]);
		dis = max(dis,a[i]-a[i-1]);
	}
	dis = max(dis,a[1]+k-a[n]);
	cout<<k-dis<<endl;
	
	return 0; 
} 

Measured memory_bytes: 4516
#include <iostream>
using namespace std;
#include <algorithm>
#include <vector>
#include <cmath>
#define MOD1 1000000007
#define MOD2 998244353
#define LIMIT1 200002
#define LIMIT2 500002
typedef long long ll;
typedef long double ld;
typedef const void cv;
#define rep(i,n) for((i)=0;(i)<(n);(i)++)
#define per(i,n) for((i)=(n)-1;(i)>=0;(i)--)
#define max(a,b) ((a)>(b) ? (a) : (b))
#define min(a,b) ((a)<(b) ? (a) : (b))
#define zt(a,b) (max((a),(b))-min((a),(b)))
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll nPr(int n,int r){ll i,result=1;rep(i,r){result*=(ll)(n-i);}return result;}
ll nCr(int n,int r){ll i,result=1;if(n<r) return 0;rep(i,min(r,n-r)){result*=(ll)(n-i);result/=(ll)(i+1);}return result;}
#define nHr(n,r) nCr((int)((n)+(r)+1),(int)(r))
#define sankaku(x) (((x)*((x)+1))/2)
int dx[8]={1,0,-1,0,1,-1,-1,1},dy[8]={0,1,0,-1,1,1,-1,-1};
#define downint greater<int>()
#define downchar greater<char>()
#define downstring greater<string>()
void tmpInit(int *c,ll m) {ll i;rep(i,m) c[i]=i;}
ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1){
      res *= a; if(mod>=1) res %= mod;
    }
    a *= a; if(mod>=1) a %= mod;
    n >>= 1;
  }
  return res;
}
void initialize(){
  
}
int main(void){
  initialize();
  ll n,m,i,j,k,result=0;
  int a[LIMIT2]={0};
  char s[LIMIT1];
  
  cin >> n >> k;
  rep(i,n){
    cin >> a[i];
    if(a[i]>=k) result++;
  }
  cout << result << endl;
  
  return 0;
}

Measured memory_bytes: 2176
#include <iostream>
#include <string>
#include <cstring>
#include <cstdlib>

using namespace std;

string convert(string str) {
    int idx = 0;
    for (;;) {
        idx = str.find("Hoshino", idx);
        if (idx == string::npos) break;
        str.replace(idx, 7, "Hoshina");
        idx += 7;
    }
    return str;
}

int main() {
    int n;
    string str;
    getline(cin, str);
    n = atoi(str.c_str());
    for (int i = 0; i < n; i++) {
        getline(cin, str);
        cout << convert(str) << endl;
    }
    return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
typedef long long ll;
using namespace std;

const ll mod = 1e9 + 7;

int main()
{
  ll N;
  cin >> N;
  ll ans = 1;
  for (int i = 1; i <= N; i++)
  {
    ans = (ans * i) % mod;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>

using namespace std;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;

int main() {
  string s;
  int m;
  cin >> s >> m;
  int n = s.size();
  string ret;
  for (int i = 0; i < n; i += m) {
    ret += s[i];
  }
  cout << ret << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define all(x) (x).begin(), (x).end()
#define PI 3.14159265358979323846264338327950L
using namespace std;
typedef long long ll;
typedef long double ld;
int main() {
    int x,y,z;
    cin>>x>>y>>z;
    x=x-z;
    cout<<x/(y+z);
}

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

int main() {
    int d, g, ans = 0, es, numpro, mus;
    cin >> d >> g;
    vector<int> p(d), c(d);
    for (int i = 0; i < d; i++) {
        cin >> p.at(i) >> c.at(i);
        ans += p.at(i);
    }
    for (int bit = 0; bit < (1 << d); bit++) {
        vector<bool> solved(d, false);
        es = 0;
        numpro = 0;
        mus = d;
        for (int i = 0; i < d; i++) {
            if(bit & (1 << i)) {
                es += 100 * (i + 1) * p.at(i) + c.at(i);
                numpro += p.at(i);
                if(!(bit & (1 << (i - 1)))) mus = i - 1;
            }
        }
        if(!(bit & (1 << (d - 1)))) mus = d - 1; 
        if (es >= g) ans = min(ans, numpro);
        else {
            if(g - es > p.at(mus) * 100 * (mus + 1)) continue;
            else numpro += (g - es + 100 * (mus + 1) - 1) / (100 * (mus + 1));
        }
        ans = min(ans, numpro);
    }
    cout << ans << endl;
}

Measured memory_bytes: 3612
// Problem Code: abc176_c

#include <bits/stdc++.h>

using namespace std;

long long C(int N, vector<int>& A) {
	int max_h = 0;
	long long cnt = 0;
	for (int& x: A) {
		cnt += max(0, max_h - x);
		max_h = max(x, max_h);
	}
	return cnt;
}

int main() {
	int N;
	cin >> N;
	vector<int> A(N);
	for (int i = 0; i < N; i++)
		cin >> A[i];
	cout << C(N, A);
	return 0;
}

Measured memory_bytes: 3992
n = int(input())
s = input()
ans = 0
for i in range(1,n):
        s1 = s[:i]
        s2 = s[i:]
        a = set()
        b = set()
        c = set()
        for j in s1:
                a.add(j)
        for j in s2:
                b.add(j)
        c = a & b
        ans = max(ans,len(c))
print (ans)

Measured memory_bytes: 3064
//26
#include<iostream>
#include<cmath>

using namespace std;

double ds(double x,double y,double z){
  return sqrt(x*x+y*y+z*z);
}

int main(){
  for(int n;cin>>n,n;){
    double x[500],y[500],z[500];
    for(int i=0;i<n;i++){
      cin>>x[i]>>y[i]>>z[i];
    }
    int m;
    cin>>m;
    bool s[500]={};
    int ans=0;
    while(m--){
      double tx,ty,tz,an;
      cin>>tx>>ty>>tz>>an;
      for(int i=0;i<n;i++){
	double a,b,c;
	a=ds(tx-x[i],ty-y[i],tz-z[i]);
	b=ds(tx,ty,tz);
	c=ds(x[i],y[i],z[i]);
	if(acos((b*b+c*c-a*a)/b/c/2)<an){
	  ans+=!s[i];
	  s[i]=true;
	}
      }
    }
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 1308
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <map>

using namespace std;

long long x;
int n=0;
long long chokin=100;

int main(){
	cin>>x;
	while(chokin<x){
		n++;
		chokin+=chokin/100;

	}
	cout<<n<<endl;
}



Measured memory_bytes: 3636
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int n;
        n = sc.nextInt();

        int[] arr = new int[n];
        for(int i = 0; i < n; i++) arr[i] = sc.nextInt();

        int[] dp = new int[n];
        dp[0] = 0;
        dp[1] = Math.abs(arr[1] - arr[0]);

        for(int i = 2; i < n; i++){
            int first = dp[i-1] + Math.abs(arr[i] - arr[i-1]);
            int second = dp[i-2] + Math.abs(arr[i] - arr[i-2]);
            dp[i] = Math.min(first,second);
        }

        System.out.print(dp[n-1]);
    }
}


Measured memory_bytes: 54092
#include <iostream>
#include<vector>
#include<algorithm>
#include<cstring>
#include<string>
#include <set>
#include <cassert>
#include<cmath>
using namespace std;
#define MOD 1000000007
class UnionFind {
	vector<int> data;
public:
	UnionFind(int size) : data(size, -1) { }
	bool unionSet(int x, int y) {
		x = root(x); y = root(y);
		if (x != y) {
			if (data[y] < data[x]) swap(x, y);
			data[x] += data[y]; data[y] = x;
		}
		return x != y;
	}
	bool findSet(int x, int y) {
		return root(x) == root(y);
	}
	int root(int x) {
		return data[x] < 0 ? x : data[x] = root(data[x]);
	}
	int size(int x) {
		return -data[root(x)];
	}
};

int find(vector<long long> &arr, long long obj) {
	if (arr[arr.size() - 1] < obj)return arr.size()-1;
	if (arr[0] > obj)return -1;

	int min = 0; int max = arr.size() - 1;
	for (int i = 0; i < arr.size(); i++) {
		if (arr[min+(max-min) / 2] > obj) {
			max = min + (max - min) / 2;
		}
		else {
			min = min + (max - min) / 2;
		}
		if (max - min == 1) {
			return min;
		}
	}


}


int main() {
	int n;
	cin >> n;
	int *a = new int[n];
	
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	int count = 1;
	int now = 0;
	int i = 0;
	while (1) {
		if (a[i+1] - a[i] > 0) {
			i++;
			now = 2;
			break;
		}
		else if (a[i+1] - a[i] < 0) {
			i++;
			now = 1;
			break;
		}
		i++;
	}
	for (i; i < n - 1; i++) {
		if (a[i + 1] - a[i] > 0) {
			if (now == 1) {
				count++;
				now = 0;
			}
			else {
				now = 2;
			}
		}
		else if (a[i + 1] - a[i] < 0) {
			if (now == 2) {
				count++;
				now = 0;
			}
			else {
				now = 1;
			}
		}
	}
	cout << count;
	return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<limits.h>
#include<math.h>

using namespace std;
#define MOD 1000000007


static long long int fact[200000] = { 0 };

long long int factrial(long long int num) {
	if (num == 0)return 1;
	if (num == 1)return 1;
	if (fact[num] != 0)return fact[num];

	long long int ans = 1;

	ans = num * factrial(num - 1) % MOD;
	fact[num] = ans;
	return ans;

}

long long int superpow(long long int num, long long int count) {
	if (count == 0)return 1;
	if (count == 1)return num;

	long long int wk = superpow(num, count / 2);

	if (count % 2 == 0)return (wk * wk) % MOD;

	return (((wk * wk) % MOD) * num) % MOD;

}

long long int inv(long long int num) {

	return superpow(num, MOD - 2) % MOD;

}

//nCrのやつ
long long int comb(long long int n, long long int r) {
	if (n == r)return 1;
	if (r == 0)return 1;
	long long int ans = 1;

	ans = factrial(n);

	long long int wk = 1;

	wk = factrial(r);
	
	ans = (ans * inv(wk)) % MOD;

	wk = 1;
	
	wk = factrial(n - r);

	ans = (ans * inv(wk)) % MOD;

	return ans;
}

long long int min(long long int a, long long int b) {
	if (a > b)return b;
	return a;



}


typedef pair<int, long long int> P;

bool pairCompare(const P& firstElof, const P& secondElof) {
	return firstElof.second > secondElof.second;
}




static int counta[100001];

void resetcount() {
	for (int i = 0; i < 100001; i++) {
		counta[i] = 0;
	}

}

int getModeNum() {
	int max = -1;
	int result;

	for (int i = 0; i < 100001; i++) {
		if (counta[i] > max) {
			max = counta[i];
			result = i;
		}
	}

	return result;
}



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

	vector<int> even;
	vector<int> odd;
	int wk;
	for (int i = 1; i <= n; i++) {
		if (i % 2 == 0) {
			cin >> wk;
			even.push_back(wk);
		}
		else {
			cin >> wk;
			odd.push_back(wk);
		}
	}

	int maxEven;
	int subMaxEven;
	int maxOdd;
	int subMaxOdd;

	int maxEvenCount;
	int subMaxEvenCount;
	int maxOddCount;
	int subMaxOddCount;


	//even配列、odd配列の各最頻値を求める。
	resetcount();
	for (int i = 0; i < even.size(); i++) {
		counta[even[i]]++;
	}
	maxEven = getModeNum();
	maxEvenCount = counta[maxEven];

	resetcount();
	for (int i = 0; i < odd.size(); i++) {
		counta[odd[i]]++;
	}
	maxOdd = getModeNum();
	maxOddCount = counta[maxOdd];

	//even配列、odd配列の最頻値を除いて、最頻のもの。
	resetcount();
	for(int i = 0; i < even.size(); i++){
		if (even[i] != maxEven)counta[even[i]]++;
	}
	subMaxEven = getModeNum();
	subMaxEvenCount = counta[subMaxEven];

	resetcount();
	for (int i = 0; i < odd.size(); i++) {
		if (odd[i] != maxOdd)counta[odd[i]]++;
	}
	subMaxOdd = getModeNum();
	subMaxOddCount = counta[subMaxOdd];

	int ans;

	//evenの最頻値とoddの最頻値が異なる場合、それにそろえるのが最良
	if (maxEven != maxOdd) {
		ans = even.size() - maxEvenCount + odd.size() - maxOddCount;
	}
	else {
		int wkans;

		//evenを最頻値に、oddをサブ最頻値に合わせる。
		ans = even.size() - maxEvenCount + odd.size() - subMaxOddCount;

		//evenをサブ最頻値に、oddを最頻値に合わせる。
		wkans = even.size() - subMaxEvenCount + odd.size() - maxOddCount;
		
		if (wkans < ans)ans = wkans;
	}

	cout << ans << endl;

}



Measured memory_bytes: 1276
n = int(input())
cnt = 0
flg = False
for i in range(n):
  a,b = list(map(int,input().split()))
  if a == b:
    cnt +=1
    if cnt > 2:
      flg = True
  else:
    cnt = 0
if flg:
  print('Yes')
else:
  print('No')

Measured memory_bytes: 9176