akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <fstream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <cstdlib>
#include <cstdio>
#include <string>
#include <cstring>
#include <cassert>
#include <utility>
#include <iomanip>
#include <chrono>
#include <random>
#include <bitset>

using namespace std;

#define sz(x) (int) x.size()
#define unique(x) x.erase(unique(x.begin(), x.end()), x.end())
#define all(a) a.begin(), a.end()
#define sqr(x) ((x) * (x)) 
#define y1 aksjdaskdjksjfksdjf
#define left kdnvldvoiwejifejg
#define right lkdsjflksdjfdjfk
#define prev asdasfsadjkjsdfjs
#define tm aklsjdasjdasjdkdjjf
#define lcm hddalkwjeidjjhasda
#define random_shuffle asdasdd

int a[10][10];
int n;

int main() { 

  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 3; j++) {
      scanf("%d", &a[i][j]);
    }
  }

  cin >> n;
  while (n--) {
    int x;
    cin >> x;
    for (int i = 0; i < 3; i++) {
      for (int j = 0; j < 3; j++) {
        if (a[i][j] == x) {
          a[i][j] = -1;
        }
      }
    }
  }

  bool has = false;

  for (int i = 0; i < 3; i++) {
    bool ok = true;
    for (int j = 0; j < 3; j++) {
      if (a[i][j] != -1) {
        ok = false;
      }
    }
    has |= ok;
  }

  for (int j = 0; j < 3; j++) {
    bool ok = true;
    for (int i = 0; i < 3; i++) {
      if (a[i][j] != -1) {
        ok = false;
      }
    }
    has |= ok;
  }

  has |= (a[0][0] == -1 && a[1][1] == -1 && a[2][2] == -1);
  has |= (a[0][2] == -1 && a[1][1] == -1 && a[2][0] == -1);

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

  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <cmath>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <map>
using ll = long long;
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)

int n,m,q;
vector<int> a,b,c,d;
int ans;

void dfs(vector<int> w){
    if(w.size()==n+1){
        // 結果を更新
        int cnt = 0;
        rep(i,q){
            if(w[b[i]]-w[a[i]]==c[i]){
                cnt += d[i];
            }
        }
        ans = max(ans,cnt);
        return;
    }
    w.push_back(w.back());
    while(w.back()<=m){
        dfs(w);
        w.back()++;
    }
}
void solve(){

}
int main (){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> n>> m >> q;
    a = b = c = d = vector<int> (q);
    rep(i,q){
        cin >> a[i] >> b[i] >> c[i] >> d[i];
    }
    ans = 0;
    vector<int> w(1,1);
    dfs(w);

    cout << ans;
    return 0;
}

    
    


Measured memory_bytes: 3632
n,k = map(int, input().split())
p = list(map(int, input().split()))

mxidx = 0
mx = 0
tot=0
for i in range(k):
    tot+=p[i]
mx=tot
for i in range(k,n):
    tot+=p[i]-p[i-k]
    if tot>mx:
        mxidx=i-k+1
        mx=tot

ans=0
for i in range(mxidx, mxidx+k):
    ans+=(1+p[i])/2

print(ans)




Measured memory_bytes: 71792
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
const lint mod = 998244353;
#define all(x) (x).begin(), (x).end()
#define bitcount(n) __builtin_popcountl((lint)(n))
#define fcout cout << fixed << setprecision(15)
#define highest(x) (63 - __builtin_clzl(x))
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T = string, class U = char>int character_count(T text, U character){ int ans = 0; for(U i: text){ ans += (i == character); } return ans; }
lint power(lint base, lint exponent, lint module){ if(exponent % 2){ return power(base, exponent - 1, module) * base % module; }else if(exponent){ lint root_ans = power(base, exponent / 2, module); return root_ans * root_ans % module; }else{ return 1; }}
struct position{ int y, x; }; position mv[4] = {{0, -1}, {1, 0}, {0, 1}, {-1, 0}}; // double euclidean(position first, position second){ return sqrt((second.x - first.x) * (second.x - first.x) + (second.y - first.y) * (second.y - first.y)); }
template<class T, class U> string to_string(pair<T, U> x){ return to_string(x.first) + "," + to_string(x.second); } string to_string(string x){ return x; }
template<class itr> void array_output(itr start, itr goal){ string ans; for(auto i = start; i != goal; i++) ans += to_string(*i) + " "; if(!ans.empty()) ans.pop_back(); cout << ans << endl; }
template<class itr> void cins(itr first, itr last){ for(auto i = first; i != last; i++){ cin >> (*i); } }
template<class T> T gcd_calc(T a, T b){ if(b){ return gcd_calc(b, a % b); }else{ return a; }}
template<class T> T gcd(T a, T b){ if(a < b) swap(a, b); return gcd_calc(a, b); }
template<class T> T lcm(T a, T b){ return a / gcd(a, b) * b; }
struct combination{ vector<lint> fact, inv; combination(int sz) : fact(sz + 1), inv(sz + 1){ fact[0] = 1; for(int i = 1; i <= sz; i++){ fact[i] = fact[i - 1] * i % mod; } inv[sz] = power(fact[sz], mod - 2, mod); for(int i = sz - 1; i >= 0; i--){ inv[i] = inv[i + 1] * (i + 1) % mod; } } lint C(int p, int q) const{ if(q < 0 || p < q) return 0; return (fact[p] * inv[q] % mod * inv[p - q] % mod); } };
template<class itr> bool next_sequence(itr first, itr last, int max_bound){ itr now = last; while(now != first){ now--; (*now)++; if((*now) == max_bound){ (*now) = 0; }else{ return true; } } return false; }
inline int at(int x, int k){ return (x >> k) & 1; }
random_device rnd;

string day[7] =  {"Sunny", "Cloudy", "Rainy"};

int main(){
    int X;
    cin >> X;
    YES(X == 7 || X == 5 || X == 3);
}


Measured memory_bytes: 256
#!/usr/bin/env python3

import re

a = input()

preans1 = 0
preans2 = 1000000
if(a[0] == "0"):
    for i in range(len(a)):
        if(i%2 == 0):
            if(a[i] != "0"):
                preans1 += 1
        elif(i%2 == 1):
            if(a[i] != "1"):
                preans1 += 1
    if(a[-1] == "1"):
        preans2 = 0
        for i in range(2,len(a)+1):
            if(i%2 == 0):
                if(a[-i] != "0"):
                    preans2 += 1
            elif(i%2 == 1):
                if(a[-i] != "1"):
                    preans2 += 1
elif(a[0] == "1"):
    for i in range(len(a)):
        if(i%2 == 1):
            if(a[i] != "0"):
                preans1 += 1
        elif(i%2 == 0):
            if(a[i] != "1"):
                preans1 += 1
    if(a[-1] == "0"):
        preans2 = 0
        for i in range(2,len(a)+1):
            if(i%2 == 0):
                if(a[-i] != "1"):
                    preans2 += 1
            elif(i%2 == 1):
                if(a[-i] != "0"):
                    preans2 += 1
print(min(preans1,preans2))

Measured memory_bytes: 3316
inp = list(map(int,input().split()))
a =inp[0]
b = inp[1]
c = inp[2]
if (c - a- b > 0):
    if (0< a**2 +b**2 + c**2- 2*(a*b + b*c + a*c)):
        print("Yes")
    else:
        print("No")
else:
    print("No")

Measured memory_bytes: 3060
#include <iostream>
#include <vector>

using namespace std;

int main()
{
    long long X, K, D;
    cin >> X >> K >> D;

    X = abs(X);

    long long K_need = X / D;

    long long ans1 = abs(D * K_need - X);
    long long ans2 = abs(D * (K_need + 1) - X);
    long long ans;

    if(K < K_need){
        ans = abs(D * K - X);
    }else if((K_need + K)%2 == 0){
        ans = ans1;
    }else{
        ans = ans2;
    }

    cout << ans << endl;
}

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

typedef vector<int> veci;
typedef pair<int, int> pii;
typedef vector<pii> vecii;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef vector<ll> vecl;
typedef vector<pll> vecll;
#define EPS (1e-9)
#define MOD (1e9 + 7)
#define fi first
#define se second
#define endl '\n'

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

    vector<int> vh(n);
    for (int i=0; i<n; ++i) {
        cin >> vh[i];
    }
    sort(vh.rbegin(), vh.rend());

    ll sum = 0;
    for (int i=k; i<n; ++i) {
        sum += vh[i];
    }

    cout << sum << endl;
}

int main(int argc, char* argv[]) {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
#ifdef LOCAL_TEST
    (void)argc;
    const string strpath = string(argv[0]) + string("-test.in");
    freopen(strpath.c_str(), "r", stdin);
    int tcs;
    cin >> tcs;
    while (tcs-- > 0)
#endif
        solve();
}


Measured memory_bytes: 1024
// J'aime
// Chemise Blanche

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

#define int long long

#define ii pair<int,int>
#define fi first
#define sc second

#define all(x) (x).begin(),(x).end()
#define dbg(x) cerr << __LINE__ << " > " << #x << " = " << (x) << endl

void MAIN() {
  vector<int> a = {0, 300000, 200000, 100000};
  int x, y;
  cin >> x >> y;
  if (x > 3) x = 0;
  if (y > 3) y = 0;
  cout << a[x] + a[y] + (x * y == 1) * 400000 << '\n';
}

signed main() {
#ifdef _DEBUG
  // freopen("in" , "r", stdin );
  // freopen("out", "w", stdout);
#endif
  ios::sync_with_stdio(0); cin.tie(0);
  int T = 1;
  // cin >> T;
  while (T--) MAIN();
}


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

int main() {
    int a, p;
    cin >> a >> p;
    p += a*3;
    cout << p/2 << endl;
    return 0;
}


Measured memory_bytes: 3560
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
ans=0
for i in range(n):
    ans+=b[a[i]-1]
    if i>=1:
        if a[i]==(a[i-1]+1):
            ans+=c[a[i-1]-1]

print(ans)

Measured memory_bytes: 3064
// import chie template :) {{{
import std.stdio, std.algorithm, std.array, std.string, std.math, std.conv,
    std.range, std.container, std.bigint, std.ascii, std.typecons;

// }}}
// nep.scanner {{{
class Scanner
{
    import std.stdio : File, stdin;
    import std.conv : to;
    import std.array : split;
    import std.string : chomp;

    private File file;
    private char[][] str;
    private size_t idx;

    this(File file = stdin)
    {
        this.file = file;
        this.idx = 0;
    }

    private char[] next()
    {
        if (idx < str.length)
        {
            return str[idx++];
        }

        char[] s;
        while (s.length == 0)
        {
            s = file.readln.chomp.to!(char[]);
        }

        str = s.split;
        idx = 0;

        return str[idx++];
    }

    T next(T)()
    {
        return next.to!(T);
    }

    T[] nextArray(T)(size_t len)
    {
        T[] ret = new T[len];

        foreach (ref c; ret)
        {
            c = next!(T);
        }

        return ret;
    }

    void scan()()
    {
    }

    void scan(T, S...)(ref T x, ref S args)
    {
        x = next!(T);
        scan(args);
    }
}
// }}}

void main()
{
    auto cin = new Scanner;
    int n, m;
    cin.scan(n, m);
    writeln((n - 1) * (m - 1));
}


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

int32_t main() {

	int t; cin >> t;

	if(t >= 400 && t < 600)
		cout << 8 << endl;
	else if(t >= 600 && t < 800)
		cout << 7 << endl;
	else if(t >= 800 && t < 1000)
		cout << 6 << endl;
	else if(t >= 1000 && t < 1200)
		cout << 5 << endl;
	else if(t >= 1200 && t < 1400)
		cout << 4 << endl;
	else if(t >= 1400 && t < 1600)
		cout << 3 << endl;
	else if(t >= 1600 && t < 1800)
		cout << 2 << endl;
	else if(t >= 1800 && t < 2000)
		cout << 1 << endl;
	
	
	
}

Measured memory_bytes: 3188
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


class data
{
    public string card;
    public int number;

};
namespace ConsoleApplication3
{
    class Program
    {
        static int count = 0;
        static void insertionSort(ref List<int> input, int g)
        {
            int v,j;
            for (int i = g ; i < input.Count; i++)
            {
                v = input[i];
                j = i - g;
                while (j >= 0 & input[j] > v)
                {
                    input[j + g] = input[j];
                    j = j - g;
                    count++;
                    if (j < 0)
                        break;
  
                }
                input[j + g] = v;

            }


        }

        static void Main(string[] args)
        {
            string temp;
            int number;
            var input = new List<int>();
            var g = new List<int>();


            temp = Console.ReadLine();
            number = int.Parse(temp);
            for (int i = 0; i < number; i++)
            {
                temp = Console.ReadLine();
                input.Add(int.Parse(temp));
            }
            int h = 0;
            while (h <= number / 9)
            {
                h = 3 * h + 1;
                g.Add(h);
            }

            for(int i = g.Count -1; i>=0; i--)
            {
                insertionSort(ref input, g[i]);
            }
            Console.WriteLine("{0}", g.Count);
            for(int i=g.Count -1; i>=1;i--)
                Console.Write("{0} ",g[i]);
            Console.WriteLine("{0}", g[0]);
            Console.WriteLine("{0}", count);
            for (int i = 0; i < input.Count; i++)
                Console.WriteLine("{0}", input[i]);

        }
    }
}



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

vector<int> ans;



int main() {
	int n;
	cin >> n;
	vector<int> b(n);
	for (int i = 0; i < n; i++) {
		cin >> b[i];
		b[i]--;
	}

	for (int i = 0; i < n; i++) {
		int same = -1;
		for (int i = b.size() - 1; i >= 0; i--) {
			if (i == b[i]) {
				same = i;
				break;
			}
		}
		if (same == -1) {
			cout << -1 << endl;
			return 0;
		}
		ans.push_back(same);
		b.erase(b.begin() + same);
	}

	reverse(ans.begin(), ans.end());

	for (int i = 0; i < n; i++) {
		cout << ans[i]  + 1 << endl;
	}	
	
	return 0;
}


Measured memory_bytes: 3612
#include<iostream>
#include<vector>
#include<cmath>
#include<map>
#include<queue>
#include<stack>
#include<algorithm>
#include<functional>

typedef unsigned long long LL;

using namespace std;

int main() {
	int N;
	cin >> N;
	vector<int>a;
	for (int i = 0; i < N; i++) {
		int tmp;
		cin >> tmp;
		a.push_back(tmp);
	}
	sort(a.begin(), a.end());
	bool isPossible;
	if (!(a[a.size() - 1] - a[0] == 0 || a[a.size() - 1] - a[0] == 1)) {
		isPossible = false;
	}
	else if(a[a.size() - 1] - a[0] == 0){
		int number = a[0];
		if (N == number + 1) {
			isPossible = true;
		}
		else if (number * 2 > N) {
			isPossible = false;
		}
		else {
			isPossible = true;
		}
	}
	else {
		int miniColor = a[0];
		int lonelyMember = 0;
		for (int i = 1; i < N; i++) {
			if (a[i] != miniColor) {
				lonelyMember = i;
				break;
			}
		}
		int tmp = N;
		tmp -= lonelyMember;
		if (miniColor - (lonelyMember - 1) <= 0 || (miniColor-(lonelyMember-1)) * 2  > tmp) {
			isPossible = false;
		}
		else {
			isPossible = true;
		}

	}
	if (isPossible) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}

Measured memory_bytes: 892
using System;
using System.Collections.Generic;

class B
{
	static void Main()
	{
		var s = int.Parse(Console.ReadLine());
		var h = new HashSet<int> { s };
		for (int t = s, v, i = 2; ; i++, t = v) if (!h.Add(v = t % 2 == 0 ? t / 2 : 3 * t + 1)) { Console.WriteLine(i); return; }
	}
}


Measured memory_bytes: 13280
sx,sy,tx,ty=gets.split.map &:to_i
puts "U"*(ty-sy) + "R"*(tx-sx) + "D"*(ty-sy) + "L"*(tx-sx+1) + "U"*(ty-sy+1) + "R"*(tx-sx+1) + "D" + "R" + "D"*(ty-sy+1) + "L"*(tx-sx+1) + "U"


Measured memory_bytes: 1916
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	vector<string> name;
	vector<int>time;
	for(int i = 0 ; i<n;i++)
	{
		string NAME;
		int a;
		cin>>NAME>>a;
		name.push_back(NAME);
		time.push_back(a);
	}
	string cnt_after;
	cin>>cnt_after;
	int cnt = 0;
	bool done = false;
	for(int i = 0; i<n;i++)
	{
		string at = name[i];
		if(done)
			cnt += time[i];
		else{
			if(at == cnt_after)
				done = true;
			else
				continue;
		}
	}
	cout<<cnt<<endl;
	return 0;
	
}

Measured memory_bytes: 256
# coding:utf-8

import sys

INF = float('inf')
MOD = 10 ** 9 + 7

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 LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()


h, w, d = LI()
coord = [0] * (h * w)
for y in range(h):
    for x, n in enumerate(LI_()):
        coord[n] = (y, x)

C = [[0] for _ in range(d)]
for i in range(d, h * w):
    diff = abs(coord[i][0] - coord[i - d][0]) + abs(coord[i][1] - coord[i - d][1])
    C[i % d].append(C[i % d][-1] + diff)

q = II()
for _ in range(q):
    l, r = LI_()
    n = l % d
    print(C[n][r // d] - C[n][l // d])


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

int main() {
  int a,b,x;

  // 変数aで入力を受け取る
  cin >> a >> b;
  x = a * b;
  if(x % 2 == 0) {
     cout << "Even" << endl;
  } else {
    cout << "Odd" << endl;
  }
}


Measured memory_bytes: 256
#!/usr/bin/env ruby

size = nil
input = []
while line = gets
  if size == nil
    size = line
  else
    input << line.chomp!.to_i
  end
end
maxv = -1000000000000000000
minv = input[0]
1.upto(input.size-1) do |j|
  maxv = input[j] - minv if maxv < input[j]-minv
  minv = input[j]  if minv > input[j]

end

p maxv

Measured memory_bytes: 10512
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif
using namespace std;


typedef long long ll;
typedef pair<int,int> Pint;
typedef pair<ll, ll> P;
//typedef pair<int, pair<int, int>> P;
//typedef tuple<int,int,int> T;
ll INFL = 1000000000000000010;//10^18 = 2^60
int INF = 2000000000;//10^9
ll MOD  = 1000000007;
vector<int> dy = {0,0,1,-1};
vector<int> dx = {1,-1,0,0};

int N, K;
vector<int> h(100010);
vector<int> dp(100010);
int main(void){
    cin >> N >> K;
		for(int i = 1; i <= N; i++) cin >> h[i];
		dp[0] = INF;
		dp[1] = 0;
		for(int i = 2; i <= N; i++){
			for(int j = 1; j <= K; j++){
				if(j == 1){
					dp[i] = dp[i-1] + abs(h[i] - h[i-1]);
				}else if(i-j>=0){dp[i] = min(dp[i], dp[i-j] + abs(h[i] - h[i-j]));

				}
			}
		}
		cout << dp[N] << endl;

}


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

using namespace std;

#define INF (1 << 30)
#define EPS 1e-10
#define MOD 1000000007

#define rep(i, n) FOR(i, 0, n)
#define FOR(i, x, n) for (int i = (x); i < (n); ++i)
#define all(v) (v).begin(), (v).end()

using ll = long long;

template<class T> void chmax(T& a, T b){ if (a < b) { a = b; } }
template<class T> void chmin(T& a, T b){ if (a > b) { a = b; } }

int main() {
    int x, n, p, a[100] = { 2 };
    cin >> x >> n;
    while (n--) {
        cin >> p;
        if (p - x >= 0) {
            a[p - x] += 1;
        }
        else {
            a[x - p] += 2;
        }
    }
    for (int i = 0;;++i) {
        if (a[i] != 3) {
            if (a[i] == 2) {
                x += i;
            }
            else {
                x -= i;
            }
            cout << x << endl;
            break;
        }
    }

    return 0;
}

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

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

typedef long long ll;
using namespace std;
int mod = 1000000007;

bool valid(int l, int r, int x){
    return (l <= x) & (x < r);
}

int main(void){
    int H, W; cin >> H >> W;
    int A[H][W], B[H][W];
    rep(i, H) rep(j, W) cin >> A[i][j];
    rep(i, H) rep(j, W) cin >> B[i][j];
    int size_3d = 80*(H+W);
    bool dp[H][W][size_3d];
    rep(i, H) rep(j, W) rep(k, size_3d) dp[i][j][k] = false;
    dp[0][0][abs(A[0][0]-B[0][0])] = true;

    for(int i = 0; i < H-1; i++){
        int val = abs(A[i+1][0]-B[i+1][0]);
        rep(k, size_3d){
            if(dp[i][0][k]){
                // -k+val, k-val, k+val
                int v1 = val-k;
                int v2 = k-val;
                int v3 = k+val;
                if(valid(0, size_3d, v1)) dp[i+1][0][v1] = true;
                if(valid(0, size_3d, v2)) dp[i+1][0][v2] = true;
                if(valid(0, size_3d, v3)) dp[i+1][0][v3] = true;
            }
        }
    }
    for(int j = 0; j < W-1; j++){
        int val = abs(A[0][j+1]-B[0][j+1]);
        rep(k, size_3d){
            if(dp[0][j][k]){
                int v1 = val-k;
                int v2 = k-val;
                int v3 = k+val;
                if(valid(0, size_3d, v1)) dp[0][j+1][v1] = true;
                if(valid(0, size_3d, v2)) dp[0][j+1][v2] = true;
                if(valid(0, size_3d, v3)) dp[0][j+1][v3] = true;
            }
        }
    }
    for(int i = 1; i < H; i++){
        for(int j = 1; j < W; j++){
            int val = abs(A[i][j]-B[i][j]);
            //dp[i-1][j]について
            rep(k, size_3d){
                if(dp[i-1][j][k]){
                    int v1 = val-k;
                    int v2 = k-val;
                    int v3 = k+val;
                    if(valid(0, size_3d, v1)) dp[i][j][v1] = true;
                    if(valid(0, size_3d, v2)) dp[i][j][v2] = true;
                    if(valid(0, size_3d, v3)) dp[i][j][v3] = true;
                }
            }
            //dp[i][j-1]について
            rep(k, size_3d){
                 if(dp[i][j-1][k]){
                    int v1 = val-k;
                    int v2 = k-val;
                    int v3 = k+val;
                    if(valid(0, size_3d, v1)) dp[i][j][v1] = true;
                    if(valid(0, size_3d, v2)) dp[i][j][v2] = true;
                    if(valid(0, size_3d, v3)) dp[i][j][v3] = true;
                }
            }
        }
    }

/*
    rep(k, 10) cout << dp[0][0][k] << " "; cout << endl;
    rep(k, 10) cout << dp[0][1][k] << " "; cout << endl;
    rep(k, 10) cout << dp[0][2][k] << " "; cout << endl;
    rep(k, 10) cout << dp[1][0][k] << " "; cout << endl;
    rep(k, 10) cout << dp[1][1][k] << " "; cout << endl;
    rep(k, 10) cout << dp[1][2][k] << " "; cout << endl;
*/
    rep(k, size_3d){
        if(dp[H-1][W-1][k]){
            cout << k << endl;
            break;
        }
    }
    return 0;
}

Measured memory_bytes: 80256
#include <iostream>
#include <cstdio>
#include <algorithm>

using namespace std;

typedef long long ll;

int A[200000];

int main()
{
  int n;
  int b;
  ll sum = 0;
  cin >> n;

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

  sort(A,A+n);
  b = ( A[(n-1)/2]);

  for ( int i = 0; i < n; ++i ) {
    sum += abs(A[i]-b);
  }

  cout << sum << endl;
}


Measured memory_bytes: 1024
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ld long double
#define al(a) (a).begin(),(a).end()
#define mk make_pair
#define check cout<<"?"<<endl;

ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

int main(){
    string ans="second";
    int n; cin>>n;
    rep(i,n){
        int a; cin>>a;
        if(a%2) ans="first";
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		int n = stdIn.nextInt();
		for(int i = 0; i < n; i++) {
			int y = stdIn.nextInt();
			int m = stdIn.nextInt();
			int d = stdIn.nextInt();
			int c = 0;
			while(true) {
				if(y == 1000 && m == 1 && d == 1) {
					break;
				}
				d++;
				c++;
				if(y % 3 == 0) {
					if(d > 20) {
						m++;
						d = 1;
						if(m > 10) {
							m = 1;
							y++;
						}
					}
				}
				else {
					if(m %2 == 0) {
						if(d > 19) {
							m++;
							d = 1;
							if(m > 10) {
								m = 1;
								y++;
							}
						}
					}
					else {
						if(d > 20) {
							m++;
							d = 1;
							if(m > 10) {
								m = 1;
								y++;
							}
						}
					}
				}
			}
			System.out.println(c);
		}
	}

}

Measured memory_bytes: 20040
import heapq
N,M=map(int,input().split())
A=list(map(lambda x: -int(x),input().split()))
heapq.heapify(A)
for m in range(M):
    t = heapq.heappop(A)
    t = (-t)//2
    heapq.heappush(A,-t)
print(-sum(A))


Measured memory_bytes: 72440
#include<iostream>
using namespace std;
int main(){
	string s;
	int n;
	cin>>n>>s;
	if(n%2!=0){
		cout<<"No";
		return 0;
	}
	for(int i=1;i<=n/2;i++){
		if(s[i-1]!=s[i+n/2-1]){
			cout<<"No";
			return 0;
		}
	}
	cout<<"Yes";
	return 0;
}

Measured memory_bytes: 256
package main

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

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

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

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

// 再帰で書くのが思いつかずループで書いてバグ多発
// 結局、写経（考えてたのとほぼ同じだがすきっりしてる
// といっても複雑）
func rec(N, X int, t, p []int) int {
	if N == 0 {
		if X == 1 {
			return 1
		}
		return 0
	}
	if X == 1 {
		return 0
	} else if X <= t[N-1]+1 {
		return rec(N-1, X-1, t, p)
	} else if X == t[N-1]+2 {
		return p[N-1] + 1
	} else if X <= t[N-1]*2+2 {
		return rec(N-1, X-(t[N-1]+2), t, p) + p[N-1] + 1
	}
	return p[N-1]*2 + 1
}

func main() {
	sc.Split(bufio.ScanWords)

	N, X := getInt(), getInt()

	p := make([]int, 51)
	t := make([]int, 51)

	p[0] = 1
	t[0] = 1

	for i := 1; i <= N; i++ {
		t[i] = t[i-1]*2 + 3
		p[i] = p[i-1]*2 + 1
	}

	ans := rec(N, X, t, p)
	out(ans)
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using pint = pair<int, int>;
using ll = long long;
using pll = pair<ll, ll>;
#define FOR(i, begin, end) for (int i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end) for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define VREP(s, ite) for (auto ite = s.begin(); ite != s.end(); ++ite)
#define FI first
#define SE second
//#define endl "\n"
#define ciosup  \
    cin.tie(0); \
    ios::sync_with_stdio(false);
#define eb emplace_back
#define vint vector<int>
constexpr ll INF = 1e9 + 7;
constexpr ll MOD = 1e9 + 7;
template <typename T>
void vecin(vector<T> &v, int n = 0)
{
    if (n == 0)
        n = v.size();
    for (int i = 0; i < n; ++i)
    {
        cin >> v[i];
    }
}
template <typename T>
void vecout(vector<T> &v, int n = 0)
{
    if (n == 0)
        n = v.size();
    for (int i = 0; i < n - 1; ++i)
    {
        cout << v[i] << " ";
    }
    cout << v[n - 1] << endl;
}

ll extgcd(ll a, ll b, ll &x, ll &y)
{ //extended Euclidean algorithm, used for modular multiplicative inverse
    ll d = a;
    if (b != 0)
    {
        d = extgcd(b, a % b, y, x);
        y -= (a / b) * x;
    }
    else
    {
        x = 1;
        y = 0;
    }
    return d; //return gcd(a,b)
}

ll mod_inv(ll a, ll m = MOD)
{ //return inv(a) mod m, ax+my=gcd(a,m)=1, m is prime int, ax-1=mq equiv. ax-mq=1
    ll x, y;
    extgcd(a, m, x, y);
    return (m + x % m) % m; //From (possibly) negative x to positive x
}

vector<ll> fact, invfact;
void calc_fact(int n, ll m = MOD)
{ //Calculate factorial up to n
    fact.resize(n + 1);
    invfact.resize(n + 1);
    fact[0] = invfact[0] = 1;
    REP(i, n)
    {
        fact[i + 1] = fact[i] * (i + 1) % m;
        invfact[i + 1] = invfact[i] * mod_inv(i + 1) % m;
    }
}
ll perm(int n, int k, ll m = MOD)
{
    if (n < 0 || k < 0 || k > n)
        return 0;
    return fact[n] * invfact[n - k] % m;
}
ll comb(int n, int k, ll m = MOD)
{
    if (n < 0 || k < 0 || k > n)
        return 0;
    return (fact[n] * invfact[n - k] % m) * invfact[k] % m;
}

int main()
{
    ciosup;
    int n;
    cin >> n;
    vint a(n + 1);
    vecin(a);
    calc_fact(n + 1);
    map<int, int> ma;
    int fi, sec;
    REP(i, n + 1)
    {
        if (ma.find(a[i]) == ma.end()){
            ma[a[i]] = i;
        }else{
            fi = ma[a[i]];
            sec = i;
        }
    }
    int le = (n - sec) + fi;
    FOR(i, 1, n + 2)
    {
        if (i == 1){
            cout << n << endl;
        }else{
            ll ans = comb(n + 1, i);
            ans = (ans + MOD - comb(le, i - 1)) % MOD;
            cout << ans << endl;
        }
    }
}

Measured memory_bytes: 7936
// Prime Number:
// int w[10100];
// for(i=2;i<=n+1;i++){
//         for(j=i+i;j<=n+1;j+=i){
//             w[j] = 1;
//         }
//    }
 
//  int x='a';
//  char p=65;
//   a[i]=i+'a';
 
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);
 
//    ios_base::sync_with_stdio(false);
//    cin.tie(nullptr);
#include<bits/stdc++.h>
#include<cmath>
using namespace std;
 
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef set<int> si;
typedef set<ll> sl;
#define forn(i, n) for(long long int i = 0; i < (long long int)(n); i++)
#define ford(i, n) for(long long int i = (long long int)(n) - 1; i >= 0; i--)
#define fore(i, a, n) for(long long int i = (long long int)(a); i <(long long int)(n); i++)
#define endl '\n'
#define pb push_back
#define po pop_back
#define mx (int)1e10
#define mn (int)-1e9
#define sqr(x) ((x)*(x))
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define watch(x) cout<<x
int main()
{
   
   string s;
   cin>>s;
   if(s[0]=='R' and s[1]=='R' and s[2]=='R')
   cout<<3;
   else if((s[0]=='R' and s[1]=='R' and s[2]=='S') or (s[0]=='S' and s[1]=='R' and s[2]=='R'))
   cout<<2;
   else if(s[0]=='S' and s[1]=='S' and s[2]=='S')
   cout<<0;
   else
   cout<<1;
   
   return 0;
   
     
}


Measured memory_bytes: 3620
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		sc.useDelimiter("");
		int s1,s2,s3;
		s1 = sc.nextInt();
		s2 = sc.nextInt();
		s3 = sc.nextInt();

		int count=0;
		if(s1 ==1 )
			count++;
		if(s2 ==1)
			count++;
		if(s3 == 1)
			count++;
		System.out.println(count);
		
	sc.close();
	}

}


Measured memory_bytes: 22740
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>

#include <algorithm>
#include <bitset>
#include <complex>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#include <cassert>
#include <functional>

typedef long long ll;
using namespace std;

#ifndef LOCAL
#define debug(x) ;
#else
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;

template<typename T1, typename T2>
ostream &operator<<(ostream &out, const pair<T1, T2> &p) {
  out << "{" << p.first << ", " << p.second << "}";
  return out;
}

template<typename T>
ostream &operator<<(ostream &out, const vector<T> &v) {
  out << '{';
  for (const T &item : v) out << item << ", ";
  out << "\b\b}";
  return out;
}
#endif

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 200010


int main() {
  int N, K, p[SIZE];

  scanf("%d%d", &N, &K);

  for (int i=0; i<N; i++) {
    scanf("%d", p+i);
  }

  double ans = 0;

  double sum = 0;

  for (int i=0; i<N; i++) {
    sum += (p[i] + 1) / 2.0;
    if (i >= K) sum -= (p[i-K] + 1) / 2.0;

    ans = max(ans, sum);
  }

  printf("%.10lf\n", ans);

  return 0;
}


Measured memory_bytes: 1024
#include <vector>
#include <iostream>

int main() {
    int n;

    while (std::cin >> n) {
        std::vector<int> a(2 * n - 1);
        for (auto& x : a) {
            std::cin >> x;
        }

        int left = 1, right = n * 2 - 1, answer = 1;
        while (left <= right) {
            int mid = (left + right) / 2;

            std::vector<bool> v(2 * n - 1);
            for (int i = 0; i < 2 * n - 1; i++) {
                v[i] = a[i] >= mid;
            }

            bool verdict = v[0];
            for (int i = 0; i <= n - 2; i++) {
                if (v[n - 1 - i] == v[n - 2 - i]) {
                    verdict = v[n - 1 - i]; break;
                }
                if (v[n - 1 + i] == v[n + i]) {
                    verdict = v[n - 1 + i]; break;
                }
            }

            if (verdict) {
                answer = mid;
                left = mid + 1;
            } else {
                right = mid - 1;
            }
        }

        std::cout << answer << '\n';
    }
    
    return 0;
}


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

using namespace std;

int aabs(int aa,int b){
    if(aa>b)return aa-b;
    else return b-aa;
}

int main()
{
    int nn[1005]={0},i,j,k,n,mmin=1000010,mmax=0,a[1005],cur;
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d",&a[i]);
        if(mmin>a[i])mmin=a[i];
        if(mmax<a[i])mmax=a[i];
    }
    //for(i=1;i<=n;i++){
        printf("%d\n",mmax-mmin);
    //}
    return 0;
}


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

using namespace std;

int main(int argc, char *argv[])
{
  string A;
  int count;
  int s = 0, e = 0;

  cin >> A;

  for(int i = 0; i < (int)A.size(); ++i){
    char ch = A[i];
    if(A[i] == 'A'){
      s = i;
      break;
    }
  }

  for(int i = s; i < (int)A.size(); ++i){
    char ch = A[i];
    if(A[i] == 'Z'){
      e = i;
    }
  }

  
  cout << e - s + 1<< endl;
  
  return 0;
}


Measured memory_bytes: 640
input_formula = gets.split(" ").map{|item|
    case item
    when "+", "-", "*"
        item
    else
        item.to_i 
    end
}

stack_array = []

input_formula.each_with_index do |item, index|
   if item.class == Integer
       stack_array.push(item)
       
   else
       case item
       when "+"
            temp_result = stack_array[-2] + stack_array[-1]
       when "-"
           temp_result = stack_array[-2] - stack_array[-1]
       when "*"
           temp_result = stack_array[-2] * stack_array[-1]
       end
       stack_array.slice!(-2, 2)
       stack_array.push(temp_result)
       
   end
end

puts stack_array.join.to_i




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

int main() {
	string s; cin >> s;
	string dic[] = { "maerd", "remaerd" ,"esare", "resare" };
	reverse(s.begin(), s.end());
	for (int i = 0; i < s.size(); i++) {
		bool no = true;
		for (int j = 0; j < 4; j++) {
			if (i + dic[j].size() - 1 < s.size() && s.substr(i, dic[j].size()) == dic[j])i += dic[j].size() - 1, no = false;
		}
		if (no) { cout << "NO" << endl; return 0; }
	}
	cout << "YES" << endl;

	return 0;
}

Measured memory_bytes: 512
def examA():
    N = I()
    ans = 0
    print(ans)
    return

def examB():
    ans = 0
    print(ans)
    return

def examC():
    ans = 0
    print(ans)
    return

def examD():
    ans = 0
    print(ans)
    return

def examE():
    N = I()
    node = N*(N-1)//2
    V = [[]for _ in range(node)]
    D = [[0]*N for _ in range(N)]
    cur = 0
    for i in range(N):
        for j in range(i+1,N):
            D[i][j] = cur
            D[j][i] = cur
            cur += 1
    #A = [LI() for _ in range(N)]
    for i in range(N):
        a = LI()
        for j in range(N-2):
            fr = D[i][a[j]-1]
            to = D[i][a[j+1]-1]
            #print(fr,to)
            V[fr].append(to)

    visited = [False] * node
    calculated = [False] * node
    dp = [1] * node
    # https://mhiro216.hatenablog.com/entry/2019/09/08/142414
    def dfs(v):
        if visited[v]:
            if not calculated[v]:
                return -1  # 計算が終わっていない頂点を2度訪れるのはループがあるということ
            return dp[v]
        visited[v] = True
        for u in V[v]:  # 全ての辺をなめる
            res = dfs(u)
            if res == -1: return -1  # ループがあれば-1を返す
            elif res+1>dp[v]:
                dp[v] = res + 1
        calculated[v] = True
        return dp[v]

    ans = 0
    for i in range(node):
        res = dfs(i)
        ans = max(ans,res)
        if res == -1:
            print('-1')  # ループがあれば-1を返す（問題文の指示）
            return
    print(ans)
    return

def examF():
    ans = 0
    print(ans)
    return

import sys,copy,bisect,itertools,heapq,math,random
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet,_ep
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
_ep = 10**(-12)
alphabet = [chr(ord('a') + i) for i in range(26)]

sys.setrecursionlimit(10**6)

if __name__ == '__main__':
    examE()

"""

"""

Measured memory_bytes: 115428
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> pint;

int main()
{
    int N,M; cin>>N>>M;
    vector<pint> v(N);
    for(int i=0;i<N;i++){
        int a,b; cin>>a>>b;
        v[i]={a,b};
    }
    sort(v.begin(),v.end());

    priority_queue<int> Q;
    int ans=0,cur=0;
    for(int cost=1;cost<=M;cost++){
        while(cur<N and v[cur].first<=cost){
            Q.push(v[cur].second);
            cur++;
        }
        if(!Q.empty()){
            ans+=Q.top(); Q.pop();
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1660
import collections

N = int(input())
S = input()

m = 0
index = 0
for i in range(N):
    a = set(S[:i])
    b = set(S[i:])
    d = 0
    for c in a:
        if c in b:
            d += 1
    if d > m:
        m = d
        index = i
print(m)

Measured memory_bytes: 3316
import java.util.Scanner;

public class Main
{
    public static void main(String[] args) 
    {
        Scanner scanner = new Scanner(System.in);
        
        int a = scanner.nextInt();
        int b = scanner.nextInt();
        
        if (a<b) {
        System.out.println("a < b");
        }
        
        if (a>b) {
        System.out.println("a > b");
        }
        
        if (a==b) {
        System.out.println("a == b");
        }
        return;
    }
}


Measured memory_bytes: 26376
#include<iostream>
#include<cstdio>
using namespace std;
int a[1001];
int t[1001];
void mergesort(int l,int r){
//	printf("mergesort[%d, %d]\n",l,r);
	if(l==r) return;
	int mid=(l+r)/2;
	
	mergesort(l,mid);
	mergesort(mid+1,r);
	
	int p=l,q=mid+1,i=l;
	
	while(p<=mid&&q<=r){
		if(a[p]<a[q])
			t[i++]=a[p++];
			
		else
			 t[i++]=a[q++];
	}
	while(p<=mid){
		t[i++]=a[p++];
	}
	while(q<=r)
		t[i++]=a[q++];
		
	for(i=l;i<=r;i++)
		a[i]=t[i]; 

}
int main(void){
	std::ios::sync_with_stdio(false);
	for(int i=1;i<=3;i++){
		cin>>a[i];
	}
	
	mergesort(1,3);
	
	cout<<a[1]+a[2];
	return 0;
}

Measured memory_bytes: 256
#include<string>
#include<iostream>
using namespace std;
int main(){
    string n;
    char tmp;
    int s,o;
    getline(cin,n);
    while(n!="-"){
        cin>>s;
        for(int i=0;i<s;i++){
            cin>>o;
            for(int j=0;j<o;j++){
                tmp=n[0];
                for(int k=1;k<(int)n.size();k++){
                    n[k-1]=n[k];
                }
                n[(int)n.size()-1]=tmp;
            }
        }
        cout<<n<<endl;
        cin>>n;
    }
    
}


Measured memory_bytes: 3156
#include <bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c;
  cin>>a>>b>>c;
  if((a==b&&a!=c)||(b==c&&b!=a)||(c==a&&a!=b)){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
}

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

#define MOD (1000000007)
#define N_MAX (100010)

using namespace std;

typedef long long int Int;

int N,M;
Int A[N_MAX];

class Disjoint_Set {
    private:
        int parent[N_MAX]; //parent node of the node x
    public:
        Int node_weight[N_MAX]; //weight of the node
        int edge_num[N_MAX]; //the number of edge in the node x
  
        Disjoint_Set(int n) {
            for(int i = 0;i < n;i++) {
                parent[i] = i;
                node_weight[i] = A[i];
                edge_num[i] = 0;
            }
        }

        int root(int x) {
            return parent[x] == x ? x : parent[x] = root(parent[x]);
        }

        void merge(int x,int y) {
            x = root(x);
            y = root(y);
            if(x != y) {
                parent[x] = y;
                node_weight[y] += node_weight[x];
                edge_num[y] += edge_num[x];
                node_weight[x] = edge_num[x] = 0;
            }
            edge_num[y]++;
        }
};

struct Edge {
    int from;
    int to;
    Int cost;
    bool operator < (const struct Edge &right) const {
        return cost < right.cost;
    }
};

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

    for(int i = 0;i < N;i++) {
        cin>>A[i];
    }

    Disjoint_Set DS(N);
    vector<struct Edge> e;
    struct Edge edge;
    for(int i = 0;i < M;i++) {
        int a,b;
        Int c;
        cin>>a>>b>>c;
        edge.from = --a;
        edge.to = --b;
        edge.cost = c;
        e.push_back(edge);
    }

    sort(e.begin(),e.end());
    Int ans = M;
    for(int i = 0;i < M;i++) {
        DS.merge(e[i].from,e[i].to);
        int r = DS.root(e[i].from);
        if(DS.node_weight[r] >= e[i].cost) {
            ans -= DS.edge_num[r];
            DS.edge_num[r] = 0;
        }
    }

    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 5748
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repI(i, d, n) for (int i = (d); i < (n); ++i)
#define reps1(i, n) for (int i = 1; i < (n); ++i)
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

using ll = long long;
using P = pair<int, int>;
using Pl = pair<ll, ll>;
using M = map<int, int>;
ll const INF = 1ll<<61;
double pi = 3.141592653589793238;

int main() {
  ll a, b;
  cin >> a >> b;

  cout << a / __gcd(a, b) * b << endl;


  return 0;
}


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

using namespace std;

int main()
{
  int n,k;
  cin >> n >> k;
  
  string str;
  cin >> str;
  
  str[k-1] = str[k-1] + ('a' - 'A');
  
  cout << str;
  
  return 0;
}

Measured memory_bytes: 256
while True:
	try:
		list = [int(item) for item in raw_input().split()]
		list.sort()
		if list[0] ** 2 + list[1] ** 2 == list[2] ** 2 :
			print 'YES'
		else :
			print 'NO'
	except EOFError:
		break
	except IndexError:
		continue

Measured memory_bytes: 4216
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    int N;
    cin >> N;
    double sum = 0, tmp;
    for(int i=0;i<N;i++){
        cin >> tmp;
        sum += 1/tmp;
    }
        
    printf("%.10lf\n", 1/sum);

}

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

using namespace std;

int main() {

	long n;
	long long counter;

	cin >> n;

	vector<long> a(n+1);
	vector<long> b(200002);

	for (long i = 1; i < n + 1; i++) {
		cin >> a[i];
		b[a[i]]++;
	}

	counter = 0;
	for (long i = 1; i < n + 1; i++) {
		counter += b[i] * (b[i] - 1) / 2;
	}

	if (counter == 0) {
		for (int i = 1; i <= n; i++) {
			cout << 0 << endl;
		}
		return 0;
	}

	for (long i = 1; i < n + 1; i++) {
		if (b[a[i]] >= 2) {
			cout << counter -b[a[i]]*(b[a[i]]-1)/2 + (b[a[i]] - 1)*(b[a[i]]-2)/2 << endl;
		}
		else {
			cout << counter << endl;
		}
	}



	return 0;
}

Measured memory_bytes: 5760
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#define llint long long
#define mod 1000000007
#define inf 1e18

using namespace std;
typedef pair<llint, llint> P;

struct SegTree{
	int size;
	vector<llint> seg;
	
	SegTree(){}
	SegTree(int size){
		this->size = size;
		seg.resize(1<<(size+1));
	}
	
	void init()
	{
		for(int i = 0; i < (1<<(size+1)); i++) seg[i] = inf;
	}
	
	void update(llint i, llint val)
	{
		i += (1 << size);
		seg[i] = val;
		while(i > 1){
			i /= 2;
			seg[i] = min(seg[i*2], seg[i*2+1]);
		}
	}

	llint query(llint a, llint b, llint k, llint l, llint r)
	{
		if(b < l || r < a) return inf;
		if(a <= l && r <= b) return seg[k];
		llint lval = query(a, b, k*2, l, (l+r)/2);
		llint rval = query(a, b, k*2+1, (l+r)/2+1, r);
		return min(lval, rval);
	}
	llint query(llint a, llint b)
	{
		if(a > b) return inf;
		return query(a, b, 1, 0, (1<<size)-1);
	}
};

llint fact[200005], fact_inv[200005];

llint POW(llint a, llint n)
{
	if(n == 0) return 1;
	if(n % 2){
		return ((a%mod) * (POW(a, n-1)%mod)) % mod;
	}
	else{
		return POW((a*a)%mod, n/2) % mod;
	}
}

void make_fact()
{
	llint val = 1;
	fact[0] = 1;
	for(int i = 1; i < 200005; i++){
		val *= i;
		val %= mod;
		fact[i] = val;
	}
	for(int i = 0; i < 200005; i++){
		fact_inv[i] = POW(fact[i], mod-2);
	}
}

llint N;
llint X, Y;
llint c[200005], w[200005];
vector<P> vec[200005];
bool same[200005], dif[200005];
bool able[200005];
llint cnt[200005];
SegTree seg(18);

int main(void)
{
	make_fact();
	cin >> N >> X >> Y;
	for(int i = 1; i <= N; i++) cin >> c[i] >> w[i];
	
	for(int i = 1; i <= N; i++) vec[c[i]].push_back({w[i], i});
	for(int i = 1; i <= N; i++) sort(vec[i].begin(), vec[i].end());
	for(int i = 1; i <= N; i++){
		if(vec[c[i]].size() == 0) continue;
		llint val = vec[c[i]][0].first;
		if(vec[c[i]][0].second == i){
			if(vec[c[i]].size() == 1) continue;
			val = vec[c[i]][1].first;
		}
		if(val <= X - w[i]) same[i] = true;
	}
	
	seg.init();
	for(int i = 1; i <= N; i++){
		if(vec[i].size() == 0) continue;
		seg.update(i, vec[i][0].first);
	}
	for(int i = 1; i <= N; i++){
		llint mn = inf;
		mn = min(mn, seg.query(1, c[i]-1));
		mn = min(mn, seg.query(c[i]+1, N));
		if(mn <= Y - w[i]) dif[i] = true;
	}
	
	for(int i = 1; i <= N; i++){
		if(dif[i]) able[i] = true;
		else if(same[i]){
			if(dif[vec[c[i]][0].second]) able[i] = true;
		}
	}
	
	llint sum = 0;
	for(int i = 1; i <= N; i++){
		if(able[i]) cnt[c[i]]++, sum++;
	}
	
	llint ans = fact[sum];
	for(int i = 1; i <= N; i++){
		ans *= fact_inv[cnt[i]];
		ans %= mod;
	}
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 23680
#include <stdio.h>
int main(void){
    int i,j,ver,hori;
    while(1){
        scanf("%d %d",&ver,&hori);
        if(ver == 0)break;
        for(i=0;i<ver;i++){
            for(j=0;j<hori;j++){
                printf("#");
            }
            printf("\n");
        }
        printf("\n");
    }
    return 0;
}



Measured memory_bytes: 2096
N,D = [int(x) for x in input().split()]

Xs = [n for n in range(N)]

for n in range(N):
    Xs[n] = [int(x) for x in input().split()]

count = 0
for i in range(N):
    for j in range(i+1,N):
        temp = 0
        for d in range(D):
            temp += (Xs[i][d] - Xs[j][d])**2
        temp = temp ** (1/2)
        if temp % 1 ==0:
            count+=1

print(count)

Measured memory_bytes: 3064