akhauriyash/Code-Regression huggingface dataset:
N, W = map(int, input().split())
items = [list(map(int, input().split())) for i in range(N)]

# dp[この重さを超えないレベルで] = 価値の最大値となるような一次元配列
dp = [0] * (W+1)

for i in range(N):
    v, w = items[i]
    # 個数制限ありでは同じものを使わないように後ろから更新したが、今回は逆に同じものを使うように前から更新する
    for j in range(w, W+1):
        # jを超えない重さであれば、前の要素番号まででこの重さを引いた数値の価値と今回の価値を足したものが上回れば今回の価値とする
        dp[j] = max(dp[j], dp[j-w] + v)
print(dp[W])


Measured memory_bytes: 5916
_lst = input().split()
d = int(_lst[0])
g = int(_lst[1])

pc = list()

for i in range(d):
    _lst = input().split()
    pc.append((int(_lst[0]), int(_lst[1])))

score = 0
result_count = -1

# 全て回答したパターンを探索する
for i in range(2 ** d):
    count = 0
    score = 0

    # 全問正解した配点のスコアを足す
    for j in range(d):
        if i >> j & 1:
            score += 100 * (j + 1) * pc[j][0] + pc[j][1]
            count += pc[j][0]

    # すでに配点を超えている場合は、最小のcountだけ考慮して処理終了
    if score >= g:
        if result_count >= count or result_count == -1:
            result_count = count
        continue

    not_reach = True
    for j in range(d-1, -1, -1):
        if not (i >> j & 1):  # 全問正解していない配点(一番大きい0)のindexを特定
            if -((score - g) // ((j + 1) * 100)) < pc[j][0]:  # 配点が全問正解しないでも目標値を超えるか確認
                count -= (score - g) // ((j + 1) * 100)  # 全問正解していない配点の正解数
                not_reach = False
                break

    # gに届かなかった場合は考慮しない
    if not_reach:
        continue

    if result_count >= count or result_count == -1:
        result_count = count

print(result_count)


Measured memory_bytes: 3064
/////////////////////////////////////////////////
//                                             //
//                 _ooOoo_                     //
//                o8888888o                    //
//                88" . "88                    //
//                (| -_- |)                    //
//             ____/`---'\\____                //
//           .'  \|     |//  `.                //
//           /  \|||  :  |||// \               //
//          /  _||||| -:- |||||- \             //
//          |   | \\  -  /// |   |             //
//          | \_|  ''\---/''  |  |             //
//          \  .-\__  `-`  ___/-. /            //
//         ___`. .'  /--.--\  `. . __          //
//      ."" '<  `.___\_<|>_/___.'  >'"".       //
//     | | :  `- \`.;`\ _ /`;.`/ - ` : | |     //
//     \  \ `-.   \_ __\ /__ _/   .-` /  /     //
//=====`-.____`-.___\_____/___.-`____.-'=======//
//^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^//
//.............................................//
/////////////////////////////////////////////////

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll modn=998244353;
const ll INF = 0x3f3f3f3f;
vector<int> ans[3];
set<int> st;
int main(){
    ll a;
    cin>>a;
    cout<<a*a<<endl;
    return 0;
}
/*
5
1 2 3 4 5
5 3 2 1 4
*/


Measured memory_bytes: 256
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    n, k = map(int, readline().split())
    l = 2 * k
    grid = [[0] * (2 * l) for _ in range(2 * l)]

    for i in range(n):
        x, y, c = input().split()
        x, y = int(x), int(y)
        if c == "W":
            x += k
        mx, my = x % l, y % l
        grid[mx][my] += 1
        grid[mx + k][my] -= 1
        grid[mx][my + k] -= 1
        grid[mx + k][my + k] += 1
        grid[mx + k][my + k] += 1
        grid[mx + 2 * k][my + k] -= 1
        grid[mx + k][my + 2 * k] -= 1
        grid[mx + 2 * k][my + 2 * k] += 1

    for x in range(1, 2 * l):
        for y in range(2 * l):
            grid[x][y] += grid[x - 1][y]

    for x in range(2 * l):
        for y in range(1, 2 * l):
            grid[x][y] += grid[x][y - 1]

    count = [[0] * l for _ in range(l)]

    for x in range(2 * l):
        for y in range(2 * l):
            count[x % l][y % l] += grid[x][y]
    ans = 0
    for x in range(l):
        for y in range(l):
            ans = max(ans, count[x][y])

    print(ans)


if __name__ == '__main__':
    main()


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

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

	vector<pair<long int, int>> fs;
	for (long int i = 2;i * i <= n;i++) {
		int x = 0;
		while (n % i == 0) {
			n /= i;
			x++;
		}
		fs.emplace_back(i, x);
	}
	if (n > 1) fs.emplace_back(n, 1);

	int num;
	num = fs.size();
	int ans = 0;
	for (int i = 0;i < num;i++) {
		int y = fs[i].second;
		int j = 1;
		while(y>0) {
			y -= j;
			j++;
			if(y>=0) ans++;
		}
	}

	cout << ans;
	return 0;
}

Measured memory_bytes: 19748
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rrep(i,n) for(ll i = 1; i <= (n); ++i)
#define drep(i,n) for(ll i = (n)-1; i >= 0; --i)
#define all(v) v.begin(),v.end()
#define len(x) (ll)(x).length()
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define pb push_back
#define sz(x) (ll)(x).size()
#define v(T) vector<T>
#define vv(T) vector<vector<T>>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
ll gcd(ll a,ll b){if(a%b==0){return b;}else{return(gcd(b,a%b));}}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
const int INF=1e9;
const ll MX = 1e18;
const ll MOD=INF+7;
const int di[] = {-1,0,1,0};
const int dj[] = {0,-1,0,1};
const double PI=acos(-1);
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
#define YN {puts("YES");}else{puts("NO");}
const ll MAX = 1000001;
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {fac[0] = fac[1] = 1;finv[0] = finv[1] = 1;inv[1] = 1;for (ll 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;}}
long long COM(ll n, ll k){if (n < k) return 0;if (n < 0 || k < 0) return 0;return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;}
ll llpow(ll n,ll i){ll cnt=n;  for(ll j=0;j<i-1;j++){n*=cnt;}return n;}

int main() {
  int w,h,n;
  cin>>w>>h>>n;
  vi x(n),y(n),a(n);
  rep(i,n) cin>>x[i]>>y[i]>>a[i];
  P state={w,h};
  P state0={0,0};
  rep(i,n){
    if(a[i]==1){
      maxs(state0.first,x[i]);
    }
    if(a[i]==2){
      mins(state.first,x[i]);
    }
    if(a[i]==3){
      maxs(state0.second,y[i]);
    }
    if(a[i]==4){
      mins(state.second,y[i]);
    }
    if(state.first-state0.first<=0||state.second-state0.second<=0){
    cout<<0<<endl;
    return 0;
    }
  }
  int ans=(state.first-state0.first)*(state.second-state0.second);
  cout<<ans<<endl;
}


Measured memory_bytes: 3612
using System;

namespace ConsoleApp6
{
    class Program
    {
        static void Main(string[] args)
        {
            var ab = Console.ReadLine().Split(' ');
            var a = int.Parse(ab[0]);
            var b = int.Parse(ab[1]);

            if(a<=8 &&b<=8)
            {
                Console.WriteLine("Yay!");
            }
            else
            {
                Console.WriteLine(":(");
            }
        }
    }
}


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

#define LL long long
int n, x, y; LL ans = 1e9;
int a[45], b[45], c[45]; LL dp[405][405];

int main() {
    ios::sync_with_stdio(0), cin.tie(0);
    
    cin >> n >> x >> y;
    for(int i = 1; i <= n; i++) cin >> a[i] >> b[i] >> c[i];

    for(int i = 0; i <= 400; i++)
        for(int j = 0; j <= 400; j++)
            dp[i][j] = 1e9;

    dp[0][0] = 0;
    for(int k = 1; k <= n; k++) 
        for(int i = 400; i >= a[k]; i--)
            for(int j = 400; j >= b[k]; j--)
                dp[i][j] = min(dp[i][j], dp[i-a[k]][j-b[k]] + c[k]);

    for(int i = 1; max(x, y) * i <= 400; i++) ans = min(ans, dp[x*i][y*i]);
    if(ans >= 1e9) cout << -1;
    else cout << ans;        
}

Measured memory_bytes: 4868
#include <bits/stdc++.h>
using namespace std;
vector<long long> h;
vector<long long> memo;
long long ans;	
long long n;

long long DP(long long v){
	if(v==n-1){
		return abs(h[v]-h[v+1]);
	}
	if(v==n)return 0;
	
	if(memo[v]!=-1)return memo[v];
	
	long long a1 = abs(h[v+1]-h[v]);
	long long a2=abs(h[v+2]-h[v]);
	
	ans = min(a1+DP(v+1), a2+DP(v+2));
	memo[v] = ans;
	
	
	return ans;
	
	
}



int main() {

	cin >> n;
	h.resize(n+1);

	for(int i=1;i<=n;i++){
		cin >> h[i];
	}
	
	memo.assign(n+1,-1);
	cout << DP(1) << endl;
	
	
	
	
	return 0;
}

Measured memory_bytes: 3456
#include<iostream>
#include<iomanip>
#include<queue>
#include<string>
#include<stack>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<cassert>
#include<ctime>
#include<algorithm>
#include<utility>
#include<map>
#include<set>
#include<vector>
#include<functional>

using namespace std;

typedef  long long           ll;
typedef  unsigned            ui;
typedef  unsigned long long  ull;
typedef  pair<int,int>       i_i;
typedef  pair<ll,int>        ll_i;
typedef  pair<ll,ll>         ll_ll;
typedef  pair<double,int>    d_i;
typedef  pair<double,double> d_d;

#ifdef DEBUG
#define dprintf      printf
#define dputs        puts
#define dout(x)      cout<<#x" = "<<(x)<<endl
#define darray(x,n)  {int i;rep(i,n)cout<<#x"["<<i<<"] = "<<*((x)+i)<<endl;}
#define dloop(i,s,g) for(int (i)=(s);(i)<(g);(i)++)
#define drep(i,n)    for(int (i)=0;(i)<(n);(i)++)
#define dstop()      scanf("%*c")
#else
#define dprintf      (1)?0:printf
#define dputs        (1)?0:puts
#define dout(x)
#define darray(x,n)
#define dloop(i,s,g) if(int i=0){}else
#define drep(i,n)    if(int i=0){}else
#define dstop()
#endif

#define F    first
#define S    second
#define pb   push_back
#define mp   make_pair

#define loop(i,s,g) for((i)=(s);(i)<(g);(i)++)
#define rep(i,n)    for((i)=0;(i)<(n);(i)++)
#define all(x)      (x.begin(),x.end())
#define in(T,...) T __VA_ARGS__; impl(__VA_ARGS__)
#define array(T,id,n) T id[(n)]; for(int i=0;i<(n);i++)cin>>id[i]
#define putv(n)     cout<<(n)<<endl

//#define int long long
#ifndef int
#define INF __INT32_MAX__
#else
#define INF __INT64_MAX__
#endif

void impl(){};
template <typename T,typename... TS >
void impl(T &head,TS &... tail)
{
  cin>>head;
  impl(tail ...);
}

signed main(void)
{
  in(string,s);
  int i=0,j=s.size();
  while(s[i++]!='A');
  while(s[j--]!='Z');
  putv(j-i+3);
  return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define MOD 1000000007
const int INF = 1LL<<30;

int main(){
    string s;
    cin>>s;
    int ans=0;
    for(int i=0,j=s.size()-1;i<j;){
        if(s[i]==s[j]) i++,j--;
        else if(s[i]=='x') ans++,i++;
        else if(s[j]=='x') ans++,j--;
        else{
            cout<<-1<<endl;
            return 0;
        }
    }

    cout<<ans<<endl;
}

Measured memory_bytes: 3728
# ABC057 B - Checkpoints
si = lambda: input()
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))
n,m = nm()

AB = [[] for _ in range(n)]
CD = [[] for _ in range(m)]

ans = 0
for i in range(n):
    a,b = nm()
    AB[i].append(a)
    AB[i].append(b)

for i in range(m):
    c,d = nm()
    CD[i].append(c)
    CD[i].append(d)

for i in range(n):
    distance = 10**10
    for j in range(m):
        t = abs(AB[i][0]-CD[j][0])+abs(AB[i][1]-CD[j][1])
        if t<distance:
            distance = abs(AB[i][0]-CD[j][0])+abs(AB[i][1]-CD[j][1])
            ans = j+1
    print(ans)

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

using namespace std;

int main()
{
    string s,t;
    cin>>s>>t;
    int n = s.length(),m = t.length();
    int diff = m;
    for(int i = 0;i<n-m+1;i++)
    {
       int total = 0;
       for(int j = 0;j<m;j++)
       {
           if(s[j+i] != t[j])
           {
               total++;
           }
       }

       diff = min(diff,total);
    }

    cout<<diff<<"\n";

    return 0;
}

Measured memory_bytes: 3624
#include <iostream>
typedef long long ll;
using namespace std;

int main() {
	string s; cin >> s;
	ll k; scanf("%lld", &k);

	ll ans;
	if (s[0] != '1') ans = s[0] - '0';
	else {
		int cnt = 0;
		while (s[0] == '1') {
			s = s.substr(1, s.size() - 1);
			++cnt;
		}

		if (cnt >= k) ans = 1;
		else ans = s[0] - '0';
	}

	printf("%lld", ans);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
using namespace std;
int a[10];
 main()
{
    string s;
    cin>>s;
    for(int i =0; i<s.size(); i++){
        a[s[i]-'A']++;
    }
    if(a[0] == 3 || a[1] == 3)cout<<"No\n";
    else cout<<"Yes\n";



    return 0;
}


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

public class Main {

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

        int H, W;
        String line;

        H = sc.nextInt();
        W = sc.nextInt();

        line = sc.nextLine();
        for (int i = 0; i < H; i++) {
            line = sc.nextLine();

            out.println(line + "\n" + line);
        }
        
        sc.close();
    }
}

Measured memory_bytes: 21460
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <numeric>
#include <set>
#include <list>
#include <bitset>
#include <cstdlib>
#include <map>
using ll = long long int;
using namespace std;

int main()
{
    int N, A, B, a = 0, b = 0, c = 0;
    cin >> N >> A >> B;
    for (int i = 0; i < N; i++)
    {
        int tmp;
        cin >> tmp;
        if (tmp <= A)
        {
            a++;
        }
        else if ((A < tmp) && (tmp <= B))
        {
            b++;
        }
        else
        {
            c++;
        }
    }
    cout << min(a, min(b, c)) << endl;

    return 0;
}

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

int main() {
	// your code goes here
	int n;
	cin>>n;
	string arr[n];
	set<string>s;
	for(int i=0;i<n;i++){
		cin>>arr[i];
		s.insert(arr[i]);
	}
	cout<<s.size();
	return 0;
}

Measured memory_bytes: 25508
#include <bits/stdc++.h>
using namespace std;
int main(){
    int i,j,A = 1010,x;
    string S,T;
    cin >> S >> T;
    for(i = 0;i < S.size() - T.size() + 1;i++){
        x = 0;
        for(j = 0;j < T.size();j++){
            if(S[i + j] != T[j]){
                x++;
            }
        }
        if(A > x){
            A = x;
        }
    }
    cout << A << endl;
}

Measured memory_bytes: 3644
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define REP(i, start, end) for (ll i = start, i##Len = (end); i < i##Len; ++i)
#define REPR(i, start, end) for (ll i = start, i##Len = (end); i > i##Len; --i)
using ll = long long;
using namespace std;

int main()
{
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);

    int n;
    cin >> n;
    bool ok = 0;
    int cnt = 0;

    REP(_, 0, n)
    {
        int x, y;
        cin >> x >> y;
        if (x != y)
            cnt = 0;
        else
            cnt += 1;
        if (cnt >= 3)
            ok = 1;
    }

    cout << (ok ? "Yes" : "No") << endl;
}

Measured memory_bytes: 3644
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>
#include <assert.h>
#include <unordered_set>
#include <random>


using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e18;
const ll MOD = 1e9 + 7;

#define REP(i, n) for(ll i = 0; i < n; i++)





















int main(){
    string s, t;
    cin >> s >> t;
    if(s == t.substr(0, s.size())){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
}


Measured memory_bytes: 3624
#include <cstdio>

typedef unsigned long long int ull;


int main(){
    ull A,B,N;
    scanf("%llu%llu%llu",&A,&B,&N);
    if (N<B){
        auto max_remainder=N;
        printf("%llu\n",max_remainder*A/B);
    }else{
        auto max_remainder=B-1;
        printf("%llu\n",max_remainder*A/B);
    }


    return 0;
}

Measured memory_bytes: 1732
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;

namespace kyoupuro {

    class MainClass {

        public static void Main() {
            var H = Input.NextInt();
            var W = Input.NextInt();
            var N = Input.NextInt();
            var list = Input.IntList();
            var matrix = new int[H, W];
            var nowH = 0;
            var nowW = 0;

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

                while (list[i] > 0) {
                    matrix[nowH, nowW] = i + 1;

                    // 継続処理
                    if (nowH % 2 == 0) {
                        if(nowW == W - 1) {
                            nowH++;
                        } else {
                            nowW++;
                        }
                    } else {
                        if(nowW == 0) {
                            nowH++;
                        } else {
                            nowW--;
                        }
                    }
                    list[i]--;
                }
            }

            for (int i = 0; i < H; i++) {
                for (int j = 0; j < W; j++) {
                    Console.Write(matrix[i, j] + " ");
                }
                Console.WriteLine();
            }
        }
    }

    class Input {
        static IEnumerator<string> enumerator = new string[] { }.AsEnumerable().GetEnumerator();

        public static string Line() {
            return Console.ReadLine();
        }

        public static int NextInt() {
            while (!enumerator.MoveNext()) {
                enumerator = StrArr().AsEnumerable().GetEnumerator();
            }
            return int.Parse(enumerator.Current);
        }

        public static long NextLong() {
            while (!enumerator.MoveNext()) {
                enumerator = StrArr().AsEnumerable().GetEnumerator();
            }
            return long.Parse(enumerator.Current);
        }

        public static string[] StrArr() {
            return Line().Split(' ');
        }

        public static List<int> IntList() {
            return StrArr().Select(int.Parse).ToList();
        }

        public static List<long> LongList() {
            return StrArr().Select(long.Parse).ToList();
        }

        public static void Skip(int line = 1) {
            enumerator.Reset();
            for (int i = 0; i < line; i++) Console.ReadLine();
        }

        public static void Reset() {
            enumerator.Reset();
        }
    }
}

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

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


int main(){
    int N,M,X;
    cin >> N >> M >> X;

    if(N==0||M==0||X==0){
        cout << -1 << endl;
        return 0;
    }
    vector<int> C(N);
    vector<vector<int>> A(N,vector<int>(M));
    long money=0;
    long result=1000000000;
    vector<int> sum(M);

    rep(i,N){
        cin >> C.at(i);
        rep(j,M){
            cin >> A.at(i).at(j);
        }
    }

    for (int bit=0; bit<(1<<N);bit++) { // 0000...00 ~ 1000...00(2^N個)
        money=0;
        rep(i,M) sum.at(i)=0;

        for(int i=0;i<N;i++){ // シフトを右にずらして判定
            if((bit >> i) & 1){
                money += C.at(i);
        //        cout << money << endl;
                for(int k=0;k<M;k++){
                    sum.at(k) += A.at(i).at(k);
                  //  cout << sum.at(k) << endl;
                }
            }
        }

        int flg=0;
        rep(i,M){
            if(sum.at(i)<X) flg=1;
        }
        if(flg!=0) continue;
        

        result = min(result,money);
  //      cout << result << endl;

    }
    if(result == 1000000000) cout << -1 << endl;
    else cout << result << endl;


}

Measured memory_bytes: 3636
from collections import Counter
from collections import defaultdict

n = int(input())
d = defaultdict(int)
S = input()
for k in S:
    d[k] += 1
for _ in range(n-1):
    count = Counter(input())
    for k in d.keys():
        if not k in count:
            d[k] = 0
        else:
            d[k] = min(d[k], count[k])
ans = ''
for i in 'abcdefghijklmnopqrstuvwxyz':
    ans += i * d[i]
print(ans)

Measured memory_bytes: 3316
import itertools 
n, m, x = list(map(int, input().split()))
result=[]
books=[]
tmp=[]
for i in range(n):
    books.append(list(map(int, input().split())))
    tmp.append(i)

# 参考書の選択パターン作成
patterns=[]
for i in range(n):
    patterns.append(itertools.combinations(tmp,i+1))
# 全ての参考書を購入しても条件を満たせないときは-1
for arg in range(m):
    point=0
    for book in books:
        point+=book[arg+1]
    if point<x:
        print(-1)
        exit()

# すべての参考書のパターン
for pattern in patterns:
    # ある参考書のパターン
    for bks in pattern:
        flg=True
        # 各アルゴリズムの時の理解度合計
        for i in range(m):
            # あるアルゴリズムのときの点数とトータルコスト
            cost=0
            point=0
            for bk in bks:
                cost+=books[bk][0]
                point+=books[bk][i+1]
            if point < x:
                # あるアルゴリズムで条件を満たさない
                flg=False
        if flg==True:
            result.append(cost)
print(min(result))

Measured memory_bytes: 9344
import itertools

N, M = map(int, input().split())
edges = [tuple(sorted(map(int, input().split()))) for _ in range(M)]

answer = 0
for i in itertools.permutations(range(2, N+1), N-1):
    l = [1] + list(i)
    answer += sum(1 for x in zip(l, l[1:]) if tuple(sorted(x)) in edges) == N-1
print(answer)    

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using P = pair<int, int>;
bool used[8];
int perm[8];
vector<P> A;
double tot = 0;

void dfs(int current, int limit)
{
    if (current == limit)
    {
        // 距離の合計を追加
        for (int i = 0; i < limit - 1; i++)
        {
            double x, y, nx, ny;
            tie(x, y) = A[perm[i]];
            tie(nx, ny) = A[perm[i + 1]];
            tot += sqrt((nx - x) * (nx - x) + (ny - y) * (ny - y));
        }
        return;
    }

    for (int i = 0; i < limit; i++)
    {
        if (!used[i])
        {
            used[i] = true;
            perm[current] = i;
            dfs(current + 1, limit);
            used[i] = false;
        }
    }
}

int main()
{
    int N;
    cin >> N;
    for (int i = 0; i < N; i++)
    {
        int x, y;
        cin >> x >> y;
        A.push_back(P(x, y));
    }

    for (int i = 0; i < N; i++)
    {
        used[i] = true;
        perm[0] = i;
        dfs(1, N);
        used[i] = false;
    }

    double div = 1;
    for (int i = N; i > 0; i--)
    {
        div *= i;
    }

    double ans = tot / div;
    cout << fixed << setprecision(15) << ans << endl;
    return 0;
}

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

#define FOR(i,n) for(int i=0;i<(n);++i)
#define FORU(i,j,k) for(int i=(j);i<=(k);++i)
#define FORD(i,j,k) for(int i=(j);i>=(k);--i)

#define error(args...) { vector<string> _v = split(#args, ','); err(_v.begin(), args); }

using namespace std;

using lli = long long int;
using pll = pair<lli, lli>;

string TYPE(int*)  { return "%d";   }
string TYPE(lli*)  { return "%lld"; }
string TYPE(char*) { return "%c";   }

void RD() {}
template<typename T, typename... Args> 
void RD(T* v, Args... args)
{
    scanf((" " + TYPE(v)).c_str(), v);
    RD(args...);
}

void PR(bool nl = true)
{ if(nl) printf("\n"); }
template<typename T, typename... Args> 
void PR(bool nl, T v, Args... args)
{
    printf((TYPE(&v) + " ").c_str(), v);
    PR(nl, args...);
}
template<typename... Args> 
void PR(Args... args)
{ PR(true, args...); }

vector<string> split(const string& s, char c)
{
    vector<string> v;
    stringstream ss(s);
    string x;
    while (getline(ss, x, c))
        v.emplace_back(x);
    return move(v);
}

void err(vector<string>::iterator) {}
template<typename T, typename... Args>
void err(vector<string>::iterator it, T a, Args... args)
{
    cerr << it -> substr((*it)[0] == ' ', it -> length()) << " = " << a << '\n';
    err(++it, args...);
}

const long long int oo = 1000*1000*1000;

struct Coord
{
    int x, y;
    Coord(int x = 0, int y = 0) : x(x), y(y) {}
    Coord operator + (const Coord& droite) const
    {
        return Coord(x + droite.x, y + droite.y);
    }
};

struct AB
{
    int k;
    vector<lli> arbre;
    AB(int _k = 20, lli def = 0)
    {
        k = _k;
        FOR(i, 1 << k)
            arbre.push_back(i < (1 << (k-1)) ? 0LL : def);
        FORD(i, ((1 << (k-1)) - 1), 1)
            arbre[i] = arbre[i << 1] + arbre[(i << 1) ^ 1];
    }
    void set(int i, lli x)
    {
        int feuille = i + (1 << (k-1));
        arbre[feuille] = x;
        iset(feuille >> 1);
    }
    void iset(int noeud)
    {
        if(noeud)
        {
            arbre[noeud] = arbre[noeud << 1] + arbre[(noeud << 1)  ^ 1];
            iset(noeud >> 1);
        }
    }
    lli sum(int deb, int fin, int noeud = 1, int p = 0, int q = -1)
    {
        if(q < p)
            q = 1 << (k-1);
        if(deb <= p && q <= fin)
            return arbre[noeud];
        if(deb >= q || fin <= p)
            return 0LL;
        int mil = (p + q) / 2;
        return sum(deb, fin, noeud << 1, p, mil) + sum(deb, fin, (noeud << 1) ^ 1, mil, q);
    }
};

int main()
{
	int k, s;
	RD(&k, &s);
	lli sum = 0;
	FOR(i, k+1)
		FOR(j, k+1)
			if(s-(i+j) <= k && i+j <= s)
				++sum;
	PR(sum);
    return 0;
}


Measured memory_bytes: 256
while True:
    n, x = map(int, input().split())
    if n == 0 and x == 0:
        break
    _ = 0
    for i in range(1, (n + 1)):
        for j in range(1, (n + 1)):
            for k in range(1, (n + 1)):
                if (i + j + k) == x and i < j < k:
                    _ += 1
    print(_)


Measured memory_bytes: 5592
def main():
    N = int(input())
    A1 = tuple(map(int, input().split()))
    A2 = tuple(map(int, input().split()))

    f(N, A1, A2)


def f(N, A1, A2):
    a1_cumsum = [A1[0]]
    for i in range(1, N):
        s = a1_cumsum[-1] + A1[i]
        a1_cumsum.append(s)

    a2_cumsum = [A2[0]]
    for i in range(1, N):
        s = a2_cumsum[-1] + A2[i]
        a2_cumsum.append(s)

    # iで下に移動した時
    ans = A1[0] + a2_cumsum[-1]
    for i in range(1, N):
        tmp_ans = a1_cumsum[i] + a2_cumsum[-1] - a2_cumsum[i - 1]
        ans = max(ans, tmp_ans)

    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

#include <bits/stdc++.h>
using namespace std;

map<ll,ll> m;

void prime_factor(ll n){
  for(ll i=2;i*i<=n;i++) {
    ll tmp=0;
    while(n%i==0){
      tmp++;
      n/=i;
    }
    if(tmp!=0) m[i]+=tmp;
  }
  if(n!=1) m[n]++;
}

int main() { 
  ll n;
  cin>>n;
  
  for(int i=2;i<=n;i++) prime_factor(i);
  
  int c2=0,c4=0,c14=0,c24=0,c74=0;
  for(auto x:m){
    if(x.second>=2) c2++;
    if(x.second>=4) c4++;
    if(x.second>=14) c14++;
    if(x.second>=24) c24++;
    if(x.second>=74) c74++;
  }
  
  int ans=c74+c24*(c2-1)+c14*(c4-1)+c4*(c4-1)/2*(c2-2);
  cout<<ans<<endl;

  return 0;
}

Measured memory_bytes: 3552
#ifndef LOCAL
#pragma GCC optimize("O3")
#endif
#include "bits/stdc++.h"
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define fastio ios_base::sync_with_stdio(false) ; cin.tie(0) ;
using ll = long long ;
const ll INF = 1e10 + 10 ;

int main(){
    fastio
    int n ;
    cin >> n ;
    vector<int> v(n) ;
    for(int i = 0; i < n; i++){
        cin >> v[i] ;
    }
    ll ans = 0 ;
    for(int i = 0; i < n; i++){
        for(int j = i + 1; j < n; j++){
            ans += v[i] * v[j] ;
        }
    }
    cout << ans << endl;
    return 0 ;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define vl vector <long long>
#define lli long long

vl st;

void update(int v,int i,int l,int r,lli val){
    if(l>r)return;
    if(l==r){
        st[v]=val;
    }
    else{
    int mid=(l+r)/2;
    if(i<=mid)update(2*v,i,l,mid,val);
    else update(2*v+1,i,mid+1,r,val);
    st[v]=max(st[2*v],st[2*v+1]);
    }
}

lli  query(int v,int ll,int rr,int l,int r){
    if(ll>rr)return 0;
    if(l==ll&&r==rr){
        return st[v];
    }
    else{
    int mid=(l+r)/2;
    lli left=query(2*v,ll,min(mid,rr),l,mid);
    lli right=query(2*v+1,max(mid+1,ll),rr,mid+1,r);
    return max(left,right);
    }
}

int main() {
    int n;
    cin>>n;
    st.assign(4*n+1,0);
    vl vec(n,0);
    vector <lli> svec(n,0);
    vl val(n,0);
    for(int i=0;i<n;i++){
        cin>>vec[i];
        svec[i]=vec[i];
    }
    for(int i=0;i<n;i++){
        cin>>val[i];
    }
    sort(svec.begin(),svec.end());
    map<lli,int>ind;
    for(int i=0;i<n;i++)ind[svec[i]]=i;
    lli ans=0;
    for(int i=n-1;i>=0;i--){
        int index=ind[vec[i]];
        lli mx=query(1,index+1,n-1,0,n-1);
        lli value=mx+val[i];
        if(ans<value)ans=value;
        update(1,index,0,n-1,value);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 23680
n, m = map(int, input().split())
graph = [[] for _ in range(n + 1)]
for _ in range(m):
    a, b = map(int, input().split())
    graph[a].append(b)
    graph[b].append(a)

def my_permutations(nums, t, path):
    if len(nums) == 0:
        path.append(t)
        return
    for i in range(len(nums)):
        my_permutations(nums[:i] + nums[i + 1:], t + [nums[i]], path)

def dfs(graph, permu, n):
    visited = [False] * (n + 1)
    next_nodes = set([1])
    for p in permu:
        if visited[p]:
            return False
        if p not in next_nodes:
            return False
        visited[p] = True
        next_nodes = set(graph[p])
    return True

path = []
my_permutations([i for i in range(1, n + 1)], [], path)
ans = 0
for permu in path:
    if permu[0] != 1:
        continue
    if dfs(graph, permu, n):
        ans += 1
print(ans)

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

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
#define rep(i, s, n) for(int i = (int)(s); i < (int)(n); i++)

ll INF = 1ll << 60;

int main(){
  int h, n;
  cin >> h >> n;
  int sum = 0;
  
  rep(i, 0, n){
    int a;
    cin >> a;
    sum += a;
  }
  
  if(sum >= h)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  
  return 0;
  
}

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

#define ll long long 
#define pii pair<int, int>
#define ull unsigned ll
#define f first
#define s second
#define FOR(i,a,b) for (int i=(a); i<(b); i++)
#define REP(i,n) for (int i=0; i<(n); i++)
#define RREP(i,n) for (int i=(n-1); i>=0; i--)
#define ALL(x) x.begin(),x.end()
#define SZ(x) (int)x.size()
#define SQ(x) (x)*(x)
#define MN(a,b) a = min(a,(__typeof__(a))(b))
#define MX(a,b) a = max(a,(__typeof__(a))(b))
#define pb push_back
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define bug(x) cerr<<#x<<" is "<<x<<endl

using namespace std;

#define int ll

const int iinf = 1<<29;
const ll inf = 1ll<<60;
const ll mod = 1e9+7;


void GG(){cout<<"Impossible\n"; exit(0);}

ll mpow(ll a, ll n, ll mo = mod){ // a^n % mod
    ll re=1;
    while (n>0){
        if (n&1) re = re*a %mo;
        a = a*a %mo;
        n>>=1;
    }
    return re;
}

ll inv (ll b, ll mo = mod){
    if (b==1) return b;
    return (mo-mo/b) * inv(mo%b) % mo;
}

const int maxn = 1e5+5;

ll gcd(ll a, ll b){
    if (b==0) return a;
    return gcd(b,a%b);
}



main(){
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    
    int n, m; cin>>n>>m;
    vector<int> e, o;
    REP(i,m){
        int x; cin>>x; if (x&1)o.pb(x); else e.pb(x);
    }
    if (SZ(o)>2) GG();
    vector<int> re;
    vector<int> mo;
    if (SZ(o)) mo.pb(o[0]);
    mo.insert(mo.end(),ALL(e));
    if (SZ(o)>1) mo.pb(o[1]);
    REP(i, SZ(mo)){
        if (i==0) {if (mo[i]!=1) re.pb(mo[i]-1);}
        else if (i==SZ(mo)-1){
            re.pb(mo[i]+1);
        } else re.pb(mo[i]);
    }
    int s = 0; REP(i, SZ(re)) s += re[i];
    if (s!=n) re.pb(n-s);
    REP(i, SZ(mo)) cout<<mo[i]<<' '; cout<<endl;
    cout<<SZ(re)<<endl;
     REP(i, SZ(re)) s+=re[i],cout<<re[i]<<' ';
} 

Measured memory_bytes: 256
import java.util.Scanner;

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

		String str = sc.next();

		boolean n = false;
		boolean s = false;
		boolean w = false;
		boolean e = false;

		for (int i = 0; i < str.length(); i++) {
			char c = str.charAt(i);
			switch (c) {
			case 'N':
				n = true;
				break;
			case 'S':
				s = true;
				break;
			case 'W':
				w = true;
				break;
			case 'E':
				e = true;
				break;
			default:
				System.out.println("error!");
				return;
			}
		}

//		System.out.println("n && s : " + (n && s));
//		System.out.println("!n && !s : " + (!n && !s));
//		System.out.println("w && e : " + (w && e));
//		System.out.println("!w && !e : " + (!w && !e));

		boolean isHome =  ((n && s) || (!n && !s))
							&& ((w && e) || (!w && !e));
		System.out.println(isHome ? "Yes" : "No");

		sc.close();
	}

}


Measured memory_bytes: 21844
N = int(input())
A = list(map(int, input().split()))

ans = []
if N % 2 == 0:
  ans = A[N-1:0:-2] + A[0:N:2]
else:
  ans = A[N:0:-2] + A[0:1] + A[1:N-1:2]

print(" ".join(map(str,ans)))

Measured memory_bytes: 29940
#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long ll;
typedef long double ld;
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define mod 1000000007
#define pii pair<ll,ll>
#define inf 1000000000000000000
#define bpc(x) __builtin_popcountll(x)
#define autoit(x,it) for(auto it = x.begin(); it != x.end(); it++)
#define rep(n) for(ll i = 0; i < n; i++)
#define repi(i,n) for(ll i = 0; i < n; i++)

#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 

#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 

using namespace std;
mt19937_64 mt(chrono::steady_clock::now().time_since_epoch().count());

#define N 1000005

int main()
{
  FAST/**/
   
   ll n;
   cin>>n;
   
   ll arr[n];
   rep(n)
        cin>>arr[i];
   
   ll fr[N];
   memset(fr,0,sizeof(fr));
   
   rep(n)
        fr[arr[i]]++;
        
   ll fr1[N];
   memset(fr1,0,sizeof(fr1));
        
   bool nono = 0;
   for(ll i=N-1;i>1;i--)
   {
       for(ll j=i;j<N;j+=i)
            fr1[i]+=fr[j];
       if(fr1[i]>1)
       {
           nono = 1;
           break;
       }
   }
   
   ll g = 0;
   rep(n)
        g = __gcd(arr[i],g);
   
   if(nono == 0)
   {
       cout<<"pairwise coprime";
       return 0;
   }
   
   if(g == 1)
   {
       cout<<"setwise coprime";
       return 0;
   }
   
   cout<<"not coprime";
   
   
   
   return 0;        
}  

  
          
   

Measured memory_bytes: 27056
#include "bits/stdc++.h"
using namespace std;

typedef long long ll;

int main() {
	vector<int> a(3), b(3);
	for(int i=0; i<3; i++) cin >> a[i] >> b[i];

	map<int,int> m;
	for (int i = 0; i < 3; i++) {
		m[a[i]]++;
		m[b[i]]++;
	}
	if (m.size() != 4) {
		cout << "NO" << endl;
	}
	else {
		bool f=true;
		for (auto itr = m.begin(); itr != m.end(); itr++) {
			//cout << itr->first << " " << itr->second << endl;
			if (itr->second >= 3) {
				f=false;
			}
		}
		cout << (f?"YES":"NO") << endl;
	}
	

}

Measured memory_bytes: 256
def inpl(): return [int(i) for i in input().split()]

sx,sy,tx,ty = inpl()

uplen = ty - sy
rightlen = tx - sx

print('U' * uplen + 'R' * rightlen +
      'D' * uplen + 'L' * (rightlen + 1) +
      'U' * (uplen + 1) + 'R' * (rightlen + 1) + 'D' +
      'R' + 'D' * (uplen + 1) + 'L' * (rightlen + 1) + 'U' )

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

int main()
{
	string C, C2;

	cin >> C >> C2;

	if (C[0] == C2[2] && C[1] == C2[1] && C[2] == C2[0])
		cout << "YES" << endl;
	else
		cout << "NO" << endl;

	return 0;
}

Measured memory_bytes: 256
using System;

namespace agc019_b
{
    class Program
    {
        static void Main(string[] args)
        {
            string s = Console.ReadLine();
            long ret = (long)s.Length * (s.Length - 1) / 2;
            int[] count = new int[26];
            for (int i = 0; i < s.Length; i++)
            {
                count[s[i] - 'a']++;
            }
            for (int i = 0; i < 26; i++)
            {
                ret -= (long)count[i] * (count[i] - 1) / 2;
            }
            Console.WriteLine(ret + 1);
        }
    }
}

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

int main()
{
        char s[100000];
        scanf("%s",s);

        int n=strlen(s);

        int i,count=0;
        for(i=1; i<n; i++){
                if(s[i] == s[i-1]){
                        if(s[i] == '0')
                                s[i] += 1;
                        else
                                s[i] -=1;
                        count++;
                }
        }

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

Measured memory_bytes: 256
n,m = map(int, input().split())
 
ac = [0] * n
wa = [0] * n
a = 0
w = 0

for i in range(m):
  p, s = input().split()
  p = int(p) - 1
  if ac[p] == 0 and s == 'AC':
    ac[p] += 1
    a += 1
    w += wa[p]
  elif ac[p] == 0 and s == 'WA':
    wa[p] += 1
  
print(a, w)


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

string solve(string s, int n) {
	if (s.length() <= n)
		return s;
	else {
		string temp;
		for (int i=0; i<n; i++) {
			temp += s[i];
		}
		temp += "...";
		return temp;
	}
}

int main() {
	int n;
	cin >> n;
	string s;
	cin >> s;
	cout << solve(s, n);
	return 0;
}

Measured memory_bytes: 3628
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define For(i,a,b) for(int i=a;i<=b;i++)
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define sz(x) ((int)x.size())
#define MOD (ll)(1e9+7)
#define INF 1e17
#define int ll
#define EPS (1e-6)
using namespace std;
using ll=long long;
using pii=pair<int,int>;

int gcd(int a,int b) { return b==0?a:gcd(b,a%b); }
int lcm(int a,int b) { return a/gcd(a,b)*b; }

int fpow(int b,int p)
{
	if(p==0) return 1;
	int h=fpow(b,p/2);
	if(p%2) return h*b%MOD*h%MOD;
	return h*h%MOD;
}

int32_t main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	int a,b; cin>>a>>b;
	cout<<(b+a-3)/(a-1)<<"\n";
	return 0;
}





























Measured memory_bytes: 256
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

from heapq import heappop, heappush

def dijkstra(E, start):
    N_d = len(E)
    dist = [INF] * N_d
    dist[start] = 0
    q = [(0, start)]
    while q:
        dist_v, v = heappop(q)
        if dist[v] != dist_v:
            continue
        for u, dist_vu in E[v]:
            dist_u = dist_v + dist_vu
            if dist_u < dist[u]:
                dist[u] = dist_u
                heappush(q, (dist_u, u))
    return dist

N = INT()
abc = [LIST() for i in range(N-1)]
Q, K = MAP()
xy = [LIST() for i in range(Q)]

graph = defaultdict(list)

for a, b, c in abc:
    graph[a-1].append((b-1, c))
    graph[b-1].append((a-1, c))

    # graph[a-1].append((b-1, c))

d = dijkstra(graph, K-1)

for x, y in xy:
    # ans = dijkstra(graph, x-1)[K-1] + dijkstra(graph, K-1)[y-1]
    # d = dijkstra(graph, K-1)
    
    ans = d[x-1] + d[y-1]
    # dijkstra(graph, x-1)
    print(ans)


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

int main(){
  int n; cin >> n;
  string s; cin >> s;
  for (int i = 0; i < s.size(); i++){
    int a = s.at(i) - 'A';
    a = (a + n) % 26;
    s.at(i) = 'A' + a;
  }
  cout << s << endl;
}

Measured memory_bytes: 256
from collections import deque
a,b=map(int,input().split())
List=[]
q=deque([[0,0]])
for i in range(a):
  l=list(input())
  for _ in range(b):
    if l[_]=="#":
      q.append([i,_])
      l[_]=0
  List.append(l)
q.popleft()
aaa=[[0,1],[0,-1],[1,0],[-1,0]]
ans=0
while q:
  h,w=q.popleft()
  for x,y in aaa:
    if 0<=h+x<a and 0<=w+y<b:
      if List[h+x][w+y]==".":
        List[h+x][w+y]=List[h][w]+1
        q.append([h+x,w+y])
        if List[h+x][w+y]>ans:
          ans=List[h+x][w+y]
print(ans)

Measured memory_bytes: 167044
#include<stdio.h>
int main(void)
{
    int a,b,c[15],d[15],i,f;
	scanf("%d",&a);
	while(a!=0){
	    f=0;
	    scanf("%d",&b);
	    for(i=0;i<b;i++){
		    scanf("%d %d",&c[i],&d[i]);
		}
		for(i=0;i<b;i++){
		    f=f+(d[i]-c[i]);
		}
		if(f>=a) printf("OK\n");
		else if(f<a) printf("%d\n",a-f);
		scanf("%d",&a);
	}
	return 0;
}

Measured memory_bytes: 2732
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using ll = long long;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repk(i, k, n) for (int i = k; i < n; i++)
#define MOD 1000000007
#define INF 1e9
#define PIE 3.14159265358979323

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;
}
template <class T>
T GCD(T a, T b) {
    if (b == 0)
        return a;
    else
        return GCD(b, a % b);
}
template <class T>
inline T LCM(T a, T b) {
    return (a * b) / GCD(a, b);
}

using namespace std;
//#inculude <bits/stdc++.h>
//#define int long long

signed main() {
    int n, T;
    cin >> n >> T;
    int ans = INF;
    int c, t;
    rep(i, n) {
        cin >> c >> t;
        if (t <= T)
            chmin(ans, c);
    }
    if (ans == INF) {
        cout << "TLE" << endl;
        return 0;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin >> n;
    map<string,int> a;
    for(int i=0;i<n;i++){
        string s;
        cin >> s;
        a[s]++;
    }
    int c=0;
    for(auto i:a){
        c = max(c,i.second);
    }
    for(auto i:a){
        if(i.second==c) cout << i.first << endl;
    }
}


Measured memory_bytes: 25216
import java.util.*;
import java.io.*;
import static java.lang.Math.*;

public class Main {
    public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		
		// 入力
		int n = sc.nextInt();
		long[][] ab = new long[n][2];
		for(int i = 0; i < n; i++){
		    ab[i][0] = sc.nextLong();
		    ab[i][1] = sc.nextLong();
		}
		
		// 計算
		long result = 0;
		long from = 0;
		long to = 0;
		if(n%2 == 1){
		    Arrays.sort(ab, (s, t) -> Long.compare(s[0], t[0]));
		    from = ab[n/2][0];
		    Arrays.sort(ab, (s, t) -> Long.compare(s[1], t[1]));
		    to = ab[n/2][1];
		}else{
		    Arrays.sort(ab, (s, t) -> Long.compare(s[0], t[0]));
		    from = ab[n/2-1][0] + ab[n/2][0];
		    Arrays.sort(ab, (s, t) -> Long.compare(s[1], t[1]));
		    to = ab[n/2-1][1] + ab[n/2][1] ;
		}
		result = to-from+1;
		
		// 出力
		System.out.println(result);
	}

	public static class Scanner {
		private BufferedReader br; private StringTokenizer tok;
		public Scanner(InputStream is) throws IOException { br = new BufferedReader(new InputStreamReader(is));}
		private void getLine() throws IOException { while(!hasNext()) tok = new StringTokenizer(br.readLine());}
		private boolean hasNext() { return tok != null && tok.hasMoreTokens();}
		public String next() throws IOException { getLine(); return tok.nextToken();}
		public int nextInt() throws IOException { return Integer.parseInt(next());}
		public long nextLong() throws IOException { return Long.parseLong(next());}
		public double nextDouble() throws IOException { return Double.parseDouble(next());}
	}
}


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

int main() {
    int n, x;
    cin >> n >> x;
    vector<int> a(n);
    for (int i = 0; i < n; i++) cin >> a[i];
    sort(a.begin(), a.end());

    int ans = 0;
    for (int i = 0; i < n; i++) {
        if (a[i] <= x) {
            x -= a[i];
            if (i == n - 1 && x != 0) break;
            ans++;
        } else {
            break;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 888
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define MAX  200003

int main(){
    int n, m, k;
    while( cin >> n >> m >> k ){
        n = max( n, m );
        int an = k/n;
        if( k%n )an++;
        cout << an << endl;
    }
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define inf 999999999
#define loop(i, a, b) for (int i = (a), i##len = (b); i < i##len; ++i)
#define rep(i, n) loop(i, 0, n)
#define lin long long
#define lfl long double

int n,tt;
int c[101], t[101];

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

    int mn = inf;

    rep(i,n)
    {
        int c, t;
        cin >> c >> t;

        if(t > tt)
            continue;

        if (mn <= c)
            continue;

        mn = c;
    }

    if(mn == inf)
        cout << "TLE" << endl;
    else
        cout << mn << endl;


    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <vector>
#include <string>

int main(){

    int m, f, r;
    while(true) {
        scanf("%d %d %d", &m, &f, &r);
        
        // end
        if (m == -1 && f == -1 && r == -1) break;
        
        if (m == -1 || f == -1) {
            printf("F\n");
            continue;
        }
        if (80 <= m + f) {
            printf("A\n");
            continue;
        }
        if (65 <= m + f) {
            printf("B\n");
            continue;
        }
        if (50 <= m + f) {
            printf("C\n");
            continue;
        }
        if (30 <= m + f) {
            if(50 <= r) {
                printf("C\n");
                continue;
            }
            printf("D\n");
            continue;
        }
        printf("F\n");
        
    }

}


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

void change(char s[],int len){
	int i,p;
	p=s[0];
	for(i=0;i<len;i++){
		s[i]=s[i+1];
	}
	s[len-1]=p;
}

int main(){
	char s[100],t[100];
	scanf("%s",s);
	scanf("%s",t);

	int i,len=strlen(s);

	for(i=0;i<len;i++){
		change(s,len);
		if(strcmp(s,t)==0){
			printf("Yes\n");
			return 0;
		}
	}
	printf("No\n");
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,n) for(long long int i = 0; i < n; i++)
#define _rep(i,m,n) for(long long int i = m; i < n; i++)
#define print(n) std::cout << n << std::endl
#define _print(n) std::cout << n
using namespace std;
typedef long long ll;
const int N = 1000000;
const ll mod = 1000000007;

int main() {
    int n; cin >> n;
    string s; cin >> s;
    int count = 0;
    _rep(i,1,n - 1){
        if(s[i - 1] == 'A' && s[i] == 'B' && s[i + 1] == 'C')count++;
    }
    print(count);
}


Measured memory_bytes: 256
import itertools
import sys

N=int(input())
L=list(map(int,input().split()))

if N<3:
  print(0)
  sys.exit()

ans=0

for i in itertools.combinations(L,3):
  t=list(i)
  t.sort()
  x,y,z=t

  if len(set(i))!=3:
    continue
  
  if x+y>z:
    ans+=1
print(ans)
  
  

Measured memory_bytes: 9164