akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <utility>
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
using namespace std;
int n;
vector<vector<int> > a;
map<pair<int,int>,int> mp;
vector<vector<int> > edge;
vector<int> dp;

int rec(int v){
  if(dp[v]>=0) return dp[v];
  int res = 0;

  int es = edge[v].size();
  rep(i,es){
    int w = edge[v][i];
    res = max(res,rec(w)+1);
  }
  return dp[v] = res;
}
vector<bool> visited,visiting;
bool find_loop(int v){
  bool f = true;
  visiting[v] = true;
  rep(i,edge[v].size()){
    int w = edge[v][i];
    if(visited[w]) continue;
    if(visiting[w]) return false;
    f = f&&find_loop(w);
  }
  visited[v] = true;
  return f;
}
pair<int,int> pair_make(int x,int y){
  if(x<y) return make_pair(x,y);
  else return make_pair(y,x);
}

int main()
{
  cin >> n;
  a.resize(n);
  rep(i,n) a[i].resize(n-1);
  rep(i,n){
    rep(j,n-1){
      cin >> a[i][j];
      a[i][j]--;
    }
  }
  
  {
    int k = 0;
    rep(i,n){
      for(int j=i+1;j<n;++j){
	mp[make_pair(i,j)] = k++;
      }
    }
  }

  
  edge.resize(n*(n-1)/2);
  rep(i,n){
    rep(j,n-2){
      edge[mp[pair_make(i,a[i][j])]].push_back(mp[pair_make(i,a[i][j+1])]);
    }
  }

  visited.assign(n*(n-1)/2,0);
  visiting.assign(n*(n-1)/2,0);  

  bool f = true;
  rep(i,n*(n-1)/2){
    if(!visited[i]) f = f&&find_loop(i);
  }
  if(f){
    dp.assign(n*(n-1)/2,-1);
    rep(i,n*(n-1)/2){
      rec(i);
    }
    int m = 0;
    rep(i,n*(n-1)/2) m = max(m,dp[i]);
    cout << m+1 << "\n";
  }
  else{
    cout << -1 << "\n";
  }
  
  return 0;
}


Measured memory_bytes: 64896
#pragma GCC optimize("O3")
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

using ll = long long;
using P = pair<int, int>;
using T = tuple<int, int, int>;

template <class T> inline T chmax(T &a, const T b) {return a = (a < b) ? b : a;}
template <class T> inline T chmin(T &a, const T b) {return a = (a > b) ? b : a;}

constexpr int MOD = 1e9 + 7;
constexpr int inf = 1e9;
constexpr long long INF = 1e18;

#define all(a) (a).begin(), (a).end()

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

vector<ll> prime_factorization(ll n){
    vector<ll> v;
    ll num = n;
    for(ll i=2; i*i<=n; i++){
        while(num % i == 0){
            num /= i;
            v.emplace_back(i);
        }
    }

    if(num != 1){
        v.emplace_back(num);
    }

    return v;
}

ll modpow(ll a, ll b){
    if(b == 0) return 1;
    else if(b % 2 == 0){
        ll d = modpow(a, b / 2) % MOD;
        return (d * d) % MOD;
    }
    else{
        return (a * modpow(a, b - 1)) % MOD;
    }
}

const int MAX_N = 200010;
ll fact[MAX_N], finv[MAX_N];
ll comb(int n, int r){
    if(n < r || r < 0) return 0;
    return fact[n] * finv[n-r] % MOD * finv[r] % MOD;
}

void comb_init(int n){
    fact[0] = finv[0] = 1;
    for(int i=1; i<=n; i++){
        fact[i] = (fact[i-1] * i) % MOD;
        finv[i] = modpow(fact[i], MOD - 2);
    }
}

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

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

    comb_init(200005);

    auto v = prime_factorization(m);

    map<int, int> pcnt;
    for(auto i : v) pcnt[i]++;

    ll ans = 1;
    for(auto i : pcnt){
        ans *= comb(i.second + n - 1, i.second);
        ans %= MOD;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3328
#include <iostream>
#include <stdio.h>
#include <cmath>
using namespace std;
int main(){
    double a,b,c,d,e,f;
    while(cin >> a >>b >> c >> d >> e >> f){
    double det,x,y;
    det = a*e-b*d;
    x = (e*c-b*f)/det;
    y = (-c*d+a*f)/det;
    if (x==0)
        x = fabs(x);
    if (y==0)
        y = fabs(y);
    printf("%.3f %.3f\n",x,y);}
}

Measured memory_bytes: 1236
using System;
using System.Linq;

namespace atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var inputs = Console.ReadLine().Split(' ');

            var n = int.Parse(inputs[0]);
            var a = int.Parse(inputs[1]);
            var b = int.Parse(inputs[2]);

            var max = Math.Min(a, b);
            var min = 0;

            var ab = a + b;

            min = ab - n;

            if (min > 0)
            {
                Console.WriteLine($"{max} {min}");
            }
            else
            {
                Console.WriteLine($"{max} 0");
            }
        }
    }
}


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

int main() {
  string s, t, u;
  int a, b;
  cin >> s >> t >> a >> b >> u;
  
  if(u == s) --a;
  else --b;
  
  cout << a << " " << b << endl;
    
  return 0;
}


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

int tairyoku(int &n,vector<int> &x,int i){ 
    int y=0;
    for(int j=0;j<n;j++){
        y+=(x.at(j)-i)*(x.at(j)-i);
    }
    return y;
}

int main(){
    int n;
    cin>>n;
    vector<int> x(n,0);
    for(int &p : x) cin>>p;
    int p=tairyoku(n,x,1);
    for(int i=2;i<=100;i++){
        if(p>tairyoku(n,x,i)) p=tairyoku(n,x,i);
    }
    cout<<p<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
	int n;cin>>n;vector<int> ls(n);
	for(auto &x:ls)cin>>x;
	vector<int>dp(n,1e9);dp[0]=0;
	for(int u=0;u<n;u++){
		for(int v:{u+1,u+2}){
			if(v<n){
				dp[v]=min(dp[v],dp[u]+abs(ls[u]-ls[v]));}
			}}
	cout<<dp[n-1];
}
	
		


Measured memory_bytes: 3972
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, _s, n) for(int i = _s, i##_len = (n); i < i##_len; ++i)
#define ALL(x) (x).begin(), (x).end()
using namespace std;

#define repi(itr, ds) for(auto itr = ds.begin(); itr != ds.end(); itr++)
// vector
template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
  for(T &x : vec) is >> x;
  return is;
}
// pair
template <typename T, typename U>
ostream &operator<<(ostream &os, pair<T, U> &pair_var) {
  os << "(" << pair_var.first << ", " << pair_var.second << ")";
  return os;
}
// vector
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
  os << "{";
  for(int i = 0; i < vec.size(); i++) {
    os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
  }
  os << "}\n   ";
  return os;
}
// map
template <typename T, typename U>
ostream &operator<<(ostream &os, map<T, U> &map_var) {
  os << "{";
  repi(itr, map_var) {
    os << *itr;
    itr++;
    if(itr != map_var.end()) os << ", ";
    itr--;
  }
  os << "}";
  return os;
}
// set
template <typename T>
ostream &operator<<(ostream &os, set<T> &set_var) {
  os << "{";
  repi(itr, set_var) {
    os << *itr;
    itr++;
    if(itr != set_var.end()) os << ", ";
    itr--;
  }
  os << "}";
  return os;
}

#define DUMPOUT cerr

void dump_func() { DUMPOUT << endl; }
template <class Head, class... Tail>
void dump_func(Head &&head, Tail &&... tail) {
  DUMPOUT << head;
  if(sizeof...(Tail) > 0) {
    DUMPOUT << ", ";
  }
  dump_func(std::move(tail)...);
}
#ifdef DEBUG_
#define DEB
#define dump(...)                                                             \
  DUMPOUT << "  " << string(#__VA_ARGS__) << ": "                             \
          << "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]" << endl \
          << "    ",                                                          \
      dump_func(__VA_ARGS__)
#else
#define DEB if(false)
#define dump(...)
#endif

typedef long long int ll;

bool comp_by_first(pair<int, int> a, pair<int, int> b) { return a.first < b.first; }
int main() {
  int N;
  cin >> N;
  auto A = vector<pair<int, int>>();
  REP(i, N) {
    int a;
    cin >> a;
    A.push_back({a, i + 1});
  }

  sort(ALL(A), comp_by_first);

  REP(i, N) {
    int n = A[i].second;
    cout << n << " ";
  }
  cout << endl;
}


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

int main(){
    long long s, i(1);
    scanf("%lld", &s);
    if(s == 4 || s == 2 || s == 1)return 0 & printf("%lld", 4);
    while(1){
        if(s == 4)return 0 & printf("%lld", i + 3);
        if(s & 1)s = 3 * s + 1;
        else s >>= 1;
        ++i;
    }
}


Measured memory_bytes: 256
# coding: utf-8
# Your code here!

SIZE=2*10**5+5; MOD=10**9+7 #998244353 #ここを変更する

SIZE += 1
inv = [0]*SIZE  # inv[j] = j^{-1} mod MOD
fac = [0]*SIZE  # fac[j] = j! mod MOD
#finv = [0]*SIZE # finv[j] = (j!)^{-1} mod MOD
inv[1] = 1
fac[0] = fac[1] = 1
#finv[0] = finv[1] = 1
for i in range(2,SIZE):
    inv[i] = MOD - (MOD//i)*inv[MOD%i]%MOD
    fac[i] = fac[i-1]*i%MOD
    #finv[i]= finv[i-1]*inv[i]%MOD


import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline
read = sys.stdin.read

n = int(input())
ab = [int(i)-1 for i in read().split()]

g = [[] for _ in range(n)]
M = iter(ab)
for a,b in zip(M,M):
    g[a].append(b)
    g[b].append(a)

order = []
parent = [-1]*n
q = [0]
while q:
    v = q.pop()
    order.append(v)
    for c in g[v]:
        if c != parent[v]:
            q.append(c)
            parent[c] = v
        
size = [1]*n
for i in order[n-1:0:-1]:
    size[parent[i]] += size[i]

res = fac[n]
for i in range(n):
    res *= inv[size[i]]
    res %= MOD

ans = [0]*n
ans[0] = res

for c in order[1::]:
    v = parent[c]
    ans[c] = ans[v]*size[c]%MOD*inv[n-size[c]]%MOD

print(*ans,sep="\n")


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

int main() {
	string str,rev,ord,rep;
    int q,a,b;
    cin >> str >> q;
    for(int i = 0;i < q;i++){
    	cin >> ord >> a >> b;
    	if (ord =="print")
    		cout << str.substr(a,b-a+1) << endl;
    	else if(ord == "reverse"){
    		for (int j = 0;j < b-a+1;j++){
    			rev[j] = str[b-j];
    		}
    		for (int j = 0;j < b-a+1;j++){
    			str[a+j] = rev[j];
    		}
    	}
    	else if(ord == "replace"){
    		cin >> rep;
    		for (int j = 0;j < b-a+1;j++){
    			str[a+j] = rep[j];
    		}
    	}
    }
	return 0;
}

Measured memory_bytes: 3184
// Template from https://techracho.bpsinc.jp/jhonda/2019_08_05/78537

// input macro for competive-programming from https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

#[allow(unused_macros)]
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)*}
    };

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

#[allow(unused_macros)]
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<_>>()
    };

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

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

    ($iter:expr, bytes) => {
        read_value!($iter, String).into_bytes()
    };

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

fn main() {
    use std::io::Read;
    let mut s = String::new();
    std::io::stdin().read_to_string(&mut s).unwrap();

    println!("{}", solve(&s));
}

macro_rules! test {
    ($($input:expr => $output:expr),* $(,)*) => {
        #[test]
        fn solve_test() {
            $(
                assert_eq!(solve($input), $output);
            )*
        }
    };
}

test! {
r#"3 4 5"# => r#"6"#,
r#"5 12 13"# => r#"30"#,
r#"45 28 53"# => r#"630"#,
}

fn solve(src: &str) -> String {
    input! {
        source = src,
        mut abc: [usize; 3]
    }
    abc.sort();

    ( abc[0] * abc[1] / 2 ).to_string()
}

Measured memory_bytes: 4352
#include <stdio.h>
#include <stack>
#include <math.h>

using namespace std;

int main(){

	int n,table[183];
	int* dp = new int[1000000];
	int* odd_dp = new int[1000000];

	for(int i=0; i < 183; i++)table[i] = i*(i+1)*(i+2)/6;

	for(int i=0; i < 1000000; i++){
		odd_dp[i] = 20000000;
		dp[i] = 20000000;
	}

	dp[0] = 0;
	dp[1] = 1;

	odd_dp[0] = 0;
	odd_dp[1] = 1;

	for(int i = 2; i < 1000000; i++){
		for(int k = 1; table[k] <= i; k++){
			dp[i] = (dp[i] <= dp[i-table[k]]+1)?dp[i]:dp[i-table[k]]+1;
			if(table[k]%2 == 1){
				odd_dp[i] = (odd_dp[i] <= odd_dp[i-table[k]]+1)?odd_dp[i]:odd_dp[i-table[k]]+1;
			}
		}
	}


	while(true){
		scanf("%d",&n);
		if(n == 0)break;

		printf("%d %d\n",dp[n],odd_dp[n]);
	}

    return 0;
}

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

int main(){
  int n,m;
  cin >> n >> m;
  priority_queue<int> q;
  rep(i,n){
    int a;
    cin >> a;
    q.push(a);
  }
  rep(i,m){
    int a = q.top(); q.pop();
    q.push(a/2);
  }
  ll ans=0;
  rep(i,n){
    ans += q.top(); q.pop();
  }
  cout << ans;
  
  return 0;
}

Measured memory_bytes: 3928
from functools import reduce

def original_sum(X, init):
    goukei = 0
    if(len(X) == 0):
        #print("aaa")
        #print(sum(init))
        return sum(init)
    else:
        for i in range(len(X)):
            lstm = init.copy()
            #print(len(X))
            num = int(reduce(lambda x, y: x + y, [str(x) for x in X[0:i+1]]))
            #print(num)
            #init = num
            lstm.append(num)
            Y = X[i+1:len(X)].copy()
            #print(len(Y))
            #if(len(X)-i-1 != 0):
            goukei = goukei + original_sum(Y, lstm)
            #else:
                #sum = sum + (len(X)-i-1)num + original_sum(Y)
            #print(sum)

    return goukei


number = list(input())
init = []
print(original_sum(number, init))

Measured memory_bytes: 9624
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
typedef int64_t llo;
#define mp make_pair
#define pb push_back
#define a first
#define b second
void setIO(string name) {
	ios_base::sync_with_stdio(0); cin.tie(0);
	freopen((name+".in").c_str(),"r",stdin);
	freopen((name+".out").c_str(),"w",stdout);
}
int n;
string s;
int dp[200003];
int ind[26][200003];
int aa[200003];
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin>>s;
	int n=s.size();
	for(int i=0;i<n;i++){
		aa[i]=s[i]-'a';
	}
//	string ss="abcdefghijklmnopqrstuvwxyz";
	string ss="abcdefghijklmnopqrstuvwxyz";
	for(int j=0;j<26;j++){
		int ind2=n;
		for(int i=n-1;i>=0;i--){
			if(aa[i]==j){
				ind2=min(ind2,i);
			}
			ind[j][i]=ind2;
			
		}

	}
	for(int i=n-1;i>=0;i--){
		dp[i]=n;
		for(int j=0;j<26;j++){

			if(ind[j][i]>=n){
				dp[i]=1;
			}
			else if(ind[j][i]==n-1){
				dp[i]=min(dp[i],2);
			}
			else{
				dp[i]=min(dp[i],dp[ind[j][i]+1]+1);
			}
		}
	}
	int ind2=0;
	for(int i=0;i<dp[0];i++){
		for(int j=0;j<26;j++){
			if(ind2>=n){
				cout<<ss[j];
				break;
			}
			if(ind[j][ind2]>=n){
				cout<<ss[j];
				break;
			}
			else{
				if(dp[ind[j][ind2]+1]+i+1==dp[0]){
					cout<<ss[j];
					ind2=ind[j][ind2]+1;
					break;
				}
			}
		}
	}
	//cout<<ind[0][0]<<endl;
	cout<<endl;
	


	return 0;
}

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

int main() {
  int n,x;
  int sum = 0;
  cin >> n >> x;
  vector<int>num(n);
  for (int i = 0; i < n; i++) {
    cin >> num.at(i);
  }
  sort(num.begin(),num.end());
  for (int i = 0; i < n; i++) {
    sum += num.at(i);
    if (sum == x) {
      cout << i+1 << endl;
      break;
    }
    else if (sum > x) {
      cout << i << endl;
      break;
    } 
    else if (i == n-1) {
      cout << n-1 << endl;
    }
  }
}  

Measured memory_bytes: 256
import java.util.*;
import java.io.*;

public class Main{

     public static void main(String []args){
       Scanner scanner = new Scanner(System.in);
       int n1= scanner.nextInt();
        int n2= scanner.nextInt();
        List<String> list = new ArrayList<>();
        
        for(int i=0;i<n1;i++)
        {
          list.add(scanner.next());  
        }
       
       Collections.sort(list);
       
        for(int i=0;i<list.size();i++)
        System.out.print(list.get(i));
       
     }
}

Measured memory_bytes: 37284
N = int(input())
t = 0
x = 0
y = 0
for i in range(N):
  T,X,Y = map(int,input().split())
  dt = T - t
  dist = abs(X-x) + abs(Y - y)
  if dist > dt:
    print("No")
    break
  if dist%2 != dt%2:
    print("No")
    break
  t = T
  x = X
  y = Y
  if i == N - 1:
    print("Yes")
  

Measured memory_bytes: 9176
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
k = int(input())

line = [a, b, c, d, e]

ans = 0
for i in range(5):
    for j in range(5):
        if abs(line[i] - line[j]) > k:
            ans += 1
            break

if ans >= 1:
    print(":(")
else:
    print("Yay!")

Measured memory_bytes: 3064
n = int(input())
rn = [[0, 0, 0]]
for i in range(n):
    rn.append(list(map(int, input().split())))

for i in range(n):
    t = rn[i + 1][0] - rn[i][0]
    distx = rn[i + 1][1] - rn[i][1]
    disty = rn[i + 1][2] - rn[i][2]
    k = abs(distx) + abs(disty)
    if (t >= k) and ((t + k) % 2 == 0):
        continue
    else:
        print('No')
        exit()
print('Yes')


Measured memory_bytes: 27300
#include<iostream>
#include<vector>
#include<string>

using namespace std;

int main(){
    int h, w, ans = 0;
    cin >> h >> w;
    vector<string> s(h);
    for(int i = 0; i < h; i++){
        cin >> s[i];
    }
    vector<bool> row(h), col(w);
    for(int y = 0; y < h; y++){
        for(int x = 0; x < w; x++){
            if(s[y][x] == '#') row[y] = col[x] = true;
        }
    }
    for(int y = 0; y < h; y++){
        if(!row[y]) continue;
        for(int x = 0; x < w; x++){
            if(!col[x]) continue;
            cout << s[y][x];
        }
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;

int main(){
  int a[3];
  for(int i=0;i<3;i++) cin >> a[i];

  sort(a, a + 3);

  cout << a[0] + a[1] << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long n,q,a[100010],b,c,d[100010],x;
int main(){
    cin>>n;
    for (int i=0;i<n;i++) cin>>a[i];
    for (int i=0;i<n;i++) d[a[i]]++,x+=a[i];
    cin>>q;
    for (int i=0;i<q;i++){
        cin>>b>>c;
        x+=(d[b]*(c-b));
        d[c]+=d[b];d[b]=0;
        cout<<x<<endl;
    }
    return 0;
}

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

int main(){
    string s;
    cin >> s;
    vector<int> a(3);
    rep(i,3){
        if(s.at(i)=='a') a.at(0) ++;
        else if(s.at(i)=='b') a.at(1) ++;
        else if(s.at(i)=='c') a.at(2) ++;
    }
    if(a[0]==1 && a[1]==1 && a[2]==1){
        cout << "Yes" << endl;
    }
    else cout << "No" << endl;
}

Measured memory_bytes: 3572
n,k = gets.split.map &:to_i
MOD = 10**9+7

# nから始まる連続したk個の自然数の和
def sum_head(n,k)
  k * (2 * n + k - 1) / 2 % MOD
end

# nを末尾に持つ連続するk個の自然数の和
def sum_tail(n,k)
  k * (2 * n - k + 1) / 2 % MOD
end

ans = 0
k.upto(n+1) do |i|
  head = sum_head(0,i)
  tail = sum_tail(n,i)
  cnt = tail - head + 1
  # p [n,k,i,head,tail,cnt]
  ans += cnt
  ans %= MOD
end

puts ans

  

Measured memory_bytes: 14320
use std::env;
use std::io::*;
use std::str::*;
use std::mem;
use std::collections::HashMap;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let s = stdin.bytes().map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect::<String>();
    s.parse::<T>().ok().unwrap()
}
fn read_char() -> char {
    let c = read::<String>();
    let c = c.chars().collect::<Vec<char>>();
    c[0]
}
fn read_String_Vec() -> Vec<char> {
    let S = read::<String>();
    S.chars().collect::<Vec<char>>()
}

fn vecchar_to_String(Vs: Vec<char>) -> String {
    let mut S = String::new();
    for i in 0..Vs.len() {
        S.push(Vs[i]);
    }
    S
}

/*
A : 65
Z : 90
a : 97
z : 122
*/

/*
let N = read::<i32>();
let S = read::<String>();
let S = read_String_Vec();
let C = read_char();
*/

/*
 .to_string() : * -> String
 &*S          : String -> &str
*/

fn main() {
    // main の引数
    /*
        引数なしのときargs.len() = 1;
    */
    let args: Vec<String> = env::args().collect();

    let N = read::<i32>();
    let L = read::<i32>();
    let mut Ss = Vec::new();
    for i in 0..N {
        let S = read::<String>();
        Ss.push(S);
    }
    Ss.sort();
    let mut strings = String::new();
    for i in 0..N {
        strings = (strings + &*Ss[i as usize]).to_string();
    }
    println!("{}", strings);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
	ll n,k;
	cin>>n>>k;
	ll a[n];
	for (ll i=0;i<n;i++)
		cin>>a[i];
	ll dp[k+1];
	//memset(dp,0,sizeof(dp));
	dp[0]=0;
	for (ll i=1;i<=k;i++)
	{	
	ll f=0;
	ll g=0;
	for (ll j=0;j<n;j++)
		{
			if (i>=a[j])
			{
				g=1;
				if (dp[i-a[j]]==0)
					f=1;
			}
		}
		if (g==0)
			dp[i]=0;
		else if (f)
			dp[i]=1;
		else
			dp[i]=0;
	}
	// for (ll i=1;i<=k;i++)
	// 	cout<<dp[i]<<" ";
	if (dp[k])
		cout<<"First";
	else
		cout<<"Second";
}

Measured memory_bytes: 1024
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define all(x) x.begin(),x.end()
#define ln '\n'
const long double PI = acos(-1.0L);
const long long MOD = 1000000007LL;
// const long long MOD = 998244353LL;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
template<class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true;} return false; }
template<class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true;} return false; }
////////////////////////////////////////////////////////////////////////////////////////////////////////

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int K,Q; cin >> K >> Q;
    vector<ll> d(K),e(K);
    rep(i,K) cin >> d[i];

    while (Q--) {
        ll N,x,m; cin >> N >> x >> m;
        rep(i,K) {
            e[i] = d[i]%m;
            if (e[i]==0) e[i] = m;
        }
        ll val = (N-1)/K*accumulate(all(e),0LL) + x;
        rep(i,(N-1)%K) {
            val += e[i];
        }
        cout << N-1-val/m+x/m << ln;
    }
}



Measured memory_bytes: 384
//#include <ext/pb_ds/assoc_container.hpp>
#include <bits/stdc++.h>
using namespace std;
//using namespace __gnu_pbds;
//template <class c, class cmp = less<c> > using ordered_set = tree<c, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL); 
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...) 
#endif
template<class T> ostream& operator<<(ostream &os, vector<T> V) {os << "[ "; for(auto v : V) os << v << " "; return os << "]";}
template<class L, class R> ostream& operator<<(ostream &os, pair<L,R> P) {return os << "(" << P.first << "," << P.second << ")";}
template <typename T,typename U>pair<T,U> operator+(const pair<T,U> & l,const std::pair<T,U> & r) { return {l.first+r.first,l.second+r.second};}
typedef long long int ll;
const ll mod =1e9+7;
const int maxn = 2000005;
#define endl '\n'
#define int ll
#define ld long double
#define all(x) (x).begin(),(x).end()

int32_t main()
{ 
  IOS
  
  string s;
  cin>>s;
  int cnt = 0;
  for(int i = 0;i<s.size();i++) if(s[i] == '?') s[i] = 'D';
  cout<<s<<endl;
}
 

Measured memory_bytes: 3732
//abc168

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

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

  if(s.size() <= k){
    cout << s;
  }else{
    cout << s.substr(0,k) << "..." << endl;
  }

}


Measured memory_bytes: 3592
###### Importing Libraries ######
import math
import operator as op
from functools import reduce
from fractions import Fraction as frac
#################################
##### User defined function #####

############ NCR ###############
def ncr(n, r):
    r = min(r, n-r)
    numer = reduce(op.mul, range(n, n-r, -1), 1)
    denom = reduce(op.mul, range(1, r+1), 1)
    return numer / denom
    
############ READ ###############
def rd(p):
    if(p==0):
        return input()
    if(p==1):
        return int(input())
    if(p==2):
        return map(int,input().split())
    if(p==3):
        return list(map(int,input().split()))


############ DSU ###############
global par
# par=[-1 for i in range(100001)]
# t=rd(1)
def find(u):
    if(par[u]<0):
        return u
    else:
        return find(par[u])
def uni(x,y):
    u=find(x)
    v=find(y)
    if u==v:
        return
    if(par[u]<par[v]):
        par[u]+=par[v]
        par[v]=u
    else:    
        par[v]+=par[u]
        par[u]=v
################################        
        

t=1
for term in range(1,t+1):
    n,a,b=rd(2)
    X=rd(3)
    ans=0
    for i in range(1,n):
        ans+=min((X[i]-X[i-1])*a,b)
    print(ans)
    
    
    
    
    
    
    
    
    
    
    
    

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

#define FLASH ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define int long long int
#define MAX 1e9
#define MIN -1e9
#define mod 1000000007
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define debug(x) cerr<<#x<<'='<<(x)<<endl;
#define output(x) cout << ( x ? "YES" : "NO" ) << '\n' ;
#define mxn 100005
using namespace std;

void solve(){
    int n;
    cin >> n ;
    int a[n + 1],pref[n + 2] = {};
    for(int i = 1; i <= n; i++){
        cin >> a[i];
    }
    for(int i = n; i >= 1; i--){
        pref[i] = pref[i + 1] + a[i];
        pref[i] %= mod;
    }
    int ans = 0;
    for(int i = 1; i <= n; i++){
        ans += a[i] * pref[i + 1];
        ans %= mod;
    }
    cout << ans ;
}

int32_t main()
{
    FLASH
    int t = 1;
    // cin >> t;
    while(t--){
        solve();
    }
    return 0;
}



Measured memory_bytes: 6764
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>
#include <cstring>
#include <cassert>


using namespace std;
#define SZ(x) (int)(x.size())
#define REP(i, n) for(int i=0;i<n;++i)
#define FOR(i, a, b) for(int i=a;i<b;++i)
#define RREP(i, n) for(int i=n-1;i>=0;--i)
#define RFOR(i, a, b) for(int i=b-1;i>=a;--i)

#define all(x) begin(x),end(x)
#define dump(x) cerr<<#x<<" = "<<(x)<<endl
#define debug(x) cerr<<#x<<" = "<<(x)<<" (L"<<__LINE__<<")"<< endl;

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using P = pair<int, int>;
const double eps = 1e-8;
const ll MOD = 1000000007;
const int INF = INT_MAX / 2;
const ll LINF = LLONG_MAX / 2;

template<class T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
bool chmin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}


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

template<class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
    os << "[";
    REP(i, SZ(v)) {
        if (i) os << ", ";
        os << v[i];
    }
    return os << "]";
}

template<class T1, class T2>
ostream &operator<<(ostream &os, const map<T1, T2> &mp) {
    os << "[";
    for (auto it = mp.begin(); it != mp.end(); ++it) {
        if (it != mp.begin()) {
            os << ", ";
        }
        os << *it;
    }
    return os << "]";
}

// edit

void solve() {
    int N;
    ll D;
    cin >> N >> D;

    int ans = 0;
    REP(i, N) {
        ll x, y;
        cin >> x >> y;
        if (x * x + y * y <= D * D) {
            ans++;
        }
    }
    cout << ans << endl;
}


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
//    std::ifstream in("input.txt");
//    std::cin.rdbuf(in.rdbuf());

    solve();


    return 0;
}


Measured memory_bytes: 3192
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    
    int[] ans = new int[N];
    for (int i = 1; i <= N; i++) {
      int a = sc.nextInt();
      if (N%2 == 0) {
        if (i%2 == 0) {
          ans[N/2-1-(i-1)/2] = a;
        } else {
          ans[N/2+i/2] = a;
        }
      } else {
        if (i%2 == 1) {
          ans[N/2-i/2] = a;
        } else {
          ans[N/2+i/2] = a;
        }
      }
    }
    
    for (int i = 0; i < N; i++) {
      System.out.print(ans[i] + " ");
    }
    System.out.println();
  }
}

Measured memory_bytes: 92304
#include<stdio.h>
int main()
{
    int A,B;
    scanf("%d%d",&A,&B);
    if(A==1&&B==2||A==2&&B==1)
    {
        printf("3");
    }
    else if(A==2&&B==3||A==3&&B==2)
    {
        printf("1");
    }
     else if(A==1&&B==3||A==3&&B==1)
    {
        printf("2");
    }

       return 0;
}


Measured memory_bytes: 1660
import java.lang.Math

val MOD: Int = 1000000000 + 7
val MODL: Long = MOD.toLong()

fun main(args: Array<String>)
{
    val n = read().toInt()
    val a = read().split(" ").map{it.toInt()}.toIntArray()

    var cnt = 1
    var ans = 0
    for (i in 0 until n) {
        if (a[i] != cnt) ans++
        else cnt++
    }

    println(if (ans == n) -1 else ans)
}

fun read(): String = readLine()!!


Measured memory_bytes: 82872
#include <algorithm>
#include <stack>
#include <queue>
#include <deque>
#include <vector>
#include <string>

using namespace std;

#include <iostream>
//#include <fstream>

//ifstream cin ("input.in");
//ofstream cout ("output.out");

//ifstream cin (".in")
//ofstream cout (".out");

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

	int a, b, c;
	cin>>a>>b>>c;
	if ( (c >= a && c <= b ) || (c <= a && c >= b ) ) {
		cout<<"Yes"<<'\n';
	} else {
		cout<<"No"<<'\n';
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define IO ios_base::sync_with_stdio(false)
long long int a[300000], b[300000];


int main()
{
    IO;
    long long int i, j, n, m, k=0, l=0, t,h, p=0, mx=0,kk,ll,lp,ans1=0,ans2=0;

   // cin>>t;
   // while(t--){
        p++;
        cin>>n;
        for(i=1; i<=n; i++){
            cin>>l;
            if(l%2==0&&l%3!=0&&l%5!=0) k=1;
        }
        k==0?cout<<"APPROVED"<<endl:cout<<"DENIED"<<endl;
        //cout<<"Case "<<p<<": ";
   //}
    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define ri(x) scanf("%d",&(x))
#define ri2(x,y) scanf("%d %d",&(x),&(y))
#define ri3(x,y,z) scanf("%d %d %d",&(x),&(y),&(z))
#define rll(x) scanf("%lld",&(x))
#define rll2(x,y) scanf("%lld %lld",&(x),&(y))
#define rll3(x,y,z) scanf("%lld %lld %lld",&(x),&(y),&(z))
#define gc(x) ((x) = getchar())
using namespace::std;

const long double PI = acos(-1);
const long long MOD = 1000000000 +7;

typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<ll,pll> tll;
typedef pair<int,int> ii;
typedef pair<int,ii> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<ll> vll;
typedef vector<pll> vpll;
typedef vector<tll> vtll;
typedef vector<string> vs;
typedef set<int> si;
typedef set<ii> sii;
typedef set<iii> siii;

ll gcd(ll a, ll b){ return b==0?a:gcd(b,a%b);}

ll add(ll a, ll b, ll m = MOD){ return (a%m + b%m+2*m)%m;}

ll mul(ll a, ll b, ll m = MOD){ return ((a%m+m)*(b%m+m))%m;}

ll pow_mod(ll a, ll b, ll m = MOD){
	ll res = 1LL;
	a = a%m;
	while(b){
		if(b&1) res = mul(res,a,m);
		b >>= 1;
		a = mul(a,a,m);
	}
	return res;
}

ll fastexp(ll a, ll b){
	ll res = 1LL;
	while(b){
		if(b&1) res = res*a;
		b >>= 1;
		a *= a;
	}
	return res;
}

int gcdExtendido(int a, int b, int *x, int *y){
	if(a == 0){
		*x = 0;
		*y = 1;
		return b;
	}
	int x1, y1;
	int gcd = gcdExtendido(b%a,a,&x1,&y1);
	
	*x = y1-(b/a)*x1;
	*y = x1;
	return gcd;
}

int modInverso(int a, int m){
	int x, y;
	int g = gcdExtendido(a,m,&x,&y);
	if(g!=1) return -1;
	else return (x%m + m)%m;
}

/****************************************
*************P*L*A*N*T*I*L*L*A************
*****************************************/

const int N = 100+5;
const int V = 100000+5;
const ll inf = 1LL<<60;

int n;
int C;
int w[N];
int v[N];
ll memo[N][V];

int main(){
	ri2(n,C);
	int S = 0;
	for(int i=1; i<=n; i++){
		ri2(w[i],v[i]);
		S += v[i];
	}
	for(int i=0; i<=S; i++) memo[0][i] = inf;
	memo[0][0] = 0;
	for(int i=1; i<=n; i++){
		for(int j=0; j<=S; j++){
			memo[i][j] = memo[i-1][j];
			if(j >= v[i]){
				if(memo[i-1][j-v[i]] + w[i] <= C){
					memo[i][j] = min(memo[i][j],memo[i-1][j-v[i]]+w[i]);
				}
			}
		}
	}
	int ans = 0;
	for(int i=0; i<=S; i++){
		if(memo[n][i] <= C){
			ans = i;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 80128
#include<stdio.h>
#include<math.h>

int main(){
  int c[10000],i,count=0,n,f,j;
  
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&c[i]);
    }
  
  for(i=0;i<n;i++){
    f=0;
    if(c[i] <= 1) {
      f=1;
      break;
    }
    
    for(j=2;j<=(int)sqrt(c[i]);j++){
     if(c[i]%j==0){
       f=1;
       break;
     }
   }
   
   if(f==0) count++;
  }
  
  printf("%d\n",count);
  return 0;
}



Measured memory_bytes: 2124
n,k=map(int,input().split())
a=list(map(int,input().split()))
cnt=1
A=sum(a)
l=[]
for i in range(1,int(A**(1/2))+1):
    if A%i!=0:continue
    l.append(i)
    if  A// i != i:
        l.append(A // i)
for i in l:
    x=[0]*n
    for j in range(n):
        x[j]=a[j]%i
    s=sum(x)
    l=0
    x.sort(reverse=True)
    for j in range(n):
        if s<=k and l<=k:
            if (s-l)%i==0:
                if i>cnt:
                    cnt=i
                break
        l+=i-x[j]
        s-=x[j]

print(cnt)

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



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

using namespace std;

int main(){
    ll N,M,X,Y;
    string res = "Yes";

    cin >> N;
    vector <string> v(N);

    string tmp;

    REP(i,N)
    {
        cin >> tmp;
        REP(j,i)
        {
            if(tmp == v[j])res = "No";
        }
        v[i] = tmp;
    }
    for(ll k = 1; k < N; k++)
    {
        if(v[k-1][v[k-1].size()-1] != v[k][0])res = "No";
    }

    cout << res << endl;
}




Measured memory_bytes: 256
#include <iostream>
using namespace std;
char c;
int n,h,m;
int main()
{
	cin>>n;
	for (int i=1;i<=n;i++)
	{
		cin>>c;
		if (c=='I') h++;
		else h--;
		m=max(m,h);
	}
	cout<<m<<endl;
}

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

int main() {
  string s,f="";
  cin>>s;
  int e=s.size();
  for(int i=0;i<e;i++) {
    if(s.at(i)=='0') {
      string h="0";
      f+=h;
    }
    else if(s.at(i)=='1') {
      string h="1";
      f+=h;
    }
    else {
      if(f.size()!=0) {
        f.erase(f.begin()+f.size()-1);
      }
    }
  }
  cout<<f<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include<set>
using namespace std;
int main(){
  int N,K;
  cin>>N>>K;
  set<int>kaza2;
  int d;
  for(int i=0;i<K;i++){
    cin>>d;
    vector<int>kaza1(d);
    for(int j=0;j<d;j++){
      cin>>kaza1.at(j);
    }
    for(int l=0;l<d;l++){
      kaza2.insert(kaza1.at(l));
    }
  }
  int count=0;
  for(int k=1;k<=N;k++){
    count+=kaza2.count(k);
  }
  cout<<N-count<<endl;
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
long long res = 0;
void solve(string s) {
  for (int i = 0; i < (1 << s.length() - 1); i++) {
    long long sum = 0;
    long long curr = s[0] - '0';
    for (int j = 0; j < s.length() - 1; j++) {
      if (i & (1 << j)) {
        sum += curr;
        curr = s[j + 1] - '0';
      } else {
        curr *= 10;
        curr += s[j + 1] - '0';
      }
    }
    sum += curr;
    res += sum;
  }
}

int main() {
  string s;
  cin >> s;
  solve(s);
  cout << res << endl;
}


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

#define FOR(i, a, b) for (int i = (a); i < static_cast<int>(b); i++)
#define FORR(i, a, b) for (int i = (a); i >= static_cast<int>(b); i--)
#define rep(i, n) FOR (i, 0, n)
#define repall(i, arr) for (auto& i : (arr))
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define dump(x) cerr << #x << " = " << (x) << '\n'
template <typename T>
void print(const vector<vector<T>> matrix);
template <typename T>
void print(const vector<T> vec);
template <typename Arg>
void print(const Arg arg);
template <typename Head, typename... Args>
void print(const Head head, const Args... args);
template <typename T>
using pq = priority_queue<T>;
template <typename T>
using pqr = priority_queue<T, vector<T>, greater<T>>;
const int INF = INT_MAX / 2;
using ll = long long;

int main() {
    int n;
    cin >> n;
    if (n == 1) {
        print("Hello World");
    } else {
        int a, b;
        cin >> a >> b;
        print(a + b);
    }

    return 0;
}

//---------------------------------------------
template <typename T>
void print(const vector<vector<T>> matrix) {
    repall (vec, matrix)
        print(vec);
}
template <typename T>
void print(const vector<T> vec) {
    unsigned int len = vec.size();
    rep (i, len - 1)
        cout << vec[i] << ' ';
    cout << vec[len - 1] << '\n';
}
template <typename Arg>
void print(const Arg arg) {
    cout << arg << '\n';
}
template <typename Head, typename... Args>
void print(const Head head, const Args... args) {
    cout << head << " ";
    print(args...);
}


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

using namespace std;

int main() {

  int n, perm, ans = 0;
  cin >> n;
  for(int i = 1;i <= n;i++){
    cin >> perm;
    if(perm != i){
      ans++;
    }
  }
  if(ans < 3){
    cout << "YES";
  }else{
    cout << "NO";
  }
  return 0;
}


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

typedef long long ll;
#define rep(i,x) for(int i=0;i<x;i++)
#define put(ans)    cout << ans << endl;

double kaijyo(int n){
    int k(1);
    for(int i=n;i>0;i--){
        k *= i;
    }

    return k;
}

double distance(int x[],int y[],int i,int j){
    int dx = (x[i] - x[j]) * (x[i] - x[j]);
    int dy = (y[i] - y[j]) * (y[i] - y[j]);
    return sqrt(dx+dy);
}

int main(){
    int x,y;
    cin >> x >> y;
    string s(""),t("");

    rep(i,x)    t += to_string(y);
    rep(i,y)    s += to_string(x);

    cout << min(s,t) << endl;

    return 0;
}

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

int main() {
    int h1, m1, h2, m2, k;
    cin >> h1 >> m1 >> h2 >> m2>> k;
    
    int t = h2*60 + m2 - h1*60 - m1 - k;
    
    cout << t << endl;
    
    return 0;
}


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

int a[200010];

inline int read(){
    int X=0,w=0; char ch=0;
    while(!isdigit(ch)) {w|=ch=='-';ch=getchar();}
    while(isdigit(ch)) X=(X<<3)+(X<<1)+(ch^48),ch=getchar();
    return w?-X:X;
}

inline void write(int x){
     if(x<0) putchar('-'),x=-x;
     if(x>9) write(x/10);
     putchar(x%10+'0');
}
inline void writeln(int x){
     if(x<0) putchar('-'),x=-x;
     if(x>9) write(x/10);
     putchar(x%10+'0');
     puts("");
}

int main(){
    string t;
    int cnt=0;
    cin>>t;
    int n=t.size();
    
    for(int i=0;i<n;i++)
        if(t[i]=='?')
            t[i]='D';
    
    cout<<t;
        
    cout<<"\n";    
    return 0;
}

Measured memory_bytes: 3752
#include <bits/stdc++.h>
        using namespace std;
        #define ll long long int
        #define pb push_back
        #define mk make_pair
        #define ft first
        #define sc second
        #define ppb pop_back
        #define sz size
        #define forn(i,a,n) for(i=a;i<n;i++)
        #define M 998244353 
        #define inf 2e18
 
        int main() {
 
        
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        cout.tie(NULL);
        
        ll n,m;
        cin>>n>>m;
        ll ans = n*(n-1)/2 + m*(m-1)/2;
        cout<<ans;



        return 0;
        }

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
int main(){
	int N, A, B, C; 
	cin >> N >> A >> B >> C; 
	int L[10] = {}; 
	for(int i = 0; i < N; i++){
		cin >> L[i]; 
	}
	int ans = 1145141919; 
	for(int bit = 0; bit < (1 << (N * 2)); bit++){
		int LA = 0, LB = 0, LC = 0;
		int used = 0;  
		for(int i = 0; i < N; i++){
			int u = (bit >> (i * 2)) % 4; 
			if(u == 0) {LA += L[i]; used ++;}
			if(u == 1) {LB += L[i]; used ++;}
			if(u == 2) {LC += L[i]; used ++;}
		}
		if(LA == 0 || LB == 0 || LC == 0) continue; 
			int tmp = 10 * (used - 3) + abs(LA - A) + abs(LB - B) + abs(LC - C); 
			ans = min(ans, tmp);
	}
	cout << ans << endl; 
}

Measured memory_bytes: 256
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from bisect import bisect_right, bisect_left
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from copy import deepcopy
from math import factorial, ceil, floor, gamma, log
from operator import mul
from functools import reduce


sys.setrecursionlimit(2147483647)
INF = float('INF')
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 10 ** 9 + 7


print(chr(ord(S()) + 1))

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

int main()
{
	//ios_base::sync_with_stdio(0);
	//cin.tie(0); cout.tie(0);
	char c = getchar();
	if (tolower(c) != c) printf("A\n");
	else printf("a\n");
	return 0;
}


Measured memory_bytes: 3592
using namespace std;
#include <iostream>/*{{{*/
struct Fast {Fast(){std::cin.tie(0);ios::sync_with_stdio(false);}} fast;

#include <bits/stdc++.h>

#define rep(i, x) for(int i = 0; i < (int)(x); i++)
#define reps(i,x) for(int i = 1; i <= (int)(x); i++)
#define rrep(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define rreps(i,x) for(int i=((int)(x));i>0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define RFOR(i, m, n) for(int i = m;i >= n;i--)
#define foreach(x,a) for(auto& (x) : (a) )
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define fill(x,y) memset(x,y,sizeof(x))
#define pb(a) push_back(a)
// dump macro{{{
// http://www.creativ.xyz/dump-cpp-652
#define DUMPOUT cerr // 変数ダンプ先。coutかcerr
 
#define DEBUG_ // 提出時はコメントアウト
#ifdef DEBUG_
#define DEB
#else
// DEB と打つとデバッグ時以外はコメントアウトになる
#define DEB /##/
#endif
 
// 変数ダンプ用マクロ。デバッグ時以外は消滅する
// 引数はいくつでもどんな型でも可（ストリーム出力演算子があればOK）
#define dump(...) DEB DUMPOUT<<"  "; \
DUMPOUT<<#__VA_ARGS__; \
DUMPOUT<<":=> "; \
dump_func(__VA_ARGS__); DUMPOUT<<"in ["<<__LINE__<<":"<<__FUNCTION__<<"]"<<endl;
 
// デバッグ用変数ダンプ関数
void dump_func() {
}
template <class Head, class... Tail>
void dump_func(Head&& head, Tail&&... tail)
{
    DUMPOUT << head;
    if (sizeof...(Tail) == 0) {
        DUMPOUT << " ";
    }
    else {
        DUMPOUT << ", ";
    }
    dump_func(std::move(tail)...);
}
 
// vector出力
template<typename T>
ostream& operator << (ostream& os, vector<T>& vec) {
    os << "{";
    for (int i = 0; i<vec.size(); i++) {
        os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
    }
    os << "}";
    return os;
}/*}}}*/
#define debug(x)                 cerr << __LINE__ << ": " << #x << " -> " << x << '\n'
#define debug2(x, y)             cerr << __LINE__ << #x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define debug3(x, y, z)          cerr << __LINE__ << #x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define debug4(a, b, c, d)       cerr << __LINE__ << #a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define debug5(a, b, c, d, e)    cerr << __LINE__ << #a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define debug6(a, b, c, d, e, f) cerr << __LINE__ << #a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
#define db_2d(d,n,m) rep(i,n){rep(j,m){ cerr << (d)[i][j] << (((j)==(m-1))?"\n":" "); }}
#define db_1d(d,n) rep(i,n){cout << d[i] << (((i)==(n-1))?"\n":" ") << __LINE__}
#define INF 999999999
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long long ll;
typedef vector<long long> vll;
typedef vector<vll> vvll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<pii> vii;
typedef vector<vii> vvii;
typedef tuple<int,int,int> iii;
typedef set<int> si;
typedef complex<double> pnt;
typedef vector<pnt> vpnt;
typedef priority_queue<pii,vii,greater<pii> > spq;
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};/*}}}*/

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

  ll p=1;
  reps(i, n){
    p *= i;
    p = p%((ll)pow(10,9)+7);
  }
  cout << p << endl;

  return 0;
}


Measured memory_bytes: 256