akhauriyash/Code-Regression huggingface dataset:
import collections

h,w,k=map(int,input().split())
a=[ [c for c in input()] for _ in range(h)]

s=False
for i in range(h):
    for j in range(w):
        if a[i][j]=="S":
            s=(i,j)
            break
    if s:
        break
min_dis=w*h
dq=collections.deque()
dq.append((0,s[0],s[1]))

moved=[[False for _ in  range(w)] for _ in range(h)]
while dq:
    m,y,x=dq.popleft()
    if moved[y][x]:
        continue
    else:
        moved[y][x]=True
    if m>k:
        continue
    if y==0 or y==h-1 or x==0 or x==w-1:
        print(1)
        exit()
    min_dis=min(min_dis, y, h-1-y, x, w-x-1)
    for dy,dx in ((1,0),(0,1),(-1,0),(0,-1)):
        if 0<=y+dy<h and 0<=x+dx<w and a[y+dy][x+dx] == '.' and not moved[y+dy][x+dx]:
            dq.append((m+1, y+dy, x+dx))
print(1+(min_dis+k-1)//k)

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

void solve(long long X, long long Y)
{
    cout << X + Y / 2 << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main()
{
    long long X;
    scanf("%lld", &X);
    long long Y;
    scanf("%lld", &Y);
    solve(X, Y);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#include <functional>
#include <numeric>
#include <iomanip>
#define fi first
#define se second
#define fcout(n) cout<<fixed<<setprecision((n))
#define cinl(str) getline(cin,(str))
using namespace std;
bool value(int y,int x,int R,int C){return 0<=y&&y<R&&0<=x&&x<C;}
typedef pair<int,int> pii;
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long > vll;
typedef vector< vi > vvi;
double pie=acos(-1);
int INF=1000000007;
int dx[4] = { 0,-1,0,1 };
int dy[4] = { -1,0,1,0 };


int main() {
	string s;
	cin>>s;
	s[5]=' ';
	s[13]=' ';
	cout<<s<<endl;
}

Measured memory_bytes: 256
fn main() {
    let a: char = read();
    println!("{}", solve(a));
}

fn read<T: std::str::FromStr>() -> T {
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).ok();
    buf.trim().parse().ok().unwrap()
}

fn solve(c: char) -> char {
    if 'a' <= c && c <= 'z' {
        'a'
    } else {
        'A'
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_solve_1() {
        assert_eq!('A', solve('B'));
    }

    #[test]
    fn test_solve_2() {
        assert_eq!('a', solve('a'));
    }
}


Measured memory_bytes: 2104
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<cstring>
using namespace std;

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

const int MAXN = 1000 * 1000 + 20;

bool p[MAXN];

int main()
{
    p[0] = p[1] = 1;
    REP(MAXN)if(!p[i])for(int j= i*2;j<MAXN;j+=i)p[j] = 1;

    int n;
    while(cin >> n && n)
    {
        int ans = 0;
     
        for(int i=3;i<= n/2 ;i+=2)
        {
            if((!p[i]) && (!p[n - i])) ans++;
        }
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 0
package main

import "fmt"

func main() {
	// Code for B - *e**** ********e* *e****e* ****e**
	var N int
	fmt.Scanf("%d", &N)

	var S string
	fmt.Scanf("%s", &S)

	var K int
	fmt.Scanf("%d", &K)

	for i := 0; i < N; i++ {
		if S[i] != S[K-1] {
			fmt.Printf("*")
		} else {
			fmt.Printf("%c", S[i])
		}
	}
	fmt.Println()
}


Measured memory_bytes: 1836
x = int(input())
import sys
if x == 1:
    print(1, 0)
    sys.exit()
for i in range(x):
    if i ** 5 == x:
        print(i, 0)
        sys.exit()
    for j in range(1, i):
        for j in range(1, i):
            if i ** 5 - (-j) ** 5 == x:
                print(i, -j)
                sys.exit()
            elif i ** 5 - j ** 5 == x:
                print(i, j)
                sys.exit()
            else:
                continue

Measured memory_bytes: 9188
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.IO.Pipes;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;

namespace AtCorders
{
	public class Program
	{
		static void Main(string[] args)
		{
			var nm = Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
			long n = nm[0];
			long m = nm[1];
			if (n == 1 && m == 1) {
				Console.WriteLine(1);
			} else if (n == 1) {
				Console.WriteLine(m - 2);
			} else if (m == 1) {
				Console.WriteLine(n - 2);
			} else {
				long ans = (n - 2) * (m - 2);
				Console.WriteLine(ans);
			}
		}
	}
}

Measured memory_bytes: 13268
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <iomanip>
#include <bitset>
#include <set>
#include <map>
#include <stdio.h>
#include <numeric>
#include <cstring>

#define rep(i,n) for (int i = 0; i < (n); i++)
#define rep1(i,n) for (int i = 1; i < (n); i++)
#define FOR(i,a,b) for (int i=(a); i < (b); i++)
#define MOD 1000000007 //10^9+7
#define TEN5 100000 //10^5
#define TEN9 1000000000 //10^9
using namespace std;
using ll = long long;
using PII = pair<int, int>;
const int INF = numeric_limits<int>::max();

// 負の数にも対応した % 演算
long long mod(long long val, long long m) {
    long long res = val % m;
    if (res < 0) res += m;
    return res;
}

//greatest common divisor
long long gcd(ll a, ll b) 
{
    if (a % b == 0) {
        return b;
    } else {
        return gcd(b, a % b);
    }
}

//least common multiple
long long lcm(ll a, ll b)
{
    return a / gcd(a, b) * b ;
}

int main()
{
    string s; cin >> s;
    string keyence = "keyence";
    int ii = 0;
    int i;
    rep(i,s.length()) {
        rep1(j,s.length()) {
            string tmp = s.substr(0,i) + s.substr(j,s.length());
            if (tmp == keyence) {
                cout << "YES" << endl;
                return 0;
            }
        }
    }
    cout << "NO" << endl;

    return 0;
}



Measured memory_bytes: 256
#include <algorithm>
#include <iterator>
#include <iostream>
#include <iomanip>
#include <cassert>
#include <utility>
#include <string>
#include <vector>
#include <limits>
#include <queue>
#include <cmath>
#include <map>
#include <set>

using namespace std;

using ll = long long;

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

    vector<int> a(n);
    for(int i = 0; i < n; ++i)
        cin >> a[i];

    vector<int> out;
    vector<int> balls(n);
    for(int i = n - 1; i >= 0; --i) {
        int cnt = 0;
        int step = i + 1;
        for(int j = i; j < n; j += step)
            cnt += balls[j];

        if(cnt % 2 == a[i] % 2)
            continue;

        ++balls[i];
        out.push_back(i + 1);
    }

    cout << out.size() << endl;
    if(!out.empty()) {
        copy(out.begin(), out.end(), ostream_iterator<int>(cout, " "));
        cout << endl;
    }
    
    return 0;
}


Measured memory_bytes: 3064
n, m = map(int, input().split())
h = list(map(int, input().split()))
l = [[] for _ in range(n)]
for _ in range(m):
    a, b = map(int, input().split())
    l[a-1].append(h[b-1])
    l[b-1].append(h[a-1])

# print(l)
cnt = 0
for i in range(n):
    if not l[i]:
        cnt += 1
    elif h[i] > max(l[i]):
        cnt += 1
print(cnt)

Measured memory_bytes: 22844
array=[1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
index=int(input())
print(array[index-1])

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define ll long long int
#define pb push_back
#define NO 1000000007
using namespace std;

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

Measured memory_bytes: 256
n = int(input())
num_list = []
for _ in range(n):
    num_list.append(int(input()))

copy =  num_list.copy()
copy.sort()
maximum = copy[-1]
second = copy[-2]

for i in num_list:
    if i == maximum:
        print(second)
    else:
        print(maximum)

Measured memory_bytes: 19164
#include<bits/stdc++.h>
using namespace std;
struct drink
{
	long long sl,dj;
};
bool cmp(drink x,drink y)
{
	return x.dj<y.dj;
}
int main()
{
long long n,m,ans=0;
cin>>n>>m;
drink drinks[n+2];
for(int i=0;i<n;i++)
{
	cin>>drinks[i].dj>>drinks[i].sl;
}
sort(drinks,drinks+n,cmp);
for(int i=0;m>=0;i++)
{
	if(m>=drinks[i].sl)
	{
		ans+=drinks[i].dj*drinks[i].sl;
		m-=drinks[i].sl;
	}
	else
	{
		ans+=drinks[i].dj*m;
        m=0;
		cout<<ans<<endl; 
		return 0;
	}
}
cout<<ans<<endl;
}


Measured memory_bytes: 1792
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define repLRE(i, l, r) for (ll i = (l); i <= (r); ++i)
#define rrepLRE(i, l, r) for (ll i = (l); i >= (r); --i)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, x) \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;

ll dx[9] = {-1, 1, 0, 0, -1, -1, 1, 1, 0};
ll dy[9] = {0, 0, -1, 1, -1, 1, -1, 1, 0};

/* Macros reg. ends here */

const ll INF = 1LL << 50;

int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cout << fixed << setprecision(15);

  ll x;
  cin >> x;

  vll tbl;
  rep(i, 121) tbl.push_back(i * i * i * i * i);

  ll n = tbl.size();
  rep(i, n) rep(j, n) {
    ll a5 = tbl[i], b5 = tbl[j];
    if (a5 - b5 == x) {
      cout << i << " " << j << endl;
      return 0;
    }
    if (a5 + b5 == x) {
      cout << i << " " << -j << endl;
      return 0;
    }
  }

  return 0;
}


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

#define sws ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define INFINITO 1000000000
#define ll long long
#define vi vector<int>
#define pb push_back
#define pii pair<int, int>
#define mp make_pair
#define ff first
#define ss second
#define vvi vector<vi>
#define all(x) x.begin(), x.end()
#define fo(i, n) for( int i = 0; i < n; i++ )


int main() {

    string a, b;
    cin >> a >> b;
    if ( a.size() > b.size() or (a.size() == b.size() and a > b) ) cout << "GREATER\n";
    else if ( a.size() == b.size() and a == b ) cout << "EQUAL\n";
    else cout << "LESS\n";

    return 0;
}

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

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

    string s;
    cin >> s;
    int n = s.size();

    rep(_, n) cout << 'x';
    cout << endl;

    return 0;
}

Measured memory_bytes: 256
import Foundation
 
let number = Int(readLine()!)!

//標準入力二行目以降
var weights = [Int]()
let input_line = readLine()! 

for i in 0..<number {
    let splits = input_line.componentsSeparatedByString(" ") //components(separatedBy:)と実質同じ
	weights.append(Int(splits[i])!)
}

let sumOfWeights = weights.reduce(0, combine: { $0 + $1 }) //重しの総和
var position = 1
var lhsWeight = weights[position - 1]

while sumOfWeights / 2 > lhsWeight {
    position += 1
    lhsWeight += weights[position - 1]
}

if abs(sumOfWeights - (lhsWeight * 2)) <= abs(sumOfWeights - ((lhsWeight - weights[position - 1]) * 2)) {
  print(abs(sumOfWeights - (lhsWeight * 2)))
} else {
  print(abs(sumOfWeights - ((lhsWeight - weights[position - 1]) * 2)))
}

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

#define rep(i, a, n)  for(int i=a; i<n; i++)
#define per(i, a, n)  for(int i=n-1; i>=a; i--)
#define fill0(n)  setfill('0') << right << setw(n)
#define all(x)  (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define MAX 1000000001;
using namespace std;
typedef long long ll;

int n;
int c[600],s[600],f[600];

int main(){
  std::cin >> n;
  rep(i,1,n)std::cin >> c[i] >> s[i] >> f[i];

  rep(i,1,n+1){
    int res = 0;
    rep(j,i,n){
      if(s[j] > res)res = s[j];
      if(res % f[j]!=0) res += (f[j]-(res%f[j]));
      res += c[j];
    }
    std::cout << res << '\n';
  }
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define mod 1000000007
#define ll long long

int main(){
	int n,m;
	ll ans=1;
	cin >> n >> m;
	if(abs(n-m) > 1){ ans = 0; }
	else{
		FOR(i,1,n+1){ ans = (ans*i) % mod; }
		FOR(i,1,m+1){ ans = (ans*i) % mod; }
		if(n == m){ ans = (ans*2) % mod; }
	}
	cout << ans;
	return 0;
}

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

using namespace std;
typedef long long ll;

// #define DEBUG

void kofh(int n, vector<pair<double, double>> &points)
{
    vector<pair<double, double>> new_points;
    double x1, y1, x2, y2, dx, dy, rx, ry;
    double x3, y3, x4, y4, x5, y5;
    for (int i = 0; i < n - 1; i++)
    {
        x1 = points[i].first, y1 = points[i].second;
        x2 = points[i + 1].first, y2 = points[i + 1].second;

        dx = (x2 - x1) / 3, dy = (y2 - y1) / 3;
        rx = (dx - sqrt(3) * dy) / 2, ry = (sqrt(3) * dx + dy) / 2;
        x3 = x1 + dx, y3 = y1 + dy;
        x4 = x3 + rx, y4 = y3 + ry;
        x5 = x2 - dx, y5 = y2 - dy;

        new_points.push_back(make_pair(x1, y1));
        new_points.push_back(make_pair(x3, y3));
        new_points.push_back(make_pair(x4, y4));
        new_points.push_back(make_pair(x5, y5));
    }
    new_points.push_back(make_pair(points[n - 1].first, points[n - 1].second));
    points.clear();
    points = new_points;
    new_points.clear();
}

int main()
{

#ifdef DEBUG
    cout << "DEBUG MODE" << endl;
    ifstream in("input.txt"); //for debug
    cin.rdbuf(in.rdbuf());    //for debug
#endif

    int n;
    cin >> n;
    vector<pair<double, double>> points;
    points.push_back(make_pair(0.0, 0.0));
    points.push_back(make_pair(100.0, 0.0));
    for (int i = 0; i < n; i++)
        kofh(points.size(), points);
    for (auto k : points)
    {
        printf("%.8f %.8f\n", k.first, k.second);
    }

    return 0;
}

// getline(cin,s);
// a = strtok(s, ",");  ","で分解
// for (int i = 0; i < n; i++)


Measured memory_bytes: 3252
import Data.List.Split
main = do
  s <- getContents
  let v = map (map (read::String->Double) . splitOn ",") . lines $ s
  let [x,y] = aux [0.0,0.0] 90.0 v
  putStrLn . show . truncate $ x
  putStrLn . show . truncate $ y

aux :: [Double] -> Double -> [[Double]] -> [Double]
aux [x,y] deg ([di,ai]:xs)
 | di==0 && ai==0 = [x,y]
 | otherwise = aux [x+di*cos(deg*pi/180.0),y+di*sin(deg*pi/180.0)] (deg - ai) xs 

Measured memory_bytes: 4236
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

typedef long long int ll;

#define FOR(i,n,m) for(ll i=(ll)(m);i<(ll)(n);++i)
#define REP(i,n) FOR(i,n,0)
#define IREP(i,n) for(ll i=(ll)(n);i>=0;--i)

const ll MOD = 1000000007;

using namespace std;

int A[200005];
int B[200005];

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

	REP(i, N)
	{
		cin >> A[i];
		B[i] = A[i];
	}
	sort(A, A + N);
	int c1 = A[N / 2 - 1];
	int c2 = A[N / 2];
	REP(i, N)
	{
		if (B[i] <= c1)
		{
			cout << c2 << endl;
		}
		else
		{
			cout << c1 << endl;
		}
	}
	return 0;
}

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

int main() {
	int a,b,c;
	cin >> a >> b;
	c = a + b;
	if (c % 2 == 0) {
		c = c / 2;
	}
	else {
		c = 1 + (c / 2);
	}
	cout << c<< endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        long P = 1000000007;
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        long K = sc.nextInt();
        long [] A = new long[N];
        for (int i=0;i<N;i++){
            A[i] = sc.nextInt();
        }
        long ans = 0;
        for (int i =0;i<N;i++){
            for (int j=i+1;j<N;j++){
                if (A[i] > A[j]){
                    ans += (K+1)*K / 2;
                    ans%=P;
                }
                if (A[i] < A[j]){
                    ans += (K-1)*K / 2;
                    ans%=P;
                }
            }
        }
        System.out.printf("%d\n",ans);
    }
}


Measured memory_bytes: 25568
import bisect

n = int(input())
sl = ['']*n
for i in range(n):
    sl[i] = input()
sl = sorted(sl, key=str.lower)
# print(sl)
c = 0
anss = []
max_n = 0
for i, t in enumerate(sl):
    if i == 0:
        c += 1
        target = t
        continue

    if t == target:
        c += 1
    else:
        if max_n < c:
            anss = []
            anss.append(target)
            max_n = c
        elif max_n == c:
            anss.append(target)
            max_n = c
        target = t
        c = 1

if max_n < c:
    anss = []
    anss.append(t)
elif max_n == c:
    anss.append(t)


print(*anss)


Measured memory_bytes: 109400
#include<bits/stdc++.h>
#include<cmath>
#include<algorithm>
#include<vector>
using namespace std;
int main()
{
	  long long  i,j,n,m;
     int tc;
     
     	long long  odd=0,even=0;
     	
        cin>>n;
          for(i=1;i<=n;i++)
          {
          	if(i%3==0||i%5==0)continue;
          	else odd+=i;
		  }
		  cout<<odd<<endl;
	return 0;
}

Measured memory_bytes: 3636
#include<iostream>

using namespace std;

typedef long long ll;
int main(){
  ll l, r;
  cin >> l >> r;
  r = min(r, l + 4038);
  int ans = 2018;
  for(ll i = l; i <= r; i++){
    for(ll j = i+1; j <= r; j++){
      int x = (i*j)%2019;
      ans = min(ans, x);
    }
  }
  cout << ans << endl;
  return 0;
}


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

N, K = MAP()
p = LIST()

l = 0
r = K
ma = 0
tmp = sum(p[:K])
ma = tmp
for i in range(N-K):
	tmp = tmp - p[i] + p[i+K]
	if tmp > ma:
		ma = tmp
		l = i+1
		r = i+K+1
# print(l, r)

ans = 0

for i in range(l, r):
	ans += (p[i]+1)/2
print(ans)


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

void dfs(int src,vector<vector<int>>& g, vector<int>& vis, vector<int>& dp )
{
    vis[src]=1;
   
    if(g.size()==0)
    {
        dp[src]=1;
        return;
    }
    // cout<<src<<" "<<cs<<endl;
    for(int i=0;i<g[src].size();i++)
    {
        
        if(vis[g[src][i]]==0)
        {
            dfs(g[src][i],g,vis,dp);
        }
         if(g[src].size()!=0)
        {
            dp[src]=max(dp[src],1+dp[g[src][i]]);
            // return;
        }
        
    }
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n,m;
    cin>>n>>m;
    // vector<int> vis(n,0);
    vector<vector<int>> a(m);
    for(int i=0;i<m;i++)
    {
        int x,y;
        cin>>x>>y;
        a[i].push_back(x-1);
        a[i].push_back(y-1);
    }
    vector<vector<int>> ad(n);
    for(int i=0;i<m;i++)
    {
        ad[a[i][0]].push_back(a[i][1]);
    }
    vector<int> vis(n,0);
    vector<int> dp(n,0);
    for(int i=0;i<n;i++)
    {
        if(vis[i]==0)
        {
            dfs(i,ad,vis,dp);
        }
    }
    // cout<<*max_element(dp.begin(),dp.end())<<endl;
    int ans=0;
    for(int i=0;i<n;i++)
        ans=max(ans,dp[i]);
    cout<<ans<<endl;

    

}

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

using namespace std;
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

int main() {

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

    vector<vector<int>> g(n);
    for (int i = 0; i < m; ++i) {
        int a, b; cin >> a >> b;
        --a; --b;

        g[a].push_back(b);
        g[b].push_back(a);
    }

    vector<int> dist(n, INF);
    vector<int> pre(n, -1);

    queue<int> q;
    dist[0] = 0;
    q.push(0);

    while (!q.empty()) {
        int v = q.front(); q.pop();

        for (auto t : g[v]) {
            if (dist[t] != INF) continue;

            dist[t] = dist[v] + 1;
            pre[t] = v;
            q.push(t);
        }
    }

    cout << "Yes" << endl;
    for (int i = 0; i < n; ++i) {
        if (i == 0) continue;

        cout << pre[i] +  1 << endl;
    }
}

Measured memory_bytes: 10628
import java.util.Scanner;

public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        
        Scanner s = new Scanner(System.in);
        int n = s.nextInt();
        int[] ds = new int[n];
        int sum = 0;
        
        for (int i = 0; i < n; i ++)
        {
            ds [i] = s.nextInt();
            
            for (int j = 0; j < i; j ++) {
                sum += ds [j] * ds [i];
            }
        }
        
        System.out.println (sum);
    }
    
}


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

// string s = "dreameraser";
string s;
string target[] = {"dreamer", "eraser", "dream", "erase"};

int main() {
    int pos = 0;
    int len = 0;
    
    cin >> s;
    while (s.size() > 0) {
        // printf("%s\n", s.c_str());
        int flag = false;
        for (int i = 0; i < 4; i++) {
            pos = s.rfind(target[i]);
            len = target[i].length();
            if (pos != std::string::npos && pos + len == s.length()) {
                flag = true;
                s.replace(pos, len, "");
                break;
            }
        }

        if (flag == false) {
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;    
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize ("-ffloat-store") // to restrict undesirable precision
#pragma GCC optimize ("-fno-defer-pop")// to pop argument of function as soon as it returns
#define all(a) a.begin(),a.end()
#define ll long long int
#define ld long double
ll power(ll a,ll b,ll m){ if(b==0) return 1; if(b==1) return a%m; ll t=power(a,b/2,m)%m; t=(t*t)%m; if(b&1) t=((t%m)*(a%m))%m; return t;}
ll modInverse(ll a, ll m) { return power(a, m-2, m); }
#define ps push_back
#define fs first
#define sc second
#define takeline cin.ignore();
#define iactive cout.flush();
#define N 3000005
#define endl "\n"
#define mod 1000000007
//((1.0l)*BIG MULTIPLY MAGIC?)
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
//-----------------------------------------------
int main(){

    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    
    ll i,j,k,l,n;
    cin>>n;
    ll ar[n+1],fl[n+1]={0};
    for(i=2;i<=n;i++){
        cin>>ar[i];
        fl[ar[i]]++;
    }
    for(i=1;i<=n;i++){
        cout<<fl[i]<<endl;
    }
    return 0;
}

Measured memory_bytes: 6784
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

#define int long long

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

        sort(a.begin(), a.end());
        sort(c.begin(), c.end());

        int ans = 0;
        for(int i = 0; i < n; i++) {
                int idx_a = lower_bound(a.begin(), a.end(), b[i]) - a.begin();
                int idx_c = c.end() - upper_bound(c.begin(), c.end(), b[i]);
                ans += idx_a * idx_c;
        }
    
        cout << ans << endl;
        return 0;
}

Measured memory_bytes: 2560
n = int(input())
ln = len(str(n))
if ln == 1:
    print(n)
elif ln == 2:
    print(9)
elif ln == 3:
    print(n-99+9)
elif ln == 4:
    print(900+9)
elif ln == 5:
    print(n-9999+909)
elif ln == 6:
    print(90909)


Measured memory_bytes: 2940
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        
        
        
        int h1 = Integer.parseInt(sc.next());
        int m1 = Integer.parseInt(sc.next());
        int h2 = Integer.parseInt(sc.next());
        int m2 = Integer.parseInt(sc.next());
        int k = Integer.parseInt(sc.next());
        
        int H = h2 - h1;
        int M = 0;
        if(m1 <= m2) {
            M = m2 - m1;
        }else {
            H--; 
            M = (60-m1) + m2;
        }
        int ans = H * 60 + M - k;
        System.out.println(ans);
    }   
}


Measured memory_bytes: 35712
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
 
#define int long long
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF 1001001001001001001ll
#define fcout cout << fixed << setprecision(10)
 
using namespace std;
 
signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int N, M;
    cin >> N >> M;
    vector<pair<pair<int, int>, int>> v;
    vector<int> vp(M);
    REP(i, M) {
        int p, y;
        cin >> p >> y;
        vp[i] = p;
        v.push_back({{p, y}, i});
    }
    sort(v.begin(), v.end());
 
    map<int, int> order;
    int o = 1;
    int prev = v[0].first.first;
    REP(i, v.size()) {
        auto vv = v[i];
        if (vv.first.first != prev) {
            o = 1;
        }
        order[vv.second] = o;
        o++;
        prev = vv.first.first;
    }
 
    REP(i, M) {
        printf("%06lld", vp[i]);
        printf("%06lld", order[i]);
        cout << endl;
    }
 
    return 0;
}

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

#define pb push_back
#define mp make_pair
#define ll long long
#define inf 10e8

using namespace std;

int inDegree[100005];
bool visited[100005];
int dp[100005];

void init(int *a, int size){
	for (int i = 0; i <= size; ++i)
	{
		a[i] = 0;
	}
}

void init(bool *a, int size){
	for (int i = 0; i <= size; ++i)
	{
		a[i] = false;
	}
}

void maxdp(vector<int>* g, int inDegreeSize){
	queue<int> q;
	for (int i = 1; i <= inDegreeSize; ++i)
	{
		if(!visited[i] && inDegree[i]==0){
			q.push(i);
			visited[i] = true;
		}
	}

	
	while(!q.empty()){
		int t = q.front();
		q.pop();
		// printf("q front %d\n", t);
		for (int i = 0; i < g[t].size(); ++i)
		{
			inDegree[g[t][i]]--;
			dp[g[t][i]] = max(dp[g[t][i]], 1+dp[t]);
			if (inDegree[g[t][i]] == 0)
			{
				q.push(g[t][i]);
				visited[g[t][i]] = true;
			}
		}
	}

}

void dfs(vector<int> *g, int a){
	visited[a] = true;
	// vector<int>::iterator it;
	// for(it = g[a].begin(); it !=g[a].end(); it++){
	for (int i = 0; i < g[a].size(); ++i){
		inDegree[g[a][i]]--;
		dp[g[a][i]] = max(dp[g[a][i]], 1+dp[a]);
		if (inDegree[g[a][i]] == 0)
		{
			dfs(g, g[a][i]);
		}
	}
}

void addEdge(vector<int> adj[], int start, int end/*, int wt*/){
	// printf("pusing start %d in end %d\n", start, end);
	adj[start].pb(end);
	inDegree[end]++;
	// adj[end].pb(start);
}

void printGraph(vector<int> g[], int nodes){
	printf("nodes \n");
	for (int i = 0; i <= nodes; ++i)
	{
		for (int j = 0; j < g[i].size(); ++j)
		{
			printf("%d, %d \n",i, g[i][j]);
		}
	}
}

void takeEntry(vector<int>*g/*, int nodes*/){
	int start, end;
	scanf("%d%d", &start, &end);
	addEdge(g, start, end);
	// printGraph(g, nodes);
}

// EDIT INPUT IN graphInput.txt

int main(int argc, char const *argv[])
{
	int nodes, edges,  wt;
	
	cin>>nodes>>edges;


	init(inDegree, nodes+1);
	init(dp,  nodes+1);
	init(visited,  nodes+1);

	vector<int> g[nodes+1];

	// vector<pair<int, int> >	adj[nodes+1];
	
	for (int i = 0; i < edges; ++i)
	{
		takeEntry(g /*, nodes*/);
	}

	// printGraph(g, nodes);

	// for (int i = 1; i <= nodes; ++i){
	// 	if (!visited[i] && inDegree[i] ==0){
	// 		dfs(g, i);
	// 	}		
	// }	
	// printf("entry done\n");
	int nax = -1;
	maxdp(g, nodes);
	for (int i = 1; i <= nodes; ++i)
	{
		if (dp[i] > nax)
		{
			nax = dp[i];
		}
	}
	printf("%d\n", nax);
	return 0;
}




Measured memory_bytes: 6656
#include <stdio.h>
int main() {
  char base;
  scanf("%c",&base);
  switch (base)	{
  case 'A':
    printf("T\n");
    break;
  case 'T':
    printf("A\n");
    break;
  case 'G':
    printf("C\n");
    break;
  default:
    printf("G\n");
  }
  return 0;
}

Measured memory_bytes: 128
import java.util.*;

class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int kna = sc.nextInt();
        int knb = sc.nextInt();
        int cca = sc.nextInt();
        int ccb = sc.nextInt();
        
        for(int i = 0;i < kna;i++)
            cca = Math.max(cca,sc.nextInt());
        for(int i = 0;i < knb;i++)
            ccb = Math.min(ccb,sc.nextInt());

        System.out.println(cca < ccb?"No War":"War");
        

        
    }
}

Measured memory_bytes: 21716
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
using namespace std;

int w, a, b;

int main(){
  ios_base::sync_with_stdio(false);
  
  int ans = 0;
  
  cin >> w >> a >> b;
  
  if(b < a)swap(a, b);
  
  ans = b - (a + w);
  
  if(ans < 0)ans = 0; 

  cout << ans << endl;

  return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define srt(a) sort(a.begin(),a.end())
#define rsrt(a) sort(a.rbegin(),a.rend())
#define lb(a,b) lower_bound(a.begin(),a.end(),b)
#define ub(a,b) upper_bound(a.begin(),a.end(),b)
#define MOD ((int)(1e9+7))
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long
#define float long double
#define sqrt sqrtl
#define cbrt cbrtl
typedef vector<int> vi;
typedef vector<float> vf;
typedef pair<float,int> fi;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef vector<fi> vfi;
typedef vector<vi> vvi;
typedef vector<vf> vvf;
typedef vector<vii> vvii;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef priority_queue<int> pqi;
typedef priority_queue<ii> pqii;
typedef priority_queue<fi> pqfi;
typedef priority_queue <int, vector<int>, greater<int> > rpqi; 
typedef priority_queue <ii, vector<ii>, greater<ii> > rpqii; 
typedef priority_queue <fi, vector<fi>, greater<fi> > rpqfi; 


int32_t main()
{
	IOS
	int r;cin>>r;
	if(r<1200){
		cout<<"ABC"<<endl;
	}
	else if(r<2800){
		cout<<"ARC"<<endl;
	}
	else cout<<"AGC"<<endl;
}
			
	


Measured memory_bytes: 256
let () =
  Scanf.scanf "%d\n" @@ fun n ->
  let lst = Array.to_list
      (Array.init n @@ fun _ -> Scanf.scanf "%d " @@ fun d -> d) in
  let (ans,_) = List.fold_left
      (fun (a,bfr) x -> if x < bfr then (a+(bfr-x),bfr) else (a,x))
      (0, List.hd lst) (List.tl lst) in
  Printf.printf "%d\n" ans

Measured memory_bytes: 12200
#include<bits/stdc++.h>
using namespace std;
int main(){
  long long a,b,c,d,x,y=0,n;
  char s[100];
  cin>>a>>b>>c>>d;
  if(a*b>=c*d)
    cout<<a*b<<endl;
  else
    cout<<c*d<<endl;
  return(0);
}

Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <set>
#include <deque>
#include <utility>

int dp[10000];
int main(){
  int N, M;
  scanf("%d", &N);
  scanf("%d", &M);
  std::vector<int > a(M), b(M);
  std::vector<int > c[1004];
  int cc;
  for (int i=0 ;i<M; i++){
    scanf("%d", &a[i]);
    scanf("%d", &b[i]);
    for (int j=0 ;j<b[i]; j++){
      scanf("%d", &cc);
      cc--;
      c[i].push_back(cc);
    }
  }

  for (int i=0; i<10000; i++){
    dp[i]=1000000005;
  }
  
  dp[0]=0;
  
  for (int i=0; i<5000; i++){
  //for (int i=0; i<30; i++){
    //printf("====i=%d====\n", i);
    for (int j=0; j<M; j++){
      int s=i;
      for (int k=0; k<b[j]; k++){
	s = s|(1<<c[j][k]);
      }
      dp[s]=std::min(dp[i]+a[j], dp[s]);
      //printf("dp[%d]=%d\n", s, dp[s]);
    }
  }
  printf("%d\n", (dp[(1<<N)-1]==1000000005)?-1:dp[(1<<N)-1]);
  return 0;
}


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

int main()
{
	int a, b, c;
	cin >> a >> b >> c;
	for(int i = 0; i <= 50000000; i ++)
	{
		if(a % 2 == 1 || b % 2 == 1 || c % 2 == 1) {cout << i << endl; return 0;}
		int aa = a, bb = b, cc = c;
		a = bb / 2 + cc / 2;
		b = aa / 2 + cc / 2;
		c = aa / 2 + bb / 2;
	}
	cout << -1 << endl;
}


Measured memory_bytes: 256
#input
#N ari  L nagasa T byou
#X ari iti W muki
import numpy as np
N,L,T = map(int,input().split())
ari_list = []
for i in range(N):
    z = list(map(int,input().split()))
    ari_list.append(z)
#print(ari_list)
counter = 0

#syori

for i in range(N):
    if ari_list[i][1] == 1:
        enzan = 1
    else:
        enzan = -1
    m = ari_list[i][0] + T * enzan
    m_kiri = m % L
    ari_list[i][0] = m_kiri 
    counter = counter - (m-m_kiri)/L

#print(counter)
#sort

sort_list = []
for i in range(N):
    sort_list.append(ari_list[i][0])
sort_list.sort()
answer_list = np.roll(sort_list,int(counter))
for i in answer_list:
    print(i)

Measured memory_bytes: 36568
use std::process;
macro_rules! get {
      ($t:ty) => {
          {
              let mut line: String = String::new();
              std::io::stdin().read_line(&mut line).unwrap();
              line.trim().parse::<$t>().unwrap()
          }
      };
      ($($t:ty),*) => {
          {
              let mut line: String = String::new();
              std::io::stdin().read_line(&mut line).unwrap();
              let mut iter = line.split_whitespace();
              (
                  $(iter.next().unwrap().parse::<$t>().unwrap(),)*
              )
          }
      };
      ($t:ty; $n:expr) => {
          (0..$n).map(|_|
              get!($t)
          ).collect::<Vec<_>>()
      };
      ($($t:ty),*; $n:expr) => {
          (0..$n).map(|_|
              get!($($t),*)
          ).collect::<Vec<_>>()
      };
      ($t:ty ;;) => {
          {
              let mut line: String = String::new();
              std::io::stdin().read_line(&mut line).unwrap();
              line.split_whitespace()
                  .map(|t| t.parse::<$t>().unwrap())
                  .collect::<Vec<_>>()
          }
      };
      ($t:ty ;; $n:expr) => {
          (0..$n).map(|_| get!($t ;;)).collect::<Vec<_>>()
      };
}
fn main() {
    let a = get!(usize);
    let b = get!(usize);

    if a == 1 && b == 2 {
        println!("3");
    }
    if a == 2 && b == 1 {
        println!("3");
    }
    if a == 1 && b == 3 {
        println!("2");
    }
    if a == 2 && b == 3 {
        println!("1");
    }
    if a == 3 && b == 1 {
        println!("2");
    }
    if a == 3 && b == 2 {
        println!("1");
    }
}


Measured memory_bytes: 4352
n =int(input())
p = list(map(int,input().split()))
cnt = 0
p_sorted = sorted(p)
for i in range(n):
  if p[i] == p_sorted[i]:
    pass
  else:
    cnt += 1
if cnt == 0 or cnt ==2:
  print('YES')
else:
  print('NO')
  

Measured memory_bytes: 3060
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <numeric>
using namespace std;
typedef long long int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

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


int main() {
  int A, P;
  cin >> A >> P;

  int ans = (A * 3 + P) / 2;

  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<iomanip>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
#define LINF (long long)4e18

using ll = long long;


int main(){
  string S; cin >> S;
  vector<int> a(100000);
  rep(i,4){
    a[S[i] - '0']++;
  }
  int cnt = 0;
  bool ok = false;
  rep(i,100000){
    if(a[i] == 2) cnt++;
  }
  if(cnt == 2) ok = true;
  if(ok) cout << "Yes" << endl;
  else cout << "No" << endl;

}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int main () {
	int N,M;
	cin >> N >> M;
	bool didDestroyedBridge[N];
    for(int i = 0; i < N; i++)didDestroyedBridge[i] = false;
	vector<pair<int,int>> isls(M);
	for(int i = 0; i < M; i++){
		int a,b;
		cin >> a >> b;
		isls[i].first = a;
		isls[i].second = b;
	}
std::sort(isls.begin(), isls.end(), [](auto &left, auto &right) {
    return left.second < right.second;
});
    for(int i = 0; i < M; i++){
    	bool tmp = false;
    	for(int j = isls[i].first; j < isls[i].second; j++){
    		if(didDestroyedBridge[j]){tmp = true;break;}
    	}
    	if(!tmp){
    		didDestroyedBridge[isls[i].second-1] = true;
    	}
    }
    int rslt = 0;
    for(int i = 0; i < N; i++){
    	if(didDestroyedBridge[i])rslt += 1;
    }
    cout << rslt << endl;
}

Measured memory_bytes: 1152
// https://atcoder.jp/contests/abc165/tasks/abc165_c
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define DIV(a, b) ((a - 1) / b + 1)

struct FOUR {
    int a, b, c, d;
};
int N, M, Q, ans;
vector<FOUR> D;
void dfs(vector<int> &A) {
    if ((int)A.size() == N) {
        int sum = 0;
        for (auto &x : D) {
            if (A[x.b - 1] - A[x.a - 1] == x.c) {
                sum += x.d;
            }
        }
        ans = max(ans, sum);
        return;
    }

    FOR(i, (A.size() > 0 ? A.back() : 0), M) {
        A.push_back(i);
        dfs(A);
        A.pop_back();
    }
}
signed main() {
    cin >> N >> M >> Q;
    D.resize(Q);
    for (auto &x : D) {
        cin >> x.a >> x.b >> x.c >> x.d;
    }
    vector<int> A;
    dfs(A);
    cout << ans << endl;
    return 0;
}

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

void read(int &x) {
    x=0;int f=1;char ch=getchar();
    for(;!isdigit(ch);ch=getchar()) if(ch=='-') f=-f;
    for(;isdigit(ch);ch=getchar()) x=x*10+ch-'0';x*=f;
}

void print(int x) {
    if(x<0) putchar('-'),x=-x;
    if(!x) return ;print(x/10),putchar(x%10+48);
}
void write(int x) {if(!x) putchar('0');else print(x);putchar('\n');}

#define lf double
#define ll long long 

#define pii pair<int,int >
#define vec vector<int >

#define pb push_back
#define mp make_pair
#define fr first
#define sc second

#define data asd09123jdf02i3h

#define FOR(i,l,r) for(int i=l,i##_r=r;i<=i##_r;i++)

const int maxn = 1e6+10;
const int inf = 1e9;
const lf eps = 1e-8;
const int mod = 1e9+7;

int n;
vector<pii > ans;

int main() {
    read(n);
    if(n&1) {
        for(int i=1;i<=n-1;i++)
            for(int j=i+1;j<=n;j++)
                if(j!=n-i) ans.pb(mp(i,j));
    } else {
        for(int i=1;i<=n;i++)
            for(int j=i+1;j<=n;j++)
                if(j!=n+1-i) ans.pb(mp(i,j));
    }
    write(ans.size());
    for(auto v:ans) printf("%d %d\n",v.fr,v.sc);
    return 0;
}


Measured memory_bytes: 384
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cmath>

using namespace std;

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

const double EPS = 1e-10;
const int INF = 1e7;

int main(){
  int a, b, c, x, y;
  scanf("%d%d%d%d%d", &a, &b, &c, &x, &y);
  int min_xy = min(x, y);
  int sum_val = 0;
  if ((a + b) > c*2) {
    x -= min_xy;
    y -= min_xy;
    sum_val += 2 * c * min_xy;
  }
  if (a > c*2 && x > 0) {
    sum_val += 2 * c * x;
    y -= x;
    x = 0;
  }
  if (b > c*2 && y > 0) {
    sum_val += 2 * c * y;
    x -= y;
    y = 0;
  }

  if (x > 0) {
    sum_val += x * a;
  }
  if (y > 0) {
    sum_val += y * b;
  }
  

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


Measured memory_bytes: 256
#input

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parent = list(range(n))
        self.rank = [1] * n
        self.grp = n
    
    def root(self,x):
        if self.parent[x] == x :
            return x
        else :
            self.parent[x] = self.root(self.parent[x])
            return self.parent[x]
    
    def same(self,x,y):
        return self.root(x) == self.root(y)
    
    def unite(self,x,y):
        x = self.root(x)
        y = self.root(y)
 
        if x == y:
            return
        if self.rank[x] < self.rank[y]:
            self.parent[x] = y
        else :
            self.parent[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1
        self.grp -= 1
        

def input_1():
    n, m = map(int,input().split())
    brg = [tuple(map(int,input().split())) for i in range(m)]
    return n,m,brg

def input_2(n):
    brg = [( 2*i-1 , 2*i ) for i in range(1,int(n/2))]
    return n,int(n/2)-1,brg

def main():
    n,m,brg = input_1()
    #n,m,brg = input_2(100000)
    uf = UnionFind(n)
    for i in range(m):
        uf.unite(brg[i][0]-1,brg[i][1]-1)
    
    print(uf.grp-1)


if __name__ == '__main__':
    main()

Measured memory_bytes: 27148
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
typedef long long ll;
int main(void){
  int N;
  cin >> N; bool OK = false; 
  for(int i = 0; i <= N / 4; i++){
      for(int j = 0; j <= N / 7; j++){
          if(4 * i + 7 * j == N) OK = true;
      }
  }
  if(OK == false) cout << "No" << endl;
  else cout << "Yes" << endl;
  return 0;
}

Measured memory_bytes: 3588
// ABC154A - Remaining Balls

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

int main() {
	string S, T, U;
	int A, B;

	cin >> S >> T >> A >> B >> U;

	if (S == U) {
		A--;
	} else { // T == U
		B--;
	}

	cout << A << " " << B << endl;

	return 0;
}


Measured memory_bytes: 256
import math as mt
import itertools as it
import functools as ft
import random as rnd

stdin = lambda type_ = "int", sep = " ": list(map(eval(type_), input().split(sep)))
joint = lambda sep = " ", *args: sep.join(str(i) if type(i) != list else sep.join(map(str, i)) for i in args)

s = input()

if len(s) < 7:
    print('NO')
else:
    for i in range(0, 8):
        if s[:i] + s[-7 + i:] == 'keyence':
            print('YES')
            exit(0)
    print("NO") 

Measured memory_bytes: 5844
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

#include <iostream>

int main()
{
    for (int i = 1; i < 6; i++)
    {
        int j;
        cin >> j;
        if (j != i)
        {
            cout << i;
        }
    }
        
}

Measured memory_bytes: 3596
#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>
#include<map>
using namespace std;

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

    vector<long long> s(N + 1);
    map<long long, long long> m;
    s[0] = 0;
    m[0] = 1;
    for (int i = 1; i <= N; i++) {
        s[i] = s[i - 1] + A[i - 1];
        m[s[i]] += 1;
    }

    long long ans = 0;
    for (auto cur : m) {
        ans += cur.second * (cur.second - 1) / 2;
    }
    cout << ans << endl;
}


Measured memory_bytes: 15872
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a , b ;
  cin >> a >> b ;
    a*=b;
  a%=2;
    
  if (a == 0) {
    cout << "Even" << endl;
  }
    else {
      cout << "Odd" << endl;
  }
}


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

using i4 = std::array<int64_t, 3>;
using vi = std::vector<int64_t>;
using v2i = std::vector<vi>;
using v3i = std::vector<v2i>;
using v4i = std::vector<v3i>;
using v5i = std::vector<v4i>;

constexpr int64_t mod{1'000'000'007};

// trueならend
std::vector<std::vector<std::pair<bool, int>>> rules;

int N[4], m, N_sum{};
v2i countDP;
v4i dp;
char DNA[8]{"ATGC"};
vi set_digit;

int64_t rc(int);
bool countRec(int);

int main()
{
	std::map<std::string, int> ruleMap;
	std::vector<std::vector<std::string>> ruleString;
	for (int i{}; i < 4; i++)
	{
		scanf("%d", N + i);
		N_sum += N[i];
	}
	scanf("%d", &m);
	std::string input;
	while (!(std::cin >> input).eof())
	{
		if (input.back() == ':')
		{
			input.pop_back();
			int num{(int)ruleMap.size()};
			ruleMap[input] = num;
			ruleString.push_back({});
		}
		else
			ruleString.back().push_back(input);
	}
	rules.resize(m);
	for (int i{}; i < m; i++)
		for (auto& e: ruleString[i])
		{
			if (e.front() != '[')
				rules[i].push_back({false, ruleMap[e]});
			else
			{
				bool used[4]{};
				for (auto& f: e)
					for (int i{}; i < 4; i++)
						if (f == DNA[i])
						{
							used[i] = true;
							break;
						}
				int num{};
				for (int i{}; i < 4; i++)
					if (used[i])
						num += 1 << i;
				rules[i].push_back({true, num});
			}
		}
	
	countDP.resize(m, vi(1 << 4, -1));
	if (!countRec(0))
	{
		puts("0");
		return 0;
	}
	int sum{};
	for (auto& e: countDP[0])
		sum += e;
	if (sum != N_sum)
	{
		puts("0");
		return 0;
	}
	for (int i{}; i < 4; i++)
	{
		N_sum -= countDP[0][1 << i];
		N[i] -= countDP[0][1 << i];
		countDP[0][1 << i] = 0;
		if (N[i] < 0)
		{
			puts("0");
			return 0;
		}
	}
	for (int i{}; i < (1 << 4); i++)
		set_digit.resize(set_digit.size() + countDP[0][i], i);
	dp.resize(set_digit.size(), v3i(N[0] + 1, v2i(N[1] + 1, vi(N[2] + 1, -1))));
	printf("%lld\n", rc(0));

	return 0;
}

bool countRec(int index)
{
	if (countDP[index].front() >= 0) return true;
	std::fill(countDP[index].begin(), countDP[index].end(), 0);
	for (auto& e: rules[index])
	{
		if (e.first)
			countDP[index][e.second]++;
		else
		{
			if (!countRec(e.second))
				return false;
			for (int i{}; i < (1 << 4); i++)
				countDP[index][i] += countDP[e.second][i];
		}
	}
	int sum{};
	for (auto& e: countDP[index])
		sum += e;
	return sum <= N_sum;
}

int64_t rc(int index)
{
	if (index == (int)set_digit.size()) return 1;
	auto& now{dp[index][N[0]][N[1]][N[2]]};
	if (now >= 0) return now;
	now = 0;
	for (int i{}; i < 4; i++)
	{
		if (~set_digit[index] >> i & 1) continue;
		if (N[i] == 0) continue;
		N[i]--;
		now = (now + rc(index + 1)) % mod;
		N[i]++;
	}
	return now;
}


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

int main()
{
	int a, b, c, d, e;
	cin >> a >> b >> c >> d >> e;
	int i, j, k, l, m;
	i = (a + 9) / 10 * 10;
	j = (b + 9) / 10 * 10;
	k = (c + 9) / 10 * 10;
	l = (d + 9) / 10 * 10;
	m = (e + 9) / 10 * 10;
	cout << min(a + j + k + l + m, min(i + b + k + l + m, min(i + j + c + l + m, min(i + j + k + d + m, i + j + k + l + e)))) << endl;
	return 0;
}

Measured memory_bytes: 256