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

#define int long long

#define rep(i,s,n) for(int i = s;i<n;i++)
#define repe(i,s,n) for(int i = s;i<=n;i++)
#define rrep(i,s,n) for(int i = (n)-1;i>=(s);i--)
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define fi first
#define se second
#define chmin(a,b) a=min((a),(b))
#define chmax(a,b) a=max((a),(b))
typedef long long ll;
typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
typedef pair<pint,int> P1;
typedef pair<int,pint> P2;
typedef pair<pint,pint>PP;
static const ll maxLL = (ll)1 << 62;
const ll MOD=1000000007;
const ll INF=1e18;
int dx[]={0,0,1,-1};
int dy[]={-1,1,0,0};

int A,B,K;

signed main(){
    cin.tie(0);
	ios::sync_with_stdio(false);
    cin>>A>>B>>K;
    rep(i,0,K){
        if(i%2){
            if(B%2)B--;
            A+=B/2;
            B/=2;
        }else{
            if(A%2)A--;
            B+=A/2;
            A/=2;
        }
    }
    cout<<A<<" "<<B<<"\n";
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	private static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) {
		int n = sc.nextInt(), h = sc.nextInt(), w = sc.nextInt();
		System.out.println((n - h + 1) * (n - w + 1));
	}
}

Measured memory_bytes: 23764
package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	sc.Split(bufio.ScanWords)
	a, b, c := nextInt(), nextInt(), nextInt()
	if (a == b && a != c) || (a == c && a != b) ||(b == c && b != a) {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}

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

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}


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

int T, card[9];

bool is_same_number(int a, int b, int c){
  return a == b && b == c;
}

bool is_sequence(int a, int b, int c){
  return a+2 == b+1 && b+1 == c;
}

bool is_set(int a, int b, int c){
  return is_same_number(a, b, c) || is_sequence(a, b, c);
}

bool is_all_OK_set(){
  return(is_set(card[0], card[1], card[2])
	 && is_set(card[3], card[4], card[5])
	 && is_set(card[6], card[7], card[8]));
}

int win(){
  sort(card, card+9);
  do{
    if(is_all_OK_set())
      return 1;
  }while(next_permutation(card, card+9));
  return 0;
}

int main(){
  scanf("%d", &T);
  for(int t=0; t<T; ++t){
    for(int i=0; i<9; ++i){
      scanf("%d", &card[i]);
    }
    string color;
    for(int i=0; i<9; ++i){
      cin >> color;
      if(color == "G") card[i] += 10;
      else if(color == "B") card[i] += 20;
    }
    printf("%d\n", win());
  }
}

Measured memory_bytes: 1248
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll dp[101][100002];
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
int main()
{
    IOS;
    ll n,W; cin>>n>>W;
    //dp[i][j] represents the minimum weight required to get a value of j considering only the items from 0 to index i
    ll wt[n],val[n];
    for(int i = 0;i<=100;i++ )
    {
        for(int j=0;j<=100000;j++)
        {
            dp[i][j] = 99999999999999;
        }
    }
    for(ll i=1;i<=n;i++) cin>>wt[i]>>val[i];
        dp[0][0] = 0;
    for(ll i=1;i<=n;i++)
    {
        for(ll j=0;j<=1000*n;j++)
        {
            if(i==0 || j==0 ) dp[i][j] = 0 ;
            else if(val[i] <= j)
            {
                dp[i][j] = min(dp[i-1][j-val[i]] + wt[i],dp[i-1][j]);
            }
            else dp[i][j] = dp[i-1][j];
        }
    }
    ll ans = 0;
    for(ll i = 1000*n;i>=0;i--)
    {
        if(dp[n][i] <= W)
        {
            cout<<i;
            return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 79232
def main():
    A = list(map(int, input().split()))

    sort_A = sorted(A)

    cnt = 0

    cnt += (sort_A[2] - sort_A[0]) // 2
    sort_A[0] = sort_A[0] + ((sort_A[2] - sort_A[0]) // 2) * 2

    cnt += (sort_A[2] - sort_A[1]) // 2
    sort_A[1] = sort_A[1] + ((sort_A[2] - sort_A[1]) // 2) * 2

    sort_A.sort()
    if sort_A[0] == sort_A[1] == sort_A[2]:
        print(cnt)
    elif sort_A[1] == sort_A[2]:
        print(cnt + 2)
    elif sort_A[0] == sort_A[1]:
        print(cnt + 1)

    

main()

Measured memory_bytes: 38512
using System;
using System.IO;
using System.Collections;
using System.Collections.Generic;
using System.Linq;

class  CompetitiveProgrammingProgram
{
    static void Main(string[] args)
    {
        string s=Console.ReadLine();
        string[] s2={"SUN","MON","TUE","WED","THU","FRI","SAT"};
        int ans=7-Array.IndexOf(s2,s);        
        Console.WriteLine(ans.ToString());
    }
}

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

int main(void){
	int a,b;
	cin >> a >> b;
	while(a != 0 || b != 0){
		if(a < b) cout << a << " " << b << "\n";
		else cout << b << " " << a << "\n";
		cin >> a >> b;
	}
	return 0;

}


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

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

int main() {
  ll a,b,c;
  cin >> a >> b >> c;
  
  ll d = c - a - b;
  
  if(d > 0 && 4*a*b < d*d)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  
}


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

int main(){
  int X,A,B;
  cin >> X >> A >> B;
  if(A>=B){
    cout << "delicious" << endl;
  }
  else if(A+X<B){
    cout << "dangerous" << endl;
  }
  else{
    cout << "safe" << endl;
  }
}

Measured memory_bytes: 3632
import java.io.*;

class Main { 
	public static void main(String[] args){
		try{
			BufferedReader  br = new BufferedReader(new InputStreamReader(System.in));
			
			int n = Integer.parseInt(br.readLine());
			
			int[][][] count = new int[4][3][10];
			
			
			for(int i = 0;i < 4;i++){
				for(int j = 0;j < 3;j++){
					for(int k = 0;k < 10;k++){
						count[i][j][k] = 0;
					}
				}
			}
						
			for(int i = 0;i < n;i++){
			String[] line = br.readLine().split(" ");
			int b = Integer.parseInt(line[0]) -1;
			int f = Integer.parseInt(line[1]) -1;
			int r = Integer.parseInt(line[2]) -1;
			int v = Integer.parseInt(line[3]);
			count[b][f][r] += v;
			}

			for(int i = 0;i < 4;i++){
				if( i != 0){
					System.out.println("####################");
				}				
				for(int j = 0;j < 3;j++){
					for(int k = 0;k < 10;k++){
						System.out.print(" ");
						System.out.print(count[i][j][k]);
					}
					System.out.print("\n");
				}
			}
		} catch(Exception e){
		}
	}
}

Measured memory_bytes: 24600
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);
        int A = scanner.nextInt();
        int B = scanner.nextInt();
        int C = scanner.nextInt();
        int D = scanner.nextInt();
        while (true) {
            C -= B;
            if (C <= 0) {
                System.out.println("Yes");
                return;
            }
            A -= D;
            if (A <= 0) {
                System.out.println("No");
                return;
            }
        }
    }
}

Measured memory_bytes: 35788
#include <iostream>
#include <vector>
#include <algorithm>
#define ll long long
#define ull unsigned long long
using namespace std;

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

	int n, k;
	cin >> n >> k;
	vector<int> V(n);
	for (int &v : V) cin >> v;
	sort(V.begin(), V.end());
	vector<int> DP(k + 1, -1);
	DP.at(0) = 0;
	bool f, found;
	for (int i = V.at(0); i <= k; i++){
		found = false;
		f = true;
		int ref = DP.at(i - V.at(0));
		for (int x : V){
			if (i - x < 0) break;
			switch (DP.at(i - x)){
				case -1:
					found = true;
					break;
				case 0:
					if (ref == 1) f = false;
					break;
				case 1:
					if (ref == 0) f = false;
					break;
			}
		}

		if (found){
			DP.at(i) = 1;
		} else if (f){
			DP.at(i) = (ref + 1) % 2;
		} else {
			DP.at(i) = 1;
		}
	}

	if (DP.back() == 0){
		cout << "Second";
	} else {
		cout << "First";
	}

	return 0;
}

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

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; }

using ll = long long;

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int INF = 1<<30;
const ll mod = 998244353LL;

ll pow(ll a, ll n, ll m) {
	ll ret = 1LL;
	for (; n > 0LL; n >>= 1LL, a = a * a % m) {
		if (n % 2LL == 1LL) {
			ret = ret * a % m;
		}
	}
	return ret;
}

int main() {
  ll N,M,K;
  cin>>N>>M>>K;
  ll ans = 0;
  ll comb = 1LL;
  for(ll i = 0LL; i <= K; i++){
    ans=(ans+(comb*pow(M-1,N-1-i,mod)))%mod;
    comb=(((comb*(N-1-i))%mod)*pow(i+1,mod-2,mod))%mod;
  }
  ans=(ans*M)%mod;
  cout<<ans<<endl;
}

Measured memory_bytes: 3596
import java.util.*;

public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
      int num1 = sc.nextInt();
      int num2 = sc.nextInt();
      int num3 = num1 * num2;
      int checknum = num3 % 2;
      if(checknum == 0){
      System.out.println("Even" /*+ checknum*/);
      }
      else{
        System.out.println("Odd"/* + checknum*/); 
      }
  }
}

Measured memory_bytes: 21844
n = int(input())
lis = list(map(int,input().split()))
ans = 1000
for i in range(n-1):
    if lis[i] < lis[i+1]:
        num = ans//lis[i]
        ans %= lis[i]
        ans += num * lis[i+1]
print(ans)

Measured memory_bytes: 9176
#include <bits/stdc++.h>
typedef long long int lli;
using namespace std;

int main()
{
	ios_base::sync_with_stdio(0);
    cin.tie(nullptr);
    cout.tie(nullptr);
    vector <int> a(3);
    for(int i=0;i<3;++i)
        cin>>a[i];
    sort(a.begin(),a.end());
    if(a[0]==a[1]&&a[0]!=a[2])
        cout<<"Yes";
    else if(a[1]==a[2]&&a[0]!=a[1])
        cout<<"Yes";
    else
        cout<<"No";
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <limits>
#include <numeric>
#include <queue>
#include <set>
#include <bitset>
#include <map>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<char> vc;
typedef vector<long long> vll;
typedef queue<int, int> qii;
typedef pair<int, int> pii;
typedef pair<string, int> psi;

#define PI 3.14159265359
#define rep(i,a) for(int i=0;i<a;i++)

//int型を受け取ってその桁数を返す
int check_digits(int n, int m) {
	int digits = 0;
	while (n != 0) {
		n /= m;
		digits++;
	}
	return digits;
}

//int型を受け取ってその各桁の和を返す
int sum_digits(int n) {
	int sum = 0;
	int N = n;
	while (N) {
		sum += N % 10;
		N /= 10;
	}
	return sum;
}


//最大公約数を返す関数
int gcd(int n, int m) {
	while (n != 0) {
		if (n < m) swap(n, m);
		n = n % m;
	}
	return m;
}


//2点間の距離を返す
float dis(int x1, int y1, int x2, int y2) {
	return sqrt(pow(abs(x1 - x2), 2) + pow(abs(y1 - y2), 2));
}


//入力された文字列が回文か判断してboolを返す
bool is_kaibun(string s) {
	string s_r(s.rbegin(), s.rend());
	return (s == s_r);
}


void yes() { cout << "Yes" << endl; }
void no() { cout << "No" << endl; }


//提出言語もしっかり確認して…
//問題文を落ち着いて読む！
//型に注意！！
//出力例もちゃんと全部見る！！！！！
int main() {
	int m,n;
	cin >> m;
	n = m - 1;
	vi b(n);
	rep(i, n)cin >> b[i];
	ll ans = b[0];
	for (int i = 1; i < n; i++) {
		if (b[i - 1] >= b[i])ans += b[i];
		else ans += b[i - 1];
	}
	ans += b[b.size() - 1];
	cout << ans << endl;

	system("pause");
	return 0;
}


Measured memory_bytes: 504
package main

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

var sc = bufio.NewScanner(os.Stdin)
var out = bufio.NewWriter(os.Stdout)

func main() {
	sc.Split(bufio.ScanWords)
	defer out.Flush() // !!!!coution!!!! you must use Fprint(out, ) not Print()
	/* --- code --- */
	k := int64(nextInt())
	// k := int64(200) //for test
	sum := int64(0)
	for i := int64(1); i <= k; i++ {
		for j := int64(1); j <= k; j++ {
			for l := int64(1); l <= k; l++ {
				sum += int64(gcd(gcd(int(i), int(j)), int(l)))
			}
		}
	}
	fmt.Println(sum)
}

// -*-*-*-*-*-*-*-*-
// * I/O utilities *
// -*-*-*-*-*-*-*-*-

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

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

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

func nextInts(n int) []int {
	ret := make([]int, n)
	for i := 0; i < n; i++ {
		ret[i] = nextInt()
	}
	return ret
}
func nextFloats(n int) []float64 {
	ret := make([]float64, n)
	for i := 0; i < n; i++ {
		ret[i] = nextFloat64()
	}
	return ret
}
func nextStrings(n int) []string {
	ret := make([]string, n)
	for i := 0; i < n; i++ {
		ret[i] = next()
	}
	return ret
}

func split(s string) []string {
	ret := make([]string, len([]rune(s)))
	for i, v := range []rune(s) {
		ret[i] = string(v)
	}
	return ret
}

func PrintOut(src interface{}, joinner string) {
	switch reflect.TypeOf(src).Kind() {
	case reflect.Slice:
		s := reflect.ValueOf(src)
		for idx := 0; idx < s.Len(); idx++ {
			fmt.Fprintf(out, "%v", s.Index(idx))
			if idx < s.Len()-1 {
				fmt.Fprintf(out, "%s", joinner)
			} else {
				fmt.Fprintln(out)
			}
		}
	default:
		fmt.Fprintln(out, "fuck")
	}
}

// -*-*-*-*-*-*-*-*-
// * tool snippets *
// -*-*-*-*-*-*-*-*-
func duplicate2Int(base [][]int) (ret [][]int) {
	ret = make([][]int, len(base))
	for i, v := range base {
		ret[i] = append([]int{}, v...)
	}
	return
}

// -*-*-*-*-*-*-*-*-*-*-*-*-*-
// * Algorithms Utility Zone *
// -*-*-*-*-*-*-*-*-*-*-*-*-*-

// -*-*-*-*-*-*-*-
// * 1. nibutan  *
// -*-*-*-*-*-*-*-
func lower_bound(arr []int, target int) int {
	l, r := 0, len(arr)
	for l < r {
		mid := (l + r) / 2
		if arr[mid] < target {
			l = mid + 1
		} else {
			r = mid
		}
	}
	return l
}

func upper_bound(arr []int, target int) int {
	l, r := 0, len(arr)
	for l < r {
		mid := (l + r) / 2
		if target < arr[mid] {
			r = mid
		} else {
			l = mid + 1
		}
	}
	return l
}

// *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-
// * math flavor typical theories *
// *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-
func gcd(a, b int) int {
	if a > b {
		return gcd(b, a)
	}
	for a != 0 {
		a, b = b%a, a
	}
	return b
}

func pow(a, b int) (ret int) {
	ret = a
	// 10^2 = 100ってことは10に10を1回掛けることだね
	// なので初期値を含めると上限b-1未満
	for i := 0; i < b-1; i++ {
		ret *= a
	}
	return
}

func powMod(n, m, mod int) (ret int) {
	ret = 1
	for m > 0 {
		if m&1 == 1 {
			ret *= n
			ret %= mod
		}
		n *= n
		n %= mod
		m >>= 1
	}
	return ret
}


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

#define reint register int
#define coint const int

using namespace std;

const double EPS = 1e-8;

struct Vector {
    double x, y;

    inline Vector operator+(const Vector &v) const {
        return (Vector){ x + v.x, y + v.y };
    }

    inline double dot(const Vector &v) const { return x * v.x + y * v.y; }
    inline double cross(const Vector &v) const { return x * v.y - y * v.x; }
    inline double length(void) const { return sqrt(x * x + y * y); }
    inline double square(void) const { return x * x + y * y; }

    inline Vector operator*(const double a) const {
        return (Vector){ x * a, y * a };
    }
};

struct Point {
    double x, y;

    inline Vector operator-(const Point &p) const {
        return (Vector){ x - p.x, y - p.y };
    }

    inline Point operator+(const Vector &v) const {
        return (Point){ x + v.x, y + v.y };
    }
};

inline int isEq(const double a, const double b) {
    return abs(a - b) < EPS;
}

int main(void) {
    Point p0, p1;
    scanf("%lf%lf%lf%lf", &p0.x, &p0.y, &p1.x, &p1.y);
    const Vector vec01 = p1 - p0;
    int q;
    scanf("%d", &q);
    for (reint i = 1; i <= q; ++i) {
        Point p2;
        scanf("%lf%lf", &p2.x, &p2.y);
        const Vector vec02 = p2 - p0;
        const double cross = vec01.cross(vec02);
        if (isEq(cross, 0)) {
            if (vec01.dot(vec02) + EPS < 0)
                puts("ONLINE_BACK");
            else if (vec01.square() + EPS < vec02.square())
                puts("ONLINE_FRONT");
            else puts("ON_SEGMENT");
        } else if (cross < 0)
            puts("CLOCKWISE");
        else puts("COUNTER_CLOCKWISE");
    }

    return 0;
}



Measured memory_bytes: 3236
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <assert.h>
#include <numeric>
#include <math.h>
#include <climits>

using namespace std;
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
typedef long long ll;

template <typename T>
T gcd(T a, T b) {
    if(a < b) gcd(b, a);
    if (b == 1) return 1;
    T r;
    while ((r=a%b)) {
        a = b;
        b = r;
    }
    return b;
}

int main() {
    int A, B;
    cin >> A >>  B;
    if (A >= 13) cout << B << endl;
    else if (A >= 6) cout << B/2 << endl;
    else cout << 0 << endl;
    
}


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

#define FOR(k,m,n) for(int (k)=(m);(k)<(n);(k)++)
#define rep(i,n) FOR((i),0,(n))

typedef long long ll;

const int INF=1e9+7;
const int MAX_N=1e3+4;
ll prime[MAX_N];
bool is_prime(int x){
	if(x<2)return false;
	for(int i=2;i*i<=x;i++){
		if(x%i==0)return false;
	}
	return true;
}
int main(){
	int n;
	cin>>n;
	ll ans=1;
	for(int i=2;i<=n;i++){
		int t=i;
		for(int j=2;j<=i;j++){
			if(is_prime(j)){
				while(t%j==0){
					prime[j]++;
					t/=j;
				}
			}
		}
	}
	rep(i,n+1)ans=(ans*(prime[i]+1))%INF;
	cout<<ans<<endl;
}


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

struct edge {
   int a, b, w;
} e[8192];

int cmp(const void *a, const void *b) {
   return (*(edge*)a).w - (*(edge*)b).w;
}

int f[128];

int getfather(int x) {
   if (f[x] != x) f[x] = getfather(f[x]);
	return f[x];
}

int main() {

int N, E, i, j, k, BEST, fa, fb;

cin >> N;
cin >> E;

do {

for (i=0; i<E; i++) {
   cin >> e[i].a; e[i].a--;
   cin >> e[i].b; e[i].b--;
	cin >> e[i].w;
}

qsort(e, E, sizeof(edge), cmp);

BEST = -1;
for (i=0; i<E; i++) {
   for (j=0; j<N; j++) f[j] = j;

	for (k=0,j=i; j<E && k<N-1; j++) {
		fa = getfather(e[j].a);
		fb = getfather(e[j].b);
	   if (fa != fb) {
			f[fa] = fb;
			k++;
		}
	}

	if (k == N-1 && (BEST == -1 || BEST > e[j-1].w - e[i].w)) BEST = e[j-1].w - e[i].w;
}

cout << BEST << endl;

cin >> N;
cin >> E;

} while (N!=0 || E!=0);

return 0;
}

Measured memory_bytes: 1384
# https://atcoder.jp/contests/diverta2019-2/tasks/diverta2019_2_b

n = int(input())
ball = []
s = set()
for _ in range(n):
    x, y = map(int, input().split())
    ball.append((x, y))
    s.add((x, y))

ans = n
for i in range(n):
    x, y = ball[i]
    for j in range(n):
        dx, dy = x - ball[j][0], y - ball[j][1]
        if dx == 0 and dy == 0:
            continue
        point = 0
        for k in range(n):
            a, b = ball[k][0] - dx, ball[k][1] - dy
            if (a, b) in s:
                point += 1
        ans = min(ans, n - point)
print(ans)

Measured memory_bytes: 40048
#include<bits/stdc++.h>
#define rep(i,n) for (int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
//vectorの中身を表示する
int main(){
    ll X;
    cin >> X;
    ll cnt=0;
    ll tmp = 100;
    while(true)
    {
        if(tmp >= X) break;
        tmp = (ll) tmp * 1.01;
        cnt++;
    }

    cout << cnt;

    return 0;
}


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

int main() {
  int N;
  cin >> N;
  
  int sum = 0;
  int l, r;

  for (int i=0; i < N; i++) {
    cin >> l >> r;
    sum += r -l + 1;
  }
  
  cout << sum << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<queue>
#include<functional>
using namespace std;
int n, x[100009], p[100009], r[100009], cnt;
int main() {
	cin >> n;
	for (int i = 1; i <= n; i++) { cin >> x[i]; if (x[i] == i)p[i] = 1; }
	for (int i = 1; i <= n; i++) {
		if (p[i] == 0)continue;
		if (p[i] == 1) {
			if (p[i - 1] == 0 || r[i] == 0) {
				cnt++; r[i + 1] = 1;
			}
		}
	}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 1408
local n, q = io.read("*n", "*n")
local edge = {}
local cost = {}
for i = 1, n do
  edge[i] = {}
  cost[i] = 0
end
for i = 1, n - 1 do
  local a, b = io.read("*n", "*n")
  edge[a][b] = true
end
for i = 1, q do
  local p, x = io.read("*n", "*n")
  cost[p] = cost[p] + x
end


local taskstate = {}
for i = 1, n do taskstate[i] = false end
local tasks = {}
local tasknum = 0
local done = 0

local function addtask(idx)
  if not taskstate[idx] then
    taskstate[idx] = true
    tasknum = tasknum + 1
    tasks[tasknum] = idx
  end
end
addtask(1)

while done < tasknum do
  done = done + 1
  local src = tasks[done]
  taskstate[src] = false
  for dst, unused in pairs(edge[src]) do
    cost[dst] = cost[dst] + cost[src]
    addtask(dst)
  end
end
print(table.concat(cost, " "))


Measured memory_bytes: 48764
import sys
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
mod = 10**9 + 7
inf = float('inf')

N = I()
p = LI()
cur = 0
ans = int(0)

for i in range(N):
    if p[i]==i+1:
        cur +=1
        if i!=(N-1):
            p[i + 1] = p[i]
ans = cur
print(ans)

Measured memory_bytes: 52316
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define For(i,n) for(int i=0;i<n;i++)
#define mem(a,b) memset(a,b,sizeof(a))
#define int long long int
#define ld long double
#define fio ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define ld long double
#define pb push_back
#define ff first
#define ss second
#define vpi vector<pair<int,int> >
#define vv vector<int>
#define MAXN 1001
#define PI 3.1415926535897932384626
int A[MAXN];


int32_t main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	fio;
	long double a, b, h, m;
	cin >> a >> b >> h >> m;
	long double x = h * 30 + m / 2;
	long double y = 6 * m;
	double e = abs(x - y) * PI / 180;
	double ans = sqrt(a * a + b * b - 2 * a * b * cos(e) );
	printf("%.12lf\n", ans);


}


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

int main() {
  int N, L;
  cin >> N >>L;
  vector<string>S(N);
  
  for(int i=0; i<N; i++)cin >> S.at(i);
  
  sort(S.begin(), S.end());
  
  for(int i=0; i<N; i++){
    cout << S.at(i);
  }
  
  cout << endl;
}

Measured memory_bytes: 3556
#include <iostream>
#include <vector>
#include <climits>

using namespace std;

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

	vector<int> a(n), b(n);
	vector<long long> d(h + 1, LLONG_MAX);
	d[0] = 0;
	for (int i = 0; i < n; i++) {
		cin >> a[i] >> b[i];
	}

	for (int i = 0; i < n; i++) {
		if (a[i] >= h) {
			for (int j = 1; j <= h; j++) {
				if (d[j] > b[i]) {
					d[j] = b[i];
				}
			}
		}
		else {
			for (int j = 1; j <= a[i]; j++) {
				if (d[j] > b[i]) {
					d[j] = b[i];
				}
			}
			for (int j = a[i] + 1; j <= h; j++) {
				if (d[j] > d[j - a[i]] + b[i]) {
					d[j] = d[j - a[i]] + b[i];
				}
			}
		}
	}

	cout << d[h] << endl;

	return 0;
}

Measured memory_bytes: 384
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cstring>
#include <string>
#include <cctype>
#include <sstream>
#include <cmath>
#include <climits>
#include <set>
#include <iostream>
#include <map>
#include <functional>
#include <cstdlib>
#include <numeric>
#include <queue>
#include <complex>

using namespace std;

#define reep(i,f,n) for(int i=f; i<int(n); ++i)
#define rep(i,n) reep(i,0,n)

typedef vector<int> vi;
typedef pair<int, int> pii;
typedef complex<double> Point;

int main()
{
	int guest[8];
	while(1){
		rep(i, 8){
			if(scanf("%d", &guest[i]) == EOF)
				return 0;
		}

		int best = INT_MAX;
		string best_str;
		string str = "14141212";
		rep(i, 8){
			int cnt = 0;
			rep(j, 8)
				cnt += max(0, guest[j]-str[j]+'0');
			if(cnt<best || (cnt==best && str<best_str)){
				best = cnt;
				best_str = str;
			}

			char tmp = str[0];
			rep(j, 7)
				str[j] = str[j+1];
			str[7] = tmp;
		}

		rep(i, 8)
			printf("%s%c", i?" ":"", best_str[i]);
		puts("");
	}

	return 0;
}

Measured memory_bytes: 0
s = list(input())
YYMM = 0
MMYY = 0
if 1 <= int(s[2]+s[3]) <= 12:
    YYMM = 1
if 1 <= int(s[0]+s[1]) <= 12:
    MMYY = 1

if MMYY == YYMM == 1:
    print("AMBIGUOUS")
elif YYMM == 1:
    print("YYMM")
elif MMYY == 1:
    print("MMYY")
else:
    print("NA")

Measured memory_bytes: 38256
#include <iostream>
#include <limits.h>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <utility>
#include <vector>

using namespace std;

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


int main(){

  ios_base::sync_with_stdio(false);
  ll x,a,b,cnt=0;
  
  cin>>x;

  a = floor(x/11);
  b = x%11;
  
  cnt += 2*a;

  if(b==0) cout << cnt << endl;
  else if(b<=6) cout << cnt+1 << endl;
  else cout << cnt+2 << endl;


  
  
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long ul;
// for文短縮類
#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPD(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i <= (ll)(b); i++)
#define FORD(i, a, b) for (ll i = a; i >= (ll)(b); i--)
// iteratorのbeginとendをまとめて渡す
#define ALL(x) (x).begin(), (x).end()
//略
#define PB push_back  // vectorヘの挿入
#define MP make_pair  // pairのコンストラクタ
#define F first       // pairの一つ目の要素
#define S second      // pairの二つ目の要素
//出力
#define COUT(x) cout << (x) << endl
#define SCOUT(x) cout << (x) << " "
#define ENDL cout << endl
/************ Combination wtih MOD ************
const int MAX = 510000;
const int MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];
// preprocess for some tables
void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++) {
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}
// combination
long long COM(int n, int k) {
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
*******************************************************/
/********** UnionFind ***************
struct UnionFInd {
vector<ll> par;
UnionFInd(ll N) : par(N) {
for (ll i = 0; i < N; i++) {
par[i] = i;
}
}
ll root(ll x) {
if (par[x] == x) return x;
return par[x] = root(par[x]);
}
void unite(ll x, ll y) {
ll rx = root(x);
ll ry = root(y);
if (rx == ry) return;
par[rx] = par[ry];
}
bool same(ll x, ll y) {
ll rx = root(x);
ll ry = root(y);
return rx == ry;
}
};
*************************************/
/***********************************
ll gcd(ll a, ll b) {
  if (a < b) {
    swap(a, b);
  }

  ll r = a % b;
  while (r > 0) {
    a = b;
    b = r;
    r = a % b;
  }
  return b;
}
***********************************/
int main(int argc, char *argv[]) {
  // input高速化。cinとcoutの結合解除。scanfとprintfは使えない。
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  ll n;
  cin >> n;
  vector<char> c;
  REP(i, n) {
    char ci;
    cin >> ci;
    c.push_back(ci);
  }
  ll left = 0;
  ll right = n - 1;
  ll ans = 0;

  while (left < n && right >= 0 && left < right) {
    while (left < n && c[left] == 'R') {
      left += 1;
    }

    while (right >= 0 && c[right] == 'W') {
      right -= 1;
    }

    if(left < right){
        ans += 1;
        left += 1;
        right -= 1;
    }
  }
  cout << ans << endl;
 
}

Measured memory_bytes: 3756
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<math.h>
#include<stdlib.h>
#include<string>
#include<iostream>
#include<set>
#include<map>
#include<deque>
using namespace std;
typedef long long ll;
typedef pair<ll, ll>pii;
typedef pair<pii, ll>pi3;
ll mod = 1000000007;
int d[1000];
int main()
{
	int n;
	scanf("%d", &n);
	set<int>se;
	for (int i = 0; i < n; i++)
	{
		int z;
		scanf("%d", &z);
		se.insert(z);
	}
	printf("%d\n", se.size());
}

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

int main() {
  int X, Y;
  int c, t;
  cin >> X >> Y;
  for (c = 0; c <= X; c++) {
    t = X - c;
    int total = 2*c + 4*t;
    if (total == Y) {
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;

  return 0;
}

Measured memory_bytes: 3628
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {
    static int N;
    static int[] s;
    static int[] p;

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

        s = new int[N];
        p = new int[N];
        PriorityQueue<Restaurant> queue = new PriorityQueue<>();
        for(int i = 0; i < N; i++) {
            Restaurant restaurant = new Restaurant(i + 1, scanner.next(), scanner.nextInt());
            queue.add(restaurant);
        }

        scanner.close();

        while (!queue.isEmpty()) {
            Restaurant r = queue.poll();
            System.out.println(r.id);
        }

    }
}

class Restaurant implements Comparable<Restaurant>{
    public int id;
    public String city;
    public int point;

    public Restaurant(int id, String city, int point) {
        this.id = id;
        this.city = city;
        this.point = point;
    }

    @Override
    public int compareTo(Restaurant o) {
        int cityName = this.city.compareToIgnoreCase(o.city);

        if(cityName == 0) {
            if(this.point > o.point) {
                return -1;
            } else if (this.point < o.point) {
                return 1;
            } else {
                return 0;
            }
        }

        return this.city.compareToIgnoreCase(o.city);
    }
}

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

using namespace std;

template<typename T>
struct BIT
{
  static const int MAX_N = 1 << 17;
  T bit[MAX_N + 1] = {};
  int n;

  void init(int n_)
  {
    n = n_;
  }

  BIT(int n_)
  {
    n = n_;
  }

  T sum(int i)
  {
    T s = 0;
    while(i > 0) {
      s += bit[i];
      i -= i & -i;
    }
    return s;
  }

  void add(int i, T x)
  {
    while(i <= n) {
      bit[i] += x;
      i += i & -i;
    }
  }
};

int n, a[100000];

void solve()
{
  int n, q;
  cin >> n >> q;
  BIT<int> bit(n);
  while(q--) {
    int com, x, y;
    cin >> com >> x >> y;
    if(com) {
      cout << bit.sum(y) - bit.sum(x - 1) << "\n";
    } else {
      bit.add(x, y);
    }
  }
}

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

Measured memory_bytes: 3672
import sys
input = sys.stdin.readline

n=int(input())
L=list(map(int,input().split()))
L.sort()
hb = L[-1]
dp = [-1 for i in range(hb+1)] 
for i in L:
    if dp[i]!=0:
        if dp[i]==1:
            dp[i]=0
            continue
        dp[i]=1
        for j in range(2*i,hb+1,i):
            dp[j]=0
ans=0
for i in L:
    if dp[i]==1:
        ans+=1
print(ans)




Measured memory_bytes: 31520
#pragma GCC optimize(2)
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
int n,m;
int fav[330][330];
int ma;
int cnt[330];
int rem[330];
int ans=0x3f3f3f3f;
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;++i)
		for(int j=1;j<=m;++j)scanf("%d",&fav[i][j]);
	rem[0]=1;
	for(int t=1;t<=m;++t)
	{
		memset(cnt,0,sizeof(cnt));
		ma=0;
		for(int i=1;i<=n;++i)
		{
			while(rem[fav[i][fav[i][0]]]&&fav[i][0]<m)fav[i][0]++;
//			cout<<fav[i][0]<<" ";
			cnt[fav[i][fav[i][0]]]++;
			if(cnt[fav[i][fav[i][0]]]>cnt[ma])ma=fav[i][fav[i][0]];
		}
		ans=min(ans,cnt[ma]);
		rem[ma]=1;
//		cout<<endl;
	}
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 640
#include<iostream>
using namespace std;
int main(){
  int n,k,cnt = 0;
  cin >> n >> k;
  for(int i = 1;i <= n;++i){
   	if(i%2==1){
      cnt++;
      if(cnt == k)break;
    }
  }
  if(cnt == k) cout << "YES" <<endl;
  else cout << "NO" <<endl;
  
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<map>
#include<algorithm>
using namespace std;
const int maxn = 200005;
int a[maxn];
int n,k,x;
map<int,int> Q;
int main()
{
    cin>>n>>k;
    int now = 0;
    for(int i=1;i<=n;i++)
    {
        a[i]=0;
    }
     for(int i=1;i<=n;i++)
    {
        cin>>x;
        a[x]++;
        if(!Q.count(x))
        {
            Q[x]=1;
            now++;
        }
    }
    sort(a+1,a+1+n);
    int sum = 0;
    for(int i=n-now+1;i<=n-k;i++)
    {
        sum+=a[i];
    }
    cout<<sum<<endl;
}


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

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

  cin >>A>>B>>C;

  if((A <= C && C <= B) || (B <= C && C <= A) )cout <<"Yes"<<endl;
  else cout <<"No"<<endl;
  return 0;
  }

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

/* 大文字を小文字に変換 */
char tolower(char c) {return (c + 0x20);}
/* 小文字を大文字に変換 */
char toupr(char c) {return (c - 0x20);}

// if('A'<=s[i] && s[i]<='Z') s[i] += 'a'-'A';

/*
string s = "abcdefg"
s.substr(4) "efg"
s.substr(0,3) "abc"
s.substr(2,4) "cdef"

// イテレータ要素のインデックス
distance(A.begin(), itr);
*/

const int A = 1000005;


int main()
{
    int n; cin >> n;
    vector<int> a(n);
    vector<int> c(A);   // Aまでの各数字が配列で何回出現したかをメモするための配列
    rep(i,n){
        cin >> a[i];
        c[a[i]]++;
    }

    bool pairwise = true;
    for(int i=2; i<A; i++){ // Aまでの数字を確かめる
        int cnt = 0;
        for(int j=i; j<A; j+=i){
            cnt += c[j];
        }
        if(cnt > 1) pairwise = false;
    }

    bool setwise = false;
    int g = 0;  // 0とその他の数字の最大公約数はその他の数字になる
    rep(i,n) g = __gcd(g, a[i]);
    if(g == 1) setwise = true;

    if(pairwise) cout << "pairwise coprime" << endl;
    else if(setwise) cout << "setwise coprime " << endl;
    else cout << "not coprime" << endl;
}

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

int main(){
    int A[3];
    cin >> A[0] >> A[1] >> A[2];
    sort(A, A + 3);
    if((A[0] == 5) && (A[1] == 5) && (A[2] == 7)) {
        cout << "YES" << endl;
    }
    else {
        cout << "NO" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <cstring>

using namespace std;

int main() {
    int k;
    string n;
    cin >> n;
    cin >> k;
    int count = 0;
    for (int i = 0; i < n.length(); ++i) {
        if (k == count) break;
        count++;
        if (n[i] != '1') {
            cout << n[i] << endl;
            return 0;
        }
    }
    cout << 1 << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <deque>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <map>
#include <stack>
#include <set>
#include <sstream>
#define IOS ios_base::sync_with_stdio(0); cin.tie(0);
#define mod 1000000007
#define eps 1e-6
#define ll long long
#define INF 0x3f3f3f3f
#define MEM(x,y) memset(x,y,sizeof(x))
#define pb push_back
#define mk make_pair
#define pi pair<int, int>
#define rep(i, a, b) for (int i = (a); i <= (b); ++i)
#define per(i,a,b) for(int i=a;i>=(b);--i)
using namespace std;
int dt[][2]= {{1,0},{-1,0},{0,1},{0,-1},{0,0}};
//typedef pair<int, int> P;
//priority_queue<int, vector<int>, greater<int> > q;

int gcd(int a,int b,int c){
    return __gcd(__gcd(a,b),c);
}

int main()
{
   IOS;
   int k;
   cin >> k;
   ll sum=0;
   rep(i,1,k){
       rep(j,1,k){
           rep(p,1,k){
               sum+=gcd(i,j,p);
           }
       }
   }
   cout << sum;
}


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

int main(){
	int n;
	long long int l;
	cin>>n>>l;
	const string imp="Impossible";
	const string posi="Possible";
	vector<int> a(n);
	vector<int> must_tie(n-1,-1);
	for(int i=0;i<n;i++) cin>>a[i];
	int pos=-1;
	for(int i=0;i<n-1;i++) if(a[i]+a[i+1]>=l) pos=i;
	if(pos==-1){
		cout<<imp<<endl;
		return 0;
	}
	else{
		cout<<posi<<endl;
		for(int i=0;i<pos;i++) cout<<i+1<<endl;
		for(int i=n-2;i>pos;i--) cout<<i+1<<endl;
		cout<<pos+1<<endl;
		return 0;

	}


}


Measured memory_bytes: 1664
def main():

    N, P = map(int, input().split())
    S = input()

    if P == 2 or P == 5:
        ans = 0
        for i in range(N):
            if int(S[i]) % P == 0:
                ans += (i + 1)
        print(ans)
        exit()

    sum_rem = [0] * N
    sum_rem[0] = int(S[N - 1]) % P
    ten = 10
    for i in range(1, N):
        a = (int(S[N - 1 - i]) * ten) % P
        sum_rem[i] = (a + sum_rem[i - 1]) % P
        ten = (ten * 10) % P

    ans = 0
    count = [0] * P
    count[0] = 1
    for i in range(N):
        ans += count[sum_rem[i]]
        count[sum_rem[i]] += 1
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 11060
while True:
    h, w = map(int, input().split())
    
    if w == 0 and h == 0:
        break
    
    for i in range(0, h):
        for j in range(0, w):
            if i == 0 or i == (h - 1) or j == 0 or (j == w - 1):
                print('#', end="")
            else:
                print('.', end="")
        print()
    print()



Measured memory_bytes: 7000
N,M=map(int,input().split())
shop = [list(map(int,input().split())) for _ in range(N)]
shop = sorted(shop,key=lambda x: x[0])
ans=0
for i in range(N):
    if M >= shop[i][1]:
        M = M - shop[i][1]
        ans = ans + shop[i][0] * shop[i][1]
        if M == 0:
            break
    else:
        ans = ans + shop[i][0] * M
        break
print(ans)

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

// See debug.cc for usage etc
#define DEBUG 1

template <class... Args>
string dbgFormat(const char* fmt, Args... args) {
  size_t len = snprintf(nullptr, 0, fmt, args...);
  char buf[len + 1];
  snprintf(buf, len + 1, fmt, args...);
  return string(buf);
}

#if DEBUG
  #define DLOG(...)        cerr << dbgFormat(__VA_ARGS__) << endl
  #define DCALL(func, ...) func(__VA_ARGS__)
#else
  #define DLOG(...)
  #define DCALL(func, ...)
#endif

ll N, M;
vector<vector <ll>> switches;
vector<ll> p;
vector<ll> com;

bool next_com() {
  for (ll i = 0; i < N; i++) {
    if (com.at(i) == 0) {
      com.at(i) = 1;
      return true;
    }else {
      com.at(i) = 0;
    }
  }
  return false;
}

bool check_one(ll mod, vector<ll> sw) {
  ll cnt = 0;
  for (ll j : sw) {
    cnt += com.at(j-1);
  }
  return cnt % 2 == mod;
}

bool check() {
  for (ll i = 0; i < M; i++) {
    if (!check_one(p.at(i), switches.at(i)))  return false;
  }
  return true;
}

int main() {
#if !DEBUG
  ios_base::sync_with_stdio(false);
#endif

  cin >> N >> M;
  switches.resize(M);
  for (ll i = 0; i < M; i++) {
    ll k;
    cin >> k;
    switches.at(i).resize(k);
    for (ll j = 0; j < k; j++) {
      cin >> switches.at(i).at(j);
    }
  }
  p.resize(M);
  for (ll i = 0; i < M; i++) {
    cin >> p.at(i);
  }
  ll answer = 0;
  com.resize(N);
  while (1) {
    if (check()) { answer++; }
    if (!next_com()) break;
  }
  cout << answer << endl;

  return 0;
}



Measured memory_bytes: 256
a,b,m = [int(x) for x in input().split()]
an = [int(x) for x in input().split()]
bn = [int(x) for x in input().split()]

ans = min(an)+min(bn)
for i in range(m):
    p, q, discount = [int(x) for x in input().split()]
    a_cost = an[p-1]
    b_cost = bn[q-1]
    total = a_cost + b_cost - discount
    ans = min(total, ans)

print(ans)





Measured memory_bytes: 18500
#include<iostream>
#include<algorithm>
using namespace std;
int main() {
	int n;//JOI?????????????????°
	int m;//?????????????????°
	int person[101] = { 0 };//???????????????
	int baton[101] = { 0 };
	cin >> n >> m;
	for (int i = 1; i <= n; i++) {
		cin >> person[i];
	}
	//cout << "ruio";
	for (int k = 1; k <= m; k++) {
		int i = 1;
		//cout << "ruio";
		while (i != n) {
			if (1 <= i&&i <= n - 1) {
				if (person[i] % k > person[i + 1] % k) {
					//	cout << "ruio";
					swap(person[i], person[i + 1]);
					i = i + 1;
				}
				else {
					i = i + 1;
				}
			}
		}
	}
	for (int j = 1; j <= n; j++) {
		cout << person[j] << endl;
	}
}

Measured memory_bytes: 3088
#include<bits/stdc++.h>
#define  ll   long long int
#define  sz   200010

using namespace std;

ll num[sz];
ll ara[sz];
//map<ll,ll>mp;

//set<ll>st;
//set<ll>::iterator it;

int main()
{

    ll n,a,b,x,y,i,j,k,p,d;

    cin>>n;

    for(i=1;i<=n;i++)
    {
        cin>>num[i];
        ara[i]=num[i];
        //mp[num[i]]++;
    }

    sort(num+1,num+n+1);

    x=n/2;
    y=x+1;


   x=num[x];
   y=num[y];


    for(i=1;i<=n;i++)
    {
        if(ara[i]>x)
        {
            cout<<x<<endl;
        }
        else if(ara[i]<=x)
        {
            cout<<y<<endl;
        }
    }

    return 0;
}



Measured memory_bytes: 5376
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define lper(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ins insert
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,-1,0,1};
ll modfac(ll a){
    ll ans=1;
    while(a>1){
        ans*=a;
        ans%=1000000007;
        a--;
    }
    return ans;
}
ll modinv(ll a,ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m; 
    if (u < 0) u += m;
    return u;
}
struct UnionFind {
    vector<int> par;
    
    UnionFind(int n) : par(n, -1) {}

    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }
    
    bool same(int x, int y) {
        return root(x) == root(y);
    }
    
    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y);
        par[x] += par[y];
        par[y] = x;
        return true;
    }
    
    int size(int x) {
        return -par[root(x)];
    }
};
ll modpow(ll a, ll n, ll mod) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
int main(){
    ll n;cin >> n;
    if(n==2||n==3){
        cout << n <<endl;
        return 0;
    }
    while(true){
        bool x=true;
        for(int i=2;i<sqrt(n)+2;i++){
            if(n%i==0){
                x=false;
                break;
            }
        }
        if(x){
            cout << n <<endl;
            return 0;
        }
        n++;
    }
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
#define inRange(x,a,b) (a <= x && x <= b)

int main(){
    int n;
    cin >> n;
    if(inRange(n, 65, 90))          cout << 1 << endl;
    else if(inRange(n, 97, 122))    cout << 2 << endl;
    else                            cout << 0 << endl;
    return 0;
}


Measured memory_bytes: 3108
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
answer = 0
b_ind = 0

for x in range(N-1):
    A[x+1] += A[x]
    if A[x+1] > K:
        A = A[:x+1]
        break

for y in range(M-1):
    B[y+1] += B[y]
    if B[y+1] > K:
        B = B[:y+1]
        break

A = [0] + A
B = [0] + B

na = len(A)
nb = len(B) 

if A[-1] + B[-1] <= K:
    answer = len(A) + len(B) - 2
    print(answer)

else:
    for i in range(na):
        for j in range(nb-b_ind-1, -1, -1):
            if A[i] + B[j] <= K:
                if answer < i+j:
                    answer = i+j
                b_ind = nb-j-1
                break
    print(answer)

Measured memory_bytes: 42304
#include <iostream>
#include <tuple>
#include <queue>
#include <cmath>
#include <iomanip>
using namespace std;

constexpr double eps = 1e-10;

using data = tuple<int, double, double, double>;

int main() {
    int K;
    double R, L;
    double P, E, T;
    cin >> K >> R >> L >> P >> E >> T;
    queue<data> que;
    que.push(make_tuple(0, R, L, 1.0));
    double res = 0;
    while(!que.empty()) {
        int d;
        double r, l, p;
        tie(d, r, l, p) = que.front(); que.pop();
        double m = (r + l) / 2;
        //cout << "d: " << d << "  r: " << r << "  l: " << l << "  m: " << m << "  p: " << p << endl;
        if(T + E + eps < r || l + E + eps < T) {
            continue;
        }
        if(d == K) {
            if(fabs(m - T) - eps <= E) {
                res += p;
            }
        } else {
            if(T + eps < r + E && l + eps < T + E) {
                res += p;
            } else if(m + eps < T) {
                que.push(make_tuple(d+1, m, l, p*(1-P)));
                que.push(make_tuple(d+1, r, m, p*P));
            } else {
                que.push(make_tuple(d+1, r, m, p*(1-P)));
                que.push(make_tuple(d+1, m, l, p*P));
            }
        }
    }
    cout << fixed << setprecision(10) << res << endl;
}


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

#define MOD 1e9+7;
#define ll long long int;

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



Measured memory_bytes: 256
N=int(input())
A=list(map(int,input().split()))
D={}
for i in range(N):
    if not(A[i] in D):
        D[A[i]]=0
    D[A[i]]+=1
ans=0
for i in D:
    ans+=(D[i]*(D[i]-1))//2
for k in range(N):
    print(ans-D[A[k]]+1)



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

using namespace std;

#define F 	first
#define S 	second
#define ll 	long long int
const int size = 3;

int t, n;
int a[100010][10];
int dp[100010][10];


int solve(int i, int from, int cost) {
	if (i > n) return 0;
	if (i == n) return cost;

	if (~dp[i][from]) return dp[i][from];

	for (int j = 0; j < size; j++) {
		if (j == from) continue;
		dp[i][from] = max(dp[i][from], cost + solve(i + 1, j, a[i][j]));
	}

	return dp[i][from];
}

int main() {
		cin >> n;
		for (int i = 0; i < n; i++)
			for (int j = 0; j < size; j++) cin >> a[i][j];

		memset(dp, -1, sizeof dp);
		printf("%d\n", solve(0, 4, 0));
	return 0;
}

Measured memory_bytes: 15872
import sys
def input(): return sys.stdin.readline().rstrip()


def main():
    mod = 10**9+7
    x, y = map(int, input().split())
    x2 = max(x, y)
    y2 = min(x, y)
    m = y2-(x2-y2)
    if m < 0 or m % 3 != 0:
        print(0)
    else:
        c = m // 3
        n = c*2+(x2-y2)
        bunshi = 1
        bunbo = 1
        for i in range(1, c+1):
            bunbo= bunbo*i % mod
            bunshi= bunshi*(n-i+1) % mod
    
        ans = bunshi * pow(bunbo,-1,mod)
        print(ans%mod)


if __name__ == '__main__':
    main()

Measured memory_bytes: 9112
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
typedef long long ll;
typedef pair<int, int> P;
typedef pair<pair<int, int>, int> PP;
typedef bitset<60> Bitset;
const ll INFL = 1LL << 60;
const int INF = INT_MAX;
const int MAX = 300000;
const int MOD = 1000000007;
ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }
ll LCM(ll a, ll b) { return (a * b) / GCD(a, b); }
//------------------------------------------------------------------------------------------------------------------------------
int main(void) {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;cin>>n;
    vector<ll> a(n);
    for(int i = 0; i < n; i++) cin>>a[i];
    sort(a.begin(),a.end());
    if(n==2){
        cout<<a[n-1]<<endl;
        return 0;
    }
    ll ans = 0;
    for(int i = n/2; i < n; i++) {
        ans += a[i];
        if(n/2<i&&i<n-1) ans += a[i];
    }
    if(n%2==0) ans += a[n/2];
    cout<<ans<<endl;
}


Measured memory_bytes: 4728