akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"

using namespace std;

using ll = long long;
using ld = long double;

const double PI = 3.1415926535897932384626433832795;
const ll MOD = 1000000007;

const int dx[] = { 0, 1, 0, -1 };
const int dy[] = { -1, 0, 1, 0 };

int gcd(int x, int y) { return y ? gcd(y, x % y) : abs(x); }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : abs(x); }
int lcm(int x, int y) { return x / gcd(x, y) * y; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }

struct edge {
	ll from;
	ll to;
	ll cost;
};

vector<ll> dist;

bool bellmanFord(int start, int n, int m, vector<edge> &es) {
	dist.resize(n, INT64_MAX);
	dist[start] = 0;

	for (int i = 0; i < n - 1; i++) {
		for (auto e : es) {
			if (dist[e.from] == INT64_MAX) {
				continue;
			}

			if (dist[e.to] > dist[e.from] + e.cost) {
				dist[e.to] = dist[e.from] + e.cost;
			}
		}
	}

	vector<bool> bads(n);
	for (int i = 0; i < n - 1; i++) {
		for (auto e : es) {
			if (dist[e.from] == INT64_MAX) {
				continue;
			}

			if (dist[e.to] > dist[e.from] + e.cost) {
				dist[e.to] = dist[e.from] + e.cost;
				bads[e.to] = true;
			}

			if (bads[e.from]) {
				bads[e.to] = true;
			}
		}
	}

	return bads[n - 1];
}

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

	int n, m, p;
	cin >> n >> m >> p;

	vector<edge> es;
	for (int i = 0; i < m; i++) {
		ll a, b, c;
		cin >> a >> b >> c;
		a--; b--; c = p - c;

		es.emplace_back(edge{ a, b, c });
	}

	bool isMinus = bellmanFord(0, n, m, es);
	if (isMinus) {
		cout << -1 << endl;
	} else {
		ll ans = -dist[n - 1];
		ans = max(0LL, ans);
		cout << ans << endl;
	}

	return 0;
}


Measured memory_bytes: 576
#include <stdio.h>
#include <stdlib.h>

typedef struct {
	long time;
	long dead;
} S_TASK;

int cmpAscDead(const void * n1, const void * n2)
{
	if (((S_TASK *)n1)->dead > ((S_TASK *)n2)->dead)
	{
		return 1;
	}
	else if (((S_TASK *)n1)->dead < ((S_TASK *)n2)->dead)
	{
		return -1;
	}
	else
	{
		return 0;
	}
}

int main(void) {

  long n;
  scanf("%ld", &n);
  S_TASK tasks[n];
  for (long i = 0; i < n; i++) {
    scanf("%ld %ld", &tasks[i].time, &tasks[i].dead);
  }
  qsort(tasks, n, sizeof(S_TASK), cmpAscDead);
  long need = 0;
  for (long i = 0; i < n; i++) {
    need += tasks[i].time;
    if (need > tasks[i].dead) {
      printf("No\n");
      return 0;
    }
  }
  printf("Yes\n");

  return 0;
}

Measured memory_bytes: 6396
# coding: utf-8

import sys
input = sys.stdin.readline

N, M = map(int, input().split())
A = list(map(int, input().split()))

need = [0,2,5,5,4,5,6,3,7,6]

dp = [-1] * (N + 1)
dp[0] = 0

for i in range(N + 1):
        for a in A:
                if i + need[a] <= N:
                        dp[i + need[a]] = max(dp[i + need[a]], dp[i] * 10 + a)

print(dp[-1])



Measured memory_bytes: 14692
INTEGER N
READ*,N
IF (N<105) THEN
  PRINT"(I0)",0
ELSE IF (N<135) THEN
  PRINT"(I0)",1
ELSE IF (N<165) THEN
  PRINT"(I0)",2
ELSE IF (N<189) THEN
  PRINT"(I0)",3
ELSE IF (N<195) THEN
  PRINT"(I0)",4
ELSE
  PRINT"(I0)",5
ENDIF
END

Measured memory_bytes: 256
use std::io::prelude::*;
use std::io::stdin;
use std::str::FromStr;

fn main() {
    let k: i64 = read();
    let a: i64 = read();
    let b: i64 = read();

    if b - a <= 1 {
        println!("{}", k + 1);
    } else {
        let mut count = a - 1;
        while (k - count) % 2 != 0 {
            count += 1;
        }
        println!("{}", count + ((k - count) / 2) * (b - a) + 1);
    }
}

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|b| b.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}


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

public class Main {
  public static void main(String[] args) throws IOException {
    execute();
  }

  private static void execute() throws IOException {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    String line = br.readLine();
    int a = Integer.parseInt(line.split(" ")[0]);
    int b = Integer.parseInt(line.split(" ")[1]);

    System.out.println(calc(a, b));
  }

  private static int calc(int a, int b) {
    if(a > 9 || b > 9){
      return  -1;
    }
    return a * b;
  }
}


Measured memory_bytes: 22996
import java.util.*;

public class Main{
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int sum = 0;
		int[] B = new int[N + 1];
		B[0] = Integer.MAX_VALUE;
		B[N] = Integer.MAX_VALUE;
		for(int i = 1; i < N; i++) {
			B[i] = sc.nextInt();
		}
		for(int i = 0; i < N; i++) {
			sum += Math.min(B[i], B[i + 1]);
		}
		System.out.println(sum);
	}
}

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

void dfs(int x,int y){
    C.at(x).at(y) = 0;
    for(int i=-1;i<2;++i){
        for(int j=-1;j<2;++j){
            int nh = x + i;
            int nw = y + j;
            if(0<=nw&&nw<w&&0<=nh&&nh<h&&C.at(nh).at(nw)==1){
            dfs(nh,nw);
            }
        }
        
    }
}

int main(){
    while(true){
        cin >> w >> h;
        if(w==0&&h==0){
            return 0;
        }
        rep(i,50){
            rep(j,50){
                C.at(i).at(j) = 0;
            }
        }
        cnt = 0;
        rep(i,h){
            rep(j,w){
                cin >> C.at(i).at(j);
            }
        }
       rep(i,h){
            rep(j,w){
                if(C.at(i).at(j)==1){
                    dfs(i,j);
                    ++cnt;
                }   
            }
        }
        cout << cnt << endl;    
    }
}



Measured memory_bytes: 3272
import scala.io.StdIn.readInt

object Main extends App {
  Iterator.continually(readInt).takeWhile(_!=0).foreach { n=>
    val total = (1 to 2*n).toList
    val taro = { for(i<-0 until n) yield readInt }.toList.sorted
    val hanako = (total filterNot taro.toSet).sorted
    def play(t:List[Int],h:List[Int],x:Int,turn:Int):(Int,Int) = {
      if(h.length==0 || t.length==0) (h.length,t.length)
      else if(turn%2 == 0) {
        if(t.exists(_ > x)) {
          val y = t.find(_>x).get
          play(t.filter(_!=y),h,y,turn+1)
        } else play(t,h,0,turn+1)
      } else {
        if(h.exists(_ > x)) {
          val y = h.find(_>x).get
          play(t,h.filter(_!=y),y,turn+1)
        } else play(t,h,0,turn+1)
      }
    }
    val (t,h) = play(taro,hanako,0,0)
    println(t)
    println(h)
  }
}

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

#define MAX 500000

struct node{
	int key;
	int parent, left, right;
} T[MAX];
int root;

void PrePrint(int t){
	if (t == -1) return;
	printf(" %d", T[t].key);
	PrePrint(T[t].left);
	PrePrint(T[t].right);
}

void InPrint(int t){
	if (t == -1) return;
	InPrint(T[t].left);
	printf(" %d", T[t].key);
	InPrint(T[t].right);
}

void initNode(int n){
	root = -1;
	for (int i = 0; i < n; i++){
		T[i].key = -1;
		T[i].parent = -1;
		T[i].left = -1;
		T[i].right = -1;
	}
}

void insert(int z){
	int y = -1; // xの親
	int x = root;
	while (x != -1){
		y = x;
		if (T[z].key < T[x].key) x = T[x].left;
		else x = T[x].right;
	}
	T[z].parent = y;

	if (y == -1) root = z;
	else if (T[z].key < T[y].key) T[y].left = z;
	else T[y].right = z;
}

int main(){
	int n = 0;
	scanf("%d", &n);
	initNode(n);
	for (int i = 0; i < n; i++){
		std::string com;
		std::cin >> com;
		if (com[0] == 'i'){
			int k = 0;
			scanf("%d", &k);
			T[i].key = k;
			insert(i);
		}
		else if (com[0] == 'p'){
			InPrint(root);
			printf("\n");
			PrePrint(root);
			printf("\n");
		}
	}
}


Measured memory_bytes: 11056
package main

import (
    "io"
    "os"
    "strings"
    "fmt"
)

var N int


func rot13(c byte) byte {
    // 文字を ROT13 変換する関数
    switch {
    case ('A' <= c && c <= 'Z'):
        // 13 文字分ずらす
        return (c - 'A' + byte(N)) % 26 + 'A'
    case ('a' <= c && c <= 'z'):
        // 13 文字分ずらす
        return (c - 'a' + byte(N)) % 26 + 'a'
    default:
        // 何もしない
        return c
    }
}

type rot13Reader struct {
    // io.Reader をラップする構造体
    r io.Reader
}

func (r *rot13Reader) Read(p []byte) (n int, err error) {
    // バイト列を読み込む
    n, err = r.r.Read(p)

    if err != nil {
        // 読み込みに失敗した
        return 0, err
    }

    for i := range p {
        // 各文字に ROT13 を適用する
        p[i] = rot13(p[i])
    }

    return
}


func main() {
    // 文字列から io.Reader インターフェースを実装したオブジェクトを生成する
    var str string
    
    fmt.Scan(&N, &str)
    s := strings.NewReader(str)
    // ROT13 変換するオブジェクトでラップする
    r := rot13Reader{s}
    // 標準出力に書き出す
    io.Copy(os.Stdout, &r)
    fmt.Println()
}


Measured memory_bytes: 768
#include <bits/stdc++.h>
#define rep(i,l,r) for (int i=l,i##end=r;i<=i##end;++i)
#define per(i,r,l) for (int i=r,i##end=l;i>=i##end;--i)
#define rep0(i,r) for (int i=0,i##end=r;i<i##end;++i)
#define pr pair<int,int>
#define mp make_pair
#define fi first
#define se second
#define ll long long
#define pb push_back
using namespace std;
const int N=1e6+6;
int main(){
    ll n,a,b; cin>>n>>a>>b;
    if (b%2==a%2) cout<<(max(a,b)-min(a,b))/2<<endl;
    else cout<<min((a+b-1)/2,(2*n-(a+b)+1)/2)<<endl;
}


Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>
#include <boost/multiprecision/cpp_int.hpp>

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
using namespace std;
typedef long long int ll;

// clang-format off
#ifdef _DEBUG_
#define dump(...) do{ cerr << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; PPPPP(__VA_ARGS__); cerr << endl; } while(false)
template<typename T> void PPPPP(T t) { cerr << t; }
template<typename T, typename... S> void PPPPP(T t, S... s) { cerr << t << ", "; PPPPP(s...); }
#else
#define dump(...)
#endif
template<typename T> vector<T> make_v(size_t a, T b) { return vector<T>(a, b); }
template<typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v(ts...))>(a, make_v(ts...)); }
template<typename T>
bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false;}
template<typename T>
bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false;}
// clang-format on

using cpp_int = boost::multiprecision::cpp_int;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n;
    ll m;
    cin >> n >> m;
    vector<cpp_int> a(n);
    REP(i, 0, n) {
        cin >> a[i];
    }
    sort(a.rbegin(), a.rend());
    vector<cpp_int> sum(n + 1, 0LL);
    REP (i, 0, n) {
        sum[i + 1] = sum[i] + a[i];
    }

    int l = 0, r = 200010;
    cpp_int ans = 0;
    while (l <= r) {
        int mid = (l + r) / 2;
        int j = n - 1;
        ll cnt = 0;
        cpp_int s = 0;
        REP(i, 0, n) {
            while (j >= 0 && a[i] + a[j] < mid) {
                j--;
            }
            cnt += (j + 1);
            s += sum[j + 1] + (j + 1) * a[i];
        }
        if (cnt < m) {
            r = mid - 1;
        } else {
            l = mid + 1;
            ans = s - mid * (cnt - m);
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 6528
#include <bitset>
#include <fstream>
#include <cstdio>
#include <iostream>
#include <vector>
#include <set>
#define NMAX 100001
#define NRHORSES 505

using namespace std;

int main()
{
    string s;
    cin >> s;

    int n = s.length();
    int sol = n;
    //make them all 0
    for (int i = 0; i < n; ++i) {
        if (s[i] == '1') {
            //compare length i with length n - i
            int aux = max(i, n - i - 1);
            sol = min(sol, aux);
        }
    }
    //make them all 1
    int sol2 = n;
    for (int i = 0; i < n; ++i) {
        if (s[i] == '0') {
            int aux = max(i, n - i - 1);
            sol2 = min(sol2, aux);
        }
    }
    cout << max(sol, sol2) << "\n";
    return 0;
}


Measured memory_bytes: 512
# Edige Weighted Digraph


from collections import namedtuple


WEIGHT_MAX = 10 ** 10
WeightedEdge = namedtuple('WeightedEdge', ('src', 'dest', 'weight'))


class Digraph:
    def __init__(self, v):
        self.v = v
        self.edges = [[] for _ in range(v)]

    def add(self, edge):
        self.edges[edge.src].append(edge)

    def adj(self, v):
        return self.edges[v]


def sp_bellmanford(graph, s):
    def relax(edge):
        s, t, w = edge
        if dists[t] > dists[s] + w:
            dists[t] = dists[s] + w
            srcs[t] = s
            _nodes.append(t)

    dists = [WEIGHT_MAX] * graph.v
    dists[s] = 0
    srcs = [-1] * graph.v
    nodes = []

    nodes.append(s)
    for _ in range(graph.v):
        _nodes = []
        for v in nodes:
            for e in graph.adj(v):
                relax(e)
        nodes = _nodes

    if len(nodes) > 0:
        return None
    else:
        return [None if dists[v] == WEIGHT_MAX else dists[v]
                for v in range(graph.v)]


def run():
    v, e, r = [int(i) for i in input().split()]

    graph = Digraph(v)
    for _ in range(e):
        edge = WeightedEdge(*[int(i) for i in input().split()])
        graph.add(edge)

    ws = sp_bellmanford(graph, r)
    if ws is None:
        print("NEGATIVE CYCLE")
    else:
        for w in ws:
            if w is None:
                print("INF")
            else:
                print("{:d}".format(w))


if __name__ == '__main__':
    run()



Measured memory_bytes: 6592
#include<bits/stdc++.h>
using namespace std;
int n, odd = 0, even = 0;
int main(){
    scanf("%d", &n);
    for(int i = 0; i < n; i++){
        int x;
        scanf("%d", &x);
        if(x % 2 == 0) even++;
        else odd++;
    }
    long long ans = 0;
    ans = pow(3, n) - pow(2, even);
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main()
{
  int x, y;
  scanf("%d %d", &x, &y);
  char str_x[x+1][y+1];
  int i, j;
  for(i = 0; i < x; i++) {
    scanf("%s", str_x[i]);
  }
  for(i = 0; i < y+2; i++) {
    printf("#");
  }
  printf("\n");
  for(i = 0; i < x; i++) {
    printf("#%s#\n", str_x[i]);
  }
  for(i = 0; i < y+2; i++) {
    printf("#");
  }
  return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define fast ios::sync_with_stdio(false), cin.tie(0);
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define endl '\n'

using namespace std;

main()
{
    fast;
    int n,k,i;
    cin>>n>>k;
    ll x[n],ans=1e10,tp;
    for (i=0;i<n;i++)
        cin>>x[i];
    for (i=0;i<n-k+1;i++)
    {
        if (x[i]<=0 && x[i+k-1]<=0)
            tp=abs(x[i]);
        else if (x[i]>=0 && x[i+k-1]>=0)
            tp=x[i+k-1];
        else
            tp=min(2*abs(x[i])+abs(x[i+k-1]),abs(x[i])+2*abs(x[i+k-1]));
        ans=min(ans,tp);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 1024
#include <stdio.h>
int main(void){
	int H[300],W[300],Count=0,i,hi,wi;
	
	while(1){
		scanf("%d %d",&H[Count],&W[Count]);
		if(H[Count]==0&&W[Count]==0){
			break;
		}
		Count++;
	}
	for(i=0;i<Count;i++){
		for(hi=0;hi<H[i];hi++){
			for(wi=0;wi<W[i];wi++){
				printf("#");
			}
			printf("\n");
		}
		printf("\n");
	}
  return 0;
}

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

int main() {
  int r,m,f;
  cin >> r >> m >> f;
  
  while (r != -1 || m != -1 || f != -1) {
    if (r == -1 || m == -1) {
        cout << 'F' << endl;
    }
    else if (r + m >= 80){
      cout << 'A' << endl;
    }
    else if (r + m >= 65) {
      cout << 'B' << endl;
    }
    else if (r + m >= 50) {
      cout << 'C' << endl;
    }
    else if (r + m >= 30 && f >= 50) {
      cout << 'C' << endl;
    }
    else if (r + m >= 30) {
      cout << 'D' << endl;
    }
    else {
      cout << 'F' << endl;
    }
    cin >> r >> m >> f;
  }
}


Measured memory_bytes: 3104
#include<iostream>
#include<cstring>
//#include<bits/stdc++.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<stack>
#include<cstdio>
#include<map>
#include<set>
#define  si(a)       scanf("%d",&a)
#define  sl(a)       scanf("%lld",&a)
#define  sii(a,b)    scanf("%d%d",&a,&b)
#define  sll(a,b)    scanf("%lld%lld",&a,&b)
#define  queues      priority_queue
#define mod  1000000007
#define mem(a)  memset(a,0,sizeof(a));
#define def(a) ((a)&(-a))
#define fi  first
#define se  second
#define mp  make_pair
#define  pb push_back
#define mem(a,b) memset(a,b,sizeof(a));
typedef long long ll;
const ll maxn=10000006;
//priority_queue<ll,vector<ll >,greater<ll > >q;
const ll INF=0x3f3f3f3f;
//const double E=exp(1);
//const double PI=acos(-1);
using namespace std;
//__builtin_popcount
//priority_queue
inline char nc()   //快的一批的fread快读
{
    static char buf[100000],*p1=buf,*p2=buf;
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
inline ll read()
{
    char ch=nc();
    ll sum=0;
    while(!(ch>='0'&&ch<='9'))ch=nc();
    while(ch>='0'&&ch<='9')sum=sum*10+ch-48,ch=nc();
    return sum;
}
bool cmp(ll a,ll b)
{
    return a>b;
}
ll pri[100003];
ll sum1[100003];
int b[maxn];
ll sum;
void so()
{
  for(ll i=2;i<=100003;i++)
  {
      if(!b[i])pri[++sum]=i;
      for(ll j=1;j<=sum;j++)
      {
          if(i*pri[j]>100000)break;
          b[i*pri[j]]=1;
           if(i%pri[j]==0)break;
      }
  }
  cout<<sum<<endl;
}
map<string,ll >q,q1;
char s[100003][20];
int main()
{
  int t;
  cin>>t;
  ll z=0;
  for(int i=1;i<=t;i++)
  {
      scanf("%s",s[i]);
      int xx=strlen(s[i]);
      sort(s[i],s[i]+xx);
      q[s[i]]++;
  }
  for(int i=1;i<=t;i++)
  {
      if(!q1[s[i]])
        z+=(q[s[i]])*(q[s[i]]-1)/2,q1[s[i]]=1;
  }cout<<z<<endl;

}



Measured memory_bytes: 24064
// #include {{{
#include <iostream>
#include <cassert>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <ctime>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <string>
#include <bitset>
#include <vector>
#include <complex>
#include <algorithm>
using namespace std;
// }}}
// #define {{{
typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define de(x) cout << #x << "=" << x << endl
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define per(i,a,b) for(int i=(b)-1;i>=(a);--i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
// }}}

string s;

int main(){
    cin >> s;
    ll ans = 1ll * sz(s) * (sz(s) - 1) / 2 + 1;
    map<char,int> vis;
    for(auto ch : s) vis[ch]++;
    for(auto e : vis) ans -= 1ll * e.se * (e.se - 1) / 2;
    cout << ans << endl;
    return 0;
}


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

int main(){
  int N;
  int num[10];
  for(int i =0;i<10;i++){
    num[i]=0;
  }
  for(int i = 0;i<4;i++){
    cin>>N;
    num[N]++;
  }
  if(num[1]==1&&num[9]==1&&num[7]==1&&num[4]==1){
    cout<<"YES"<<endl;
  }else{
    cout<<"NO"<<endl;
  }
  
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int A = sc.nextInt();
		int B = sc.nextInt();
		if (A>B) {
			System.out.print(B+" ");
		} else {
			System.out.print(A+" ");
		}
		if (A+B>N) {
			System.out.println(A+B-N);
		} else {
			System.out.println(0);
		}
	}
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
//make_tuple emplace_back next_permutation push_back make_pair second first setprecision

#if MYDEBUG
#include "lib/cp_debug.h"
#else
#define DBG(...) ;
#endif

using LL = long long;
constexpr LL LINF=334ll<<53;
constexpr int INF=15<<26;
constexpr LL  MOD=1E9+7;

struct Problem{
    int n;
    map<LL,LL> m;
    Problem(LL n):n(n){};

    void solve(){
        for(int i=0; i<n; ++i){
            LL tmp;
            cin >>tmp;
            m[tmp]++;
        }
        LL a=0,b=0;
        auto it = m.end();
        for(it--;;it--){
            DBG(*it)
            if(it->second>=4){
                if(a==0)a=b=it->first;
                else b=it->first;
                break;
            }else if(it->second>=2){
                if(a==0)a=it->first;
                else{
                    b=it->first;
                    break;
                }
            }
            if(it==m.begin())break;
        }
        cout << a*b <<"\n";
    }
};

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    long long n=0;
    cin >> n;
    Problem p(n);
    p.solve();
    return 0;
}



Measured memory_bytes: 6528
#pragma GCC optimize(3,"Ofast","inline")
#pragma GCC optimize(2)
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#define NIL -1

using namespace std;

struct node{
	int pa;
	int le;
	int ri;
};

const int maxn=1e7+10;
node nd[maxn];
int deep[maxn];

void Init(int n)
{
	for(int i=0;i<n;i++){
		nd[i].pa=nd[i].le=nd[i].ri=NIL;
	}
}

void setDepth(int u,int p)
{
	deep[u]=p;
	if(nd[u].ri!=NIL){
		setDepth(nd[u].ri,p);
	}
	if(nd[u].le!=NIL){
		setDepth(nd[u].le,p+1);
	}
}

void print_node(int n)
{
	for(int i=0;i<n;i++){
		printf("node %d: parent = %d, depth = %d,",i,nd[i].pa,deep[i]);
		if(nd[i].pa==NIL){
			printf(" root, ");
		}else if(nd[i].le==NIL){
			printf(" leaf, ");
		}else{
			printf(" internal node, ");
		}
		printf("[");
		for(int j=0,c=nd[i].le;c!=NIL;c=nd[c].ri,j++){//打印同层子节点 
			if(j>0)printf(", ");
			printf("%d",c);
		}
		printf("]\n");
	}
}

int main()
{
	int n;
	scanf("%d",&n);
	Init(n);//用for循环初始化空间复杂度更小，但是跑的更慢，到了test7就tle了 
	//memset(nd,NIL,sizeof(nd));用这段代码进行初始化，时间上的确更快了，但是空间复杂度一下就大了，memory limit exceed 
	memset(deep,0,sizeof(deep));
	int v,d,c,l,root;
	for(int k=0;k<n;k++){
		scanf("%d%d",&v,&d);
		for(int i=0;i<d;i++){
			scanf("%d",&c);
			if(i==0){
				nd[v].le=c;
			}else{
				nd[l].ri=c;
			}
			l=c;
			nd[c].pa=v;
		}
		/*for(int i=0;i<n;i++){
			if(nd[i].pa==NIL)root=i;//寻找根节点 
		}
		setDepth(root,0);*/
	}
	for(int i=0;i<n;i++){
			if(nd[i].pa==NIL)root=i;//寻找根节点 
	}
	setDepth(root,0);
	print_node(n);
	return 0;
}


Measured memory_bytes: 46488
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
using namespace std;

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)

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; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }

string str;

int main() {
    while (cin >> str) {
        map<char,int> ma;
        for (int i = 0; i < str.size(); ++i) {
            ma[str[i]]++;
        }
        bool ok = true;
        for (map<char,int>::iterator it = ma.begin(); it != ma.end(); ++it) {
            if (it->second & 1) ok = false;
        }
        if (ok) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
}
















Measured memory_bytes: 256
require 'set'

gets # nは捨てる
s = gets.strip.split('')
 
r_pos = Set.new(s.map.with_index { |e, i| e == 'R' ? i : nil }.compact)
g_pos = Set.new(s.map.with_index { |e, i| e == 'G' ? i : nil }.compact)
b_pos = Set.new(s.map.with_index { |e, i| e == 'B' ? i : nil }.compact)
 
num_ex = 0
 
r_pos.each{|r|
  g_pos.each{|g|

    # middle
    if (r+g)%2 == 0 and b_pos.include?((r+g)/2)
      num_ex = num_ex.next
    end
    
    # edge
    diff = (r-g).abs
    if r < g
      if b_pos.include?(r-diff) 
        num_ex = num_ex.next
      end
      if b_pos.include?(g+diff)
        num_ex = num_ex.next
      end
    else
      if b_pos.include?(g-diff)
        num_ex = num_ex.next
      end
      if b_pos.include?(r+diff)
        num_ex = num_ex.next
      end
    end
    
  }
}
 
puts (r_pos.size * g_pos.size * b_pos.size) - num_ex

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


using namespace std;
#define rep(i,a,b) for(int i=a;i<b;i+=1)
#define repb(i,a,b) for(int i=a;i>=b;i--)
#define repv(arr)  for(auto it=arr[i].begin();it!=arr[i].end();it++)  
#define vi vector<int>
#define vb vector<bool>
#define vs vector<string>
#define vl vector<long long int>
#define ssortA(arr)   stable_sort(arr.begin(),arr.end())
#define search(arr,c)  binary_search(arr.begin(),arr.end(),c)
#define pb   push_back
#define ll long long
#define LCM(a,b) boost::math::lcm(a,b)
#define cl_bf cin.ignore(numeric_limits<streamsize>::max(), '\n');

int main(){

    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int t;
    cin>>t;
    int k=pow(t,1)+pow(t,2)+pow(t,3);
    cout<<k<<endl;
}

Measured memory_bytes: 4072
#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 n;
  ll d;
  cin >> n >> d;
  int ans = 0;
  rep(i, n) {
    ll x, y;
    cin >> x >> y;
    if (x * x + y * y <= d * d) ans++;
  }
  cout << ans << endl;
  return 0;
}


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

int main(){
  int H, W;
  scanf("%d",&H);
  scanf("%d",&W);
  std::string S;
  char field[H][W];
  int yoko[H][W];
  int tate[H][W];
  for (int i=0; i<H; i++){
    std::cin >> S;
    for (int j=0; j<W; j++){
      field[i][j] = S[j];
      if (field[i][j]=='#'){
        yoko[i][j]=0;
        tate[i][j]=0;
      }
    }
  }

  for (int i=0; i<H; i++){
    int start = -1;
    int pos = 0;
    while(pos<W){
      //printf("pos=%d\n",pos);
      if (field[i][pos]=='#'){
        for (int j=start+1; j<pos; j++){
          //printf("yoko[%d][%d]=%d\n",i,j,pos-start-1);
          yoko[i][j]=pos-start-1;
        }
        start=pos;
      }
      pos++;
    }
    for (int j=start+1; j<pos; j++){
      yoko[i][j]=pos-1-start;
    }
  }

  for (int i=0; i<W; i++){
    int start = -1;
    int pos = 0;
    while(pos<H){
      if (field[pos][i]=='#'){
        //printf("field[%d][%d]=#\n",pos,i);
        for (int j=start+1; j<pos; j++){
          //printf("tate[%d][%d]=%d\n",j,i,tate[j][i]);
          tate[j][i]=pos-start-1;
        }
        start=pos;
      }
      pos++;
    }
    for (int j=start+1; j<H; j++){
      tate[j][i]=H-1-start;
      //printf("tate[%d][%d]=%d\n",j,i,tate[j][i]);
    }
  }

  for (int i=0; i<H; i++){
    for (int j=0; j<W; j++){
      //printf("%d ",yoko[i][j]);
    }
    //    printf("\n");
  }
  for (int i=0; i<H; i++){
    for (int j=0; j<W; j++){
      //printf("%d ",tate[i][j]);
    }
    //    printf("\n");
  }

  
  int maxnum = 0;
  for (int i=0; i<H; i++){
    for (int j=0; j<W; j++){
      maxnum = std::max(maxnum,yoko[i][j]+tate[i][j]);
    }
  }
  printf("%d\n",maxnum-1);
  return 0;
}


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

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

  string s[n];
  rep(i,n) cin >> s[i];

  int ans=1;
  
  sort(s,s+n);

  string check=s[0];

  for(int i=1;i<n;i++){
   if(s[i] != check){
       ans++;
       check = s[i];
   }  
  }

  cout << ans << endl;
}

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

//フラグの立て方は、ループでbit<(1<<i)
//フラグが立っているかどうかは、bit&1<<n

int main(){
    //人数
    int n; cin>>n;
    //誰の何個めの証言か、名宛人とその内容
    int x[n][n],y[n][n];
    //各々の証言数
    int a[n];
    
    for(int i=0;i<n;i++){
        cin>>a[i];
        for(int j=0;j<a[i];j++){
            cin>>x[i][j]>>y[i][j];
        }
    }

    int ans=0;
    
    for(int bit=0;bit<(1<<n);bit++){
        bool can=true;
        for(int j=0;j<n;j++){
            if(!(bit&(1<<j))) continue;

            for(int k=0;k<a[j];k++){
                //名宛人は1からｎ、bitは0からn-1なので名宛人にー1する
                if(!(bit&(1<<(x[j][k]-1))) && y[j][k]) can=false;
                else if(bit&(1<<(x[j][k]-1)) && !(y[j][k])) can=false;
            }
        }

        if(can){
            int count=0;
            for(int i=0;i<n;i++){
                if(bit&(1<<i)) count++;
            }

            ans=max(ans,count);
        }

    }

    cout<<ans<<endl;
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;

#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (ll i = (l); i < (r); i++)
#define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--)
#define repa(i,n) for (auto& i: n)

template<class T> inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
void init() {cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(15);}

#ifdef DEBUG
template <class T, class N> void verr(const T& a, const N& n) { rep(i, n) cerr << a[i] << " "; cerr << "\n" << flush; }
ll dbgt = 1; void err() { cerr << "passed " << dbgt++ << "\n" << flush; }
template<class H, class... T> void err(H&& h,T&&... t){ cerr<< h << (sizeof...(t)?" ":"\n") << flush; if(sizeof...(t)>0) err(forward<T>(t)...); }
#endif

const ll INF = 4e18;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
//--------------------------------------------------------------------------------//

// 分割数テーブル
// NをK個の非負整数の和で表す通り数 O(NK)
struct PartitionNumber {
    vector<vector<ll>> P;
    PartitionNumber (ll N) : P(N + 1, vector<ll>(N + 1)){
        for (ll k = 0; k <= N; k++) P[0][k] = 1;
        for (ll n = 1; n <= N; n++) {
            for (ll k = 1; k <= N; k++) {
                P[n][k] = P[n][k - 1] + (n - k >= 0 ? P[n - k][k] : 0);
                if (P[n][k] >= MOD) P[n][k] -= MOD;
            }
        }
    }

    ll get(ll n, ll k){
        return P[n][k];
    }
};

int main() {
    init();
    ll N, K;
    cin >> N >> K;

    PartitionNumber P(max(N, K));

    cout << P.get(N, K) << endl;
}


Measured memory_bytes: 10828
n,a,b=map(int,input().split())

cmba=1
cmbb=1
p=(10**9)+7
lst=[]
num=pow(2,n,p)-1
for i in range(1,b+1):
  cmbb*=((n-i+1)*(pow(i,p-2,p)))%p
  if cmbb>p:
    cmbb=cmbb%p
  cmba=cmbb
  if i==a:
    lst.append(cmba)
    
num=num-lst[0]-cmbb
num=num%p

print(num)


Measured memory_bytes: 38896
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
 
def main():
    S = input()
    N = len(S)
    preString = 'A'
    i = 0
    cnt = 0
    #Sを前から調べる
    while i < N: 
        #Sをは切り出す最後尾の位置を示すポインタ
        #文字列に差異が出るまでjをインクリメントしていく
        j = i + 1
        while j <= N:
            if preString == S[i:j]:
                #一致したらjを次の位置に変更する
                j += 1
            else:
                #一致しなかったところで切り出すのでカウントする
                cnt += 1
                preString = S[i:j]
                break
            #先頭のポインタをjにする
        i = j
    print(cnt)
if __name__ == '__main__':
    main()


Measured memory_bytes: 9288
#include<bits/stdc++.h>
#define pb push_back
#define all(v) (v).begin() , (v).end()
#define popcnt(x) __builtin_popcount(x)
#define inf 0x3f3f3f3f
#define watch(x) cout << (#x) << " is " << (x) << endl
#define rand() (rand() << 15 | rand())
using namespace std;
typedef long long  ll;
#define EPS 1e-9
#define PI acos(-1.0)
int main() {
   ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
   string s;
   cin >> s;
   bool good = true;
   for(int i = 0 ; i < (int)s.size() ; ++i){
      if(i & 1){
         if(s[i] == 'R')good = false;
      }
      else{
         if(s[i] == 'L')good = false;
      }
   }

   cout << (good ? "Yes" : "No") << "\n";
}

Measured memory_bytes: 256
def main():
    N, A, B, C, D = (int(i) for i in input().split())
    S = "#" + input() + "#"
    if "##" in S[A:C+1] or "##" in S[B:D+1]:
        return print("No")
    if D < C and "..." not in S[B-1:D+2]:
        return print("No")
    print("Yes")


if __name__ == '__main__':
    main()


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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
  os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
  for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
  for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}

ll modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

ll fact(ll x){
	if(x==0) return 1;
	return fact(x-1) * x % mod;
}

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

    ll N;
    cin >> N;
    vector<ll> A(N);
    REP(i, N) cin >> A[i];

    ll res = 0;
    vector<ll> B(101011, 0);
    REP(i, 101010){
    	B[i+1] = modinv(i+1, mod);
    }

    REP(i, 101010){
    	B[i+1] += B[i];
    	B[i+1] %= mod;
    }

    REP(i, N){
    	ll tmp = 0;
    	tmp += B[i+1];
    	tmp %= mod;
    	tmp += B[N-i];
    	tmp %= mod;
    	tmp -= 1;
    	tmp = (tmp+mod)%mod;
    	res += (tmp * A[i])%mod;
    	res %= mod;
    }

    res *= fact(N);
    res %= mod;

    cout  << res << endl;
    return 0;
}

Measured memory_bytes: 3456
from itertools import combinations
n = int(input())
names = [input() for _ in range(n)]
march = "MARCH"
cnt = {k: 0 for k in march}
for name in names:
    if any(name.startswith(s) for s in march):
        cnt[name[0]] += 1
cnt = [v for _, v in cnt.items()]
if len([v for v in cnt if v > 0]) < 3:
    print(0)
else:
    result = sum(a * b * c for a, b, c in combinations(cnt, 3))
    print(result)


Measured memory_bytes: 9772
import sys

sys.setrecursionlimit(10 ** 7)
rl = sys.stdin.readline


def solve():
    N = rl().rstrip()
    
    s = N[-1]
    if s == '2' or s == '4' or s == '5' or s == '7' or s == '9':
        print('hon')
    elif s == '0' or s == '1' or s == '6' or s == '8':
        print('pon')
    else:
        print('bon')


if __name__ == '__main__':
    solve()


Measured memory_bytes: 61904
import sys
import math
import bisect
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop


def LI(): return [int(x) for x in sys.stdin.readline().split()]


def I(): return int(sys.stdin.readline())


def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res


def IR(n):
    return [I() for i in range(n)]


# A
def A():
    s = S()
    t = S()
    ans = 0
    for i in range(3):
        if s[i] == t[i]:
            ans += 1
    print(ans)
    return


# B
def B():
    a, b = LI()
    print(-(-(b - 1) // (a - 1)))
    return


# C
def C():
    N = I()
    H = LI()
    ans = 0
    cnt = 0
    for i in range(1, N):
        if H[i - 1] >= H[i]:
            cnt += 1
            ans = max(ans, cnt)
        else:
            cnt = 0
    print(ans)
    return


# D
def D():
    N = I()
    print(N * (N - 1) // 2)
    return


# E
def E():
    return


# F
def F():
    return


# Unittest
def resolve():
    D()
    return


# Solve
if __name__ == "__main__":
    D()


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

using namespace std;
#define set_precision(ans,l) cout << fixed << setprecision(l)<<ans;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define repb(i, a, b) for (int i = a; i >= b; i--)
#define vi vector<int>
#define vl vector<long long int>
#define Vi vector<vector<int>>
#define vpi vector<pair<int,int>>
#define seti set<int>
#define setl set<ll>
#define dseti set<int, greater<int>>
#define dsetl set<ll, greater<ll>>
#define mseti multiset<int>
#define msetl multiset<ll>
#define dmseti multiset<int, greater<int>>
#define dmsetl multiset<ll, greater<ll>>
#define sortA(arr) sort(arr.begin(), arr.end())
#define dsortA(arr) sort(arr.begin(), arr.end(), greater<ll>())
#define ssort(arr) stable_sort(arr.begin(), arr.end())
#define nth(v,n) nth_element(v.begin,v.begin+n-1,v.end())
#define dnth(v,n) nth_element(v.begin,v.begin+n-1,v.end(), greater<ll>())
#define init(a)  memset((a),0,sizeof(a))
#define pi pair<int,int>
#define pb push_back
#define pl pair<ll,ll>
#define ll long long
#define FIO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define mod 1000000007
long double EPS = 1e-9;

/*struct comp {
  bool operator() (const int& lhs, const int& rhs) const
  {return lhs<rhs;}
};*/

ll cel(ll a,ll b){return((a-1)/b+1);} 
ll gcd(ll a, ll b){
    if (a < b)swap(a, b);
    return (b == 0)? a: gcd(b, a % b);
}
ll lcm(ll a,ll b){return (a*b)/gcd(a,b);}
ll po(ll x,ll y){
    ll ans=1;
    while(y){
        if(y&1){ans=(ans*x)%mod;}
        y>>=1;x=(x*x)%mod;
    }
    return ans;
}

const int N=200001;
vi adj[N];vi vis(N,0);

void dfs(ll u,ll &l){
    vis[u]=1;l++;
    for(int t:adj[u]){
        if(vis[t])continue;
        dfs(t,l);
    }
}

int main()
{
    FIO;
    ll n,t,x,y,m,k=0,l=0;
    cin>>n>>m;
    rep(i,0,m){
        cin>>x>>y;
        adj[x].pb(y);adj[y].pb(x);
    }
    rep(i,1,n+1){
        if(vis[i])continue;
        l=0;
        dfs(i,l);
        k=max(k,l);
        //cout<<i<<" "<<l<<" ";
    }
    cout<<k;
    return 0;
}

Measured memory_bytes: 21092
#include <iostream>

int main()
{
	using namespace std;
	int N, K;
	cin >> N >> K;
	int ans = 0;
	for (int i = 0; i < N; i++) {
		int temp;
		cin >> temp;
		if (temp >= K)
			ans++;
	}

	cout << ans << endl;
}

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

using namespace std;
#define PB push_back
#define MP make_pair
#define rep(i,a,b) for (int i = a; i <= b; i++)

#pragma comment(linker, "/STACK:16777216")

typedef long long int64;
typedef unsigned long long uint64;

int main()
{
	int a, b, c, d;
	cin >> a >> b >> c >> d;

	int res = min(a,b) + min(c,d);
	cout << res << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i = (a); i <= (b); i++)
#define rng(a) a.begin(), a.end()
#define ina(n,a) cin >> n; for(int i = 1; i <= n; i++) cin >> a[i]
#define sz(x) (int)(x).size()
#define se second
#define fi first
#define prev            coyhhhhhhyoc    
#define next          sdNNNmNNNNNNNmds  
#define y0           hNNNNy_yNNNNNN_sNh
#define y1          mNNNNNdtdNNNNNNtsNNm
#define yn          mNNNNNNNNy___smNNNms
#define tm            oooooosyysooooot 
#define read               tyhyt        
#define rank              ytmNmo         
#define index              yyy
#define pb push_back
#define pcnt __builtin_popcountll
#define rrep(i,a,b) for(int i = (b); i >= (a); i--)
#define rall(x,a) for(auto x : a)
#define MOD 1000000007
#define endl "\n"
typedef long long ll;
using namespace std;

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int a, b, c, d, e;
    cin >> a >> b >> c >> d >> e;
    if(!a) {
        cout << 1 << endl;
    } else if(!b) {
        cout << 2 << endl;
    } else if(!c) {
        cout << 3 << endl;
    } else if(!d) {
        cout << 4 << endl;
    } else if(!e) {
        cout << 5 << endl;
    }
    return 0;
}


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

int main()
{
   int n,k;
   cin>>n>>k;
   int arr[n+1],minarr[n+1];
   for(int i=1;i<=n;i++)
      cin>>arr[i];
    minarr[1]=0;
    minarr[2]=abs(arr[2]-arr[1]);
    
 //   cout<<minarr[2]<<minarr[3]<<endl;
    for(int i=3;i<=n;i++)
    {
	    minarr[i]=INT_MAX;
	    int j = i-k;
	    if(j<=0)j=1;
	    while(j<i)
	    {
//		cout<<i<<" it comes here";
		minarr[i] = min(minarr[j] + abs(arr[j]-arr[i]), minarr[i]);
//		cout<<minarr[j]<<endl;
		j++;

	    }
//	    cout<<i<<" "<<minarr[i]<<endl;
    }
//    cout<<minarr[3]<<endl;
    cout<<minarr[n];
    return 0;
}


Measured memory_bytes: 1024
n, Y = map(int,input().split())
c = 0
for y in range(n+1):
        for z in range(n+1):
                if y + z > n:
                        break
                else:
                        x = n - y - z
                        if c == 1:
                                break
                        elif 10000 * x + 5000 * y + 1000 * z == Y:
                                c = 1
                                s = x
                                t = y
                                r = z

if c == 1:
        print("{} {} {}".format(s,t,r))
else:
        print("-1 -1 -1")

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

public class Main {

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int m = Integer.parseInt(br.readLine());
        System.out.println(problem173a(m));
    }

    private static int problem173a(int n) {
        return ((n % 1000) == 0) ? 0 : (1000 - (n % 1000));
    }
}

Measured memory_bytes: 25348
rot = ((1,2,4,3),(2,0,3,5),(0,1,5,4))
f = input().split()

for i in range(int(input())):
    t, s = map(f.index, input().split())
    for j in rot:
        if not (t in j)*(s in j):
            continue
        d = rot.index(j)
        if (j.index(t) - j.index(s)) %4 == 1:
            d -= 5
    print(f[abs(d)])

Measured memory_bytes: 7676
from collections import Counter
n = int(input())
a = Counter(sorted(list(map(int, input().split()))))

ans = 0
p = 0
for x, y in a.items():
    p = y
    if x-1 in a: p += a[x-1]
    if x+1 in a: p += a[x+1]
    if p > ans: ans = p
print(ans)

Measured memory_bytes: 14548
groupa = [1,3,5,7,8,10,12]
groupb = [4,6,9,11]
groupc = [2]

inputs = gets.split(' ')

x = inputs[0].to_i
y = inputs[1].to_i
if (groupa.include?(x) and groupa.include?(y)) or (groupb.include?(x) and groupb.include?(y)) or (groupc.include?(x) and groupc.include?(y))
  puts 'Yes'
else
  puts 'No'
end


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

int W, H;
string s[1000], ss[2], joi = "JOI";
int b[1000][1000];

int check(int x, int y)
{
  bool bb = true;
  for(int yy = 0; yy < 2; yy++)
    for(int xx = 0; xx < 2; xx++)
      bb &= s[y + yy][x + xx] == ss[yy][xx];
  return bb ? 1 : 0;
}

int count(int x, int y)
{
  int n = 0, m = 0;
  if(x > 0 && y > 0)
  {
    n += check(x - 1, y - 1);
    m += b[y - 1][x - 1];
  }
  if(x > 0 && y < H - 1)
  {
    n += check(x - 1, y);
    m += b[y][x - 1];
  }
  if(y > 0 && x < W - 1)
  {
    n += check(x, y - 1);
    m += b[y - 1][x];
  }
  if(y < H - 1 && x < W - 1)
  {
    n += check(x, y);
    m += b[y][x];
  }
  return n - m;
}

int main()
{
  int n = 0, ans = -1;
  
  cin >> H >> W;
  for(int i = 0; i < H; i++)
    cin >> s[i];
  cin >> ss[0] >> ss[1];
  
  for(int y = 0; y < H - 1; y++)
    for(int x = 0; x < W - 1; x++)
      n += b[y][x] = check(x, y);
  for(int y = 0; y < H; y++)
  {
    for(int x = 0; x < W; x++)
    {
      auto c = s[y][x];
      for(int i = 0; i < 3; i++)
      {
        s[y][x] = joi[i];
        ans = max(ans, n + count(x, y));
      }
      s[y][x] = c;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 6172
import java.util.Scanner;

class Main {  
  public static void main(String[] args) {
    Scanner in = new Scanner(System.in);
    
    while (in.hasNext()){
      int n = in.nextInt();
      if (n == 0) break;
      int[] numbers = new int[n];
      
      for (int i = 0; i < n; i++) numbers[i] = in.nextInt();
      
      long double_sum = 0;
      for (int i = 0; i < n; i++) double_sum += numbers[i];
      double_sum = double_sum * double_sum;
      
      long sum_double = 0;
      for (int i = 0; i < n; i++) sum_double += (numbers[i] * numbers[i]);
      
      double sd = Math.sqrt((sum_double - double_sum / (double)n) / (double)n);
      
      System.out.printf("%5.8f", sd);
      System.out.println();
    }
  }
}

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

int main(){
    int a, b;
    
    cin >> a >> b;
    if (a<=5){
        cout << "0" << endl;
    } else if(a<=12){
        cout << b/2 << endl;
    } else {
        cout << b << endl;
    }
    return 0;
}




Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<set>
#include<cmath>
#include<queue>
#include<unordered_map>
#include<map>
#include<stack>
//#include<bits/stdc++.h>		
#include<string.h>
#include <ext/pb_ds/assoc_container.hpp>
#define FASTIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define int long long
#define f first
#define respr(fir,sec) for(int i=0;i<=fir;i++){for(int j=0;j<=sec;j++){cout << res[i][j] << " ";}cout << "\n";}
#define pb push_back
#define vint vector<int>
const int mod = 1000000007;
using namespace std;
const int maxsize=3005;



void assignee(int &x, int ans)
{
	x += ans;
	x %= mod;
}



int32_t main()
{
	//freopen("input.txt", "r" , stdin);
	int d;	
	string s;
	cin >> s >> d;
	vector<vector<int>> dp(d,vector<int>(2));
	dp[0][0]=1;
	for(int len=0;len<(int)s.length();len++)
	{
		vector<vector<int>> n_dp(d, vector<int>(2));
		for(int sum=0;sum<d;sum++)
		{
			for(bool last_trace : {false, true})
			{
				for(int i=0;i<=9;i++)
				{
					if(i>s[len]-'0' && !last_trace)
						break;
				
				assignee(n_dp[(sum+i)%d][last_trace || i<s[len]-'0'], dp[sum][last_trace]);
				}
			}
		}
		dp =  n_dp;
	}
	int ans;
	ans = (dp[0][0]+dp[0][1])%mod;
	--ans;
	if(ans == -1)
		ans = mod-1;
	
	cout << ans <<"\n";
	return 0;
}


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

int main() {

  int N, K, X, Y;
  cin >> N >> K >> X >> Y;
  if (N < K+1){
  	cout << N * X << endl;
  }
  else {
  	cout << K * X + (N - K) * Y << endl;
  }
  
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
//INSERT ABOVE HERE
signed main(){
  set<int> s;
  int q;
  cin>>q;
  for(int i=0;i<q;i++){
    int t,x;
    cin>>t>>x;
    if(t==0) s.emplace(x);
    if(t==0) cout<<s.size()<<endl;
    if(t==1) cout<<s.count(x)<<endl;
  }
  return 0;
}



Measured memory_bytes: 12360