akhauriyash/Code-Regression huggingface dataset:
# -*- coding: utf-8 -*-
"""
AtCoder A
"""

import sys, math, random
import numpy as np

# N = int(input())
# A = list(map(int,input().split())) # N row 1 column
# A = [int(input()) for _ in range(N)] # 1 row N column
# S = str(input()) # str(input()) == input() -> 'abc'
# S = list(input()) # abc -> ['a','b','c']
# S.replace('ABC','X') # "testABCABC" -> "testXX"
 
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]
 
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()


def main():
    N = I()
    A=LI()
    tmp=1
    out=0
    for i in range(N):
        out+=A[i]*tmp
        tmp*=-1
    bf=out/2
    out=str(out)
    for i in range(N-1):
        bf=A[i]-bf
        out+=" %d"%(bf*2)
    print(out)
    
if __name__ == "__main__":
    main()

Measured memory_bytes: 23748
#include<iostream>
#include<algorithm>
using namespace std;
bool cmp(int i,int j)
{return(i>j);} 
int main(){
    int n;
    cin>>n;
    int a[110];
    for(int i=0;i<n;i++)
    cin>>a[i];
    sort(a,a+n,cmp);
    int ans1=a[0];
    sort(a,a+n);
    int ans2=a[0];
    cout<<ans1-ans2<<endl;
    return 0;
}
    

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<unordered_set>
#include<set>
#include<map>
#include<unordered_map>
#include<stack>
#include<queue>
#include<string>
#include<cmath>
#include<climits>
using namespace std;

int main() {
    int h,w;
    cin>>h>>w;
    vector<vector<int>> dp(h, vector<int> (w,0));
    int mod = 1e9 + 7;
    for(int i=0;i<h;i++) {
        for(int j=0;j<w;j++) {
            char ch;
            cin>>ch;
            if(i==0 && j==0)   {dp[0][0]=1; continue;}
            if(ch=='#')     dp[i][j]=0;
            else {
                if(i==0)    dp[i][j]=dp[i][j-1];
                else if(j==0)   dp[i][j] = dp[i-1][j];
                else
                    dp[i][j] = (dp[i-1][j] + dp[i][j-1])%mod;
            }
        }
    }
    cout<<dp[h-1][w-1];
}


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

int main() {
  int N;
  int f = 0;
  cin >> N;
  
  for (int d = 1; d <= N; d*=10){
    f += N/d % 10;
  }

  if (N % f == 0){
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 3628
#include <iostream>
#include <utility>
#include <vector>
using namespace std;


int cnt=0;
vector<int> bsort(vector<int> vec){
     for(int i=0;i<vec.size()-1;++i){
        for(auto itr=vec.rbegin();itr!=vec.rend()-i;++itr){
            if(*itr>=*(itr+1)) continue;
            swap(*itr,*(itr+1));
            cnt++; 
        }
    }
    return vec;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int nb; cin>>nb;
    std::vector<int> lines; lines.resize(nb);
    for(auto& a:lines) cin>>a;
    
    auto sorted = bsort(lines);
    for(auto& a:sorted) cout<<a<<(&a!=&sorted.back()?" ":"\n");
    cout<<cnt<<"\n";
}

Measured memory_bytes: 3164
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(i=0;i<(n);i++)
#define loop(i,a,n) for(i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

typedef vector<int> vi;
typedef pair<int,int> pii;

int main(void) {
  int i,j;
  int n,a,b;
  cin>>n>>a>>b;
  int ans=0;
  loop(i,1,n+1){
    int tmp=i;
    int sum=0;
    while(tmp)sum+=tmp%10,tmp/=10;
    if(a<=sum && sum<=b)ans+=i;
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<queue>
#include<string>
#include<map>
#include<sstream>
using namespace std;

const int NODE_L = 0;   // 0 to 99 land
const int NODE_C = 100; // 100 to 105 cake
const int NODE_H = 106;
const int NODE_D = 107;
const int MAX = 108;
const int INF = 1e8;
typedef pair<int,int>P;
typedef pair<int,P>P2;

int d[MAX][(1 << 6)];
int M,N,K,D;
int C[6];
int G[MAX][MAX];

int getVal(string str){
  int ret;
  stringstream s(str);
  s >> ret;
  return ret;
}

int getPos(){
  string str;
  int ret;
  cin >> str;
  if(str == "H")ret = NODE_H;
  else if(str == "D")ret = NODE_D;
  else if(str[0] == 'L'){
    ret = NODE_L + getVal(str.substr(1)) - 1;
  }
  else if(str[0] == 'C'){
    ret = NODE_C + getVal(str.substr(1)) - 1;    
  }
  return ret;
}

void input(){
  for(int i = 0 ; i < M ; i++){
    cin >> C[i];
  }
  for(int i = 0 ; i < D ; i++){
    int n1,n2,dis;
    n1 = getPos();
    n2 = getPos();
    cin >> dis;
    G[n1][n2] = G[n2][n1] = dis;
  }
}

void init(){
  for(int i = 0 ; i < MAX ; i++){
    for(int j = 0 ; j < MAX ; j++){
      G[i][j] = INF;
    }
  }
}

void dijkstra(){
  priority_queue<P2,vector<P2>,greater<P2> >que;

  for(int i = 0 ; i < MAX ; i++){
    for(int j = 0 ; j < (1 << M); j++){
      d[i][j] = INF;
    }
  }
  
  que.push(P2(0,P(NODE_H,0)));
  d[NODE_H][0] = 0;

  int res = INF;

  while(que.size()){
    P2 p2 = que.top(); que.pop();
    int cost = p2.first;
    int now = p2.second.first;
    int state = p2.second.second;

    if(d[now][state] < cost)continue;

    for(int to = 0 ; to < MAX ; to++){
      int ncost = cost;
      int c = to - NODE_C;
      int nstate = state;

      if(G[now][to] == INF)continue;

      ncost += G[now][to]*K;

      if(NODE_C <= to && to < NODE_H){
	if((state >> c)&1)continue;
	nstate |= (1 << c);
	ncost -= C[c];
      }
      
      if(d[to][nstate] > ncost){
	d[to][nstate] = ncost;
	que.push(P2(d[to][nstate],P(to,nstate)));
      }

      if(to == NODE_D){
	res = min(res,d[to][nstate]);
      }
    }
  }

  cout << res << endl;
  
}

void solve(){
  init();
  input();
  dijkstra();
}

int main(){
  while(1){
    cin >> M >> N >> K >> D;
    if(!M&&!N&&!K&&!D)break;
    solve();
  }
  return 0;
}

Measured memory_bytes: 1384
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<LL,int> P;
const LL mod=1000000007;
const LL LINF=1LL<<62;
const LL INF=1<<17;

int main(){
    int N;cin >> N;
    if(N==1){
        puts("Yes");
        puts("2");
        cout << "1 1" << endl;
        cout << "1 1" << endl;
        return 0;
    }
    LL s=0;
    for(LL i=1;i<=N;i++){
        if(i*(i-1)==2*N){
            s=i;
            break;
        }
    }
    if(s==0){
        puts("No");
        return 0;
    }
    int ans[s][s-1];
    int a=1;
    for (int i = 0; i < s; i++) {
        for (int j = i; j < s-1; j++) {
            ans[i][j]=a++;
        }
        a-=s-i-2;
        for (int j = i+1; j < s-1; j++) {
            ans[j][i]=a++;
        }
    }
    for (int i = 0; i < s-1; i++) {
        ans[s-1][i]=ans[i][i];
    }
    puts("Yes");
    cout << s << endl;
    for (int i = 0; i < s; i++) {
        cout << s-1 << " ";
        for (int j = 0; j < s-1; j++) {
            cout << ans[i][j] << (j==s-2?"\n":" ");
        }
    }
    return 0;
}


Measured memory_bytes: 2176
#include "bits/stdc++.h"
// #include "boost/math/common_factor.hpp" // gcd, lcm
using namespace std;

// #define int long long

signed main(void) {
  int num; // num
  num = 0; // count, result
  // num = numeric_limits<int>::min(); // max
  // num = numeric_limits<int>::max(); // min
  int n;

  array<int, 4> a;

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

  bool flag = true;

  flag &= a.end() != find(a.begin(), a.end(), 1);
  flag &= a.end() != find(a.begin(), a.end(), 9);
  flag &= a.end() != find(a.begin(), a.end(), 7);
  flag &= a.end() != find(a.begin(), a.end(), 4);

  if (flag) cout << "YES" << endl;
  else cout << "NO" << endl;
  
  // cout << num << endl;
  return 0;
}


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

using namespace std;
typedef unsigned long long ll;
const int mod=1e9+7;
int a[20010];
int main()
{
	ll n,k;
	scanf("%lld %lld",&n,&k);
	ll cot=0; 
	for(int i=0;i<n;i++)
	{
		scanf("%d",&a[i]);
	}
	for(int i=0;i<n;i++)
	{
		for(int j=i+1;j<n;j++)
		{
			if(a[i]>a[j]) cot++;
		}
	}
	ll cnt=0;
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<i;j++)
		{
			if(a[j]<a[i]) cnt++;
		}
	} 
	ll sum=0;
	ll kk=k*(k+1)/2;
	if(kk==1) cout <<cot;
	else
	{
		ll kkk=(k-1)*(k)/2;
		sum=cot%mod*(kk%mod)%mod+cnt%mod*(kkk%mod)%mod;
		cout <<sum%mod<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main {

    public static void main(String args[]) {
        Scanner scan = new Scanner(System.in);

        int x = scan.nextInt();
        int i = 1;
        while (x != 0) {
            
            System.out.println("Case "+ i + ": " + x);
            x = scan.nextInt();
            i++;
        }
    }
    
}


Measured memory_bytes: 40044
#include <bits/stdc++.h>
#define int llint
#define rep(i, a, n) for(int (i) = (int)(a);(i) < (int)(n);++(i))
#define repe(i, a, n) for(int (i) = (int)(a);(i) <= (int)(n);++(i))
#define repif(i, a, x) for(int (i) = (int)(a);(x);++(i))
#define repr(i, a, n) for(int (i) = ((int)(a)-1);(i) >= (int)(n);--(i))
#define reper(i, a, n) for(int (i) = (int)(a);(i) >= (int)(n);--(i))
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define SIZE(x) ((int)(x).size())
#define ALL(x) (x).begin(), (x).end()
#define RNG(x, a, n) &((x)[a]), &((x)[n])
#define ADD(a, b) ((((a+MOD)%MOD)+((b+MOD)%MOD))%MOD)
#define MUL(a, b) ((((a)%MOD)*((b)%MOD))%MOD)
#define CEIL(x) ((int)ceil(((double)x)))
#define POW(x, y) ((int)pow(x, y))
#define UNIQUE(x) (x).erase(unique(ALL((x))), (x).end())
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define yes cout << "yes" << endl;
#define no cout << "no" << endl;
#define fcout cout << fixed << setprecision(10)
#define pb push_back
#define pf push_front
#define mp make_pair
#define mt make_tuple
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define EPS (1e-20)
#define INF INT_MAX
#define INFLL LLONG_MAX
#define MOD 1000000007
using llint = long long;
using VI = std::vector<int>;
using PII = std::pair<int, int>;
using SI = std::set<int>;
using MII = std::map<int, int>;
using TIII = std::tuple<int, int, int>;
using MCI = std::map<char, int>;
using VPII = std::vector<PII>;
using namespace std;


int N, A, B;
int v[60];
int comb[60][60];


void makeComb(){
	rep(i, 0, 60){
		comb[i][0] = comb[i][i] = 1;
		rep(j, 1, i) comb[i][j] = comb[i-1][j-1]+comb[i-1][j];
	}
}


void solve(){
	fcout << accumulate(RNG(v, 0, A), 0LL)/(double)A << endl;
	if(v[0] == v[A-1]){
		int ans = 0;
		int X = count(RNG(v, 0, N), v[0]);
		repe(i, A, B) ans += comb[X][i];
		cout << ans << endl;
	}
	else {
		int X = count(RNG(v, 0, N), v[A-1]);
		int Y = count(RNG(v, 0, A), v[A-1]);
		cout << comb[X][Y] << endl;
	}
}


signed main(){
	cin >> N >> A >> B;
	rep(i, 0, N) cin >> v[i];
	sort(RNG(v, 0, N), greater<int>());

	makeComb();

	solve();

	return 0;
}

Measured memory_bytes: 256
n, m, x = map(int, input().split())
X = [list(map(int, input().split())) for _ in range(n)]
ans = 193934993409409

for mask in range(2 ** n):
    C = [0] * m
    cost = 0

    for i in range(n):
        if (mask >> i) & 1:
            cost += X[i][0]
            #値段を加味して1から始めてる。そして収得すべきアルゴリズムの個数m
            #n個本があるので二次元配列のひとつめはi, m冊本があるので第2引数はj
            #Cはフラグの個数。

            for j in range(1, m + 1):
                C[j - 1] += X[i][j]
    #こいつ天才か?下一個舐めれば理解できるもんな。
    if min(C) >= x:
        ans = min(ans, cost)

if ans < 91912922191:
    print(ans)
else:
    print(-1)


Measured memory_bytes: 9200
#include <algorithm>
#include <cmath>
#include <climits>
#include <functional>
#include <iostream>
#include <queue>
#include <string>
#include <numeric>
#include <vector>

using namespace std;
using ll = long long;
template<typename T> void print(T t) {cout << t << endl;}


int main() {
	int H, W;
	cin >> H >> W;
	vector<vector<char>> board(H+2, vector<char>(W+2, '.'));
	for (int h = 1; h <= H; h++) {
		for (int w = 1; w <= W; w++) {
			cin >> board[h][w];
		}
	}
	for (int h = 1; h <= H; h++) {
		for (int w = 1; w <= W; w++) {
			if (board[h][w] == '#') {
				bool ok = false;
				if (board[h + 1][w] == '#') ok = true;
				if (board[h - 1][w] == '#') ok = true;
				if (board[h][w + 1] == '#') ok = true;
				if (board[h][w - 1] == '#') ok = true;
				if (!ok) {
					print("No");
					return 0;
				}
			}
		}
	}
	print("Yes");
}

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


int a[4];
int b[4];
int hit = 0;
int blow = 0;


void solve(){
	for (int i = 0; i < 4; i++){
		for (int j = 0; j < 4; j++){
			if (b[i] == a[j] && i == j){
				hit++;
				break;
			}
			if (b[i] == a[j]){
				blow++;
				break;
			}
		}
	}
}


int main(){
	while (cin >> a[0] >> a[1] >> a[2] >> a[3] >> b[0] >> b[1] >> b[2] >> b[3]){
		solve();
		cout << hit << ' ' << blow << endl;
		hit = 0;
		blow = 0;
	}

	return 0;
}

Measured memory_bytes: 3092
let X = stdin.ReadLine() |> int

let inline sqrtInt n =
    n
    |> float
    |> sqrt
    |> int

let isPrime x =
    let rec loop n =
        if n <= 1 then true
        elif x % n = 0 then false
        else loop (n - 1)
    loop (sqrtInt x)

let rec resolver x =
    if isPrime x then x
    else resolver (x + 1)

resolver X |> stdout.WriteLine


Measured memory_bytes: 11220
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();
        int B = sc.nextInt();
        
        if (B < A) {
            int w = A;
            A = B;
            B = w;
        }
        
        List<Integer> list = new ArrayList<>();
        list.add(1);
        list.add(2);
        list.add(3);
        
        list.remove(A - 1);
        list.remove(B - 2);
        
        System.out.println(list.get(0));
        
    }
    
}


Measured memory_bytes: 35288
#include<stdio.h>
#include<vector>
#include<iostream>

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

template <typename Abel=ll> class WeightedUnionFind {
    public:
    std::vector<ll> parent;
    std::vector<ll> sizes;
    std::vector<Abel> diff_weight;
    Abel Abel_unit = 0;                 //可換群の単位元 1
    Abel Abel_plus(Abel a, Abel b){      //可換群の加法 ab
        return a+b;
    }
    Abel Abel_minus(Abel a, Abel b){    //ab^-1
        return a-b;
    }

    WeightedUnionFind(ll N) : parent(N), sizes(N, 1), diff_weight(N) {
        for(ll i=0; i<N; i++){
            parent[i] = i;
            diff_weight[i] = Abel_unit;
        }
    }
    ll find(ll x){
        if(x==parent[x]) return x;
        ll r = find(parent[x]);
        diff_weight[x] = Abel_plus(diff_weight[x], diff_weight[parent[x]]);
        return parent[x]=r;
    }
    bool unite(ll x, ll y, Abel w){
        w = Abel_plus(w, weight(x));
        w = Abel_minus(w, weight(y));
        ll x_class = find(x);
        ll y_class = find(y);
        if(x_class == y_class) return false;
        if(sizes[x_class] < sizes[y_class]){
            std::swap(x_class, y_class);
            w = Abel_minus(Abel_unit, w);
        }
        parent[y_class] = x_class;
        sizes[x_class] += sizes[y_class];
        sizes[y_class] = 0;
        diff_weight[y_class] = w;
        return true;
    }
    bool same(ll x, ll y){
        return find(x)==find(y);
    }
    ll size(ll x){
        return sizes[find(x)];
    }
    Abel weight(ll x){
        find(x);  // 経路圧縮
        return diff_weight[x];
    }
    Abel diff(ll x, ll y){
        return Abel_minus(weight(y), weight(x));
    }
};


int main(){
    WeightedUnionFind<ll> uf(100005);
    int n,q, com, x, y, z;

    cin >> n >> q;
    REP(i,q){
        cin >> com;
        if(com==0){
            cin >> x >> y >> z;
            uf.unite(x,y,z);
        }
        else{
            cin >> x >> y;
            if(uf.find(x)==uf.find(y)){
                cout << uf.diff(x,y) << endl;
            }
            else{
                cout << "?" << endl;
            }
        }
    }
    return 0;
}


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

int main(){
	int n;
	cin>>n;
	double a[102];
	double sum;
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	sort(a,a+n);
	double ave=a[0];
	for(int i=1;i<n;i++){
		ave=(a[i]+ave)/2;
	}
	cout<<ave<<endl;
}


Measured memory_bytes: 256
#define rep(i, a, b) for (int i = a; i < b; ++i)
#define repr(i,a,b) for (int i = a; i > b; --i)
#define mm(lamb, tttt) memset(lamb, tttt, sizeof lamb)
 
#define null NULL
#define eps 0.000000001
#define mod 1000000007
#define PI 3.14159265358979323846
#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define ALL(V) V.begin(), V.end()
#define sz(V) (int)V.size()
#define _ <<" "<<
 
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long int ll;
typedef vector <int> vi;
typedef vector<vi> vvi;
typedef pair <int, int> ii;
typedef pair<int, pair<int,int> > iii;
typedef vector<ii> vii;
vector<int >v[200005];
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
 	
 
//	freopen ("test.txt","r",stdin);
	int n,m;
	cin>>n>>m;
	for (int i = 0; i < n; ++i)
	{
		int x,y;
		cin>>x>>y;
		v[x].pb(y);
	}
	multiset<int ,greater<int > >mul;
	ll ans = 0;
	for (int i = 1; i <=m; ++i)
	{
		int temp = v[i].size();
		for(int j=0;j<temp;j++)
		{
			mul.insert(v[i][j]);
		}

		auto k = mul.begin();

		if(!mul.empty())
		{
			ans += *(k);
			mul.erase(k);
		} 
	}

	cout<<ans;


} 



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



//int main(){
// int a[10];
// for(int i=0;i<10;i++){
//  cin>>a[i];
// }
// sort(a,a+10);
// for(int i=9;i>6;i--)
//  cout<<a[i]<<endl;
//return 0;
//}


int main(){
	int a,b,ans;
	while(cin>>a>>b){
		a+=b;
		ans=1;
		while(a/10){
			a/=10;
			ans++;
			}
		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 3048
//Author : Sukarna Paul

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/trie_policy.hpp>
#include<ext/pb_ds/detail/standard_policies.hpp>
#define pi acos(-1)
#define pb push_back
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
#define MAX 300005
#define INF 0x3f3f3f3f
template <class T> inline T bigmod(T p,T e,T M){ll ret = 1LL;for(; e > 0LL; e >>= 1LL){if(e & 1LL) ret = (ret * p) % M;p = (p * p) % M;}return (T)ret;}
template <class T> inline T modinverse(T a,T M){return bigmod(a,M-2,M);}   // M is prime}

using namespace std;
using namespace __gnu_pbds;

typedef trie<string,null_type,trie_string_access_traits<>,pat_trie_tag,trie_prefix_search_node_update>pref_trie;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
typedef tree<pair<int, int>,null_type,less<pair<int, int>>,rb_tree_tag,tree_order_statistics_node_update> ordered_multiset;




int main(){
    IOS
    //freopen("output.txt","w",stdout);
    int n;
    cin>>n;
    set<string>st;
    for(int i=0;i<n;i++){
        string s;
        cin>>s;

        st.insert(s);
    }
    cout<<st.size()<<"\n";
}


Measured memory_bytes: 19232
#include <stdio.h>

int GetSum(char num[]);

int main(void)
{
	int sum;
	char num[1001];
	
	while(1)
	{
		scanf("%s", num);
		if(num[0] == '0') break;
		sum = GetSum(num);
		printf("%d\n", sum);
	}
	
	return 0;
}

int GetSum(char num[])
{
	int i = 0, sum = 0;
	
	while(num[i])
	{
		sum += num[i] - '0';
		i++;
	}
	return sum;
}

Measured memory_bytes: 536
#include<bits/stdc++.h>
using namespace std;
int main(){
    ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
    char a[20],b[20];
    cin>>a;
    cin>>b;
    int flag=0;
    int x=strlen(a);
    for(int i=0;i<x;i++){
        if(a[i]!=b[i]){
            flag=1;
            break;
        }
    }
    if(flag==1) cout<<"No";
    else cout<<"Yes";
    return 0;
}

Measured memory_bytes: 3636
#include <stdio.h>
#include <stdlib.h>
#include "time.h"
#include "unistd.h"
#include "string.h"
#include <math.h>
int ans;
int main(int argc, char* argv[]){
  long int a=0,b,c;
  scanf("%ld %ld",&a,&b);
  if (a>b) {
    printf("%d\n",a-1);
  }else{
    printf("%d\n",a);
  }
}


Measured memory_bytes: 128
/*
LANG:C++
PROB:

*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>
#include <iostream>
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)


using namespace __gnu_pbds;
using namespace std;


typedef tree<int, null_type, less<int>, rb_tree_tag,
            tree_order_statistics_node_update>
    ordered_set;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef double ld;
typedef unsigned long long ui64;

template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }
const int mod=1000000007;
  i64 poww(i64 a, i64 b)
  {
    a%=mod;
    i64 res=1;
    while(b)
      {
if(b&1)res=res*a%mod;

      a=a*a%mod;
      b/=2;

      }
      return res;
  }
  i64 inv(i64 a)
  {
    return poww(a,mod-2);
  }


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

    // ifstream fin(".in");
    // ofstream fout(".in");
    int n;
cin>>n;
    vi v(n);
    forn(i,n)cin>>v[i];

    sort(all(v));
    unordered_map<int,int>mp;
    int ans=n;
    forn(i,n)
    {
      if(i+1<n&&v[i+1]==v[i])
      {
        ans--;
        mp[v[i]]++;
        continue;
      }
      for(int j=1;j*j<=v[i];j++)
      {
        if(v[i]%j==0)
        {
          if(mp[j]||mp[v[i]/j]){
            ans--;
            break;
          }
        }

      }

      mp[v[i]]++;
    }




cout<<ans;


    return 0;
  }


Measured memory_bytes: 32488
n=int(input())
a=list(map(int,input().split()))
x=sum(a)
y=0
for i in range(0,n-1):
    y+=a[i]
    if i==0:
        ans=abs(y-(x-y))
    else:
        if ans>abs(y-(x-y)):
            ans=abs(y-(x-y))
    #print(ans,y)
print(ans)

Measured memory_bytes: 24812
import scala.annotation.tailrec
object Main extends App {
  import scala.io.StdIn._
  val map = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ".zipWithIndex.map{case (c, i) ⇒ (1L << i, c)}.toMap
  loop()
  @tailrec def loop(): Unit = {
    val Array(n, m, q) = readLine.trim.split(' ').map(_.toInt)
    if (n == 0 && m == 0 && q == 0) return
    val bulbs = Array.fill(m){(1L << n) - 1}
    var switch = 0L
    for (_ ← 0 until q){
      val Array(s, b) = readLine.trim.split(' ')
      switch ^= java.lang.Long.parseLong(s.reverse, 2)
      for (i ← b.indices) {
        bulbs(i) &= (if (b(i) == '1') switch else ~switch)
      }
    }
    println(bulbs.map(map.getOrElse(_, '?')).mkString(""))
    loop()
  }
}


Measured memory_bytes: 130172
#include <algorithm>
#include <array>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>
using namespace std;

int main(int argc, char** argv) {
	int n;
	vector<int> a, order;

	cin >> n;
	a.resize(n);
	order.resize(n);

	for (int i = 0; i < a.size(); i++) {
		cin >> a.at(i);
		order.at(a.at(i) - 1) = i + 1;
	}

	for (auto &i : order) {
		cout << i << " ";
	}
	cout << endl;

	return 0;
}


Measured memory_bytes: 1664
#include  <iostream>
#include  <stdio.h>
#include <algorithm>
#include <map>
#include <math.h>

using namespace std;
#include <vector>
#define rep(i,n) for (ll i = 0; i < (n) ; i++)
#define INF 1e9
#define llINF 1e18
#define base10_4 10000      //1e4
#define base10_5 100000     //1e5
#define base10_6 1000000    //1e6
#define base10_7 10000000   //1e7
#define base10_8 100000000  //1e8
#define base10_9 1000000000 //1e9

#define MOD 1000000007
#define pb push_back
#define ll long long
#define ull unsigned long long
#define vint vector<int>
#define vll vector<ll>

//#include <stack>
//#include <queue>

// #include <iomanip>
//  cout << fixed << setprecision(15) << y << endl;

string ans_Yes = "Yes"; 
string ans_No = "No"; 
string ans_yes = "yes"; 
string ans_no = "no"; 

ll A;
ll B;
ll C;
ll N;
ll M;
ll K;


ll ltmp;
string stmp;
double dtmp;

int main(){

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

    cin >> N;
    cin >> K;

    char S[N];
    cin >> S;

    char conv = S[K-1];
    conv = conv - 'A' + 'a';

    S[K-1] = conv;
    cout << S << endl;


    

}

Measured memory_bytes: 3672
#include <iostream>
#include <vector>
#include <string>
using namespace std;
int main() {
 int N;
  cin >>N;
vector<int> A;
  for(int i=0;i<N;i++)
{
    int aa;
    cin >>aa;
  A.push_back(aa);
}
  long long count=0;
  long long max=0;
  for(int i=0;i<A.size();i++)
  {
   if(max<A[i])
   {
     max=A[i];
   }
    count+=max-A[i];
  }
   cout << count << endl;

}

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

int main(){
  int a,b;

  cin>>a>>b;

  if(a==b)
    cout<<"Draw"<<endl;
  else if(a==1||a>b&&b!=1)
    cout<<"Alice"<<endl;
  else
    cout<<"Bob"<<endl;

  return 0;
}


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

using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

#define long long ll

int main(){
    int n, k, x, y;
    cin >> n >> k >> x >> y;
    int fee;
    if (n > k){
        fee = k * x;
        fee += (n-k) * y;
        cout << fee << endl;
        
    }else{
        fee = n * x;
        cout << fee << endl;
    }
    return 0;
}


Measured memory_bytes: 256
k = int(input())
 
def gcd2(a,b):
    if b == 0:
        return a
    return gcd2(b,a%b)

def gcd3(a,b,c):
    return gcd2(gcd2(a,b), c)

ans = 0
for i in range(1,k+1):
    for j in range(i,k+1):
        for m in range(j, k+1):
            if i == j == m:
                ans += gcd3(i,j,m)
            elif i == j or j == m:
                ans += gcd3(i,j,m)*3
            else:
                ans += gcd3(i,j,m)*6

print(ans)

Measured memory_bytes: 9152
require 'bigdecimal'
input = STDIN.read.split("\n")
a = Array.new(input.shift.to_i) do
  x1, y1, x2, y2, x3, y3, x4, y4 = input.shift.chomp.split.map { |e| BigDecimal.new(e) }
  (y1 == y2 && y3 == y4) || (y2 - y1) / (x2 - x1) == (y4 - y3) / (x4 - x3) ? 'YES' : 'NO'
end
puts a

Measured memory_bytes: 8872
N,T=map(int,input().split())
c=[list(map(int,input().split())) for i in range(N)]

cost = 1001
for i in range(N):
  if c[i][0] < cost and c[i][1]<=T:
    cost=c[i][0]
if cost==1001:
  print("TLE")
else:
  print(cost)

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

using namespace std;

#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#pragma GCC optimize("-ffloat-store")

#define fastio               \
    ios::sync_with_stdio(0); \
    cin.tie(0);              \
    cout.tie(0);
//#define int long long
#define ll long long
#define endl "\n"
#define inf ULLONG_MAX
#define gcd __gcd
#define deb(x) cout << #x << " " << x << endl;
#define pr(x) cout << x << endl;

#define sz(a) ((ll)(a).size())
#define all(v) (v).begin(), (v).end()
#define tr(c, it) for (auto(it) = (c).begin(); (it) != (c).end(); it++)
#define pres(c, val) ((c).find(val) != (c).end())
#define cpres(c, val) (find(all(c), val) != (c).end())
#define dec greater<ll>()
#define sortv(x) sort(all(x))
#define revsortv(x) sort(all(x), dec)
#define com(x) ((x) * (x + 1) / 2)

#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define bg begin()
#define ed end()
#define bs binary_search // to find if an element is present or not in Ologn time, return a boolean
#define ub upper_bound   // to find an element strictly greater than the given no.
#define lb lower_bound   // lb(v,begin(), v.end(), n) gives the iterator

#define fo(n) for (ll i = 0; i < n; i++)
#define fo1(n) for (ll i = 1; i < n; i++)
#define fo2(i, n) for (ll i = 0; i < n; i++)
#define fo3(i, a, b) for (ll i = a; i < b; i++)
#define fors(a) cin >> a[i]
#define forp(a) cout << a[i] << " "
#define prv(a, n)  \
    fo(n) forp(a); \
    cout << endl;
#define fob(i, a, b) for (ll i = (b); i >= (a); i--)

typedef pair<ll, ll> pll;
typedef vector<string> vs;
typedef vector<char> vc;
typedef vector<ll> vl;
typedef vector<pll> vll;
typedef set<ll> sl;
typedef map<string, ll> msl;
typedef unordered_map<string, ll> umsl;
typedef map<ll, ll> mll;
typedef unordered_map<ll, ll> umll;

#define scan(v, n)   \
    vl v;            \
    fo(n)            \
    {                \
        ll item;     \
        cin >> item; \
        v.pb(item);  \
    }

const ll INF = 0xFFFFFFFFFFFFFFFL;;
const ll N = 1e9 + 7;
void swap1(ll a,ll b){
    ll temp;
    temp=a;
    a=b;
    b=temp;
}
void solve()
{
ll n,k,d,x;
vl s;
cin>>n>>k;
fo(k){
    cin>>d;
    fo(d){
        cin>>x;
        s.pb(x);
    }
}
sort(s.begin(),s.end());
vl ss;
ss.pb(s[0]);
fo(s.size()-1){
if(s[i]!=s[i+1])ss.pb(s[i+1]);
}
cout<<n-ss.size();

}

int32_t main(int32_t argc, char **argv)
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    /*#ifndef ONLINE_JUDGE
    freopen("inputf.txt", "r", stdin);
    freopen("outputf.txt", "w", stdout);
    freopen("error.txt", "w", stderr);
#endif*/

    ll t;
   // cin >> t;
    t=1;
   while (t--)
        solve();

    cerr << endl
         << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";

    return 0;
}

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

int main(){
    string s;
    cin >> s;
    string ans = "";
    for(char c:s){
        if(c == '1') ans.push_back('1');
        if(c == '0') ans.push_back('0');
        if(c == 'B'){
            if(ans != "") ans.pop_back();
        } 
    }
    cout << ans << endl;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
using ull=unsigned long long;
#define mod 1000000007
#define mod2 998244353 
#define PI 3.14159265
#define ll long long
#define ld long double
#define pi pair<ll,ll>
#define pb push_back
#define vi vector<ll>
#define sz size()
#define setbits(x)  __builtin_popcount(x)
#define fi first
#define se second
#define lz length()
#define all(x) (x).begin(),(x).end()
#define scf(x) scanf("%lld",&x)
#define rep(i,n) for(ll i=0;i<n;i++)
const int INF = (int)1e9;
const ll IINF=1LL<<62;
const int maxn=10000005;

//int divr[maxn];
/**/
/*void divisor()
{for(int i=2;i<sqrt(maxn);i++)
     {
          if(!divr[i])
          {
               for(int j=i*i;j<maxn;j+=i)if(!divr[j])divr[j]=i;     
          }
     }
     for(int i=1;i<maxn;i++)if(!divr[i])divr[i]=i;
}*/
 
/*const int N=1000005;
ll n;
struct line {
    long long m, c;
    long long eval(long long x) { return m * x + c; }
    long double intersectX(line l) { return (long double) (c - l.c) / (l.m - m); }
};
vector<pair<pi,ll>> rect;
deque<line> dq;
*/
/*int find(int a){
     if(a==par[a])return a;
     return par[a]=find(par[a]);
}
void unite(int a,int b){
     a=find(a),b=find(b);
     if(a==b)return ;
     par[b]=a;
}
ll modexpo(ll a,ll b)
{
     ll ans=1LL;
     while(b>0)
     {
          if(b&1)ans=(ans*a)%mod;
          a=(a*a)%mod;
          b>>=1;
     }
     return ans;
}
*/
vector<int> adj[10005];
int c[100005];
int m;
int val[100005];
void dfs(int node,int par){
     val[node]=c[m--];
     for(int child:adj[node]){
          if(child==par)continue;
          dfs(child,node);
     }
}
int main(){
     int n;
     cin>>n;
     for(int i=1;i<n;i++){
          int a,b;cin>>a>>b;
          adj[a].pb(b);adj[b].pb(a);
     }
     for(int i=0;i<n;i++)cin>>c[i];
     sort(c,c+n);
     m=n-1;
     dfs(1,-1);
     ll res=0;
     for(int i=0;i<n-1;i++)res+=c[i];
     cout<<res<<"\n";
     for(int i=1;i<=n;i++)cout<<val[i]<<" ";

}
 
 
 
 

























Measured memory_bytes: 4608
#include <iostream>
#include <cmath>
using namespace std;
int main() {
	long long N, P;
	cin >> N >> P;
	long long ans = 1;
	long long Q = P;
	for (long long i = 2; i <= sqrt(P)+1; i++) {
		long long num = 0;
		while (Q % i == 0) {
			Q /= i;
			num++;
		}
		if (num >= N) for (int j=0; j<num/N; j++) ans *= i;
		if (Q == 1) break;
	}
	cout << (Q>1 && N==1 ? P : ans) << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void){
	int a,n,p=1;
	scanf("%d %d",&a,&n);
	for(int i=0;i<a;i++){
		p*=100;
	}
	if(n==100){
		p*=101;
	}else{
		p*=n;
	}
	printf("%d",p);
	return 0;
}

Measured memory_bytes: 128
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,copy,time
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())

N,T = inpl()
ans = INF
for _ in range(N):
    c,t = inpl()
    if t <= T:
        ans = min(ans,c)


if ans == INF:
    print("TLE")
else:
    print(ans)


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

typedef long long ll;

#define int ll
#define all(v) v.begin(), v.end()
#define reps(__i, a, b) for (int __i = a; i < b; i++)
#define rep(__i, n) reps(__i, 0, n)

const ll INF = (1ll << 60);
const ll MOD = (ll)1e9 + 7;

int n;
int arr[10001][10001] = {};
int ret[10001] = {};
priority_queue<int> pq;
void dfs(int node, int value)
{

    ret[node] = value;

    for (int i = 1; i <= n; i++)
    {
        if (arr[node][i] == 1)
        {
            arr[node][i] = 0;
            arr[i][node] = 0;
            int tmp = pq.top();
            pq.pop();
            dfs(i, tmp);
        }
    }
}

signed main()
{
    int a[10001], b[10001], c[10001];
    cin >> n;
    for (int i = 0; i < n - 1; i++)
    {
        cin >> a[i] >> b[i];
        arr[a[i]][b[i]] = 1;
        arr[b[i]][a[i]] = 1;
    }
    for (int i = 0; i < n; i++)
    {
        cin >> c[i];
        pq.push(c[i]);
    }

    sort(c, c + n, greater<int>());
    int sum = 0;
    for (int i = 1; i < n; i++)
        sum += c[i];

    pq.pop();
    dfs(1, c[0]);
    cout << sum << endl;
    for (int i = 1; i <= n; i++)
        cout << ret[i] << " ";
    cout << endl;
}

Measured memory_bytes: 779776
#include <bits/stdc++.h>
using namespace std;
/*---define tricks---*/
#define ALL(v) v.begin(),v.end()
#define UN(v) sort(ALL(v)),v.erase(unique(ALL(v)),v.end())
#define FILL(x,y) memset(x,y,sizeof(x))
#define EACH(v,it) for(__typeof(v.begin()) it=v.begin();it!=v.end();it++)
#define FIO ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define revsort(b,e) sort(b,e),reverse(b,e)
/*---define types---*/
typedef long long ll;
typedef unsigned int uint;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<pii> vii;
/*---define variables---*/
vi a;
int n;
/*---define function---*/

/*---main code---*/
int main()
{
	FIO;
	cin>>n;
	a.resize(n);
	for(int i=0;i<n;++i)
	{
		cin>>a[i];
	}
	UN(a);
	int s=a.size();
	if(s%2)
	{
		cout<<s<<'\n';
	}
	else
	{
		cout<<s-1<<'\n';
	}
	return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define r0 return 0;
#define f(k,i,n,j) for(ll k=i;k<=n;k=k+j)
#define cin(a) cin>>a;
#define loop while(t--)
#define vi vector<int>
#define vii vector<long long int>
#define SORT(v) sort(v.begin(),v.end());
#define mod (1e9+7)
#define crap ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define endl "\n"
signed main()
{
    crap;
    int a,p;
    cin>>a>>p;
    cout<<(3*a+p)/2<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,s,e) for(int i=(s); i<(e);i++)
#define rep(i,n) REP(i,0,n)
#define rep1(i,n) REP(i,1,n)
#define repe(i,n) for(auto &&i:n)
#define all(v) (v).begin(),(v).end()
#define decimal fixed<<setprecision(20)
#define fastcin() cin.tie(0);ios::sync_with_stdio(false)
using namespace std;
using LL = long long;
using Graph = vector<vector<int>>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = 1e9;
const LL LLINF = 1e16;
const int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};

int main(){
    fastcin();

    int k, n;
    cin >> k >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];

    a.push_back(a[0]+k);
    LL ans = LLINF;
    rep(i, n) chmin(ans, 0LL+k-(a[i+1]-a[i]));
    cout << ans << endl;

}

Measured memory_bytes: 1792
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int[] a = new int[n];
		long ans = 0;

		for(int i=0;i<n;i++) {
			a[i] = scan.nextInt();
		}

		for(int i=0;i<n-1;i++) {
			if(a[i] > a[i+1]) {
				ans += a[i] - a[i+1];
				a[i+1] = a[i];
			}
		}

		System.out.println(ans);

	}

}

Measured memory_bytes: 61220
let readInt _ = stdin.ReadLine() |> int

let readIntArray _ =
    stdin.ReadLine().Split(" ") |> Array.map int

()
|> readInt
|> fun x -> [ 1 .. x ]
|> List.map readIntArray
|> List.sumBy (fun [| a; b |] -> b - a + 1)
|> printfn "%d"


Measured memory_bytes: 30308
# seg = SegmentTree(init_val=dp, segfunc=max, ide_ele=0)
class SegmentTree:
    # original: @solzard_
    def __init__(self,
                 init_val: 'initial value: iterable',
                 segfunc: 'operation unique in case',
                 ide_ele: 'identity element corresponding init_val' = 0,
                 ):
        self.segfunc = segfunc
        self.ide_ele = ide_ele
        self.size = 1 << (len(init_val) - 1).bit_length()
        self.tree = self._build(init_val)

    def _build(self, init_val) -> 'tree':
        segfunc = self.segfunc

        tree = [self.ide_ele] * (self.size * 2 - 1)

        for idx, val in enumerate(init_val, self.size - 1):  # set
            # modify val if needed (e.g. str -> ord())
            tree[idx] = val

        for idx in range(self.size - 2, -1, -1):  # build
            tree[idx] = segfunc(tree[idx * 2 + 1], tree[idx * 2 + 2])

        return tree

    def update(self, idx: int, val) -> None:
        tree = self.tree
        segfunc = self.segfunc

        idx += self.size - 1
        # modify val if needed as same as in _build()
        tree[idx] = val
        while idx > 0:
            idx = (idx - 1) // 2
            tree[idx] = segfunc(tree[idx * 2 + 1], tree[idx * 2 + 2])

    def query(self, left: int, right: int) -> 'result':
        left += self.size
        right += self.size
        ret = self.ide_ele  # left >= right: return self.ide_ele
        segfunc = self.segfunc
        tree = self.tree
        while left < right:
            if left & 1:  # odd
                ret = segfunc(ret, tree[left - 1])
                left += 1
            if right & 1:  # odd
                right -= 1
                ret = segfunc(ret, tree[right - 1])
            left >>= 1
            right >>= 1
        return ret


n = int(input())
h = tuple(map(int, input().split()))
a = tuple(map(int, input().split()))

dp = [0] * (n + 1)
# dp[j] := 末尾jの単調増加列の美しさの総和の最大値

seg = SegmentTree(init_val=dp, segfunc=max, ide_ele=0)

for h_, a_ in zip(h, a):
    # i本目を取って末尾にするとき
    max_ = seg.query(0, h_) + a_
    seg.update(h_, max_)
print(seg.query(0, n + 1))


Measured memory_bytes: 128892
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using datas=pair<ll,ll>;
using ddatas=pair<double,double>;
using tdata=pair<ll,datas>;
using vec=vector<ll>;
using mat=vector<vec>;
using pvec=vector<datas>;
using pmat=vector<pvec>;
#define For(i,a,b) for(i=a;i<b;i++)
#define bFor(i,a,b) for(i=a;i>=b;i--)
#define rep(i,N) For(i,0,N)
#define rep1(i,N) For(i,1,N)
#define brep(i,N) bFor(i,N-1,0)
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define vsort(v) sort(all(v))
#define vrsort(v) sort(allr(v))
#define endl "\n"
#define pb push_back
#define output(v) do{bool f=0;for(auto outi:v){cout<<(f?" ":"")<<outi;f=1;}cout<<endl;}while(0)
const ll mod=1000000007;
const ll inf=1LL<<60;
template<class T> inline bool chmax(T& a,T b){bool x=a<b;if(x)a=b;return x;} 
template<class T> inline bool chmin(T& a,T b){bool x=a>b;if(x)a=b;return x;} 

double distance(ddatas& x,ddatas& y){
  double a=x.first-y.first,b=x.second-y.second;
  return sqrt(a*a+b*b);
}

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

ll moddevide(ll a,ll b){return (a*modinv(b))%mod;}

vec modncrlistp,modncrlistm;

ll modncr(ll n,ll r){
  ll i,size=modncrlistp.size();
  if(size<=n){
    modncrlistp.resize(n+1);
    modncrlistm.resize(n+1);
    if(!size){
      modncrlistp[0]=modncrlistm[0]=1;
      size++;
    }
    For(i,size,n+1){
      modncrlistp[i]=modncrlistp[i-1]*i%mod;
      modncrlistm[i]=modinv(modncrlistp[i]);
    }
  }
  return modncrlistp[n]*modncrlistm[r]%mod*modncrlistm[n-r]%mod;
}

ll modpow(ll a,ll n){
  ll res=1;
  while(n){
    if(n&1)res=res*a%mod;
    a=a*a%mod;
    n>>=1;
  }
  return res;
}

ll gcd(ll a,ll b){if(!b)return a;return (a%b==0)?b:gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

ll countdigits(ll n){
  ll ans=0;
  while(n){n/=10;ans++;}
  return ans;
}

ll sumdigits(ll n){
  ll ans=0;
  while(n){ans+=n%10;n/=10;}
  return ans;
}

vec eratosthenes(ll N){
  ll i;
  vec ch(N+1,1),p;
  ch[0]=ch[1]=0;
  rep(i,N+1){
    if(ch[i]){
      p.pb(i);
      for(ll j=2;i*j<=N;j++){
        ch[i*j]=0;
      }
    }
  }
  return ch;
}

int main(){
  ll i=11,N,ans=0,x;
  cin>>N;
  vec v=eratosthenes(55555);
  while(1){
    if(v[i]){
      cout<<i<<" ";
      if(--N==0)return 0;
    }
    i+=5;
  }
  return 0;
}

Measured memory_bytes: 768
#include<map>
#include<iostream>
#include<deque>
#include<algorithm>
#include<string>
#include<cctype>
#include<iomanip>
#include<vector>
#include<queue>
 
using namespace std;
#define REP(i,b,e) for(ll i=(ll)b;i<(ll)e;i++)
#define rep0(i,n) REP(i,0ll,n)
#define rep1(i,n) REP(i,1ll,n+1)
 
#define shosu setprecision(13)
 
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,P> Q;
//ll longinf=1ll<<60;
int inf=1<<29;
int dn[4]={-1,1,0,0};
int dm[4]={0,0,-1,1};
ll longinf=(1ll<<60);

const ll MOD = 1e9+7;

class unionFind{
      private:
      vector<int> parent;
      vector<int> rank;
      vector<int> sizes;

      public:
      unionFind(int n){
            rep0(i,n){
                  parent.push_back(i);
                  rank.push_back(0);
                  sizes.push_back(1);
            }
      }
      int root(int x){
            if(parent[x]==x){
                  return x;
            }
            else{
                  parent[x] = root(parent[x]);
                  return parent[x];
            }
      }
      void merge(int x,int y){
            x=root(x);
            y=root(y);
            if(x==y) return;
            if(rank[x]<rank[y]) swap(x,y);
            if(rank[x]==rank[y]) rank[x]++;
            parent[y]=x;
            sizes[x]+=sizes[y];
      }
      bool same(int x,int y){
            return root(x)==root(y);
      }
      int size(int x){
            return sizes[root(x)];
      }
};
int main(){
      int N,K,L;
      cin>>N>>K>>L;
      unionFind road(N);
      unionFind train(N);
      int p[K],q[K];
      rep0(i,K){
            cin>>p[i]>>q[i];
            p[i]--,q[i]--;
            road.merge(p[i],q[i]);
      }
      int r[L],s[L];
      rep0(i,L){
            cin>>r[i]>>s[i];
            r[i]--,s[i]--;
            train.merge(r[i],s[i]);
      }
      map<pair<int,int>,int> mp;
      rep0(i,N){
            mp[{road.root(i),train.root(i)}]++;
      }
      rep0(i,N){
            cout<<mp[{road.root(i),train.root(i)}]<<" ";
      }
      cout<<endl;
      
}

Measured memory_bytes: 18144
// Problem : C - Sum of gcd of Tuples (Easy)
// Contest : AtCoder Beginner Contest 162
// URL : https://atcoder.jp/contests/abc162/tasks/abc162_c
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cp-editor)

#include<bits/stdc++.h>
#define int long long
#define mod 1000000007
#define trace(x) cerr<<#x<<": "<<x<<" "<<endl
#define tarce(x) cerr<<#x<<": "<<x<<" "<<endl
#define trace2(x, y) cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z) cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define sa(a,n) for(int i =0 ; i<n ; i++) cin>>a[i]
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define pb push_back
#define inf 2e18
#define scan() int n; cin>>n ; int a[n]; for(int i = 0 ; i<n ; i++) cin>>a[i]
#define print(a,n) for(int i = 0 ; i < n ; i++) cout<<a[i]<<' '
#define mem(a,v) memset(a,v,sizeof(a))
#define pii pair<int,int>
#define mkp make_pair
using namespace std;
#define N 200005


int32_t main(){
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        cout.tie(NULL);
        int i,j,k;
        int n;
        cin >> n;
        int ans=0;
        for(i=1; i<=n; i++){
        	for(j=1; j<=n; j++){
        		for(k=1; k<=n; k++){
        			int x=__gcd(i,j);
        			int y=__gcd(x,k);
        			ans+=y;
        		}
        	}
        }
        cout << ans << '\n';
        
        
        
        
        
        

}

Measured memory_bytes: 3620
from sys import stdin

data = []
for _ in range(3):
    data.append([int(x) for x in stdin.readline().rstrip().split()])

flag = False

for j in range(0,101):
    b1 = data[0][0] - j
    b2 = data[0][1] - j
    b3 = data[0][2] - j
    cnt = 0
    for k in data[1:]:
        if (k[0] - b1) == (k[1] - b2) == (k[2] - b3):
            cnt += 1
    if cnt == 2:
        flag = True
if flag:
    print("Yes")
else:
    print("No")

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

using namespace std;

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

  int n, m;
  cin >> n >> m;
  cout << n * (n - 1) / 2 + m * (m - 1) / 2;

  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define each(a,x) for(auto a : (x))
#define all(a) (a).begin(),(a).end()
#define chmin(a,b) ((a) = min((a),(b)))
#define chmax(a,b) ((a) = max((a),(b)))
#define in_range(x,l,r) ((l)<=(x) && (x)<(r))
#define printvec(a) rep(i,a) cout << a[i] << " \n"[i+1==(a).size()];
#define fs first
#define sc second
#define em emplace
#define eb emplace_back
#define sz size()
#define MP make_pair
using namespace std;
typedef long long ll;
typedef double D;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vs;

const ll INF = 1e15;
const D EPS = 1e-8;
const ll MOD = 1e9+7;

int main(){
  ll n,c,k;
  cin >> n >> c >> k;
  vl t(n);
  rep(i,n) cin >> t[i];
  sort(all(t));

  ll ans = 0;
  ll num = 0, lim = INF;
  rep(i,n){
    if(t[i] > lim){
      ans++; num = 1; lim = t[i] + k;
    }else{
      if(num == 0){
        lim = t[i] + k;
      }
      num++;
      if(num == c){
        ans++; num = 0; lim = INF;
      }
    }
  }
  if(num) ans++;
  cout << ans << endl;
}


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

using namespace std;

int main(){
  string S;
  cin >> S;
  int n = (int)S.size();
  
  int h = 0;
  for(int i = 0; i < n - i; i++){
    if(S[i] != S[n - i - 1]) h++;
  }
  
  cout << h << endl;
  
  return 0;
}

Measured memory_bytes: 256