akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define EPS (1e-9)
#define INF (1e17)
#define PI (acos(-1))
//const double PI = acos(-1);
//const double EPS = 1e-15;
//long long INF=(long long)1E17;
#define i_7 (long long)(1e9+7)
//#define i_7 998'244'353
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
using namespace std;

bool prime_(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}

long long gcd_(long long a, long long b){
  if(a<b){
    swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd_(b,a%b);
  }
}
 
long long lcm_(long long x, long long y){
  return (x/gcd_(x,y))*y;
}

int main(){
  
  int n,t;
  cin>>n>>t;
  int a[n],b[n];
  REP(i,n){
    cin>>a[i]>>b[i];
  }
  int dp[n][t] = {};
  REP(i,n){
    REP(j,t){
      if(i==0){
        if(j>=a[i]){
          dp[i][j] = b[i];
        }else{
          continue;
        }
      }else if(j-a[i]<0){
        dp[i][j] = dp[i-1][j];
      }else{
        dp[i][j] = max(dp[i-1][j], dp[i-1][j-a[i]] + b[i]);
      }
    }
  }
  
  int ans = dp[n-1][t-1];
  bool used[n] = {};
  int tt = t-1;
  for(int i = n-1; i>=1; i--){
    if(tt-a[i] < 0){
      continue;
    }
    if(dp[i][tt] == dp[i-1][tt-a[i]] + b[i]){
      used[i] = true;
      tt = tt-a[i];
    }
  }
  if(dp[0][tt] == b[0]){
    used[0] = true;
  }
  int m = 0;
  REP(i,n){
    if(used[i])continue;
    m = max(m, b[i]);
  }
  ans += m;
  cout<<ans<<endl;
  return 0; 
}

Measured memory_bytes: 35456
W,H,N=map(int,input().split())
flag=0
lst=[]
most_up=H
most_down=0
most_right=W
most_left=0
now_location=[most_up, most_down, most_right, most_left]
for i in range(N):
    lst.append(list(map(int,input().split())))
for i in lst:
    if i[2]==1:
        if now_location[3] <= i[0]:
            now_location[3]=i[0]
    elif i[2]==2:
        if now_location[2] >= i[0]:
            now_location[2]=i[0]
    elif i[2]==3:
        if now_location[1] <= i[1]:
            now_location[1]=i[1]
    else:
        if now_location[0] >= i[1]:
            now_location[0]=i[1]
height=now_location[0]-now_location[1]
width=now_location[2]-now_location[3]
print(0) if (height<0 or width<0) else print(height*width)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mod 1000000007

int main(void){
    int n;
    cin>>n;
    vector<ll> v(n);
    ll ans=0;
    for(int i=0;i<n;i++){
        ll a,b;
        cin>>a>>b;
        v[i]=a+b;
        ans-=b;
    }
    sort(v.rbegin(),v.rend());
    for(int i=0;i<n;i+=2) ans+=v[i];
    cout<<ans<<endl;
}

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

int main(){
    int H, W, h, w;
    cin >> H >> W;
    cin >> h >> w;

    cout << (H-h)*(W-w) << "\n";

    return 0;
}

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

int main(){
    int N;
    cin >> N;
    vector<ll> A(N+1);
    ll leaves = 0;
    for (int i=0; i<N+1; i++){
        cin >> A[i];
        leaves += A[i];
    }
    vector<ll> node(N+1, 0);
    vector<ll> leaf(N+1, 0);
    node[N] = A[N];
    leaf[N] = A[N];
    node[0] = 1;
    if (A[0] > 1){
        cout << -1 << endl;
        return 0;
    } else{
        leaf[0] = A[0];
    }
    for (int i=1; i<N+1; i++){
        // printf("node: %d, leaf: %d\n", node[i-1], leaf[i-1]);
        // 次の葉の数が多すぎる場合
        if (A[i] > 2 * (node[i-1] - leaf[i-1])){
            cout << -1 << endl;
            return 0;
        // 次のnode数を増やせるギリギリまで増やす
        // それは 末尾の葉の数 + 途中の葉の数 = leaves
        } else{
            node[i] = min(leaves, 2 * (node[i-1] - leaf[i-1]));
            leaf[i] = A[i];
            leaves -= A[i];
        }
    }

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

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

int main() {
	int a, b, c;
	cin >> a >> b >> c;
	int ans = abs(a-b)+abs(b-c)+abs(c-a) - max(max(abs(a-b),abs(b-c)),abs(c-a));
	cout << ans << endl;
	return 0;
}


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

int main(){
	string s;	cin>>s;
	char acgt[4]={'A','C','G','T'};

	int ans=0,cnt=0;
	for(int i=0; i<s.length(); i++){
		bool flag=false;
		for(int j=0;j<4;j++){
			if(s[i]==acgt[j]){
				flag=true;	break;
			}
		}

		if(flag)cnt++;
		else{
			ans=max(ans,cnt);
			cnt=0;
		}
	}
	ans=max(ans,cnt);

	cout<<ans<<endl;

	return 0;
}


Measured memory_bytes: 256
import math
N = int(input())
def gcdtriple(a,b,c):
    return math.gcd(a, math.gcd(b,c))
ans = 0
for a in range(1, N+1):
    for b in range(1, a+1):
        for c in range(1, b+1):
            if a == b and b == c:
                ans += gcdtriple(a,b,c)
            elif a == b or b == c or c == a:
                ans += gcdtriple(a,b,c) * 3
            else:
                ans += gcdtriple(a,b,c) * 6
print(ans)

Measured memory_bytes: 9212
#include <cstdio>
#include <cstring>
#include <algorithm>
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
const int inf = 123456789;
const int max_coord = 200000;
int N, X[200704], Y[200704], S[200704], T[200704]; char D[200704];
int cnt[401408], ord[401408], pa[401408], pb[401408];
int readint() {
	char ch = '-';
	while(!('0' <= ch && ch <= '9')) {
		ch = getchar_unlocked();
	}
	int res = 0;
	while('0' <= ch && ch <= '9') {
		res = res * 10 + int(ch - '0');
		ch = getchar_unlocked();
	}
	return res;
}
int main() {
	N = readint();
	for(int i = 0; i < N; ++i) {
		X[i] = readint();
		Y[i] = readint();
		D[i] = getchar_unlocked();
	}
	// sorting of (X, Y, D) in increasing order
	memset(cnt, 0, sizeof(cnt));
	for(int i = 0; i < N; ++i) ++cnt[Y[i] + 1];
	for(int i = 0; i < max_coord; ++i) cnt[i + 1] += cnt[i];
	for(int i = 0; i < N; ++i) pa[cnt[Y[i]]++] = i;
	memset(cnt, 0, sizeof(cnt));
	for(int i = 0; i < N; ++i) ++cnt[X[i] + 1];
	for(int i = 0; i < max_coord; ++i) cnt[i + 1] += cnt[i];
	for(int i = 0; i < N; ++i) ord[cnt[X[pa[i]]]++] = pa[i];
	for(int i = 0; i < N; ++i) pa[i] = X[ord[i]];
	for(int i = 0; i < N; ++i) X[i] = pa[i];
	for(int i = 0; i < N; ++i) pa[i] = Y[ord[i]];
	for(int i = 0; i < N; ++i) Y[i] = pa[i];
	for(int i = 0; i < N; ++i) pa[i] = D[ord[i]];
	for(int i = 0; i < N; ++i) D[i] = pa[i];
	for(int i = 0; i < N; ++i) {
		S[i] = X[i] + Y[i];
		T[i] = X[i] - Y[i] + max_coord;
	}
	// calculation part #1
	int ans = inf;
	memset(pa, -55, sizeof(pa));
	memset(pb, -55, sizeof(pb));
	for(int i = 0; i < N; ++i) {
		if(D[i] == 'U') pa[X[i]] = Y[i];
		if(D[i] == 'R') pb[Y[i]] = X[i];
		if(D[i] == 'D') ans = std::min(ans, Y[i] - pa[X[i]]);
		if(D[i] == 'L') ans = std::min(ans, X[i] - pb[Y[i]]);
	}
	// calculation part #2
	memset(pa, -55, sizeof(pa));
	memset(pb, -55, sizeof(pb));
	for(int i = 0; i < N; ++i) {
		if(D[i] == 'D') pa[S[i]] = T[i];
		if(D[i] == 'R') pb[S[i]] = T[i];
		if(D[i] == 'L') ans = std::min(ans, T[i] - pa[S[i]]);
		if(D[i] == 'U') ans = std::min(ans, T[i] - pb[S[i]]);
	}
	// calculation part #3
	memset(pa, -55, sizeof(pa));
	memset(pb, -55, sizeof(pb));
	for(int i = 0; i < N; ++i) {
		if(D[i] == 'U') pa[T[i]] = S[i];
		if(D[i] == 'R') pb[T[i]] = S[i];
		if(D[i] == 'L') ans = std::min(ans, S[i] - pa[T[i]]);
		if(D[i] == 'D') ans = std::min(ans, S[i] - pb[T[i]]);
	}
	if(ans == inf) printf("SAFE\n");
	else printf("%d\n", ans * 5);
	return 0;
}

Measured memory_bytes: 10392
/*
Author: Sagar Gupta
E mail: sagar.june97p@gmail.com
*/

#pragma comment(linker, "/STACK:268435456")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define endl ("\n")
#define deb(n) cerr << #n << " = " << (n) << '\n'
#define FOR(i, n) for (int(i) = 0; (i) < n; (i)++)
#define PI (3.141592653589)
#define ordered_set tree<int, null_type, std::less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define MOD 1000000007
using ll = long long;

vector<int> parent, len;
int find(int n)
{
    if (parent[n] == n)
    {
        return n;
    }
    return parent[n] = find(parent[n]);
}

bool add(int u, int v)
{
    int a = find(u);
    int b = find(v);
    if (a == b)
    {
        return false;
    }
    if (len[a] < len[b])
    {
        swap(a, b);
    }
    len[a] += len[b];
    parent[b] = a;
    return true;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed;
    cout.precision(10);
    // Those who cannot acknowledge themselves, will invariably fail

    int n;
    cin >> n;
    cout << "ABC" << n;
    return 0;
}

Measured memory_bytes: 256
// card-eater.rs ---
// author: Seong Yong-ju <sei40kr@gmail.com>

// tanakah's input macro
// cf https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

fn main() {
    input! {
      n: usize,
      xs: [usize; n]
    }

    let mut memo = [0; 100001];
    for x in xs.into_iter() {
        memo[x] += 1;
    }

    let k = memo
        .into_iter()
        .map(|&t| if 1 < t { t - 1 } else { 0 })
        .sum::<usize>();
    let ans = n - (k + 1) / 2 * 2;
    println!("{}", ans);
}


Measured memory_bytes: 7164
import java.util.*

fun main(args: Array<String>) {
  val sc = Scanner(System.`in`)
  val k = sc.nextInt()
  val s = sc.next()

  println(abc168b(k, s))
}

private fun abc168b(k: Int, s: String): String {
  if (s.length <= k) return s

  val sub = s.substring(0, k)

  return sub + "..."
}


Measured memory_bytes: 36788
#define _USE_MATH_DEFINES
#include<iostream>
#include<sstream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<unordered_map>
#include<math.h>
#include<iterator>
 
using namespace std;
 
int main(){
  int n,k,x,y;
  cin >> n>>k>>x>>y;
  cout << (n<=k ? n*x : x*k + y*(n-k) ) <<endl;
}

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

#define int long long
#define double long double
#define ff first
#define ss second
#define endl '\n'
#define ii pair<int, int>
#define DESYNC ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define pb push_back
#define vi vector<int>
#define vii vector< ii >
#define EPS 1e-9
#define INF 1e18
#define ROOT 1
#define M 1000000007
const double PI = acos(-1);

using namespace std;

inline int mod(int n, int m){ int ret = n%m; if(ret < 0) ret += m; return ret; }

int gcd(int a, int b){
  if(a == 0 || b == 0) return 0;
  else return abs(__gcd(a,b));
}

int32_t main(){
  DESYNC;
  int n,k;
  k = 2;
  cin >> n;
  int dp[n+1];
  int v[n+1];
  for(int i=1; i<=n; i++){
    cin >> v[i];
  }
  for(int i=0; i<=n; i++) dp[i] = INF;
  dp[1] = 0;
  for(int i=2; i<=n; i++){
    for(int j = max(1LL, i -k); j<i; j++){
      dp[i] = min(dp[i], dp[j] + abs(v[i] - v[j]));
    }
  }
  cout << dp[n] << endl;
}



Measured memory_bytes: 1792
#include <stdio.h>

int main(){
	int n,sum;
	scanf("%d",&n);
	int a[n],b[n],c[n];
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]);
	}
	for(int i=1;i<=n;i++){
		scanf("%d",&b[i]);
	}
	for(int i=1;i<n;i++){
		scanf("%d",&c[i]);
	}
	sum=b[a[1]];
	for(int i=2;i<=n;i++){
		//printf("b[%d]=%d\n",i,b[i]);
		if(a[i]==a[i-1]+1){
			sum+=(b[a[i]]+c[a[i]-1]);
		}else{
			sum+=b[a[i]];
		}
		//printf("%d\n",sum);
	}
	printf("%d\n",sum);
	return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<string>
#include<cstring>
#include<cstdlib>
using namespace std;
int n,m,a[2000000+5],a_n,x,y; 
int main()
{
  scanf("%d%d",&n,&m);
  for(int i=1;i<=m;i++)
  {
    scanf("%d%d",&x,&y);
    if(x==1)
    {
      if(y==n){printf("POSSIBLE\n");return 0;}
      a_n++,a[a_n]=y;
    }
    if(x==n)
    {
      if(y==1){printf("POSSIBLE\n");return 0;}
      a_n++,a[a_n]=y;
    }
    if(y==1)
    {
      if(x==n){printf("POSSIBLE\n");return 0;}
      a_n++,a[a_n]=x;
    }
    if(y==n)
    {
      if(x==1){printf("POSSIBLE\n");return 0;}
      a_n++,a[a_n]=x;
    }
  } 
  sort(a+1,a+1+a_n);
  for(int i=1;i<=a_n;i++)
    if(a[i]==a[i+1]){printf("POSSIBLE\n");return 0;}
  printf("IMPOSSIBLE\n");
  return 0;
}


Measured memory_bytes: 1024
import sys
a, b = input().split()

A = int(a)
B = int(b)

Adiv = A
Bdiv = B
k = 0




for i in reversed(range(min([A, B]))):
    j = i+1
    if Adiv % j == 0 and Bdiv % j == 0:
        k = j
        break


if k == 0:
    k = 1


res = A * B / k

print(int(res))


Measured memory_bytes: 3060
n,k=map(int,input().split())
r,s,p=map(int,input().split())
t=input()
a=[[]for i  in range(k)]
for i in range(n):
    a[i%k].append(t[i])
s1=0
for i in range(k):
    for j in range(len(a[i])):
        if j==0 or a[i][j]!=a[i][j-1]:
            if a[i][j]=='r':
                s1+=p
            elif a[i][j]=='s':
                s1+=r
            else:
                s1+=s
        else:
            a[i][j]='k'
print(s1)

Measured memory_bytes: 54016
import java.util.*;
public class Main{
  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
    String str = sc.next();
    char s = str.charAt(0);
    switch(s){
      case 'A':
          System.out.println("T");
          break;
      case 'T':
          System.out.println("A");
          break;
      case 'C':
          System.out.println("G");
          break;
      case 'G':
          System.out.println("C");
          break;
    }
 }
}

Measured memory_bytes: 20564
N,M,X,Y,=map(int,input().split())
x=list(map(int,input().split()))
y=list(map(int,input().split()))
x.sort(reverse=True)
y.sort()
if x[0]<Y and X<y[0] and x[0]<y[0]:
    print("No War")
else:
    print("War")

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

using ll = long long;
using lli = long long int;

int n, k, p;
std::vector<int> vec;
int max_value;

int main() {
    max_value = 0;
    std::cin >> n >> k;
    vec.assign(n+1, 0);
    for (int i = 1; i <= n; i++) {
        std::cin >> p;
        p++;
        vec[i] = vec[i-1] + p;
    }
    for (int i = 0; i+k <= n; i++) {
        if (max_value < vec[i+k]-vec[i])
            max_value = vec[i+k] - vec[i];
    }
    std::cout << std::fixed << std::setprecision(10) << ((long double)max_value / 2.0) << std::endl;
}


Measured memory_bytes: 3980
#include<iostream>
#include<vector>
#include<string>
using namespace std;
int main(){
  int n,q;cin>>n>>q;
  string s;cin>>s;
  vector<int>a(n,0);
  for(int i=0;i<n-1;i++){
    if(s[i]=='A' && s[i+1]=='C')a[i+1]=a[i]+1;
    else a[i+1]=a[i];
  }
  for(int i=0;i<q;i++){
    int l,r;cin>>l>>r;
    cout<<a[r-1]-a[l-1]<<endl;
  }
}


Measured memory_bytes: 1408
s = input()[::-1]
length = len(s)
a = [0] * length
d = [0] * length
ans = [0] * 2019
x = 10

a[0] = int(s[0])
d[0] = a[0]
ans[d[0]] += 1

for i in range(1, length):
    a[i] = int(s[i]) * x % 2019
    d[i] = (d[i-1] + a[i]) % 2019
    ans[d[i]] += 1
    x = x * 10 % 2019

ans_c = [i for i in ans if i != 0]

print(int(sum([ans_c[i] * (ans_c[i]-1) for i in range(len(ans_c))]) / 2) + ans[0])

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

int main(){
	string s;
	cin>>s;
	int l=s.length();
	vector<char> v;
	for(int i=0;i<l;i++){
		if(s[i]!='B')v.push_back(s[i]);
		else{
			if(v.size()!=0)v.pop_back();
		} 
	}
	for(int i=0;i<v.size();i++){
		cout<<v[i];
	}
}

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


int main() {
    int n;
    cin >> n;
    double a = (double)(n / 2 + n % 2) / (double)n;
    cout << a;
}

Measured memory_bytes: 256
def probC():
    N = input()
    A = map(int, input().split())

    step = 0
    max_height = 0
    for i in A:
        if max_height < i:
            max_height = i
        else:
            step += max_height - i

    print(step)


def main():
    probC()


if __name__ == '__main__':
    main()


Measured memory_bytes: 24988
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main {

	public static void main(String[] args) throws IOException {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String datas = br.readLine();
		String[] data = datas.split(" ");
		int a = Integer.parseInt(data[0]);
		int b = Integer.parseInt(data[1]);
		int c = Integer.parseInt(data[2]);

		int count = 0;
		for(int i = a;i<=b;i++) {

			if(c%i==0) {
				count++;
			}

		}

		System.out.println(count);
	}
}

Measured memory_bytes: 24452
#include<stdio.h>
#include<math.h>
int main()
{
    int i,j,tem,height[15];
    for(i=0;i<10;i++){

    scanf("%d",&height[i]);
}
    for(i=0;i<10;i++)
    {
        for(j=i+1;j<10;j++)
        {
            if(height[i]>height[j])
            {
                tem=height[j];
                height[j]=height[i];
                height[i]=tem;
            }
        }
    }
    for(i=9;i>6;i--)
    {
        printf("%d\n",height[i]);
    }



    return 0;

}

Measured memory_bytes: 600
N,M=map(int,input().split())
AC=[0]*N
WA=[0]*N

for i in range(M):
    p,s=input().split()
    p=int(p)-1
    if AC[p]==0:
        if s=='AC':
            AC[p]+=1
        else:
            WA[p]+=1

for i in range(N):
    if AC[i]==0:
        WA[i]=0
    
print(sum(AC),sum(WA))


Measured memory_bytes: 4596
#include <algorithm>
#include <cassert>
#include <chrono>
#include <cmath>
#include <complex>
#include <cstdlib>
#include <deque>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  int k;
  cin >> k;
  int ans = -1, num = 7;
  for (int i = 1; i <= (k + 10); i++) {
    if (num % k == 0) {
      ans = i;
      break;
    }
    num = (num * 10 + 7) % k;
  }
  cout << ans << "\n";
}

Measured memory_bytes: 3648
M, D = map(int, input().split())

# print("M:", M, "D:", D)

count = 0
# days = []

for m in range(1, M+1):
    for d in range(1, D+1):
        # print("m: ", m, " d: ", d, " d10: ", d/10, " d1", d%10)
        d1 = d % 10
        d10 = d // 10
        if (d1 * d10) == m and d1 != 1 and d10 != 1:
            # days.append("{}月{}日".format(m, d))
            count += 1

# for day in days:
#     print(day)
print(count)

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <string>
using namespace std;
#define INF 1010101010
#define MOD 1000000007

class DisjointSet {
private:
    vector<int> parent;
    vector<int> rank;
public:
    DisjointSet(int size) : parent(size, -1), rank(size, 0) {}

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

    bool same(int x, int y) {
        return root(x) == root(y);
    }

    void unite(int x, int y) {
        x = root(x);
        y = root(y);
        if (x == y) return;
        
        if (rank[x] < rank[y]) {
            parent[x] = y;
        } else {
            parent[y] = x;
            if (rank[x] == rank[y]) rank[x]++;
        }
    }
};

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

    int N, K, L;
    cin >> N >> K >> L;
    DisjointSet t(N);
    DisjointSet r(N);
    
    for (int i = 0; i < K; i++) {
        int p, q;
        cin >> p >> q;
        t.unite(--p, --q);
    }
    
    for (int i = 0; i < L; i++) {
        int a, b;
        cin >> a >> b;
        r.unite(--a, --b);
    }

    map<pair<int, int>, int> cnt;
    for (int i = 0; i < N; i++) {
        cnt[make_pair(t.root(i), r.root(i))]++;
    }

    for (int i = 0; i < N; i++) {
        cout << cnt[make_pair(t.root(i), r.root(i))] << ' ';
    }

    cout << '\n';
}

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

int n;
int a[2000005];
int c[10005];
int b[2000005];

int main()
{
    cin>>n;
    int i,j;
    memset(c,0,sizeof(c));
    for(i=0;i<n;i++){cin>>a[i];c[a[i]]++;}
    for(i=1;i<=10000;i++){c[i]+=c[i-1];}
    for(i=n-1;i>=0;i--){
        b[c[a[i]]]=a[i];
        c[a[i]]--;
    }
    for(i=1;i<=n;i++){
        cout<<b[i];
        if(i!=n)cout<<" ";
    }
    cout<<endl;
    return 0;
}

Measured memory_bytes: 18684
#include <bits/stdc++.h>
#define INF 1e18
#define PI M_PI
#define ll long long
#define vi vector<int>
#define all(v) v.begin(), v.end()
#define REP(i, n) for (int i=0; i<n; i++)
#define REPD(i, n) for (int i=n-1; i>=0; i--)
#define print(x) cout << x << endl;
#define debug(x) cout << #x << " = " << endl;

using namespace std;

void solve()
{
    int N;
    cin >> N;
    vector<int> A(N);
    REP(i, N) cin >> A.at(i);

    vector<int> tmp = A;
    vector<int> tmptmp = A;
    sort(all(tmp));
    int firstValue = tmp.at(N-1);
    int firstIndex = distance(tmptmp.begin(), find(tmptmp.begin(), tmptmp.end(), firstValue));
    int secondValue = tmp.at(N-2);

    REP(i, N) {
        if (firstIndex != i) {
            print(firstValue);
        } else {
            print(secondValue);
        }
    }
}

int main()
{
    solve();

    return 0;
}


Measured memory_bytes: 3968
/* ---------- STL Libraries ---------- */
// IO library
#include <cstdio>
#include <fstream>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm library
#include <algorithm>
#include <cmath>
#include <numeric>
#include <random>
#include <cstring>

// container library
#include <array>
#include <bitset>
#include <deque>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>
#include <stack>

/* ---------- Namespace ---------- */
using namespace std;

/* ---------- Type ---------- */
using ll = long long;
#define int ll
#define P pair<ll, ll>

/* ---------- Constants  */
const double PI = 3.141592653589793238462643383279;
const ll MOD = 1e9 + 7;
const int INF = 1LL << 55;

/* v-v-v-v-v-v-v-v-v Main Part v-v-v-v-v-v-v-v-v */
signed main() {
    int N;
    cin >> N;
    vector<int> A(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }

    int cnt = 0;
    for (int i = 0; i< N; i++) {
        if (A[i] != i + 1) cnt++;
    }

    if (cnt <= 2) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
    return 0;
}

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

int main() {
  int A,B;
  int a[5],b[5];
  int base = 1; //10000;
  int sumA=0;
  int sumB=0;

  cin >> A >> B;

  bool Judge =false;
  if (A==B) Judge = true;

  for (int i=4; i>-1; i--){
      base *= 10;
      for (int j=0; j<10; j++) {
          if ((A-j*(base/10))%base==0) {
              A -= j*(base/10);
              a[i] = j;
              break;
          }       
      }
      if (A==0) break;
  }

  if (10*a[1]+a[0] <= 10*a[3]+a[4]) sumA += 1;
  sumA += a[2] + (10*a[0]+a[1]-10)*10;

  base = 1;

  for (int i=4; i>-1; i--){
      base *= 10;
      for (int j=0; j<10; j++) {
          if ((B-j*(base/10))%base==0) {
              B -= j*(base/10);
              b[i] = j;
              break;
          }       
      }
      if (B==0) break;
  }

  if (10*b[1]+b[0] <= 10*b[3]+b[4]) sumB += 1;
  sumB += b[2] + (10*b[0]+b[1]-10)*10;

  if(Judge){
      cout << 1 << endl;
      } else if(a[0]==a[4] && a[1]==a[3]) {
          cout << sumB-sumA+1 << endl;
          } else {
              cout << sumB-sumA << endl;
              }
  
}

Measured memory_bytes: 256
#define debug_interval ' '
#define dump_interval ','
#define debug_toggle 1
//{
#include<bits/stdc++.h>
using namespace std;
#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define fi first
#define se second
#define mp make_pair
#define rev reverse
 
//{
inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}
template<class...A> inline void dump(){cout<<endl;}
template<class...A> inline void dump_rest() {cout<<endl;}
template<class T, class...A> inline void dump_rest(const T& first, const A&... rest){cout<<dump_interval<<first;dump_rest(rest...);}
template<class T,class...A> inline void dump(const T&first,const A&...rest){cout<<first;dump_rest(rest...);}
template<class...A> inline void debug(){cerr<<endl;}
template<class...A> inline void debug_rest() {cerr<<endl;}
template<class T, class...A> inline void debug_rest(const T& first, const A&... rest){cerr<<debug_interval<<first;debug_rest(rest...);}
template<class T,class...A> inline void debug(const T&first,const A&...rest){if(debug_toggle)cerr<<first,debug_rest(rest...);}
//}

typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}


//}
int n,m,ans;

main(){
	cin>>n;
	if(n==1)dump("Hello World");
	else {
		cin>>n>>m;
		dump(n+m);
	}
}

Measured memory_bytes: 256
#include<cstdio>
#include<queue>
#include<utility>
#include<cstring>
#include<stack>
#include<algorithm>
#include<cmath>
#include<iostream>
#include<map>
#define MAX_N 100001
#define INF_INT 2147483647
#define INF_LL 9223372036854775807
#define REP(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;
void init(int n);
int find(int n);
void unite(int x,int y);
bool same(int x, int y);
ll bpow(ll,ll,ll);
typedef vector<int> vec;
typedef vector<vec> mat;
mat mul(mat &A,mat &B);
mat pow(mat A,ll n);
int dx[4] = {1,0,0,-1};
int dy[4] = {0,1,-1,0};


bool cmp_P(const P &a,const P &b){
  return a.second < b.second;
}
int main()
{
  int N,K,x[100001],res=INF_INT,negares=0,pojires=0;
  vector<int> nega(0),poji(0);
  cin >> N >> K;
  REP(i,N){
    cin >> x[i];
    if(x[i] >= 0)
      poji.push_back(x[i]);
    else
      nega.push_back(x[i]);
  }
  reverse(nega.begin(),nega.end());
  if(poji.size() == 0){
    cout << abs(nega[K-1]) << endl;
    return 0;
  }
  if(nega.size() == 0){
    cout << abs(poji[K-1]) << endl;
    return 0;
  }

  if(nega.size() > K-1){
    res = min(res,abs(nega[K-1]));
  }
  if(poji.size() > K-1){
    res = min(res,poji[K-1]);
  }
  for(int i=0;i<nega.size();i++){
    if(K-i-2 >= 0 && poji.size() > K-i-2)
      res = min(res,min(2*abs(nega[i])+poji[K-i-2],abs(nega[i])+2*poji[K-i-2]));
  }
  cout << res << endl;
  return 0;
}

int par[MAX_N];
int ranks[MAX_N];

//n要素で初期化
void init(int n){
  REP(i,n){
    par[i] = i;
    ranks[i] = 0;
  }

}

//木の根を求める
int find(int x){
  if(par[x] == x){
    return x;
  }else{
    return par[x] = find(par[x]);
  }
}

void unite(int x,int y){
  x = find(x);
  y = find(y);
  if(x == y) return ;
  if(ranks[x] < ranks[y]){
    par[x] = y;
  }else{
    par[y] = x;
    if(ranks[x] == ranks[y]) ranks[x]++;
  }
}

bool same(int x, int y){
  return find(x) == find(y);
}

ll bpow(ll a, ll n,ll mod){
  int i = 0;
  ll res=1;
  while(n){
    if(n & 1)
      res = (res*a) % mod;
    a = (a*a) % mod;
    n >>= 1;
  }
  return res;
}
const int MOD = 1000000007;
mat mul(mat &A, mat &B){
  mat C(A.size(),vec(B[0].size()));
    REP(i,A.size())REP(k,B.size())REP(j,B[0].size()){
    C[i][j] = (C[i][j] + A[i][k] * B[k][j]) % MOD;
  }
  return C;
}

mat pow(mat A,ll n)
{
  mat B(A.size(),vec(A.size()));
  REP(i,A.size()){
    B[i][i] = 1;
  }
  while(n > 0){
    if ( n & 1) B = mul(B,A);
    A = mul(A,A);
    n >>= 1;
  }
  return B;
}


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

const ll INF = 1LL << 62;
const double PI = acos(-1);
const double eps = 1e-10;

int main() {
  ll k, x;
  cin >> k>>x;
  cout << (500*k>=x?"Yes":"No")<< endl;
  return 0;
}


Measured memory_bytes: 3596
//According to all known laws of aviation, there is no way that a bee should be able to fly.
//Its wings are too small to get its fat little body off the ground. The bee, of course, flies anyway.
//Because bees don't care what humans think is impossible.
#include <bits/stdc++.h>
#define FAST_IO  ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define mod 1000000007
#define endl "\n"
using namespace std ;
using bigint = long long int ;
using vi = vector<int> ;
using vll = vector<long long int> ;
  
int main(){
    bigint A ; cin >> A ;
    cout << A + A * A + A * A * A << endl ;
    return 0 ;
}


Measured memory_bytes: 3624
import java.util.*;

public class Main {

    public static void main(String[] args) {
        // write your code here
        Scanner sc = new Scanner(System.in);

        String[] list = sc.next().split("");

        int count = 0;

        for (int i = 0; i < list.length / 2; i++) {
            if (!list[i].equals(list[list.length - 1 - i])) {
                count++;
            }
        }

        System.out.println(count);
    }
}

Measured memory_bytes: 22100
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    string S, T;
    cin >> S >> T;
    rep(i, n) {
        cout << S[i] << T[i];
    }
    cout << endl;

    return 0;
}


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

set<string> v;

int main() {
	string s;
	int k;
	cin >> s;
	cin >> k;
	for (int i = 0; i < s.size(); i++) {
		string s0;
		for (int j = 0; j < k && i+j<s.size(); j++) {
			s0 = s0 + s[i+j];
			v.insert(s0);
			//cout << s0 << "\n";
		}
	}
	//cout << v.size() << "\n";
	//for (auto it = v.begin(); it != v.end(); it++) cout << *it << "\n";
	int cur = 1;
	auto it = v.begin();
	while (cur < k) {
		cur++;
		it++;
	}
	string ans = *it;
	cout << ans << "\n";
}

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

using namespace std;

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

struct UnionFind {
    vec<int> data;
    UnionFind(int size) : data(size, - 1) {}
    bool unionSet(int x, int y) {
        x = root(x);
        y = root(y);
        if (x != y) {
            if (data[y] < data[x]) swap(x, y);
            data[x] += data[y];
            data[y] = x;
        }
        return x != y;
    }

    bool findSet(int x, int y) {
        return root(x) == root(y);
    }

    int root(int x) {
        return data[x] < 0 ? x : data[x] = root(data[x]);
    }

    int size(int x) {
        return -data[root(x)];
    }
};

int main(void)
{
    int n, m;
    cin >> n >> m;
    vec<int> p(n), q(n);
    rep(i, n) {
        cin >> p[i];
        p[i]--;
    }
    rep(i, n) q[p[i]] = i;

    UnionFind uf(n);
    rep(i, m) {
        int a, b;
        cin >> a >> b;
        a--; b--;

        uf.unionSet(a, b);
    }

    int ans = 0;
    rep(i, n) {
        if (uf.findSet(p[i], q[p[i]])) ans++;
    }
    cout <<  ans <<  endl;
    return 0;
}


Measured memory_bytes: 1408
h, w = map(int, input().split())
masu = [input() for _ in range(h)]

ans = []
dy = [-1, -1, -1, 0, 0, 1, 1, 1]
dx = [-1, 0, 1, -1, 1, -1, 0, 1]

for y in range(h):
  tmp = ""
  for x in range(w):
    num = 0
    if masu[y][x] == "#":
      tmp += "#"
      continue
      
    for k in range(8):
      cy = y + dy[k]
      cx = x + dx[k]
      if cy < 0 or cy >= h:
        continue
      if cx < 0 or cx >= w:
        continue
      if masu[cy][cx] == "#":
        num += 1
    tmp += str(num)
  ans.append(tmp)
  
for a in ans:
  print(a)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
vector<pair<long long,long long> >v[20];
long long x[20];
int main()
{
    long long a,b,c,f=0,i,ii,j,n,m,d=0,p,q;
    string s;
    cin>>n;
    for(i=0;i<n;i++){
        cin>>m;
        for(j=0;j<m;j++){
            cin>>a>>b;
            v[i].push_back({a,b});
        }
    }
    f=1;
    for(i=0;i<n;i++){
        f*=2;
    }
    for(ii=0;ii<f;ii++){
        vector<long long>vc;
        a=ii;b=0;
        memset(x,0,sizeof(x));
        while(a){
            vc.push_back(a%2);
            x[b++]=a%2;
            a/=2;
        }
        while(vc.size()<n)vc.push_back(0);
        a=1;b=0;
        for(i=0;i<n;i++){
            if(vc[i]){
                b++;
                for(j=0;j<v[i].size();j++){
                    p=v[i][j].first;
                    q=v[i][j].second;
                    if(x[p-1]!=q)a=0;
                }
            }
        }
        if(a){
            d=max(d,b);
        }

    }
    cout<<d<<'\n';
    return 0;
}


Measured memory_bytes: 256
import math
n,d = list(map(int, input().split()))
x = [list(map(int, input().split())) for N in range(n)]
 
cnt = 0
 
for i in range(n):
  for j in range(i+1,n):
    kaijou = 0
    for k in range(d):
      kaijou = kaijou + abs(x[j][k]-x[i][k])**2
    if math.sqrt(kaijou).is_integer():
      cnt += 1
      
print(cnt)

Measured memory_bytes: 3064
#include<stdio.h>

int main()
{
	int a, b, c, mem;
  	scanf(" %d %d %d", &a, &b, &c);

  	if(a > c)

    {
      mem = a;
      a = c;
      c = mem;
    }
    if(a > b)
    {
      mem = a;
      a = b;
      b = mem;
    }
	if(b > c)
    {
      mem = b;
      b = c;
      c = mem;
    }

  	printf("%d\n", (b-a)+(c-b));

  	return 0;

}


Measured memory_bytes: 128
#include<cstdio>
#include<iostream>
using namespace std;
const int N = 1e5+10;
int n,a[N];
int main()
{
	cin>>n;
	for (int i = 0 ;i < n ;i++)
		cin>>a[i];

	long long ans = -1;
	for (int i = 0; i <= 1 ; i++)
	{
		long long sum = 0;
		long long cnt = 0;
		for (int j = 0; j < n; j++)
		{
			if (j%2 == i)
			{
				if (sum+a[j] <= 0)
				{
					long long dif = 1-sum;
					cnt+= abs(dif-a[j]);
					sum = 1;
				}
				else	sum+=a[j];
			}
			else
			{
				if(sum + a[j] >= 0)
				{
					long long dif = -1 - sum;
					cnt+= abs(dif - a[j]);
					sum = -1;
				}
				else	sum+=a[j];
			}
		}
		if (ans == -1) ans = cnt;
		else		   ans = min(ans,cnt);
	}
	cout<<ans<<endl;

return 0;
}

Measured memory_bytes: 4032
import sys
sys.setrecursionlimit(10**6)
n=int(input())
g=[[] for _ in range(n)]
for i in range(n-1):
  a,b=map(int,input().split())
  g[a-1]+=[(b-1,i)]
  g[b-1]+=[(a-1,i)]
l=[0]*(n-1)
def dfs(v,p=-1,s=-1):
  t=1
  for c,i in g[v]:
    if c==p: continue
    if t==s: t+=1
    l[i]=t
    dfs(c,v,t)
    t+=1
dfs(0)
print(max(l))
for i in l: print(i)

Measured memory_bytes: 94520
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);++i)
class BellmanFord{
    private:
    typedef std::pair<std::pair<int,int>,long long> P;
    int V,E;
    long long INF = (1LL<<61);
    std::vector<std::pair<std::pair<int,int>,long long>> es;
    
    public:
    void init(std::vector<std::pair<std::pair<int,int>,long long>> edge){
        //辺数をもとめる　
        E=edge.size();
        //頂点数を決定する
        V=0;
        for(int i=0;i<edge.size();i++){
            V=std::max(V,edge[i].first.first+1);
            V=std::max(V,edge[i].first.second+1);
        }
        es=edge;
    }
    
    std::vector<std::pair<long long,bool>> solve(int s){
        std::vector<std::pair<long long,bool>> d;
        //INFで初期化する
        for(int i=0;i<V;i++){
            d.push_back({INF,false});
        }
        d[s].first=0;
        for(int j=0;j<2*V;j++){
             bool update=false;
            for(int i=0;i<E;i++){
                P k=es[i];
                if(d[k.first.first].first!=INF && d[k.first.second].first>d[k.first.first].first+k.second){
                    d[k.first.second].first=d[k.first.first].first+k.second;
                    if(j>=V){
                        d[k.first.second].second=true;
                    }
                    update=true;
                }
            }
            if(!update)break;
        }
        return d;
    }
    
    //init:{{int,int},longlong}のvectorを渡すことで有向グラフを構築する
    //solve:始点を渡すとinitで構築したグラフでベルマンフォードをし、コストのvectorを返す
};

int main(){
    int N,M;
    int a[114514],b[114514],c[114514];
    std::vector<std::pair<std::pair<int,int>,long long>> G;
    std::vector<std::pair<long long,bool>> D;
    cin >> N >> M;
    REP(i,M){
        cin >> a[i] >> b[i] >> c[i];
        a[i]--;b[i]--;
        G.push_back({{a[i],b[i]},-c[i]});
    }
    BellmanFord bell;
    bell.init(G);
    D = bell.solve(0);
    if(D[N-1].second){
        cout << "inf" << endl;
    }else{
        cout << -D[N-1].first << endl;
    }
    return 0;
}


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

int main(){
    ll a,b;
    cin>>a>>b;
    int count=0;
    while(a--){
        ll x,y;
        cin>>x>>y;
        ll summ = x*x + y*y;
        ll sq = sqrt(summ);
        if(sq*sq < summ)sq=sq+1;
        if(sq<=b)count++;
    }
    cout<<count;




}

Measured memory_bytes: 3676
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <cstdio>
#include <limits>
#include <vector>
#include <cstdlib>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional> 
#include <iomanip>
#include <unordered_map>
#include <memory.h>
#include <cstring>
#include <fstream>
#include <stdio.h>
#include <stdlib.h>
#include <cassert>
#include <atcoder/all>
#include <cstdio>
#include <atcoder/math>

using namespace std;
using namespace atcoder;

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

	cin >> T;

	while (T--)
	{
		long long int n, m, a, b;
        cin >> n >> m >> a >> b;
		cout << floor_sum(n, m, a, b) << '\n';
	}
	return 0;
}


Measured memory_bytes: 3672
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N, M, P;
  int A[100];
  int s;
  cin >> N >> M >> P;
  while( N!=0 || M!= 0 || P!= 0){
  	s = 0;
  	for(int i = 0; i < N; i++){
  		cin >> A[i];
  		s += A[i];
  	}
  	if(A[M-1] != 0)cout << s*(100-P)/A[M-1] << endl;
  	else cout << 0 << endl;
  	cin >> N >> M >> P;
  }
  return 0;
}


Measured memory_bytes: 3048
#include<stdio.h>
int main(void){
    int a = 0,b = 0;
    while(1 > a || 1 > b || 100 < a || 100 < b){
        scanf("%d %d", &a, &b);
    }
    printf("%d %d\n", a*b, 2*(a+b));
    return 0;
}


Measured memory_bytes: 2052
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
typedef vector<vector<P>> vvP;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;

ll dp[110][110][310];  // dp[i+1][j][k] : i番目の品物まででj個選んで重さの総和k以下のときの価値の総和の最大値

int main() {
    ll n, W;
    cin >> n >> W;

    vl weight(n), value(n);
    rep(i, n) {
        cin >> weight[i] >> value[i];
    }

    ll w0 = weight[0];
    rep(i, n) {
        weight[i] -= w0;
    }
    
    rep(i, n) {
        rep(j, n) {
            exrep(k, 0, 3*n) {
                chmax(dp[i+1][j+1][k], dp[i][j+1][k]);
                if(k >= weight[i]) {
                    chmax(dp[i+1][j+1][k], dp[i][j][k - weight[i]] + value[i]);
                }
            }
        }
    }
    
    ll ans = 0;
    exrep(j, 1, n) {
        exrep(k, 0, 3*n) {
            if(w0*j + k <= W) {
                chmax(ans, dp[n][j][k]);
            }
        }
    }
    
    out(ans);
    re0;
}

Measured memory_bytes: 28672
#include<vector>
#include<cmath>
#include<map>
#include<cstdlib>
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<set>
#include<stack>
#include<bitset>
#include<functional>
#include<ctime>
#include<queue>
#include<deque>
#include<complex>
#include<cassert>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
//問題文および制約はちゃんと確認しよう！
//サイズは10^5じゃなくて2×10^5とかかもしれないし、重要な制約・条件を見落としているかも
//とりあえずサンプルを読んでから解法を考えよう？
int s[283];
lint dp[210][100100];
lint co[283][283],pa[283][283];
lint mo=1000000007;
vector<lint> zyo,rz;
lint extgcd(lint a, lint b, lint &x, lint &y) {
  lint g = a; x = 1; y = 0;
  if (b != 0) g = extgcd(b, a % b, y, x), y -= (a / b) * x;
  return g;
}
lint invMod(lint a, lint m) {
  lint x, y;
  if (extgcd(a, m, x, y) == 1) return (x + m) % m;return 0;
}
int main()
{
	rep(i,280){
		co[i][0]=co[i][i]=1;
		REP(j,1,i) co[i][j]=(co[i-1][j]+co[i-1][j-1])%mo;
	}
	rep(i,280) rep(j,280){
		pa[i][j]=co[i][j];
		rep(k,j){
			pa[i][j]*=k+1;pa[i][j]%=mo;
		}
	}
	int n,x;
	cin>>n>>x;
	rep(i,n) cin>>s[i];
	sort(s,s+n);reverse(s,s+n);
	memset(dp,0,sizeof(dp));
	dp[0][x]=1;
	rep(i,n) rep(j,100050){
		//if(dp[i][j]>0) cout<<i<<' '<<j<<' '<<dp[i][j]<<endl;
		dp[i+1][j]+=dp[i][j]*(n-i-1);
		dp[i+1][j]%=mo;
		dp[i+1][j%s[i]]+=dp[i][j];
		dp[i+1][j%s[i]]%=mo;
	}
	lint out=0;
	rep(i,100050){
		//if(dp[n][i]>0) cout<<n<<' '<<i<<' '<<dp[n][i]<<endl;
		out+=i*dp[n][i];out%=mo;
	}
	cout<<out<<endl;
}


Measured memory_bytes: 165760
read a b c
if [ $a -eq $b -a $a -eq $c ]
then
	echo 1
elif [ $a -eq $b -a $b -ne $c ] || [ $a -eq $c -a $c -ne $b ] || [ $b -eq $c -a $c -ne $a ]
then
	echo 2
else
	echo 3
fi


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

int main() {
	int n;
	cin>>n;
	vector<int> h(n+1);
	for(int i=1; i<=n; i++) cin>>h[i];
	
	vector<int> dp(n+1, 0);
	dp[1] = 0;
	dp[2] = dp[0] + abs(h[1] - h[2]);
	for(int i=3; i<=n; i++) {
		dp[i] = min(dp[i-1] + abs(h[i] - h[i-1]), dp[i-2] + abs(h[i] - h[i-2]));
	}
	cout<<dp[n];
	return 0;
	
	
}

Measured memory_bytes: 4036
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n, tmp = 0, max = 0;
    string s;
    cin >> n >> s;
    for (int i = 0; i < n; i++) {
        tmp = s[i] == 'I' ? ++tmp : --tmp;
        max = (tmp > max ? tmp : max);
    }
    cout << max << endl;
    return 0;
}


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

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

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

    long long ans = 0;
    int acc = 0;
    for (int i = 0; i < n; i++) {
        if (s[i] == 'A') {
            acc++;
            continue;
        }
        if (i + 1 < n && s[i] == 'B' && s[i + 1] == 'C') {
            ans += acc;
            i++;
            continue;
        }
        acc = 0;
    }
    cout << ans << endl;
}

Measured memory_bytes: 720
#include<iostream>
#include<string>
#include<vector>
#include<iomanip>
#include<map>
using namespace std;
#define ll long long
int main(){
    int A,B,C;
    cin >> A >> B >>C;
    int ans =10*A+B+C;
    if(10*B+A+C>ans)ans=10*B+A+C;
    if(10*C+A+B>ans)ans=10*C+A+B;
    cout << ans;
    return 0;
}


Measured memory_bytes: 256
use proconio::fastout;
use proconio::input;

#[fastout]
fn main() {
    input! {
        x: i64,
        k: u64,
        d: u64,
    }
    let x = if x < 0 { (-x) as u64 } else { x as u64 };
    let c = x / d; //何回移動するか
    let ans = if c >= k {
        x - k * d
    } else {
        let rest = k - c;
        let dist = x - c * d;
        if rest % 2 == 0 {
            dist
        } else {
            d - dist
        }
    };
    println!("{}", ans);
}


Measured memory_bytes: 2200
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
    ll n,a,b;
    double m=-1;
    cin>>a>>b>>n;
    if(b>n)
    cout<<(a*(n)/b)<<endl;
    else cout<<(a*(b-1)/b)-a*((b-1)/b)<<endl;
    return 0;
}


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

string S;

int main() {
  cin >> S;
  bool flag = true;
  for(int i=0; i<ceil((S.size()+1)/2); i++) {
    if(S[2*i] == 'L') {
      flag = false;
    }
  }
  for(int i=0; i<S.size()/2; i++) {
    if(S[2*i+1] == 'R') {
      flag = false;
    }
  }
  if(flag) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}



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

#ifdef _DEBUG
#define dout cout
#define debug() if (true)
#define dvout(v) vout(v)
#else
#define dout if (false) cout
#define debug() if (false)
#define dvout(v) if(false) vout(v)
#endif

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define all(x) (x).begin(), (x).end()
#define vout(v)           \
	for (auto &i : v)     \
	{                     \
		cout << i << " "; \
	}                     \
	cout << "\n"; //配列出力
#define vec(v, n) vector<int> v(n, 0);
#define vin(v)        \
	for (auto &i : v) \
		cin >> i; //配列入力

#define mod (int)(1e9+7)
typedef long long ll;
typedef unsigned long long ull;
#define next asdnext
#define prev asdprev
#define _n "\n"
#define _n2 "\n\n"
#define _t "\t"



void Main()
{
	int N;
	cin>>N;
	vec(v,N+1);
	for(int k=1;k<=N;k++){
		for(int i=k; i<=N; i+=k){
			v[i]++;
		}
	}

	ull ans=0;
	for(int k=1; k<=N;k++){
		ans += (ull)k*v[k];
		//dout<<k<<':'<<v[k]<<_n;
	}

	cout<<ans<<endl;
}



int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << std::fixed << std::setprecision(15);
	Main();
	return 0;
}


Measured memory_bytes: 42252
def main():
	a,b , c = map(int , input().split())
	ans = a*b*c
	ans = min(ans, abs(b*c*((a//2)-(a-(a//2)))))
	ans = min(ans, abs(a*c*((b//2)-(b-(b//2)))))
	ans = min(ans, abs(b*a*((c//2)-(c-(c//2)))))
	print(ans)
if __name__=="__main__":
	main()

Measured memory_bytes: 61836