akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define REP(i, n) for(int i = 1; i < (int)(n); ++i)
using namespace std;

int main() {
    int N, A, B;
    cin >> N >> A >> B;
    if ((B - A) % 2) cout << "Borys" << endl;
    else cout << "Alice" << endl;
    return 0;
}


Measured memory_bytes: 256
from sys import stdin
import math
import re
import queue

input = stdin.readline

MOD = 1000000007
INF = 122337203685477580


def solve():
    x,k,d = map(int, input().split())
    move = k*d
    x = abs(x)
    if x > k*d:
        print(x -k*d)
    else:
        q = x//d
        if abs(q - k)%2 == 0:
            print(x%d)
        else:
            print(d - x%d)
            
if __name__ == '__main__':
    solve()


Measured memory_bytes: 10144
import numpy as np
 
n = int(input())
h = list(map(int, input().split()))
 
h = np.array(h)
 
for i in range(len(h)-1):
   if h[i] < h[i+1]:
       h[i+1] -= 1
np.diff(h-1, n=1)
 
minus = [i for i in np.diff(h-1, n=1) if i < 0]
 
if len(minus) > 0:
    print('No')
else:
    print('Yes')

Measured memory_bytes: 23076
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int N, X;
    cin >> N >> X;
    vector<int> L(N);
    for(int i=0; i<N; i++){
        cin >> L.at(i);
    }
    
    vector<int> jump(N+1);
    for(int i=1; i<=N; i++){
        jump.at(i) = jump.at(i-1) + L.at(i-1);
    }
    /*
    for(int i=0; i<N+1; i++){
        cout << jump.at(i) << " ";
    }
    */
    
    int count =0;
    for(int i=0; i<=X; i++){
        for(int j=0; j<N+1; j++){
            if(i == jump.at(j)){
                count++;
            }
        }   
    }
    cout << count << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <set>

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,j) FOR(i,0,j)
#define mp std::make_pair

typedef long long ll;
typedef unsigned long long ull;

struct P{
    P(){}
    P(double _x, double _y, double _z):x(_x), y(_y), z(_z){}
    double x, y, z;
};

double norm(const P& p){return p.x * p.x + p.y * p.y + p.z * p.z;}

P operator+(const P& lhs, const P& rhs){
    return P(lhs.x+rhs.x, lhs.y+rhs.y, lhs.z+rhs.z);
}
P operator-(const P& lhs, const P& rhs){
    return P(lhs.x-rhs.x, lhs.y-rhs.y, lhs.z-rhs.z);
}
P operator-(const P& p){
    return P(-p.x, -p.y, -p.z);
}
P operator*(const P& p, const double& k){
    return P(p.x*k, p.y*k, p.z*k);
}

P cross(const P& lhs, const P& rhs){
    return P(lhs.y*rhs.z-lhs.z*rhs.y, lhs.z*rhs.x-lhs.x*rhs.z, lhs.x*rhs.y-lhs.y*rhs.x);
}

double dot(const P& lhs, const P& rhs){
    return lhs.x*rhs.x + lhs.y*rhs.y + lhs.z*rhs.z;
}

const int INF = 1001001001;
const double EPS = 1e-8;

// S N E W(南北東西)
const int dx[8] = {0, 0, 1, -1, 1, 1, -1, -1}, dy[8] = {1, -1, 0, 0, 1, -1, 1, -1};

P pp, ep, t[3];

int main(){
    scanf("%lf %lf %lf", &pp.x, &pp.y, &pp.z);
    scanf("%lf %lf %lf", &ep.x, &ep.y, &ep.z);

    REP(i, 3){
        scanf("%lf %lf %lf", &t[i].x, &t[i].y, &t[i].z);
    }

    P n = cross(t[1]-t[0], t[2]-t[0]);
    
    double d1 = dot(n, pp-t[0]), d2 = dot(n, ep-t[0]);
    if(d1 * d2 > 0){
        puts("HIT");
    }else{
        P p = pp + (ep-pp) * (std::abs(d1) / (std::abs(d1)+std::abs(d2)));
    
        P cs[3] = {cross(t[1]-t[0], p-t[1]),
                   cross(t[2]-t[1], p-t[2]),
                   cross(t[0]-t[2], p-t[0])};
        
        if(dot(cs[0], cs[1]) > -EPS && dot(cs[0], cs[2]) > -EPS){
            puts("MISS");
        }else{
            puts("HIT");
        }
    }
}

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

int main(){
    string s;
    string ans = "Good";
    char before = ' ';
    cin >> s;

    for (auto c : s){
        if ( before == c ) {
            ans = "Bad";
        } 
        before = c;
    }
    cout << ans << endl;

}

Measured memory_bytes: 256
#include<cstdio>
using namespace std;
const int maxn = 10000000;
int main()
{
	int a,b,c,d;
	scanf("%d%d%d%d",&a,&b,&c,&d);
	if(a % c == 0 && b % d == 0)
	{
		printf("No\n");
	}
	else
	{
		int nz = maxn / (c * d - 1);
		int nf = (c * d - 1) * nz + 1;
		printf("Yes\n");
		for(int i = 1;i <= a;++i)
		{
			for(int j = 1;j <= b;++j)
			{
				if(i % c == 0 && j % d == 0)
					printf("-%d ",nf);
				else
					printf("%d ",nz);
			}
			putchar('\n');
		}
	}
	return 0;
}

Measured memory_bytes: 2432
#coding : utf-8　

import os
import sys

N, L = map(lambda x: int(x), input().split(" "))

t = [0 for i in range(N)]

for i in range(N):
	t[i] = L + i + 1 - 1

t0 = sum(t)

min_diff = 10**9
min_idx = -1
min_t = 10**9

for i in range(N):
	tmp = t[i]
	t[i] = 0
	tt = sum(t)
	diff = abs(tt - t0)
	if diff < min_diff:
		min_diff = diff
		min_idx = i
		min_t = tt
	t[i] = tmp

print(min_t)



Measured memory_bytes: 3064
using System;
using System.Collections.Generic;
using System.Linq;

public class Prog
{
    public static void Main()
    {
        var input = Console.ReadLine().Split();
        int R = int.Parse(input[0]);
        int G = int.Parse(input[1]);
        int B = int.Parse(input[2]);
        int N = int.Parse(input[3]);
        int max = Math.Max(R, Math.Max(G, B));
        int num = 0;
        int maxNum = N / max;
        if(max == R)
        {
            for(int i = 0; i <= maxNum; i++)
            {
                int M = N - R * i;
                int second = M / G;
                for(int j = 0; j <= second; j++)
                {
                    int L = M - G * j;
                    if(L%B == 0)
                    {
                        num++;
                    }
                }
            }
        }else if(max == G)
        {
            for(int i = 0; i <= maxNum; i++)
            {
                int M = N - G * i;
                int second = M / R;
                for(int j = 0; j <= second; j++)
                {
                    int L = M - R * j;
                    if(L%B == 0)
                    {
                        num++;
                    }
                }
            }
        }
        else
        {
            for (int i = 0; i <= maxNum; i++)
            {
                int M = N - B * i;
                int second = M / R;
                for (int j = 0; j <= second; j++)
                {
                    int L = M - R * j;
                    if (L % G == 0)
                    {
                        num++;
                    }
                }
            }
        }
        Console.WriteLine(num);
    }
}



Measured memory_bytes: 13140
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[][] cnt = new int[n][26];
		for (int i = 0; i < n; i++) {
			String s = sc.next();
			for (int j = 0; j < s.length(); j++) {
				cnt[i][s.charAt(j) - 'a']++;
			}
		}
		sc.close();

		int[] ans = new int[26];
		Arrays.fill(ans, 51);
		for (int k = 0; k < 26; k++) {
			for (int i = 0; i < n; i++) {
				ans[k] = Math.min(ans[k], cnt[i][k]);
			}
		}

		StringBuilder sb = new StringBuilder();
		for (int k = 0; k < 26; k++) {
			char[] str = new char[ans[k]];
			Arrays.fill(str, (char) ('a' + k));
			sb.append(str);
		}
		System.out.println(sb.toString());
	}
}


Measured memory_bytes: 21716
#include <stdio.h>
#define LENGTH 256

int main()
{
    char input[LENGTH];
    char *result;
    int score;
    fgets(input, LENGTH-1, stdin);
    sscanf(input, "%d", &score);
    if (score < 1200)
    {
        result = "ABC";
    }else if (score < 2800)
    {
        result = "ARC";
    }else
    {
        result = "AGC";
    }
    printf("%s\n", result);
    return 0;
}


Measured memory_bytes: 128
#include<iostream>
using namespace std;
int main(){
  int w,a,b;
  cin >> w >> a >> b;
  if((a+w >= b && b >= a)||(a+w >= b+w && b+w >= a)){
    cout << 0;
  }else if(a+w < b){
    cout << b-(a+w);
  }else{
    cout << a-(b+w);
  }
}


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

int main() {
	string s;
	cin >> s;
	int cng = 0;
	for (int i = 0, j = s.size() - 1;i < j;) {
		if (s[i] == 'x') {
			i ++;
			if (s[j] == 'x') j --;
			else cng ++;
			continue;
		}
		if (s[j] == 'x') {
			j --;
			cng ++;
			continue;
		}
		if (s[i] != s[j]) {
			cout << -1;
			return 0;
		} else {
			i ++;
			j --;
		}
	}
	cout << cng;
	return 0;
}
// 左右から見ていき、左と右が一致しなければ回文ではない
// この時、xの個数にのみ注目する
// xの挿入だけで回文に変更できるから、片方のみにxがあるならもう片方にxを追加

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

int main(int argc, char const *argv[])
{
    string s;cin>>s;
    int x = stod(s);
    int a1,a2,a3,a4;
    a4=x%10;x/=10;
    a3=x%10;x/=10;
    a2=x%10;x/=10;
    a1=x%10;
    string ret;
    int f=10*a1+a2;
    int b=10*a3+a4;
    if(f>0 && f<=12){
        if(b>0 && b<=12)ret = "AMBIGUOUS";
        else ret = "MMYY";
    }
    else{
        if(b>0 && b<=12)ret = "YYMM";
        else ret = "NA";
    }

    cout << ret<<endl;
    

    return 0;
}


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

struct UnionFind {
    vector<int> par;
    
    UnionFind(int n) : par(n, -1) { }
    void init(int n) { par.assign(n, -1); }
    
    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }
    
    bool issame(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); // merge technique
        par[x] += par[y];
        par[y] = x;
        return true;
    }
    
    int size(int x) {
        return -par[root(x)];
    }
};

int main() {
    long long N, M; cin >> N >> M;
    vector<int> A(M), B(M);
    for (int i = 0; i < M; ++i) {
        cin >> A[i] >> B[i], --A[i], --B[i];
    }
        
    UnionFind uf(N);
    long long cur = N * (N-1) / 2;
    vector<long long> res;
    for (int i = 0; i < M; ++i) {
        res.push_back(cur);
            
        int a = A[M-1-i], b = B[M-1-i];
        if (uf.issame(a, b)) continue;
        
        long long sa = uf.size(a), sb = uf.size(b);
        cur -= sa * sb;
        uf.merge(a, b);
    }
        
    reverse(res.begin(), res.end());
    for (int i = 0; i < res.size(); ++i) cout << res[i] <<endl;
}


Measured memory_bytes: 3444
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define db(x) (cerr << #x << ": " << (x) << '\n')
#define cps CLOCKS_PER_SEC
#define tests(t) int t; cin >> t; while(t--)
#define iceil(n, x) (((n) + (x) - 1) / (x))
#define eb emplace_back
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define sz size()
#define all(v) (v).begin(), (v).end()
#define uni(v) sort(all(v)), (v).erase(unique(all(v)), (v).end())
#define fi first
#define se second
#define bitcount(x) __builtin_popcount(x)
#define bit(x) (1LL << x)
#define PI acos(-1.0)
#define EPS 1e-9

#define mod 1000000007
#define maxn 105

using namespace std;

using namespace __gnu_pbds;
template<class key, class cmp = std::less<key>>
using ordered_set = tree<key, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
///All indexing is 0-based
///methods: find_by_order(k); & order_of_key(k);
///To make it an ordered_multiset, use pairs of (value, time_of_insertion)
///to distinguish values which are similar

typedef long long ll;
typedef double ld;
typedef pair<int, int> par;

struct trio
{
    ll nod,silv,cost;
    bool operator < (const trio &h) const{
        return cost>h.cost;
    }
};

ll N,M,S,C[maxn],D[maxn],a,b,c,d,Dp[maxn][maxn*maxn],MAX,sol[maxn];
priority_queue<trio> Q;
vector<trio> G[maxn];

void dijkstra(ll nod)
{
    ll cost,silv,newc,news;
    for(int i=1;i<=N;i++,sol[i] = 1ll<<60)
        for(int j=0;j<=MAX;j++)
            Dp[i][j]=1LL<<60;
    Dp[1][S]=0;
    Q.push({1,S,0});
    while(!Q.empty()){
        auto a = Q.top();
        Q.pop();
        nod = a.nod , cost = a.cost, silv = a.silv;
        if(cost > Dp[nod][silv])
            continue;
        sol[nod] = min(sol[nod],cost);

        news = min(silv+C[nod],MAX) , newc = cost+D[nod];
        if(Dp[nod][news]>newc){
            Q.push({nod,news,newc});
            Dp[nod][news]=newc;
        }

        for(auto b:G[nod]){
           if(silv>=b.silv && Dp[b.nod][silv-b.silv]>cost+b.cost){
                Q.push({b.nod,silv-b.silv,cost+b.cost});
                Dp[b.nod][silv-b.silv]=cost+b.cost;
           }
        }
    }
}


int main()
{
    #ifdef acm
    freopen("a.in","r",stdin);
    #endif // acm
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    cin >> N >> M >> S;

    for(int i=1;i<=M;i++){
        cin >> a >> b >> c >> d;
        G[a].pb( {b,c,d} );
        G[b].pb( {a,c,d} );
        MAX = max(MAX,c);
    }
    MAX*=N-1;
    S=min(S,MAX);
    for(int i=1;i<=N;i++)
        cin >> C[i] >> D[i];

    dijkstra(1);

    for(int i=2;i<=N;i++)
        cout << sol[i] << "\n";




}



Measured memory_bytes: 7416
using System;
using System.Collections.Generic;
using System.Text;
using System.Linq;

class Program
{
    public void Proc()
    {
        Reader.IsDebug = false;
        long[] inpt = Reader.ReadLine().Split(' ').Select(a => long.Parse(a)).OrderByDescending(a => a).ToArray();
        Nullable<long> ans = GetAns(inpt);

        if (ans == null)
        {
            ans = -1;
        }
        Console.WriteLine(ans.Value);

    
    }


    private Dictionary<long, Dictionary<long, Dictionary<long, Nullable<long>>>> dic = new Dictionary<long, Dictionary<long, Dictionary<long, Nullable<long>>>>();
    private Nullable<long> GetAns(long[] inpt)
    {
        if (!dic.ContainsKey(inpt[0]))
        {
            dic.Add(inpt[0], new Dictionary<long, Dictionary<long, long?>>());
        }
        if (!dic[inpt[0]].ContainsKey(inpt[1]))
        {
            dic[inpt[0]].Add(inpt[1], new Dictionary<long, long?>());
        }
        if (dic[inpt[0]][inpt[1]].ContainsKey(inpt[2]))
        {
            return dic[inpt[0]][inpt[1]][inpt[2]];
        }

        dic[inpt[0]][inpt[1]][inpt[2]] = null;

        long ans = 0;
        if (inpt.Any(a => a % 2 == 1))
        {
            ans = 0;
        }
        else
        {
            Nullable<long> ret = GetAns(new long[] { inpt[1] / 2 + inpt[2] / 2, inpt[0] / 2 + inpt[2] / 2, inpt[0] / 2 + inpt[1] / 2 }.OrderByDescending(a=>a).ToArray());
            if (ret == null)
            {
                return null;
            }
            else
            {
                ans = ret.Value + 1;
            }
        }

        dic[inpt[0]][inpt[1]][inpt[2]] = ans;
        return ans;
    }




    public class Reader
    {
        public static bool IsDebug = true;
        private static String PlainInput = @"


454 414 444


";
        private static System.IO.StringReader Sr = null;
        public static string ReadLine()
        {
            if (IsDebug)
            {
                if (Sr == null)
                {
                    Sr = new System.IO.StringReader(PlainInput.Trim());
                }
                return Sr.ReadLine();
            }
            else
            {
                return Console.ReadLine();
            }
        }
    }
    static void Main()
    {
        Program prg = new Program();
        prg.Proc();
    }
}

Measured memory_bytes: 13536
from collections import defaultdict, deque
dic = defaultdict(list)
N, Q = map(int, input().split())
point = [0 for _ in range(N)]

for i in range(N-1):
    a, b = map(int, input().split())
    dic[a].append(b)
    dic[b].append(a)

for _ in range(Q):
    p, x = map(int, input().split())
    point[p-1]+=x
    
queue = deque()
for i in dic[1]:
    queue.append(1)
    queue.append(i) #親、子
    
while queue:
    p = queue.popleft()
    c = queue.popleft()
    point[c-1]+=point[p-1] 
    
    for j in dic[c]:
        if j != p:
            queue.append(c)
            queue.append(j)
            
        
print(*point)


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

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

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

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

int main(){
    ll h;
    cin >> h;
    printf("%ld\n",(ll)pow(2,(int)log2(h)+1)-1);    
    return 0;
}


Measured memory_bytes: 384
/*
ID: Aman Raj
LANG: C++
TASK: money
*/
#include<iostream>
#include <stdio.h>
//#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
#include<math.h>
typedef  long long int ll;
#include <bits/stdc++.h>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <iomanip>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
//setbase - cout << setbase (16); cout << 100 << endl; Prints 64
//setfill -   cout << setfill ('x') << setw (5); cout << 77 << endl; prints xxx77
//setprecision - cout << setprecision (14) << f << endl; Prints x.xxxx
//cout.precision(x)  cout<<fixed<<val;  // prints x digits after decimal in val
//Â
using namespace std;
using namespace __gnu_pbds;
//Â
#define f(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) f(i,0,n)
#define fd(i,a,b) for(i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define vi vector< int >
#define vl vector< ll >
#define ss second
#define ff first
//#define ll long long
#define pii pair< int,int >
#define pll pair< ll,ll >
#define sz(a) a.size()
#define inf (1000*1000*1000+5)
#define all(a) a.begin(),a.end()
#define tri pair<int,pii>
#define vii vector<pii>
#define vll vector<pll>
#define viii vector<tri>
#define mod (1000*1000*1000+7)
#define pqueue priority_queue< int >
#define pdqueue priority_queue< int,vi ,greater< int > >
//#define flush fflush(stdout)
#define primeDEN 727999983
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#include <fstream>
// find_by_order()  // order_of_key
typedef tree<
	int,
	null_type,
	less<int>,
	rb_tree_tag,
	tree_order_statistics_node_update>
	ordered_set;
  //# define mod 1e9+7
   ll gcd(ll a,ll b)
   {
       if(a==0)return b;
       return gcd(b%a,a);
   }
//Â

ll power1(ll a, ll b)//a raised to power b
   {  if(b<=0) return 1; if(b==1) return a;
       ll c=power1(a,b/2);
        c*=c;c%=mod;if(b%2==1) c*=a;c%=mod;
        return c;
   }
   ll mi(ll a,ll m)
   { ll c= power1(a,m-2);

     return c;
   }
int main()
{    ifstream fin("money.in");
     ofstream fout("money.out");

     ll n;cin>>n;
      double a;
      double b;cin>>b;
      double c=1;
       a=c/b;
       for(ll i=1;i<n;i++)
       {
           cin>>b;
           a+=(c/b);
       }
       a=c/a;
       cout<<setprecision(12)<<fixed;
       cout<<a;

      return 0;
}


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


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main(){
  string a,b,c;
  cin >> a >> b >> c;
  if(a[a.length()-1]==b[0] && b[b.length()-1]==c[0]){
    cout << "YES" << endl;
  }
  else cout << "NO" << endl;
  return 0;
}

Measured memory_bytes: 384
#include <stdio.h>
#include <string>
#include <iostream>
#include <iomanip>
#include <map>
#include <algorithm>
#include <vector>
using namespace std;

int main(void){
    int i;
    cin >> i;
    if(i==2){
        int a,b;
        cin >> a >> b;
        cout << a+b << endl;
    }
    else if(i==1){
        cout << "Hello World" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
from fractions import gcd

N = int(input())
A = [int(x) for x in input().split()]

L=[0]
R=[0]

for i in range(N):
    L.append(gcd(L[i],A[i]))
    R.append(gcd(R[i],A[N-1-i]))
    
R_new = R[::-1]
ans = 0
for i in range(N):
    temp = gcd(L[i], R_new[i+1])
    ans = max(ans,temp)
    
print(ans)

Measured memory_bytes: 16164
#include "bits/stdc++.h"
using namespace std;
using ll = long long;

#ifdef LOCAL
        #include "debug.h"
        #define input freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    #else
        #define debug(...) 42
        #define input ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#endif
    
const int N = 2e5 + 50;
int fac[N],invf[N];
const int mod = 998244353;
inline int add(int x, int y) { return x + y >= mod ? x + y - mod : x + y; }
inline int sub(int x, int y) { return x - y >= 0 ? x - y : x - y + mod; }
inline int power(int x, int y, int res = 1) {
    for (; y; y >>= 1, x = 1ll * x * x % mod) {
        if (y & 1) { res = 1ll * res * x % mod; }
    } return res;
}
void initcombi(int n) {
    for (int i = fac[0] = 1; i <= n; i++) { fac[i] = 1ll * fac[i - 1] * i % mod; }
    invf[n] = power(fac[n], mod - 2);
    for (int i = n; i; i--) { invf[i - 1] = 1ll * invf[i] * i % mod; }
}
 
inline int NCR(int n, int m) {
    if (n < m) { return 0; }
    return 1ll * fac[n] * invf[m] % mod * invf[n - m] % mod;
}

ll ans;
int main() {
    input;
    initcombi(200000);
    int n, m, k;
    cin >> n >> m >> k;
    for(int i = n - k; i <= n; i++) {
        ll x = (1LL * NCR(n - 1, i - 1) * m);
        x %= mod;
        x *= power(m - 1, i - 1);
        x %= mod;
        ans += x;
        ans %= mod;
    }
    cout << ans;
}



Measured memory_bytes: 5212
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep2(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep_inv(i, n, m) for(int i = (int)(n); i > (int)(m); i--)
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vc = vector<char>;
using vvl = vector<vl>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;

int main(){
  ll N, R;
  cin >> N >> R;

  if(N < 10)
    cout << R + 100*(10 - N) << "\n";
  else
    cout << R << "\n";
  
  return 0;
}


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

int main(void)
{
    int w;
    
    while (1){
        int money = 0;
        
        scanf("%d", &w);
        if (w == -1) break;
        
        while (1){
            if (30 < w){
                money += 160;
            }
            else if (20 < w){
                money += 140;
            }
            else if (10 < w){
                money += 125;
            }
            else if (w == 0){
                money += 1150;
                break;
            }
            w--;
        }
        
        printf("%d\n", 4280 - money);
    }
    
    return (0);
}

Measured memory_bytes: 0
N,T= map(int,input().split(" "))

min=2000

for i in range(0,N):
  c,t=map(int,input().split(" "))
  if t>T:
    continue
  else:
    min=min-(min-c)*(c<min)

if min==2000:
  print("TLE")
else:
  print(min)  


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
const int maxn=2e5;
int d[5];
int main()
{
    //freopen("ce.in","r",stdin);
    int a,b;
    for(int i=1;i<=3;++i)
    {
    cin>>a>>b;
    ++d[a],++d[b];
    }
    bool flag=0;
    for(int i=1;i<=4;++i)
        if(d[i]==3) flag=1;
    if(flag) puts("NO");else puts("YES");
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e18,MOD = 1e9 + 7;
const int INT_INF = 1e9,INT_MOD=1e9+7;
#define rep(i, N) for(int i = 0; i < N; i++)
typedef pair<int, int> Pi;
typedef pair<double, double> P;
signed main(){
    ll n,k,c=0;cin>>n>>k;
    ll a[n],num[n+5],ch[n+5];
    rep(i,n){
        cin>>a[i];
    }
    rep(i,n+5){
        num[i]=0;ch[i]=0;
    }
    ll tmp=1;
    ch[0]=1;
    num[0]=1;
    ll start=0,finish=0;
    for(ll j=0;j<n;j++){
        if(j==k) {
            cout<<tmp<<endl;
            return 0;
        }
        tmp=a[tmp-1];
        num[j+1]=tmp;
        if(ch[tmp-1]==1){
            c=j+1;
            break;
        }else{
            ch[tmp-1]=1;
        }
    }
    for(int p=0;;p++){
                if(num[p]==tmp){
                    start=p;break;
                }
            }
            finish=c;
    cout<<num[start+(k-start)%(finish-start)]<<endl;
    return 0;
}

Measured memory_bytes: 8276
def main():
    s = int(input())
    ak = s
    k = 1

    history = set([ak])
    while True:
        k += 1
        if ak%2 == 0:
            ak = ak//2
        else:
            ak = ak*3 + 1

        if ak in history:
            print(k)
            break
        else:
            history = history | set([ak])

main()

Measured memory_bytes: 38384
#include<bits/stdc++.h>
#include<algorithm>
#include<math.h>
#include<iostream>
using namespace std;
long long int lcm(long long int a,long long int b){
  long long int n;
  n=a*b/__gcd(a,b);
  return n;
}
using ll =long long int;
#define ci(a) cin>>a
#define co(a) cout<<a<<endl
#define gcd(a,b) __gcd(a,b)
#define vec vector<ll>
#define For(i,a,b) for(int i=a;i<b;i++)
#define rFor(i,a,b) for(int i=a;i>b;i--)
#define sort(a,b) sort(a.begin(),b.end())
//gcd 最大公約数
//lcm 最小公倍数
//double 少数（変数）
//string 文字列（変数）
//sqrt 平方根
//ceil 天井関数
//floor 床関数
//abs 絶対値
//pow 累乗
//cbrt  立方根
//hypot 平方和の平方根
//(string-'0') 文字列を数字に変換
//vector<vector<int>> data(a,vector<b>(b)) a×b行列
//for(int i=0;i<a;i++)
//for(int j=0;j<b;j++)
//cin>>data.at(i).at(j)  a×b行列の入力
//floor(log10(a)+1) aの10進法での桁数
//ceil(log10(a)) aの10進法での桁数

int main() {
  ll a;
  ci(a);
  ll c=0;
  for(int i=1;i<a+1;i+=2){
    ll b=0;
    For(j,1,a+1)
      if(i%j==0)
        b++;
    if(b==8)
      c++;
  }
  co(c);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long tint;
 
#define forsn(i, s, n) for(int i=s;i<int(n);i++)
#define forn(i, n) forsn(i, 0, n)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(), v.rend() 
#define NACHO ios::sync_with_stdio(0); cin.tie(NULL);

const int INF = 1111122222;
const int MOD = 1e9+7;

int dp[10001];

int main(){
	int h, n; cin >> h >> n;
	int a[n], b[n];
	forn(i, n){
		cin >> a[i] >> b[i];
	}
	forn(i, h+1) dp[i] = INF;
	dp[0] = 0;
	forsn(i, 1, h+1){
		forn(j, n){
			if(i-a[j] >= 0) dp[i] = min(dp[i], dp[i-a[j]]+b[j]);
			else dp[i] = min(dp[i], b[j]);
		}
	}
	cout << dp[h] << "\n";
}


Measured memory_bytes: 256
import math

n = int(input())

max = 50000
herf = 25000

arr = []
result = ':('

for t in range(50000):
  arr.append(t)

if herf > n:
  for s in range(herf):
    ans = math.floor(s * 1.08)
    if ans == n:
      result = str(s)
      break;
else:
  for s in range(25000, max):
    ans = math.floor(s * 1.08)
    if ans == n:
      result = str(s)
      break;

print(result)


Measured memory_bytes: 5064
import java.util.*;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long[] A = new long[n];
        long[] B = new long[n];
        for(int i=0;i<n;i++){
            A[i]=sc.nextLong();
            B[i]=sc.nextLong();
        }
        long ans = 0;
        for(int i=n-1;i>=0;i--){
            A[i]+=ans;
            if(A[i]%B[i]==0) continue;
            ans += B[i]-A[i]%B[i];
        }
        System.out.println(ans);
    }
}


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

current_money = 1000
for i in range(N-1):
    stock = 0
    if A[i] < A[i+1]:
        stock = current_money // A[i]
    current_money += (A[i+1] - A[i]) * stock

print(current_money)


Measured memory_bytes: 9144
#include <bits/stdc++.h>
#define rep(i, a, b) for(ll i = ll(a); i < ll(b); i++)
#define rer(i, a, b) for(ll i = ll(a) - 1; i >= ll(b); i--)
#define sz(v) (int)(v).size()
#define pb push_back
#define sc second
#define fr first
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define uniq(vec) vec.erase(unique(vec.begin(),vec.end()),vec.end())
using namespace std;
typedef long long int ll;
typedef pair <int, int> P;

const ll MOD=1000000007;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    for(;;){
        int n;
        cin>>n;
        if(!n){
            return 0;
        }
        vector<double> v(n);
        double a=0;
        rep(i,0,n){
            cin>>v[i];
            a+=v[i];
        }
        a/=n;
        int cnt=0;
        rep(i,0,n){
            if(v[i]<=a) cnt++;
        }
        cout <<cnt<<"\n";
    }
}


Measured memory_bytes: 3232
fun main(args: Array<String>) {
    val (a, v) = readLine()!!.split(' ').map { it.toLong() }
    val (b, w) = readLine()!!.split(' ').map { it.toLong() }
    val t = readLine()!!.toLong()

    val dist = Math.abs(b - a)
    val move = w - v
    if (move >= 0L) {
        println("NO")
    } else {
        if (move*t*-1L >= dist) {
            println("YES")
        } else {
            println("NO")
        }
    }
}


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

int main(){
	int n,a,b,c,x;
	while(cin >> n >> a >> b >> c >> x,n){
		int cnt=0,y[100];
		for(int i=0;i<n;i++){
			cin >> y[i];
		}
		int idx = 0;
		while(1){
			if(cnt > 10000) break;
			if(x == y[idx]) idx++;
			if(idx >= n) break;
			x = (a*x + b)%c;
			cnt++;
		}
		if(cnt > 10000){
			cout << -1 << endl;
		} else {
			cout << cnt << endl;
		}
	}
	return 0;
}

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

int main(void){
	int n, k;
	cin >> n >> k;
	vector<long> h;

	for(int i=0; i<n; i++){
		long val;
		cin >> val;
		h.push_back(val);
	}
	sort(h.begin(), h.end());

	long min_diff = 10000000000;
	for(int i=0; i<n-k+1; i++){
		min_diff = min(min_diff, h[i+k-1] - h[i]);
	}
	cout << min_diff << endl;

	return 0;
}

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

int main()
{
	int s,n;
	cin>>s;
	n=s%10;
	
	if(n==2||n==4||n==5||n==7||n==9)
	  cout<<"hon";
	if(n==0||n==1||n==6||n==8)
	  cout<<"pon";
	if(n==3)
	  cout<<"bon";
	  
	return 0;
	
}

Measured memory_bytes: 3636
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 998244353

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    rr = []

    while True:
        n = I()
        if n == 0:
            break

        a = [LS() for _ in range(n)]
        b = []
        for s,e in a:
            b.append((s,1))
            b.append((e,-1))
        b.sort()
        r = c = 0
        for t,f in b:
            c += f
            if r < c:
                r = c

        rr.append(r)

    return '\n'.join(map(str, rr))


print(main())




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

const int N_MAX = 20000;
int rs[N_MAX];

int main() {
    int n, s;
    while (cin >> n >> s, n|s) {
        for (int i = 0; i < n; i++) {
            cin >> rs[i];
        }
        int ans = 0;
        for (int i = 0; i + 1 < n; i++) {
            for (int j = i + 1; j < n; j++) {
                if (rs[i] + rs[j] > s) {
                    ans++;
                }
            }
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 1200
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <functional>

using namespace std;
typedef long long int ll;

#define repi(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,a) repi(i,0,a)
#define rrep(i,a) for(ll i=a-1;i>=0;i--)

ll llmin(ll a, ll b){
  return a < b ? a : b;
}

int main(){
  ll N;
  cin >> N;
  ll W[N];
  ll wsum = 0;
  rep(i, N){
    cin >> W[i];
    wsum += W[i];
  }
  ll ans = wsum;
  ll sumtmp = 0;
  rep(i, N){
    sumtmp += W[i];
    ans = llmin(ans, abs(sumtmp * 2 - wsum));
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();

int main() {
    int n, val, ans = 0;
    cin >> n;
    for(int i = 0; i < n; i++) {
        cin >> val;
        ans += val-1;
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 256
#!usr/bin/env python3
from collections import defaultdict, deque, Counter, OrderedDict
from bisect import bisect_left, bisect_right
from functools import reduce, lru_cache
from heapq import heappush, heappop, heapify

import itertools, bisect
import math, fractions
import sys, copy

def L(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline().rstrip())
def S(): return list(sys.stdin.readline().rstrip())
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI1(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LS(): return [list(x) for x in sys.stdin.readline().split()]
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def LIR1(n): return [LI1() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
def LR(n): return [L() for _ in range(n)]

alphabets = "abcdefghijklmnopqrstuvwxyz"

sys.setrecursionlimit(1000000)
dire = [[1, 0], [0, 1], [-1, 0], [0, -1]]
dire8 = [[1, 0], [1, 1], [0, 1], [-1, 1], [-1, 0], [-1, -1], [0, -1], [1, -1]]
MOD = 1000000007

def main():
    N = I()

    if N % 2 == 1:
        print(0)

    else:
        ans = 0
        for i in range(1, 30):
            ans += N // (2 * 5 ** i)

        print(ans)

if __name__ == '__main__':
    main()

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

using namespace std;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
#define watch(a) { std::cout << #a << " = " << a << "\n"; }
template<class T1, class T2> inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); }
template<class T1, class T2> inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); }
template<class T, class V> istream& operator>> (istream& ist, pair<T, V>& p) { return ist >> p.first >> p.second; }
template<class T> ostream& operator<< (ostream& ost, pair<T, T>& p) { return ost << p.first << ", " << p.second; }
template<class T> istream& operator>> (istream& ist, vector<T>& vs) { for(auto& e: vs) ist >> e; return ist; }

typedef long long ll;
int const inf = INT_MAX / 2;

int sum[11][1001][11][1001];

int main() {
  int H, W, K; cin >> H >> W >> K;
  vector<string> S(H); cin >> S;
  rep(si, H) rep(sj, W) REP(ti, si, H) REP(tj, sj, W) {
    sum[si][sj][ti][tj] =
        (ti ? sum[si][sj][ti - 1][tj] : 0)
      + (tj ? sum[si][sj][ti][tj - 1] : 0)
      - (ti && tj ? sum[si][sj][ti - 1][tj - 1] : 0)
      + (S[ti][tj] == '1');
  }
  int ans = inf;
  rep(S, (1 << H)) {
    vector<int> is;
    rep(i, H) if (S >> i & 1) is.push_back(i);
    is.push_back(H - 1);
    int start_j = 0, cut_count = is.size() - 1;
    bool good = 1;
    rep(last_j, W) {
      bool ok = 1;
      int start_i = 0;
      for (auto last_i : is) {
        ok = ok && sum[start_i][start_j][last_i][last_j] <= K;
        start_i = last_i + 1;
      }
      if (!ok) {
        if (start_j == last_j) { good = 0; break; }
        start_j = last_j;
        cut_count++;
      }
    }
    if (!good) { continue; }
    ans = min(ans, cut_count);
  }
  cout << ans << endl;
}


Measured memory_bytes: 432512
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define E "\n"

using namespace std;
const long long MOD = (long long)1e9 + 7;

int n, cnt[10009];

int main()
{
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> n;
    for (int x = 1; x * x < n; x++) {
        for (int y = 1; y * y < n; y++) {
            for (int z = 1; z * z < n; z++) {
                int tmp = x * x + y * y + z * z;
                tmp += x * y + y * z + x * z;
                if (tmp <= n) cnt[tmp]++;
            }
        }
    }
    for (int i = 1; i <= n; i++) {
        cout << cnt[i] << E;
    }
    //system("pause");
    return 0;
}

Measured memory_bytes: 3520
N = int(input())
H = list(map(int,input().split()))
dp=[0]*N
dp[1] = abs(H[1]-H[0])
for i in range(2,N):
    dp[i] = min(dp[i-1]+abs(H[i]-H[i-1]),dp[i-2]+abs(H[i]-H[i-2]))
print(dp[-1])

Measured memory_bytes: 13980
#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define bit(x) (1L << (x))
using ll = long long;
using namespace std;

int main(){
  int n; cin >> n;
  int t[n], sum = 0;
  REP(i, n){
    cin >> t[i];
    sum += t[i];
  }

  bool f = true;
  REP(i, n){
    if(t[i] >= sum-t[i]) f = false;
  }

  cout << ((f)? "Yes": "No") << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <math.h>
#include <map>
#include <functional>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <typeinfo>
#define PI 3.14159265359
#define INF 99999999;
#define rep(i, n) for(int i=0; i<n; i++)
#define REP(n) rep(i, n)
#define EPS 1e-10
typedef long long ll;
using namespace std;
typedef pair<int, int> P;

double distanceAB(double xa, double ya, double xb, double yb);
void trace(int A[], int N);

/*
class Target
{
public:
	vector <string> draw(int n)
	{

	}
};
*/


int search(int A[], int n, int key)
{
	int i = 0;
	A[n] = key;
	while (A[i] != key) i++;
	return i != n;
}


int main()
{
	int i, n, A[10000+1], q, key, sum = 0;
	
	cin >> n;
	REP(n) cin >> A[i];
	cin >> q;
	REP(q)
	{
		cin >> key;
		if (search(A, n, key)) sum++;
	}
	cout << sum << endl;
	
	return 0;
}


void trace(int A[], int N)
{
	REP(N)
	{
		if (i > 0) cout << " ";
		cout << A[i];
	}
	cout << endl;
}


double distanceAB(double xa, double ya, double xb, double yb)
{
	return sqrt((xb-xa)*(xb-xa) + (yb-ya)*(yb-ya));
}

Measured memory_bytes: 1196
use std::collections::*;
use std::io::*;
use std::*;
// template {{{
macro_rules! get {
    ($($t:tt),*; $n:expr) => {
        {
            let stdin = std::io::stdin();
            let ret = std::io::BufRead::lines(stdin.lock()).take($n).map(|line| {
                let line = line.unwrap();
                let mut it = line.split_whitespace();
                _get!(it; $($t),*)
            }).collect::<Vec<_>>();
            ret
        }
    };
    ($($t:tt),*) => {
        {
            let mut line = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut it = line.split_whitespace();
            _get!(it; $($t),*)
        }
    };
}
macro_rules! _get {
    ($it:ident; [char]) => {
        _get!($it; String).chars().collect::<Vec<_>>()
    };
    ($it:ident; [u8]) => {
        _get!($it; String).bytes().collect::<Vec<_>>()
    };
    ($it:ident; usize1) => {
        $it.next().unwrap().parse::<usize>().unwrap_or_else(|e| panic!("{}", e)) - 1
    };
    ($it:ident; [usize1]) => {
        $it.map(|s| s.parse::<usize>().unwrap_or_else(|e| panic!("{}", e)) - 1).collect::<Vec<_>>()
    };
    ($it:ident; [$t:ty]) => {
        $it.map(|s| s.parse::<$t>().unwrap_or_else(|e| panic!("{}", e))).collect::<Vec<_>>()
    };
    ($it:ident; $t:ty) => {
        $it.next().unwrap().parse::<$t>().unwrap_or_else(|e| panic!("{}", e))
    };
    ($it:ident; $($t:tt),+) => {
        ($(_get!($it; $t)),*)
    };
}
// }}}

fn main() {
    let n = get!(usize);
    let vil = get!(i32,i32,i64;n);
    let mut ans = vec![1 << 60; n + 1];
    let mut horimin = vec![vec![0; n]; 1 << n];
    let mut vertmin = vec![vec![0; n]; 1 << n];
    for i in 0..(1 << n) {
        for j in 0..n {
            horimin[i][j] = vil[j].1.abs();
            vertmin[i][j] = vil[j].0.abs();
            for k in 0..n {
                if i & (1 << k) != 0 {
                    horimin[i][j] = horimin[i][j].min((vil[j].1 - vil[k].1).abs());
                    vertmin[i][j] = vertmin[i][j].min((vil[j].0 - vil[k].0).abs());
                }
            }
        }
    }
    for i in 0..(1 << n) {
        let overs: Vec<_> = (0..n).filter(|x| i as i32 & (1 << x) != 0).collect();
        for j in 0..(1 << overs.len()) {
            let mut hori = i;
            for k in 0..overs.len() {
                if j & (1 << k) != 0 {
                    hori &= !(1 << overs[k]);
                }
            }
            let vert = i & !hori;
            let s: i64 = (0..n)
                .map(|x| horimin[hori][x].min(vertmin[vert][x]) as i64 * vil[x].2)
                .sum();
            ans[overs.len()] = ans[overs.len()].min(s);
        }
    }
    ans.iter().map(|x| println!("{}", x)).count();
}


Measured memory_bytes: 8584
n = gets.chomp.to_i
arr = gets.chomp.split(' ').map(&:to_i)
i = 0
array = []
bs = []
while i < n
  j = i+1
  while j < n
    k = j+1
    while k < n
      a = [arr[i],arr[j],arr[k]]
      b = [i+1,j+1,k+1]
      if arr[i]==arr[j] || arr[j]==arr[k] || arr[k]==arr[i] 
      else
        a.sort!
        if a[0] + a[1] > a[2]  
          array << a
          bs << b
        end
      end
      k += 1
    end
    j += 1
  end
  i += 1
end
p array.size

Measured memory_bytes: 31572
#include <bits/stdc++.h>
#define Roc ios_base::sync_with_stdio(false), cin.tie(NULL)
#define ll long long
#define NMAX 100009

using namespace std;
const int inf = 1e9 + 5;
int v[NMAX][3], pd[NMAX][3], k,n;
int main()
{
    Roc;
    cin >> n ;
    for(int i = 1; i <= n; ++i)
        for(int j = 1 ; j <= 3; ++j)
        cin >> v[i][j];
    for(int i = 1; i <= 3; ++i)
        pd[1][i] = v[1][i];
    for(int i = 2; i <= n; ++i)
    {
        pd[i][1] = v[i][1] + max(pd[i - 1][2] ,pd[i - 1][3]);
        pd[i][2] = v[i][2] + max(pd[i - 1][1] ,pd[i - 1][3]);
        pd[i][3] = v[i][3] + max(pd[i - 1][2] ,pd[i - 1][1]);
    }
    int ans = 0;
    for(int i = 1; i <= 3; ++i)
        ans = max(ans, pd[n][i]);
    cout << ans;
    return 0;
}


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


int main() {
    int h , w ;
    cin >> h >> w ;
    vector<string> S(h) ;
    rep(i,h) cin >> S.at(i) ;
    int dp[h+1][w+1] ;
    fill(dp[0],dp[h+1],1e9) ;
    if( S[0][0] == '#' ) dp[0][0] = 1 ;
    else dp[0][0] = 0 ;
    int a=0;
    rep(i,h){
        rep(j,w){
            if(i+1 == h )a++ ;
            else{
            int new_i = i+1 ;
                if(S[new_i][j] == S[i][j] ) dp[new_i][j] = min(dp[new_i][j],dp[i][j]) ;
                else if(S[new_i][j] == '#' ) dp[new_i][j] = min(dp[new_i][j],dp[i][j]+1) ;
                else dp[new_i][j] = min(dp[new_i][j],dp[i][j]) ;
            }
            if(j+1 == w )a++ ;
            else{
            int new_j = j+1 ;   
                if(S[i][new_j] == S[i][j] ) dp[i][new_j] = min(dp[i][new_j],dp[i][j]) ;
                else if(S[i][new_j] == '#' ) dp[i][new_j] = min(dp[i][new_j],dp[i][j]+1) ;
                else dp[i][new_j] = min(dp[i][new_j],dp[i][j]) ;
            }
            }
        }
    cout << dp[h-1][w-1] << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;


int main(){
  int a,b;
  for(int i=0;i<7;++i){
    cin >> a >> b;
    if(a > b) cout << a-b;
    else cout << b-a;
    cout << endl;
  }
  
  return 0;
}



Measured memory_bytes: 3096
//url:
//problem name: 

#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); ++i)
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Pl = pair<long long,long long>;
using veci = vector<int>;
using vecl = vector<long>;
using vecveci = vector<vector<int>>;
using vecvecl = vector<vector<long long>>;

struct UnionFind {
    vector <ll> par; // 各元の親を表す配列
    vector <ll> siz; // 素集合のサイズを表す配列(1 で初期化)

    // Constructor
    UnionFind(ll sz_): par(sz_), siz(sz_, 1LL) {
        for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
    }
    void init(ll sz_) {
        par.resize(sz_);
        siz.assign(sz_, 1LL);  // resize だとなぜか初期化されなかった
        for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
    }

    // Member Function
    // Find
    ll root(ll x) { // 根の検索
        while (par[x] != x) {
            x = par[x] = par[par[x]]; // x の親の親を x の親とする
        }
        return x;
    }

    // Union(Unite, Merge)
    bool merge(ll x, ll y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        // merge technique（データ構造をマージするテク．小を大にくっつける）
        if (siz[x] < siz[y]) swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }

    bool issame(ll x, ll y) { // 連結判定
        return root(x) == root(y);
    }

    ll size(ll x) { // 素集合のサイズ
        return siz[root(x)];
    }
};

int main() {
    ll N,M;
    cin >> N >> M;
    vector<Pl> res(M);
    vecl ans;

    UnionFind UF(N);
    UF.init(N);
 
    REP(i,M) {
        ll a,b; cin >> a >> b;
        a--;b--;
        res[i] = Pl(a,b);
    }

    ll cur = N*(N-1)/2;

    for(int i = M-1; i >= 0; --i) {
        ans.push_back(cur);
        int a = res[i].first;
        int b = res[i].second;
        if(UF.issame(a,b)) continue;
        cur -= UF.size(a)*UF.size(b);
        UF.merge(a,b);
    }
    for(int i = M-1; i >= 0; --i) cout << ans[i] << endl;
}


Measured memory_bytes: 5364
N=input()

CC=[]
for _ in xrange(N):
    a,b=list(map(int,raw_input().strip().split(' ')))
    CC+=[(b,a)]

CC=sorted(CC)

pre_sum=0
bad=0
for i in xrange(len(CC)):
    b,a=CC[i]
    pre_sum+=a
    if pre_sum>b:
        bad=1

if bad==0:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 55068
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;


public class Main {
	private	static	BufferedReader br = null;

	static {
		br = new BufferedReader(new InputStreamReader(System.in));
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		ArrayList<Integer>	point   = new ArrayList<Integer>();
		double[][]			tresure = new double[1000][2];
		double				angle   = 0.0;
		int					num     = 0;
		int					max     = 0;

		tresure[0][0] = 1.0;
		tresure[0][1] = 1.0;//0.0;
		while ((num = parseNum()) != -1) {
			point.add(num);
			max = Math.max(max, num);
		}

		tresure[1][0] = 1.0;
		tresure[1][1] = 1.0;
		for(int n = 2; n < max; n++) {
			angle = Math.atan2(-tresure[n - 1][1], -tresure[n - 1][0]) / Math.PI * 180.0 + 90.0;
			tresure[n][0] = tresure[n - 1][0] - Math.cos(angle / 180.0 * Math.PI);
			tresure[n][1] = tresure[n - 1][1] - Math.sin(angle / 180.0 * Math.PI);
		}

		for(int n = 0; n < point.size(); n++) {
			int	item = point.get(n);
			System.out.printf("%.2f\n%.2f\n", tresure[item - 1][0], tresure[item - 1][1]);
		}
	}

	private static int parseNum() {
		int		num   = -1;
		String	strIn = null;

		if ((strIn = parseStdin()) != null) {
			num = Integer.parseInt(strIn);
		}
		
		return num;
	}

	private static String parseStdin() {
		String	strNum = null;

		try {
			String line = br.readLine();
			if (line != null) {
				if (!line.isEmpty()) {
					strNum = line;
				}
			}
		}
		catch (IOException e) {}

		return strNum;
	}
}

Measured memory_bytes: 16992