akhauriyash/Code-Regression huggingface dataset:
#![allow(non_snake_case)]
#[allow(unused_imports)]
use std::io::{self, Write};
#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};
    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };
    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };
    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };
    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
     };
     ($next:expr, $t:ty) => {
         $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(dead_code)]
const MOD: u64 = 1000000007;


fn digit_sum(n: i64, b: i64) -> i64 {
    if n < b {
        n
    } else {
        digit_sum((n as f64/b as f64).floor() as i64, b) + (n % b)
    }
}


fn main() {
    input!{
        n: usize,
        s: usize,
    }

    let ce = (n as f64).sqrt().ceil() as usize;

    if n == s {
        println!("{}", n+1);
    } else if n < s {
        println!("-1");
    } else {

        let mut ans: i64 = -1;

        for p in (1..ce+1).rev() {
            if (n - s) % p != 0 {
                continue;
            }
            let b = (n - s) / p + 1;
            if digit_sum(n as i64, b as i64) == s as i64 {
                ans = b as i64;
                break;
            }
        }

        for b in 2..ce+1 {
            let ret = digit_sum(n as i64, b as i64);
            if ret == s as i64 {
                ans = b as i64;
                break;
            }
        }

        println!("{}", ans);

    }


}

Measured memory_bytes: 4352
var
	N,i,j:Longint;
	ans:int64;
begin
	read(N);
	j:=round(sqrt(N));
	if j*j>N then dec(j);
	for i:=1 to j do inc(ans,(N div i)*(N div i+1)*i-i*i*i);
	writeln(ans);
end.

Measured memory_bytes: 1356
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define N 100
#define MAX(A,B) ((B) > (A) ? (B) : (A))

static int n;
static char d[N];

static int h['Z' - 'A' + 2];

int main(void) {
  int i, j;

  for (;;) {
    scanf(" %d", &n);
    if (n == 0) break ;
    for (i = 0; i < n; ++i)
      scanf(" %c", &d[i]);
    memset(h, 0, sizeof(h));

    for (i = 0; i < n; ++i) {
      int u = 'Z' + 1, v = 'Z' + 1;
      
      h[d[i] - 'A'] += 1;
      for (j = 'A'; j <= 'Z'; ++j) {
        if (h[u - 'A'] < h[j - 'A']) {
          v = u;
          u = j;
        } else if (h[v - 'A'] < h[j - 'A']) {
          v = j;
        }
      }
      if (h[v - 'A'] + n - i - 1 < h[u - 'A']) {
        printf("%c %d\n", u, i + 1);
        break ;
      }
    }
    if (i == n)
      puts("TIE");
  }

  return EXIT_SUCCESS;
}

Measured memory_bytes: 612
#include <cstdio>
#include <iostream>
using namespace std;
int N, Q, arr[100005], Sum[100005];
char S[100005];

int main()
{
    scanf("%d %d %s", &N, &Q, S);
    for(int i = 0; i < N; i++)
    {
        if(S[i] == 'A' && S[i + 1] == 'C')
        {
            arr[i] = 1;
            i++;
        }
    }
    for(int i = 1; i <= N; i++)
    {
        Sum[i] = Sum[i - 1] + arr[i - 1];
    }
    for(int i = 0; i < Q; i++)
    {
        int l, r;
        scanf("%d %d", &l, &r);
        printf("%d\n", Sum[r - 1] - Sum[l - 1]);
    }
}

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

#if DEBUG && !ONLINE_JUDGE
  #include "header.h"
#else
  #define debug(args...)
#endif

typedef vector<int> vi;
typedef pair<int,int> ii;
typedef long long lli;
typedef long double ld;

#define pb push_back
#define all(x) x.begin(),x.end()
#define SZ(x) (int)(x).size()
#define fi first
#define se second
#define lb lower_bound
#define ub upper_bound
#define rep(i,a,b) for(auto i=(a);i<b;i++)

#define INF (int)1e9
#define EPS 1e-9
#define MOD 1000000007
void preprocess(void) {
  return;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.precision(20);
  preprocess();
  int h, w, n; cin>>h>>w>>n;
  int ans = MOD;
  rep(r,0,h+1) {
    rep(c,0,w+1) {
      int p = r * w + c * h - r * c;
      if(p >= n) {
        ans = min(ans, r + c);
      }
    }
  }
  cout<<ans<<endl;
}



Measured memory_bytes: 256
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>
#include <random>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;;
#define MEM(a,b) memset((a),(b),sizeof(a))
const LL INF = 1e9 + 7;
const int N = 1e2 + 10;

int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	double t, x;
	cin >> t >> x;
	printf("%.15f\n", t / x);
	return 0;
}


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

int main()
{
    string s, m;
    cin >> s;
    m = s.at(5);
    m += s.at(6);
    int im;
    im = stoi(m);
    if (im <= 4)
        cout << "Heisei" << endl;
    else
        cout << "TBD" << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
 


long long int minx(long long int v[],int n){
	int i,j,k;
	long long int tmp;
	tmp=v[0];
	for(i=1;i<=n-1;i++){
		if(tmp>v[i])
		tmp=v[i];}
		return tmp;}
int maxx(int v[],int n){
	int i,j,k,tmp;
	tmp=v[0];
	for(i=1;i<=n-1;i++){
		if(tmp<v[i])
		tmp=v[i];}
		return tmp;}
int max(int n1,int n2,int n3){
	int tmp;
	tmp=n1;
	if(n2>tmp)
	tmp=n2;
	if(n3>tmp)
	tmp=n3;
	return tmp;}
int max2(int n1,int n2){
	int tmp;
	tmp=n1;
	if(n2>tmp)
	tmp=n2;
	return tmp;}
int min3(int n1,int n2,int n3){
	int tmp;
	tmp=n1;
	if(n2<tmp)
	tmp=n2;
	if(n3<tmp)
	tmp=n3;
	return tmp;}
int min2(int n1,int n2){
	int tmp;
	tmp=n1;
	if(n2<tmp)
	tmp=n2;
	return tmp;}
long long int abs(long long int n){
	if(n>=0)
	return n;
	else return(-1)*n;
}
int main(void)
{int N,A,M,B,j,i,k,H,W,l,m,flag;
	long long int sum,min;
	scanf("%d",&N);
	long long int a[200000];
	long long int x[200000];
	long long int diff[200000];
	flag=0;
	sum=0;
	for(i=0;i<=N-1;i++){
		scanf("%lld",&a[i]);}
	x[0]=a[0];
	for(j=0;j<=N-1;j++){
		sum+=a[j];}
	for(l=0;l<=N-2;l++){
			x[l+1]=x[l]+a[l+1];
			diff[l]=abs(sum-2*x[l]);}
	printf("%lld",minx(diff,N-1));



	return 0;
}


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

#define MOD 1000000007
using namespace std;

long long v[105], dp[105][100005], sum[100005];

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    int n, k;
    cin >> n >> k;

    for(int i = 1; i <= n; ++i)
        cin >> v[i];

    dp[0][0] = 1;
    for(int i = 1; i <= n; ++i){
        memset(sum, 0, sizeof(sum));
        for(int j = 0; j <= k; ++j)
            sum[j + 1] += sum[j] + dp[i - 1][j];
        for(int j = 0; j <= k; ++j)
            dp[i][j] = (sum[j + 1] - sum[max(0LL, j - v[i])]) % MOD;
    }
    cout << dp[n][k] << '\n';
    return 0;
}


Measured memory_bytes: 79360
import math
from collections import *
import sys
inp=sys.stdin.readline

def linp(x):
    return list(map(int,x.split()))
def minp(x):
    return map(int,x.split())
    
def main():
    n=int(inp())
    l =linp(inp())
    c=0
    for i in range(1,n+1):
        if i%2 == 1 and l[i-1]%2==1:
            c+=1
    print(c)



if __name__ == "__main__":
    main()

Measured memory_bytes: 9464
#include <iostream>
#include <cstdio>

int main(int argc, const char * argv[])
{
    int month[12] = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
    int m, d;
    while (scanf("%d %d", &m, &d) != 0) {
        int cnt = 0;
        if (m == 0 && d == 0) {
            return 0;
        }
        for (int i = 0; i < m - 1; i++) {
            cnt += month[i];
        }
        cnt += d;

        if (cnt % 7 == 0) {
            printf("Wednesday\n");
        }
        if (cnt % 7 == 1) {
            printf("Thursday\n");
        }
        if (cnt % 7 == 2) {
            printf("Friday\n");
        }
        if (cnt % 7 == 3) {
            printf("Saturday\n");
        }
        if (cnt % 7 == 4) {
            printf("Sunday\n");
        }
        if (cnt % 7 == 5) {
            printf("Monday\n");
        }
        if (cnt % 7 == 6) {
            printf("Tuesday\n");
        }
    }
    return 0;
}

Measured memory_bytes: 1168
N=int(input())
S=input()


count = 0
for i in range(1000):
  if i < 100:
    target_1 = "0"
    if i < 10:
      target_2 = "0"
      target_3 = str(i)
    else:
      target_2 = str(i)[0]
      target_3 = str(i)[1]
  else:
    target_1 = str(i)[0]
    target_2 = str(i)[1]
    target_3 = str(i)[2]
  
  step = 1
  for j in range(N):
    if S[j] == target_1 and step == 1:
      step = 2
      pass
    
    elif S[j] == target_2 and step == 2:
      step = 3
      
    elif S[j] == target_3 and step == 3:
      count += 1
      break

print(count)
      
      
    
      
    
    


    
  


Measured memory_bytes: 68060
#include<bits/stdc++.h>
using namespace std;
int gcd(int x,int y){
  if(x%y==0) return y;
  else return gcd(y,x%y);
}
int main(){
  int n,i,k,a,G,MAX;scanf("%d%d",&n,&k);
  scanf("%d",&G);MAX = G;
  if(n == 1){
    printf((k==G) ? "POSSIBLE\n":"IMPOSSIBLE\n");
    return 0;
  }
  for(i=1;i<n;i++){
    scanf("%d",&a);
    G = gcd(G,a);
    MAX = max(MAX,a);
  }
  printf((k<=MAX && k%G==0) ? "POSSIBLE\n":"IMPOSSIBLE\n");
}

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

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
mod2 = 998244353
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def pe(s): return print(str(s), file=sys.stderr)
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)


def M(n): return ModInt(n)
def MI(): return M(I())

class ModInt():
    def __init__(self, n):
        self.n = n

    def __add__(self, x):
        x = ModInt.xn(x)
        return ModInt((self.n+x) % mod)

    def __sub__(self, x):
        x = ModInt.xn(x)
        return ModInt((self.n-x) % mod)

    def __mul__(self, x):
        x = ModInt.xn(x)
        return ModInt((self.n*x) % mod)

    def __truediv__(self, x):
        x = ModInt.xn(x)
        return ModInt(self.n * pow(x, mod-2, mod) % mod)

    @classmethod
    def xn(cls, x):
        if isinstance(x, ModInt):
            return x.n
        return x

    def __str__(self):
        return str(self.n)

def main():
    n,a,b = LI()
    t = pow(2,n,mod) - 1

    def f(a,b):
        t = M(1)
        for j in range(a):
            t *= n-j
            t /= j+1
        r = t.n
        for j in range(a,b):
            t *= n-j
            t /= j+1
        return r + t.n

    t -= f(a,b)

    return t % mod


print(main())





Measured memory_bytes: 7556
#include <bits/stdc++.h>
#define div1 1000000007
const long long INF = 1LL << 60;
using namespace std;
typedef long long ll;
typedef long double ld;
// a>b -> a==b;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
// a<b -> a==b;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

int main(void)
{
    ll N, i, A[100001], Q, B[100001], C[100001], sum=0;
    map<ll,ll> mp;

    cin >> N;

    for(i=1; i<=N; i++){
        cin >> A[i];
        mp[A[i]]++;
        sum += A[i];
    }

    cin >> Q;

    for(i=1; i<=Q; i++){
        cin >> B[i] >> C[i];
        sum += mp[B[i]] * (C[i]-B[i]);
        mp[C[i]] += mp[B[i]];
        mp[B[i]] = 0;

        cout << sum << endl;
    }

    return 0;
}

Measured memory_bytes: 11724
#include <iostream>
using namespace std;
int main(){
  int n, l[10], max=0,p, sum=0;
  cin >> n;
  for(int i=0; i<n; i++)cin >> l[i];
   
  for(int i=0; i<n; i++){
    if(l[i] > max){
      max = l[i];
      p = i;
    }
  }
  l[p] = 0;
  
  for(int i=0; i<n; i++)sum += l[i];
  
  if(max >= sum)cout << "No" << endl;
  else cout << "Yes" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int INF = 0x3f3f3f3f;
const int maxn = 2e5+100;
LL a[maxn];
int n;
LL k;
bool check(LL x)
{
    LL sum = 0;
    for(int i = 1;i<=n;++i)
    {
        if(a[i]!=0)
        {
            LL flag = x/a[i];
            if(x%a[i])
            {
                if(x>0&&a[i]<0)
                {
                    sum += n+1-(lower_bound(a+1,a+1+n,flag)-a);
                    if(a[i]>=flag)
                    {
                        --sum;
                    }
                }
                else if(x>0&&a[i]>0)
                {
                    sum+=lower_bound(a+1,a+1+n,flag+1)-a-1;
                    if(a[i]<=flag)
                    {
                        --sum;
                    }
                }
                else if(x<0&&a[i]<0)
                {
                    sum+=n+1-(upper_bound(a+1,a+1+n,flag)-a);
                }
                else if(x<0&&a[i]>0)
                {
                    sum+=lower_bound(a+1,a+1+n,flag)-a-1;
                }
            }
            else
            {
                if(x>0&&a[i]<0)
                {
                    sum += n+1-(upper_bound(a+1,a+1+n,flag)-a);
                    if(a[i]>flag)
                    {
                        --sum;
                    }
                }
                else if(x>0&&a[i]>0)
                {
                    sum+=lower_bound(a+1,a+1+n,flag)-a-1;
                    if(a[i]<flag)
                    {
                        --sum;
                    }
                }
                else if(x<0&&a[i]<0)
                {
                    sum+=n+1-(upper_bound(a+1,a+1+n,flag)-a);
                }
                else if(x<0&&a[i]>0)
                {
                    sum+=lower_bound(a+1,a+1+n,flag)-a-1;
                }
                else if(x==0&&a[i]<0)
                    sum+=n+1-(upper_bound(a+1,a+1+n,0)-a);
                else if(x==0&&a[i]>0)
                    sum+=(lower_bound(a+1,a+n+1,0)-a)-1;
            }
        }
        else if(a[i]==0&&x>0)
            sum+=n-1;
    }
    sum/=2;
    return sum<k;
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cin >> n >> k;
    for(int i = 1;i<=n;++i)
    {
        cin >>a[i];
    }
    sort(a+1,a+n+1);
    LL l = -1e18,r = 1e18;
    LL ans = 0;
    while(l<=r)
    {
        LL mid = (l+r)>>1;
        if(check(mid))
        {
            ans =mid;
            l = mid+1;
        }
        else
            r = mid-1;
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define ll  long long int
#define ull unsigned long long int 
#define pb  push_back
#define mp  make_pair
#define pii pair<int, int>
using namespace std;

const ll mod = 1e9+7;
const int N = 1e5;

int dp[N+1][3] = {0};

int n;
int arr[N+1][3] = {0};
bool check[N+1][3] = {0};

int dp_recurse(int ind, int prev){
	if(check[ind][prev] == 1){
		return dp[ind][prev];
	}

	if(ind == n){
		return 0;
	}

	int maxi = -1;

	for(int i=0;i<3;i++){
		if(i!=prev){
			maxi = max(maxi, arr[ind][i] + dp_recurse(ind+1, i));
		}
	}

	dp[ind][prev] = maxi;
	check[ind][prev] = 1;

	return dp[ind][prev];

}


void solve(){
    //solve here//
	cin >> n;
	for(int i=0;i<n;i++){
		cin >> arr[i][0] >> arr[i][1] >> arr[i][2]; 
	}

	cout << max(dp_recurse(0, 0) , dp_recurse(0, 1)) << endl;
}


int main(){
    ll t=1;
    //cin >> t;
    while(t--){
        solve();
    }
}



Measured memory_bytes: 10752
#include <bits/stdc++.h>
using namespace std;
int main(void){
  string s, t;
  cin >> s >> t;
  sort(s.begin(), s.end());
  sort(t.rbegin(), t.rend());
  if(s < t) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
using System.Numerics;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            Solve();
            //Out.Flush();
            Read();
        }

        static void Solve()
        {
            var s = ReadLine();
            WriteLine(s.Count(c => c == '+') - s.Count(c => c == '-'));
        }
 
        static long Mod = 998244353;
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }
        static public (T1 a, T2 b) Slice<T1, T2>()
        {
            var t = ReadLine().Split();
            return (
            (T1)Convert.ChangeType(t[0], typeof(T1)),
            (T2)Convert.ChangeType(t[1], typeof(T2)));
        }
        static public (T a, T b) Slice2<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)));
        }
        static public (T a, T b, T c) Slice3<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)),
            (T)Convert.ChangeType(t[2], typeof(T)));
        }
    }
}

Measured memory_bytes: 27620
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
#include<stdio.h>
#include <cstdint>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define all(a) a.begin(), a.end()
#define fi first
#define se second
#define RNG(x, a, n) &((x)[a]), &((x)[n])
typedef pair<int, int> PII;
typedef long long ll;
template<typename T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } return false; }
template<typename T> bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } return false; }
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const ll mod = 1e9 + 7;

int n;
string s, t, ans;

int main() {

	cin >> n >> s >> t;

	rep(i, n){
		ans += s[i];
		ans += t[i];
	}

	cout << ans << endl;

	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
//using namespace boost::multiprecision;
typedef long long int ll;
typedef long double ld;
#define PI 3.141592653589793
#define MOD 1000000007
#define ALL(obj) (obj).begin(),(obj).end()
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;}
const ll INF = 1LL << 60;
bool pairCompare(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.first < secondElof.first;
}
bool pairCompareSecond(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.second < secondElof.second;
}
//四方向への移動ベクトル
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

struct edge{//グラフに使うヤツ
    ll from,to,cost;
};

typedef vector<vector<edge> > G;
ll gcd(ll a,ll b){
    if (a%b==0)return(b);
    else return(gcd(b,a%b));
}

ll n,ans=0;
void solve(string s,string t){
    for (ll i=0;i<10;i++){

    }
}

int main(){
    cin >> n;
    string s;
    ll ans[10][10],count=0;
    memset(ans,0,sizeof(ans));
    for (ll i=1;i<=n;i++){
        s=to_string(i);
        ans[s[0]-'0'][i%10]++;
    }
    for (ll i=1;i<10;i++){
        for (ll j=1;j<10;j++){
            count+=ans[i][j]*ans[j][i];
        }
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 3700
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
const int INF=1145141919,MOD=1e9+7;
const long long LINF=8931145141919364364,LMOD=998244353;
inline long long mod(long long n,long long m){return(n%m+m)%m;}
// const int dx[]={1,0,-1,0,1,1,-1,-1},dy[]={0,-1,0,1,1,-1,-1,1};

int main(){
    int n,k; cin>>n>>k;
    long long a[n+1]={}; rep(i,n) cin>>a[i+1];
    long long b[n+1]={};
    rep(i,n){
        b[i+1]=max(0ll,a[i+1]);
        b[i+1]+=b[i];
        a[i+1]+=a[i];
    }
    long long ans=0;
    for(int i=k;i<=n;i++){
        long long tmp=max(a[i]-a[i-k],0LL);
        tmp+=b[i-k];
        tmp+=b[n]-b[i];
        ans=max(ans,tmp);
    }
    cout<<ans<<endl;
    return 0;
}


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

using namespace std;

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

    int length;
    string S;
    cin >> S;
    length = S.length();
  
    string answer = "Yes";
    for (int i=0; i<length; i++) {
      if ((i+1) % 2 == 0 && S[i] == 'R') {
        answer = "No";
        break;
      }
      
      if ((i+1) % 2 != 0 && S[i] == 'L') {
        answer = "No";
        break;
      }
    }


    cout << answer << endl;

    return 0;
}

Measured memory_bytes: 256
# @uthor : Kaleab Asfaw
from sys import stdin, stdout
# Fast IO
def input():
	a = stdin.readline()
	if a[-1] == "\n": a = a[:-1]
	return a
def print(*argv, end="\n", sep=" "):
	n = len(argv)
	for i in range(n):
		if i == n-1: stdout.write(str(argv[i]))
		else: stdout.write(str(argv[i]) + sep)
	stdout.write(end)
# Others
mod = 10**9+7
def lcm(x, y): return (x * y) / (gcd(x, y))
def comb(lst, x):
	from itertools import combination as c
	return list(comb(lst, x))
def fact(x, mod=mod):
	ans = 1
	for i in range(1, x+1): ans = (ans * i) % mod
	return ans
def arr2D(n, m, default=0):
	lst = []
	for i in range(n): temp = [default] * m; lst.append(temp)
	return lst
def sortDictV(x): return {k: v for k, v in sorted(x.items(), key = lambda item : item[1])}
def smaller(lst, x): return bisect_left(lst, x) -1
def smallerEq(lst, x): return bisect_right(lst, x) -1

def solve(n):
	lst = [0] * 10000
	for i in range(1, 101):
		for j in range(1, 101):
			for k in range(1, 101):
				val = (i**2) + (j**2) + (k**2) + (i*j) + (i*k) + (j*k)
				if val >= 1 and val <= 10000:
					lst[val-1] += 1
	for i in range(0, n):
		print(lst[i])

n = int(input())
solve(n)

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

int main () {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  while (a > 0 && c > 0) {
    c -= b;
    a -= d;
  }
  string ans = "Yes";
  if (a <= 0 && c > 0) ans = "No";
  cout << ans << endl;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
typedef long long ll;
typedef pair<int, int> P;
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
int main() {
  int A, B, C;
  cin >> A >> B >> C;
  if (A <= C && C <= B) {
    puts("Yes");

  } else {
    puts("No");
  }
}

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

using namespace std;

int dp[501][501];

void show(int n) {
  for (int i = 0; i <= n; ++i) {
    for (int j = 0; j <= n; ++j) {
      cout << dp[i][j];
    }
    cout << endl;
  }
}

int main() {
  int n, m, Q;
  cin >> n >> m >> Q;
  for (int i = 0; i < m; ++i) {
    int l, r;
    cin >> l >> r; --l; --r;
    ++dp[0][r];
    --dp[l+1][r];
  }
  // show(n);
  for (int i = 1; i < n; ++i) {
    for (int j = 0; j < n; ++j) {
      dp[i][j] += dp[i-1][j];
    }
  }
  for (int i = 0; i < n; ++i) {
    for (int j = 1; j < n; ++j) {
      dp[i][j] += dp[i][j-1];
    }
  }
  for (int i = 0; i < Q; ++i) {
    int p, q;
    cin >> p >> q; --p; --q;
    cout << dp[p][q] << endl;
  }
}


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

int main() {
  int N, D;
  cin >> N >> D;
  vector<vector<int>> X(N, vector<int>(D));
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < D; j++) {
      cin >> X.at(i).at(j);
    }
  }

  int ans = 0;
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < i; j++) {
      int tmp = 0;
      for (int k = 0; k < D; k++) {
        int tmp2 = X.at(i).at(k) - X.at(j).at(k);
        tmp += tmp2 * tmp2;
      }
      if (sqrt(tmp) == (int)sqrt(tmp)) ans++;
    }
  }

  cout << ans << "\n";
}

Measured memory_bytes: 256
import sys
input=sys.stdin.readline
n,x,y=map(int,input().split())
d=[0]*(n)
for i in range(n):
    for j in range(i+1,n):
        a=j-i
        b=abs(x-1-i)+1+abs(y-1-j)
        d[min(a,b)]+=1
for i in range(n-1):
    print(d[i+1])

Measured memory_bytes: 47068
#!/usr/bin/env python3
import sys


def solve(N: int, T: int, c: "List[int]", t: "List[int]"):
    if min(t) > T:
        print("TLE")
    else:
        ans = max(c)
        for i in range(N):
            if t[i] <= T:
                ans = min(ans, c[i])
        print(ans)


# 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)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    T = int(next(tokens))  # type: int
    c = [int()] * (N)  # type: "List[int]"
    t = [int()] * (N)  # type: "List[int]"
    for i in range(N):
        c[i] = int(next(tokens))
        t[i] = int(next(tokens))
    solve(N, T, c, t)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <cstdio>
#include <algorithm>
#include <set>
int N, a[100001], L, TAG, H;
std::set < int > S;
void Extend(int w)
{
	if (w == 0)
		H ^= 1;
	else
	{
		if (!(w & 1) && !H)
			S.insert(L - TAG + 1);
		if ((w & 1) && H)
			S.insert(L - TAG);
		H = 0;
	}
	L += w;
	TAG--;
	if (S.size() && *S.begin() + TAG < 1)
		S.erase(S.begin());
}
int main()
{
	scanf("%d", &N);
	for (int i = 1; i <= N; i++)
		scanf("%d", a + i);
	std::sort(a + 1, a + N + 1);
	for (int i = 1; i <= N; i++)
		Extend(a[i] - a[i - 1]);
	puts((L ^ H ^ S.size()) & 1 ? "Second" : "First");
	return 0;
}


Measured memory_bytes: 1792
#include<stdio.h>

int main(void){
  char str[500];
  char c;
  int stack[100];
  int count=0;
  int reset=0;
  int x,y;
  // fgets(str,500,stdin);
  //printf("%s",str);
  while((c=getchar())!='\n'){
    //printf("%c ",c);
    if(c=='+'){
      //printf("test:+\n");
      y=stack[count-1];
      x=stack[count-2];
      stack[count-2]=x+y;
      count--;
    }else if(c=='*'){
      //printf("test:*\n");
      y=stack[count-1];
      x=stack[count-2];
      stack[count-2]=x*y;
      count--;
    }else if(c=='/'){
      // printf("test:/\n");
      y=stack[count-1];
      x=stack[count-2];
      stack[count-2]=x/y;
      count--;
    }else if(c=='-'){
      // printf("test:-\n");
      y=stack[count-1];
      x=stack[count-2];
      stack[count-2]=x-y;
      count--; 
    }else if(c==' '){
      //printf("test: \n");
      //スルー
      reset=0;
    }else{
      //printf("test:123\n");
      x=(int)(c-'0');
      if(reset==1){
	stack[count-1]=(stack[count-1]*10)+x;
      }else{
	stack[count]=x;
	//printf("%d\n",stack[count]);
	count++;
      }
      reset=1;
    }
    
  }
  printf("%d\n",stack[0]);
  return 0;
}



Measured memory_bytes: 2100
#include <cstdio>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <string>
#include <queue>
#include <map>
#include <stack>
#include <vector>
#include <algorithm>
#include <set>
#include <deque>
#include <utility>
#include <chrono>
#include <sstream>
#include <iomanip>
#define INF 1 << 30
#define MOD 1000000007;
#define pi 3.14159265358979
#define rep(i, n) for (int (i) = 0; (i) < (int)(n); (i)++)
#define rer(i, l, r) for (int (i) = (int)(l); (i) <= (int)(r); (i)++)
#define reu(i, l, r) for (int (i) = (int)(l); (i) < (int)(r); (i)++)
#define D(x) cout << x << endl
#define d(x) cout << x
#define all(x) (x).begin(), (x).end()
#define pub(x) push_back(x)
#define pob() pop_back()
#define puf(x) push_front(x)
#define pof() pop_front()
#define mp(x, y) make_pair((x), (y))
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long long> vll;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef pair<long, long> pll;
template<typename T, typename U> inline void amin(T &x, U y) { if (y < x) x = y; }
template<typename T, typename U> inline void amax(T &x, U y) { if (x < y) x = y; }
static const int dx[] = {0, 0, 1, -1};
static const int dy[] = {-1, 1, 0, 0};

int main() { 
  int n;
  cin >> n;
  string s;
  cin >> s;
  int x = 0, xmax = 0;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == 'I') {
      x++;
      amax(xmax, x);
    } else {
      x--;
    }
  }
  D(xmax);
  return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {

char sth;
cin >> sth;

if (sth != 'a' && sth !=  'i' && sth !=  'u' && sth !=  'e' && sth !=  'o') {
cout << "consonant" << endl;
}

else {
cout << "vowel" << endl;
}
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
	long long A, B, C;
	while( cin >> A >> B >> C ){
		if(A%2 == 1 || B%2 == 1 || C%2 == 1)
			cout << "0" << endl;
		else{
			long long cnt = 0;
			for( ; ; ){
				int t1, t2, t3;
				t1 = A;
				t2 = B;
				t3 = C;
				A = t2/2 + t3/2;
				B = t1/2 + t3/2;
				C = t1/2 + t2/2;
				cnt++;
				if( A%2 == 1 || B%2 == 1 || C%2 == 1 )	break;
				if( cnt > 1000 )		break;
			}
			if( cnt > 1000 )	cout << "-1" << endl;
			else	cout << cnt << endl;
		}
	}
	
	return 0;
}

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

#ifdef LOCAL
#include "debug.hpp"
#endif
 
const long long mod = 1e9+7;
const int maxn = 3e5+1;
const int bit = 60;
int dp[maxn][bit] = {};

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  long long n;
  cin >> n;
  vector<long long> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  } 
  for (int i = 0; i < n; i++) {
    for (long long j = 0; j < bit; j++) {
      dp[i][j] = (a[i]>>j)&1LL;
    }
  } 
  for (long long j = 0; j < bit; j++) {
    for (long long i = n-1; i > 0; i--) {
      dp[i][j] += dp[i+1][j];
    }
  }
  long long sum = 0;
  for (int i = 0; i  < n-1; i++) {
    for (long long j = 0; j < bit; j++) {
      if((a[i]>>j)&1LL) {
        sum = (sum + ((n-1-i - dp[i+1][j])*((1LL<<j)%mod))%mod)%mod;
      } else {
        sum = (sum + ((dp[i+1][j])*((1LL<<j)%mod))%mod)%mod;
      }
    }
  }  
  cout << sum << '\n';
  return 0;
}


Measured memory_bytes: 72960
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)

ll mod = 1e09;

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

  ll n;
  cin >> n;
  ll l[n], r[n];
  ll sum = 0;
  REP(i, n){
    cin >> l[i] >> r[i];
    sum += r[i] - l[i] + 1;
  }
  cout << sum << endl;
  return 0;
}


Measured memory_bytes: 256
N = int(input())

S = input()
listR = []
listB = []
listG = []
numR = 0
numG = 0
numB = 0

for idx,i in enumerate(S):
    if i == 'R':
        numR += 1
        listR.append((idx, numR, numG, numB))
    elif i == 'G':
        numG += 1
        listG.append((idx, numR, numG, numB))
    else:
        numB += 1
        listB.append((idx, numR, numG, numB))

result = 0
patterns = [
    (listR, listG, (3, "B", numB)),
    (listR, listB, (2, "G", numG)),
    (listG, listR, (3, "B", numB)),
    (listG, listB, (1, "R", numR)),
    (listB, listG, (1, "R", numR)),
    (listB, listR, (2, "G", numG)),
]
#Si = R
for list1, list2, str3 in patterns:
    for datR in list1:
        for dat2 in list2:
            idx = dat2[0]
            if idx > datR[0]:
                result += str3[2] - dat2[str3[0]]
                k = idx + (idx - datR[0])
                if k < N and S[k] == str3[1]:
                    result -= 1
print(result)


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


int main()
{
  int N,max=0,min=99999999999;
  cin>>N;
  int vec[N];
  for(int i=0;i<N;i++)
  {
    cin>>vec[i];
    if(vec[i]>max)max=vec[i];
    if(vec[i]<min)min=vec[i];
  }
  cout<<max-min<<endl;
}


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

#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace __gnu_pbds;
using namespace std;
#define int long long
//for set
// typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;   
// for multiset
typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update> ordered_set;

#define ff first
#define ss second
#define endl "\n"
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x.size())
#define PI 3.1415926535897932384626433832795
int MOD=1e9+7;
int powmod(int a,int l, int md){int res=1;while(l){if(l&1)res=res*a%md;l/=2;a=a*a%md;}return res;}
int binpow(int a,int l){int res=1;while(l){if(l&1)res=res*a;l/=2;a=a*a;}return res;}
typedef long long ll; typedef vector<ll> vi; typedef pair<ll, ll> ii; typedef vector<ii> vii;
#define pb push_back
int __set(int b, int i) {return b|(1ll<<i);} //set ith bit
int __unset(int b, int i) {return b&(~(1UL<<i));}
int __check(int b, int i) {return b&(1ll<<i);} //returns 0 if ith bit is 0
int mulmod(int a, int b, int md) {return ((a%md)*(b%md))%md;}
int addmod(int a, int b, int md) {return (a+b)%md;}
int submod(int a, int b, int md) {return (((a-b)%md)+md)%md;}
int divmod(int a, int b, int md) {return mulmod(a, powmod(b, md-2, md), md);} //if md is prime;
const ll inf = 0xFFFFFFFFFFFFFFFL; //very large number
// priority_queue<int, vector<int>, greater<int> > pq; //for min priority_queue
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
clock_t time_p=clock();
void time()
{
    time_p=clock()-time_p;
    cerr<<"Time Taken : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";
}

signed main(void)
{
	IOS;
	int n; cin>>n;
	map<ii,int> m1; map<ii,int> m2;
	for(int i = 1; i <= n; i++) {
		int ff=i%10,ss;
		int num=i;
		while(num>0) {
			ss=num%10;
			num/=10;
		}
		if(m1.find({ff,ss})!=m1.end())
			m1[{ff,ss}]++;
		else
			m1[{ff,ss}]=1;
		if(m2.find({ss,ff})!=m2.end())
			m2[{ss,ff}]++;
		else
			m2[{ss,ff}]=1;
	}
	int ans=0;
	for(auto it=m1.begin(); it!=m1.end(); it++) {
		ii p = it->ff;
		int cnt1=it->ss;
		int cnt2=0;
		if(m2.find(p)!=m2.end())
			cnt2=m2.find(p)->ss;
		ans=(ans+cnt1*cnt2);
	}
	cout<<ans<<endl;
	time();
	return 0;
}

Measured memory_bytes: 384
#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 < 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 < v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}

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

    ll W, H, x, y;
    cin >> W >> H >> x >> y;

    double res = (double)(W*H)/2.0;
    bool flag = (2*x == W && 2*y == H);
    cout << res << " " << (flag ? 1 : 0) << endl;
    return 0;
}

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

int main() {
    int h,w, i, j;

    cin >> h >> w;
    while(h!=0 || w!=0){
        for(j=0;j<w;j++){
            cout << "#";
        }
        cout << endl;
        for(i=1;i<h-1;i++){
            cout << "#";
            for(j=1;j<w-1;j++){
                cout << ".";
            }
            cout << "#";
            cout << endl;
        }
        for(j=0;j<w;j++){
            cout << "#";
        }
        cout << endl;
        cout << endl;
        cin >> h >> w;
    }
    return 0;
}


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


int main(){
	int N;
	cin >> N;
	while(N--){
		int i[3],c;
		int max;
		cin >> i[0] >> i[1] >> i[2];
		sort(i,i+3);
		if(i[0]*i[0]+i[1]*i[1]==i[2]*i[2])
			cout<<"YES\n";
		else
			cout<<"NO\n";

	}
}

Measured memory_bytes: 1136
#include<iostream>
#include<iomanip>
#include<math.h>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<set>
#include<map>
#define REP(i, N) for(ll i = 0; i < N; ++i)
#define FOR(i, a, b) for(ll i = a; i < b; ++i)
#define ALL(a) (a).begin(),(a).end()
#define pb push_back
#define INF (long long)1000000000
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
int dh[4] = {1, 0, -1, 0};
int dw[4] = {0, 1, 0, -1};

int main(void) {
	int n;
	cin>>n;
	string s;
	cin>>s;
	int lc = 0;
	int rc = 0;
	string ans = s;
	REP(i, n) {
		if(s[i] == '(') ++lc;
		if(s[i] == ')') ++rc;
		if(lc <  rc) {
			++lc;
			ans = '(' + ans;
		}
	}
	if(lc > rc) {
		REP(i, lc - rc) {
			ans += ')';
		}
	}
	cout<<ans<<endl;
}



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

typedef long long ll;

ll arr[55];
ll diff[55][55];

int main() {
	/* freopen("input.in", "r", stdin);
	freopen("output.o", "w", stdout); */
	ll k;
	scanf("%lld", &k);
	for (ll i = 1; i <= 50; i++) arr[i] = 100;
	for (ll i = 1; i <= 50; i++) {
		ll idx = 0;
		ll cur = 0;
		for (ll j = 1; j <= 50; j++) {
			if (arr[j] >= cur) {
				idx = j;
				cur = arr[j];
			}
		}
		arr[idx] -= 50;
		for (ll j = 1; j <= 50; j++) {
			if (j != idx) {
				arr[j]++;
			}
		}
		for (ll j = 1; j <= 50; j++) {
			diff[i][j] = arr[j] - 100;
		}
	}
	ll rem = k / 50;
	ll res = 50 + rem;
	ll thing = (rem + 1) * 50 - k;
	printf("50\n");
	for (ll i = 1; i <= 50; i++) {
		printf("%lld ", res + diff[thing][i]);
	}
}

Measured memory_bytes: 256
package main

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

func main() {
	r := bufio.NewReader(os.Stdin)
	var h, w int
	fmt.Fscan(r, &h)
	fmt.Fscan(r, &w)

	if h == 1 || w == 1 {
		fmt.Println(1)
		return
	}

	st1 := w / 2
	if w%2 != 0 {
		st1++
	}
	st2 := w / 2

	ans := 0
	for i := 0; i < h; i++ {
		if i%2 == 0 {
			ans += st1
		} else {
			ans += st2
		}
	}

	fmt.Println(ans)
}

// Union-Find
type unionFind struct {
	d []int
}

func newUnionFind(n int) *unionFind {
	uf := new(unionFind)
	uf.d = make([]int, n)
	for i := 0; i < n; i++ {
		uf.d[i] = -1
	}
	return uf
}

func (uf *unionFind) find(x int) int {
	if uf.d[x] < 0 {
		return x
	}
	uf.d[x] = uf.find(uf.d[x])
	return uf.d[x]
}

func (uf *unionFind) unite(x, y int) bool {
	rootX := uf.find(x)
	rootY := uf.find(y)
	if rootX == rootY {
		return false
	}

	if uf.d[rootX] < uf.d[rootY] {
		uf.d[rootX] += uf.d[rootY]
		uf.d[rootY] = rootX
	} else {
		uf.d[rootY] += uf.d[rootX]
		uf.d[rootX] = rootY
	}

	return true
}

func (uf *unionFind) same(x, y int) bool {
	return uf.find(x) == uf.find(y)
}

func (uf *unionFind) size(x int) int {
	return -uf.d[uf.find(x)]
}

// Utility

func min(x, y int) int {
	if x < y {
		return x
	}
	return y
}

func max(x, y int) int {
	if x > y {
		return x
	}
	return y
}

func abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}


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

long long dp[101][100001];

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

	int N, W;
	cin >> N >> W;
	vector<int> w(N+1), v(N+1);
	for (int i = 1; i <= N; ++i) cin >> w[i] >> v[i];

	dp[0][0] = 0;
	for (int j = 1; j <= W; ++j) dp[0][j] = -1;

	for (int i = 1; i <= N; ++i) {
		for (int j = 0; j <= W; ++j) dp[i][j] = dp[i-1][j];

		for (int j = 0; j <= W - w[i]; ++j) {
			if (dp[i-1][j] != -1) dp[i][j+w[i]] = max(dp[i][j+w[i]], dp[i-1][j] + v[i]);
		}
	}

	long long ans = 0;
	for (int j = 0; j <= W; ++j) ans = max(ans, dp[N][j]);
	cout << ans << endl;
}


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

using namespace std;

#define reg register

typedef long long ll;

inline int read() {
  ll s = 0, t = 1; char ch = getchar();
  while(ch < '0' || ch > '9') { if(ch == '-') t = -1; ch = getchar(); }
  while(ch <= '9' && ch >= '0') { s = s * 10 + ch - '0'; ch = getchar(); }
  return s * t;
}

int main() {
  int n = read();
  int k = read();
  ll res = 1ll * (n / k) * (n / k) * (n / k);
  n += k >> 1;
  printf("%lld\n", res + (k & 1 ? 0LL : 1LL * (n / k) * (n / k) * (n / k)));
  return 0;
}

Measured memory_bytes: 256
K, T = map(int, input().split())
a = list(map(int, input().split()))

if T == 1:
    print(K - 1)
else:
    max_ai = max(a)
    slit = max_ai - 1
    if slit > sum(a) - max_ai:
        print(slit - (sum(a) - max_ai))
    else:
        print(0)

Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <string>
#include <cstring>
#include <sstream>
#include <cmath>
#include <functional>
#include <fstream>
#include <cstdlib>
typedef long long ll;
const int MOD = 1e9+7;


#define REP(i, N) for (int i = 0; i < (N); i++)
#define REPP(i, a, b) for (int i = (a); i < (b); i++)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define VSORT(c) sort((c).begin(),(c).end())
#define SZ(x) ((int)(x).size())
//vvintを作る　マクロで　 #define vvint(N,M) vector<vector<int>>

using namespace std;
vector<int> group_id(100001);
vector<vector<int> > groups(100001);
int n;
void dfs(int i ,int c){
    stack<int> s;
    s.push(i);
    group_id[i] = c;
    while(!s.empty()){
        int u = s.top();s.pop();
        for(int l = 0; l < groups[u].size();l++){
            int g = groups[u][l];
            if(group_id[g] == -1){
                group_id[g] = c;
                s.push(g);
            }
        }
    }
}
void makeGroup(){
    int id = 0;
    for(int i = 0; i < n;i++) group_id[i] = -1;
    for(int i = 0; i < n;i++){
        if(group_id[i] == -1){
            dfs(i,id++);
        }
    }
}


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

    cin >> n >> m;

    int f,s;
    for(int i = 0; i < m;i++){
        cin >> f >> s;
        groups[f].push_back(s);
        groups[s].push_back(f);
    }

    makeGroup();

    int cnt;
    cin >> cnt;
    for(int i = 0; i < cnt;i++){
        cin >> f >> s;
        if(group_id[f] == group_id[s]){
            cout << "yes" << endl;
        }else{
            cout << "no" << endl;
        }
    }

    // for(int i = 0; i < n;i++){
    //     cout << i << " : " << group_id[i] << endl;
    // }


    return 0;
}


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

using namespace std;

const int MXN = 110;

int a[MXN];

int main ()
{
	int n, sum = 0;
	scanf("%d", &n);
	for (int i = 0; i < n; i++)
	{
		scanf("%d", &a[i]);
		sum += a[i];
	}
	int best = 1e4 + 10, ans;
	for (int i = 0; i < n; i++)
	{
		if (abs(sum - n * a[i]) < best)
		{
			best = abs(sum - n * a[i]);
			ans = i; 
		}
	}
	printf("%d", ans);
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <tuple>
#include <queue>
#include <vector>
#define int long long
using namespace std;
typedef tuple<int, int, int> T;

int n;
int a[300][300];
int b[300][300];

signed main() {
	int i, j, k;
	
	cin >> n;
	for (i = 0; i < n; i++) {
		for (j = 0; j < n; j++) {
			cin >> a[i][j];
			b[i][j] = a[i][j];
		}
	}
	
	for (k = 0; k < n; k++)
		for (i = 0; i < n; i++)
			for (j = 0; j < n; j++)
				b[i][j] = min(b[i][j], b[i][k] + b[k][j]);
	
	for (i = 0; i < n; i++) {
		for (j = 0; j < n; j++) {
			if (a[i][j] != b[i][j]) {
				cout << -1 << endl;
				return 0;
			}
		}
	}
	
	//各頂点対(i, j)についてコストa[i][j]の辺を使わずに, コストa[i][j]で移動できるか判定。
	int ans = 0;
	for (i = 0; i < n; i++) {
		for (j = i + 1; j < n; j++) {
			int minCost = 1145141919810893;
			for (k = 0; k < n; k++) {
				if (k == i || k == j) continue;
				minCost = min(minCost, a[i][k] + a[k][j]);
			}
			if (minCost > a[i][j]) {
				ans += a[i][j];
			}
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 2296
#ifdef _DEBUG
#include "MyLib.h"
#else
#define main_D main
#include "bits/stdc++.h" 
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>
#define FOR(i,s,e) for (int i = int(s); i < int(e); ++i)
#define REP(i,e) FOR(i,0,e)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define LINF (LLONG_MAX/2)
const int MGN = 8;
const int ARY_SZ_MAX = 10000000;
using namespace std;
using ll = long long; using ull = unsigned long long;
using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>;
using vb = vector<bool>; using vvb = vector<vb>; using vvvb = vector<vvb>;
using vl = vector<ll>; using vvl = vector<vl>;
using vd = vector<double>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>;
using psi = pair<string, int>;
// functions
bool second_greater(const pll& left, const pll& right) {
    return left.second > right.second;
}
#endif


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

    int N, H; cin >> N >> H;
    vi A(N), B(N);
    REP(i, N) cin >> A[i] >> B[i];

    vector<pii> c;
    REP(i, N) c.push_back(pii(A[i], B[i]));
    sort(c.begin(), c.end());

    int a = c[N - 1].first;

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

    int h = H;
    int cnt = 0;
    bool dead = false;
    REP(i,N) {
        if (a < c[i].second) {
            h -= c[i].second;
            cnt++;
        }
        if (h<=0) {
            dead = true;
            break;
        }
    }
    if (!dead) cnt += (h + a - 1) / a;

    int ans = cnt;
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 2168
N = int(input())
A = list(map(int,input().split()))+[0]
baibai = []
kane = 1000
kabu = 0
for i in range(N):
    sa = A[i+1] -A[i]
    if sa == 0:
        baibai.append(0)
    elif sa != abs(sa):
        baibai.append(-1)
    else:
        baibai.append(1)
if 1 in baibai:
    uri = N - (baibai[::-1].index(1))
else:
    uri = -1

for j in range(N):
    if j == uri:
        kane += A[j] * kabu
        print(kane)
        exit()
    elif baibai[j] > 0:
        kabu += (kane//A[j])
        kane -= A[j] * (kane//A[j])
    elif baibai[j] < 0:
        kane += A[j] * kabu
        kabu = 0
        
print(kane)

Measured memory_bytes: 9232